Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(release): revert external id query parsing #2265

Merged
merged 1 commit into from
Jan 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
import org.eclipse.sw360.rest.resourceserver.vendor.Sw360VendorService;
import org.eclipse.sw360.rest.resourceserver.licenseinfo.Sw360LicenseInfoService;
import org.eclipse.sw360.rest.resourceserver.vulnerability.Sw360VulnerabilityService;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.data.rest.webmvc.BasePathAwareController;
Expand All @@ -104,6 +105,7 @@
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.multipart.MultipartFile;
Expand Down Expand Up @@ -360,25 +362,58 @@ public ResponseEntity<CollectionModel<EntityModel>> getUsedByResourceDetails(@Pa
@Operation(
summary = "Get releases by external IDs.",
description = "Get releases where provided external IDs match.",
tags = {"Releases"}
tags = {"Releases"},
parameters = {
@Parameter(
description = "The external IDs of the releases to filter.",
example = "{\n" +
"\"mainline-id-component\": \"1432\",\n" +
"\"mainline-id-component\": \"4876\"\n" +
"}",
in = ParameterIn.QUERY,
name = "externalIds",
explode = Explode.TRUE,
schema = @Schema(implementation = LinkedMultiValueMap.class)
)
}
)
@GetMapping(value = RELEASES_URL + "/searchByExternalIds")
public ResponseEntity<Release> searchByExternalIds(
@Parameter(
description = "The external IDs of the releases to filter.",
example = "{\n" +
"\"mainline-id-component\": \"1432\",\n" +
"\"mainline-id-component\": \"4876\"\n" +
"}",
in = ParameterIn.QUERY,
name = "externalIds",
explode = Explode.TRUE
)
@RequestParam LinkedMultiValueMap<String, String> externalIdsMultiMap
HttpServletRequest request
) throws TException {
String queryString = request.getQueryString();
MultiValueMap<String, String> externalIdsMultiMap = parseQueryString(queryString);
return restControllerHelper.searchByExternalIds(externalIdsMultiMap, releaseService, null);
}

/**
* Bypass spring query parser to distinguish between URL encoded and
* un-encoded ids.
*
* @param queryString Query from request
* @return Query parsed as a value map.
*/
private @NotNull MultiValueMap<String, String> parseQueryString(String queryString) {
MultiValueMap<String, String> parameters = new LinkedMultiValueMap<>();

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

return parameters;
}

@PreAuthorize("hasAuthority('WRITE')")
@Operation(
summary = "Delete releases.",
Expand Down