Merge pull request #2418 from atmire/entities-feedback-2019-04

Configurable entities feedback
This commit is contained in:
Tim Donohue
2019-05-09 12:01:37 -05:00
committed by GitHub
6 changed files with 118 additions and 95 deletions

View File

@@ -1501,17 +1501,16 @@ prevent the generation of resource policy entry values with null dspace_object a
}
private String getEntityTypeStringFromMetadata(List<MetadataValue> list) {
String entityType = null;
for (MetadataValue mdv : list) {
if (StringUtils.equals(mdv.getMetadataField().getMetadataSchema().getName(),
"relationship")
&& StringUtils.equals(mdv.getMetadataField().getElement(),
"type")) {
entityType = mdv.getValue();
return mdv.getValue();
}
}
return entityType;
return null;
}
private RelationshipMetadataValue constructResultingMetadataValue(Item item, String value,

View File

@@ -248,10 +248,7 @@ public class RelationshipServiceImpl implements RelationshipService {
return false;
}
String leftEntityType = list.get(0).getValue();
if (!StringUtils.equals(leftEntityType, entityTypeToProcess.getLabel())) {
return false;
}
return true;
return StringUtils.equals(leftEntityType, entityTypeToProcess.getLabel());
}
public Relationship find(Context context, int id) throws SQLException {

View File

@@ -20,6 +20,7 @@ import org.dspace.core.Context;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.rest.webmvc.ResourceNotFoundException;
import org.springframework.stereotype.Component;
/**
@@ -36,7 +37,11 @@ public class EntityTypeRestRepository extends DSpaceRestRepository<EntityTypeRes
public EntityTypeRest findOne(Context context, Integer integer) {
try {
return entityTypeConverter.fromModel(entityTypeService.find(context, integer));
EntityType entityType = entityTypeService.find(context, integer);
if (entityType == null) {
throw new ResourceNotFoundException("The entityType for ID: " + integer + " could not be found");
}
return entityTypeConverter.fromModel(entityType);
} catch (SQLException e) {
throw new RuntimeException(e.getMessage(), e);
}

View File

@@ -146,8 +146,8 @@ public class WorkflowItemRestRepository extends DSpaceRestRepository<WorkflowIte
@Override
protected WorkflowItemRest createAndReturn(Context context, List<String> stringList) {
XmlWorkflowItem source;
if (stringList.isEmpty()) {
throw new UnprocessableEntityException("The given URI list could not be parsed and is empty as a result");
if (stringList == null || stringList.isEmpty() || stringList.size() > 1) {
throw new UnprocessableEntityException("The given URI list could not be properly parsed to one result");
}
try {
source = submissionService.createWorkflowItem(context, stringList.get(0));

View File

@@ -10,14 +10,10 @@ package org.dspace.app.rest;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import java.sql.SQLException;
import org.dspace.app.rest.matcher.EntityTypeMatcher;
import org.dspace.app.rest.test.AbstractEntityIntegrationTest;
import org.dspace.content.EntityType;
@@ -31,59 +27,6 @@ public class EntityTypeRestRepositoryIT extends AbstractEntityIntegrationTest {
@Autowired
private EntityTypeService entityTypeService;
@Test
public void findAllEntityTypesSizeTest() throws SQLException {
assertEquals(7, entityTypeService.findAll(context).size());
}
@Test
public void findPublicationEntityTypeTest() throws SQLException {
String type = "Publication";
checkEntityType(type);
}
@Test
public void findPersonEntityTypeTest() throws SQLException {
String type = "Person";
checkEntityType(type);
}
@Test
public void findProjectEntityTypeTest() throws SQLException {
String type = "Project";
checkEntityType(type);
}
@Test
public void findOrgUnitEntityTypeTest() throws SQLException {
String type = "OrgUnit";
checkEntityType(type);
}
@Test
public void findJournalEntityTypeTest() throws SQLException {
String type = "Journal";
checkEntityType(type);
}
@Test
public void findJournalVolumeEntityTypeTest() throws SQLException {
String type = "JournalVolume";
checkEntityType(type);
}
@Test
public void findJournalIssueEntityTypeTest() throws SQLException {
String type = "JournalIssue";
checkEntityType(type);
}
private void checkEntityType(String type) throws SQLException {
EntityType entityType = entityTypeService.findByEntityType(context, type);
assertNotNull(entityType);
assertEquals(type, entityType.getLabel());
}
@Test
public void getAllEntityTypeEndpoint() throws Exception {
//When we call this facets endpoint
@@ -109,4 +52,60 @@ public class EntityTypeRestRepositoryIT extends AbstractEntityIntegrationTest {
.matchEntityTypeEntry(entityTypeService.findByEntityType(context, "JournalIssue"))
)));
}
@Test
public void getAllEntityTypeEndpointWithPaging() throws Exception {
getClient().perform(get("/api/core/entitytypes").param("size", "5"))
//We expect a 200 OK status
.andExpect(status().isOk())
//The type has to be 'discover'
.andExpect(jsonPath("$.page.size", is(5)))
.andExpect(jsonPath("$.page.totalElements", is(7)))
.andExpect(jsonPath("$.page.totalPages", is(2)))
//There needs to be a self link to this endpoint
.andExpect(jsonPath("$._links.self.href", containsString("api/core/entitytypes")))
//We have 4 facets in the default configuration, they need to all be present in the embedded section
.andExpect(jsonPath("$._embedded.entitytypes", containsInAnyOrder(
EntityTypeMatcher
.matchEntityTypeEntry(entityTypeService.findByEntityType(context, "Publication")),
EntityTypeMatcher.matchEntityTypeEntry(entityTypeService.findByEntityType(context, "Person")),
EntityTypeMatcher.matchEntityTypeEntry(entityTypeService.findByEntityType(context, "Project")),
EntityTypeMatcher.matchEntityTypeEntry(entityTypeService.findByEntityType(context, "OrgUnit")),
EntityTypeMatcher.matchEntityTypeEntry(entityTypeService.findByEntityType(context, "Journal"))
)));
getClient().perform(get("/api/core/entitytypes").param("size", "5").param("page", "1"))
//We expect a 200 OK status
.andExpect(status().isOk())
//The type has to be 'discover'
.andExpect(jsonPath("$.page.size", is(5)))
.andExpect(jsonPath("$.page.totalElements", is(7)))
.andExpect(jsonPath("$.page.totalPages", is(2)))
.andExpect(jsonPath("$.page.number", is(1)))
//There needs to be a self link to this endpoint
.andExpect(jsonPath("$._links.self.href", containsString("api/core/entitytypes")))
//We have 4 facets in the default configuration, they need to all be present in the embedded section
.andExpect(jsonPath("$._embedded.entitytypes", containsInAnyOrder(
EntityTypeMatcher
.matchEntityTypeEntry(entityTypeService.findByEntityType(context, "JournalVolume")),
EntityTypeMatcher
.matchEntityTypeEntry(entityTypeService.findByEntityType(context, "JournalIssue"))
)));
}
@Test
public void retrieveOneEntityType() throws Exception {
EntityType entityType = entityTypeService.findByEntityType(context, "Publication");
getClient().perform(get("/api/core/entitytypes/" + entityType.getID()))
.andExpect(status().isOk())
.andExpect(jsonPath("$", EntityTypeMatcher.matchEntityTypeEntry(entityType)));
}
@Test
public void retrieveOneEntityTypeThatDoesNotExist() throws Exception {
getClient().perform(get("/api/core/entitytypes/" + 5555))
.andExpect(status().isNotFound());
}
}

View File

@@ -7,6 +7,7 @@
*/
package org.dspace.app.rest;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertEquals;
@@ -25,6 +26,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.lang3.StringUtils;
import org.dspace.app.rest.builder.CollectionBuilder;
import org.dspace.app.rest.builder.CommunityBuilder;
import org.dspace.app.rest.builder.EPersonBuilder;
import org.dspace.app.rest.builder.ItemBuilder;
import org.dspace.app.rest.builder.RelationshipBuilder;
import org.dspace.app.rest.matcher.PageMatcher;
@@ -160,6 +162,28 @@ public class RelationshipRestRepositoryIT extends AbstractEntityIntegrationTest
RelationshipMatcher.matchRelationship(relationship3)
)))
;
getClient().perform(get("/api/core/relationships").param("size", "2"))
.andExpect(status().isOk())
.andExpect(jsonPath("$.page",
is(PageMatcher.pageEntryWithTotalPagesAndElements(0, 2, 2, 3))))
.andExpect(jsonPath("$._embedded.relationships", containsInAnyOrder(
RelationshipMatcher.matchRelationship(relationship1),
RelationshipMatcher.matchRelationship(relationship2)
)))
;
getClient().perform(get("/api/core/relationships").param("size", "2").param("page", "1"))
.andExpect(status().isOk())
.andExpect(jsonPath("$.page",
is(PageMatcher.pageEntryWithTotalPagesAndElements(1, 2, 2, 3))))
.andExpect(jsonPath("$._embedded.relationships", contains(
RelationshipMatcher.matchRelationship(relationship3)
)))
;
}
@Test
@@ -197,16 +221,8 @@ public class RelationshipRestRepositoryIT extends AbstractEntityIntegrationTest
"isAuthorOfPublication", "isPublicationOfAuthor");
EPerson user = ePersonService.create(context);
user.setFirstName(context, "first");
user.setLastName(context, "last");
user.setEmail("testaze@email.com");
user.setCanLogIn(true);
user.setLanguage(context, I18nUtil.getDefaultLocale().getLanguage());
ePersonService.setPassword(user, password);
// actually save the eperson to unit testing DB
ePersonService.update(context, user);
EPerson user = EPersonBuilder.createEPerson(context).withEmail("testaze@email.com")
.withNameInMetadata("first", "last").withPassword(password).build();
context.setCurrentUser(user);
authorizeService.addPolicy(context, publication, Constants.WRITE, user);
@@ -228,6 +244,17 @@ public class RelationshipRestRepositoryIT extends AbstractEntityIntegrationTest
.andExpect(status().isCreated())
.andReturn();
ObjectMapper mapper = new ObjectMapper();
String content = mvcResult.getResponse().getContentAsString();
Map<String, Object> map = mapper.readValue(content, Map.class);
String firstRelationshipIdString = String.valueOf(map.get("id"));
getClient().perform(get("/api/core/relationships/" + firstRelationshipIdString))
.andExpect(status().isOk())
.andExpect(jsonPath("$.leftId", is(publication.getID().toString())))
.andExpect(jsonPath("$.rightId", is(author1.getID().toString())));
}
@Test
@@ -266,15 +293,8 @@ public class RelationshipRestRepositoryIT extends AbstractEntityIntegrationTest
EPerson user = ePersonService.create(context);
user.setFirstName(context, "first");
user.setLastName(context, "last");
user.setEmail("testazhfhdfhe@email.com");
user.setCanLogIn(true);
user.setLanguage(context, I18nUtil.getDefaultLocale().getLanguage());
ePersonService.setPassword(user, password);
// actually save the eperson to unit testing DB
ePersonService.update(context, user);
EPerson user = EPersonBuilder.createEPerson(context).withEmail("testaze@email.com")
.withNameInMetadata("first", "last").withPassword(password).build();
context.setCurrentUser(user);
authorizeService.addPolicy(context, author1, Constants.WRITE, user);
@@ -295,6 +315,16 @@ public class RelationshipRestRepositoryIT extends AbstractEntityIntegrationTest
.andExpect(status().isCreated())
.andReturn();
ObjectMapper mapper = new ObjectMapper();
String content = mvcResult.getResponse().getContentAsString();
Map<String, Object> map = mapper.readValue(content, Map.class);
String firstRelationshipIdString = String.valueOf(map.get("id"));
getClient().perform(get("/api/core/relationships/" + firstRelationshipIdString))
.andExpect(status().isOk())
.andExpect(jsonPath("$.leftId", is(publication.getID().toString())))
.andExpect(jsonPath("$.rightId", is(author1.getID().toString())));
}
@@ -334,15 +364,8 @@ public class RelationshipRestRepositoryIT extends AbstractEntityIntegrationTest
EPerson user = ePersonService.create(context);
user.setFirstName(context, "first");
user.setLastName(context, "last");
user.setEmail("testazeazeazezae@email.com");
user.setCanLogIn(true);
user.setLanguage(context, I18nUtil.getDefaultLocale().getLanguage());
ePersonService.setPassword(user, password);
// actually save the eperson to unit testing DB
ePersonService.update(context, user);
EPerson user = EPersonBuilder.createEPerson(context).withEmail("testaze@email.com")
.withNameInMetadata("first", "last").withPassword(password).build();
context.setCurrentUser(user);
context.restoreAuthSystemState();