Skip to content

Commit

Permalink
Merge pull request DSpace#9469 from tdonohue/fix_oai_error
Browse files Browse the repository at this point in the history
Fix OAI indexing error & AuthorityConsumer error
  • Loading branch information
tdonohue authored Apr 11, 2024
2 parents 3922878 + 2a533e7 commit 78010b0
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
29 changes: 20 additions & 9 deletions dspace-api/src/main/java/org/dspace/content/EntityServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<MetadataValue> 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
Expand Down Expand Up @@ -103,7 +99,12 @@ public List<RelationshipType> getAllRelationshipTypes(Context context, Entity en
@Override
public List<RelationshipType> 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
Expand All @@ -115,7 +116,12 @@ public List<RelationshipType> getLeftRelationshipTypes(Context context, Entity e
@Override
public List<RelationshipType> 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
Expand All @@ -128,7 +134,12 @@ public List<RelationshipType> getRightRelationshipTypes(Context context, Entity
public List<RelationshipType> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 78010b0

Please sign in to comment.