Skip to content

Commit

Permalink
Merge pull request #668 from eclipse/jp/fix-mapof
Browse files Browse the repository at this point in the history
Fix Map.of doesn't allow null values
  • Loading branch information
amvanbaren authored Feb 1, 2023
2 parents 90606d3 + ff7be8a commit 962947c
Showing 1 changed file with 32 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ private ResponseEntity<byte[]> getFile(String urlTemplate, Map<String, ?> uriVar
var url = UriComponentsBuilder.fromUriString(urlTemplate).build(uriVariables);
logger.error("HEAD " + url, exc);
}

throw new NotFoundException();
}
var statusCode = response.getStatusCode();
Expand Down Expand Up @@ -196,24 +196,23 @@ public ReviewListJson getReviews(String namespace, String extension) {
var url = UriComponentsBuilder.fromUriString(urlTemplate).build(uriVariables);
logger.error("GET " + url, exc);
}

throw new NotFoundException();
}
}

@Override
public SearchResultJson search(ISearchService.Options options) {
var urlTemplate = urlConfigService.getUpstreamUrl() + "/api/-/search";
var uriVariables = Map.of(
"size", Integer.toString(options.requestedSize),
"offset", Integer.toString(options.requestedOffset),
"includeAllVersions", Boolean.toString(options.includeAllVersions),
"query", options.queryString,
"category", options.category,
"sortOrder", options.sortOrder,
"sortBy", options.sortBy,
"targetPlatform", options.targetPlatform
);
var uriVariables = new HashMap<String,String>();
uriVariables.put("size", Integer.toString(options.requestedSize));
uriVariables.put("offset", Integer.toString(options.requestedOffset));
uriVariables.put("includeAllVersions", Boolean.toString(options.includeAllVersions));
uriVariables.put("query", options.queryString);
uriVariables.put("category", options.category);
uriVariables.put("sortOrder", options.sortOrder);
uriVariables.put("sortBy", options.sortBy);
uriVariables.put("targetPlatform", options.targetPlatform);

var queryString = uriVariables.entrySet().stream()
.filter(entry -> !Strings.isNullOrEmpty(entry.getValue()))
Expand All @@ -238,16 +237,16 @@ public SearchResultJson search(ISearchService.Options options) {
@Override
public QueryResultJson query(QueryParamJson param) {
var urlTemplate = urlConfigService.getUpstreamUrl() + "/api/-/query";
var queryParams = Map.of(
"namespaceName", param.namespaceName,
"extensionName", param.extensionName,
"extensionVersion", param.extensionVersion,
"extensionId", param.extensionId,
"extensionUuid", param.extensionUuid,
"namespaceUuid", param.namespaceUuid,
"includeAllVersions", String.valueOf(param.includeAllVersions),
"targetPlatform", param.targetPlatform
);
var queryParams = new HashMap<String,String>();
queryParams.put("namespaceName", param.namespaceName);
queryParams.put("extensionName", param.extensionName);
queryParams.put("extensionVersion", param.extensionVersion);
queryParams.put("extensionId", param.extensionId);
queryParams.put("extensionUuid", param.extensionUuid);
queryParams.put("namespaceUuid", param.namespaceUuid);
queryParams.put("includeAllVersions", String.valueOf(param.includeAllVersions));
queryParams.put("targetPlatform", param.targetPlatform);


var queryString = queryParams.entrySet().stream()
.filter(entry -> !Strings.isNullOrEmpty(entry.getValue()))
Expand All @@ -272,16 +271,15 @@ public QueryResultJson query(QueryParamJson param) {
@Override
public QueryResultJson queryV2(QueryParamJsonV2 param) {
var urlTemplate = urlConfigService.getUpstreamUrl() + "/api/v2/-/query";
var queryParams = Map.of(
"namespaceName", param.namespaceName,
"extensionName", param.extensionName,
"extensionVersion", param.extensionVersion,
"extensionId", param.extensionId,
"extensionUuid", param.extensionUuid,
"namespaceUuid", param.namespaceUuid,
"includeAllVersions", String.valueOf(param.includeAllVersions),
"targetPlatform", param.targetPlatform
);
var queryParams = new HashMap<String,String>();
queryParams.put("namespaceName", param.namespaceName);
queryParams.put("extensionName", param.extensionName);
queryParams.put("extensionVersion", param.extensionVersion);
queryParams.put("extensionId", param.extensionId);
queryParams.put("extensionUuid", param.extensionUuid);
queryParams.put("namespaceUuid", param.namespaceUuid);
queryParams.put("includeAllVersions", String.valueOf(param.includeAllVersions));
queryParams.put("targetPlatform", param.targetPlatform);

var queryString = queryParams.entrySet().stream()
.filter(entry -> !Strings.isNullOrEmpty(entry.getValue()))
Expand All @@ -302,7 +300,7 @@ public QueryResultJson queryV2(QueryParamJsonV2 param) {
throw new NotFoundException();
}
}

private void handleError(Throwable exc) throws RuntimeException {
if (exc instanceof HttpStatusCodeException) {
var status = ((HttpStatusCodeException) exc).getStatusCode();
Expand All @@ -327,4 +325,4 @@ private boolean isNotFound(RestClientException exc) {
return exc instanceof HttpStatusCodeException
&& ((HttpStatusCodeException) exc).getStatusCode() == HttpStatus.NOT_FOUND;
}
}
}

0 comments on commit 962947c

Please sign in to comment.