Skip to content

Commit

Permalink
refactor: add name to view for the get views endpoint (#256)
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthijsSmets authored Aug 23, 2024
1 parent 3440438 commit 664dec9
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 35 deletions.
31 changes: 31 additions & 0 deletions src/main/java/nl/nn/testtool/filter/View.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@
*/
package nl.nn.testtool.filter;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.HashMap;

import nl.nn.testtool.MetadataExtractor;
import nl.nn.testtool.storage.CrudStorage;
import org.springframework.beans.factory.annotation.Autowired;

import jakarta.enterprise.context.Dependent;
Expand All @@ -44,6 +48,7 @@ public class View implements BeanParent {
private List<CheckpointMatcher> checkpointMatchers;
private BeanParent beanParent;
private Echo2Application echo2Application;
private @Inject @Autowired MetadataExtractor metadataExtractor;

protected enum NodeLinkStrategy {
PATH,
Expand Down Expand Up @@ -118,4 +123,30 @@ public String toString() {
return getName();
}

public Map<String, Object> toMap(boolean isDefaultView) {
Map<String, String> metadataTypes = new HashMap<>();
for (String metadataName : getMetadataNames()) {
metadataTypes.put(metadataName, metadataExtractor.getType(metadataName));
}

return new HashMap<String, Object>() {{
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<String> getMetadataLabels() {
List<String> metadataLabels = new ArrayList<>();
for (String metadataName : getMetadataNames()) {
metadataLabels.add(metadataExtractor.getLabel(metadataName));
}

return metadataLabels;
}
}
49 changes: 14 additions & 35 deletions src/main/java/nl/nn/testtool/web/api/TestToolApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -167,17 +167,17 @@ public Response deleteReportInProgress(@PathParam("index") int index) {
}
}

/**
* 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();
}
/**
* 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.
Expand Down Expand Up @@ -231,39 +231,18 @@ 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<String, Map<String, Object>> response = new LinkedHashMap<String, Map<String, Object>>();
Map<String, Map<String, Object>> response = new LinkedHashMap<>();
for (View view : views) {
Map<String, Object> map = new HashMap<String, Object>();
map.put("storageName", view.getDebugStorage().getName());
map.put("defaultView", view == views.getDefaultView());
map.put("metadataNames", view.getMetadataNames());
map.put("metadataLabels", getMetadataLabels(view.getMetadataNames()));
map.put("crudStorage", view.getDebugStorage() instanceof CrudStorage);
map.put("nodeLinkStrategy", view.getNodeLinkStrategy());
Map<String, String> metadataTypes = new HashMap<>();
for(String metadataName : view.getMetadataNames()) {
metadataTypes.put(metadataName, metadataExtractor.getType(metadataName));
}
map.put("metadataTypes", metadataTypes);
response.put(view.getName(), map);
response.put(view.getName(), view.toMap(view == views.getDefaultView()));
}
return Response.ok(response).build();
}

public List<String> getMetadataLabels(List<String> metadataNames) {
List<String> metadataLabels = new ArrayList<>();
for (String metadataName : metadataNames) {
metadataLabels.add(metadataExtractor.getLabel(metadataName));
}

return metadataLabels;
}

@PUT
@Path("/node-link-strategy")
@Consumes(MediaType.APPLICATION_JSON)
public Response changeNodeLinkStrategy(@QueryParam("nodeLinkStrategy") String nodeLinkStrategy, @QueryParam("viewName") String viewName) {
for (View view: views) {
for (View view : views) {
if (viewName.equals(view.getName())) {
setSessionAttr(view.getName() + ".NodeLinkStrategy", nodeLinkStrategy);
break;
Expand Down

0 comments on commit 664dec9

Please sign in to comment.