Skip to content

Commit

Permalink
add support for isShownBy #EA-3956
Browse files Browse the repository at this point in the history
  • Loading branch information
gsergiu committed Oct 17, 2024
1 parent 7588e7e commit 1b824d4
Show file tree
Hide file tree
Showing 10 changed files with 290 additions and 49 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package eu.europeana.set.definitions.model;

import java.util.Objects;

public class BaseWebResource {

public static final String TYPE = "WebResource";
private String source;
private String id;
private String thumbnail;

public BaseWebResource() {
super();
}

public BaseWebResource(BaseWebResource copy) {
this.source = copy.getSource();
this.id = copy.getId();
this.thumbnail = copy.getThumbnail();
}

public BaseWebResource(String id, String source, String thumbnail) {
this.id = id;
this.source = source;
this.thumbnail = thumbnail;
}

public String getId() {
return id;
}

public String getSource() {
return source;
}

public String getThumbnail() {
return thumbnail;
}

public String getType() {
return TYPE;
}

public void setThumbnail(String thumbnailParam) {
thumbnail = thumbnailParam;
}

public void setSource(String sourceParam) {
source = sourceParam;
}

public void setId(String idParam) {
id = idParam;
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}

BaseWebResource that = (BaseWebResource) o;

return Objects.equals(source, that.getSource())
&& id.equals(that.getId())
&& Objects.equals(thumbnail, that.getThumbnail());
}

