From 3b04f4c461d341ac6c10c3709db1c68e41717838 Mon Sep 17 00:00:00 2001 From: eskander Date: Mon, 15 Jul 2024 11:46:00 +0300 Subject: [PATCH 1/3] [DSC-1818] edit cris consumer to add entity type to the item if not exist --- .../org/dspace/authority/CrisConsumer.java | 15 ++++++++++++ .../org/dspace/authority/CrisConsumerIT.java | 24 +++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/dspace-api/src/main/java/org/dspace/authority/CrisConsumer.java b/dspace-api/src/main/java/org/dspace/authority/CrisConsumer.java index a83cc8692e3..826a4b72597 100644 --- a/dspace-api/src/main/java/org/dspace/authority/CrisConsumer.java +++ b/dspace-api/src/main/java/org/dspace/authority/CrisConsumer.java @@ -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); @@ -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(); diff --git a/dspace-server-webapp/src/test/java/org/dspace/authority/CrisConsumerIT.java b/dspace-server-webapp/src/test/java/org/dspace/authority/CrisConsumerIT.java index 2d887caa7b2..4e8af0e1ff7 100644 --- a/dspace-server-webapp/src/test/java/org/dspace/authority/CrisConsumerIT.java +++ b/dspace-server-webapp/src/test/java/org/dspace/authority/CrisConsumerIT.java @@ -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; @@ -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)) From 8252696af2853b16a0edf23328b04328adb19c56 Mon Sep 17 00:00:00 2001 From: eskander Date: Mon, 15 Jul 2024 11:51:51 +0300 Subject: [PATCH 2/3] Revert "[DSC-1818] edit cris consumer to add entity type to the item if not exist" This reverts commit 3b04f4c461d341ac6c10c3709db1c68e41717838. --- .../org/dspace/authority/CrisConsumer.java | 15 ------------ .../org/dspace/authority/CrisConsumerIT.java | 24 ------------------- 2 files changed, 39 deletions(-) diff --git a/dspace-api/src/main/java/org/dspace/authority/CrisConsumer.java b/dspace-api/src/main/java/org/dspace/authority/CrisConsumer.java index 826a4b72597..a83cc8692e3 100644 --- a/dspace-api/src/main/java/org/dspace/authority/CrisConsumer.java +++ b/dspace-api/src/main/java/org/dspace/authority/CrisConsumer.java @@ -138,8 +138,6 @@ 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); @@ -187,19 +185,6 @@ 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(); diff --git a/dspace-server-webapp/src/test/java/org/dspace/authority/CrisConsumerIT.java b/dspace-server-webapp/src/test/java/org/dspace/authority/CrisConsumerIT.java index 4e8af0e1ff7..2d887caa7b2 100644 --- a/dspace-server-webapp/src/test/java/org/dspace/authority/CrisConsumerIT.java +++ b/dspace-server-webapp/src/test/java/org/dspace/authority/CrisConsumerIT.java @@ -20,7 +20,6 @@ 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; @@ -1206,29 +1205,6 @@ 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)) From 13dd385d30ec02e25cb507272e938625fc15de5b Mon Sep 17 00:00:00 2001 From: eskander Date: Mon, 15 Jul 2024 11:53:44 +0300 Subject: [PATCH 3/3] [DSC-1819] edit cris consumer to add entity type to the item if not exist --- .../org/dspace/authority/CrisConsumer.java | 15 ++++++++++++ .../org/dspace/authority/CrisConsumerIT.java | 24 +++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/dspace-api/src/main/java/org/dspace/authority/CrisConsumer.java b/dspace-api/src/main/java/org/dspace/authority/CrisConsumer.java index a83cc8692e3..826a4b72597 100644 --- a/dspace-api/src/main/java/org/dspace/authority/CrisConsumer.java +++ b/dspace-api/src/main/java/org/dspace/authority/CrisConsumer.java @@ -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); @@ -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(); diff --git a/dspace-server-webapp/src/test/java/org/dspace/authority/CrisConsumerIT.java b/dspace-server-webapp/src/test/java/org/dspace/authority/CrisConsumerIT.java index 2d887caa7b2..4e8af0e1ff7 100644 --- a/dspace-server-webapp/src/test/java/org/dspace/authority/CrisConsumerIT.java +++ b/dspace-server-webapp/src/test/java/org/dspace/authority/CrisConsumerIT.java @@ -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; @@ -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))