mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-19 10:39:59 +00:00
Deliver error to client if no importer succeeded to process the file
This commit is contained in:
1 parent
86e6cf5205
commit
a62c4f8177
3 files changed
+29
-11
No files matched your search
+8
-6
@@ -16,7 +16,6 @@ public class SensorDataImportResultsDialog {
|
||||
List<ErrorMessage> errorMessages = response.getErrors();
|
||||
SafeHtmlBuilder shb = new SafeHtmlBuilder();
|
||||
shb.appendHtmlConstant("<div style='margin:40px;'>");
|
||||
|
||||
if (response.didSucceedImportingAnyFile()) {
|
||||
shb.appendHtmlConstant("<p>Succesful uploads</p>");
|
||||
shb.appendHtmlConstant("<ul>");
|
||||
@@ -27,17 +26,20 @@ public class SensorDataImportResultsDialog {
|
||||
} else {
|
||||
shb.appendHtmlConstant("<p>No succesful upload</p>");
|
||||
}
|
||||
|
||||
if (response.hasErrors()) {
|
||||
shb.appendHtmlConstant("<p>Error messages</p>");
|
||||
for (ErrorMessage errorMsg : errorMessages) {
|
||||
shb.appendHtmlConstant("<div style='font-weight:bold;'>").appendEscaped(errorMsg.getMessage())
|
||||
.appendHtmlConstant("</div>");
|
||||
shb.appendHtmlConstant("<ul>");
|
||||
shb.appendHtmlConstant(" <li>ServerLog UUID: ").appendEscaped(errorMsg.getExUUID())
|
||||
.appendHtmlConstant("</li>");
|
||||
shb.appendHtmlConstant(" <li>Exception Classname: ").appendEscaped(errorMsg.getClassName())
|
||||
.appendHtmlConstant("</li>");
|
||||
if (!isNullOrEmpty(errorMsg.getExUUID())) {
|
||||
shb.appendHtmlConstant(" <li>ServerLog UUID: ").appendEscaped(errorMsg.getExUUID())
|
||||
.appendHtmlConstant("</li>");
|
||||
}
|
||||
if (!isNullOrEmpty(errorMsg.getClassName())) {
|
||||
shb.appendHtmlConstant(" <li>Exception Classname: ").appendEscaped(errorMsg.getClassName())
|
||||
.appendHtmlConstant("</li>");
|
||||
}
|
||||
if (!isNullOrEmpty(errorMsg.getFilename())) {
|
||||
shb.appendHtmlConstant(" <li>Filename: ").appendEscaped(errorMsg.getFilename())
|
||||
.appendHtmlConstant("</li>");
|
||||
|
||||
+7
@@ -69,4 +69,11 @@ public class JsonHolder {
|
||||
resp.setContentType("text/html");
|
||||
jsonResponseObj.writeJSONString(resp.getWriter());
|
||||
}
|
||||
|
||||
public void noImporterSucceeded(String filename) {
|
||||
JSONObject jsonExceptionObj = new JSONObject();
|
||||
jsonErrorObj.add(jsonExceptionObj);
|
||||
jsonExceptionObj.put("filename", filename);
|
||||
jsonExceptionObj.put("message", "No importer succeeded to process file");
|
||||
}
|
||||
}
|
||||
+14
-5
@@ -7,6 +7,7 @@ import java.util.Collection;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -96,20 +97,25 @@ public class TrackFilesImportServlet extends AbstractFileUploadServlet {
|
||||
importersToTry.addAll(getGPSFixImporters(null));
|
||||
logger.log(Level.INFO, "System knows " + importersToTry.size() + " importers: "
|
||||
+ importersToTry.stream().map(i -> i.getType()).collect(Collectors.joining(", ")));
|
||||
|
||||
AtomicBoolean succeeded = new AtomicBoolean(false);
|
||||
parsersLoop: for (GPSFixImporter importer : importersToTry) {
|
||||
boolean succeeded = false;
|
||||
|
||||
logger.log(Level.INFO, "Trying to import file " + fileName + " with importer " + importer.getType());
|
||||
try (BufferedInputStream in = new BufferedInputStream(fileItem.getInputStream())) {
|
||||
try {
|
||||
succeeded = importer.importFixes(in, new Callback() {
|
||||
boolean ok = importer.importFixes(in, new Callback() {
|
||||
@Override
|
||||
public void addFix(GPSFix fix, TrackFileImportDeviceIdentifier device) {
|
||||
storeFix(fix, device);
|
||||
jsonResult.addDeviceIndentifier(device);
|
||||
}
|
||||
}, true, fileName);
|
||||
|
||||
if (ok) {
|
||||
succeeded.set(ok);
|
||||
} else {
|
||||
logger.log(Level.FINE,
|
||||
"Importer " + importer.getType() + " did not succesfully import fixes");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.log(Level.INFO, "Failed with " + e.getClass().getSimpleName()
|
||||
+ " while importing file using " + importer.getType());
|
||||
@@ -118,11 +124,14 @@ public class TrackFilesImportServlet extends AbstractFileUploadServlet {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (succeeded) {
|
||||
if (succeeded.get()) {
|
||||
logger.log(Level.INFO, "Successfully imported file " + fileName + " using " + importer.getType());
|
||||
break parsersLoop;
|
||||
}
|
||||
}
|
||||
if (!succeeded.get()) {
|
||||
jsonResult.noImporterSucceeded(fileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user