Skip to content

Commit

Permalink
Merged in task/dspace-cris-2023_02_x/DSC-1958_fix (pull request DSpac…
Browse files Browse the repository at this point in the history
…e#2873)

Task/dspace cris 2023 02 x/DSC-1958

Approved-by: Vincenzo Mecca
  • Loading branch information
highhopes85 authored and vins01-4science committed Oct 16, 2024
2 parents 5780e79 + a68c659 commit 4425985
Show file tree
Hide file tree
Showing 43 changed files with 225 additions and 189 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
package org.dspace.app.rest.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.dspace.app.rest.projection.Projection;

/**
Expand Down Expand Up @@ -45,14 +46,14 @@ public void setProjection(Projection projection) {
this.projection = projection;
}

@JsonIgnore
/**
*
* @return an unique string useful to unambiguously identify the type of rest
* object. It is in the form of category.model where model is in its
* singular form. Examples include core.item, core.community,
* submission.workspaceitem, etc.
*/
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
public String getUniqueType() {
return getCategory() + "." + getType();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6434,9 +6434,11 @@ public void discoverSearchFacetValuesTest() throws Exception {
"/api/discover/facets/discoverable?configuration=administrativeView&sort=score,DESC")))
.andExpect(jsonPath("$._embedded.values", Matchers.containsInAnyOrder(
SearchResultMatcher.matchEmbeddedFacetValues("true", 2, "discover",
"/api/discover/search/objects?configuration=administrativeView&f.discoverable=true,equals"),
"/api/discover/search/objects?configuration=administrativeView&f.discoverable=true,equals",
"discover"),
SearchResultMatcher.matchEmbeddedFacetValues("false", 1, "discover",
"/api/discover/search/objects?configuration=administrativeView&f.discoverable=false,equals")
"/api/discover/search/objects?configuration=administrativeView&f.discoverable=false,equals",
"discover")
)));

}
Expand Down Expand Up @@ -6496,7 +6498,8 @@ public void discoverSearchFacetValuesPaginationTest() throws Exception {
"/api/discover/facets/discoverable?configuration=administrativeView&sort=score,DESC&page=1&size=1")))
.andExpect(jsonPath("$._embedded.values", Matchers.contains(
SearchResultMatcher.matchEmbeddedFacetValues("true", 2, "discover",
"/api/discover/search/objects?configuration=administrativeView&f.discoverable=true,equals")
"/api/discover/search/objects?configuration=administrativeView&f.discoverable=true,equals",
"discover")
)));

getClient(adminToken).perform(get("/api/discover/facets/discoverable")
Expand All @@ -6513,7 +6516,8 @@ public void discoverSearchFacetValuesPaginationTest() throws Exception {
"/api/discover/facets/discoverable?configuration=administrativeView&sort=score,DESC&page=1&size=1")))
.andExpect(jsonPath("$._embedded.values", Matchers.contains(
SearchResultMatcher.matchEmbeddedFacetValues("false", 1, "discover",
"/api/discover/search/objects?configuration=administrativeView&f.discoverable=false,equals")
"/api/discover/search/objects?configuration=administrativeView&f.discoverable=false,equals",
"discover")
)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ public static Matcher<? super Object> matchProperties(AuditEvent audit) {
hasJsonPath("$.objectType", is(audit.getObjectType())),
//we should apply the date formatter to make the check
//hasJsonPath("$.timeStamp", is(audit.getDatetime())),
hasJsonPath("$.type", is("auditevent")));
hasJsonPath("$.type", is("auditevent")),
hasJsonPath("$.uniqueType", is("system.auditevent")));
}

