This commit is contained in:
Michele Artini 2024-12-03 09:48:27 +01:00
parent 4cfd49c4f0
commit 9ca02e22c9
5 changed files with 156 additions and 99 deletions

View File

@ -1,7 +1,5 @@
package eu.dnetlib.app.directindex.clients; package eu.dnetlib.app.directindex.clients;
import java.io.Serializable;
import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
@ -10,6 +8,8 @@ import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable; import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import eu.dnetlib.app.directindex.clients.model.ProjectInfo;
@Component @Component
public class ProjectClient implements HasCache { public class ProjectClient implements HasCache {
@ -212,99 +212,4 @@ public class ProjectClient implements HasCache {
return "RCUK".equals(funderShortName) ? "UKRI" : funderShortName; return "RCUK".equals(funderShortName) ? "UKRI" : funderShortName;
} }
public class ProjectInfo implements Serializable {
private static final long serialVersionUID = 4433787349231982285L;
private String id;
private String acronym;
private String title;
private String code;
private String jurisdiction;
private String funderId;
private String funderShortName;
private String funderName;
private String fundingId;
private String fundingName;
public String getId() {
return id;
}
public void setId(final String id) {
this.id = id;
}
public String getAcronym() {
return acronym;
}
public void setAcronym(final String acronym) {
this.acronym = acronym;
}
public String getTitle() {
return title;
}
public void setTitle(final String title) {
this.title = title;
}
public String getCode() {
return code;
}
public void setCode(final String code) {
this.code = code;
}
public String getJurisdiction() {
return jurisdiction;
}
public void setJurisdiction(final String jurisdiction) {
this.jurisdiction = jurisdiction;
}
public String getFunderId() {
return funderId;
}
public void setFunderId(final String funderId) {
this.funderId = funderId;
}
public String getFunderShortName() {
return funderShortName;
}
public void setFunderShortName(final String funderShortName) {
this.funderShortName = funderShortName;
}
public String getFunderName() {
return funderName;
}
public void setFunderName(final String funderName) {
this.funderName = funderName;
}
public String getFundingId() {
return fundingId;
}
public void setFundingId(final String fundingId) {
this.fundingId = fundingId;
}
public String getFundingName() {
return fundingName;
}
public void setFundingName(final String fundingName) {
this.fundingName = fundingName;
}
}
} }

View File

@ -0,0 +1,99 @@
package eu.dnetlib.app.directindex.clients.model;
import java.io.Serializable;
public class ProjectInfo implements Serializable {
private static final long serialVersionUID = 4433787349231982285L;
private String id;
private String acronym;
private String title;
private String code;
private String jurisdiction;
private String funderId;
private String funderShortName;
private String funderName;
private String fundingId;
private String fundingName;
public String getId() {
return id;
}
public void setId(final String id) {
this.id = id;
}
public String getAcronym() {
return acronym;
}
public void setAcronym(final String acronym) {
this.acronym = acronym;
}
public String getTitle() {
return title;
}
public void setTitle(final String title) {
this.title = title;
}
public String getCode() {
return code;
}
public void setCode(final String code) {
this.code = code;
}
public String getJurisdiction() {
return jurisdiction;
}
public void setJurisdiction(final String jurisdiction) {
this.jurisdiction = jurisdiction;
}
public String getFunderId() {
return funderId;
}
public void setFunderId(final String funderId) {
this.funderId = funderId;
}
public String getFunderShortName() {
return funderShortName;
}
public void setFunderShortName(final String funderShortName) {
this.funderShortName = funderShortName;
}
public String getFunderName() {
return funderName;
}
public void setFunderName(final String funderName) {
this.funderName = funderName;
}
public String getFundingId() {
return fundingId;
}
public void setFundingId(final String fundingId) {
this.fundingId = fundingId;
}
public String getFundingName() {
return fundingName;
}
public void setFundingName(final String fundingName) {
this.fundingName = fundingName;
}
}

View File

@ -18,8 +18,8 @@ import eu.dnetlib.app.directindex.clients.CommunityClient;
import eu.dnetlib.app.directindex.clients.CommunityClient.ContextInfo; import eu.dnetlib.app.directindex.clients.CommunityClient.ContextInfo;
import eu.dnetlib.app.directindex.clients.DatasourceManagerClient; import eu.dnetlib.app.directindex.clients.DatasourceManagerClient;
import eu.dnetlib.app.directindex.clients.ProjectClient; import eu.dnetlib.app.directindex.clients.ProjectClient;
import eu.dnetlib.app.directindex.clients.ProjectClient.ProjectInfo;
import eu.dnetlib.app.directindex.clients.VocabularyClient; import eu.dnetlib.app.directindex.clients.VocabularyClient;
import eu.dnetlib.app.directindex.clients.model.ProjectInfo;
import eu.dnetlib.app.directindex.errors.DirectIndexApiException; import eu.dnetlib.app.directindex.errors.DirectIndexApiException;
import eu.dnetlib.app.directindex.input.DatasourceEntry; import eu.dnetlib.app.directindex.input.DatasourceEntry;
import eu.dnetlib.app.directindex.input.PidEntry; import eu.dnetlib.app.directindex.input.PidEntry;

View File

