1. Java Rosa
  2. javarosa

Commits

Clayton Sims  committed 12b0c99

Lots of updates to send helpers to deal with out of date transq/v. stored forms in the j2merosa demo. Updated for now to match ODK style behavior

  • Participants
  • Parent commits 8a6d689
  • Branches default

Comments (0)

Files changed (10)

File j2me/communication/src/org/javarosa/services/transport/SubmissionTransportHelper.java

View file
 		return new SubmissionProfile(new XPathReference("/"), "post", url, null);
 	}
 	
-	public static TransportMessage createMessage(FormInstance instance, SubmissionProfile profile) throws IOException {
+	public static TransportMessage createMessage(FormInstance instance, SubmissionProfile profile, boolean cacheable) throws IOException {
 		//If there is a submission profile, we need to use the relevant portions.
 		if(profile.getMethod().toLowerCase().equals("post")) {
 			
 			String url = profile.getAction();
 		
 			IDataPayload payload = new XFormSerializingVisitor().createSerializedPayload(instance, profile.getRef());
-			return new SimpleHttpTransportMessage(payload.getPayloadStream(),url);
+			SimpleHttpTransportMessage message = new SimpleHttpTransportMessage(payload.getPayloadStream(),url);
+			message.setCacheable(cacheable);
+			message.setOpenRosaApiVersion(null);
+			return message;
 		} else if(profile.getMethod().toLowerCase().equals("smspush")) {
 			
 			//#if polish.api.wmapi

File j2me/form-entry/src/org/javarosa/formmanager/api/FormTransportState.java

View file
 public abstract class FormTransportState implements FormTransportStateTransitions, State, HandledCommandListener, HandledItemStateListener {
 	//not separating out state/controller/etc, as form send is already kind of a mess
 	
-	FormTransportStateTransitions transitions;
-	FormTransportSubmitStatusScreen screen;
+	protected FormTransportStateTransitions transitions;
+	protected FormTransportSubmitStatusScreen screen;
 	
-	FormSender sender;
+	protected FormSender sender;
 
 	public FormTransportState(TransportMessage message) {
 		this(message, null);
 	
 	public FormTransportState(TransportMessage message, TransportResponseProcessor responder) {
 		FormTransportViews views = new FormTransportViews(this, this, responder);
-		sender = new FormSender(views, message);
 		screen = views.getSubmitStatusScreen();
+		sender = new FormSender(screen, message);
 		this.transitions = this;
 	}
 	

File j2me/form-entry/src/org/javarosa/formmanager/utility/FormSender.java

View file
 
 	TransportMessage message;
 	private ISubmitStatusObserver observer;
-	private FormTransportViews views;
+	FormTransportSubmitStatusScreen view;
 
 	/**
 	 * @param shell
 	 * @param activity
 	 */
-	public FormSender(FormTransportViews views, TransportMessage message) {
-		this.views = views;
+	public FormSender(FormTransportSubmitStatusScreen view, TransportMessage message) {
+		this.view = view;
 		this.message = message;
 	}
 	
-	private FormTransportSubmitStatusScreen createDisplay() {
 
-		FormTransportSubmitStatusScreen statusScreen = views.getSubmitStatusScreen();
-		J2MEDisplay.setView(statusScreen);
-		setObserver(statusScreen);
-		return statusScreen;
-	}
-	
 	public void setObserver(ISubmitStatusObserver o) {
 		this.observer = o;
 	}
 
 	public void sendData() {
-		FormTransportSubmitStatusScreen screen = createDisplay();
 		if (this.message == null)
 			throw new RuntimeException(
 					"null data when trying to send single data");
 					+ this.message.getCacheIdentifier());
 
 			SenderThread thread = TransportService.send(message);
-			
-			//ctsims, April 16, 2010: Race condition: The transport service
-			//needs to have a cache identifier for the message here before
-			//the display can do anything. Show the screen first, but only
-			//start polling once the cache identifier is available.
-			screen.reinit(this.message.getCacheIdentifier());
-			
+			view.reinit(message.getCacheIdentifier());
 			thread.addListener(observer);
 		}
 		catch(TransportException e) {

File j2me/javarosa-app/src/org/javarosa/demo/activity/savedformlist/JRDemoSavedFormListController.java

View file
 		if (d == view) {
 			if (c == List.SELECT_COMMAND) {
 				int index = view.getSelectedIndex();
+				
 				if (index != -1){
 					SavedFormListItem listItem  = (SavedFormListItem) formInfo.elementAt(index);
 					FormInstance formInstance = JRDemoUtil.getSavedFormInstance(listItem.getFormId(),listItem.getInstanceId());
 				}
 			} else 	if (c == view.CMD_SEND_DATA) {
 				int index = view.getSelectedIndex();
+				
 				if (index != -1){
 					SavedFormListItem listItem  = (SavedFormListItem) formInfo.elementAt(index);
 					FormInstance formInstance = JRDemoUtil.getSavedFormInstance(listItem.getFormId(),listItem.getInstanceId());

File j2me/javarosa-app/src/org/javarosa/demo/activity/savedformlist/JRDemoSavedFormListTransitions.java

View file
 	void savedFormSelected(int formId,int instanceId);
 	
 	public void sendDataFormInstance(FormInstance data);
-
-
+	
 }

File j2me/javarosa-app/src/org/javarosa/demo/activity/savedformlist/JRDemoSavedFormListView.java

View file
 	
 	public JRDemoSavedFormListView (String title, Vector formNames) {
 		super(title, List.IMPLICIT);
-	
+		
 		for (int i = 0; i < formNames.size(); i++) {
 			append( ((SavedFormListItem)formNames.elementAt(i) ).toString(), null);
 		}

File j2me/javarosa-app/src/org/javarosa/demo/applogic/JRDemoContext.java

View file
 		}
 		
 		try {
-			return SubmissionTransportHelper.createMessage(data, profile);
+			return SubmissionTransportHelper.createMessage(data, profile, false);
 		} catch (IOException e) {
 			e.printStackTrace();
 			throw new RuntimeException("Error Serializing Data to be transported");

File j2me/javarosa-app/src/org/javarosa/demo/applogic/JRDemoFormEntryState.java

View file
 			try {
 				Logger.log("formentry","writing data: " + instanceData.getName());
 				storage.write(instanceData);
-				final int record = instanceData.getID();	
+				final int record = instanceData.getID();
 
 				TransportMessage message = JRDemoContext._().buildMessage(instanceData, profile);
 				
 	
 					public void sendData(TransportMessage message) {
 						
-						FormTransportState send = new FormTransportState(message) {
+						JRDemoFormTransportState send = new JRDemoFormTransportState(message, record) {
 							public void done() {
 								JRDemoUtil.goToList(cameFromFormList);
 							}
 						};
 							
 						send.start();
-						
-						// Now that we've ensured that the data is in the transport queue, we need to remove it
-						// from storage? What normally happens if a message can't send immediately?
-						StorageManager.getStorage(FormInstance.STORAGE_KEY).remove(record);
 					}
 	
 					public void skipSend(TransportMessage message) {

File j2me/javarosa-app/src/org/javarosa/demo/applogic/JRDemoFormTransportState.java

View file
 
 import org.javarosa.core.model.SubmissionProfile;
 import org.javarosa.core.model.instance.FormInstance;
+import org.javarosa.core.services.storage.IStorageUtility;
+import org.javarosa.core.services.storage.StorageManager;
 import org.javarosa.formmanager.api.FormTransportState;
+import org.javarosa.formmanager.view.ISubmitStatusObserver;
+import org.javarosa.j2me.view.J2MEDisplay;
+import org.javarosa.services.transport.TransportMessage;
 
 /**
  * @author ctsims
  *
  */
-public abstract class JRDemoFormTransportState extends FormTransportState {
+public abstract class JRDemoFormTransportState extends FormTransportState implements ISubmitStatusObserver {
+	int formId;	
+	boolean screenDestroyed = false;
+	TransportMessage themessage;
 	
+	public JRDemoFormTransportState(FormInstance tree, SubmissionProfile profile, int formId) throws IOException {
+		this(JRDemoContext._().buildMessage(tree, profile), formId);
+	}
 	
-	public JRDemoFormTransportState(FormInstance tree, SubmissionProfile profile) throws IOException {
-		super(JRDemoContext._().buildMessage(tree, profile));
+	public JRDemoFormTransportState(TransportMessage message, int formId) {
+		super(message);
+		themessage = message; 
+		this.formId = formId;
+	}
+	
+	public void start() {
+		sender.setObserver(this);
+		sender.sendData();
+		J2MEDisplay.setView(screen);
+	}
+	
+	///OVERRIDES
+	
+	
+	/// IMPLEMENTATIONS FOR TRANSPORT STATUS
+	
+	
+	public void onChange(TransportMessage message, String remark) {
+		//Doesn't actually reflect a change in send/not sent
+		if(!screenDestroyed && screen != null) {
+			screen.onChange(message, remark);
+		}
+	}
 
+	public void onStatusChange(TransportMessage message) {
+		if(!screenDestroyed && screen != null) {
+			screen.onStatusChange(message);
+		}
+		if(message.isSuccess()) {
+				
+			//make sure we've got the right message
+			if(message.equals(themessage) || message.getCacheIdentifier().equals(themessage.getCacheIdentifier())) {
+				IStorageUtility storage = StorageManager.getStorage(FormInstance.STORAGE_KEY);
+				
+				if(storage.exists(formId)) {
+					storage.remove(formId);
+				}
+			}
+		}
+	}
+
+	//Forward along to children
+	
+	/**
+	 * Destroys the current status screen and cleans up any running
+	 * processes.
+	 */
+	public void destroy() {
+		if(!screenDestroyed && screen != null) {
+			screen.destroy();
+			screenDestroyed = true;
+		}
+	}
+
+	/**
+	 * Destroys the current status screen and cleans up any running
+	 * processes.
+	 */
+	public void receiveError(String details) {
+		if(!screenDestroyed && screen != null) {
+			screen.receiveError(details);
+		}
 	}
 
 }

File j2me/javarosa-app/src/org/javarosa/demo/applogic/JRDemoSavedFormListState.java

View file
 			//Link to the FormDef so we can find the appropriate submission profile
 			FormDefFetcher fd = new FormDefFetcher(new ModelRmsRetrievalMethod(data), JRDemoContext._().getPreloaders(), JRDemoContext._().getFuncHandlers());
 			SubmissionProfile profile = fd.getFormDef().getSubmissionProfile();
-			send = new JRDemoFormTransportState(data, profile) {
+			send = new JRDemoFormTransportState(data, profile, data.getID()) {
 
 				public void done() {
-
-					IStorageUtility forms = StorageManager.getStorage(FormInstance.STORAGE_KEY);
-					forms.remove(data);
 					new JRDemoSavedFormListState().start();				
 				}