public static Matcher<? super Object> matchLinks(AuditEvent audit) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,14 @@ public static Matcher<? super Object> matchProperties(Authorization authz) {
if (authz != null) {
return allOf(
hasJsonPath("$.id", is(authz.getID())),
hasJsonPath("$.type", is("authorization"))
hasJsonPath("$.type", is("authorization")),
hasJsonPath("$.uniqueType", is("authz.authorization"))
);
} else {
return allOf(
hasJsonPath("$.id"),
hasJsonPath("$.type", is("authorization"))
hasJsonPath("$.type", is("authorization")),
hasJsonPath("$.uniqueType", is("authz.authorization"))
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public static Matcher<? super Object> matchBitstreamFormat(int id, String mimety
hasJsonPath("$.mimetype", is(mimetype)),
hasJsonPath("$.description", is(description)),
hasJsonPath("$.type", is("bitstreamformat")),
hasJsonPath("$.uniqueType", is("core.bitstreamformat")),
hasJsonPath("$._links.self.href", startsWith(REST_SERVER_URL)),
hasJsonPath("$._links.self.href", endsWith("/api/core/bitstreamformats/" + id))
);
Expand All @@ -43,6 +44,7 @@ public static Matcher<? super Object> matchBitstreamFormat(int id, String mimety
hasJsonPath("$.shortDescription", is(shortDescription)),
hasJsonPath("$.mimetype", is(mimetype)),
hasJsonPath("$.type", is("bitstreamformat")),
hasJsonPath("$.uniqueType", is("core.bitstreamformat")),
hasJsonPath("$._links.self.href", startsWith(REST_SERVER_URL)),
hasJsonPath("$._links.self.href", endsWith("/api/core/bitstreamformats/" + id))
);
Expand All @@ -56,6 +58,7 @@ public static Matcher<? super Object> matchBitstreamFormat(int id, String mimety
hasJsonPath("$.mimetype", is(mimetype)),
hasJsonPath("$.supportLevel", is(supportLevel)),
hasJsonPath("$.type", is("bitstreamformat")),
hasJsonPath("$.uniqueType", is("core.bitstreamformat")),
hasJsonPath("$._links.self.href", startsWith(REST_SERVER_URL)),
hasJsonPath("$._links.self.href", endsWith("/api/core/bitstreamformats/" + id))
);
Expand All @@ -65,14 +68,16 @@ public static Matcher<? super Object> matchBitstreamFormat(String mimetype, Stri
return allOf(
hasJsonPath("$.mimetype", is(mimetype)),
hasJsonPath("$.description", is(description)),
hasJsonPath("$.type", is("bitstreamformat"))
hasJsonPath("$.type", is("bitstreamformat")),
hasJsonPath("$.uniqueType", is("core.bitstreamformat"))
);
}

public static Matcher<? super Object> matchBitstreamFormatMimeType(String mimetype) {
return allOf(
hasJsonPath("$.mimetype", is(mimetype)),
hasJsonPath("$.type", is("bitstreamformat"))
hasJsonPath("$.type", is("bitstreamformat")),
hasJsonPath("$.uniqueType", is("core.bitstreamformat"))
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ private static Matcher<? super Object> matchFormat() {
return allOf(
hasJsonPath("$.mimetype", not(empty())),
hasJsonPath("$.type", is("bitstreamformat")),
hasJsonPath("$.uniqueType", is("core.bitstreamformat")),
hasJsonPath("$._links.self.href", not(empty()))
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public static Matcher<? super Object> subjectBrowseIndex(final String order) {
hasJsonPath("$.metadata", contains("dc.subject.*")),
hasJsonPath("$.browseType", equalToIgnoringCase(BROWSE_TYPE_VALUE_LIST)),
hasJsonPath("$.type", equalToIgnoringCase("browse")),
hasJsonPath("$.uniqueType", equalToIgnoringCase("discover.browse")),
hasJsonPath("$.dataType", equalToIgnoringCase("text")),
hasJsonPath("$.order", equalToIgnoringCase(order)),
hasJsonPath("$.sortOptions[*].name", containsInAnyOrder("title", "dateissued", "dateaccessioned")),
Expand All @@ -49,6 +50,7 @@ public static Matcher<? super Object> titleBrowseIndex(final String order) {
hasJsonPath("$.metadata", contains("dc.title")),
hasJsonPath("$.browseType", equalToIgnoringCase(BROWSE_TYPE_FLAT)),
hasJsonPath("$.type", equalToIgnoringCase("browse")),
hasJsonPath("$.uniqueType", equalToIgnoringCase("discover.browse")),
hasJsonPath("$.dataType", equalToIgnoringCase("title")),
hasJsonPath("$.order", equalToIgnoringCase(order)),
hasJsonPath("$.sortOptions[*].name", containsInAnyOrder("title", "dateissued", "dateaccessioned")),
Expand All @@ -62,6 +64,7 @@ public static Matcher<? super Object> contributorBrowseIndex(final String order)
hasJsonPath("$.metadata", contains("dc.contributor.*", "dc.creator")),
hasJsonPath("$.browseType", equalToIgnoringCase(BROWSE_TYPE_VALUE_LIST)),
hasJsonPath("$.type", equalToIgnoringCase("browse")),
hasJsonPath("$.uniqueType", equalToIgnoringCase("discover.browse")),
hasJsonPath("$.dataType", equalToIgnoringCase("text")),
hasJsonPath("$.order", equalToIgnoringCase(order)),
hasJsonPath("$.sortOptions[*].name", containsInAnyOrder("title", "dateissued", "dateaccessioned")),
Expand All @@ -76,6 +79,7 @@ public static Matcher<? super Object> dateIssuedBrowseIndex(final String order)
hasJsonPath("$.metadata", contains("dc.date.issued")),
hasJsonPath("$.browseType", equalToIgnoringCase(BROWSE_TYPE_FLAT)),
hasJsonPath("$.type", equalToIgnoringCase("browse")),
hasJsonPath("$.uniqueType", equalToIgnoringCase("discover.browse")),
hasJsonPath("$.dataType", equalToIgnoringCase("date")),
hasJsonPath("$.order", equalToIgnoringCase(order)),
hasJsonPath("$.sortOptions[*].name", containsInAnyOrder("title", "dateissued", "dateaccessioned")),
Expand Down Expand Up @@ -160,6 +164,7 @@ public static Matcher<? super Object> typesBrowseIndex() {
hasJsonPath("$.browseType", is("hierarchicalBrowse")),
hasJsonPath("$.facetType", is("itemtype")),
hasJsonPath("$.type", is("browse")),
hasJsonPath("$.uniqueType", is("discover.browse")),
hasJsonPath("$._links.self.href", is(REST_SERVER_URL + "discover/browses/types")),
hasJsonPath("$._links.items.href", is(REST_SERVER_URL + "discover/browses/types/items"))
);
Expand All @@ -172,6 +177,7 @@ public static Matcher<? super Object> hierarchicalBrowseIndex(
hasJsonPath("$.metadata", contains(metadata)),
hasJsonPath("$.browseType", equalToIgnoringCase(BROWSE_TYPE_HIERARCHICAL)),
hasJsonPath("$.type", equalToIgnoringCase("browse")),
hasJsonPath("$.uniqueType", equalToIgnoringCase("discover.browse")),
hasJsonPath("$.facetType", equalToIgnoringCase(facetType)),
hasJsonPath("$.vocabulary", equalToIgnoringCase(vocabulary)),
hasJsonPath("$._links.vocabulary.href",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public static Matcher<? super Object> matchProperties(String name, UUID uuid, St
hasJsonPath("$.name", is(name)),
hasJsonPath("$.handle", is(handle)),
hasJsonPath("$.type", is(Constants.typeText[type].toLowerCase())),
hasJsonPath("$.uniqueType", is(String.format("core.%s",Constants.typeText[type].toLowerCase()))),
hasJsonPath("$.metadata", Matchers.allOf(
MetadataMatcher.matchMetadata("dc.title", name)
))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ public static Matcher matchClaimedTask(ClaimedTask cTask, String step) {
public static Matcher<? super Object> matchProperties(ClaimedTask cTask) {
return allOf(
cTask != null ? hasJsonPath("$.id", is(cTask.getID())) : hasJsonPath("$.id"),
hasJsonPath("$.type", is("claimedtask"))
hasJsonPath("$.type", is("claimedtask")),
hasJsonPath("$.uniqueType", is("workflow.claimedtask"))
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public static Matcher<? super Object> matchProperties(String name, UUID uuid, St
hasJsonPath("$.name", is(name)),
hasJsonPath("$.handle", is(handle)),
hasJsonPath("$.type", is("collection")),
hasJsonPath("$.uniqueType", is("core.collection")),
hasJsonPath("$.metadata", Matchers.allOf(
MetadataMatcher.matchMetadata("dc.title", name)
)));
Expand Down Expand Up @@ -137,6 +138,7 @@ public static Matcher<? super Object> matchCollection(Collection collection) {
return allOf(hasJsonPath("$.uuid", is(collection.getID().toString())),
hasJsonPath("$.name", is(collection.getName())),
hasJsonPath("$.type", is("collection")),
hasJsonPath("$.uniqueType", is("core.collection")),
hasJsonPath("$.handle", is(collection.getHandle())));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import java.util.List;
import java.util.UUID;

import org.dspace.content.Collection;
import org.dspace.content.Community;
import org.hamcrest.Matcher;
import org.hamcrest.Matchers;
Expand All @@ -32,6 +31,7 @@ public static Matcher<? super Object> matchCommunityEntry(UUID uuid, String hand
hasJsonPath("$.uuid", is(uuid.toString())),
hasJsonPath("$.handle", is(handle)),
hasJsonPath("$.type", is("community")),
hasJsonPath("$.uniqueType", is("core.community")),
matchLinks(uuid)
);
}
Expand All @@ -45,6 +45,7 @@ public static Matcher<? super Object> matchCommunityEntryMultipleTitles(List<Str
hasJsonPath("$.name", is(titles.get(0))),
hasJsonPath("$.handle", is(handle)),
hasJsonPath("$.type", is("community")),
hasJsonPath("$.uniqueType", is("core.community")),
hasJsonPath("$._embedded.collections", Matchers.not(Matchers.empty())),
hasJsonPath("$._embedded.logo", Matchers.not(Matchers.empty())),
matchLinks(uuid)
Expand Down Expand Up @@ -84,6 +85,7 @@ public static Matcher<? super Object> matchProperties(String name, UUID uuid, St
hasJsonPath("$.name", is(name)),
hasJsonPath("$.handle", is(handle)),
hasJsonPath("$.type", is("community")),
hasJsonPath("$.uniqueType", is("core.community")),
hasJsonPath("$.metadata", Matchers.allOf(
MetadataMatcher.matchMetadata("dc.title", name)
))
Expand Down Expand Up @@ -129,18 +131,6 @@ public static Matcher<? super Object> matchLinks(UUID uuid) {
);
}

public static Matcher<? super Object> matchCommunityWithCollectionEntry(String name, UUID uuid, String handle,
Collection col) {
return allOf(
matchProperties(name, uuid, handle),
hasJsonPath("$._embedded.collections._embedded.collections[0]",
CollectionMatcher
.matchCollectionEntry(col.getName(), col.getID(), col.getHandle(), col.getLogo())),
hasJsonPath("$._embedded.logo", Matchers.not(Matchers.empty())),
matchLinks(uuid)
);
}

public static String getNonAdminEmbeds() {
return "collections,logo,parentCommunity,subcommunities";
}
Expand All @@ -149,6 +139,7 @@ public static Matcher<? super Object> matchCommunity(Community community) {
return allOf(hasJsonPath("$.uuid", is(community.getID().toString())),
hasJsonPath("$.name", is(community.getName())),
hasJsonPath("$.type", is("community")),
hasJsonPath("$.uniqueType", is("core.community")),
hasJsonPath("$.handle", is(community.getHandle())));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,19 @@ public static Matcher<? super Object> matchCrisMetrics(CrisMetrics crisMetrics)
hasJsonPath("$.deltaPeriod1", is(crisMetrics.getDeltaPeriod1())),
hasJsonPath("$.deltaPeriod2", is(crisMetrics.getDeltaPeriod2())),
hasJsonPath("$.rank", is(crisMetrics.getRank())),
hasJsonPath("$.type", is(CrisMetricsRest.NAME))
hasJsonPath("$.type", is(CrisMetricsRest.NAME)),
hasJsonPath("$.uniqueType", is("cris.metric"))
);
}

public static Matcher<? super Object> matchCrisDynamicMetrics(UUID itemUuid, String type, String remark) {
return allOf(
hasJsonPath("$.id", itemUuid != null ?
is(itemUuid.toString() + ":" + type) :
is(itemUuid + ":" + type) :
Matchers.endsWith("-" + type)),
hasJsonPath("$.metricType", is(type)),
hasJsonPath("$.type", is(CrisMetricsRest.NAME)),
hasJsonPath("$.uniqueType", is("cris.metric")),
hasJsonPath("$.remark", containsString(remark))
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public static Matcher<? super Object> matchEPersonEntry(EPerson ePerson) {
public static Matcher<? super Object> matchEPersonOnEmail(String email) {
return allOf(
hasJsonPath("$.type", is("eperson")),
hasJsonPath("$.uniqueType", is("eperson.eperson")),
hasJsonPath("$.email", is(email))
);
}
Expand All @@ -50,17 +51,12 @@ public static Matcher<? super Object> matchEPersonWithGroups(String email, Strin

return allOf(
hasJsonPath("$.type", is("eperson")),
hasJsonPath("$.uniqueType", is("eperson.eperson")),
hasJsonPath("$.email", is(email)),
hasJsonPath("$._embedded.groups._embedded.groups", containsInAnyOrder(
matchers)));
}

public static Matcher<? super Object> matchDefaultTestEPerson() {
return allOf(
hasJsonPath("$.type", is("eperson"))
);
}

/**
* Gets a matcher for all expected embeds when the full projection is requested.
*/
Expand All @@ -85,6 +81,7 @@ public static Matcher<? super Object> matchProperties(EPerson ePerson) {
hasJsonPath("$.uuid", is(ePerson.getID().toString())),
hasJsonPath("$.name", is(ePerson.getName())),
hasJsonPath("$.type", is("eperson")),
hasJsonPath("$.uniqueType", is("eperson.eperson")),
hasJsonPath("$.canLogIn", not(empty())),
hasJsonPath("$.metadata", Matchers.allOf(
MetadataMatcher.matchMetadata("eperson.firstname", ePerson.getFirstName()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public static Matcher<? super Object> matchEntityTypeExplicitValuesEntry(int id,
matchId(id),
hasJsonPath("$.label", is(label)),
hasJsonPath("$.type", is("entitytype")),
hasJsonPath("$.uniqueType", is("core.entitytype")),
matchSelfLink(id)
);
}
Expand Down
Loading

0 comments on commit 4425985

Please sign in to comment.