public int hashCode() {
int result = (id == null) ? 0 : id.hashCode();
result += (thumbnail == null) ? 0 : thumbnail.hashCode();
result += (source == null) ? 0 : source.hashCode();
return result;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,8 @@ public interface UserSet extends PageInfo {
Provider getProvider();

boolean hasItem(String itemId);

void setIsShownBy(BaseWebResource isShownBy);

BaseWebResource getIsShownBy();
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.Date;
import java.util.List;
import java.util.Map;
import eu.europeana.set.definitions.model.BaseWebResource;
import eu.europeana.set.definitions.model.UserSet;
import eu.europeana.set.definitions.model.agent.Agent;
import eu.europeana.set.definitions.model.vocabulary.UserSetTypes;
Expand Down Expand Up @@ -54,6 +55,11 @@ public abstract class BaseUserSet extends BasePageInfo implements UserSet {
* of this set of the Entity user sets
*/
private List<String> contributor;

/**
* depiction, primarily used y Galleries
*/
private BaseWebResource isShownBy;

/**
* Indicates whether the set is generated by a User as opposed to more
Expand Down Expand Up @@ -320,4 +326,14 @@ public Provider getProvider() {
public void setProvider(Provider provider) {
this.provider = provider;
}

@Override
public BaseWebResource getIsShownBy() {
return isShownBy;
}

@Override
public void setIsShownBy(BaseWebResource isShownBy) {
this.isShownBy = isShownBy;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,47 +5,52 @@
*/
public class 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";

//** user set fields **/
public static final String AT_CONTEXT = "@context";
public static final String CREATOR = "creator";
public static final String CONTRIBUTOR = "contributor";
public static final String CREATED = "created";
public static final String MODIFIED = "modified";
public static final String ISSUED = "issued";
public static final String IS_DEFINED_BY = "isDefinedBy";
public static final String SUBJECT = "subject";
public static final String ITEMS = "items";
public static final String TOTAL = "total";
public static final String VISIBILITY = "visibility";
public static final String IDENTIFIER = "identifier";
public static final String TITLE = "title";
public static final String PINNED = "pinned";
public static final String TEXT = "text";
public static final String PROVIDER = "provider";

//** creator fields **/
public static final String NICKNAME = "nickname";
public static final String ENTITYUSER_NICKNAME = "entitygalleries";

//** provider fields **/
public static final String NAME = "name";

// Pinned items constants
public static final String PINNED_POSITION = "pin";


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

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";

// ** user set fields **/
public static final String AT_CONTEXT = "@context";
public static final String CREATOR = "creator";
public static final String CONTRIBUTOR = "contributor";
public static final String CREATED = "created";
public static final String MODIFIED = "modified";
public static final String ISSUED = "issued";
public static final String IS_DEFINED_BY = "isDefinedBy";
public static final String SUBJECT = "subject";
public static final String ITEMS = "items";
public static final String TOTAL = "total";
public static final String VISIBILITY = "visibility";
public static final String IDENTIFIER = "identifier";
public static final String TITLE = "title";
public static final String PINNED = "pinned";
public static final String TEXT = "text";
public static final String PROVIDER = "provider";

// ** creator fields **/
public static final String NICKNAME = "nickname";
public static final String ENTITYUSER_NICKNAME = "entitygalleries";

// ** provider fields **/
public static final String NAME = "name";

// ** Web Resource fields **/
public static final String SOURCE = "source";
public static final String THUMBNAIL = "thumbnail";
public static final String IS_SHOWN_BY = "isShownBy";

// Pinned items constants
public static final String PINNED_POSITION = "pin";


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 @@ -65,6 +65,7 @@ public abstract class BaseUserSetTestUtils {
protected static final String BASE_URL = "/set/";
public static final String USER_SET_REGULAR = "/content/userset_regular.json";
public static final String USER_SET_GALLERY = "/content/userset_gallery.json";
public static final String USER_SET_GALLERY_DEPICTION = "/content/userset_gallery_with_depiction.json";
public static final String USER_SET_MANDATORY = "/content/userset_mandatory.json";
public static final String USER_SET_OPEN = "/content/userset_open.json";
public static final String USER_SET_MULTIPLE_QUERY_OPEN =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ public class MongoContainer extends GenericContainer<MongoContainer> {
private final String annotationDb;
private final String adminUsername = "admin_user";
private final String adminPassword = "admin_password";

//MUST BE KEPT INLINE WITH THE IMAGE FROM THE DOCKERFILE
public static final String MONGO_IMAGE = "library/mongo:6.0.14-jammy";

int hostPort;
int defaultMongoPort = 27017;
Expand All @@ -22,6 +23,8 @@ public class MongoContainer extends GenericContainer<MongoContainer> {
*/
public MongoContainer(String annotationDb, int hostPort) {
this(
//SG: deleteOnExit doesn't seems to make a difference in current version
//new ImageFromDockerfile(MONGO_IMAGE, false)
new ImageFromDockerfile()
// in test/resources directory
.withFileFromClasspath("Dockerfile", "mongo-docker/Dockerfile")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,25 @@ public void create_UserSet_201Created() throws Exception {
addToCreatedSets(identifier);
}

@Test
public void createGalleryWithDepiction() throws Exception {
String requestJson = getJsonStringInput(USER_SET_GALLERY_DEPICTION);

String result = mockMvc
.perform(
post(BASE_URL)
.content(requestJson).header(HttpHeaders.AUTHORIZATION, regularUserToken)
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE))
.andExpect(status().isCreated()).andReturn().getResponse().getContentAsString();
String identifier = getSetIdentifier(getConfiguration().getSetDataEndpoint(), result);
assertNotNull(identifier);
addToCreatedSets(identifier);

assertTrue(containsKeyOrValue(result, WebUserSetFields.TYPE_GALLERY));
assertTrue(containsKeyOrValue(result, WebUserSetFields.IS_SHOWN_BY));
}


@Test
public void create_UserSet_DynamicCollecton_without_isDefinedBy() throws Exception {
String requestJson = getJsonStringInput(USER_SET_OPEN);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"type": "Collection",
"collectionType": "Gallery",
"title": {
"en": "Sportswear"
},
"description": {
"en": "From tennis ensemble to golf uniforms, browse Europeana Fashion wide collection of historical sportswear and activewear designs!"
},
"isShownBy":{
"id": "https://i.vimeocdn.com/video/572458027_1280x960.jpeg",
"type": "WebResource",
"source": "http://data.europeana.eu/item/08641/1037479000000476703",
"thumbnail": "https://api.europeana.eu/thumbnail/v2/url.json?uri=https%3A%2F%2Fi.vimeocdn.com%2Fvideo%2F572458027_1280x960.jpeg&type=VIDEO"
},
"items":[
"http://data.europeana.eu/item/08641/1037479000000476703",
"http://data.europeana.eu/item/08641/1037479000000476591",
"http://data.europeana.eu/item/08641/1037479000000476903",
"http://data.europeana.eu/item/08641/1037479000000476467",
"http://data.europeana.eu/item/08641/1037479000000476875",
"http://data.europeana.eu/item/11654/_Botany_U_1419207",
"http://data.europeana.eu/item/2048128/618580"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package eu.europeana.set.web.model;

import static eu.europeana.set.definitions.model.vocabulary.WebUserSetModelFields.ID;
import static eu.europeana.set.definitions.model.vocabulary.WebUserSetModelFields.SOURCE;
import static eu.europeana.set.definitions.model.vocabulary.WebUserSetModelFields.THUMBNAIL;
import static eu.europeana.set.definitions.model.vocabulary.WebUserSetModelFields.TYPE;
import java.util.Objects;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import dev.morphia.annotations.Embedded;
import eu.europeana.set.definitions.model.BaseWebResource;

@Embedded
@JsonInclude(value = JsonInclude.Include.NON_EMPTY)
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonPropertyOrder({ID, TYPE, SOURCE, THUMBNAIL})
public class WebResource extends BaseWebResource {

public static final String TYPE = "WebResource";
@JsonProperty(SOURCE)
private String source;
@JsonProperty(ID)
private String id;
@JsonProperty(THUMBNAIL)
private String thumbnail;

public WebResource() {
super();
}

public WebResource(BaseWebResource copy) {
super(copy);
}

public WebResource(String id, String source, String thumbnail) {
super(id, source, thumbnail);
}


public void setThumbnail(String thumbnailParam) {
super.setThumbnail(thumbnailParam);
}

public void setSource(String sourceParam) {
source = sourceParam;
}

public void setId(String idParam) {
id = idParam;
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}

WebResource that = (WebResource) o;

return Objects.equals(source, that.getSource())
&& id.equals(that.getId())
&& Objects.equals(thumbnail, that.getThumbnail());
}

public int hashCode() {
int result = (id == null) ? 0 : id.hashCode();
result += (thumbnail == null) ? 0 : thumbnail.hashCode();
result += (source == null) ? 0 : source.hashCode();
return result;
}

}
Loading

0 comments on commit 1b824d4

Please sign in to comment.