@ -1,11 +1,13 @@
package eu.dnetlib.app.directindex.mapping; package eu.dnetlib.app.directindex.mapping;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail; import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.Mockito.lenient; import static org.mockito.Mockito.lenient;
import static org.mockito.Mockito.times; import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtendWith;
@ -18,6 +20,7 @@ import eu.dnetlib.app.directindex.clients.CommunityClient;
import eu.dnetlib.app.directindex.clients.DatasourceManagerClient; import eu.dnetlib.app.directindex.clients.DatasourceManagerClient;
import eu.dnetlib.app.directindex.clients.ProjectClient; import eu.dnetlib.app.directindex.clients.ProjectClient;
import eu.dnetlib.app.directindex.clients.VocabularyClient; import eu.dnetlib.app.directindex.clients.VocabularyClient;
import eu.dnetlib.app.directindex.clients.model.ProjectInfo;
import eu.dnetlib.app.directindex.errors.DirectIndexApiException; import eu.dnetlib.app.directindex.errors.DirectIndexApiException;
import eu.dnetlib.app.directindex.input.DatasourceEntry; import eu.dnetlib.app.directindex.input.DatasourceEntry;
import eu.dnetlib.app.directindex.input.ResultEntry; import eu.dnetlib.app.directindex.input.ResultEntry;
@ -52,6 +55,23 @@ class SolrRecordMapperTest {
lenient().when(dsmClient.findDatasource(COLLECTED_FROM_ID)).thenReturn(new DatasourceEntry(COLLECTED_FROM_ID, "TEST AGGREGATOR", "test________")); lenient().when(dsmClient.findDatasource(COLLECTED_FROM_ID)).thenReturn(new DatasourceEntry(COLLECTED_FROM_ID, "TEST AGGREGATOR", "test________"));
lenient().when(dsmClient.findDatasource(HOSTED_BY_ID)).thenReturn(new DatasourceEntry(HOSTED_BY_ID, "TEST AGGREGATOR", "test________")); lenient().when(dsmClient.findDatasource(HOSTED_BY_ID)).thenReturn(new DatasourceEntry(HOSTED_BY_ID, "TEST AGGREGATOR", "test________"));
lenient().when(vocClient.findTermLabel("dnet:languages", "eng")).thenReturn("English");
lenient().when(vocClient.findTermLabel("dnet:access_modes", "OPEN")).thenReturn("Open Access");
lenient().when(vocClient.findTermLabel("dnet:countries", "EU")).thenReturn("Europe");
lenient().when(vocClient.findTermLabel("dnet:pid_types", "doi")).thenReturn("doi");
final ProjectInfo project = new ProjectInfo();
project.setCode("283595");
project.setAcronym("OPENAIREPLUS");
project.setTitle("OpenAIREplus");
project.setFunderId("openaire____::EC");
project.setFunderShortName("EC");
project.setFunderName("European Commission");
project.setJurisdiction("EU");
project.setFundingId("ec__________::EC::FP7");
project.setFundingName("FP7");
lenient().when(projectClient.resolveProjectLink("info:eu-repo/grantAgreement/EC/FP7/283595/EU//OpenAIREplus")).thenReturn(project);
} }
@Test @Test
@ -61,7 +81,39 @@ class SolrRecordMapperTest {
final SolrRecord solrRecord = solrRecordMapper.toSolrRecord(result); final SolrRecord solrRecord = solrRecordMapper.toSolrRecord(result);
System.out.println(new ObjectMapper().writeValueAsString(solrRecord)); // System.out.println(new ObjectMapper().writeValueAsString(solrRecord));
assertEquals("test________::1c733a354f58e08710edef8fde95d800", solrRecord.getHeader().getId());
assertEquals("record-oai-12345", solrRecord.getHeader().getOriginalId().get(0));
assertTrue(StringUtils.isNotBlank(solrRecord.getResult().getMaintitle()));
assertEquals(3, solrRecord.getResult().getAuthor().size());
assertTrue(StringUtils.isNotBlank(solrRecord.getResult().getDescription().get(0)));
assertTrue(StringUtils.isNotBlank(solrRecord.getResult().getPublisher()));
verify(vocClient, times(3)).findTermLabel("dnet:pid_types", "doi");
assertEquals(3, solrRecord.getPid().size());
verify(vocClient, times(1)).findTermLabel("dnet:languages", "eng");
assertEquals("eng", solrRecord.getResult().getLanguage().getCode());
assertEquals("English", solrRecord.getResult().getLanguage().getLabel());
verify(vocClient, times(2)).findTermLabel("dnet:access_modes", "OPEN");
assertEquals("OPEN", solrRecord.getResult().getBestaccessright().getCode());
assertEquals("Open Access", solrRecord.getResult().getBestaccessright().getLabel());
assertEquals(1, solrRecord.getLinks().size());
verify(vocClient, times(1)).findTermLabel("dnet:countries", "EU");
assertEquals("OPENAIREPLUS", solrRecord.getLinks().get(0).getAcronym());
assertEquals("OpenAIREplus", solrRecord.getLinks().get(0).getProjectTitle());
assertEquals("283595", solrRecord.getLinks().get(0).getCode());
assertEquals("openaire____::EC", solrRecord.getLinks().get(0).getFunding().getFunder().getId());
assertEquals("EU", solrRecord.getLinks().get(0).getFunding().getFunder().getJurisdiction().getCode());
assertEquals("Europe", solrRecord.getLinks().get(0).getFunding().getFunder().getJurisdiction().getLabel());
assertEquals("EC", solrRecord.getLinks().get(0).getFunding().getFunder().getShortname());
assertEquals("European Commission", solrRecord.getLinks().get(0).getFunding().getFunder().getName());
assertEquals("ec__________::EC::FP7", solrRecord.getLinks().get(0).getFunding().getLevel0().getId());
assertEquals("FP7", solrRecord.getLinks().get(0).getFunding().getLevel0().getName());
} }
@Test @Test

View File

@ -1,4 +1,5 @@
{ {
"openaireId": "test________::1c733a354f58e08710edef8fde95d800",
"originalId" : "record-oai-12345", "originalId" : "record-oai-12345",
"title": "Simple test record", "title": "Simple test record",
"authors": [ "authors": [