Skip to content

Commit

Permalink
Merge pull request #261 from europeana/EA-3925-issue-itemDescriptions…
Browse files Browse the repository at this point in the history
…-profile

Ea 3925 issue item descriptions profile
  • Loading branch information
gsergiu authored Sep 11, 2024
2 parents df4b300 + fe655ee commit 9e6db26
Show file tree
Hide file tree
Showing 14 changed files with 72 additions and 28 deletions.
4 changes: 2 additions & 2 deletions set-common/src/main/resources/set.common.properties
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,5 @@ europeana.search.itemdescription.profile=minimal
#the name for annotation api resources in keyckloak tokens
authorization.api.name=usersets

#max size of Collection sets
set.collection.size.max=100
#max size of Gallery sets
set.gallery.size.max=100
4 changes: 2 additions & 2 deletions set-common/src/main/resources/set.user.properties.template
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,5 @@ europeana.apikey.jwttoken.siganturekey=
# location for the elevation file
elevation.file.folder=

#overwrite max size of Collection sets
#set.collection.size.max=100
#overwrite max size of Gallery sets
#set.gallery.size.max=100
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,5 @@ public interface UserSetConfiguration {

boolean isAuthEnabled();

int getCollectionMaxSize();
int getGalleryMaxSize();
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class UserSetConfigurationImpl implements UserSetConfiguration {

public static final int DEFAULT_ITEMS_PER_PAGE = 10;
public static final int MIN_ITEMS_PER_PAGE = 1;
public static final int DEFAULT_MAX_COLLECTION_SIZE = 100;
public static final int DEFAULT_MAX_GALLERY_SIZE = 100;
public static final int DEFAULT_MAX_ITEMS_TO_PRESENT = 1000;


Expand Down Expand Up @@ -46,7 +46,7 @@ public class UserSetConfigurationImpl implements UserSetConfiguration {
public static final String KEY_SEARCH_ITEM_DESCRIPTION_PROFILE = "europeana.search.itemdescription.profile";
public static final String API_BASE_PATH = "set.api.basePath";

public static final String COLLECTION_SIZE_MAX = "set.collection.size.max";
public static final String GALLERY_SIZE_MAX = "set.gallery.size.max";

private Properties setProperties;

Expand Down Expand Up @@ -177,8 +177,8 @@ public String getEuropeanaPublisherNickname() {
}

@Override
public int getCollectionMaxSize() {
return Integer.parseInt(getSetProperties().getProperty(COLLECTION_SIZE_MAX, ""+DEFAULT_MAX_COLLECTION_SIZE));
public int getGalleryMaxSize() {
return Integer.parseInt(getSetProperties().getProperty(GALLERY_SIZE_MAX, ""+DEFAULT_MAX_GALLERY_SIZE));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ public interface UserSet extends PageInfo {

void setType(String type);

String getCollectionType();

void setCollectionType(String collectionType);

String getVisibility();

void setVisibility(String visibility);
Expand Down Expand Up @@ -81,6 +85,8 @@ public interface UserSet extends PageInfo {
public boolean isEntityBestItemsSet();

public boolean isCollection();

public boolean isGallery();

public boolean isPrivate();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import eu.europeana.set.definitions.model.agent.Agent;
import eu.europeana.set.definitions.model.vocabulary.UserSetTypes;
import eu.europeana.set.definitions.model.vocabulary.VisibilityTypes;
import eu.europeana.set.definitions.model.vocabulary.WebUserSetModelFields;

/**
* Europeana Sets API Specification
Expand All @@ -19,6 +20,8 @@ public abstract class BaseUserSet extends BasePageInfo implements UserSet {

// Type of user set : #UserSetTypes
private String type;

private String collectionType;

// Visibility of user set : #VisibilityTypes
private String visibility;
Expand Down Expand Up @@ -115,6 +118,16 @@ public void setType(String type) {
this.type = type;
}

@Override
public String getCollectionType() {
return collectionType;
}

@Override
public void setCollectionType(String collectionType) {
this.collectionType = collectionType;
}

@Override
public Map<String, String> getTitle() {
return title;
Expand Down Expand Up @@ -280,6 +293,11 @@ public boolean isCollection() {
return UserSetTypes.COLLECTION.getJsonValue().equals(getType());
}

@Override
public boolean isGallery() {
return WebUserSetModelFields.TYPE_GALLERY.equals(getCollectionType());
}

@Override
public String toString() {
StringBuilder res = new StringBuilder("\t### User set ###\n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@
*/
public class WebUserSetModelFields {

WebUserSetModelFields() {

}

//common fields constants
public static final String ID = "id";
public static final String TYPE = "type";
public static final String COLLECTION_TYPE = "collectionType";
public static final String TYPE_COLLECTION = "Collection";
public static final String TYPE_GALLERY = "Gallery";
public static final String SET_OPEN = "open";
public static final String SET_CLOSED = "closed";

Expand Down Expand Up @@ -46,4 +44,8 @@ public class WebUserSetModelFields {


public static final String VALUE_CONTEXT_EUROPEANA_COLLECTION = "http://www.europeana.eu/schemas/context/collection.jsonld";

WebUserSetModelFields() {
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ private void disableOauth() {

private void changeProperiesForTests() {
((UserSetConfigurationImpl) configuration).getSetProperties()
.put(UserSetConfigurationImpl.COLLECTION_SIZE_MAX, "249");
.put(UserSetConfigurationImpl.GALLERY_SIZE_MAX, "249");
}

public static void initRegularUserToken() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"type": "Collection",
"collectionType": "Gallery",
"title":{
"en": "Tradition and beauty - early-flowering plants from bulbs in botany and arts"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ public interface PersistentUserSet extends UserSet, NoSqlEntity {
String getType();

void setType(String type);

String getCollectionType();

void setCollectionType(String collectionType);

Map<String, String> getTitle();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@
import eu.europeana.set.definitions.model.vocabulary.WebUserSetModelFields;
import eu.europeana.set.mongo.model.PersistentUserSetImpl;

@JsonPropertyOrder({ WebUserSetModelFields.ID, WebUserSetModelFields.TYPE, WebUserSetModelFields.TITLE, WebUserSetModelFields.SUBJECT,
WebUserSetFields.DESCRIPTION, WebUserSetModelFields.VISIBILITY, WebUserSetModelFields.IS_DEFINED_BY, WebUserSetModelFields.PINNED,
WebUserSetModelFields.ITEMS, WebUserSetModelFields.CREATOR, WebUserSetModelFields.CONTRIBUTOR, WebUserSetModelFields.PROVIDER,
WebUserSetModelFields.CREATED, WebUserSetModelFields.MODIFIED, WebUserSetModelFields.TOTAL, WebUserSetFields.NEXT, WebUserSetFields.PREV })
@JsonPropertyOrder({ WebUserSetModelFields.ID, WebUserSetModelFields.TYPE, WebUserSetModelFields.COLLECTION_TYPE, WebUserSetModelFields.TITLE,
WebUserSetModelFields.SUBJECT, WebUserSetFields.DESCRIPTION, WebUserSetModelFields.VISIBILITY, WebUserSetModelFields.IS_DEFINED_BY,
WebUserSetModelFields.PINNED, WebUserSetModelFields.ITEMS, WebUserSetModelFields.CREATOR, WebUserSetModelFields.CONTRIBUTOR,
WebUserSetModelFields.PROVIDER, WebUserSetModelFields.CREATED, WebUserSetModelFields.MODIFIED, WebUserSetModelFields.TOTAL,
WebUserSetFields.NEXT, WebUserSetFields.PREV })
@JsonInclude(value = JsonInclude.Include.NON_DEFAULT)
@JsonIgnoreProperties(ignoreUnknown = true)
public class WebUserSetImpl extends PersistentUserSetImpl {
Expand Down Expand Up @@ -63,11 +64,18 @@ public String getIdentifier() {
return super.getIdentifier();
}

@JsonProperty(WebUserSetFields.TYPE)
@Override
@JsonProperty(WebUserSetModelFields.TYPE)
public void setType(String type) {
super.setType(type);
}

@Override
@JsonProperty(WebUserSetModelFields.COLLECTION_TYPE)
public void setCollectionType(String collType) {
super.setCollectionType(collType);
}

@JsonProperty(WebUserSetModelFields.VISIBILITY)
public void setVisibility(String visibility) {
super.setVisibility(visibility);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +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;
void validateGallerySize(UserSet webUserSet, int newItems) throws ItemValidationException;

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package eu.europeana.set.web.service.impl;

import static eu.europeana.set.web.config.UserSetI18nConstants.*;
import static eu.europeana.set.web.config.UserSetI18nConstants.USERSET_ITEMS_LIMIT_REACHED;
import static eu.europeana.set.web.config.UserSetI18nConstants.USERSET_NUMBER_OF_ITEMS;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
Expand Down Expand Up @@ -134,6 +135,10 @@ void mergeDescriptiveProperties(PersistentUserSet persistedSet, UserSet updates)
persistedSet.setType(updates.getType());
}

if (updates.getCollectionType() != null) {
persistedSet.setCollectionType(updates.getCollectionType());
}

if (updates.getVisibility() != null) {
persistedSet.setVisibility(updates.getVisibility());
}
Expand Down Expand Up @@ -581,7 +586,7 @@ public void validateWebUserSet(UserSet webUserSet, boolean isAlreadyPublished) t
}

//validate number of items for the sets of type Collection
validateCollectionSize(webUserSet, 0);
validateGallerySize(webUserSet, 0);

validateProvider(webUserSet);
validateBookmarkFolder(webUserSet);
Expand All @@ -592,15 +597,15 @@ public void validateWebUserSet(UserSet webUserSet, boolean isAlreadyPublished) t
}

@Override
public void validateCollectionSize(UserSet webUserSet, int newItems) throws ItemValidationException {
final int collectionMaxSize = getConfiguration().getCollectionMaxSize();
if(webUserSet.isCollection()
public void validateGallerySize(UserSet webUserSet, int newItems) throws ItemValidationException {
final int galleryMaxSize = getConfiguration().getGalleryMaxSize();
if(webUserSet.isGallery()
&& webUserSet.getItems()!=null
&& webUserSet.getItems().size() + newItems > collectionMaxSize) {
&& webUserSet.getItems().size() + newItems > galleryMaxSize) {

String messageKey = (newItems == 0) ? USERSET_NUMBER_OF_ITEMS : USERSET_ITEMS_LIMIT_REACHED;
throw new ItemValidationException(messageKey,
new String[] {String.valueOf(collectionMaxSize)} );
new String[] {String.valueOf(galleryMaxSize)} );
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ public UserSet insertItem(String datasetId, String localId, String position,

//check max number of items for the sets of type Collection
if(existingUserSet.isCollection() && !existingUserSet.hasItem(newItem)) {
validateCollectionSize(existingUserSet, 1);
validateGallerySize(existingUserSet, 1);
}

// check if the position is "pin" and is a EntityBestItem set then
Expand Down

0 comments on commit 9e6db26

Please sign in to comment.