diff --git a/set-definitions/src/main/java/eu/europeana/set/definitions/model/UserSet.java b/set-definitions/src/main/java/eu/europeana/set/definitions/model/UserSet.java index 7394b2a4..eb942b0c 100644 --- a/set-definitions/src/main/java/eu/europeana/set/definitions/model/UserSet.java +++ b/set-definitions/src/main/java/eu/europeana/set/definitions/model/UserSet.java @@ -97,4 +97,6 @@ public interface UserSet extends PageInfo { void setProvider(Provider provider); Provider getProvider(); + + boolean hasItem(String itemId); } \ No newline at end of file diff --git a/set-mongo/src/main/java/eu/europeana/set/mongo/model/PersistentUserSetImpl.java b/set-mongo/src/main/java/eu/europeana/set/mongo/model/PersistentUserSetImpl.java index 3c464eb2..4c384de6 100644 --- a/set-mongo/src/main/java/eu/europeana/set/mongo/model/PersistentUserSetImpl.java +++ b/set-mongo/src/main/java/eu/europeana/set/mongo/model/PersistentUserSetImpl.java @@ -74,4 +74,9 @@ public String toString() { public void setBaseUrl(String baseUrl) { //used only for web userset } + + @Override + public boolean hasItem(String itemId) { + return getItems() != null && getItems().contains(itemId); + } } \ No newline at end of file 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 d150302c..e7a79b44 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 @@ -255,4 +255,6 @@ ItemIdsResultPage buildItemIdsResultsPage(String setId, List itemIds, in */ UserSet publishUnpublishUserSet(String userSetId, Date issued, Authentication authentication, boolean publish) throws HttpException; + void validateCollectionSize(UserSet webUserSet, int newItems) throws ItemValidationException; + } \ No newline at end of file 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 90f787fb..b32ea3c9 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 @@ -479,6 +479,7 @@ protected ResponseEntity insertItemIntoUserSet(HttpServletRequest reques String eTagOrigin = generateETag(existingUserSet.getModified(), WebFields.FORMAT_JSONLD, getApiVersion()); checkIfMatchHeader(eTagOrigin, request); + UserSet updatedUserSet = getUserSetService().insertItem(datasetId, localId, position, existingUserSet); 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 1f0b89d5..a4d09ed0 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 @@ -591,6 +591,7 @@ public void validateWebUserSet(UserSet webUserSet, boolean isAlreadyPublished) t validateItems(webUserSet.getItems()); } + @Override public void validateCollectionSize(UserSet webUserSet, int newItems) throws ItemValidationException { final int collectionMaxSize = getConfiguration().getCollectionMaxSize(); if(webUserSet.isCollection() diff --git a/set-web/src/main/java/eu/europeana/set/web/service/impl/UserSetServiceImpl.java b/set-web/src/main/java/eu/europeana/set/web/service/impl/UserSetServiceImpl.java index 3e95b79e..3167e2ed 100644 --- a/set-web/src/main/java/eu/europeana/set/web/service/impl/UserSetServiceImpl.java +++ b/set-web/src/main/java/eu/europeana/set/web/service/impl/UserSetServiceImpl.java @@ -239,10 +239,13 @@ public UserSet insertItem(String datasetId, String localId, String position, String itemForPartialValidation = "/" + datasetId + "/" + localId; validateItemPartial(itemForPartialValidation); - //check max number of items for the sets of type Collection - validateCollectionSize(existingUserSet, 1); String newItem = UserSetUtils.buildItemUrl(getConfiguration().getItemDataEndpoint(), datasetId, localId); + + //check max number of items for the sets of type Collection + if(existingUserSet.isCollection() && !existingUserSet.hasItem(newItem)) { + validateCollectionSize(existingUserSet, 1); + } // check if the position is "pin" and is a EntityBestItem set then // insert the item at the 0 position