Skip to content
Snippets Groups Projects
Commit f3f72f40 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

api allows to get reactions by participanet element id

parent ca45d7f1
No related branches found
No related tags found
1 merge request!8Resolve "missing methods for JS app API"
...@@ -48,8 +48,9 @@ public class ProjectController extends BaseController { ...@@ -48,8 +48,9 @@ public class ProjectController extends BaseController {
@RequestMapping(value = "/getReactions", method = { RequestMethod.GET, RequestMethod.POST }, produces = { MediaType.APPLICATION_JSON_VALUE }) @RequestMapping(value = "/getReactions", method = { RequestMethod.GET, RequestMethod.POST }, produces = { MediaType.APPLICATION_JSON_VALUE })
public List<Map<String, Object>> getReactions(@RequestParam(value = "projectId") String projectId, @RequestParam(value = "id", defaultValue = "") String id, public List<Map<String, Object>> getReactions(@RequestParam(value = "projectId") String projectId, @RequestParam(value = "id", defaultValue = "") String id,
@RequestParam(value = "columns", defaultValue = "") String columns, @RequestParam(value = "token") String token) throws SecurityException { @RequestParam(value = "columns", defaultValue = "") String columns, @RequestParam(value = "token") String token,
return projectController.getReactions(projectId, id, columns, token); @RequestParam(value = "participantId", defaultValue = "") String participantId) throws SecurityException {
return projectController.getReactions(projectId, id, columns, token, participantId);
} }
@RequestMapping(value = "/getClosestElementsByCoordinates", method = { RequestMethod.GET, RequestMethod.POST }, @RequestMapping(value = "/getClosestElementsByCoordinates", method = { RequestMethod.GET, RequestMethod.POST },
...@@ -123,8 +124,8 @@ public class ProjectController extends BaseController { ...@@ -123,8 +124,8 @@ public class ProjectController extends BaseController {
@RequestParam(value = "modelId") String modelId, @RequestParam(value = "handlerClass") String handlerClass, @RequestParam(value = "modelId") String modelId, @RequestParam(value = "handlerClass") String handlerClass,
@RequestParam(value = "backgroundOverlayId", defaultValue = "") String backgroundOverlayId, @RequestParam(value = "backgroundOverlayId", defaultValue = "") String backgroundOverlayId,
@RequestParam(value = "overlayIds", defaultValue = "") String overlayIds, @RequestParam(value = "zoomLevel", defaultValue = "") String zoomLevel, @RequestParam(value = "overlayIds", defaultValue = "") String overlayIds, @RequestParam(value = "zoomLevel", defaultValue = "") String zoomLevel,
@RequestParam(value = "polygonString") String polygonString) throws SecurityException, QueryException, IOException, @RequestParam(value = "polygonString") String polygonString) throws SecurityException, QueryException, IOException, InvalidColorSchemaException,
InvalidColorSchemaException, CommandExecutionException, ConverterException, InconsistentModelException { CommandExecutionException, ConverterException, InconsistentModelException {
FileEntry file = projectController.getModelAsModelFile(token, projectId, modelId, handlerClass, backgroundOverlayId, overlayIds, zoomLevel, polygonString); FileEntry file = projectController.getModelAsModelFile(token, projectId, modelId, handlerClass, backgroundOverlayId, overlayIds, zoomLevel, polygonString);
MediaType type = MediaType.APPLICATION_OCTET_STREAM; MediaType type = MediaType.APPLICATION_OCTET_STREAM;
......
...@@ -284,7 +284,8 @@ public class ProjectRestImpl { ...@@ -284,7 +284,8 @@ public class ProjectRestImpl {
return result; return result;
}; };
public List<Map<String, Object>> getReactions(String projectId, String id, String columns, String token) throws UserAccessException, SecurityException { public List<Map<String, Object>> getReactions(String projectId, String id, String columns, String token, String participantElementId)
throws UserAccessException, SecurityException {
Model model = modelService.getLastModelByProjectId(projectId, userService.getToken(token)); Model model = modelService.getLastModelByProjectId(projectId, userService.getToken(token));
Set<Integer> ids = new HashSet<>(); Set<Integer> ids = new HashSet<>();
if (!id.equals("")) { if (!id.equals("")) {
...@@ -292,6 +293,12 @@ public class ProjectRestImpl { ...@@ -292,6 +293,12 @@ public class ProjectRestImpl {
ids.add(Integer.valueOf(str)); ids.add(Integer.valueOf(str));
} }
} }
Set<Element> elementSet = new HashSet<>();
if (!participantElementId.equals("")) {
for (String str : participantElementId.split(",")) {
elementSet.add(model.getElementByDbId(Integer.valueOf(str)));
}
}
Set<String> columnsSet = createReactionColumnSet(columns); Set<String> columnsSet = createReactionColumnSet(columns);
List<Map<String, Object>> result = new ArrayList<>(); List<Map<String, Object>> result = new ArrayList<>();
...@@ -302,7 +309,9 @@ public class ProjectRestImpl { ...@@ -302,7 +309,9 @@ public class ProjectRestImpl {
for (Model model2 : models) { for (Model model2 : models) {
for (Reaction reaction : model2.getReactions()) { for (Reaction reaction : model2.getReactions()) {
if (ids.size() == 0 || ids.contains(reaction.getId())) { if (ids.size() == 0 || ids.contains(reaction.getId())) {
result.add(preparedReaction(reaction, columnsSet)); if (elementSet.size() == 0 || reactionContainsElement(reaction, elementSet)) {
result.add(preparedReaction(reaction, columnsSet));
}
} }
} }
} }
...@@ -310,6 +319,15 @@ public class ProjectRestImpl { ...@@ -310,6 +319,15 @@ public class ProjectRestImpl {
return result; return result;
} }
private boolean reactionContainsElement(Reaction reaction, Set<Element> elementSet) {
for (Element element : elementSet) {
if (reaction.containsElement(element)) {
return true;
}
}
return false;
}
private Map<String, Object> preparedReaction(Reaction reaction, Set<String> columnsSet) { private Map<String, Object> preparedReaction(Reaction reaction, Set<String> columnsSet) {
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
for (String string : columnsSet) { for (String string : columnsSet) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment