use of org.opendatakit.briefcase.model.DocumentDescription in project briefcase by opendatakit.
the class ServerFetcher method fetchFormList.
public static final AggregateUtils.DocumentFetchResult fetchFormList(ServerConnectionInfo serverInfo, boolean alwaysResetCredentials, TerminationFuture terminationFuture) throws XmlDocumentFetchException {
String urlString = serverInfo.getUrl();
if (urlString.endsWith("/")) {
urlString = urlString + "formList";
} else {
urlString = urlString + "/formList";
}
DocumentDescription formListDescription = new DocumentDescription("Unable to fetch formList: ", "Unable to fetch formList.", "form list", terminationFuture);
AggregateUtils.DocumentFetchResult result = AggregateUtils.getXmlDocument(urlString, serverInfo, alwaysResetCredentials, formListDescription, null);
return result;
}
use of org.opendatakit.briefcase.model.DocumentDescription in project briefcase by opendatakit.
the class ServerFetcher method downloadManifestAndMediaFiles.
private String downloadManifestAndMediaFiles(File mediaDir, FormStatus fs) {
RemoteFormDefinition fd = getRemoteFormDefinition(fs);
if (fd.getManifestUrl() == null)
return null;
fs.setStatusString("Fetching form manifest", true);
EventBus.publish(new FormStatusEvent(fs));
List<MediaFile> files = new ArrayList<>();
AggregateUtils.DocumentFetchResult result;
try {
DocumentDescription formManifestDescription = new DocumentDescription("Fetch of manifest failed. Detailed reason: ", "Fetch of manifest failed ", "form manifest", terminationFuture);
result = AggregateUtils.getXmlDocument(fd.getManifestUrl(), serverInfo, false, formManifestDescription, null);
} catch (XmlDocumentFetchException e) {
return e.getMessage();
}
try {
files = XmlManipulationUtils.parseFormManifestResponse(result.isOpenRosaResponse, result.doc);
} catch (ParsingException e) {
return e.getMessage();
}
// OK we now have the full set of files to download...
log.info("Downloading " + files.size() + " media files.");
int mCount = 0;
if (files.size() > 0) {
for (MediaFile m : files) {
++mCount;
fs.setStatusString(String.format(" (getting %1$d of %2$d media files)", mCount, files.size()), true);
EventBus.publish(new FormStatusEvent(fs));
try {
downloadMediaFileIfChanged(mediaDir, m, fs);
} catch (Exception e) {
return e.getLocalizedMessage();
}
}
}
return null;
}
use of org.opendatakit.briefcase.model.DocumentDescription in project briefcase by opendatakit.
the class ServerUploader method subtractServerInstances.
// remove any instances already completed on server
private void subtractServerInstances(FormStatus fs, DatabaseUtils formDatabase, Set<File> instancesToUpload) {
/*
* The /view/submissionList interface returns the list of COMPLETED submissions
* on the server. Fetch this list and filter out the locally-held submissions
* with the same instanceIds. We know the server is already content with what
* it has, so we don't need to send any of these to the server, as that POST
* request will be treated as a no-op.
*/
String baseUrl = serverInfo.getUrl() + "/view/submissionList";
String oldWebsafeCursorString = "not-empty";
String websafeCursorString = "";
for (; !oldWebsafeCursorString.equals(websafeCursorString); ) {
if (isCancelled()) {
fs.setStatusString("aborting retrieval of instanceIds of submissions on server...", true);
EventBus.publish(new FormStatusEvent(fs));
return;
}
fs.setStatusString("retrieving next chunk of instanceIds from server...", true);
EventBus.publish(new FormStatusEvent(fs));
Map<String, String> params = new HashMap<>();
params.put("numEntries", Integer.toString(MAX_ENTRIES));
params.put("formId", fs.getFormDefinition().getFormId());
params.put("cursor", websafeCursorString);
String fullUrl = WebUtils.createLinkWithProperties(baseUrl, params);
// remember what we had...
oldWebsafeCursorString = websafeCursorString;
AggregateUtils.DocumentFetchResult result;
try {
DocumentDescription submissionChunkDescription = new DocumentDescription("Fetch of instanceIds (submission download chunk) failed. Detailed error: ", "Fetch of instanceIds (submission download chunk) failed.", "submission download chunk", terminationFuture);
result = AggregateUtils.getXmlDocument(fullUrl, serverInfo, false, submissionChunkDescription, null);
} catch (XmlDocumentFetchException e) {
fs.setStatusString("Not all submissions retrieved: Error fetching list of instanceIds: " + e.getMessage(), false);
EventBus.publish(new FormStatusEvent(fs));
return;
}
SubmissionChunk chunk;
try {
chunk = XmlManipulationUtils.parseSubmissionDownloadListResponse(result.doc);
} catch (ParsingException e) {
fs.setStatusString("Not all instanceIds retrieved: Error parsing the submission download chunk: " + e.getMessage(), false);
EventBus.publish(new FormStatusEvent(fs));
return;
}
websafeCursorString = chunk.websafeCursorString;
for (String uri : chunk.uriList) {
File f = formDatabase.hasRecordedInstance(uri);
if (f != null) {
instancesToUpload.remove(f);
}
}
}
}
use of org.opendatakit.briefcase.model.DocumentDescription in project briefcase by opendatakit.
the class ServerUploader method uploadForm.
public boolean uploadForm(FormStatus formToTransfer, File briefcaseFormDefFile, File briefcaseFormMediaDir) {
// very similar to upload submissions...
URI u;
try {
u = AggregateUtils.testServerConnectionWithHeadRequest(serverInfo, "formUpload");
} catch (TransmissionException e) {
formToTransfer.setStatusString(e.getMessage(), false);
EventBus.publish(new FormStatusEvent(formToTransfer));
return false;
}
// try to send form...
if (!briefcaseFormDefFile.exists()) {
String msg = "Form definition file not found: " + briefcaseFormDefFile.getAbsolutePath();
formToTransfer.setStatusString(msg, false);
EventBus.publish(new FormStatusEvent(formToTransfer));
return false;
}
// find all files in parent directory
File[] allFiles = null;
if (briefcaseFormMediaDir != null) {
allFiles = briefcaseFormMediaDir.listFiles();
}
// clean up the list, removing anything that is suspicious
// or that we won't attempt to upload. For OpenRosa servers,
// we'll upload just about everything...
List<File> files = new ArrayList<>();
if (allFiles != null) {
for (File f : allFiles) {
String fileName = f.getName();
if (fileName.startsWith(".")) {
// potential Apple file attributes file -- ignore it
continue;
}
files.add(f);
}
}
DocumentDescription formDefinitionUploadDescription = new DocumentDescription("Form definition upload failed. Detailed error: ", "Form definition upload failed.", "form definition", terminationFuture);
return AggregateUtils.uploadFilesToServer(serverInfo, u, "form_def_file", briefcaseFormDefFile, files, formDefinitionUploadDescription, null, terminationFuture, formToTransfer);
}
use of org.opendatakit.briefcase.model.DocumentDescription in project briefcase by opendatakit.
the class ServerUploader method uploadSubmission.
private final boolean uploadSubmission(DatabaseUtils formDatabase, FormStatus formToTransfer, URI u, int count, int totalCount, File instanceDirectory) {
// We have the actual server URL in u, possibly redirected to https.
// We know we are talking to the server because the head request
// succeeded and had a Location header field.
// try to send instance
// get instance file
File file = new File(instanceDirectory, "submission.xml");
String submissionFile = file.getName();
if (!file.exists()) {
String msg = "Submission file not found: " + file.getAbsolutePath();
formToTransfer.setStatusString(msg, false);
EventBus.publish(new FormStatusEvent(formToTransfer));
return false;
}
// find all files in parent directory
File[] allFiles = instanceDirectory.listFiles();
// clean up the list, removing anything that is suspicious
// or that we won't attempt to upload. For OpenRosa servers,
// we'll upload just about everything...
List<File> files = new ArrayList<>();
for (File f : allFiles) {
String fileName = f.getName();
if (fileName.startsWith(".")) {
// potential Apple file attributes file -- ignore it
continue;
}
if (fileName.equals(submissionFile)) {
// this is always added
continue;
} else {
files.add(f);
}
}
SubmissionResponseAction action = new SubmissionResponseAction(file);
if (isCancelled()) {
formToTransfer.setStatusString("aborting upload of submission...", true);
EventBus.publish(new FormStatusEvent(formToTransfer));
return false;
}
DocumentDescription submissionUploadDescription = new DocumentDescription("Submission upload failed. Detailed error: ", "Submission upload failed.", "submission (" + count + " of " + totalCount + ")", terminationFuture);
boolean outcome = AggregateUtils.uploadFilesToServer(serverInfo, u, "xml_submission_file", file, files, submissionUploadDescription, action, terminationFuture, formToTransfer);
// and try to rename the instance directory to be its instanceID
action.afterUpload(formToTransfer);
return outcome;
}
Aggregations