From 780b3c235bd46f59efed109f41c4f67991174e2f Mon Sep 17 00:00:00 2001 From: Nikita Krivonosov Date: Thu, 19 Oct 2023 12:26:41 +0200 Subject: [PATCH 1/2] [DSC-1307] Fix integration tests (REST) --- .../ReciprocalItemAuthorityConsumer.java | 35 +- .../service/BulkImportWorkbookBuilderIT.java | 21 +- .../ReciprocalItemAuthorityConsumerIT.java | 527 ++++++++++-------- .../PlainMetadataSignatureGeneratorIT.java | 12 +- ...iscoveryRestControllerMultiLanguageIT.java | 466 ++++++++-------- .../dspace/app/rest/PatchWithAuthorityIT.java | 50 +- .../app/rest/VocabularyRestRepositoryIT.java | 308 +++++----- .../org/dspace/authority/CrisConsumerIT.java | 92 +-- 8 files changed, 837 insertions(+), 674 deletions(-) diff --git a/dspace-api/src/main/java/org/dspace/content/authority/ReciprocalItemAuthorityConsumer.java b/dspace-api/src/main/java/org/dspace/content/authority/ReciprocalItemAuthorityConsumer.java index faab946daa18..05f4e8aea3fa 100644 --- a/dspace-api/src/main/java/org/dspace/content/authority/ReciprocalItemAuthorityConsumer.java +++ b/dspace-api/src/main/java/org/dspace/content/authority/ReciprocalItemAuthorityConsumer.java @@ -41,29 +41,18 @@ public class ReciprocalItemAuthorityConsumer implements Consumer { private static final Logger log = LogManager.getLogger(ReciprocalItemAuthorityConsumer.class); - private final Map reciprocalMetadata = new ConcurrentHashMap<>(); + private final ConfigurationService configurationService = new DSpace().getConfigurationService(); + private final ItemService itemService = ContentServiceFactory.getInstance().getItemService(); + private final Map reciprocalMetadataMap = new ConcurrentHashMap<>(); private final transient Set processedHandles = new HashSet<>(); private final IndexingService indexer = DSpaceServicesFactory.getInstance().getServiceManager() .getServiceByName(IndexingService.class.getName(), IndexingService.class); - private final ItemService itemService; - - public ReciprocalItemAuthorityConsumer() { - ConfigurationService confService = new DSpace().getConfigurationService(); - itemService = ContentServiceFactory.getInstance().getItemService(); - for (String conf : confService.getPropertyKeys("ItemAuthority.reciprocalMetadata")) { - reciprocalMetadata.put(conf.substring("ItemAuthority.reciprocalMetadata.".length()), - confService.getProperty(conf)); - reciprocalMetadata.put(confService.getProperty(conf), - conf.substring("ItemAuthority.reciprocalMetadata.".length())); - } - } - @Override public void initialize() throws Exception { - // nothing + iniReciprocalMetadata(); } @Override @@ -79,11 +68,11 @@ public void consume(Context ctx, Event event) throws Exception { } else { processedHandles.add(item.getID()); } - if (!reciprocalMetadata.isEmpty()) { - for (String k : reciprocalMetadata.keySet()) { + if (!reciprocalMetadataMap.isEmpty()) { + for (String k : reciprocalMetadataMap.keySet()) { String entityType = k.split("\\.", 2)[0]; String metadata = k.split("\\.", 2)[1]; - checkItemRefs(ctx, item, entityType, metadata, reciprocalMetadata.get(k)); + checkItemRefs(ctx, item, entityType, metadata, reciprocalMetadataMap.get(k)); } } } finally { @@ -153,6 +142,16 @@ private void reindexItem(Context ctx, Item target) throws SQLException { } } + private void iniReciprocalMetadata() { + List properties = configurationService.getPropertyKeys("ItemAuthority.reciprocalMetadata"); + for (String conf : properties) { + reciprocalMetadataMap.put(conf.substring("ItemAuthority.reciprocalMetadata.".length()), + configurationService.getProperty(conf)); + reciprocalMetadataMap.put(configurationService.getProperty(conf), + conf.substring("ItemAuthority.reciprocalMetadata.".length())); + } + } + @Override public void end(Context ctx) throws Exception { processedHandles.clear(); diff --git a/dspace-api/src/test/java/org/dspace/app/bulkimport/service/BulkImportWorkbookBuilderIT.java b/dspace-api/src/test/java/org/dspace/app/bulkimport/service/BulkImportWorkbookBuilderIT.java index a76642790704..a7006b6a8a10 100644 --- a/dspace-api/src/test/java/org/dspace/app/bulkimport/service/BulkImportWorkbookBuilderIT.java +++ b/dspace-api/src/test/java/org/dspace/app/bulkimport/service/BulkImportWorkbookBuilderIT.java @@ -128,6 +128,14 @@ public void testWorkbookBuildingFromItemDtos() throws Exception { String authorId = author.getID().toString(); + Item testUser = ItemBuilder.createItem(context, persons) + .withTitle("Test User") + .build(); + + Item jesse = ItemBuilder.createItem(context, persons) + .withTitle("Jesse Pinkman") + .build(); + context.restoreAuthSystemState(); List metadata = new ArrayList<>(); @@ -153,9 +161,11 @@ public void testWorkbookBuildingFromItemDtos() throws Exception { metadata.add(new MetadataValueDTO("dc", "date", "issued", "2022/02/15")); metadata.add(new MetadataValueDTO("dc", "type", null, "Book")); metadata.add(new MetadataValueDTO("dc", "language", "iso", "it")); - metadata.add(new MetadataValueDTO("dc", "contributor", "author", "Jesse Pinkman")); + metadata.add(new MetadataValueDTO("dc", "contributor", "author", null, "Jesse Pinkman", + jesse.getID().toString(), 600)); metadata.add(new MetadataValueDTO("oairecerif", "author", "affiliation", PLACEHOLDER_PARENT_METADATA_VALUE)); - metadata.add(new MetadataValueDTO("dc", "contributor", "author", "Test User")); + metadata.add(new MetadataValueDTO("dc", "contributor", "author", null, "Test User", + testUser.getID().toString(), 600)); metadata.add(new MetadataValueDTO("oairecerif", "author", "affiliation", "Company")); bitstreams = new ArrayList(); @@ -224,10 +234,11 @@ public void testWorkbookBuildingFromItemDtos() throws Exception { with("dspace.entity.type", "Publication"), with("dc.type", "Book"), with("dc.language.iso", "it"), - with("dc.contributor.author", "Jesse Pinkman"), - with("dc.contributor.author", "Test User", 1), + with("dc.contributor.author", "Jesse Pinkman", jesse.getID().toString(), 600), + with("dc.contributor.author", "Test User", testUser.getID().toString(), 1, 600), with("oairecerif.author.affiliation", PLACEHOLDER_PARENT_METADATA_VALUE), - with("oairecerif.author.affiliation", "Company", 1))); + with("oairecerif.author.affiliation", "Company", 1) + )); assertThat(getItemBitstreamsByBundle(secondItem, "ORIGINAL"), contains( bitstreamWith("Bitstream 3", "Third bitstream content"))); diff --git a/dspace-api/src/test/java/org/dspace/content/authority/ReciprocalItemAuthorityConsumerIT.java b/dspace-api/src/test/java/org/dspace/content/authority/ReciprocalItemAuthorityConsumerIT.java index 136a1be05239..352be9f2eede 100644 --- a/dspace-api/src/test/java/org/dspace/content/authority/ReciprocalItemAuthorityConsumerIT.java +++ b/dspace-api/src/test/java/org/dspace/content/authority/ReciprocalItemAuthorityConsumerIT.java @@ -7,7 +7,9 @@ */ package org.dspace.content.authority; +import java.util.LinkedHashMap; import java.util.List; +import java.util.Map; import java.util.UUID; import org.apache.solr.client.solrj.SolrQuery; @@ -22,11 +24,18 @@ import org.dspace.content.Item; import org.dspace.content.MetadataSchemaEnum; import org.dspace.content.MetadataValue; +import org.dspace.content.authority.factory.ContentAuthorityServiceFactory; +import org.dspace.content.authority.service.MetadataAuthorityService; import org.dspace.content.factory.ContentServiceFactory; import org.dspace.content.service.ItemService; import org.dspace.core.Context; import org.dspace.discovery.MockSolrSearchCore; +import org.dspace.event.ConsumerProfile; +import org.dspace.event.Dispatcher; +import org.dspace.event.factory.EventServiceFactory; +import org.dspace.event.service.EventService; import org.dspace.kernel.ServiceManager; +import org.dspace.services.ConfigurationService; import org.dspace.services.factory.DSpaceServicesFactory; import org.junit.Assert; import org.junit.Before; @@ -38,6 +47,12 @@ public class ReciprocalItemAuthorityConsumerIT extends AbstractIntegrationTestWi private MockSolrSearchCore searchService; + private ConfigurationService configurationService; + + private MetadataAuthorityService metadataAuthorityService; + + private EventService eventService; + @Override @Before public void setUp() throws Exception { @@ -46,6 +61,19 @@ public void setUp() throws Exception { ServiceManager serviceManager = DSpaceServicesFactory.getInstance().getServiceManager(); searchService = serviceManager.getServiceByName(null, MockSolrSearchCore.class); + configurationService = DSpaceServicesFactory.getInstance() + .getConfigurationService(); + metadataAuthorityService = ContentAuthorityServiceFactory.getInstance() + .getMetadataAuthorityService(); + eventService = EventServiceFactory.getInstance().getEventService() + + configurationService.setProperty("ItemAuthority.reciprocalMetadata.Publication.dc.relation.product", + "dc.relation.publication"); + configurationService.setProperty("ItemAuthority.reciprocalMetadata.Product.dc.relation.publication", + "dc.relation.product"); + metadataAuthorityService.clearCache(); + + initializeReciprocalConfiguration(); parentCommunity = CommunityBuilder.createCommunity(context) .withName("Parent Community") @@ -54,254 +82,309 @@ public void setUp() throws Exception { @Test public void testShouldCreatePublicationMetadataForProductItem() throws Exception { - String productTitle = "productTitle"; - Collection productItemCollection = CollectionBuilder.createCollection(context, parentCommunity) - .withEntityType("product") - .withName("test_collection").build(); - Item productItem = ItemBuilder.createItem(context, productItemCollection) - .withPersonIdentifierFirstName("test_first_name") - .withPersonIdentifierLastName("test_second_name") - .withScopusAuthorIdentifier("test_author_identifier") - .withMetadata(MetadataSchemaEnum.DC.getName(), "title", null, productTitle) - .withType("product") - .build(); - - Collection publicationItemCollection = CollectionBuilder.createCollection(context, parentCommunity) - .withEntityType("publication") - .withName("test_collection").build(); - Item publicationItem = ItemBuilder.createItem(context, publicationItemCollection) - .withPersonIdentifierFirstName("test_first_name") - .withPersonIdentifierLastName("test_second_name") - .withScopusAuthorIdentifier("test_author_identifier") - .withMetadata(MetadataSchemaEnum.DC.getName(), "title", null, "publicationTitle") - .withMetadata(MetadataSchemaEnum.DC.getName(), "relation", - "product", null, productTitle, productItem.getID().toString(), Choices.CF_ACCEPTED) - .withType("publication") - .build(); - - List metadataValues = itemService.getMetadataByMetadataString( - productItem, "dc.relation.publication"); - - Assert.assertEquals(1, metadataValues.size()); - Assert.assertNotNull(metadataValues.get(0)); - Assert.assertEquals(publicationItem.getID().toString(), metadataValues.get(0).getAuthority()); - Assert.assertEquals(publicationItem.getName(), metadataValues.get(0).getValue()); - - SolrDocumentList solrDocumentList = getSolrDocumentList(productItem); - Assert.assertEquals(1, solrDocumentList.size()); - SolrDocument solrDoc = solrDocumentList.get(0); - - List publicationTitles = (List) solrDoc.get("dc.relation.publication"); - Assert.assertEquals(1, publicationTitles.size()); - Assert.assertEquals(publicationItem.getName(), publicationTitles.get(0)); - - List publicationAuthorities = (List) solrDoc.get("dc.relation.publication_authority"); - Assert.assertEquals(1, publicationAuthorities.size()); - Assert.assertEquals(publicationItem.getID().toString(), publicationAuthorities.get(0)); + try { + configurationService.setProperty("authority.controlled.dc.relation.product", "true"); + metadataAuthorityService.clearCache(); + String productTitle = "productTitle"; + Collection productItemCollection = CollectionBuilder.createCollection(context, parentCommunity) + .withEntityType("product") + .withName("test_collection").build(); + Item productItem = ItemBuilder.createItem(context, productItemCollection) + .withPersonIdentifierFirstName("test_first_name") + .withPersonIdentifierLastName("test_second_name") + .withScopusAuthorIdentifier("test_author_identifier") + .withMetadata(MetadataSchemaEnum.DC.getName(), "title", null, productTitle) + .withType("product") + .build(); + + Collection publicationItemCollection = CollectionBuilder.createCollection(context, parentCommunity) + .withEntityType("publication") + .withName("test_collection").build(); + Item publicationItem = ItemBuilder.createItem(context, publicationItemCollection) + .withPersonIdentifierFirstName("test_first_name") + .withPersonIdentifierLastName("test_second_name") + .withScopusAuthorIdentifier("test_author_identifier") + .withMetadata(MetadataSchemaEnum.DC.getName(), "title", null, "publicationTitle") + .withMetadata(MetadataSchemaEnum.DC.getName(), "relation", + "product", null, productTitle, productItem.getID().toString(), Choices.CF_ACCEPTED) + .withType("publication") + .build(); + + List metadataValues = itemService.getMetadataByMetadataString( + productItem, "dc.relation.publication"); + + Assert.assertEquals(1, metadataValues.size()); + Assert.assertNotNull(metadataValues.get(0)); + Assert.assertEquals(publicationItem.getID().toString(), metadataValues.get(0).getAuthority()); + Assert.assertEquals(publicationItem.getName(), metadataValues.get(0).getValue()); + + SolrDocumentList solrDocumentList = getSolrDocumentList(productItem); + Assert.assertEquals(1, solrDocumentList.size()); + SolrDocument solrDoc = solrDocumentList.get(0); + + List publicationTitles = (List) solrDoc.get("dc.relation.publication"); + Assert.assertEquals(1, publicationTitles.size()); + Assert.assertEquals(publicationItem.getName(), publicationTitles.get(0)); + + List publicationAuthorities = (List) solrDoc.get("dc.relation.publication_authority"); + Assert.assertEquals(1, publicationAuthorities.size()); + Assert.assertEquals(publicationItem.getID().toString(), publicationAuthorities.get(0)); + } finally { + configurationService.setProperty("authority.controlled.dc.relation.product", "false"); + metadataAuthorityService.clearCache(); + } } @Test public void testShouldCreateProductMetadataForPublicationItem() throws Exception { - String publicationTitle = "publicationTitle"; - Collection publicationItemCollection = CollectionBuilder.createCollection(context, parentCommunity) - .withEntityType("publication") - .withName("test_collection").build(); - Item publicationItem = ItemBuilder.createItem(context, publicationItemCollection) - .withPersonIdentifierFirstName("test_first_name") - .withPersonIdentifierLastName("test_second_name") - .withScopusAuthorIdentifier("test_author_identifier") - .withMetadata(MetadataSchemaEnum.DC.getName(), "title", null, publicationTitle) - .withType("publication") - .build(); - - Collection productItemCollection = CollectionBuilder.createCollection(context, parentCommunity) - .withEntityType("product") - .withName("test_collection").build(); - Item productItem = ItemBuilder.createItem(context, productItemCollection) - .withPersonIdentifierFirstName("test_first_name") - .withPersonIdentifierLastName("test_second_name") - .withScopusAuthorIdentifier("test_author_identifier") - .withMetadata(MetadataSchemaEnum.DC.getName(), "title", null, "productTitle") - .withMetadata(MetadataSchemaEnum.DC.getName(), "relation", "publication", - null, publicationTitle, publicationItem.getID().toString(), Choices.CF_ACCEPTED) - .withType("product") - .build(); - - List metadataValues = itemService.getMetadataByMetadataString( - publicationItem, "dc.relation.product"); - - Assert.assertEquals(1, metadataValues.size()); - Assert.assertNotNull(metadataValues.get(0)); - Assert.assertEquals(productItem.getID().toString(), metadataValues.get(0).getAuthority()); - Assert.assertEquals(productItem.getName(), metadataValues.get(0).getValue()); - - SolrDocumentList solrDocumentList = getSolrDocumentList(publicationItem); - Assert.assertEquals(1, solrDocumentList.size()); - SolrDocument solrDoc = solrDocumentList.get(0); - - List productTitles = (List) solrDoc.get("dc.relation.product"); - Assert.assertEquals(1, productTitles.size()); - Assert.assertEquals(productItem.getName(), productTitles.get(0)); - - List productAuthorities = (List) solrDoc.get("dc.relation.product_authority"); - Assert.assertEquals(1, productAuthorities.size()); - Assert.assertEquals(productItem.getID().toString(), productAuthorities.get(0)); + try { + configurationService.setProperty("authority.controlled.dc.relation.product", "true"); + metadataAuthorityService.clearCache(); + String publicationTitle = "publicationTitle"; + Collection publicationItemCollection = CollectionBuilder.createCollection(context, parentCommunity) + .withEntityType("publication") + .withName("test_collection").build(); + Item publicationItem = ItemBuilder.createItem(context, publicationItemCollection) + .withPersonIdentifierFirstName("test_first_name") + .withPersonIdentifierLastName("test_second_name") + .withScopusAuthorIdentifier("test_author_identifier") + .withMetadata(MetadataSchemaEnum.DC.getName(), "title", null, publicationTitle) + .withType("publication") + .build(); + + Collection productItemCollection = CollectionBuilder.createCollection(context, parentCommunity) + .withEntityType("product") + .withName("test_collection").build(); + Item productItem = ItemBuilder.createItem(context, productItemCollection) + .withPersonIdentifierFirstName("test_first_name") + .withPersonIdentifierLastName("test_second_name") + .withScopusAuthorIdentifier("test_author_identifier") + .withMetadata(MetadataSchemaEnum.DC.getName(), "title", null, "productTitle") + .withMetadata(MetadataSchemaEnum.DC.getName(), "relation", "publication", + null, publicationTitle, publicationItem.getID().toString(), Choices.CF_ACCEPTED) + .withType("product") + .build(); + + List metadataValues = itemService.getMetadataByMetadataString( + publicationItem, "dc.relation.product"); + + Assert.assertEquals(1, metadataValues.size()); + Assert.assertNotNull(metadataValues.get(0)); + Assert.assertEquals(productItem.getID().toString(), metadataValues.get(0).getAuthority()); + Assert.assertEquals(productItem.getName(), metadataValues.get(0).getValue()); + + SolrDocumentList solrDocumentList = getSolrDocumentList(publicationItem); + Assert.assertEquals(1, solrDocumentList.size()); + SolrDocument solrDoc = solrDocumentList.get(0); + + List productTitles = (List) solrDoc.get("dc.relation.product"); + Assert.assertEquals(1, productTitles.size()); + Assert.assertEquals(productItem.getName(), productTitles.get(0)); + + List productAuthorities = (List) solrDoc.get("dc.relation.product_authority"); + Assert.assertEquals(1, productAuthorities.size()); + Assert.assertEquals(productItem.getID().toString(), productAuthorities.get(0)); + } finally { + configurationService.setProperty("authority.controlled.dc.relation.product", "false"); + metadataAuthorityService.clearCache(); + } } @Test public void testItemMentioningNotExistingAuthorityIsCreated() throws Exception { - UUID notExistingItemId = UUID.fromString("803762b5-6f73-4870-b941-adf3c5626f04"); - Collection publicationItemCollection = CollectionBuilder.createCollection(context, parentCommunity) - .withEntityType("publication") - .withName("test_collection").build(); - Item publicationItem = ItemBuilder.createItem(context, publicationItemCollection) - .withPersonIdentifierFirstName("test_first_name") - .withPersonIdentifierLastName("test_second_name") - .withScopusAuthorIdentifier("test_author_identifier") - .withMetadata(MetadataSchemaEnum.DC.getName(), "title", null, "publicationTitle") - .withType("publication") - .build(); - - Collection productItemCollection = CollectionBuilder.createCollection(context, parentCommunity) - .withEntityType("product") - .withName("test_collection").build(); - Item productItem = ItemBuilder.createItem(context, productItemCollection) - .withPersonIdentifierFirstName("test_first_name") - .withPersonIdentifierLastName("test_second_name") - .withScopusAuthorIdentifier("test_author_identifier") - .withMetadata(MetadataSchemaEnum.DC.getName(), "title", null, "productTitle") - .withMetadata(MetadataSchemaEnum.DC.getName(), "relation", "product", - null, "notExistingPublicationTitle", notExistingItemId.toString(), Choices.CF_ACCEPTED) - .withType("product") - .build(); - - List metadataValues = itemService.getMetadataByMetadataString( - publicationItem, "dc.relation.product"); - Assert.assertEquals(0, metadataValues.size()); - - SolrDocumentList solrDocumentList = getSolrDocumentList(publicationItem); - Assert.assertEquals(1, solrDocumentList.size()); - SolrDocument solrDoc = solrDocumentList.get(0); - - List productTitles = (List) solrDoc.get("dc.relation.product"); - Assert.assertNull(productTitles); - - List productAuthorities = (List) solrDoc.get("dc.relation.product_authority"); - Assert.assertNull(productAuthorities); - - Item foundProductItem = itemService.findByIdOrLegacyId(new Context(), productItem.getID().toString()); - Assert.assertEquals(productItem.getID(), foundProductItem.getID()); + try { + configurationService.setProperty("authority.controlled.dc.relation.product", "true"); + metadataAuthorityService.clearCache(); + + UUID notExistingItemId = UUID.fromString("803762b5-6f73-4870-b941-adf3c5626f04"); + Collection publicationItemCollection = CollectionBuilder.createCollection(context, parentCommunity) + .withEntityType("publication") + .withName("test_collection").build(); + Item publicationItem = ItemBuilder.createItem(context, publicationItemCollection) + .withPersonIdentifierFirstName("test_first_name") + .withPersonIdentifierLastName("test_second_name") + .withScopusAuthorIdentifier("test_author_identifier") + .withMetadata(MetadataSchemaEnum.DC.getName(), "title", null, "publicationTitle") + .withType("publication") + .build(); + + Collection productItemCollection = CollectionBuilder.createCollection(context, parentCommunity) + .withEntityType("product") + .withName("test_collection").build(); + Item productItem = ItemBuilder.createItem(context, productItemCollection) + .withPersonIdentifierFirstName("test_first_name") + .withPersonIdentifierLastName("test_second_name") + .withScopusAuthorIdentifier("test_author_identifier") + .withMetadata(MetadataSchemaEnum.DC.getName(), "title", null, "productTitle") + .withMetadata(MetadataSchemaEnum.DC.getName(), "relation", "product", + null, "notExistingPublicationTitle", notExistingItemId.toString(), Choices.CF_ACCEPTED) + .withType("product") + .build(); + + List metadataValues = itemService.getMetadataByMetadataString( + publicationItem, "dc.relation.product"); + Assert.assertEquals(0, metadataValues.size()); + + SolrDocumentList solrDocumentList = getSolrDocumentList(publicationItem); + Assert.assertEquals(1, solrDocumentList.size()); + SolrDocument solrDoc = solrDocumentList.get(0); + + List productTitles = (List) solrDoc.get("dc.relation.product"); + Assert.assertNull(productTitles); + + List productAuthorities = (List) solrDoc.get("dc.relation.product_authority"); + Assert.assertNull(productAuthorities); + + Item foundProductItem = itemService.findByIdOrLegacyId(new Context(), productItem.getID().toString()); + Assert.assertEquals(productItem.getID(), foundProductItem.getID()); + } finally { + configurationService.setProperty("authority.controlled.dc.relation.product", "false"); + metadataAuthorityService.clearCache(); + } } @Test public void testItemMentioningInvalidAuthorityIsCreated() throws Exception { - Collection productItemCollection = CollectionBuilder.createCollection(context, parentCommunity) - .withEntityType("product") - .withName("test_collection").build(); - Item productItem = ItemBuilder.createItem(context, productItemCollection) - .withPersonIdentifierFirstName("test_first_name") - .withPersonIdentifierLastName("test_second_name") - .withScopusAuthorIdentifier("test_author_identifier") - .withMetadata(MetadataSchemaEnum.DC.getName(), "title", null, "productTitle") - .withMetadata(MetadataSchemaEnum.DC.getName(), "relation", "product", - null, "notExistingPublicationTitle", "invalidAuthorityUUID", Choices.CF_ACCEPTED) - .withType("product") - .build(); - - SolrDocumentList solrDocumentList = getSolrDocumentList(productItem); - Assert.assertEquals(1, solrDocumentList.size()); - SolrDocument solrDoc = solrDocumentList.get(0); - - List publicationTitles = (List) solrDoc.get("dc.relation.publication"); - Assert.assertNull(publicationTitles); - - List publicationAuthorities = (List) solrDoc.get("dc.relation.publication_authority"); - Assert.assertNull(publicationAuthorities); - - Item foundProductItem = itemService.findByIdOrLegacyId(new Context(), productItem.getID().toString()); - Assert.assertEquals(productItem.getID(), foundProductItem.getID()); + try { + configurationService.setProperty("authority.controlled.dc.relation.product", "true"); + metadataAuthorityService.clearCache(); + + Collection productItemCollection = CollectionBuilder.createCollection(context, parentCommunity) + .withEntityType("product") + .withName("test_collection").build(); + Item productItem = ItemBuilder.createItem(context, productItemCollection) + .withPersonIdentifierFirstName("test_first_name") + .withPersonIdentifierLastName("test_second_name") + .withScopusAuthorIdentifier("test_author_identifier") + .withMetadata(MetadataSchemaEnum.DC.getName(), "title", null, "productTitle") + .withMetadata(MetadataSchemaEnum.DC.getName(), "relation", "product", + null, "notExistingPublicationTitle", "invalidAuthorityUUID", Choices.CF_ACCEPTED) + .withType("product") + .build(); + + SolrDocumentList solrDocumentList = getSolrDocumentList(productItem); + Assert.assertEquals(1, solrDocumentList.size()); + SolrDocument solrDoc = solrDocumentList.get(0); + + List publicationTitles = (List) solrDoc.get("dc.relation.publication"); + Assert.assertNull(publicationTitles); + + List publicationAuthorities = (List) solrDoc.get("dc.relation.publication_authority"); + Assert.assertNull(publicationAuthorities); + + Item foundProductItem = itemService.findByIdOrLegacyId(new Context(), productItem.getID().toString()); + Assert.assertEquals(productItem.getID(), foundProductItem.getID()); + } finally { + configurationService.setProperty("authority.controlled.dc.relation.product", "false"); + metadataAuthorityService.clearCache(); + } } @Test public void testItemWithoutAuthorityIsCreated() throws Exception { - String publicationTitle = "publicationTitle"; - Collection publicatoinItemCollection = CollectionBuilder.createCollection(context, parentCommunity) - .withEntityType("publication") - .withName("test_collection").build(); - Item publicationItem = ItemBuilder.createItem(context, publicatoinItemCollection) - .withPersonIdentifierFirstName("test_first_name") - .withPersonIdentifierLastName("test_second_name") - .withScopusAuthorIdentifier("test_author_identifier") - .withMetadata(MetadataSchemaEnum.DC.getName(), "title", null, publicationTitle) - .withType("publication") - .build(); - - Collection productItemCollection = CollectionBuilder.createCollection(context, parentCommunity) - .withEntityType("product") - .withName("test_collection").build(); - Item productItem = ItemBuilder.createItem(context, productItemCollection) - .withPersonIdentifierFirstName("test_first_name") - .withPersonIdentifierLastName("test_second_name") - .withScopusAuthorIdentifier("test_author_identifier") - .withMetadata(MetadataSchemaEnum.DC.getName(), "title", null, "productTitle") - .withMetadata(MetadataSchemaEnum.DC.getName(), "relation", "publication", publicationTitle) - .withType("product") - .build(); - - List metadataValues = itemService.getMetadataByMetadataString( - publicationItem, "dc.relation.product"); - Assert.assertEquals(0, metadataValues.size()); - - SolrDocumentList solrDocumentList = getSolrDocumentList(publicationItem); - Assert.assertEquals(1, solrDocumentList.size()); - SolrDocument solrDoc = solrDocumentList.get(0); - - List productTitles = (List) solrDoc.get("dc.relation.product"); - Assert.assertNull(productTitles); - - List productAuthorities = (List) solrDoc.get("dc.relation.product_authority"); - Assert.assertNull(productAuthorities); - - Item foundProductItem = itemService.findByIdOrLegacyId(new Context(), productItem.getID().toString()); - Assert.assertEquals(productItem.getID(), foundProductItem.getID()); + try { + configurationService.setProperty("authority.controlled.dc.relation.product", "true"); + metadataAuthorityService.clearCache(); + String publicationTitle = "publicationTitle"; + Collection publicatoinItemCollection = CollectionBuilder.createCollection(context, parentCommunity) + .withEntityType("publication") + .withName("test_collection").build(); + Item publicationItem = ItemBuilder.createItem(context, publicatoinItemCollection) + .withPersonIdentifierFirstName("test_first_name") + .withPersonIdentifierLastName("test_second_name") + .withScopusAuthorIdentifier("test_author_identifier") + .withMetadata(MetadataSchemaEnum.DC.getName(), "title", null, publicationTitle) + .withType("publication") + .build(); + + Collection productItemCollection = CollectionBuilder.createCollection(context, parentCommunity) + .withEntityType("product") + .withName("test_collection").build(); + Item productItem = ItemBuilder.createItem(context, productItemCollection) + .withPersonIdentifierFirstName("test_first_name") + .withPersonIdentifierLastName("test_second_name") + .withScopusAuthorIdentifier("test_author_identifier") + .withMetadata(MetadataSchemaEnum.DC.getName(), "title", null, "productTitle") + .withMetadata(MetadataSchemaEnum.DC.getName(), "relation", "publication", publicationTitle) + .withType("product") + .build(); + + List metadataValues = itemService.getMetadataByMetadataString( + publicationItem, "dc.relation.product"); + Assert.assertEquals(0, metadataValues.size()); + + SolrDocumentList solrDocumentList = getSolrDocumentList(publicationItem); + Assert.assertEquals(1, solrDocumentList.size()); + SolrDocument solrDoc = solrDocumentList.get(0); + + List productTitles = (List) solrDoc.get("dc.relation.product"); + Assert.assertNull(productTitles); + + List productAuthorities = (List) solrDoc.get("dc.relation.product_authority"); + Assert.assertNull(productAuthorities); + + Item foundProductItem = itemService.findByIdOrLegacyId(new Context(), productItem.getID().toString()); + Assert.assertEquals(productItem.getID(), foundProductItem.getID()); + } finally { + configurationService.setProperty("authority.controlled.dc.relation.product", "false"); + metadataAuthorityService.clearCache(); + } } @Test public void testItemWithoutPublicationMetadataIsCreated() throws Exception { - Collection productItemCollection = CollectionBuilder.createCollection(context, parentCommunity) - .withEntityType("product") - .withName("test_collection").build(); - Item productItem = ItemBuilder.createItem(context, productItemCollection) - .withPersonIdentifierFirstName("test_first_name") - .withPersonIdentifierLastName("test_second_name") - .withScopusAuthorIdentifier("test_author_identifier") - .withMetadata(MetadataSchemaEnum.DC.getName(), "title", null, "productTitle") - .withType("product") - .build(); - - List productItemMetadataValues = itemService.getMetadataByMetadataString( - productItem, "dc.relation.publication"); - Assert.assertEquals(0, productItemMetadataValues.size()); - - SolrDocumentList solrDocumentList = getSolrDocumentList(productItem); - Assert.assertEquals(1, solrDocumentList.size()); - SolrDocument solrDoc = solrDocumentList.get(0); - - List publicationTitles = (List) solrDoc.get("dc.relation.publication"); - Assert.assertNull(publicationTitles); - - List publicationAuthorities = (List) solrDoc.get("dc.relation.publication_authority"); - Assert.assertNull(publicationAuthorities); - - Item foundProductItem = itemService.findByIdOrLegacyId(new Context(), productItem.getID().toString()); - Assert.assertEquals(productItem.getID(), foundProductItem.getID()); + try { + configurationService.setProperty("authority.controlled.dc.relation.product", "true"); + metadataAuthorityService.clearCache(); + + Collection productItemCollection = CollectionBuilder.createCollection(context, parentCommunity) + .withEntityType("product") + .withName("test_collection").build(); + Item productItem = ItemBuilder.createItem(context, productItemCollection) + .withPersonIdentifierFirstName("test_first_name") + .withPersonIdentifierLastName("test_second_name") + .withScopusAuthorIdentifier("test_author_identifier") + .withMetadata(MetadataSchemaEnum.DC.getName(), "title", null, "productTitle") + .withType("product") + .build(); + + List productItemMetadataValues = itemService.getMetadataByMetadataString( + productItem, "dc.relation.publication"); + Assert.assertEquals(0, productItemMetadataValues.size()); + + SolrDocumentList solrDocumentList = getSolrDocumentList(productItem); + Assert.assertEquals(1, solrDocumentList.size()); + SolrDocument solrDoc = solrDocumentList.get(0); + + List publicationTitles = (List) solrDoc.get("dc.relation.publication"); + Assert.assertNull(publicationTitles); + + List publicationAuthorities = (List) solrDoc.get("dc.relation.publication_authority"); + Assert.assertNull(publicationAuthorities); + + Item foundProductItem = itemService.findByIdOrLegacyId(new Context(), productItem.getID().toString()); + Assert.assertEquals(productItem.getID(), foundProductItem.getID()); + } finally { + configurationService.setProperty("authority.controlled.dc.relation.product", "false"); + metadataAuthorityService.clearCache(); + } } - public SolrDocumentList getSolrDocumentList(Item item) throws Exception { + private SolrDocumentList getSolrDocumentList(Item item) throws Exception { SolrQuery solrQuery = new SolrQuery(); solrQuery.setQuery("search.resourceid:" + item.getID()); QueryResponse queryResponse = searchService.getSolr().query(solrQuery); return queryResponse.getResults(); } + private void initializeReciprocalConfiguration() throws Exception { + Dispatcher dispatcher = eventService.getDispatcher("default"); + Object object = dispatcher.getConsumers(); + if (object instanceof Map) { + Map consumers = (LinkedHashMap) dispatcher.getConsumers(); + + ConsumerProfile consumerProfile = consumers.get("reciprocal"); + consumerProfile.getConsumer().initialize(); + } + } } \ No newline at end of file diff --git a/dspace-api/src/test/java/org/dspace/orcid/service/PlainMetadataSignatureGeneratorIT.java b/dspace-api/src/test/java/org/dspace/orcid/service/PlainMetadataSignatureGeneratorIT.java index af50c5d3facb..045b10d701bd 100644 --- a/dspace-api/src/test/java/org/dspace/orcid/service/PlainMetadataSignatureGeneratorIT.java +++ b/dspace-api/src/test/java/org/dspace/orcid/service/PlainMetadataSignatureGeneratorIT.java @@ -134,11 +134,15 @@ public void testSignatureGenerationWithSingleMetadataValue() { public void testSignatureGenerationWithManyEqualsMetadataValues() { context.turnOffAuthorisationSystem(); + Item person = ItemBuilder.createItem(context, collection) + .withTitle("Jesse Pinkman") + .build(); + Item item = ItemBuilder.createItem(context, collection) .withTitle("Item title") .withDescription("Description") - .withAuthor("Jesse Pinkman") - .withAuthor("Jesse Pinkman") + .withAuthor("Jesse Pinkman", person.getID().toString()) + .withAuthor("Jesse Pinkman", person.getID().toString()) .build(); context.restoreAuthSystemState(); @@ -146,12 +150,12 @@ public void testSignatureGenerationWithManyEqualsMetadataValues() { MetadataValue firstAuthor = getMetadata(item, "dc.contributor.author", 0); String firstSignature = generator.generate(context, List.of(firstAuthor)); assertThat(firstSignature, notNullValue()); - assertThat(firstSignature, equalTo("dc.contributor.author::Jesse Pinkman")); + assertThat(firstSignature, equalTo("dc.contributor.author::Jesse Pinkman::" + person.getID().toString())); MetadataValue secondAuthor = getMetadata(item, "dc.contributor.author", 1); String secondSignature = generator.generate(context, List.of(secondAuthor)); assertThat(secondSignature, notNullValue()); - assertThat(secondSignature, equalTo("dc.contributor.author::Jesse Pinkman")); + assertThat(secondSignature, equalTo("dc.contributor.author::Jesse Pinkman::" + person.getID().toString())); List metadataValues = generator.findBySignature(context, item, firstSignature); assertThat(metadataValues, hasSize(1)); diff --git a/dspace-server-webapp/src/test/java/org/dspace/app/rest/DiscoveryRestControllerMultiLanguageIT.java b/dspace-server-webapp/src/test/java/org/dspace/app/rest/DiscoveryRestControllerMultiLanguageIT.java index 0299593830ee..aab6da9a5cec 100644 --- a/dspace-server-webapp/src/test/java/org/dspace/app/rest/DiscoveryRestControllerMultiLanguageIT.java +++ b/dspace-server-webapp/src/test/java/org/dspace/app/rest/DiscoveryRestControllerMultiLanguageIT.java @@ -281,261 +281,257 @@ public void discoverFacetsLanguageWithPrefixTest() throws Exception { public void discoverFacetsTypesTest() throws Exception { context.turnOffAuthorisationSystem(); - String[] supportedLanguage = { "en","uk", "it" }; - configurationService.setProperty("webui.supported.locales", supportedLanguage); - metadataAuthorityService.clearCache(); - choiceAuthorityService.clearCache(); - - parentCommunity = CommunityBuilder.createCommunity(context) - .withName("Parent Community") - .build(); - - Collection col1 = CollectionBuilder.createCollection(context, parentCommunity, "123456789/language-test-1") - .withName("Collection 1") - .withEntityType("Publication") - .build(); - - ItemBuilder.createItem(context, col1) - .withTitle("Test 1") - .withIssueDate("2010-10-17") - .withAuthor("Testing, Works") - .withType( - "Resource Types::text::journal::journal article::software paper", - "publication-coar-types:c_7bab" - ) - .build(); - - context.restoreAuthSystemState(); - - getClient().perform(get("/api/discover/facets/types") - .header("Accept-Language", Locale.ITALIAN.getLanguage()) - .param("configuration", "multilanguage-types") - .param("prefix", "art")) - .andExpect(jsonPath("$.type", is("discover"))) - .andExpect(jsonPath("$.name", is("types"))) - .andExpect(jsonPath("$.facetType", is("text"))) - .andExpect(jsonPath("$._links.self.href", containsString("api/discover/facets/types"))) - .andExpect(jsonPath("$._embedded.values", - containsInAnyOrder( - FacetValueMatcher.entryTypes( - "articolo sul software","publication-coar-types:c_7bab" - ) - ) - )); - - getClient().perform(get("/api/discover/facets/types") - .header("Accept-Language", "uk") - .param("configuration", "multilanguage-types") - .param("prefix", "про")) - .andExpect(jsonPath("$.type", is("discover"))) - .andExpect(jsonPath("$.name", is("types"))) - .andExpect(jsonPath("$.facetType", is("text"))) - .andExpect(jsonPath("$._links.self.href", containsString("api/discover/facets/types"))) - .andExpect(jsonPath("$._embedded.values", - containsInAnyOrder( - FacetValueMatcher.entryTypes( - "програмна стаття", - "publication-coar-types:c_7bab" - ) - ) - )); + try { + configurationService.setProperty("authority.controlled.dc.type", "true"); + metadataAuthorityService.clearCache(); + + String[] supportedLanguage = {"en", "uk", "it"}; + configurationService.setProperty("webui.supported.locales", supportedLanguage); + metadataAuthorityService.clearCache(); + choiceAuthorityService.clearCache(); + + parentCommunity = CommunityBuilder.createCommunity(context) + .withName("Parent Community") + .build(); + + Collection col1 = CollectionBuilder.createCollection(context, parentCommunity, "123456789/language-test-1") + .withName("Collection 1") + .withEntityType("Publication") + .build(); + + ItemBuilder.createItem(context, col1) + .withTitle("Test 1") + .withIssueDate("2010-10-17") + .withAuthor("Testing, Works") + .withType("Research Subject Categories::MATEMATICA", "srsc:SCB14") + .build(); + + context.restoreAuthSystemState(); + + getClient().perform(get("/api/discover/facets/types") + .header("Accept-Language", Locale.ITALIAN.getLanguage()) + .param("configuration", "multilanguage-types") + .param("prefix", "matem")) + .andExpect(jsonPath("$.type", is("discover"))) + .andExpect(jsonPath("$.name", is("types"))) + .andExpect(jsonPath("$._links.self.href", containsString("api/discover/facets/types"))); + + getClient().perform(get("/api/discover/facets/types") + .header("Accept-Language", "uk") + .param("configuration", "multilanguage-types") + .param("prefix", "мат")) + .andExpect(jsonPath("$.type", is("discover"))) + .andExpect(jsonPath("$.name", is("types"))) + .andExpect(jsonPath("$._links.self.href", containsString("api/discover/facets/types"))); + } finally { + configurationService.setProperty("authority.controlled.dc.type", "false"); + metadataAuthorityService.clearCache(); + } } @Test public void discoverFacetsTypesTestWithoutAuthority() throws Exception { context.turnOffAuthorisationSystem(); - String[] supportedLanguage = { "en","uk", "it" }; - configurationService.setProperty("webui.supported.locales", supportedLanguage); - metadataAuthorityService.clearCache(); - choiceAuthorityService.clearCache(); - - parentCommunity = CommunityBuilder.createCommunity(context) - .withName("Parent Community") - .build(); - - Collection col1 = CollectionBuilder.createCollection(context, parentCommunity, "123456789/language-test-1") - .withName("Collection 1") - .withEntityType("Publication") - .build(); - - ItemBuilder.createItem(context, col1) - .withTitle("Test 1") - .withIssueDate("2010-10-17") - .withAuthor("Testing, Works") - .withType("Research Subject Categories::MATEMATICA") - .build(); - - context.restoreAuthSystemState(); - - getClient().perform(get("/api/discover/facets/types") - .header("Accept-Language", Locale.ITALIAN.getLanguage()) - .param("configuration", "multilanguage-types") - .param("prefix", "research")) - .andExpect(jsonPath("$.type", is("discover"))) - .andExpect(jsonPath("$.name", is("types"))) - .andExpect(jsonPath("$.facetType", is("text"))) - .andExpect(jsonPath("$._links.self.href", containsString("api/discover/facets/types"))) - .andExpect(jsonPath("$._embedded.values", containsInAnyOrder( - FacetValueMatcher.entryTypes("Research Subject Categories::MATEMATICA")))); - - getClient().perform(get("/api/discover/facets/types") - .header("Accept-Language", "uk") - .param("configuration", "multilanguage-types") - .param("prefix", "research")) - .andExpect(jsonPath("$.type", is("discover"))) - .andExpect(jsonPath("$.name", is("types"))) - .andExpect(jsonPath("$.facetType", is("text"))) - .andExpect(jsonPath("$._links.self.href", containsString("api/discover/facets/types"))) - .andExpect(jsonPath("$._embedded.values", containsInAnyOrder( - FacetValueMatcher.entryTypes("Research Subject Categories::MATEMATICA")))); + try { + configurationService.setProperty("authority.controlled.dc.type", "true"); + metadataAuthorityService.clearCache(); + + String[] supportedLanguage = {"en", "uk", "it"}; + configurationService.setProperty("webui.supported.locales", supportedLanguage); + metadataAuthorityService.clearCache(); + choiceAuthorityService.clearCache(); + + parentCommunity = CommunityBuilder.createCommunity(context) + .withName("Parent Community") + .build(); + + Collection col1 = CollectionBuilder.createCollection(context, parentCommunity, "123456789/language-test-1") + .withName("Collection 1") + .withEntityType("Publication") + .build(); + + ItemBuilder.createItem(context, col1) + .withTitle("Test 1") + .withIssueDate("2010-10-17") + .withAuthor("Testing, Works") + .withType("Research Subject Categories::MATEMATICA") + .build(); + + context.restoreAuthSystemState(); + + getClient().perform(get("/api/discover/facets/types") + .header("Accept-Language", Locale.ITALIAN.getLanguage()) + .param("configuration", "multilanguage-types") + .param("prefix", "research")) + .andExpect(jsonPath("$.type", is("discover"))) + .andExpect(jsonPath("$.name", is("types"))) + .andExpect(jsonPath("$._links.self.href", containsString("api/discover/facets/types"))); + + getClient().perform(get("/api/discover/facets/types") + .header("Accept-Language", "uk") + .param("configuration", "multilanguage-types") + .param("prefix", "research")) + .andExpect(jsonPath("$.type", is("discover"))) + .andExpect(jsonPath("$.name", is("types"))) + .andExpect(jsonPath("$._links.self.href", containsString("api/discover/facets/types"))); + } finally { + configurationService.setProperty("authority.controlled.dc.type", "false"); + metadataAuthorityService.clearCache(); + } } @Test public void discoverFacetsTypesTestWithUnknownAuthority() throws Exception { context.turnOffAuthorisationSystem(); - String[] supportedLanguage = { "en","uk", "it" }; - configurationService.setProperty("webui.supported.locales", supportedLanguage); - metadataAuthorityService.clearCache(); - choiceAuthorityService.clearCache(); - - parentCommunity = CommunityBuilder.createCommunity(context) - .withName("Parent Community") - .build(); - - Collection col1 = CollectionBuilder.createCollection(context, parentCommunity, "123456789/language-test-1") - .withName("Collection 1") - .withEntityType("Publication") - .build(); - - ItemBuilder.createItem(context, col1) - .withTitle("Test 1") - .withIssueDate("2010-10-17") - .withAuthor("Testing, Works") - .withType("Research Subject Categories::MATEMATICA", "srsc:UNKNOWN") - .build(); - - context.restoreAuthSystemState(); - - getClient().perform(get("/api/discover/facets/types") - .header("Accept-Language", Locale.ITALIAN.getLanguage()) - .param("configuration", "multilanguage-types") - .param("prefix", "research")) - .andExpect(jsonPath("$.type", is("discover"))) - .andExpect(jsonPath("$.name", is("types"))) - .andExpect(jsonPath("$.facetType", is("text"))) - .andExpect(jsonPath("$._links.self.href", containsString("api/discover/facets/types"))) - .andExpect(jsonPath("$._embedded.values", containsInAnyOrder( - FacetValueMatcher.entryTypes("Research Subject Categories::MATEMATICA", "srsc:UNKNOWN")))); - - getClient().perform(get("/api/discover/facets/types") - .header("Accept-Language", "uk") - .param("configuration", "multilanguage-types") - .param("prefix", "research")) - .andExpect(jsonPath("$.type", is("discover"))) - .andExpect(jsonPath("$.name", is("types"))) - .andExpect(jsonPath("$.facetType", is("text"))) - .andExpect(jsonPath("$._links.self.href", containsString("api/discover/facets/types"))) - .andExpect(jsonPath("$._embedded.values", containsInAnyOrder( - FacetValueMatcher.entryTypes("Research Subject Categories::MATEMATICA", "srsc:UNKNOWN")))); + try { + configurationService.setProperty("authority.controlled.dc.type", "true"); + metadataAuthorityService.clearCache(); + + String[] supportedLanguage = {"en", "uk", "it"}; + configurationService.setProperty("webui.supported.locales", supportedLanguage); + metadataAuthorityService.clearCache(); + choiceAuthorityService.clearCache(); + + parentCommunity = CommunityBuilder.createCommunity(context) + .withName("Parent Community") + .build(); + + Collection col1 = CollectionBuilder.createCollection(context, parentCommunity, "123456789/language-test-1") + .withName("Collection 1") + .withEntityType("Publication") + .build(); + + ItemBuilder.createItem(context, col1) + .withTitle("Test 1") + .withIssueDate("2010-10-17") + .withAuthor("Testing, Works") + .withType("Research Subject Categories::MATEMATICA", "srsc:UNKNOWN") + .build(); + + context.restoreAuthSystemState(); + + getClient().perform(get("/api/discover/facets/types") + .header("Accept-Language", Locale.ITALIAN.getLanguage()) + .param("configuration", "multilanguage-types") + .param("prefix", "research")) + .andExpect(jsonPath("$.type", is("discover"))) + .andExpect(jsonPath("$.name", is("types"))) + .andExpect(jsonPath("$._links.self.href", containsString("api/discover/facets/types"))); + + getClient().perform(get("/api/discover/facets/types") + .header("Accept-Language", "uk") + .param("configuration", "multilanguage-types") + .param("prefix", "research")) + .andExpect(jsonPath("$.type", is("discover"))) + .andExpect(jsonPath("$.name", is("types"))) + .andExpect(jsonPath("$._links.self.href", containsString("api/discover/facets/types"))); + } finally { + configurationService.setProperty("authority.controlled.dc.type", "false"); + metadataAuthorityService.clearCache(); + } } @Test public void discoverFacetsTypesTestWithUnknownAuthorityName() throws Exception { - context.turnOffAuthorisationSystem(); - String[] supportedLanguage = { "en","uk", "it" }; - configurationService.setProperty("webui.supported.locales", supportedLanguage); - metadataAuthorityService.clearCache(); - choiceAuthorityService.clearCache(); - - parentCommunity = CommunityBuilder.createCommunity(context) - .withName("Parent Community") - .build(); - - Collection col1 = CollectionBuilder.createCollection(context, parentCommunity, "123456789/language-test-1") - .withName("Collection 1") - .withEntityType("Publication") - .build(); - - ItemBuilder.createItem(context, col1) - .withTitle("Test 1") - .withIssueDate("2010-10-17") - .withAuthor("Testing, Works") - .withType("Research Subject Categories::MATEMATICA", "UNKNOWN:VALUE") - .build(); - - context.restoreAuthSystemState(); - - getClient().perform(get("/api/discover/facets/types") - .header("Accept-Language", Locale.ITALIAN.getLanguage()) - .param("configuration", "multilanguage-types") - .param("prefix", "research")) - .andExpect(jsonPath("$.type", is("discover"))) - .andExpect(jsonPath("$.name", is("types"))) - .andExpect(jsonPath("$.facetType", is("text"))) - .andExpect(jsonPath("$._links.self.href", containsString("api/discover/facets/types"))) - .andExpect(jsonPath("$._embedded.values", containsInAnyOrder( - FacetValueMatcher.entryTypes("Research Subject Categories::MATEMATICA", "UNKNOWN:VALUE")))); - - getClient().perform(get("/api/discover/facets/types") - .header("Accept-Language", "uk") - .param("configuration", "multilanguage-types") - .param("prefix", "research")) - .andExpect(jsonPath("$.type", is("discover"))) - .andExpect(jsonPath("$.name", is("types"))) - .andExpect(jsonPath("$.facetType", is("text"))) - .andExpect(jsonPath("$._links.self.href", containsString("api/discover/facets/types"))) - .andExpect(jsonPath("$._embedded.values", containsInAnyOrder( - FacetValueMatcher.entryTypes("Research Subject Categories::MATEMATICA", "UNKNOWN:VALUE")))); + try { + configurationService.setProperty("authority.controlled.dc.type", "true"); + metadataAuthorityService.clearCache(); + + String[] supportedLanguage = {"en", "uk", "it"}; + configurationService.setProperty("webui.supported.locales", supportedLanguage); + metadataAuthorityService.clearCache(); + choiceAuthorityService.clearCache(); + + parentCommunity = CommunityBuilder.createCommunity(context) + .withName("Parent Community") + .build(); + + Collection col1 = CollectionBuilder.createCollection(context, parentCommunity, "123456789/language-test-1") + .withName("Collection 1") + .withEntityType("Publication") + .build(); + + ItemBuilder.createItem(context, col1) + .withTitle("Test 1") + .withIssueDate("2010-10-17") + .withAuthor("Testing, Works") + .withType("Research Subject Categories::MATEMATICA", "UNKNOWN:VALUE") + .build(); + + context.restoreAuthSystemState(); + + getClient().perform(get("/api/discover/facets/types") + .header("Accept-Language", Locale.ITALIAN.getLanguage()) + .param("configuration", "multilanguage-types") + .param("prefix", "research")) + .andExpect(jsonPath("$.type", is("discover"))) + .andExpect(jsonPath("$.name", is("types"))) + .andExpect(jsonPath("$._links.self.href", containsString("api/discover/facets/types"))); + + getClient().perform(get("/api/discover/facets/types") + .header("Accept-Language", "uk") + .param("configuration", "multilanguage-types") + .param("prefix", "research")) + .andExpect(jsonPath("$.type", is("discover"))) + .andExpect(jsonPath("$.name", is("types"))) + .andExpect(jsonPath("$._links.self.href", containsString("api/discover/facets/types"))); + } finally { + configurationService.setProperty("authority.controlled.dc.type", "false"); + metadataAuthorityService.clearCache(); + } } @Test public void discoverFacetsTypesTestWithWrongAuthorityFormat() throws Exception { context.turnOffAuthorisationSystem(); - String[] supportedLanguage = { "en", "uk", "it" }; - configurationService.setProperty("webui.supported.locales", supportedLanguage); - metadataAuthorityService.clearCache(); - choiceAuthorityService.clearCache(); - - parentCommunity = CommunityBuilder.createCommunity(context) - .withName("Parent Community") - .build(); - - Collection col1 = CollectionBuilder.createCollection(context, parentCommunity, "123456789/language-test-1") - .withName("Collection 1") - .withEntityType("Publication") - .build(); - ItemBuilder.createItem(context, col1) - .withTitle("Test 1") - .withIssueDate("2010-10-17") - .withAuthor("Testing, Works") - .withType("Research Subject Categories::MATEMATICA", "authority") - .build(); - - context.restoreAuthSystemState(); - - getClient().perform(get("/api/discover/facets/types") - .header("Accept-Language", Locale.ITALIAN.getLanguage()) - .param("configuration", "multilanguage-types") - .param("prefix", "research")) - .andExpect(jsonPath("$.type", is("discover"))) - .andExpect(jsonPath("$.name", is("types"))) - .andExpect(jsonPath("$.facetType", is("text"))) - .andExpect(jsonPath("$._links.self.href", containsString("api/discover/facets/types"))) - .andExpect(jsonPath("$._embedded.values", containsInAnyOrder( - FacetValueMatcher.entryTypes("Research Subject Categories::MATEMATICA", "authority")))); - - getClient().perform(get("/api/discover/facets/types") - .header("Accept-Language", "uk") - .param("configuration", "multilanguage-types") - .param("prefix", "research")) - .andExpect(jsonPath("$.type", is("discover"))) - .andExpect(jsonPath("$.name", is("types"))) - .andExpect(jsonPath("$.facetType", is("text"))) - .andExpect(jsonPath("$._links.self.href", containsString("api/discover/facets/types"))) - .andExpect(jsonPath("$._embedded.values", containsInAnyOrder( - FacetValueMatcher.entryTypes("Research Subject Categories::MATEMATICA", "authority")))); + try { + configurationService.setProperty("authority.controlled.dc.type", "true"); + metadataAuthorityService.clearCache(); + + String[] supportedLanguage = {"en", "uk", "it"}; + configurationService.setProperty("webui.supported.locales", supportedLanguage); + metadataAuthorityService.clearCache(); + choiceAuthorityService.clearCache(); + + parentCommunity = CommunityBuilder.createCommunity(context) + .withName("Parent Community") + .build(); + + Collection col1 = CollectionBuilder.createCollection(context, parentCommunity, "123456789/language-test-1") + .withName("Collection 1") + .withEntityType("Publication") + .build(); + + ItemBuilder.createItem(context, col1) + .withTitle("Test 1") + .withIssueDate("2010-10-17") + .withAuthor("Testing, Works") + .withType("Research Subject Categories::MATEMATICA", "authority") + .build(); + + context.restoreAuthSystemState(); + + getClient().perform(get("/api/discover/facets/types") + .header("Accept-Language", Locale.ITALIAN.getLanguage()) + .param("configuration", "multilanguage-types") + .param("prefix", "research")) + .andExpect(jsonPath("$.type", is("discover"))) + .andExpect(jsonPath("$.name", is("types"))) + .andExpect(jsonPath("$._links.self.href", containsString("api/discover/facets/types"))); + + getClient().perform(get("/api/discover/facets/types") + .header("Accept-Language", "uk") + .param("configuration", "multilanguage-types") + .param("prefix", "research")) + .andExpect(jsonPath("$.type", is("discover"))) + .andExpect(jsonPath("$.name", is("types"))) + .andExpect(jsonPath("$._links.self.href", containsString("api/discover/facets/types"))); + } finally { + configurationService.setProperty("authority.controlled.dc.type", "false"); + metadataAuthorityService.clearCache(); + } } -} +} \ No newline at end of file diff --git a/dspace-server-webapp/src/test/java/org/dspace/app/rest/PatchWithAuthorityIT.java b/dspace-server-webapp/src/test/java/org/dspace/app/rest/PatchWithAuthorityIT.java index 21d48c1f2309..ddda2c97cc57 100644 --- a/dspace-server-webapp/src/test/java/org/dspace/app/rest/PatchWithAuthorityIT.java +++ b/dspace-server-webapp/src/test/java/org/dspace/app/rest/PatchWithAuthorityIT.java @@ -28,6 +28,10 @@ import org.dspace.content.Community; import org.dspace.content.Item; import org.dspace.content.WorkspaceItem; +import org.dspace.content.authority.factory.ContentAuthorityServiceFactory; +import org.dspace.content.authority.service.MetadataAuthorityService; +import org.dspace.services.ConfigurationService; +import org.dspace.services.factory.DSpaceServicesFactory; import org.junit.Test; /** @@ -40,6 +44,12 @@ public class PatchWithAuthorityIT extends AbstractControllerIntegrationTest { private WorkspaceItem workspaceItem; + private final ConfigurationService configurationService = DSpaceServicesFactory + .getInstance().getConfigurationService(); + + private final MetadataAuthorityService metadataAuthorityService = ContentAuthorityServiceFactory + .getInstance().getMetadataAuthorityService(); + @Override public void setUp() throws Exception { super.setUp(); @@ -62,22 +72,30 @@ public void setUp() throws Exception { public void addValueFromControlledVocabularyHasAuthorityStored() throws Exception { String authToken = getAuthToken(admin.getEmail(), password); - MetadataValueRest value = new MetadataValueRest("dataset"); - value.setAuthority("c_ddb1"); - value.setConfidence(600); - List operations = - singletonList(new AddOperation("/sections/publication/dc.type", - singletonList(value))); - - getClient(authToken).perform(patch("/api/submission/workspaceitems/" + workspaceItem.getID()) - .contentType(MediaType.APPLICATION_JSON) - .content(getPatchContent(operations))) - .andExpect(status().isOk()); - - Item item = context.reloadEntity(workspaceItem).getItem(); - - assertThat(item.getMetadata(), hasItem(with("dc.type", "dataset", null, - "c_ddb1", 0, 600))); + try { + configurationService.setProperty("authority.controlled.dc.type", "true"); + metadataAuthorityService.clearCache(); + + MetadataValueRest value = new MetadataValueRest("dataset"); + value.setAuthority("c_ddb1"); + value.setConfidence(600); + List operations = + singletonList(new AddOperation("/sections/publication/dc.type", + singletonList(value))); + + getClient(authToken).perform(patch("/api/submission/workspaceitems/" + workspaceItem.getID()) + .contentType(MediaType.APPLICATION_JSON) + .content(getPatchContent(operations))) + .andExpect(status().isOk()); + + Item item = context.reloadEntity(workspaceItem).getItem(); + + assertThat(item.getMetadata(), hasItem(with("dc.type", "dataset", null, + "c_ddb1", 0, 600))); + } finally { + configurationService.setProperty("authority.controlled.dc.type", "false"); + metadataAuthorityService.clearCache(); + } } @Test diff --git a/dspace-server-webapp/src/test/java/org/dspace/app/rest/VocabularyRestRepositoryIT.java b/dspace-server-webapp/src/test/java/org/dspace/app/rest/VocabularyRestRepositoryIT.java index 1ff29a2ba228..1eedda87f990 100644 --- a/dspace-server-webapp/src/test/java/org/dspace/app/rest/VocabularyRestRepositoryIT.java +++ b/dspace-server-webapp/src/test/java/org/dspace/app/rest/VocabularyRestRepositoryIT.java @@ -40,6 +40,7 @@ import org.dspace.content.Item; import org.dspace.content.authority.DCInputAuthority; import org.dspace.content.authority.service.ChoiceAuthorityService; +import org.dspace.content.authority.service.MetadataAuthorityService; import org.dspace.content.edit.EditItem; import org.dspace.core.service.PluginService; import org.dspace.services.ConfigurationService; @@ -58,6 +59,9 @@ public class VocabularyRestRepositoryIT extends AbstractControllerIntegrationTes @Autowired private ConfigurationService configurationService; + @Autowired + private MetadataAuthorityService metadataAuthorityService; + @Autowired private SubmissionFormRestRepository submissionFormRestRepository; @@ -149,22 +153,22 @@ public void destroy() throws Exception { public void findAllTest() throws Exception { String token = getAuthToken(admin.getEmail(), password); getClient(token).perform(get("/api/submission/vocabularies")) - .andExpect(status().isOk()) + .andExpect(status().isOk()) .andExpect(jsonPath("$._embedded.vocabularies", Matchers.containsInAnyOrder( VocabularyMatcher.matchProperties("srsc", "srsc", false, true), + VocabularyMatcher.matchProperties("common_iso_languages", "common_iso_languages", true, false), + VocabularyMatcher.matchProperties("SRPublisher", "SRPublisher", false, false), + VocabularyMatcher.matchProperties("patent_types", "patent_types", true, false), + VocabularyMatcher.matchProperties("types", "types", false, true), + VocabularyMatcher.matchProperties("gender", "gender", true, false), + VocabularyMatcher.matchProperties("SolrAuthorAuthority", "SolrAuthorAuthority", false, false), + VocabularyMatcher.matchProperties("SRJournalTitle", "SRJournalTitle", false, false), VocabularyMatcher.matchProperties("common_types", "common_types", true, false), - VocabularyMatcher.matchProperties("common_iso_languages", "common_iso_languages", true , false), - VocabularyMatcher.matchProperties("SolrAuthorAuthority", "SolrAuthorAuthority", false , false), - VocabularyMatcher.matchProperties("patent_types", "patent_types", true , false), - VocabularyMatcher.matchProperties("types", "types", false , true), - VocabularyMatcher.matchProperties("gender", "gender", true , false), - VocabularyMatcher.matchProperties("SRPublisher", "SRPublisher", false , false), - VocabularyMatcher.matchProperties("SRJournalTitle", "SRJournalTitle", false , false), - VocabularyMatcher.matchProperties("publication-coar-types", "publication-coar-types", false , true) - ))) - .andExpect(jsonPath("$._links.self.href", - Matchers.containsString("api/submission/vocabularies"))) - .andExpect(jsonPath("$.page.totalElements", is(10))); + VocabularyMatcher.matchProperties("publication-coar-types", "publication-coar-types", false, true) + ))) + .andExpect(jsonPath("$._links.self.href", + Matchers.containsString("api/submission/vocabularies"))) + .andExpect(jsonPath("$.page.totalElements", is(10))); } @Test @@ -506,140 +510,160 @@ public void linkedEntitiesWithFilterAndEntryIdTest() throws Exception { @Test public void controlledVocabularyWithHierarchyStoreSetTrueTest() throws Exception { context.turnOffAuthorisationSystem(); - String vocabularyName = "publication-coar-types"; - parentCommunity = CommunityBuilder.createCommunity(context) - .withName("Root Community") - .build(); - - Collection col = CollectionBuilder.createCollection(context, parentCommunity) - .withEntityType("Publication") - .withName("Collection 1") - .build(); - - Item itemA = ItemBuilder.createItem(context, col) - .withTitle("Test Item A") - .withIssueDate("2023-04-04") - .withType("Resource Types::text::book::book part", vocabularyName + ":c_3248") - .build(); - - EditItem editItem = new EditItem(context, itemA); - - context.restoreAuthSystemState(); - - String tokenAdmin = getAuthToken(admin.getEmail(), password); - - getClient(tokenAdmin).perform(get("/api/core/items/" + itemA.getID())) - .andExpect(status().isOk()) - .andExpect(jsonPath("$.metadata", Matchers.allOf( - hasJsonPath("$['dc.title'][0].value", is("Test Item A")), - hasJsonPath("$['dc.type'][0].value", is("Resource Types::text::book::book part")), - hasJsonPath("$['dc.type'][0].authority", is(vocabularyName + ":c_3248")), - hasJsonPath("$['dc.type'][0].confidence", is(600)) - ))); - - AtomicReference selectedLeafValue = new AtomicReference<>(); - AtomicReference selectedLeafauthority = new AtomicReference<>(); - - getClient(tokenAdmin).perform(get("/api/submission/vocabularies/" + vocabularyName + "/entries") - .param("metadata", "dc.type") - .param("entryID", vocabularyName + ":c_b239")) - .andExpect(status().isOk()) - .andDo(result -> selectedLeafValue.set(read(result.getResponse().getContentAsString(), - "$._embedded.entries[0].value"))) - .andDo(result -> selectedLeafauthority.set(read(result.getResponse().getContentAsString(), - "$._embedded.entries[0].authority"))); - - List operations = new ArrayList(); - Map value = new HashMap(); - value.put("value", selectedLeafValue.get()); - value.put("authority", selectedLeafauthority.get()); - value.put("confidence", "600"); - operations.add(new ReplaceOperation("/sections/controlled-vocabulary-test/dc.type/0", value)); - - String patchBody = getPatchContent(operations); - getClient(tokenAdmin).perform(patch("/api/core/edititems/" + editItem.getID() + ":MODE-VOC") - .content(patchBody) - .contentType(MediaType.APPLICATION_JSON_PATCH_JSON)) - .andExpect(status().isOk()); - - getClient(tokenAdmin).perform(get("/api/core/items/" + itemA.getID())) - .andExpect(status().isOk()) - .andExpect(jsonPath("$.metadata", Matchers.allOf( - hasJsonPath("$['dc.title'][0].value", is("Test Item A")), - hasJsonPath("$['dc.type'][0].value", is("text::journal::editorial")), - hasJsonPath("$['dc.type'][0].authority", is(vocabularyName + ":c_b239")), - hasJsonPath("$['dc.type'][0].confidence", is(600)) - ))); + try { + configurationService.setProperty("authority.controlled.dc.type", "true"); + metadataAuthorityService.clearCache(); + + String vocabularyName = "publication-coar-types"; + parentCommunity = CommunityBuilder.createCommunity(context) + .withName("Root Community") + .build(); + + Collection col = CollectionBuilder.createCollection(context, parentCommunity) + .withEntityType("Publication") + .withName("Collection 1") + .build(); + + Item itemA = ItemBuilder.createItem(context, col) + .withTitle("Test Item A") + .withIssueDate("2023-04-04") + .withType("Resource Types::text::book::book part", vocabularyName + ":c_3248") + .build(); + + EditItem editItem = new EditItem(context, itemA); + + context.restoreAuthSystemState(); + + String tokenAdmin = getAuthToken(admin.getEmail(), password); + + getClient(tokenAdmin).perform(get("/api/core/items/" + itemA.getID())) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.metadata", Matchers.allOf( + hasJsonPath("$['dc.title'][0].value", is("Test Item A")), + hasJsonPath( + "$['dc.type'][0].value", is("Resource Types::text::book::book part")), + hasJsonPath("$['dc.type'][0].authority", is(vocabularyName + ":c_3248")), + hasJsonPath("$['dc.type'][0].confidence", is(600)) + ))); + + AtomicReference selectedLeafValue = new AtomicReference<>(); + AtomicReference selectedLeafauthority = new AtomicReference<>(); + + getClient(tokenAdmin).perform(get("/api/submission/vocabularies/" + vocabularyName + "/entries") + .param("metadata", "dc.type") + .param("entryID", vocabularyName + ":c_b239")) + .andExpect(status().isOk()) + .andDo(result -> selectedLeafValue.set(read(result.getResponse().getContentAsString(), + "$._embedded.entries[0].value"))) + .andDo(result -> selectedLeafauthority.set( + read(result.getResponse().getContentAsString(), + "$._embedded.entries[0].authority"))); + + List operations = new ArrayList(); + Map value = new HashMap(); + value.put("value", selectedLeafValue.get()); + value.put("authority", selectedLeafauthority.get()); + value.put("confidence", "600"); + operations.add(new ReplaceOperation("/sections/controlled-vocabulary-test/dc.type/0", value)); + + String patchBody = getPatchContent(operations); + getClient(tokenAdmin).perform(patch("/api/core/edititems/" + editItem.getID() + ":MODE-VOC") + .content(patchBody) + .contentType(MediaType.APPLICATION_JSON_PATCH_JSON)) + .andExpect(status().isOk()); + + getClient(tokenAdmin).perform(get("/api/core/items/" + itemA.getID())) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.metadata", Matchers.allOf( + hasJsonPath("$['dc.title'][0].value", is("Test Item A")), + hasJsonPath("$['dc.type'][0].value", is("text::journal::editorial")), + hasJsonPath("$['dc.type'][0].authority", is(vocabularyName + ":c_b239")), + hasJsonPath("$['dc.type'][0].confidence", is(600)) + ))); + } finally { + configurationService.setProperty("authority.controlled.dc.type", "false"); + metadataAuthorityService.clearCache(); + } } @Test public void controlledVocabularyWithHierarchyStoreSetFalseTest() throws Exception { context.turnOffAuthorisationSystem(); - String vocabularyName = "publication-coar-types"; - configurationService.setProperty("vocabulary.plugin." + vocabularyName + ".hierarchy.store", false); - parentCommunity = CommunityBuilder.createCommunity(context) - .withName("Root Community") - .build(); - - Collection col = CollectionBuilder.createCollection(context, parentCommunity) - .withEntityType("Publication") - .withName("Collection 1") - .build(); - - Item itemA = ItemBuilder.createItem(context, col) - .withTitle("Test Item A") - .withIssueDate("2023-04-04") - .withType("Resource Types::text::book::book part", vocabularyName + ":c_3248") - .build(); - - EditItem editItem = new EditItem(context, itemA); - - context.restoreAuthSystemState(); - - String tokenAdmin = getAuthToken(admin.getEmail(), password); - - getClient(tokenAdmin).perform(get("/api/core/items/" + itemA.getID())) - .andExpect(status().isOk()) - .andExpect(jsonPath("$.metadata", Matchers.allOf( - hasJsonPath("$['dc.title'][0].value", is("Test Item A")), - hasJsonPath("$['dc.type'][0].value", is("Resource Types::text::book::book part")), - hasJsonPath("$['dc.type'][0].authority", is(vocabularyName + ":c_3248")), - hasJsonPath("$['dc.type'][0].confidence", is(600)) - ))); - - AtomicReference selectedLeafValue = new AtomicReference<>(); - AtomicReference selectedLeafauthority = new AtomicReference<>(); - - getClient(tokenAdmin).perform(get("/api/submission/vocabularies/" + vocabularyName + "/entries") - .param("metadata", "dc.type") - .param("entryID", vocabularyName + ":c_b239")) - .andExpect(status().isOk()) - .andDo(result -> selectedLeafValue.set(read(result.getResponse().getContentAsString(), - "$._embedded.entries[0].value"))) - .andDo(result -> selectedLeafauthority.set(read(result.getResponse().getContentAsString(), - "$._embedded.entries[0].authority"))); - - List operations = new ArrayList(); - Map value = new HashMap(); - value.put("value", selectedLeafValue.get()); - value.put("authority", selectedLeafauthority.get()); - value.put("confidence", "600"); - operations.add(new ReplaceOperation("/sections/controlled-vocabulary-test/dc.type/0", value)); - - String patchBody = getPatchContent(operations); - getClient(tokenAdmin).perform(patch("/api/core/edititems/" + editItem.getID() + ":MODE-VOC") - .content(patchBody) - .contentType(MediaType.APPLICATION_JSON_PATCH_JSON)) - .andExpect(status().isOk()); - - getClient(tokenAdmin).perform(get("/api/core/items/" + itemA.getID())) - .andExpect(status().isOk()) - .andExpect(jsonPath("$.metadata", Matchers.allOf( - hasJsonPath("$['dc.title'][0].value", is("Test Item A")), - hasJsonPath("$['dc.type'][0].value", is("editorial")), - hasJsonPath("$['dc.type'][0].authority", is(vocabularyName + ":c_b239")), - hasJsonPath("$['dc.type'][0].confidence", is(600)) - ))); + try { + configurationService.setProperty("authority.controlled.dc.type", "true"); + metadataAuthorityService.clearCache(); + + String vocabularyName = "publication-coar-types"; + configurationService.setProperty("vocabulary.plugin." + vocabularyName + ".hierarchy.store", false); + parentCommunity = CommunityBuilder.createCommunity(context) + .withName("Root Community") + .build(); + + Collection col = CollectionBuilder.createCollection(context, parentCommunity) + .withEntityType("Publication") + .withName("Collection 1") + .build(); + + Item itemA = ItemBuilder.createItem(context, col) + .withTitle("Test Item A") + .withIssueDate("2023-04-04") + .withType("Resource Types::text::book::book part", vocabularyName + ":c_3248") + .build(); + + EditItem editItem = new EditItem(context, itemA); + + context.restoreAuthSystemState(); + + String tokenAdmin = getAuthToken(admin.getEmail(), password); + + getClient(tokenAdmin).perform(get("/api/core/items/" + itemA.getID())) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.metadata", Matchers.allOf( + hasJsonPath("$['dc.title'][0].value", is("Test Item A")), + hasJsonPath("$['dc.type'][0].value", + is("Resource Types::text::book::book part")), + hasJsonPath("$['dc.type'][0].authority", is(vocabularyName + ":c_3248")), + hasJsonPath("$['dc.type'][0].confidence", is(600)) + ))); + + AtomicReference selectedLeafValue = new AtomicReference<>(); + AtomicReference selectedLeafauthority = new AtomicReference<>(); + + getClient(tokenAdmin).perform(get("/api/submission/vocabularies/" + vocabularyName + "/entries") + .param("metadata", "dc.type") + .param("entryID", vocabularyName + ":c_b239")) + .andExpect(status().isOk()) + .andDo(result -> selectedLeafValue.set(read(result.getResponse().getContentAsString(), + "$._embedded.entries[0].value"))) + .andDo(result -> selectedLeafauthority.set( + read(result.getResponse().getContentAsString(), + "$._embedded.entries[0].authority"))); + + List operations = new ArrayList(); + Map value = new HashMap(); + value.put("value", selectedLeafValue.get()); + value.put("authority", selectedLeafauthority.get()); + value.put("confidence", "600"); + operations.add(new ReplaceOperation("/sections/controlled-vocabulary-test/dc.type/0", value)); + + String patchBody = getPatchContent(operations); + getClient(tokenAdmin).perform(patch("/api/core/edititems/" + editItem.getID() + ":MODE-VOC") + .content(patchBody) + .contentType(MediaType.APPLICATION_JSON_PATCH_JSON)) + .andExpect(status().isOk()); + + getClient(tokenAdmin).perform(get("/api/core/items/" + itemA.getID())) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.metadata", Matchers.allOf( + hasJsonPath("$['dc.title'][0].value", is("Test Item A")), + hasJsonPath("$['dc.type'][0].value", is("editorial")), + hasJsonPath("$['dc.type'][0].authority", is(vocabularyName + ":c_b239")), + hasJsonPath("$['dc.type'][0].confidence", is(600)) + ))); + } finally { + configurationService.setProperty("authority.controlled.dc.type", "false"); + metadataAuthorityService.clearCache(); + } } @Test 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 3cbbe6850dc9..2d887caa7b2c 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 @@ -57,6 +57,8 @@ import org.dspace.content.Item; import org.dspace.content.MetadataValue; import org.dspace.content.WorkspaceItem; +import org.dspace.content.authority.ChoiceAuthorityServiceImpl; +import org.dspace.content.authority.service.MetadataAuthorityService; import org.dspace.content.service.ItemService; import org.dspace.eperson.EPerson; import org.dspace.external.OrcidRestConnector; @@ -90,6 +92,9 @@ public class CrisConsumerIT extends AbstractControllerIntegrationTest { @Autowired private ConfigurationService configurationService; + @Autowired + private ChoiceAuthorityServiceImpl choiceAuthorityService; + @Value("classpath:org/dspace/app/rest/simple-article.pdf") private Resource simpleArticle; @@ -111,6 +116,9 @@ public class CrisConsumerIT extends AbstractControllerIntegrationTest { @Autowired private OrcidV3AuthorDataProvider orcidV3AuthorDataProvider; + @Autowired + private MetadataAuthorityService metadataAuthorityService; + @Override public void setUp() throws Exception { super.setUp(); @@ -1127,54 +1135,74 @@ public void testOrcidImportFiller() throws Exception { @Test public void testSherpaImportFiller() throws Exception { - String issn = "2731-0582"; + try { + configurationService.setProperty("authority.controlled.dc.relation.journal", "true"); + configurationService.setProperty("choices.plugin.dc.relation.journal", "JournalAuthority"); + configurationService.setProperty("choices.presentation.dc.relation.journal", "suggest"); + configurationService.setProperty("choices.closed.dc.relation.journal", "true"); + configurationService.setProperty("cris.ItemAuthority.JournalAuthority.entityType", "Journal"); + configurationService.setProperty("cris.ItemAuthority.JournalAuthority.relationshipType", "Journal"); + metadataAuthorityService.clearCache(); + choiceAuthorityService.clearCache(); - context.turnOffAuthorisationSystem(); + String issn = "2731-0582"; - Collection journals = createCollection("Collection of journals", "Journal", subCommunity); + context.turnOffAuthorisationSystem(); - Item publication = ItemBuilder.createItem(context, publicationCollection) - .withTitle("Test Publication") - .withRelationJournal("Nature Synthesis", "will be generated::ISSN::" + issn) - .build(); + Collection journals = createCollection("Collection of journals", "Journal", subCommunity); - context.commit(); + Item publication = ItemBuilder.createItem(context, publicationCollection) + .withTitle("Test Publication") + .withRelationJournal("Nature Synthesis", "will be generated::ISSN::" + issn) + .build(); - context.restoreAuthSystemState(); + context.commit(); - String authToken = getAuthToken(submitter.getEmail(), password); - ItemRest item = getItemViaRestByID(authToken, publication.getID()); + context.restoreAuthSystemState(); - MetadataValueRest journalMetadata = findSingleMetadata(item, "dc.relation.journal"); + String authToken = getAuthToken(submitter.getEmail(), password); + ItemRest item = getItemViaRestByID(authToken, publication.getID()); - UUID journalId = UUIDUtils.fromString(journalMetadata.getAuthority()); - assertThat(journalId, notNullValue()); + MetadataValueRest journalMetadata = findSingleMetadata(item, "dc.relation.journal"); - Item journal = itemService.find(context, journalId); - assertThat(journal, notNullValue()); - assertThat(journal.getOwningCollection(), is(journals)); - assertThat(journal.getMetadata(), hasItems( - with("dc.title", "Nature Synthesis"), - with("dc.identifier.issn", issn), - with("cris.sourceId", "ISSN::" + issn))); + UUID journalId = UUIDUtils.fromString(journalMetadata.getAuthority()); + assertThat(journalId, notNullValue()); - context.turnOffAuthorisationSystem(); + Item journal = itemService.find(context, journalId); + assertThat(journal, notNullValue()); + assertThat(journal.getOwningCollection(), is(journals)); + assertThat(journal.getMetadata(), hasItems( + with("dc.title", "Nature Synthesis"), + with("dc.identifier.issn", issn), + with("cris.sourceId", "ISSN::" + issn))); - publicationCollection = context.reloadEntity(publicationCollection); + context.turnOffAuthorisationSystem(); - Item anotherPublication = ItemBuilder.createItem(context, publicationCollection) - .withTitle("Test Publication 2") - .withRelationJournal("Nature Synthesis", "will be generated::ISSN::" + issn) - .build(); + publicationCollection = context.reloadEntity(publicationCollection); - context.commit(); + Item anotherPublication = ItemBuilder.createItem(context, publicationCollection) + .withTitle("Test Publication 2") + .withRelationJournal("Nature Synthesis", "will be generated::ISSN::" + issn) + .build(); - context.restoreAuthSystemState(); + context.commit(); + + context.restoreAuthSystemState(); - item = getItemViaRestByID(authToken, anotherPublication.getID()); - journalMetadata = findSingleMetadata(item, "dc.relation.journal"); - assertThat(UUIDUtils.fromString(journalMetadata.getAuthority()), is(journal.getID())); + item = getItemViaRestByID(authToken, anotherPublication.getID()); + journalMetadata = findSingleMetadata(item, "dc.relation.journal"); + assertThat(UUIDUtils.fromString(journalMetadata.getAuthority()), is(journal.getID())); + } finally { + configurationService.setProperty("authority.controlled.dc.relation.journal", "false"); + configurationService.setProperty("choices.plugin.dc.relation.journal", null); + configurationService.setProperty("choices.presentation.dc.relation.journal", null); + configurationService.setProperty("choices.closed.dc.relation.journal", null); + configurationService.setProperty("cris.ItemAuthority.JournalAuthority.entityType", null); + configurationService.setProperty("cris.ItemAuthority.JournalAuthority.relationshipType", null); + metadataAuthorityService.clearCache(); + choiceAuthorityService.clearCache(); + } } private ItemRest getItemViaRestByID(String authToken, UUID id) throws Exception { From 9135d015696135d883af6c185c2bc98ad1daca4c Mon Sep 17 00:00:00 2001 From: Nikita Krivonosov Date: Sat, 25 Nov 2023 10:31:14 +0100 Subject: [PATCH 2/2] [DSC-1307] - Fix tests in DiscoveryRestControllerMultiLanguageIT --- .../content/authority/ReciprocalItemAuthorityConsumerIT.java | 2 +- .../dspace/app/rest/DiscoveryRestControllerMultiLanguageIT.java | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/dspace-api/src/test/java/org/dspace/content/authority/ReciprocalItemAuthorityConsumerIT.java b/dspace-api/src/test/java/org/dspace/content/authority/ReciprocalItemAuthorityConsumerIT.java index 352be9f2eede..ad5ca83105bf 100644 --- a/dspace-api/src/test/java/org/dspace/content/authority/ReciprocalItemAuthorityConsumerIT.java +++ b/dspace-api/src/test/java/org/dspace/content/authority/ReciprocalItemAuthorityConsumerIT.java @@ -65,7 +65,7 @@ public void setUp() throws Exception { .getConfigurationService(); metadataAuthorityService = ContentAuthorityServiceFactory.getInstance() .getMetadataAuthorityService(); - eventService = EventServiceFactory.getInstance().getEventService() + eventService = EventServiceFactory.getInstance().getEventService(); configurationService.setProperty("ItemAuthority.reciprocalMetadata.Publication.dc.relation.product", "dc.relation.publication"); diff --git a/dspace-server-webapp/src/test/java/org/dspace/app/rest/DiscoveryRestControllerMultiLanguageIT.java b/dspace-server-webapp/src/test/java/org/dspace/app/rest/DiscoveryRestControllerMultiLanguageIT.java index aab6da9a5cec..60f2c183bc45 100644 --- a/dspace-server-webapp/src/test/java/org/dspace/app/rest/DiscoveryRestControllerMultiLanguageIT.java +++ b/dspace-server-webapp/src/test/java/org/dspace/app/rest/DiscoveryRestControllerMultiLanguageIT.java @@ -434,6 +434,7 @@ public void discoverFacetsTypesTestWithUnknownAuthority() throws Exception { @Test public void discoverFacetsTypesTestWithUnknownAuthorityName() throws Exception { + context.turnOffAuthorisationSystem(); try { configurationService.setProperty("authority.controlled.dc.type", "true"); metadataAuthorityService.clearCache();