limit the number of plots
This commit is contained in:
@@ -7,6 +7,7 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.lucares.ludb.Proposal;
|
||||
import org.lucares.pdb.plot.api.PlotSettings;
|
||||
import org.lucares.pdbui.domain.AutocompleteProposal;
|
||||
import org.lucares.pdbui.domain.AutocompleteProposalByValue;
|
||||
import org.lucares.pdbui.domain.AutocompleteResponse;
|
||||
@@ -46,12 +47,10 @@ public class PdbController implements HardcodedValues, CollectionUtils {
|
||||
PlotResponse createPlot(@RequestBody final PlotRequest request) {
|
||||
|
||||
try {
|
||||
final String query = request.getQuery();
|
||||
final int height = request.getHeight();
|
||||
final int width = request.getWidth();
|
||||
|
||||
System.out.println(query);
|
||||
final File image = plotter.plot(query, height, width, request.getGroupBy());
|
||||
final PlotSettings plotSettings = PlotSettingsTransformer.toSettings(request);
|
||||
|
||||
final File image = plotter.plot(plotSettings);
|
||||
|
||||
final Path relativeImagePath = plotter.getOutputDir().relativize(image.toPath());
|
||||
return new PlotResponse(WEB_IMAGE_OUTPUT_PATH + "/" + relativeImagePath.toString());
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package org.lucares.pdbui;
|
||||
|
||||
import org.lucares.pdb.plot.api.Limit;
|
||||
import org.lucares.pdb.plot.api.PlotSettings;
|
||||
import org.lucares.pdbui.domain.LimitBy;
|
||||
import org.lucares.pdbui.domain.PlotRequest;
|
||||
|
||||
class PlotSettingsTransformer {
|
||||
static PlotSettings toSettings(final PlotRequest request) {
|
||||
|
||||
final PlotSettings result = new PlotSettings();
|
||||
|
||||
result.setQuery(request.getQuery());
|
||||
result.setGroupBy(request.getGroupBy());
|
||||
result.setHeight(request.getHeight());
|
||||
result.setWidth(request.getWidth());
|
||||
result.setLimit(request.getLimit());
|
||||
result.setLimitBy(toLimit(request.getLimitBy()));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static Limit toLimit(final LimitBy limitBy) {
|
||||
switch (limitBy) {
|
||||
case NO_LIMIT:
|
||||
return Limit.NO_LIMIT;
|
||||
case FEWEST_VALUES:
|
||||
return Limit.FEWEST_VALUES;
|
||||
case MOST_VALUES:
|
||||
return Limit.MOST_VALUES;
|
||||
default:
|
||||
throw new IllegalStateException("unhandled enum: " + limitBy);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package org.lucares.pdbui.domain;
|
||||
|
||||
public enum LimitBy {
|
||||
NO_LIMIT, MOST_VALUES, FEWEST_VALUES
|
||||
}
|
||||
@@ -9,6 +9,10 @@ public class PlotRequest {
|
||||
|
||||
private String groupBy;
|
||||
|
||||
private LimitBy limitBy = LimitBy.NO_LIMIT;
|
||||
|
||||
private int limit = Integer.MAX_VALUE;
|
||||
|
||||
public String getQuery() {
|
||||
return query;
|
||||
}
|
||||
@@ -45,4 +49,20 @@ public class PlotRequest {
|
||||
public void setGroupBy(final String groupBy) {
|
||||
this.groupBy = groupBy;
|
||||
}
|
||||
|
||||
public LimitBy getLimitBy() {
|
||||
return limitBy;
|
||||
}
|
||||
|
||||
public void setLimitBy(final LimitBy limitBy) {
|
||||
this.limitBy = limitBy;
|
||||
}
|
||||
|
||||
public int getLimit() {
|
||||
return limit;
|
||||
}
|
||||
|
||||
public void setLimit(final int limit) {
|
||||
this.limit = limit;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user