Skip to content

Commit

Permalink
Merge branch 'develop' into 0.11_maintenance
Browse files Browse the repository at this point in the history
  • Loading branch information
gsergiu authored Mar 12, 2024
2 parents 505b85c + 0bc9fae commit 5f0d6c7
Show file tree
Hide file tree
Showing 29 changed files with 573 additions and 430 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build_test_analyse.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Build, run tests and analyse
run: mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Pcoverage -Dsonar.projectKey=europeana_set-api -Dsonar.organization=europeana
run: mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Pcoverage -Dsonar.projectKey=europeana_set-api
env:
# Needed to get some information about the pull request, if any
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
8 changes: 4 additions & 4 deletions k8s/base/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ spec:
httpHeaders:
- name: Accept
value: application/json
initialDelaySeconds: 30
periodSeconds: 30
initialDelaySeconds: 40
periodSeconds: 20
readinessProbe:
httpGet:
port: 8080
path: /actuator/health/readiness
httpHeaders:
- name: Accept
value: application/json
initialDelaySeconds: 30
periodSeconds: 30
initialDelaySeconds: 40
periodSeconds: 20
volumeMounts:
- name: app-properties
mountPath: "/opt/app/config/set.user.properties"
Expand Down
7 changes: 5 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@
</repositories>

