From 7fa4917537ba587e1be83cc422cc5574302573c3 Mon Sep 17 00:00:00 2001 From: srishti Date: Fri, 22 Nov 2024 13:31:30 +0100 Subject: [PATCH] EA-4015 fixed the url issues --- .../client/connection/BaseApiConnection.java | 36 +++++++++++++------ .../connection/UserSetApiConnection.java | 11 ++---- set-client/src/main/resources/.gitignore | 4 +-- 3 files changed, 29 insertions(+), 22 deletions(-) diff --git a/set-client/src/main/java/eu/europeana/set/client/connection/BaseApiConnection.java b/set-client/src/main/java/eu/europeana/set/client/connection/BaseApiConnection.java index 6c4c8203..cec71c57 100644 --- a/set-client/src/main/java/eu/europeana/set/client/connection/BaseApiConnection.java +++ b/set-client/src/main/java/eu/europeana/set/client/connection/BaseApiConnection.java @@ -4,6 +4,7 @@ import java.net.URI; import java.util.function.Function; +import eu.europeana.api.commons.definitions.vocabulary.CommonApiConstants; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.springframework.http.ResponseEntity; @@ -11,6 +12,7 @@ import eu.europeana.set.common.http.HttpConnection; import eu.europeana.set.definitions.model.vocabulary.WebUserSetFields; import org.springframework.web.util.UriBuilder; +import org.springframework.web.util.UriComponentsBuilder; import static eu.europeana.set.definitions.model.vocabulary.WebUserSetFields.SEARCH_PATH; import static eu.europeana.api.commons.definitions.vocabulary.CommonApiConstants.*; @@ -139,6 +141,21 @@ public StringBuilder getUserSetServiceUri() { return urlBuilder; } + /** + * Build get user Set get Url + * @param path + * @param profile + * @return + */ + public static URI buildGetUrls(String path, String profile, String apikey) { + UriBuilder builder = UriComponentsBuilder.newInstance().path(path) + .queryParam(CommonApiConstants.PARAM_WSKEY, apikey); // by default pass apikey. If in case outh token is null apikey can be used to authenticate; + if (profile != null) { + builder.queryParam(QUERY_PARAM_PROFILE, profile); + } + return builder.build(); + } + /** * Builds search url with the given params * @param query @@ -151,17 +168,15 @@ public StringBuilder getUserSetServiceUri() { * @param profile * @return */ - public static Function buildSearchUrl(String query, String[] qf, String sort, int page, + public static URI buildSearchUrl(String query, String[] qf, String sort, int page, int pageSize, String facet, int facetLimit, - String profile) { - return uriBuilder -> { - UriBuilder builder = - uriBuilder - .path(SEARCH_PATH) - //.queryParam(WSKEY, wskey) - .queryParam(QUERY_PARAM_QUERY, query) - .queryParam(QUERY_PARAM_PAGE, page) - .queryParam(QUERY_PARAM_PAGE_SIZE, pageSize); + String profile, String apikey) { + UriBuilder builder = UriComponentsBuilder.newInstance().path(SEARCH_PATH) + .queryParam(QUERY_PARAM_QUERY, query) + .queryParam(QUERY_PARAM_PAGE, page) + .queryParam(QUERY_PARAM_PAGE_SIZE, pageSize) + .queryParam(CommonApiConstants.PARAM_WSKEY, apikey); // by default pass apikey. If in case outh token is null apikey can be used to authenticate + if (qf != null) { builder.queryParam(QUERY_PARAM_QF, qf); } @@ -176,7 +191,6 @@ public static Function buildSearchUrl(String query, String[] qf builder.queryParam(QUERY_PARAM_PROFILE, profile); } return builder.build(); - }; } public String getApiKey() { diff --git a/set-client/src/main/java/eu/europeana/set/client/connection/UserSetApiConnection.java b/set-client/src/main/java/eu/europeana/set/client/connection/UserSetApiConnection.java index bc544428..8416f594 100644 --- a/set-client/src/main/java/eu/europeana/set/client/connection/UserSetApiConnection.java +++ b/set-client/src/main/java/eu/europeana/set/client/connection/UserSetApiConnection.java @@ -57,14 +57,7 @@ public ResponseEntity createUserSet(String set, String profile) throws I * @throws IOException */ public ResponseEntity getUserSet(String identifier, String profile) throws IOException { - - StringBuilder urlBuilder = getUserSetServiceUri(); - urlBuilder.append(identifier).append(WebUserSetFields.JSON_LD_REST); - if (StringUtils.isNotEmpty(profile)) { - urlBuilder.append(WebUserSetFields.PAR_CHAR); - urlBuilder.append(CommonApiConstants.QUERY_PARAM_PROFILE) - .append(WebUserSetFields.EQUALS_PARAMETER).append(profile); - } + StringBuilder urlBuilder = getUserSetServiceUri().append(buildGetUrls(identifier + WebUserSetFields.JSON_LD_REST, profile, getApiKey())); return getURL(urlBuilder.toString(), regularUserAuthorizationValue); } @@ -125,7 +118,7 @@ public ResponseEntity searchUserSet(String query, String[] qf, String so int pageSize, String facet, int facetLimit, String profile) throws IOException { - StringBuilder urlBuilder = getUserSetServiceUri().append(buildSearchUrl(query, qf, sort, page, pageSize, facet, facetLimit, profile)); + StringBuilder urlBuilder = getUserSetServiceUri().append(buildSearchUrl(query, qf, sort, page, pageSize, facet, facetLimit, profile, getApiKey())); System.out.println(urlBuilder.toString()); return getURL(urlBuilder.toString(), regularUserAuthorizationValue); } diff --git a/set-client/src/main/resources/.gitignore b/set-client/src/main/resources/.gitignore index d05ae35b..6597be1a 100644 --- a/set-client/src/main/resources/.gitignore +++ b/set-client/src/main/resources/.gitignore @@ -1,4 +1,4 @@ -set.client.properties +set-client.properties **user.properties.template /log4j.xml -/log4j2.xml +/log4j2.xml \ No newline at end of file