Skip to content

Commit

Permalink
EA-4015 fixed the url issues
Browse files Browse the repository at this point in the history
  • Loading branch information
SrishtiSingh-eu committed Nov 22, 2024
1 parent 5724d0a commit 7fa4917
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
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;

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.*;
Expand Down Expand Up @@ -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
Expand All @@ -151,17 +168,15 @@ public StringBuilder getUserSetServiceUri() {
* @param profile
* @return
*/
public static Function<UriBuilder, URI> 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);
}
Expand All @@ -176,7 +191,6 @@ public static Function<UriBuilder, URI> buildSearchUrl(String query, String[] qf
builder.queryParam(QUERY_PARAM_PROFILE, profile);
}
return builder.build();
};
}

public String getApiKey() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,7 @@ public ResponseEntity<String> createUserSet(String set, String profile) throws I
* @throws IOException
*/
public ResponseEntity<String> 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);
}

Expand Down Expand Up @@ -125,7 +118,7 @@ public ResponseEntity<String> 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);
}
Expand Down
4 changes: 2 additions & 2 deletions set-client/src/main/resources/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
set.client.properties
set-client.properties
**user.properties.template
/log4j.xml
/log4j2.xml
/log4j2.xml

0 comments on commit 7fa4917

Please sign in to comment.