<properties>
<revision>0.11.2</revision>
<revision>0.12-SNAPSHOT</revision>
<version.java>11</version.java>
<version.javac.release>11</version.javac.release>
<version.log4j2>2.17.2</version.log4j2>
<version.commonsApi>0.3.19</version.commonsApi>
<version.commonsApi>0.3.22-SNAPSHOT</version.commonsApi>
<version.springBoot>2.5.7</version.springBoot>
<version.springBootMongoStarter>2.0.3.RELEASE</version.springBootMongoStarter>
<version.swagger>3.0.0</version.swagger>
Expand Down Expand Up @@ -76,6 +76,9 @@
<sonar.java.pmd.reportPaths>${project.build.directory}/pmd.xml</sonar.java.pmd.reportPaths>
<sonar.java.spotbugs.reportPaths>${project.build.directory}/spotbugsXml.xml</sonar.java.spotbugs.reportPaths>
<sonar.organization>europeana</sonar.organization>
<!--
<sonar.projectKey>europeana_set-api</sonar.projectKey>
-->
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
<!-- Exclude POJOs code duplication analysis -->
<sonar.cpd.exclusions>**/model/**/*</sonar.cpd.exclusions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ public interface UserSetConfiguration {

public String getAuthorizationApiName();

public String getApiVersion();

public String getSearchApiUrl();

String getUserDataEndpoint();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ public class UserSetConfigurationImpl implements UserSetConfiguration {
public static final String KEY_SEARCH_APIKEY = "europeana.search.apikey";
public static final String KEY_SEARCH_URL = "europeana.search.url";
public static final String KEY_SEARCH_ITEM_DESCRIPTION_PROFILE = "europeana.search.itemdescription.profile";
public static final String API_VERSION = "set.api.version";
public static final String API_BASE_PATH = "set.api.basePath";


Expand Down Expand Up @@ -131,11 +130,6 @@ public String getAuthorizationApiName() {
return getSetProperties().getProperty(AUTHORIZATION_API_NAME);
}

@Override
public String getApiVersion() {
return getSetProperties().getProperty(API_VERSION);
}

@Override
public String getSearchApiKey() {
return getSetProperties().getProperty(KEY_SEARCH_APIKEY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.util.Date;
import java.util.List;
import java.util.Map;

import eu.europeana.set.definitions.model.agent.Agent;
import eu.europeana.set.definitions.model.impl.Provider;

Expand Down Expand Up @@ -49,6 +48,10 @@ public interface UserSet extends PageInfo {

void setModified(Date modified);

Date getIssued();

void setIssued(Date issued);

List<String> getItems();

void setItems(List<String> items);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.util.Date;
import java.util.List;
import java.util.Map;

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 @@ -79,6 +78,12 @@ public abstract class BaseUserSet extends BasePageInfo implements UserSet {
* literal expressed as xsd:dateTime with the UTC timezone expressed as "Z".
*/
private Date modified;

/**
* The time at which the Set was published, after creation. The value must be a
* literal expressed as xsd:dateTime with the UTC timezone expressed as "Z".
*/
private Date issued;

/**
* Ordered Collections from Activity Streams For EDM Collection class
Expand Down Expand Up @@ -198,6 +203,16 @@ public void setModified(Date modified) {
this.modified = modified;
}

@Override
public Date getIssued() {
return issued;
}

@Override
public void setIssued(Date issued) {
this.issued = issued;
}

@Override
public List<String> getItems() {
return items;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,17 @@ public UserSet updatePagination(UserSet userSet, UserSetConfiguration config) {
int total = userSet.getItems().size();
userSet.setTotal(total);
//NOTE: the first and last properties are not used now and might be deprecated, they should not be stored in the database
if (total > 0) {

if (total > 0) {
int first = 0;
String firstPageStr = fillPage(userSet, config, first, UserSetConfigurationImpl.DEFAULT_ITEMS_PER_PAGE);
userSet.setFirst(firstPageStr);
int last = (int) Math.ceil( (double)total / UserSetConfigurationImpl.DEFAULT_ITEMS_PER_PAGE);
if(last > 0) {
last = last - 1; // we start counting by 0
last = last - 1; // we start counting by 0
}
String lastPageStr = fillPage(userSet, config, last, UserSetConfigurationImpl.DEFAULT_ITEMS_PER_PAGE);
userSet.setLast(lastPageStr);
}
}

} else if (userSet != null && userSet.getTotal() == 0) {
// no items
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class WebUserSetFields extends WebUserSetModelFields {
public static final String PATH_PARAM_CREATOR_ID = "creator";
public static final String PATH_PARAM_LOCAL_ID = "localId";
public static final String PATH_PARAM_POSITION = "position";
public static final String REQUEST_PARAM_ISSUED = "issued";

/**
* sort order should be included in the sort param
Expand All @@ -33,6 +34,10 @@ public class WebUserSetFields extends WebUserSetModelFields {
*/
@Deprecated(since = "")
public static final String PARAM_SORT_ORDER = "sortOrder";
public static final String SORT_ORDER_DESC = "desc";
public static final String SORT_ORDER_ASC = "asc";

public static final String TEXT_SCORE_SORT = "score";

// JsonLd Constants
public static final String CONTEXT = "http://www.europeana.eu/schemas/context/collection.jsonld";
Expand Down Expand Up @@ -67,8 +72,6 @@ public class WebUserSetFields extends WebUserSetModelFields {

// Serialization Constants
public static final String SEPARATOR_SEMICOLON = ":";
public static final String SET_DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss'Z'";
// public static final String DEFAULT_USER_BASE_URL = "http://data.europeana.eu/user/";

// Entity user set and Elevation Constants
public static final String ELEVATION_FILENAME = "elevate.xml";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class WebUserSetModelFields {
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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -316,4 +317,17 @@ protected void addToCreatedSets(String identifier) {
userSet.setIdentifier(identifier);
createdUserSets.add(userSet);
}

protected String getStringValue(String jsonBody, String fieldName) throws JSONException {
JSONObject json = new JSONObject(jsonBody);
return json.getString(fieldName);
}

protected List<String> getStringListValues(String jsonBody, String fieldName) throws JSONException {
assertNotNull(jsonBody);
JSONObject json = new JSONObject(jsonBody);
return Collections.singletonList(json.getString(fieldName));
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import java.util.Collections;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -105,10 +101,10 @@ void createSetSuccessfully() throws Exception {
createdUserSets.add(createdSet);

assertNotNull(identifier);
String creator = getCreator(result);
String creator = getStringValue(result, WebUserSetModelFields.CREATOR);
assertNotNull(creator);
assertTrue(StringUtils.contains(creator, getConfiguration().getEntityUserSetUserId()));
String provider = getProvider(result);
String provider = getStringValue(result, WebUserSetModelFields.PROVIDER);
assertNotNull(provider);
// check name
assertTrue(containsKeyOrValue(provider, "Europeana XX"));
Expand All @@ -117,7 +113,7 @@ void createSetSuccessfully() throws Exception {
containsKeyOrValue(provider, "https:\\/\\/pro.europeana.eu\\/project\\/europeana-xx"));
// check subject
assertEquals("http://data.europeana.eu/concept/114", createdSet.getSubject().get(0));
assertNotNull(getSetContributors(result));
assertNotNull(getStringListValues(result, WebUserSetModelFields.CONTRIBUTOR));
}


Expand All @@ -140,18 +136,18 @@ void createSetWithProviderId() throws Exception {
createdUserSets.add(createdSet);

assertNotNull(identifier);
String creator = getCreator(result);
String creator = getStringValue(result, WebUserSetModelFields.CREATOR);
assertNotNull(creator);
assertTrue(StringUtils.contains(creator, getConfiguration().getEntityUserSetUserId()));
String provider = getProvider(result);
String provider = getStringValue(result, WebUserSetModelFields.PROVIDER);
assertNotNull(provider);
// check name - must not be present
assertFalse(containsKeyOrValue(provider, "Europeana XX"));
// check id
assertTrue(
containsKeyOrValue(provider, "https:\\/\\/pro.europeana.eu\\/project\\/europeana-xx"));

assertNotNull(getSetContributors(result));
assertNotNull(getStringListValues(result, WebUserSetModelFields.CONTRIBUTOR));
}

@Test
Expand Down Expand Up @@ -684,26 +680,6 @@ void deletePinnedItems_EntityUserSets_withEditorUser() throws Exception {

}

private String getCreator(String result) throws JSONException {
assertNotNull(result);
JSONObject json = new JSONObject(result);
String creator = json.getString(WebUserSetModelFields.CREATOR);
return creator;
}

private String getProvider(String result) throws JSONException {
assertNotNull(result);
JSONObject json = new JSONObject(result);
String provider = json.getString(WebUserSetModelFields.PROVIDER);
return provider;
}

private List<String> getSetContributors(String result) throws JSONException {
assertNotNull(result);
JSONObject json = new JSONObject(result);
return Collections.singletonList(json.getString(WebUserSetModelFields.CONTRIBUTOR));
}

private void checkItemCountAndPosition(UserSet existingUserSet, String newItem,
int expectedTotalItems, int expectedPinnedItems, int expectedPositionOfItem) {
assertEquals(expectedPinnedItems, existingUserSet.getPinned());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,20 @@ public void searchSetByTextQuery() throws Exception {
.getContentAsString();
}

@Test
public void searchSetWithoutTextQueryWithScoreSort() throws Exception {
// subject in json file: http://data.europeana.eu/concept/base/114
String query = "visibility:public";
mockMvc
.perform(get(SEARCH_URL)
.param(CommonApiConstants.QUERY_PARAM_PROFILE, LdProfiles.STANDARD.name())
.queryParam(CommonApiConstants.PARAM_WSKEY, API_KEY)
.queryParam(CommonApiConstants.QUERY_PARAM_QUERY, query)
.queryParam(CommonApiConstants.QUERY_PARAM_PAGE_SIZE, PAGE_SIZE)
.queryParam(CommonApiConstants.QUERY_PARAM_SORT, WebUserSetFields.TEXT_SCORE_SORT))
.andExpect(status().is(HttpStatus.BAD_REQUEST.value()));
}

@Test
public void searchSetByTextQueryDefault() throws Exception {
// create object in database
Expand All @@ -299,7 +313,8 @@ public void searchSetByTextQueryDefault() throws Exception {
.param(CommonApiConstants.QUERY_PARAM_PROFILE, LdProfiles.STANDARD.name())
.queryParam(CommonApiConstants.PARAM_WSKEY, API_KEY)
.queryParam(CommonApiConstants.QUERY_PARAM_QUERY, query)
.queryParam(CommonApiConstants.QUERY_PARAM_PAGE_SIZE, PAGE_SIZE))
.queryParam(CommonApiConstants.QUERY_PARAM_PAGE_SIZE, PAGE_SIZE)
.queryParam(CommonApiConstants.QUERY_PARAM_SORT, WebUserSetFields.TEXT_SCORE_SORT))
.andExpect(status().is(HttpStatus.OK.value())).andReturn().getResponse()
.getContentAsString();

Expand All @@ -316,6 +331,24 @@ public void searchSetByTextQueryDefault() throws Exception {
// getUserSetService().deleteUserSet(set.getIdentifier());
}

@Test
public void searchWithScoreSortInAscOrder() throws Exception {
// create object in database
UserSet set = createTestUserSet(USER_SET_REGULAR_PUBLIC, editorUserToken);
// subject in json file: http://data.europeana.eu/concept/base/114
final String title = set.getTitle().get("en");
// String query = "sportswear golf";
String query = title;
mockMvc
.perform(get(SEARCH_URL)
.param(CommonApiConstants.QUERY_PARAM_PROFILE, LdProfiles.STANDARD.name())
.queryParam(CommonApiConstants.PARAM_WSKEY, API_KEY)
.queryParam(CommonApiConstants.QUERY_PARAM_QUERY, query)
.queryParam(CommonApiConstants.QUERY_PARAM_PAGE_SIZE, PAGE_SIZE)
.queryParam(CommonApiConstants.QUERY_PARAM_SORT, WebUserSetFields.TEXT_SCORE_SORT + " asc"))
.andExpect(status().is(HttpStatus.BAD_REQUEST.value()));
}

@Test
public void searchSetByTextQueryWithMultipleCriteria1() throws Exception {
String query = "sportswear golf visibility:public";
Expand Down
Loading

0 comments on commit 5f0d6c7

Please sign in to comment.