Refactors Funder, Grant and Project external fetching by adding distinct values for key, indicating the source it was fetched, and it's respected display value.

This commit is contained in:
gkolokythas 2020-01-14 13:00:02 +02:00
parent ff9aa14047
commit 3aa7dc0481
14 changed files with 201 additions and 54 deletions

View File

@ -17,6 +17,7 @@ public class FunderBuilder extends Builder<Funder> {
private Date modified;
private Integer type;
private String source;
private String key;
public FunderBuilder id(UUID id) {
this.id = id;
@ -63,6 +64,11 @@ public class FunderBuilder extends Builder<Funder> {
return this;
}
public FunderBuilder key(String key) {
this.key = key;
return this;
}
@Override
public Funder build() {
Funder funder = new Funder();
@ -75,6 +81,7 @@ public class FunderBuilder extends Builder<Funder> {
funder.setModified(modified);
funder.setType(type);
funder.setSource(source);
funder.setKey(key);
return funder;
}
}

View File

@ -9,9 +9,6 @@ import java.util.Date;
import java.util.List;
import java.util.UUID;
/**
* Created by ikalyvas on 2/15/2018.
*/
public class GrantBuilder extends Builder<Grant> {
private UUID id;
@ -44,6 +41,8 @@ public class GrantBuilder extends Builder<Grant> {
private String source;
private String key;
public GrantBuilder id(UUID id) {
this.id = id;
return this;
@ -119,6 +118,11 @@ public class GrantBuilder extends Builder<Grant> {
return this;
}
public GrantBuilder key(String key) {
this.key = key;
return this;
}
@Override
public Grant build() {
Grant grant = new Grant();
@ -137,6 +141,7 @@ public class GrantBuilder extends Builder<Grant> {
grant.setCreationUser(creationUser);
grant.setStartDate(startDate);
grant.setSource(source);
grant.setKey(key);
return grant;
}
}

View File

@ -28,6 +28,7 @@ public class ProjectBuilder extends Builder<Project> {
private Date modified;
private String description;
private String source;
private String key;
public ProjectBuilder id(UUID id) {
this.id = id;
@ -109,6 +110,11 @@ public class ProjectBuilder extends Builder<Project> {
return this;
}
public ProjectBuilder key(String key) {
this.key = key;
return this;
}
@Override
public Project build() {
Project project = new Project();
@ -127,6 +133,7 @@ public class ProjectBuilder extends Builder<Project> {
project.setCreationUser(creationUser);
project.setStartDate(startDate);
project.setSource(source);
project.setKey(key);
return project;
}
}

View File

@ -3,6 +3,7 @@ package eu.eudat.logic.managers;
import eu.eudat.data.query.items.item.funder.FunderCriteriaRequest;
import eu.eudat.logic.builders.model.models.FunderBuilder;
import eu.eudat.logic.proxy.config.ExternalUrlCriteria;
import eu.eudat.logic.proxy.config.configloaders.ConfigLoader;
import eu.eudat.logic.proxy.config.exceptions.HugeResultSet;
import eu.eudat.logic.proxy.config.exceptions.NoURLFound;
import eu.eudat.logic.proxy.fetching.RemoteFetcher;
@ -47,6 +48,8 @@ public class FunderManager {
eu.eudat.models.data.funder.Funder funder = apiContext.getOperationsContext().getBuilderFactory().getBuilder(FunderBuilder.class)
.reference(externalListingItem.getRemoteId()).label(externalListingItem.getName())
.status(eu.eudat.data.entities.Funder.Status.fromInteger(0))
.key(externalListingItem.getKey())
.source(externalListingItem.getTag())
.build();
if (externalListingItem.getSource() != null) {
funder.setSource(externalListingItem.getSource());

View File

@ -134,6 +134,7 @@ public class GrantManager {
eu.eudat.models.data.grant.Grant grant = apiContext.getOperationsContext().getBuilderFactory().getBuilder(GrantBuilder.class)
.reference(externalListingItem.getRemoteId()).label(externalListingItem.getName())
.description(externalListingItem.getDescription()).uri(externalListingItem.getUri())
.key(externalListingItem.getKey())
.abbreviation(externalListingItem.getAbbreviation()).status(eu.eudat.data.entities.Grant.Status.fromInteger(0))
.source(externalListingItem.getTag())
.build();

View File

@ -48,6 +48,7 @@ public class ProjectManager {
.reference(externalListingItem.getRemoteId()).label(externalListingItem.getName())
.description(externalListingItem.getDescription()).uri(externalListingItem.getUri())
.abbreviation(externalListingItem.getAbbreviation()).status(eu.eudat.data.entities.Project.Status.fromInteger(0))
.key(externalListingItem.getKey())
.source(externalListingItem.getTag())
.build();

View File

@ -129,7 +129,7 @@ public class RemoteFetcher {
for (UrlConfiguration urlConfig : urlConfigs) {
ifFunderQueryExist(urlConfig, externalUrlCriteria);
if (urlConfig.getType() == null || urlConfig.getType().equals("External")) {
results.addAll(getAllResultsFromUrl(urlConfig.getUrl(), fetchStrategy, urlConfig.getData(), urlConfig.getPaginationPath(), externalUrlCriteria, urlConfig.getLabel(), urlConfig.getContentType(), urlConfig.getFirstpage()));
results.addAll(getAllResultsFromUrl(urlConfig.getUrl(), fetchStrategy, urlConfig.getData(), urlConfig.getPaginationPath(), externalUrlCriteria, urlConfig.getLabel(), urlConfig.getKey(), urlConfig.getContentType(), urlConfig.getFirstpage()));
} else if (urlConfig.getType() != null && urlConfig.getType().equals("Internal")) {
results.addAll(getAllResultsFromMockUpJson(urlConfig.getUrl(), externalUrlCriteria.getLike()));
}
@ -184,14 +184,14 @@ public class RemoteFetcher {
return completedPath;
}
private List<Map<String, String>> getAllResultsFromUrl(String path, FetchStrategy fetchStrategy, final DataUrlConfiguration jsonDataPath, final String jsonPaginationPath, ExternalUrlCriteria externalUrlCriteria, String key, String contentType, String firstPage) throws HugeResultSet {
private List<Map<String, String>> getAllResultsFromUrl(String path, FetchStrategy fetchStrategy, final DataUrlConfiguration jsonDataPath, final String jsonPaginationPath, ExternalUrlCriteria externalUrlCriteria, String tag, String key, String contentType, String firstPage) throws HugeResultSet {
Set<Integer> pages = new HashSet<>();
String replacedPath = replaceCriteriaOnUrl(path, externalUrlCriteria, firstPage);
Results results = getResultsFromUrl(replacedPath, jsonDataPath, jsonPaginationPath, contentType);
if (fetchStrategy == FetchStrategy.FIRST)
return results == null ? new LinkedList<>() : results.getResults().stream().peek(x -> x.put("tag", key)).collect(Collectors.toList());
return results == null ? new LinkedList<>() : results.getResults().stream().peek(x -> x.put("tag", tag)).peek(x -> x.put("key", key)).collect(Collectors.toList());
if (results != null && results.getPagination() != null && results.getPagination().get("pages") != null) //if has more pages, add them to the pages set
for (int i = 2; i <= results.getPagination().get("pages"); i++)
@ -210,7 +210,7 @@ public class RemoteFetcher {
Results remainingResults = optionalResults.orElseGet(Results::new);
remainingResults.getResults().addAll(results.getResults());
return remainingResults.getResults().stream().peek(x -> x.put("tag", key)).collect(Collectors.toList());
return remainingResults.getResults().stream().peek(x -> x.put("tag", tag)).collect(Collectors.toList());
}
@ -271,8 +271,7 @@ public class RemoteFetcher {
String filePath = Paths.get(path).toUri().toURL().toString();
ObjectMapper mapper = new ObjectMapper();
internalResults = mapper.readValue(new File(filePath), new TypeReference<List<Map<String, Object>>>(){});
searchListMap(internalResults, query);
return internalResults;
return searchListMap(internalResults, query);
} catch (Exception e) {
e.printStackTrace();
return new LinkedList<>();

View File

@ -15,6 +15,7 @@ public class FundersExternalSourcesModel extends ExternalListingItem<FundersExte
model.setDescription(item.get("description"));
model.setSource(item.get("source"));
model.setTag(item.get("tag"));
model.setKey(item.get("key"));
this.add(model);
}
return this;

View File

@ -14,6 +14,7 @@ public class GrantsExternalSourcesModel extends ExternalListingItem<GrantsExtern
model.setName(item.get("name"));
model.setDescription(item.get("description"));
model.setTag(item.get("tag"));
model.setKey(item.get("key"));
this.add(model);
}
return this;

View File

@ -51,6 +51,13 @@ public class ProjectsExternalSourcesModel extends ExternalListingItem<ProjectsEx
model.setTag(item.get("tag"));
}
JsonNode key = node.get("key");
if (key != null && !key.isNull() && key.isObject()) {
model.setKey(node.get("key").get("$").asText());
} else {
model.setKey(item.get("key"));
}
this.add(model);
} catch (IOException e) {

View File

@ -16,6 +16,7 @@ public class Funder implements DataModel<eu.eudat.data.entities.Funder, Funder>
private Date modified;
private Integer type;
private String source;
private String key;
public UUID getId() {
return id;
@ -80,6 +81,13 @@ public class Funder implements DataModel<eu.eudat.data.entities.Funder, Funder>
this.source = source;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
@Override
public Funder fromDataModel(eu.eudat.data.entities.Funder entity) {
this.id = entity.getId();
@ -93,9 +101,9 @@ public class Funder implements DataModel<eu.eudat.data.entities.Funder, Funder>
if (entity.getReference() != null) {
String source = entity.getReference().substring(0, entity.getReference().indexOf(":"));
if (source.equals("dmp")) {
this.source = "Internal";
this.key = "Internal";
} else {
this.source = source;
this.key = source;
}
}
@ -105,19 +113,26 @@ public class Funder implements DataModel<eu.eudat.data.entities.Funder, Funder>
@Override
public eu.eudat.data.entities.Funder toDataModel() {
eu.eudat.data.entities.Funder entity = new eu.eudat.data.entities.Funder();
entity.setId(UUID.randomUUID());
if (this.getId() != null) {
entity.setId(this.getId());
} else {
entity.setId(UUID.randomUUID());
}
entity.setLabel(this.label);
entity.setType(this.type);
if (this.source != null && this.source.equals("Internal")) this.source = "dmp";
if (this.source == null && this.reference != null && this.reference.startsWith("dmp:")) {
entity.setReference(this.reference);
// If internal, key has no value, fill it.
if ((this.source != null && this.source.equals("Internal")) || (this.key != null && this.key.equals("Internal"))) this.key = "dmp";
// Logic for the different "key" cases.
if ((this.key == null || this.key.trim().isEmpty()) && (this.source != null && !this.source.trim().isEmpty())) {
this.key = this.source;
}
if (this.reference != null && !this.reference.trim().isEmpty()
&& this.source != null && !this.source.trim().isEmpty()) {
if (this.source.equals(this.reference.substring(0, this.source.length()))) {
if (this.reference != null && this.reference.startsWith("dmp:")) {
entity.setReference(this.reference);
} else if (this.reference != null && !this.reference.trim().isEmpty() && this.key != null && !this.key.trim().isEmpty()) {
if (this.key.equals(this.reference.substring(0, this.key.length()))) {
entity.setReference(this.reference);
} else {
entity.setReference(this.source.toLowerCase() + ":" + this.reference);
entity.setReference(this.key.toLowerCase() + ":" + this.reference);
}
}
entity.setDefinition(this.definition);

View File

@ -32,6 +32,7 @@ public class Grant implements DataModel<eu.eudat.data.entities.Grant, Grant> {
private List<ContentFile> files;
private UUID funderId;
private String source;
private String key;
public UUID getId() {
return id;
@ -159,6 +160,13 @@ public class Grant implements DataModel<eu.eudat.data.entities.Grant, Grant> {
this.source = source;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
@Override
public Grant fromDataModel(eu.eudat.data.entities.Grant entity) {
this.id = entity.getId();
@ -180,9 +188,9 @@ public class Grant implements DataModel<eu.eudat.data.entities.Grant, Grant> {
if (entity.getReference() != null) {
String source = entity.getReference().substring(0, entity.getReference().indexOf(":"));
if (source.equals("dmp")) {
this.source = "Internal";
this.key = "Internal";
} else {
this.source = source;
this.key = source;
}
}
@ -192,20 +200,22 @@ public class Grant implements DataModel<eu.eudat.data.entities.Grant, Grant> {
@Override
public eu.eudat.data.entities.Grant toDataModel() {
eu.eudat.data.entities.Grant entity = new eu.eudat.data.entities.Grant();
entity.setId(UUID.randomUUID());
if (this.getId() != null) {
entity.setId(this.getId());
} else {
entity.setId(UUID.randomUUID());
}
entity.setAbbreviation(this.abbreviation);
entity.setLabel(this.label);
entity.setType(this.type);
if (this.source != null && this.source.equals("Internal")) this.source = "dmp";
if (this.source == null && this.reference != null && this.reference.startsWith("dmp:")) {
if ((this.source != null && this.source.equals("Internal")) || (this.key != null && this.key.equals("Internal"))) this.key = "dmp";
if (this.reference != null && this.reference.startsWith("dmp:")) {
entity.setReference(this.reference);
}
if (this.reference != null && !this.reference.trim().isEmpty()
&& this.source != null && !this.source.trim().isEmpty()) {
if (this.source.equals(this.reference.substring(0, this.source.length()))) {
} else if (this.reference != null && !this.reference.trim().isEmpty() && this.key != null && !this.key.trim().isEmpty()) {
if (this.key.equals(this.reference.substring(0, this.key.length()))) {
entity.setReference(this.reference);
} else {
entity.setReference(this.source.toLowerCase() + ":" + this.reference);
entity.setReference(this.key.toLowerCase() + ":" + this.reference);
}
}
entity.setUri(this.uri);

View File

@ -29,6 +29,7 @@ public class Project implements DataModel<eu.eudat.data.entities.Project, Projec
private String description;
private List<ContentFile> files;
private String source;
private String key;
public UUID getId() {
return id;
@ -149,6 +150,13 @@ public class Project implements DataModel<eu.eudat.data.entities.Project, Projec
this.source = source;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
@Override
public Project fromDataModel(eu.eudat.data.entities.Project entity) {
this.id = entity.getId();
@ -168,9 +176,9 @@ public class Project implements DataModel<eu.eudat.data.entities.Project, Projec
if (entity.getReference() != null) {
String source = entity.getReference().substring(0, entity.getReference().indexOf(":"));
if (source.equals("dmp")) {
this.source = "Internal";
this.key = "Internal";
} else {
this.source = source;
this.key = source;
}
}
@ -184,16 +192,14 @@ public class Project implements DataModel<eu.eudat.data.entities.Project, Projec
entity.setAbbreviation(this.abbreviation);
entity.setLabel(this.label);
entity.setType(this.type);
if (this.source != null && this.source.equals("Internal")) this.source = "dmp";
if (this.source == null && this.reference != null && this.reference.startsWith("dmp:")) {
if ((this.source != null && this.source.equals("Internal")) || (this.key != null && this.key.equals("Internal"))) this.key = "dmp";
if (this.reference != null && this.reference.startsWith("dmp:")) {
entity.setReference(this.reference);
}
if (this.reference != null && !this.reference.trim().isEmpty()
&& this.source != null && !this.source.trim().isEmpty()) {
if (this.source.equals(this.reference.substring(0, this.source.length()))) {
} else if (this.reference != null && !this.reference.trim().isEmpty() && this.key != null && !this.key.trim().isEmpty()) {
if (this.key.equals(this.reference.substring(0, this.key.length()))) {
entity.setReference(this.reference);
} else {
entity.setReference(this.source.toLowerCase() + ":" + this.reference);
entity.setReference(this.key.toLowerCase() + ":" + this.reference);
}
}
entity.setUri(this.uri);

View File

@ -49,7 +49,7 @@
<label>Internal</label>
<ordinal>1</ordinal>
<type>Internal</type>
<url>mockData/RegistriesInternalMockUpData.json</url>
<url>web/src/main/resources/mockData/RegistriesInternalMockUpData.json</url>
<data>
<path>$['data'][*]['attributes']</path>
<fields>
@ -109,7 +109,7 @@
<label>internal</label>
<ordinal>1</ordinal>
<type>Internal</type>
<url>mockData/TagsInternalMockUpData.json</url>
<url>web/src/main/resources/mockData/TagsInternalMockUpData.json</url>
<data>
<path>$['data'][*]['attributes']</path>
<fields>
@ -146,7 +146,7 @@
<paginationpath>$['meta']['pagination']['page','pages','count']</paginationpath>
</urlConfig>
<urlConfig>
<key>openAIRE</key>
<key>openaire</key>
<label>OpenAIRE</label>
<ordinal>1</ordinal>
<url>https://services.openaire.eu/search/v2/api/resources?query=((oaftype%20exact%20project)%20and%20((projectcode_nt%20exact%20%22{like}%22)or({like}))){funderQuery}&amp;page={page}&amp;size={pageSize}&amp;format=json</url>
@ -185,7 +185,7 @@
<key>internal</key>
<label>Internal</label>
<ordinal>1</ordinal>
<url>mockData/GrantInternalMockUpData.json</url>
<url>web/src/main/resources/mockData/GrantInternalMockUpData.json</url>
<type>Internal</type>
<data>
<path>$['data'][*]['attributes']</path>
@ -224,7 +224,7 @@
<paginationpath>$['meta']['pagination']['page','pages','count']</paginationpath>
</urlConfig>
<urlConfig>
<key>openAIRE</key>
<key>openaire</key>
<label>OpenAIRE</label>
<ordinal>1</ordinal>
<type>External</type>
@ -265,7 +265,7 @@
<label>Internal</label>
<ordinal>1</ordinal>
<type>Internal</type>
<url>mockData/ProjectInternalMockUpData.json</url>
<url>web/src/main/resources/mockData/ProjectInternalMockUpData.json</url>
<data>
<path>$['data'][*]['attributes']</path>
<fields>
@ -283,6 +283,74 @@
<funders>
<urls>
<urlConfig>
<key>openaire</key>
<label>OpenAIRE</label>
<ordinal>1</ordinal>
<type>External</type>
<url>https://services.openaire.eu/search/v2/api/publications?&amp;refine=true&amp;fields=relfunder&amp;page={page}&amp;size=0&amp;format=json</url>
<firstPage>0</firstPage>
<contenttype>application/json; charset=utf-8</contenttype>
<data>
<path>$['refineResults']['relfunder'][*]</path>
<fields>
<name>'name'</name>
<id>'id'</id>
<count>'count'</count>
</fields>
</data>
</urlConfig>
<urlConfig>
<key>openaire</key>
<label>OpenAIRE</label>
<ordinal>1</ordinal>
<type>External</type>
<url>https://services.openaire.eu/search/v2/api/datasets?&amp;refine=true&amp;fields=relfunder&amp;page=0&amp;size={page}&amp;format=json</url>
<firstPage>0</firstPage>
<contenttype>application/json; charset=utf-8</contenttype>
<data>
<path>$['refineResults']['relfunder'][*]</path>
<fields>
<name>'name'</name>
<id>'id'</id>
<count>'count'</count>
</fields>
</data>
</urlConfig>
<urlConfig>
<key>openaire</key>
<label>OpenAIRE</label>
<ordinal>1</ordinal>
<type>External</type>
<url>https://services.openaire.eu/search/v2/api/software?&amp;refine=true&amp;fields=relfunder&amp;page={page}&amp;size=0&amp;format=json</url>
<firstPage>0</firstPage>
<contenttype>application/json; charset=utf-8</contenttype>
<data>
<path>$['refineResults']['relfunder'][*]</path>
<fields>
<name>'name'</name>
<id>'id'</id>
<count>'count'</count>
</fields>
</data>
</urlConfig>
<urlConfig>
<key>openaire</key>
<label>OpenAIRE</label>
<ordinal>1</ordinal>
<type>External</type>
<url>https://services.openaire.eu/search/v2/api/other?&amp;refine=true&amp;fields=relfunder&amp;page={page}&amp;size=0&amp;format=json</url>
<firstPage>0</firstPage>
<contenttype>application/json; charset=utf-8</contenttype>
<data>
<path>$['refineResults']['relfunder'][*]</path>
<fields>
<name>'name'</name>
<id>'id'</id>
<count>'count'</count>
</fields>
</data>
</urlConfig>
<!-- <urlConfig>
<key>cristin</key>
<label>Cristin</label>
@ -303,8 +371,8 @@
<paginationpath>$['meta']['pagination']['page','pages','count']</paginationpath>
</urlConfig>-->
<urlConfig>
<key>openAire</key>
<label>OpenAIRE</label>
<key>cristin</key>
<label>Cristin</label>
<ordinal>1</ordinal>
<type>External</type>
<url>https://eestore.paas2.uninett.no/api/projectrepo/?search={like}&amp;page={page}&amp;size={pageSize}</url>
@ -317,11 +385,26 @@
<name>'name'</name>
<uri>'uri'</uri>
<description>'description'</description>
<source>'source'</source>
</fields>
</data>
<paginationpath>$['meta']['pagination']['page','pages','count']</paginationpath>
</urlConfig>
<urlConfig>
<key>crossref</key>
<label>Crossref Funder Registry</label>
<ordinal>1</ordinal>
<type>External</type>
<url>https://api.crossref.org/funders?query={like}&amp;rows={pageSize}</url>
<contenttype>application/json; charset=utf-8</contenttype>
<data>
<path>$['message']['items'][*]</path>
<fields>
<name>'name'</name>
<id>'id'</id>
<count>'count'</count>
</fields>
</data>
</urlConfig>
<!-- <urlConfig>
<key>servicesOpenAire</key>
<label>OpenAIRE</label>
@ -395,7 +478,7 @@
<label>Internal</label>
<ordinal>1</ordinal>
<type>Internal</type>
<url>FunderInternalMockUpData.json</url>
<url>web/src/main/resources/mockData/FunderInternalMockUpData.json</url>
<data>
<path>$['data'][*]['attributes']</path>
<fields>
@ -452,12 +535,12 @@
</data>
<paginationpath>$['meta']['pagination']['page','pages','count']</paginationpath>
</urlConfig>-->
<!-- <urlConfig>
<!--<urlConfig>
<key>internal</key>
<label>Internal</label>
<ordinal>1</ordinal>
<type>Internal</type>
<url>mockData/RepositoriesInternalMockUpData.json</url>
<url>web/src/main/resources/mockData/RepositoriesInternalMockUpData.json</url>
<data>
<path>$['data'][*]['attributes']</path>
<fields>
@ -520,7 +603,7 @@
<label>Internal</label>
<ordinal>1</ordinal>
<type>Internal</type>
<url>mockData/ServicesInternalMockUpData.json</url>
<url>web/src/main/resources/mockData/ServicesInternalMockUpData.json</url>
<data>
<path>$['data'][*]['attributes']</path>
<fields>
@ -583,7 +666,7 @@
<label>Internal</label>
<ordinal>1</ordinal>
<type>Internal</type>
<url>mockData/ResearcherInternalMockUpData.json</url>
<url>web/src/main/resources/mockData/ResearcherInternalMockUpData.json</url>
<data>
<path>$['data'][*]['attributes']</path>
<fields>
@ -646,7 +729,7 @@
<label>Internal</label>
<ordinal>1</ordinal>
<type>Internal</type>
<url>mockData/OrganisationInternalMockUpData.json</url>
<url>web/src/main/resources/mockData/OrganisationInternalMockUpData.json</url>
<data>
<path>$['data'][*]['attributes']</path>
<fields>
@ -679,6 +762,7 @@
<name>'name'</name>
<uri>'uri'</uri>
<description>'description'</description>
<source>'source'</source>
</fields>
</data>
<paginationpath>$['meta']['pagination']['page','pages','count']</paginationpath>
@ -707,7 +791,7 @@
<label>Internal</label>
<ordinal>1</ordinal>
<type>Internal</type>
<url>mockData/DatasetsInternalMockUpData.json</url>
<url>web/src/main/resources/mockData/DatasetsInternalMockUpData.json</url>
<data>
<path>$['data'][*]['attributes']</path>
<fields>