From ddc211cc0c041159c3fa737b6e90c71975a257af Mon Sep 17 00:00:00 2001 From: gsergiu <4517853+gsergiu@users.noreply.github.com> Date: Tue, 13 Aug 2024 17:02:41 +0200 Subject: [PATCH] fix default profile for retrieve set and collection page --- .../controller/jsonld/WebUserSetRest.java | 31 ++++++++++++------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/set-web/src/main/java/eu/europeana/set/web/service/controller/jsonld/WebUserSetRest.java b/set-web/src/main/java/eu/europeana/set/web/service/controller/jsonld/WebUserSetRest.java index 266cea4a..90f787fb 100644 --- a/set-web/src/main/java/eu/europeana/set/web/service/controller/jsonld/WebUserSetRest.java +++ b/set-web/src/main/java/eu/europeana/set/web/service/controller/jsonld/WebUserSetRest.java @@ -154,32 +154,42 @@ public ResponseEntity getUserSet( required = false) String sortOrderField, @RequestParam(value = CommonApiConstants.QUERY_PARAM_PAGE, required = false) String page, @RequestParam(value = CommonApiConstants.QUERY_PARAM_PAGE_SIZE, required = false) String pageSize, - @RequestParam(value = CommonApiConstants.QUERY_PARAM_PROFILE, required = false, - defaultValue = CommonApiConstants.PROFILE_MINIMAL) String profile, + @RequestParam(value = CommonApiConstants.QUERY_PARAM_PROFILE, required = false) String profile, HttpServletRequest request) throws HttpException { Authentication authentication = verifyReadAccess(request); - - Integer pageNr=null; + Integer pageNr=null; Integer pageItems=null; + + // validate params - profile + List profiles = getProfiles(profile, request); + //if no pagination requested, apply minimal profile (profiles deprecation) if(isSetMetadataResponse(page)) { - List profiles = getProfiles(profile, request); if(profiles.contains(LdProfiles.ITEMDESCRIPTIONS) || profiles.contains(LdProfiles.STANDARD)) { //only minimal allow when retrieving metadata throw new ParamValidationException(I18nConstants.INVALID_PARAM_VALUE, - I18nConstants.INVALID_PARAM_VALUE, new String[] {CommonApiConstants.QUERY_PARAM_PROFILE, profile}); + I18nConstants.INVALID_PARAM_VALUE, new String[] {CommonApiConstants.QUERY_PARAM_PROFILE, profiles.toString()}); + } + //add default profile if not present + if(!profiles.contains(LdProfiles.MINIMAL)) { + profiles.add(LdProfiles.MINIMAL); } - profile=CommonApiConstants.PROFILE_MINIMAL; + } else { pageNr = parseIntegerParam(CommonApiConstants.QUERY_PARAM_PAGE, page, -1, UserSetUtils.DEFAULT_PAGE); pageNr = (pageNr == null) ? Integer.valueOf(UserSetUtils.DEFAULT_PAGE) : pageNr; int maxPageSize = getConfiguration().getMaxPageSize(null); pageItems = parseIntegerParam(CommonApiConstants.QUERY_PARAM_PAGE_SIZE, pageSize, maxPageSize, UserSetConfigurationImpl.MIN_ITEMS_PER_PAGE); pageItems = (pageItems == null) ? Integer.valueOf(UserSetConfigurationImpl.DEFAULT_ITEMS_PER_PAGE) : pageItems; + //add default profile + final boolean noSerializationProfile = profiles.isEmpty() || (profiles.size() == 1 && profiles.contains(LdProfiles.MINIMAL)); + if( noSerializationProfile ) { + profiles.add(LdProfiles.STANDARD); + } } - return getUserSet(profile, identifier, request, sortField, sortOrderField, pageNr, pageItems, + return getUserSet(profiles, identifier, request, sortField, sortOrderField, pageNr, pageItems, authentication); } @@ -211,13 +221,10 @@ private Integer parseIntegerParam(String paramName, String paramValue, int maxVa * @return response entity that comprises response body, headers and status code * @throws HttpException */ - private ResponseEntity getUserSet(String profileStr, String identifier, + private ResponseEntity getUserSet(List profiles, String identifier, HttpServletRequest request, String sort, String sortOrder, Integer pageNr, Integer pageSize, Authentication authentication) throws HttpException { try { - // validate params - profile - List profiles = getProfiles(profileStr, request); - // retrieve a Set based on its identifier - process query // if the Set doesn’t exist, respond with HTTP 404 // if the Set is disabled respond with HTTP 410