diff --git a/set-web/src/main/java/eu/europeana/set/web/service/UserSetService.java b/set-web/src/main/java/eu/europeana/set/web/service/UserSetService.java index 5e54c99b..57d7d5ac 100644 --- a/set-web/src/main/java/eu/europeana/set/web/service/UserSetService.java +++ b/set-web/src/main/java/eu/europeana/set/web/service/UserSetService.java @@ -219,6 +219,15 @@ ItemIdsResultPage buildItemIdsResultsPage(String setId, List itemIds, in * @return profiled user set value */ void applyProfile(UserSet userSet, LdProfiles profile); + + /** + * Gets the profile for pagination urls and item page. Basically gets the profile valid for + * collection page from the list of profiles passed during search request + * + * @param profiles list of candidate profiles + * @return the profile to be applied for generating the pagination + */ + LdProfiles getProfileForPagination(List profiles); /** * Return the List of entity sets with 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 19b59e72..d5739245 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 @@ -99,8 +99,9 @@ protected ResponseEntity storeUserSet(String userSetJsonLdStr, throws HttpException { try { - LdProfiles profile = getProfile(profileStr, request); - + // validate params - profile + List profiles = getProfiles(profileStr, request); + // parse user set UserSet webUserSet = getUserSetService().parseUserSetLd(userSetJsonLdStr); @@ -116,6 +117,9 @@ protected ResponseEntity storeUserSet(String userSetJsonLdStr, UserSet storedUserSet = getUserSetService().storeUserSet(webUserSet, authentication); + // get profile for pagination urls and item Page + LdProfiles profile = getUserSetService().getProfileForPagination(profiles); + if (mustFetchItems(storedUserSet, profile)) { int derefItems = getDerefItemsCount(storedUserSet, UserSetConfigurationImpl.DEFAULT_ITEMS_PER_PAGE); @@ -213,8 +217,9 @@ private ResponseEntity getUserSet(String profileStr, String identifier, HttpServletRequest request, String sort, String sortOrder, Integer pageNr, int pageSize, Authentication authentication) throws HttpException { try { - LdProfiles profile = getProfile(profileStr, request); - + // 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 @@ -225,6 +230,9 @@ private ResponseEntity getUserSet(String profileStr, String identifier, getUserSetService().verifyOwnerOrAdmin(userSet, authentication, false); } + // get profile for pagination urls and item Page + LdProfiles profile = getUserSetService().getProfileForPagination(profiles); + if (mustFetchItems(userSet, profile)) { // pageNr, if empty default value 0 is sent for fetching items int page = (pageNr != null) ? pageNr : UserSetUtils.DEFAULT_PAGE; @@ -289,8 +297,9 @@ protected ResponseEntity updateUserSet(HttpServletRequest request, Authe String identifier, String userSetJsonLdStr, String profileStr) throws HttpException { try { - LdProfiles profile = getProfile(profileStr, request); - + // validate params - profile + List profiles = getProfiles(profileStr, request); + // check if the Set exists, if not respond with HTTP 404 // retrieve an existing user set based on its identifier UserSet existingUserSet = getUserSetService().getUserSetById(identifier); @@ -308,6 +317,9 @@ protected ResponseEntity updateUserSet(HttpServletRequest request, Authe // parse fields of the new user set to an object UserSet newUserSet = getUserSetService().parseUserSetLd(userSetJsonLdStr); + // get profile for pagination urls and item Page + LdProfiles profile = getUserSetService().getProfileForPagination(profiles); + // Respond with HTTP 200 // update an existing user set. merge user sets - insert new fields in existing // object @@ -407,8 +419,12 @@ protected ResponseEntity publishUnpublishUserSet(String identifier, UserSet updatedUserSet = getUserSetService().publishUnpublishUserSet(identifier, issued, authentication, publish); + // validate params - profile + List profiles = getProfiles(profileStr, request); + // get profile for pagination urls and item Page + LdProfiles profile = getUserSetService().getProfileForPagination(profiles); + // serialize to JsonLd - LdProfiles profile = getProfile(profileStr, request); String serializedUserSetJsonLdStr = serializeUserSet(profile, updatedUserSet); String etag = generateETag(updatedUserSet.getModified(), WebFields.FORMAT_JSONLD, getApiVersion()); @@ -470,8 +486,9 @@ protected ResponseEntity insertItemIntoUserSet(HttpServletRequest reques String position, String profileStr) throws HttpException { try { - LdProfiles profile = getProfile(profileStr, request); - + // validate params - profile + List profiles = getProfiles(profileStr, request); + // check if the Set exists, if not respond with HTTP 404 // retrieve an existing user set based on its identifier UserSet existingUserSet = getUserSetService().getUserSetById(identifier); @@ -502,6 +519,10 @@ protected ResponseEntity insertItemIntoUserSet(HttpServletRequest reques checkIfMatchHeader(eTagOrigin, request); UserSet updatedUserSet = getUserSetService().insertItem(datasetId, localId, position, existingUserSet); + + // get profile for pagination urls and item Page + LdProfiles profile = getUserSetService().getProfileForPagination(profiles); + String serializedUserSetJsonLdStr = serializeUserSet(profile, updatedUserSet); String etag = @@ -648,8 +669,9 @@ protected ResponseEntity deleteItemFromUserSet(HttpServletRequest reques String profileStr) throws HttpException { try { - LdProfiles profile = getProfile(profileStr, request); - + // validate params - profile + List profiles = getProfiles(profileStr, request); + // check if the Set exists, if not respond with HTTP 404 // retrieve an existing user set based on its identifier UserSet existingUserSet = getUserSetService().getUserSetById(identifier); @@ -688,6 +710,9 @@ protected ResponseEntity deleteItemFromUserSet(HttpServletRequest reques // update an existing user set UserSet updatedUserSet = getUserSetService().updateItemList(existingUserSet); + // get profile for pagination urls and item Page + LdProfiles profile = getUserSetService().getProfileForPagination(profiles); + // serialize to JsonLd String serializedUserSetJsonLdStr = serializeUserSet(profile, updatedUserSet); String etag = diff --git a/set-web/src/main/java/eu/europeana/set/web/service/impl/BaseUserSetServiceImpl.java b/set-web/src/main/java/eu/europeana/set/web/service/impl/BaseUserSetServiceImpl.java index 14888820..71439e34 100644 --- a/set-web/src/main/java/eu/europeana/set/web/service/impl/BaseUserSetServiceImpl.java +++ b/set-web/src/main/java/eu/europeana/set/web/service/impl/BaseUserSetServiceImpl.java @@ -49,7 +49,7 @@ public abstract class BaseUserSetServiceImpl implements UserSetService { @Resource(name = UserSetConfiguration.BEAN_SET_PERSITENCE_SERVICE) PersistentUserSetService mongoPersistance; - + UserSetUtils userSetUtils = new UserSetUtils(); UserSetSearchApiUtils userSetSearchApiUtils = new UserSetSearchApiUtils(); @@ -459,13 +459,7 @@ private boolean isUri(String value) { return value.startsWith("http://") || value.startsWith("https://"); } - /** - * Gets the profile for pagination urls and item page. Basically gets the profile valid for - * collection page from the list of profiles passed during search request - * - * @param profiles - * @return - */ + @Override public LdProfiles getProfileForPagination(List profiles) { LdProfiles profile = null; for (LdProfiles ldProfile : profiles) {