show better error message, when no data points are found
This commit is contained in:
@@ -4,6 +4,10 @@ public class InternalPlottingException extends Exception {
|
|||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
public InternalPlottingException() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
public InternalPlottingException(final String message, final Throwable cause) {
|
public InternalPlottingException(final String message, final Throwable cause) {
|
||||||
super(message, cause);
|
super(message, cause);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package org.lucares.recommind.logs;
|
||||||
|
|
||||||
|
public class NoDataPointsException extends InternalPlottingException {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1054594230615520105L;
|
||||||
|
|
||||||
|
public NoDataPointsException() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,7 +10,9 @@ import java.nio.file.Files;
|
|||||||
import java.nio.file.LinkOption;
|
import java.nio.file.LinkOption;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
import java.time.Instant;
|
||||||
import java.time.OffsetDateTime;
|
import java.time.OffsetDateTime;
|
||||||
|
import java.time.ZoneOffset;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.time.temporal.ChronoUnit;
|
import java.time.temporal.ChronoUnit;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -74,8 +76,8 @@ public class Plotter {
|
|||||||
|
|
||||||
final Result result = db.get(query, groupBy);
|
final Result result = db.get(query, groupBy);
|
||||||
|
|
||||||
OffsetDateTime maxDate = OffsetDateTime.MIN;
|
OffsetDateTime maxDate = OffsetDateTime.ofInstant(Instant.ofEpochMilli(Long.MIN_VALUE), ZoneOffset.UTC);
|
||||||
OffsetDateTime minDate = OffsetDateTime.MAX;
|
OffsetDateTime minDate = OffsetDateTime.ofInstant(Instant.ofEpochMilli(Long.MAX_VALUE), ZoneOffset.UTC);
|
||||||
|
|
||||||
for (final GroupResult groupResult : result.getGroups()) {
|
for (final GroupResult groupResult : result.getGroups()) {
|
||||||
|
|
||||||
@@ -94,6 +96,10 @@ public class Plotter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (dataSeries.isEmpty()) {
|
||||||
|
throw new NoDataPointsException();
|
||||||
|
}
|
||||||
|
|
||||||
sortAndLimit(dataSeries, plotSettings);
|
sortAndLimit(dataSeries, plotSettings);
|
||||||
|
|
||||||
final File outputFile = File.createTempFile("out", ".png", outputDir.toFile());
|
final File outputFile = File.createTempFile("out", ".png", outputDir.toFile());
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import org.lucares.pdbui.domain.PlotRequest;
|
|||||||
import org.lucares.pdbui.domain.PlotResponse;
|
import org.lucares.pdbui.domain.PlotResponse;
|
||||||
import org.lucares.performance.db.CollectionUtils;
|
import org.lucares.performance.db.CollectionUtils;
|
||||||
import org.lucares.recommind.logs.InternalPlottingException;
|
import org.lucares.recommind.logs.InternalPlottingException;
|
||||||
|
import org.lucares.recommind.logs.NoDataPointsException;
|
||||||
import org.lucares.recommind.logs.Plotter;
|
import org.lucares.recommind.logs.Plotter;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@@ -53,13 +54,17 @@ public class PdbController implements HardcodedValues, CollectionUtils {
|
|||||||
|
|
||||||
final PlotSettings plotSettings = PlotSettingsTransformer.toSettings(request);
|
final PlotSettings plotSettings = PlotSettingsTransformer.toSettings(request);
|
||||||
|
|
||||||
final File image = plotter.plot(plotSettings);
|
try {
|
||||||
|
final File image = plotter.plot(plotSettings);
|
||||||
|
|
||||||
final Path relativeImagePath = plotter.getOutputDir().relativize(image.toPath());
|
final Path relativeImagePath = plotter.getOutputDir().relativize(image.toPath());
|
||||||
final String relativeImgUrl = relativeImagePath.toString().replace('\\', '/');
|
final String relativeImgUrl = relativeImagePath.toString().replace('\\', '/');
|
||||||
final String imageUrl = WEB_IMAGE_OUTPUT_PATH + "/" + relativeImgUrl;
|
final String imageUrl = WEB_IMAGE_OUTPUT_PATH + "/" + relativeImgUrl;
|
||||||
LOGGER.trace("image url: {}", imageUrl);
|
LOGGER.trace("image url: {}", imageUrl);
|
||||||
return new PlotResponse(imageUrl);
|
return new PlotResponse(imageUrl);
|
||||||
|
} catch (final NoDataPointsException e) {
|
||||||
|
throw new NotFoundException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(path = "/autocomplete", //
|
@RequestMapping(path = "/autocomplete", //
|
||||||
|
|||||||
@@ -99,7 +99,13 @@ function plot(event){
|
|||||||
$('#result-view').html('<img src=\"'+response.imageUrls+'" />');
|
$('#result-view').html('<img src=\"'+response.imageUrls+'" />');
|
||||||
};
|
};
|
||||||
var error = function(e) {
|
var error = function(e) {
|
||||||
$('#result-view').text("FAILED: " + JSON.stringify(e));
|
|
||||||
|
if (e.status == 404){
|
||||||
|
$('#result-view').text("No data points found.");
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
$('#result-view').text("FAILED: " + JSON.stringify(e));
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user