From 4d1ddd09ae03d7a41a3dd97320ea27c909774542 Mon Sep 17 00:00:00 2001 From: Matthijs Smets Date: Tue, 20 Aug 2024 11:03:25 +0200 Subject: [PATCH] refactor: hopefully fix indentation --- src/main/java/nl/nn/testtool/filter/View.java | 226 +++++----- .../nl/nn/testtool/web/api/TestToolApi.java | 410 +++++++++--------- 2 files changed, 317 insertions(+), 319 deletions(-) diff --git a/src/main/java/nl/nn/testtool/filter/View.java b/src/main/java/nl/nn/testtool/filter/View.java index 0d04f6b8..2d2f22e2 100644 --- a/src/main/java/nl/nn/testtool/filter/View.java +++ b/src/main/java/nl/nn/testtool/filter/View.java @@ -40,114 +40,120 @@ */ @Dependent public class View implements BeanParent { - protected String name; - protected String nodeLinkStrategy; - private @Setter @Getter @Inject @Autowired LogStorage debugStorage; - private @Setter @Getter @Inject @Autowired List metadataNames; - private Map metadataFilter; - private List checkpointMatchers; - private BeanParent beanParent; - private Echo2Application echo2Application; - private @Inject @Autowired MetadataExtractor metadataExtractor; - - protected enum NodeLinkStrategy { - PATH, - CHECKPOINT_NUMBER, - NONE - } - - public void setName(String name) { - this.name = name; - } - - public String getName() { - return name; - } - - public void setNodeLinkStrategy(String nodeLinkStrategy) { - this.nodeLinkStrategy = nodeLinkStrategy; - } - - public String getNodeLinkStrategy() { - if (nodeLinkStrategy == null) { - return NodeLinkStrategy.PATH.toString(); - } - return nodeLinkStrategy; - } - - public void setMetadataFilter(Map metadataFilter) { - this.metadataFilter = metadataFilter; - } - - public Map getMetadataFilter() { - return metadataFilter; - } - - public void setCheckpointMatchers(List checkpointMatchers) { - this.checkpointMatchers = checkpointMatchers; - } - - /** - * @see nl.nn.testtool.echo2.Echo2Application#initBean() - */ - public void initBean(BeanParent beanParent) { - this.beanParent = beanParent; - this.echo2Application = Echo2Application.getEcho2Application(beanParent, this); - } - - public BeanParent getBeanParent() { - return beanParent; - } - - public Echo2Application getEcho2Application() { - return echo2Application; - } - - public String isOpenReportAllowed(Object StorageId) { - return ReportsComponent.OPEN_REPORT_ALLOWED; - } - - public boolean showCheckpoint(Report report, Checkpoint checkpoint) { - boolean match = false; - if (checkpointMatchers == null) { - match = true; - } - for (int i = 0; !match && i < checkpointMatchers.size(); i++) { - CheckpointMatcher checkpointMatcher = checkpointMatchers.get(i); - match = checkpointMatcher.match(report, checkpoint); - } - return match; - } - - public String toString() { - return getName(); - } - - public Map toHashMap(boolean isDefaultView) { - Map metadataTypes = new HashMap<>(); - for (String metadataName : getMetadataNames()) { - metadataTypes.put(metadataName, metadataExtractor.getType(metadataName)); - } - - return new HashMap() {{ - put("storageName", debugStorage.getName()); - put("defaultView", isDefaultView); - put("metadataNames", metadataNames); - put("metadataLabels", getMetadataLabels()); - put("crudStorage", debugStorage instanceof CrudStorage); - put("nodeLinkStrategy", nodeLinkStrategy); - put("name", getName()); - put("metadataTypes", metadataTypes); - }}; - } - - public List getMetadataLabels() { - List metadataLabels = new ArrayList<>(); - for (String metadataName : getMetadataNames()) { - metadataLabels.add(metadataExtractor.getLabel(metadataName)); - } - - return metadataLabels; - } - + protected String name; + protected String nodeLinkStrategy; + private @Setter + @Getter + @Inject + @Autowired LogStorage debugStorage; + private @Setter + @Getter + @Inject + @Autowired List metadataNames; + private Map metadataFilter; + private List checkpointMatchers; + private BeanParent beanParent; + private Echo2Application echo2Application; + private @Inject + @Autowired MetadataExtractor metadataExtractor; + + protected enum NodeLinkStrategy { + PATH, + CHECKPOINT_NUMBER, + NONE + } + + public void setName(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public void setNodeLinkStrategy(String nodeLinkStrategy) { + this.nodeLinkStrategy = nodeLinkStrategy; + } + + public String getNodeLinkStrategy() { + if (nodeLinkStrategy == null) { + return NodeLinkStrategy.PATH.toString(); + } + return nodeLinkStrategy; + } + + public void setMetadataFilter(Map metadataFilter) { + this.metadataFilter = metadataFilter; + } + + public Map getMetadataFilter() { + return metadataFilter; + } + + public void setCheckpointMatchers(List checkpointMatchers) { + this.checkpointMatchers = checkpointMatchers; + } + + /** + * @see nl.nn.testtool.echo2.Echo2Application#initBean() + */ + public void initBean(BeanParent beanParent) { + this.beanParent = beanParent; + this.echo2Application = Echo2Application.getEcho2Application(beanParent, this); + } + + public BeanParent getBeanParent() { + return beanParent; + } + + public Echo2Application getEcho2Application() { + return echo2Application; + } + + public String isOpenReportAllowed(Object StorageId) { + return ReportsComponent.OPEN_REPORT_ALLOWED; + } + + public boolean showCheckpoint(Report report, Checkpoint checkpoint) { + boolean match = false; + if (checkpointMatchers == null) { + match = true; + } + for (int i = 0; !match && i < checkpointMatchers.size(); i++) { + CheckpointMatcher checkpointMatcher = checkpointMatchers.get(i); + match = checkpointMatcher.match(report, checkpoint); + } + return match; + } + + public String toString() { + return getName(); + } + + public Map toMap(boolean isDefaultView) { + Map metadataTypes = new HashMap<>(); + for (String metadataName : getMetadataNames()) { + metadataTypes.put(metadataName, metadataExtractor.getType(metadataName)); + } + + return new HashMap() {{ + put("storageName", debugStorage.getName()); + put("defaultView", isDefaultView); + put("metadataNames", metadataNames); + put("metadataLabels", getMetadataLabels()); + put("crudStorage", debugStorage instanceof CrudStorage); + put("nodeLinkStrategy", nodeLinkStrategy); + put("name", getName()); + put("metadataTypes", metadataTypes); + }}; + } + + public List getMetadataLabels() { + List metadataLabels = new ArrayList<>(); + for (String metadataName : getMetadataNames()) { + metadataLabels.add(metadataExtractor.getLabel(metadataName)); + } + + return metadataLabels; + } } diff --git a/src/main/java/nl/nn/testtool/web/api/TestToolApi.java b/src/main/java/nl/nn/testtool/web/api/TestToolApi.java index 9144c5cc..0a94282e 100644 --- a/src/main/java/nl/nn/testtool/web/api/TestToolApi.java +++ b/src/main/java/nl/nn/testtool/web/api/TestToolApi.java @@ -50,214 +50,206 @@ @Path("/" + ApiServlet.LADYBUG_API_PATH + "/testtool") public class TestToolApi extends ApiBase { - private @Setter - @Inject - @Autowired TestTool testTool; - private @Setter - @Inject - @Autowired MetadataExtractor metadataExtractor; - private @Setter - @Inject - @Autowired ReportXmlTransformer reportXmlTransformer; - private @Setter - @Inject - @Autowired Views views; - private String defaultTransformation; - - @PostConstruct - public void init() { - defaultTransformation = reportXmlTransformer.getXslt(); - } - - public String getDefaultTransformation() { - return defaultTransformation; - } - - /** - * @return Response containing test tool data. - */ - @GET - @Path("/") - @Produces(MediaType.APPLICATION_JSON) - public Response getInfo() { - Map info = getTestToolInfo(); - return Response.ok(info).build(); - } - - @GET - @Path("/reset") - @Produces(MediaType.APPLICATION_JSON) - public Response resetInfo() { - testTool.reset(); - Map info = getTestToolInfo(); - return Response.ok(info).build(); - } - - public Map getTestToolInfo() { - Map map = new HashMap<>(4); - map.put("generatorEnabled", testTool.isReportGeneratorEnabled()); - map.put("estMemory", testTool.getReportsInProgressEstimatedMemoryUsage()); - map.put("regexFilter", testTool.getRegexFilter()); - map.put("reportsInProgress", testTool.getNumberOfReportsInProgress()); - map.put("stubStrategies", testTool.getStubStrategies()); - return map; - } - - /** - * Change settings of the testtool. - * - * @param map New settings that can contain (generatorEnabled, regexFilter) - * @return The response after changing the settings. - */ - @POST - @Path("/") - @Consumes(MediaType.APPLICATION_JSON) - public Response updateInfo(Map map) { - if (map.isEmpty()) { - return Response.status(Response.Status.BAD_REQUEST).entity("No settings have been provided - detailed error message - The settings that have been provided are " + map).build(); - } - - if (map.size() > 2) { - return Response.status(Response.Status.BAD_REQUEST).entity("Too many settings have been provided - detailed error message - The settings that have been provided are " + map).build(); - } - // TODO: Check user roles. - String generatorEnabled = map.remove("generatorEnabled"); - String regexFilter = map.remove("regexFilter"); - - if (StringUtils.isNotEmpty(generatorEnabled)) { - testTool.setReportGeneratorEnabled("1".equalsIgnoreCase(generatorEnabled) || "true".equalsIgnoreCase(generatorEnabled)); - testTool.sendReportGeneratorStatusUpdate(); - } - if (StringUtils.isNotEmpty(regexFilter)) - testTool.setRegexFilter(regexFilter); - - return Response.ok().build(); - } - - /** - * Returns the specified report in progress. - * - * @param index Index of the report to return - * @return Response containing the specified report, if present. - */ - @GET - @Path("/in-progress/{index}") - @Produces(MediaType.APPLICATION_JSON) - public Response getReportsInProgress(@PathParam("index") int index) { - if (index == 0) - return Response.status(Response.Status.BAD_REQUEST).entity("No progresses have been queried [" + index + "] and/or are available [" + testTool.getNumberOfReportsInProgress() + "]").build(); - - try { - Report report = testTool.getReportInProgress(index - 1); - return Response.ok(report).build(); - } catch (Exception e) { - return Response.status(Response.Status.BAD_REQUEST).entity("Could not find report in progress with index [" + index + "] - detailed error message - " + e + Arrays.toString(e.getStackTrace())).build(); - } - } - - /** - * Removes the report in progress - * - * @param index Index of the report to be deleted - * @return Response confirming the delete, if report is present - */ - @DELETE - @Path("/in-progress/{index}") - public Response deleteReportInProgress(@PathParam("index") int index) { - if (index == 0) - return Response.status(Response.Status.BAD_REQUEST).entity("No progresses have been queried [" + index + "] or are available [" + testTool.getNumberOfReportsInProgress() + "]").build(); - - try { - testTool.removeReportInProgress(index - 1); - return Response.ok().build(); - } catch (Exception e) { - return Response.status(Response.Status.BAD_REQUEST).entity("Could not find report in progress with index [" + index + "] :: " + e + Arrays.toString(e.getStackTrace())).build(); - } - } - - /** - * Gets the report in progress warning threshold time - * - * @return Response containing the time it will take before ladybug shows a warning that a report is still in progress - */ - @GET - @Path("/in-progress/threshold-time") - @Produces(MediaType.APPLICATION_JSON) - public Response getReportsInProgressWarningThreshold() { - return Response.ok(testTool.getReportsInProgressThreshold()).build(); - } - - /** - * Change the default transformation. - * - * @param map Map containing key "transformation" - * @return The response after changing the transformation. - */ - @POST - @Path("/transformation/") - @Consumes(MediaType.APPLICATION_JSON) - public Response updateReportTransformation(Map map) { - String transformation = map.get("transformation"); - if (StringUtils.isEmpty(transformation)) - return Response.status(Response.Status.BAD_REQUEST).entity("No transformation has been provided").build(); - - reportXmlTransformer.setXslt(transformation); - return Response.ok().build(); - } - - /** - * @param defaultTransformation Boolean to check if we need to use the default transformation - * @return Response containing the current default transformation of the test tool. - */ - @GET - @Path("/transformation/{defaultTransformation}") - @Produces(MediaType.APPLICATION_JSON) - public Response getReportTransformation(@PathParam("defaultTransformation") boolean defaultTransformation) { - String transformation; - - if (defaultTransformation) { - transformation = getDefaultTransformation(); - } else { - transformation = reportXmlTransformer.getXslt(); - } - - if (StringUtils.isEmpty(transformation)) - return Response.noContent().build(); - - Map map = new HashMap<>(1); - map.put("transformation", transformation); - return Response.ok(map).build(); - } - - /** - * @return The configured views - */ - @GET - @Path("/views/") - @Produces(MediaType.APPLICATION_JSON) - public Response getViewsResponse() { - // Starting from CXF 3.2.0 the setViews() will not be called by Spring when the name of this method is - // getViews() instead of getViewsResponse() (with CXF 3.1.18 this was not the case) (maybe Spring's - // ExtendedBeanInfo isn't used anymore with newer CXF versions) - Map> response = new LinkedHashMap<>(); - for (View view : views) { - response.put(view.getName(), view.toHashMap(view == views.getDefaultView())); - } - return Response.ok(response).build(); - } - - @PUT - @Path("/node-link-strategy") - @Consumes(MediaType.APPLICATION_JSON) - public Response changeNodeLinkStrategy(@QueryParam("nodeLinkStrategy") String nodeLinkStrategy, @QueryParam("viewName") String viewName) { - for (View view : views) { - if (viewName.equals(view.getName())) { - setSessionAttr(view.getName() + ".NodeLinkStrategy", nodeLinkStrategy); - break; - } - } - - return Response.ok().build(); - } + private @Setter @Inject @Autowired TestTool testTool; + private @Setter @Inject @Autowired MetadataExtractor metadataExtractor; + private @Setter @Inject @Autowired ReportXmlTransformer reportXmlTransformer; + private @Setter @Inject @Autowired Views views; + private String defaultTransformation; + + @PostConstruct + public void init() { + defaultTransformation = reportXmlTransformer.getXslt(); + } + + public String getDefaultTransformation() { + return defaultTransformation; + } + + /** + * @return Response containing test tool data. + */ + @GET + @Path("/") + @Produces(MediaType.APPLICATION_JSON) + public Response getInfo() { + Map info = getTestToolInfo(); + return Response.ok(info).build(); + } + + @GET + @Path("/reset") + @Produces(MediaType.APPLICATION_JSON) + public Response resetInfo() { + testTool.reset(); + Map info = getTestToolInfo(); + return Response.ok(info).build(); + } + + public Map getTestToolInfo() { + Map map = new HashMap<>(4); + map.put("generatorEnabled", testTool.isReportGeneratorEnabled()); + map.put("estMemory", testTool.getReportsInProgressEstimatedMemoryUsage()); + map.put("regexFilter", testTool.getRegexFilter()); + map.put("reportsInProgress", testTool.getNumberOfReportsInProgress()); + map.put("stubStrategies", testTool.getStubStrategies()); + return map; + } + + /** + * Change settings of the testtool. + * + * @param map New settings that can contain (generatorEnabled, regexFilter) + * @return The response after changing the settings. + */ + @POST + @Path("/") + @Consumes(MediaType.APPLICATION_JSON) + public Response updateInfo(Map map) { + if (map.isEmpty()) { + return Response.status(Response.Status.BAD_REQUEST).entity("No settings have been provided - detailed error message - The settings that have been provided are " + map).build(); + } + + if (map.size() > 2) { + return Response.status(Response.Status.BAD_REQUEST).entity("Too many settings have been provided - detailed error message - The settings that have been provided are " + map).build(); + } + // TODO: Check user roles. + String generatorEnabled = map.remove("generatorEnabled"); + String regexFilter = map.remove("regexFilter"); + + if (StringUtils.isNotEmpty(generatorEnabled)) { + testTool.setReportGeneratorEnabled("1".equalsIgnoreCase(generatorEnabled) || "true".equalsIgnoreCase(generatorEnabled)); + testTool.sendReportGeneratorStatusUpdate(); + } + if (StringUtils.isNotEmpty(regexFilter)) + testTool.setRegexFilter(regexFilter); + + return Response.ok().build(); + } + + /** + * Returns the specified report in progress. + * + * @param index Index of the report to return + * @return Response containing the specified report, if present. + */ + @GET + @Path("/in-progress/{index}") + @Produces(MediaType.APPLICATION_JSON) + public Response getReportsInProgress(@PathParam("index") int index) { + if (index == 0) + return Response.status(Response.Status.BAD_REQUEST).entity("No progresses have been queried [" + index + "] and/or are available [" + testTool.getNumberOfReportsInProgress() + "]").build(); + + try { + Report report = testTool.getReportInProgress(index - 1); + return Response.ok(report).build(); + } catch (Exception e) { + return Response.status(Response.Status.BAD_REQUEST).entity("Could not find report in progress with index [" + index + "] - detailed error message - " + e + Arrays.toString(e.getStackTrace())).build(); + } + } + + /** + * Removes the report in progress + * + * @param index Index of the report to be deleted + * @return Response confirming the delete, if report is present + */ + @DELETE + @Path("/in-progress/{index}") + public Response deleteReportInProgress(@PathParam("index") int index) { + if (index == 0) + return Response.status(Response.Status.BAD_REQUEST).entity("No progresses have been queried [" + index + "] or are available [" + testTool.getNumberOfReportsInProgress() + "]").build(); + + try { + testTool.removeReportInProgress(index - 1); + return Response.ok().build(); + } catch (Exception e) { + return Response.status(Response.Status.BAD_REQUEST).entity("Could not find report in progress with index [" + index + "] :: " + e + Arrays.toString(e.getStackTrace())).build(); + } + } + + /** + * Gets the report in progress warning threshold time + * + * @return Response containing the time it will take before ladybug shows a warning that a report is still in progress + */ + @GET + @Path("/in-progress/threshold-time") + @Produces(MediaType.APPLICATION_JSON) + public Response getReportsInProgressWarningThreshold() { + return Response.ok(testTool.getReportsInProgressThreshold()).build(); + } + + /** + * Change the default transformation. + * + * @param map Map containing key "transformation" + * @return The response after changing the transformation. + */ + @POST + @Path("/transformation/") + @Consumes(MediaType.APPLICATION_JSON) + public Response updateReportTransformation(Map map) { + String transformation = map.get("transformation"); + if (StringUtils.isEmpty(transformation)) + return Response.status(Response.Status.BAD_REQUEST).entity("No transformation has been provided").build(); + + reportXmlTransformer.setXslt(transformation); + return Response.ok().build(); + } + + /** + * @param defaultTransformation Boolean to check if we need to use the default transformation + * @return Response containing the current default transformation of the test tool. + */ + @GET + @Path("/transformation/{defaultTransformation}") + @Produces(MediaType.APPLICATION_JSON) + public Response getReportTransformation(@PathParam("defaultTransformation") boolean defaultTransformation) { + String transformation; + + if (defaultTransformation) { + transformation = getDefaultTransformation(); + } else { + transformation = reportXmlTransformer.getXslt(); + } + + if (StringUtils.isEmpty(transformation)) + return Response.noContent().build(); + + Map map = new HashMap<>(1); + map.put("transformation", transformation); + return Response.ok(map).build(); + } + + /** + * @return The configured views + */ + @GET + @Path("/views/") + @Produces(MediaType.APPLICATION_JSON) + public Response getViewsResponse() { + // Starting from CXF 3.2.0 the setViews() will not be called by Spring when the name of this method is + // getViews() instead of getViewsResponse() (with CXF 3.1.18 this was not the case) (maybe Spring's + // ExtendedBeanInfo isn't used anymore with newer CXF versions) + Map> response = new LinkedHashMap<>(); + for (View view : views) { + response.put(view.getName(), view.toMap(view == views.getDefaultView())); + } + return Response.ok(response).build(); + } + + @PUT + @Path("/node-link-strategy") + @Consumes(MediaType.APPLICATION_JSON) + public Response changeNodeLinkStrategy(@QueryParam("nodeLinkStrategy") String nodeLinkStrategy, @QueryParam("viewName") String viewName) { + for (View view : views) { + if (viewName.equals(view.getName())) { + setSessionAttr(view.getName() + ".NodeLinkStrategy", nodeLinkStrategy); + break; + } + } + + return Response.ok().build(); + } }