Skip to content

Commit

Permalink
[DSC-1819] edit cris consumer to add entity type to the item if not e…
Browse files Browse the repository at this point in the history
…xist
  • Loading branch information
eskander committed Jul 15, 2024
1 parent 8252696 commit 13dd385
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
15 changes: 15 additions & 0 deletions dspace-api/src/main/java/org/dspace/authority/CrisConsumer.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ public void consume(Context context, Event event) throws Exception {

private void consumeItem(Context context, Item item) throws Exception {

addEntityTypeIfNotExist(context, item);

for (MetadataValue metadata : item.getMetadata()) {

String fieldKey = getFieldKey(metadata);
Expand Down Expand Up @@ -185,6 +187,19 @@ private void consumeItem(Context context, Item item) throws Exception {

}

private void addEntityTypeIfNotExist(Context context, Item item) throws SQLException {
String entityType = itemService.getEntityType(item);
if (StringUtils.isBlank(entityType)) {
Collection collection = item.getOwningCollection();
if (collection != null) {
String collectionEntityType = collectionService.getEntityType(collection);
if (StringUtils.isNotBlank(collectionEntityType)) {
itemService.addMetadata(context, item, "dspace", "entity", "type", null, collectionEntityType);
}
}
}
}

private boolean isMetadataSkippable(MetadataValue metadata) {

String authority = metadata.getAuthority();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertNull;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.matches;
Expand Down Expand Up @@ -1205,6 +1206,29 @@ public void testSherpaImportFiller() throws Exception {
}
}

@Test
public void testAddItemEntityTypeIfNotExit() throws Exception {

InputStream pdf = simpleArticle.getInputStream();

WorkspaceItem wsitem = WorkspaceItemBuilder.createWorkspaceItem(context, publicationCollection)
.withTitle("Submission Item")
.withIssueDate("2017-10-17")
.withFulltext("simple-article.pdf", "/local/path/simple-article.pdf", pdf)
.grantLicense()
.build();

// clear the entity type metadata
itemService.clearMetadata(context, wsitem.getItem(), "dspace", "entity", "type", null);
assertNull(itemService.getEntityType(wsitem.getItem()));

String authToken = getAuthToken(submitter.getEmail(), password);
submitItemViaRest(authToken, wsitem.getID());

// check that the entity type equals to the entity type of the owning collection
assertThat(itemService.getEntityType(context.reloadEntity(wsitem.getItem())), is("Publication"));
}

private ItemRest getItemViaRestByID(String authToken, UUID id) throws Exception {
MvcResult result = getClient(authToken)
.perform(get(BASE_REST_SERVER_URL + "/api/core/items/{id}", id))
Expand Down

0 comments on commit 13dd385

Please sign in to comment.