Skip to content

Commit

Permalink
fix creation of indices, search galleries #EA-3956
Browse files Browse the repository at this point in the history
  • Loading branch information
gsergiu committed Oct 16, 2024
1 parent 8f0edde commit 7588e7e
Show file tree
Hide file tree
Showing 10 changed files with 399 additions and 272 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,9 @@ public interface UserSetQuery extends Query{
void setTitleLang(String lang);

String getTitleLang();

void setCollectionType(String collectionType);

String getCollectionType();

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class UserSetQueryImpl extends QueryImpl implements UserSetQuery{
String text;
String provider;
String titleLang;
String collectionType;

@Override
public String getUser() {
Expand Down Expand Up @@ -126,4 +127,14 @@ public void setTitleLang(String lang) {
public String getTitleLang() {
return titleLang;
}

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

@Override
public void setCollectionType(String collectionType) {
this.collectionType = collectionType;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,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_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 Expand Up @@ -134,7 +135,10 @@ public abstract class BaseUserSetTestUtils {
static {
// MONGO_CONTAINER = new MongoDBContainer("mongo:6.0.14-jammy")
final String serviceDB = "admin"; // to change to "set-api-test"
MONGO_CONTAINER = new MongoContainer(serviceDB)
//for debugging set the host port to 27017 or 27018
int hostPort = -1;

MONGO_CONTAINER = new MongoContainer(serviceDB, hostPort)
.withLogConsumer(new WaitingConsumer()
.andThen(new ToStringConsumer()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,29 @@ public class MongoContainer extends GenericContainer<MongoContainer> {
private final String adminPassword = "admin_password";


private final boolean useFixedPorts = false;
int hostPort;
int defaultMongoPort = 27017;

/**
* Creates a new Mongo container instance
*
* @param annotationDb entity database
*/
public MongoContainer(String annotationDb) {
public MongoContainer(String annotationDb, int hostPort) {
this(
new ImageFromDockerfile()
// in test/resources directory
.withFileFromClasspath("Dockerfile", "mongo-docker/Dockerfile")
.withFileFromClasspath("init-mongo.sh", "mongo-docker/init-mongo.sh"),
annotationDb);
annotationDb, hostPort);
}

private MongoContainer(
ImageFromDockerfile dockerImageName, String annotationDb) {
ImageFromDockerfile dockerImageName, String annotationDb, int hostPort) {
super(dockerImageName);

if (useFixedPorts) {
this.addFixedExposedPort(27018, defaultMongoPort);
if (hostPort > 0) {
this.addFixedExposedPort(hostPort, defaultMongoPort);
} else {
this.withExposedPorts(defaultMongoPort);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public class SearchUserSetRestIT extends BaseUserSetTestUtils {
WebUserSetFields.TYPE + ":" + UserSetTypes.COLLECTION;
private static final String SEARCH_ENTITY_SET =
WebUserSetFields.TYPE + ":" + UserSetTypes.ENTITYBESTITEMSSET;
private static final String SEARCH_GALLERY =
WebUserSetFields.COLLECTION_TYPE + ":" + WebUserSetFields.TYPE_GALLERY;
private static final String SEARCH_TITLE_LANG_EN = WebUserSetFields.LANG + ":" + "en";
// private static final String SORT_MODIFIED_WebUserSetFields.MODIFIED
private static final String PAGE_SIZE = "100";
Expand Down Expand Up @@ -730,6 +732,44 @@ private MockHttpServletRequestBuilder buildSearchItemsInSetRequest(String setIde
return getRequest;
}

@Test
public void searchGalleries() throws Exception {
UserSet set1 = createTestUserSet(USER_SET_GALLERY, regularUserToken);
assertNotNull(set1);
String result = mockMvc
.perform(
get(SEARCH_URL).param(CommonApiConstants.QUERY_PARAM_PROFILE, LdProfiles.MINIMAL.name())
.queryParam(CommonApiConstants.PARAM_WSKEY, API_KEY)
.queryParam(CommonApiConstants.QUERY_PARAM_QUERY, SEARCH_GALLERY)
.queryParam(CommonApiConstants.QUERY_PARAM_PAGE_SIZE, PAGE_SIZE)
.header("Authorization", "Bearer " + regularUserToken)
)
.andExpect(status().is(HttpStatus.OK.value())).andReturn().getResponse()
.getContentAsString();

assertTrue(containsKeyOrValue(result,
UserSetUtils.buildUserSetId(getConfiguration().getSetDataEndpoint(), set1.getIdentifier())));
//only id retured in the minimal profile, to be enabled after refactoring profiles
//assertTrue(containsKeyOrValue(result, WebUserSetFields.TYPE_GALLERY));
}

@Test
public void searchByWrongCollectionType() throws Exception {
final String wrongCollectionType = "wrongCollectionType";
final String query = WebUserSetFields.COLLECTION_TYPE+":"+wrongCollectionType;
String result = mockMvc
.perform(
get(SEARCH_URL).param(CommonApiConstants.QUERY_PARAM_PROFILE, LdProfiles.MINIMAL.name())
.queryParam(CommonApiConstants.PARAM_WSKEY, API_KEY)
.queryParam(CommonApiConstants.QUERY_PARAM_QUERY, query)
.queryParam(CommonApiConstants.QUERY_PARAM_PAGE_SIZE, PAGE_SIZE))
.andExpect(status().is(HttpStatus.BAD_REQUEST.value())).andReturn().getResponse()
.getContentAsString();

assertTrue(result.contains(wrongCollectionType));
}


@Test
public void searchTypeCollection() throws Exception {
UserSet set1 = createTestUserSet(USER_SET_REGULAR, regularUserToken);
Expand All @@ -746,6 +786,7 @@ public void searchTypeCollection() throws Exception {
assertNotNull(set2);
}


// Facet validation
@Test
public void searchFacetsNoFacetValidationTest() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"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!"
},
"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
Expand Up @@ -17,6 +17,7 @@
@Indexes({@Index(fields = {@Field(WebUserSetFields.IDENTIFIER)},options = @IndexOptions(unique = true)),
@Index(fields = {@Field(WebUserSetFields.CREATOR)}),
@Index(fields = {@Field(WebUserSetFields.TYPE)}),
@Index(fields = {@Field(WebUserSetFields.COLLECTION_TYPE)}),
@Index(fields = {@Field(WebUserSetFields.VISIBILITY)}),
@Index(fields = {@Field(WebUserSetFields.CONTRIBUTOR)}),
@Index(fields = {@Field(WebUserSetFields.SUBJECT)}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,10 @@ private Query<PersistentUserSet> buildUserConditionsQuery(UserSetQuery query) {
if (query.getType() != null) {
mongoQuery.filter(WebUserSetModelFields.TYPE, query.getType());
}

if (query.getCollectionType() != null) {
mongoQuery.filter(WebUserSetModelFields.COLLECTION_TYPE, query.getCollectionType());
}

if (query.getCreator() != null) {
mongoQuery.filter(WebUserSetModelFields.CREATOR + ".httpUrl", query.getCreator());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
import org.springframework.context.annotation.PropertySource;
import com.mongodb.WriteConcern;
import dev.morphia.Datastore;
import eu.europeana.api.commons.nosql.entity.ApiWriteLockImpl;
import eu.europeana.corelib.db.wrapper.ApiMongoConnector;
import eu.europeana.set.definitions.config.UserSetConfiguration;
import eu.europeana.set.mongo.model.PersistentUserSetImpl;

/**
* This mongo config crates a org.mongodb.morphia.Datastore instead of a dev.morphia.Datastore
Expand All @@ -33,8 +34,7 @@ public class MongoConfig {
@Value("${mongodb.set.truststorepass:''}")
private String mongoTrustStorePass;

private static final String[] MODEL_PACKAGES = new String[]{"eu.europeana.set.definitions", "eu.europeana.api.commons.nosql.entity"};

private static final String[] MODEL_PACKAGES = new String[]{PersistentUserSetImpl.class.getPackageName(), ApiWriteLockImpl.class.getPackageName()};
private ApiMongoConnector mongoConnector;

@Bean(BeanNames.BEAN_SET_MONGO_STORE)
Expand Down
Loading

0 comments on commit 7588e7e

Please sign in to comment.