/* * (non-Javadoc) * @see org.commcare.android.tasks.templates.CommCareTask#doTaskBackground(java.lang.Object[]) */ @Override protected Boolean doTaskBackground(Void... params) { publishProgress(Localization.get("bulk.form.send.start")); //sanity check if(!(dumpDirectory.isDirectory())){ return false; } File[] files = dumpDirectory.listFiles(); int counter = 0; results = new Long [files.length]; for(int i = 0; i < files.length ; ++i ) { //Assume failure results[i] = FormUploadUtil.FAILURE; } boolean allSuccessful = true; for(int i=0;i<files.length;i++){ publishProgress(Localization.get("bulk.send.dialog.progress",new String[]{""+ (i+1)})); File f = files[i]; if(!(f.isDirectory())){ Log.e("send","Encountered non form entry in file dump folder at path: " + f.getAbsolutePath()); CommCareApplication._().reportNotificationMessage(NotificationMessageFactory.message(StockMessages.Send_MalformedFile, new String[] {null, f.getName()}, MALFORMED_FILE_CATEGORY)); continue; } try{ User user = CommCareApplication._().getSession().getLoggedInUser(); results[i] = FormUploadUtil.sendInstance(counter,f,url, user); if(results[i] == FormUploadUtil.FULL_SUCCESS){ FileUtil.deleteFile(f); } else if(results[i] == FormUploadUtil.TRANSPORT_FAILURE){ allSuccessful = false; publishProgress(Localization.get("bulk.send.transport.error")); return false; } else{ allSuccessful = false; CommCareApplication._().reportNotificationMessage(NotificationMessageFactory.message(StockMessages.Send_MalformedFile, new String[] {null, f.getName()}, MALFORMED_FILE_CATEGORY)); publishProgress(Localization.get("bulk.send.file.error", new String[] {f.getAbsolutePath()})); } counter++; } catch(SessionUnavailableException | FileNotFoundException fe){ Log.e("E", Localization.get("bulk.send.file.error", new String[] {f.getAbsolutePath()}), fe); publishProgress(Localization.get("bulk.send.file.error", new String[] {fe.getMessage()})); } } return allSuccessful; }
/* (non-Javadoc) * @see android.os.AsyncTask#onCancelled() */ @Override protected void onCancelled() { super.onCancelled(); if(this.formSubmissionListener != null) { formSubmissionListener.endSubmissionProcess(); } CommCareApplication._().reportNotificationMessage(NotificationMessageFactory.message(ProcessIssues.LoggedOut)); }