Skip to content

Commit 9c874af

Browse files
vins01-4scienceatarix83
authored andcommitted
Merged in task/main-cris/DSC-2092 (pull request DSpace#3248)
[DSC-2092] Approved-by: Giuseppe Digilio
2 parents 057a6d1 + 1ddab83 commit 9c874af

File tree

7 files changed

+209
-29
lines changed

7 files changed

+209
-29
lines changed

dspace-api/src/main/java/org/dspace/content/authority/RorOrgUnitAuthority.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@
2121
import org.dspace.importer.external.datamodel.ImportRecord;
2222
import org.dspace.importer.external.exception.MetadataSourceException;
2323
import org.dspace.importer.external.metadatamapping.MetadatumDTO;
24-
import org.dspace.importer.external.ror.service.RorImportMetadataSourceServiceImpl;
24+
import org.dspace.importer.external.ror.service.RorImportMetadataSourceService;
25+
import org.dspace.importer.external.ror.service.RorServicesFactory;
2526
import org.dspace.services.ConfigurationService;
2627
import org.dspace.services.factory.DSpaceServicesFactory;
27-
import org.dspace.utils.DSpace;
2828

2929
public class RorOrgUnitAuthority extends ItemAuthority {
3030

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

3434
private final ItemAuthorityServiceFactory itemAuthorityServiceFactory =
3535
dspace.getServiceManager().getServiceByName("itemAuthorityServiceFactory", ItemAuthorityServiceFactory.class);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* The contents of this file are subject to the license and copyright
3+
* detailed in the LICENSE and NOTICE files at the root of the source
4+
* tree and available online at
5+
*
6+
* http://www.dspace.org/license/
7+
*/
8+
package org.dspace.importer.external.ror.service;
9+
10+
import org.dspace.importer.external.service.components.QuerySource;
11+
12+
/**
13+
* @author Vincenzo Mecca (vins01-4science - vincenzo.mecca at 4science.com)
14+
**/
15+
public interface RorImportMetadataSourceService extends QuerySource {
16+
}

dspace-api/src/main/java/org/dspace/importer/external/ror/service/RorImportMetadataSourceServiceImpl.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import org.dspace.importer.external.exception.MetadataSourceException;
3232
import org.dspace.importer.external.liveimportclient.service.LiveImportClient;
3333
import org.dspace.importer.external.service.AbstractImportMetadataSourceService;
34-
import org.dspace.importer.external.service.components.QuerySource;
3534
import org.springframework.beans.factory.annotation.Autowired;
3635

3736
/**
@@ -40,7 +39,7 @@
4039
* @author Vincenzo Mecca (vins01-4science - vincenzo.mecca at 4science.com)
4140
*/
4241
public class RorImportMetadataSourceServiceImpl extends AbstractImportMetadataSourceService<String>
43-
implements QuerySource {
42+
implements RorImportMetadataSourceService {
4443

4544
private final static Logger log = LogManager.getLogger();
4645
protected static final String ROR_IDENTIFIER_PREFIX = "https://ror.org/";
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* The contents of this file are subject to the license and copyright
3+
* detailed in the LICENSE and NOTICE files at the root of the source
4+
* tree and available online at
5+
*
6+
* http://www.dspace.org/license/
7+
*/
8+
package org.dspace.importer.external.ror.service;
9+
10+
import org.dspace.services.factory.DSpaceServicesFactory;
11+
12+
/**
13+
* Factory that handles {@code RorImportMetadataSourceService} instance
14+
*
15+
* @author Vincenzo Mecca (vins01-4science - vincenzo.mecca at 4science.com)
16+
**/
17+
public abstract class RorServicesFactory {
18+
19+
public abstract RorImportMetadataSourceService getRorImportMetadataSourceService();
20+
21+
public static RorServicesFactory getInstance() {
22+
return DSpaceServicesFactory.getInstance().getServiceManager()
23+
.getServiceByName("rorServiceFactory", RorServicesFactory.class);
24+
}
25+
26+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* The contents of this file are subject to the license and copyright
3+
* detailed in the LICENSE and NOTICE files at the root of the source
4+
* tree and available online at
5+
*
6+
* http://www.dspace.org/license/
7+
*/
8+
package org.dspace.importer.external.ror.service;
9+
10+
import org.springframework.beans.factory.annotation.Autowired;
11+
12+
/**
13+
* @author Vincenzo Mecca (vins01-4science - vincenzo.mecca at 4science.com)
14+
**/
15+
public class RorServicesFactoryImpl extends RorServicesFactory {
16+
17+
protected RorImportMetadataSourceService metadataSourceService;
18+
19+
public RorServicesFactoryImpl(@Autowired RorImportMetadataSourceService metadataSourceService) {
20+
this.metadataSourceService = metadataSourceService;
21+
}
22+
23+
@Override
24+
public RorImportMetadataSourceService getRorImportMetadataSourceService() {
25+
return metadataSourceService;
26+
}
27+
}

dspace-api/src/main/resources/spring/spring-dspace-addon-import-services.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@
187187
</bean>
188188
<bean id="scopusMetadataFieldMapping" class="org.dspace.importer.external.scopus.service.ScopusFieldMapping"/>
189189

190+
<bean id="rorServiceFactory" class="org.dspace.importer.external.ror.service.RorServicesFactoryImpl"/>
190191
<bean id="rorImportService" class="org.dspace.importer.external.ror.service.RorImportMetadataSourceServiceImpl">
191192
<property name="metadataFieldMapping" ref="rorMetadataFieldMapping"/>
192193
<property name="url" value="${ror.orgunit-import.api-url}"/>

dspace-server-webapp/src/test/java/org/dspace/app/rest/RorOrgUnitAuthorityIT.java

Lines changed: 134 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,49 +15,160 @@
1515
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
1616

1717
import java.util.HashMap;
18+
import java.util.List;
1819
import java.util.Map;
1920

2021
import org.dspace.app.rest.test.AbstractControllerIntegrationTest;
22+
import org.dspace.content.authority.service.ChoiceAuthorityService;
23+
import org.dspace.content.authority.service.MetadataAuthorityService;
24+
import org.dspace.core.service.PluginService;
25+
import org.dspace.importer.external.datamodel.ImportRecord;
26+
import org.dspace.importer.external.metadatamapping.MetadatumDTO;
27+
import org.dspace.importer.external.ror.service.RorImportMetadataSourceService;
28+
import org.dspace.importer.external.ror.service.RorServicesFactory;
29+
import org.dspace.importer.external.ror.service.RorServicesFactoryImpl;
30+
import org.dspace.services.ConfigurationService;
31+
import org.junit.AfterClass;
32+
import org.junit.Before;
33+
import org.junit.BeforeClass;
2134
import org.junit.Test;
35+
import org.mockito.Mock;
36+
import org.mockito.MockedStatic;
37+
import org.mockito.Mockito;
38+
import org.springframework.beans.factory.annotation.Autowired;
2239

2340
public class RorOrgUnitAuthorityIT extends AbstractControllerIntegrationTest {
2441

42+
public static final String ROR_ORGUNIT_AUTHORITY =
43+
"org.dspace.content.authority.RorOrgUnitAuthority = OrgUnitAuthority";
44+
45+
public static final String ROR_FILTER = "02z02cv32 OR 03vb2cr34";
46+
47+
private static MockedStatic<RorServicesFactory> mockRorServiceFactory;
48+
49+
@Autowired
50+
protected ChoiceAuthorityService choiceAuthorityService;
51+
@Autowired
52+
protected PluginService pluginService;
53+
@Autowired
54+
protected MetadataAuthorityService metadataAuthorityService;
55+
@Autowired
56+
protected ConfigurationService configurationService;
57+
@Mock
58+
private RorImportMetadataSourceService metadataSourceService;
59+
60+
@BeforeClass
61+
public static void init() {
62+
mockRorServiceFactory = Mockito.mockStatic(RorServicesFactory.class);
63+
}
64+
65+
@AfterClass
66+
public static void close() {
67+
mockRorServiceFactory.close();
68+
}
69+
70+
@Before
71+
public void setup() throws Exception {
72+
73+
RorServicesFactoryImpl rorServiceFactory =
74+
new RorServicesFactoryImpl(this.metadataSourceService);
75+
76+
Mockito.when(
77+
metadataSourceService.getRecords(
78+
ROR_FILTER, 0, 0
79+
)
80+
).thenReturn(List.of(getImportRecord1(), getImportRecord2()));
81+
82+
mockRorServiceFactory.when(RorServicesFactory::getInstance).thenReturn(rorServiceFactory);
83+
}
84+
2585
@Test
2686
public void testAuthority() throws Exception {
2787

28-
Map<String, String> expectedExtras = new HashMap<>();
29-
expectedExtras.put("data-ror_orgunit_id", "https://ror.org/02z02cv32");
30-
expectedExtras.put("ror_orgunit_id", "https://ror.org/02z02cv32");
31-
expectedExtras.put("data-ror_orgunit_type", "Nonprofit");
32-
expectedExtras.put("ror_orgunit_type", "Nonprofit");
33-
expectedExtras.put("data-ror_orgunit_acronym", "WEICan, IEEC");
34-
expectedExtras.put("ror_orgunit_acronym", "WEICan, IEEC");
35-
expectedExtras.put("data-ror_orgunit_country", "CA");
36-
expectedExtras.put("data-ror_orgunit_countryName", "CA");
37-
expectedExtras.put("ror_orgunit_countryName", "CA");
38-
39-
Map<String, String> expectedExtras2 = new HashMap<>();
40-
expectedExtras2.put("data-ror_orgunit_id", "https://ror.org/03vb2cr34");
41-
expectedExtras2.put("ror_orgunit_id", "https://ror.org/03vb2cr34");
42-
expectedExtras2.put("data-ror_orgunit_type", "Company");
43-
expectedExtras2.put("ror_orgunit_type", "Company");
44-
expectedExtras2.put("data-ror_orgunit_countryName", "Italia");
45-
expectedExtras2.put("ror_orgunit_countryName", "Italia");
46-
expectedExtras2.put("data-ror_orgunit_country", "IT");
47-
4888
String token = getAuthToken(eperson.getEmail(), password);
4989
getClient(token).perform(get("/api/submission/vocabularies/OrgUnitAuthority/entries")
50-
.param("filter", "02z02cv32 OR 03vb2cr34"))
90+
.param("filter", ROR_FILTER))
5191
.andExpect(status().isOk())
5292
.andExpect(jsonPath("$._embedded.entries", hasSize(2)))
5393
.andExpect(jsonPath("$._embedded.entries",
5494
hasItems(
5595
matchItemAuthorityWithOtherInformations("will be referenced::ROR-ID::https://ror.org/02z02cv32",
5696
"Wind Energy Institute of Canada", "Wind Energy Institute of Canada", "vocabularyEntry",
57-
expectedExtras),
97+
getExtrasRecord1()
98+
),
5899
matchItemAuthorityWithOtherInformations("will be referenced::ROR-ID::https://ror.org/03vb2cr34",
59100
"4Science", "4Science", "vocabularyEntry",
60-
expectedExtras2))));
101+
getExtrasRecord2()
102+
)
103+
)
104+
));
105+
}
106+
107+
private ImportRecord getImportRecord1() {
108+
return new ImportRecord(
109+
List.of(
110+
new RorMetadatum("dc.title", "Wind Energy Institute of Canada"),
111+
new RorMetadatum("organization.identifier.ror", "https://ror.org/02z02cv32"),
112+
new RorMetadatum("oairecerif.identifier.url", "http://www.weican.ca/"),
113+
new RorMetadatum("dc.type", "Nonprofit"),
114+
new RorMetadatum("oairecerif.acronym", "IEEC"),
115+
new RorMetadatum("oairecerif.acronym", "WEICan"),
116+
new RorMetadatum("organization.address.addressCountry", "CA"),
117+
new RorMetadatum("organization.foundingDate", "1981")
118+
119+
)
120+
);
121+
}
122+
123+
private Map<String, String> getExtrasRecord1() {
124+
Map<String, String> extras = new HashMap<>();
125+
extras.put("data-ror_orgunit_id", "https://ror.org/02z02cv32");
126+
extras.put("ror_orgunit_id", "https://ror.org/02z02cv32");
127+
extras.put("data-ror_orgunit_type", "Nonprofit");
128+
extras.put("ror_orgunit_type", "Nonprofit");
129+
extras.put("data-ror_orgunit_acronym", "IEEC, WEICan");
130+
extras.put("ror_orgunit_acronym", "IEEC, WEICan");
131+
extras.put("data-ror_orgunit_country", "CA");
132+
extras.put("data-ror_orgunit_countryName", "CA");
133+
extras.put("ror_orgunit_countryName", "CA");
134+
return extras;
135+
}
136+
137+
private ImportRecord getImportRecord2() {
138+
return new ImportRecord(
139+
List.of(
140+
new RorMetadatum("dc.title", "4Science"),
141+
new RorMetadatum("organization.identifier.ror", "https://ror.org/03vb2cr34"),
142+
new RorMetadatum("oairecerif.identifier.url", "https://www.4science.it/"),
143+
new RorMetadatum("dc.type", "Company"),
144+
new RorMetadatum("organization.address.addressCountry", "IT"),
145+
new RorMetadatum("organization.foundingDate", "2015")
146+
)
147+
);
148+
}
149+
150+
private Map<String, String> getExtrasRecord2() {
151+
Map<String, String> extras = new HashMap<>();
152+
extras.put("data-ror_orgunit_id", "https://ror.org/03vb2cr34");
153+
extras.put("ror_orgunit_id", "https://ror.org/03vb2cr34");
154+
extras.put("data-ror_orgunit_type", "Company");
155+
extras.put("ror_orgunit_type", "Company");
156+
extras.put("data-ror_orgunit_countryName", "Italia");
157+
extras.put("ror_orgunit_countryName", "Italia");
158+
extras.put("data-ror_orgunit_country", "IT");
159+
return extras;
160+
}
161+
162+
private final class RorMetadatum extends MetadatumDTO {
163+
public RorMetadatum(String field, String value) {
164+
String[] split = field.split("\\.");
165+
setSchema(split[0]);
166+
setElement(split[1]);
167+
if (split.length > 2) {
168+
setQualifier(split[2]);
169+
}
170+
setValue(value);
171+
}
61172
}
62173

63174
}

0 commit comments

Comments
 (0)