Skip to content

Commit

Permalink
Merged in task/main-cris/DSC-2092 (pull request DSpace#3248)
Browse files Browse the repository at this point in the history
[DSC-2092]

Approved-by: Giuseppe Digilio
  • Loading branch information
vins01-4science authored and atarix83 committed Dec 27, 2024
2 parents 057a6d1 + 1ddab83 commit 9c874af
Show file tree
Hide file tree
Showing 7 changed files with 209 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@
import org.dspace.importer.external.datamodel.ImportRecord;
import org.dspace.importer.external.exception.MetadataSourceException;
import org.dspace.importer.external.metadatamapping.MetadatumDTO;
import org.dspace.importer.external.ror.service.RorImportMetadataSourceServiceImpl;
import org.dspace.importer.external.ror.service.RorImportMetadataSourceService;
import org.dspace.importer.external.ror.service.RorServicesFactory;
import org.dspace.services.ConfigurationService;
import org.dspace.services.factory.DSpaceServicesFactory;
import org.dspace.utils.DSpace;

public class RorOrgUnitAuthority extends ItemAuthority {

private final RorImportMetadataSourceServiceImpl rorImportMetadataSource = new DSpace().getServiceManager()
.getServicesByType(RorImportMetadataSourceServiceImpl.class).get(0);
private final RorImportMetadataSourceService rorImportMetadataSource =
RorServicesFactory.getInstance().getRorImportMetadataSourceService();

private final ItemAuthorityServiceFactory itemAuthorityServiceFactory =
dspace.getServiceManager().getServiceByName("itemAuthorityServiceFactory", ItemAuthorityServiceFactory.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
*
* http://www.dspace.org/license/
*/
package org.dspace.importer.external.ror.service;

import org.dspace.importer.external.service.components.QuerySource;

/**
* @author Vincenzo Mecca (vins01-4science - vincenzo.mecca at 4science.com)
**/
public interface RorImportMetadataSourceService extends QuerySource {
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.dspace.importer.external.exception.MetadataSourceException;
import org.dspace.importer.external.liveimportclient.service.LiveImportClient;
import org.dspace.importer.external.service.AbstractImportMetadataSourceService;
import org.dspace.importer.external.service.components.QuerySource;
import org.springframework.beans.factory.annotation.Autowired;

/**
Expand All @@ -40,7 +39,7 @@
* @author Vincenzo Mecca (vins01-4science - vincenzo.mecca at 4science.com)
*/
public class RorImportMetadataSourceServiceImpl extends AbstractImportMetadataSourceService<String>
implements QuerySource {
implements RorImportMetadataSourceService {

private final static Logger log = LogManager.getLogger();
protected static final String ROR_IDENTIFIER_PREFIX = "https://ror.org/";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
*
* http://www.dspace.org/license/
*/
package org.dspace.importer.external.ror.service;

import org.dspace.services.factory.DSpaceServicesFactory;

/**
* Factory that handles {@code RorImportMetadataSourceService} instance
*
* @author Vincenzo Mecca (vins01-4science - vincenzo.mecca at 4science.com)
**/
public abstract class RorServicesFactory {

public abstract RorImportMetadataSourceService getRorImportMetadataSourceService();

public static RorServicesFactory getInstance() {
return DSpaceServicesFactory.getInstance().getServiceManager()
.getServiceByName("rorServiceFactory", RorServicesFactory.class);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
*
* http://www.dspace.org/license/
*/
package org.dspace.importer.external.ror.service;

import org.springframework.beans.factory.annotation.Autowired;

/**
* @author Vincenzo Mecca (vins01-4science - vincenzo.mecca at 4science.com)
**/
public class RorServicesFactoryImpl extends RorServicesFactory {

protected RorImportMetadataSourceService metadataSourceService;

public RorServicesFactoryImpl(@Autowired RorImportMetadataSourceService metadataSourceService) {
this.metadataSourceService = metadataSourceService;
}

@Override
public RorImportMetadataSourceService getRorImportMetadataSourceService() {
return metadataSourceService;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@
</bean>
<bean id="scopusMetadataFieldMapping" class="org.dspace.importer.external.scopus.service.ScopusFieldMapping"/>

<bean id="rorServiceFactory" class="org.dspace.importer.external.ror.service.RorServicesFactoryImpl"/>
<bean id="rorImportService" class="org.dspace.importer.external.ror.service.RorImportMetadataSourceServiceImpl">
<property name="metadataFieldMapping" ref="rorMetadataFieldMapping"/>
<property name="url" value="${ror.orgunit-import.api-url}"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,49 +15,160 @@
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.dspace.app.rest.test.AbstractControllerIntegrationTest;
import org.dspace.content.authority.service.ChoiceAuthorityService;
import org.dspace.content.authority.service.MetadataAuthorityService;
import org.dspace.core.service.PluginService;
import org.dspace.importer.external.datamodel.ImportRecord;
import org.dspace.importer.external.metadatamapping.MetadatumDTO;
import org.dspace.importer.external.ror.service.RorImportMetadataSourceService;
import org.dspace.importer.external.ror.service.RorServicesFactory;
import org.dspace.importer.external.ror.service.RorServicesFactoryImpl;
import org.dspace.services.ConfigurationService;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.MockedStatic;
import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;

public class RorOrgUnitAuthorityIT extends AbstractControllerIntegrationTest {

public static final String ROR_ORGUNIT_AUTHORITY =
"org.dspace.content.authority.RorOrgUnitAuthority = OrgUnitAuthority";

public static final String ROR_FILTER = "02z02cv32 OR 03vb2cr34";

private static MockedStatic<RorServicesFactory> mockRorServiceFactory;

@Autowired
protected ChoiceAuthorityService choiceAuthorityService;
@Autowired
protected PluginService pluginService;
@Autowired
protected MetadataAuthorityService metadataAuthorityService;
@Autowired
protected ConfigurationService configurationService;
@Mock
private RorImportMetadataSourceService metadataSourceService;

@BeforeClass
public static void init() {
mockRorServiceFactory = Mockito.mockStatic(RorServicesFactory.class);
}

@AfterClass
public static void close() {
mockRorServiceFactory.close();
}

@Before
public void setup() throws Exception {

RorServicesFactoryImpl rorServiceFactory =
new RorServicesFactoryImpl(this.metadataSourceService);

Mockito.when(
metadataSourceService.getRecords(
ROR_FILTER, 0, 0
)
).thenReturn(List.of(getImportRecord1(), getImportRecord2()));

mockRorServiceFactory.when(RorServicesFactory::getInstance).thenReturn(rorServiceFactory);
}

@Test
public void testAuthority() throws Exception {

Map<String, String> expectedExtras = new HashMap<>();
expectedExtras.put("data-ror_orgunit_id", "https://ror.org/02z02cv32");
expectedExtras.put("ror_orgunit_id", "https://ror.org/02z02cv32");
expectedExtras.put("data-ror_orgunit_type", "Nonprofit");
expectedExtras.put("ror_orgunit_type", "Nonprofit");
expectedExtras.put("data-ror_orgunit_acronym", "WEICan, IEEC");
expectedExtras.put("ror_orgunit_acronym", "WEICan, IEEC");
expectedExtras.put("data-ror_orgunit_country", "CA");
expectedExtras.put("data-ror_orgunit_countryName", "CA");
expectedExtras.put("ror_orgunit_countryName", "CA");

Map<String, String> expectedExtras2 = new HashMap<>();
expectedExtras2.put("data-ror_orgunit_id", "https://ror.org/03vb2cr34");
expectedExtras2.put("ror_orgunit_id", "https://ror.org/03vb2cr34");
expectedExtras2.put("data-ror_orgunit_type", "Company");
expectedExtras2.put("ror_orgunit_type", "Company");
expectedExtras2.put("data-ror_orgunit_countryName", "Italia");
expectedExtras2.put("ror_orgunit_countryName", "Italia");
expectedExtras2.put("data-ror_orgunit_country", "IT");

String token = getAuthToken(eperson.getEmail(), password);
getClient(token).perform(get("/api/submission/vocabularies/OrgUnitAuthority/entries")
.param("filter", "02z02cv32 OR 03vb2cr34"))
.param("filter", ROR_FILTER))
.andExpect(status().isOk())
.andExpect(jsonPath("$._embedded.entries", hasSize(2)))
.andExpect(jsonPath("$._embedded.entries",
hasItems(
matchItemAuthorityWithOtherInformations("will be referenced::ROR-ID::https://ror.org/02z02cv32",
"Wind Energy Institute of Canada", "Wind Energy Institute of Canada", "vocabularyEntry",
expectedExtras),
getExtrasRecord1()
),
matchItemAuthorityWithOtherInformations("will be referenced::ROR-ID::https://ror.org/03vb2cr34",
"4Science", "4Science", "vocabularyEntry",
expectedExtras2))));
getExtrasRecord2()
)
)
));
}

private ImportRecord getImportRecord1() {
return new ImportRecord(
List.of(
new RorMetadatum("dc.title", "Wind Energy Institute of Canada"),
new RorMetadatum("organization.identifier.ror", "https://ror.org/02z02cv32"),
new RorMetadatum("oairecerif.identifier.url", "http://www.weican.ca/"),
new RorMetadatum("dc.type", "Nonprofit"),
new RorMetadatum("oairecerif.acronym", "IEEC"),
new RorMetadatum("oairecerif.acronym", "WEICan"),
new RorMetadatum("organization.address.addressCountry", "CA"),
new RorMetadatum("organization.foundingDate", "1981")

)
);
}

private Map<String, String> getExtrasRecord1() {
Map<String, String> extras = new HashMap<>();
extras.put("data-ror_orgunit_id", "https://ror.org/02z02cv32");
extras.put("ror_orgunit_id", "https://ror.org/02z02cv32");
extras.put("data-ror_orgunit_type", "Nonprofit");
extras.put("ror_orgunit_type", "Nonprofit");
extras.put("data-ror_orgunit_acronym", "IEEC, WEICan");
extras.put("ror_orgunit_acronym", "IEEC, WEICan");
extras.put("data-ror_orgunit_country", "CA");
extras.put("data-ror_orgunit_countryName", "CA");
extras.put("ror_orgunit_countryName", "CA");
return extras;
}

private ImportRecord getImportRecord2() {
return new ImportRecord(
List.of(
new RorMetadatum("dc.title", "4Science"),
new RorMetadatum("organization.identifier.ror", "https://ror.org/03vb2cr34"),
new RorMetadatum("oairecerif.identifier.url", "https://www.4science.it/"),
new RorMetadatum("dc.type", "Company"),
new RorMetadatum("organization.address.addressCountry", "IT"),
new RorMetadatum("organization.foundingDate", "2015")
)
);
}

private Map<String, String> getExtrasRecord2() {
Map<String, String> extras = new HashMap<>();
extras.put("data-ror_orgunit_id", "https://ror.org/03vb2cr34");
extras.put("ror_orgunit_id", "https://ror.org/03vb2cr34");
extras.put("data-ror_orgunit_type", "Company");
extras.put("ror_orgunit_type", "Company");
extras.put("data-ror_orgunit_countryName", "Italia");
extras.put("ror_orgunit_countryName", "Italia");
extras.put("data-ror_orgunit_country", "IT");
return extras;
}

private final class RorMetadatum extends MetadatumDTO {
public RorMetadatum(String field, String value) {
String[] split = field.split("\\.");
setSchema(split[0]);
setElement(split[1]);
if (split.length > 2) {
setQualifier(split[2]);
}
setValue(value);
}
}

}

0 comments on commit 9c874af

Please sign in to comment.