Skip to content

Commit

Permalink
Merge pull request #2043 from siemens/fix/restEndpointComponentNameSe…
Browse files Browse the repository at this point in the history
…arch

fix(Rest): Allowing search for components without encoding

Reviewed by: [email protected]
Tested by:  [email protected]
  • Loading branch information
ag4ums authored Jul 19, 2023
2 parents 08abbeb + c0df933 commit 882466d
Showing 1 changed file with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,11 @@ public ResponseEntity<CollectionModel> getComponents(Pageable pageable,
User sw360User = restControllerHelper.getSw360UserFromAuthentication();

List<Component> allComponents = new ArrayList<>();
String queryString = request.getQueryString();
Map<String, String> params = parseQueryString(queryString);

if (name != null && !name.isEmpty()) {
allComponents.addAll(componentService.searchComponentByName(name));
allComponents.addAll(componentService.searchComponentByName(params.get("name")));
} else {
allComponents.addAll(componentService.getComponentsForUser(sw360User));
}
Expand Down Expand Up @@ -161,6 +164,24 @@ public ResponseEntity<CollectionModel> getComponents(Pageable pageable,
return new ResponseEntity<>(resources, HttpStatus.OK);
}

private Map<String, String> parseQueryString(String queryString) {
Map<String, String> parameters = new HashMap<>();

if (queryString != null && !queryString.isEmpty()) {
String[] params = queryString.split("&");
for (String param : params) {
String[] keyValue = param.split("=");
if (keyValue.length == 2) {
String key = keyValue[0];
String value = keyValue[1];
parameters.put(key, value);
}
}
}

return parameters;
}

@RequestMapping(value = COMPONENTS_URL + "/usedBy" + "/{id}", method = RequestMethod.GET)
public ResponseEntity<CollectionModel<EntityModel>> getUsedByResourceDetails(@PathVariable("id") String id)
throws TException {
Expand Down

0 comments on commit 882466d

Please sign in to comment.