From fb252cf576458e3cab4b054e4a3ee8b2fc5518bb Mon Sep 17 00:00:00 2001 From: milanmajchrak <90026355+milanmajchrak@users.noreply.github.com> Date: Thu, 21 Sep 2023 15:35:05 +0200 Subject: [PATCH] ufal/be-confidence-authority-not-imported (#438) * Configured `dc.relation` for controlled authority and created test. * Updated VersioningWithRelationshipsTest - updated adding dc.relation metadata. --- .../test/data/dspaceFolder/config/local.cfg | 3 + .../VersioningWithRelationshipsTest.java | 6 +- .../rest/ClarinItemImportControllerIT.java | 60 +++++++++++++++++++ dspace/config/clarin-dspace.cfg | 5 ++ 4 files changed, 71 insertions(+), 3 deletions(-) diff --git a/dspace-api/src/test/data/dspaceFolder/config/local.cfg b/dspace-api/src/test/data/dspaceFolder/config/local.cfg index f3f01989a43b..84f89de4398f 100644 --- a/dspace-api/src/test/data/dspaceFolder/config/local.cfg +++ b/dspace-api/src/test/data/dspaceFolder/config/local.cfg @@ -268,3 +268,6 @@ versioning.enabled=true ### PID config lr.pid.community.configurations = community=47501cdc-e2eb-44e5-85e0-89a31dc8ceee, prefix=123456789, type=epic, canonical_prefix=http://hdl.handle.net/, subprefix=1 lr.pid.community.configurations = community=*, prefix=123456789, type=local, canonical_prefix=http://hdl.handle.net/, subprefix=2 + +#### Authority configuration `authority.cfg` +authority.controlled.dc.relation = true diff --git a/dspace-api/src/test/java/org/dspace/content/VersioningWithRelationshipsTest.java b/dspace-api/src/test/java/org/dspace/content/VersioningWithRelationshipsTest.java index 528568c4e5fb..88bde022f78a 100644 --- a/dspace-api/src/test/java/org/dspace/content/VersioningWithRelationshipsTest.java +++ b/dspace-api/src/test/java/org/dspace/content/VersioningWithRelationshipsTest.java @@ -2162,7 +2162,7 @@ public void test_placeRecalculationAfterDelete_complex() throws Exception { .build(); // metadata - person 3 & project 2 - itemService.addMetadata(context, pe3_1, "dc", "relation", null, null, "project 2 (mdv)"); + itemService.addMetadata(context, pe3_1, "dc", "relation", null, null, "project 2 (mdv)", "20000", 300); // relationship - person 1 & project 3 RelationshipBuilder.createRelationshipBuilder(context, pe1_1, pr3_1, isProjectOfPerson) @@ -2193,14 +2193,14 @@ public void test_placeRecalculationAfterDelete_complex() throws Exception { .build(); // metadata - person 3 & project 4 - itemService.addMetadata(context, pe3_1, "dc", "relation", null, null, "project 4 (mdv)"); + itemService.addMetadata(context, pe3_1, "dc", "relation", null, null, "project 4 (mdv)", "20000", 300); // relationship - person 3 & project 5 RelationshipBuilder.createRelationshipBuilder(context, pe3_1, pr5_1, isProjectOfPerson) .build(); // metadata - person 3 & project 6 - itemService.addMetadata(context, pe3_1, "dc", "relation", null, null, "project 6 (mdv)"); + itemService.addMetadata(context, pe3_1, "dc", "relation", null, null, "project 6 (mdv)", "20000", 300); // SUMMARY // diff --git a/dspace-server-webapp/src/test/java/org/dspace/app/rest/ClarinItemImportControllerIT.java b/dspace-server-webapp/src/test/java/org/dspace/app/rest/ClarinItemImportControllerIT.java index 8e1ad2a697e5..c8c6f5a9ce24 100644 --- a/dspace-server-webapp/src/test/java/org/dspace/app/rest/ClarinItemImportControllerIT.java +++ b/dspace-server-webapp/src/test/java/org/dspace/app/rest/ClarinItemImportControllerIT.java @@ -410,4 +410,64 @@ public void importItemWithUnsortedAuthors() throws Exception { ItemBuilder.deleteItem(uuid); context.restoreAuthSystemState(); } + + @Test + public void testImportAuthorityAndConfidenceInMetadata() throws Exception { + String DC_RELATION_METADATA_FIELD = "dc.relation"; + String DC_RELATION_METADATA_VALUE = "this is metadata value"; + int CONFIDENCE = 300; + int AUTHORITY = 20000; + + context.turnOffAuthorisationSystem(); + ObjectNode node = jsonNodeFactory.objectNode(); + node.set("withdrawn", jsonNodeFactory.textNode("false")); + node.set("inArchive", jsonNodeFactory.textNode("false")); + node.set("discoverable", jsonNodeFactory.textNode("false")); + + // Metadata which should be kept after installing the new Item. + ObjectNode metadataNode = jsonNodeFactory.objectNode(); + + // `dc.relation` metadata added into `metadata` of the ItemRest object + ObjectNode dcRelationMetadataNode = jsonNodeFactory.objectNode(); + dcRelationMetadataNode.set("value", jsonNodeFactory.textNode(DC_RELATION_METADATA_VALUE)); + dcRelationMetadataNode.set("language", jsonNodeFactory.textNode("en_US")); + dcRelationMetadataNode.set("authority", jsonNodeFactory.numberNode(AUTHORITY)); + dcRelationMetadataNode.set("confidence", jsonNodeFactory.numberNode(CONFIDENCE)); + metadataNode.set(DC_RELATION_METADATA_FIELD, jsonNodeFactory.arrayNode() + .add(dcRelationMetadataNode)); + + node.set("metadata", metadataNode); + context.restoreAuthSystemState(); + + ObjectMapper mapper = new ObjectMapper(); + String token = getAuthToken(admin.getEmail(), password); + + UUID uuid = UUID.fromString(read(getClient(token).perform(post("/api/clarin/import/item") + .content(mapper.writeValueAsBytes(node)) + .contentType(org.springframework.http.MediaType.APPLICATION_JSON) + .param("owningCollection", col.getID().toString()) + .param("epersonUUID", submitter.getID().toString())) + .andExpect(status().isOk()).andReturn().getResponse().getContentAsString(), + "$.id")); + + // workspaceitem should nt exist + List workflowItems = workspaceItemService.findAll(context); + assertEquals(workflowItems.size(), 0); + // controlling of the created item + Item item = itemService.find(context, uuid); + assertFalse(item.isWithdrawn()); + assertFalse(item.isArchived()); + assertFalse(item.isDiscoverable()); + assertEquals(item.getSubmitter().getID(), submitter.getID()); + assertEquals(item.getOwningCollection().getID(), col.getID()); + + // get all `dc.contributor.author`metadata values + List dcRelationValues = + itemService.getMetadata(item, "dc", "relation", null, "en_US"); + assertEquals(dcRelationValues.size(), 1); + + MetadataValue dcRelationValue = dcRelationValues.get(0); + assertEquals(dcRelationValue.getAuthority(), String.valueOf(AUTHORITY)); + assertEquals(dcRelationValue.getConfidence(), CONFIDENCE); + } } diff --git a/dspace/config/clarin-dspace.cfg b/dspace/config/clarin-dspace.cfg index 0562d134d3a3..2c50811ec00a 100644 --- a/dspace/config/clarin-dspace.cfg +++ b/dspace/config/clarin-dspace.cfg @@ -219,3 +219,8 @@ identifiers.item-status.register-doi = false ##### Dataquest URL - sing in the footer ##### themed.by.url = https://www.dataquest.sk/dspace themed.by.company.name = dataquest s.r.o. + + +#### Authority configuration `authority.cfg` +## dc.relation authority is configured only because of correct item importing, but it is not used anymore. +authority.controlled.dc.relation = true