diff --git a/dspace-api/src/main/java/org/dspace/content/DSpaceObjectServiceImpl.java b/dspace-api/src/main/java/org/dspace/content/DSpaceObjectServiceImpl.java index 2119959073f0..ba4bce0de7d3 100644 --- a/dspace-api/src/main/java/org/dspace/content/DSpaceObjectServiceImpl.java +++ b/dspace-api/src/main/java/org/dspace/content/DSpaceObjectServiceImpl.java @@ -629,6 +629,7 @@ public void update(Context context, T dso) throws SQLException, AuthorizeExcepti // E.g. for an Author relationship, // the place should be updated using the same principle as dc.contributor.author. StringUtils.startsWith(metadataValue.getAuthority(), Constants.VIRTUAL_AUTHORITY_PREFIX) + && metadataValue instanceof RelationshipMetadataValue && ((RelationshipMetadataValue) metadataValue).isUseForPlace() ) { int mvPlace = getMetadataValuePlace(fieldToLastPlace, metadataValue); diff --git a/dspace-api/src/main/java/org/dspace/content/EntityServiceImpl.java b/dspace-api/src/main/java/org/dspace/content/EntityServiceImpl.java index 2f34129f2e69..9b28203827e0 100644 --- a/dspace-api/src/main/java/org/dspace/content/EntityServiceImpl.java +++ b/dspace-api/src/main/java/org/dspace/content/EntityServiceImpl.java @@ -8,6 +8,7 @@ package org.dspace.content; import java.sql.SQLException; +import java.util.Collections; import java.util.LinkedList; import java.util.List; import java.util.UUID; @@ -51,12 +52,7 @@ public Entity findByItemId(Context context, UUID itemId, Integer limit, Integer @Override public EntityType getType(Context context, Entity entity) throws SQLException { Item item = entity.getItem(); - List list = itemService.getMetadata(item, "dspace", "entity", "type", Item.ANY, false); - if (!list.isEmpty()) { - return entityTypeService.findByEntityType(context, list.get(0).getValue()); - } else { - return null; - } + return itemService.getEntityType(context, item); } @Override @@ -103,7 +99,12 @@ public List getAllRelationshipTypes(Context context, Entity en @Override public List getAllRelationshipTypes(Context context, Entity entity, Integer limit, Integer offset) throws SQLException { - return relationshipTypeService.findByEntityType(context, this.getType(context, entity), limit, offset); + EntityType entityType = this.getType(context, entity); + if (entityType != null) { + return relationshipTypeService.findByEntityType(context, entityType, limit, offset); + } else { + return Collections.emptyList(); + } } @Override @@ -115,7 +116,12 @@ public List getLeftRelationshipTypes(Context context, Entity e @Override public List getLeftRelationshipTypes(Context context, Entity entity, boolean isLeft, Integer limit, Integer offset) throws SQLException { - return relationshipTypeService.findByEntityType(context, this.getType(context, entity), isLeft, limit, offset); + EntityType entityType = this.getType(context, entity); + if (entityType != null) { + return relationshipTypeService.findByEntityType(context, entityType, isLeft, limit, offset); + } else { + return Collections.emptyList(); + } } @Override @@ -128,7 +134,12 @@ public List getRightRelationshipTypes(Context context, Entity public List getRightRelationshipTypes(Context context, Entity entity, boolean isLeft, Integer limit, Integer offset) throws SQLException { - return relationshipTypeService.findByEntityType(context, this.getType(context, entity), isLeft, limit, offset); + EntityType entityType = this.getType(context, entity); + if (entityType != null) { + return relationshipTypeService.findByEntityType(context, entityType, isLeft, limit, offset); + } else { + return Collections.emptyList(); + } } @Override diff --git a/dspace-api/src/test/java/org/dspace/content/EntityServiceImplTest.java b/dspace-api/src/test/java/org/dspace/content/EntityServiceImplTest.java index 305ebff69710..11fbbb9f9119 100644 --- a/dspace-api/src/test/java/org/dspace/content/EntityServiceImplTest.java +++ b/dspace-api/src/test/java/org/dspace/content/EntityServiceImplTest.java @@ -145,6 +145,7 @@ public void testGetAllRelationshipTypes() throws Exception { // Declare objects utilized for this test Item item = mock(Item.class); Entity entity = mock(Entity.class); + EntityType entityType = mock(EntityType.class); RelationshipType relationshipType = mock(RelationshipType.class); relationshipType.setLeftType(leftType); relationshipType.setLeftType(rightType); @@ -156,7 +157,8 @@ public void testGetAllRelationshipTypes() throws Exception { // Mock the state of objects utilized in getAllRelationshipTypes() // to meet the success criteria of the invocation when(entity.getItem()).thenReturn(item); - when(relationshipTypeService.findByEntityType(context, entityService.getType(context, entity), -1, -1)) + when(entityService.getType(context, entity)).thenReturn(entityType); + when(relationshipTypeService.findByEntityType(context, entityType, -1, -1)) .thenReturn(relationshipTypeList); // The relation(s) reported from our mocked Entity should match our relationshipList @@ -181,10 +183,9 @@ public void testGetLeftRelationshipTypes() throws Exception { // Mock the state of objects utilized in getLeftRelationshipTypes() // to meet the success criteria of the invocation - when(itemService.getMetadata(item, "dspace", "entity", "type", Item.ANY, false)).thenReturn(metsList); when(entity.getItem()).thenReturn(item); when(entityService.getType(context, entity)).thenReturn(entityType); - when(relationshipTypeService.findByEntityType(context, entityService.getType(context, entity), true, -1, -1)) + when(relationshipTypeService.findByEntityType(context, entityType, true, -1, -1)) .thenReturn(relationshipTypeList); // The left relationshipType(s) reported from our mocked Entity should match our relationshipList @@ -209,10 +210,9 @@ public void testGetRightRelationshipTypes() throws Exception { // Mock the state of objects utilized in getRightRelationshipTypes() // to meet the success criteria of the invocation - when(itemService.getMetadata(item, "dspace", "entity", "type", Item.ANY, false)).thenReturn(metsList); when(entity.getItem()).thenReturn(item); when(entityService.getType(context, entity)).thenReturn(entityType); - when(relationshipTypeService.findByEntityType(context, entityService.getType(context, entity), false, -1, -1)) + when(relationshipTypeService.findByEntityType(context, entityType, false, -1, -1)) .thenReturn(relationshipTypeList); // The right relationshipType(s) reported from our mocked Entity should match our relationshipList