Skip to content

Commit

Permalink
Merge pull request #259 from europeana/EA-3873_fix_default_profile
Browse files Browse the repository at this point in the history
verify size only if the item is not present in the collection  #EA-3871
  • Loading branch information
gsergiu authored Aug 14, 2024
2 parents 9921d43 + f5eb9e0 commit 7c2e9be
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,6 @@ public interface UserSet extends PageInfo {
void setProvider(Provider provider);

Provider getProvider();

boolean hasItem(String itemId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -255,4 +255,6 @@ ItemIdsResultPage buildItemIdsResultsPage(String setId, List<String> itemIds, in
*/
UserSet publishUnpublishUserSet(String userSetId, Date issued, Authentication authentication, boolean publish) throws HttpException;

void validateCollectionSize(UserSet webUserSet, int newItems) throws ItemValidationException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,7 @@ protected ResponseEntity<String> insertItemIntoUserSet(HttpServletRequest reques
String eTagOrigin =
generateETag(existingUserSet.getModified(), WebFields.FORMAT_JSONLD, getApiVersion());
checkIfMatchHeader(eTagOrigin, request);

UserSet updatedUserSet =
getUserSetService().insertItem(datasetId, localId, position, existingUserSet);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7c2e9be

Please sign in to comment.