Refactors how researchers are fetched from external sources and saved in general.
This commit is contained in:
parent
9d627a11da
commit
ff9aa14047
|
@ -19,8 +19,8 @@ import java.util.UUID;
|
||||||
public class Researcher implements DataEntity<Researcher, UUID> {
|
public class Researcher implements DataEntity<Researcher, UUID> {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue
|
/*@GeneratedValue
|
||||||
@GenericGenerator(name = "uuid2", strategy = "uuid2")
|
@GenericGenerator(name = "uuid2", strategy = "uuid2")*/
|
||||||
@Column(name = "\"ID\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
|
@Column(name = "\"ID\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
|
||||||
private UUID id;
|
private UUID id;
|
||||||
|
|
||||||
|
|
|
@ -3,15 +3,14 @@ package eu.eudat.logic.builders.model.models;
|
||||||
import eu.eudat.logic.builders.Builder;
|
import eu.eudat.logic.builders.Builder;
|
||||||
import eu.eudat.models.data.dmp.Researcher;
|
import eu.eudat.models.data.dmp.Researcher;
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by ikalyvas on 3/6/2018.
|
|
||||||
*/
|
|
||||||
public class ResearcherBuilder extends Builder<Researcher> {
|
public class ResearcherBuilder extends Builder<Researcher> {
|
||||||
private String label;
|
private String label;
|
||||||
private String name;
|
private String name;
|
||||||
private String id;
|
private String id;
|
||||||
|
private String reference;
|
||||||
private int status;
|
private int status;
|
||||||
private String tag;
|
private String tag;
|
||||||
|
private String key;
|
||||||
|
|
||||||
public String getLabel() {
|
public String getLabel() {
|
||||||
return label;
|
return label;
|
||||||
|
@ -40,6 +39,13 @@ public class ResearcherBuilder extends Builder<Researcher> {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getReference() { return reference; }
|
||||||
|
|
||||||
|
public ResearcherBuilder reference(String reference) {
|
||||||
|
this.reference = reference;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public int getStatus() {
|
public int getStatus() {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
@ -58,14 +64,25 @@ public class ResearcherBuilder extends Builder<Researcher> {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getKey() {
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ResearcherBuilder key(String key) {
|
||||||
|
this.key = key;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Researcher build() {
|
public Researcher build() {
|
||||||
Researcher researcher = new Researcher();
|
Researcher researcher = new Researcher();
|
||||||
researcher.setId(id);
|
researcher.setId(id);
|
||||||
|
researcher.setReference(reference);
|
||||||
researcher.setLabel(label);
|
researcher.setLabel(label);
|
||||||
researcher.setName(name);
|
researcher.setName(name);
|
||||||
researcher.setStatus(status);
|
researcher.setStatus(status);
|
||||||
researcher.setTag(tag);
|
researcher.setTag(tag);
|
||||||
|
researcher.setKey(key);
|
||||||
return researcher;
|
return researcher;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,8 @@ package eu.eudat.logic.managers;
|
||||||
import eu.eudat.logic.builders.model.models.ResearcherBuilder;
|
import eu.eudat.logic.builders.model.models.ResearcherBuilder;
|
||||||
import eu.eudat.data.entities.Researcher;
|
import eu.eudat.data.entities.Researcher;
|
||||||
import eu.eudat.logic.proxy.config.ExternalUrlCriteria;
|
import eu.eudat.logic.proxy.config.ExternalUrlCriteria;
|
||||||
|
import eu.eudat.logic.proxy.config.configloaders.ConfigLoader;
|
||||||
|
import eu.eudat.logic.utilities.helpers.ListHelper;
|
||||||
import eu.eudat.models.data.external.ExternalSourcesItemModel;
|
import eu.eudat.models.data.external.ExternalSourcesItemModel;
|
||||||
import eu.eudat.models.data.external.ResearchersExternalSourcesModel;
|
import eu.eudat.models.data.external.ResearchersExternalSourcesModel;
|
||||||
import eu.eudat.data.query.items.item.researcher.ResearcherCriteriaRequest;
|
import eu.eudat.data.query.items.item.researcher.ResearcherCriteriaRequest;
|
||||||
|
@ -17,7 +19,6 @@ import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -28,11 +29,13 @@ public class ResearcherManager {
|
||||||
|
|
||||||
private ApiContext apiContext;
|
private ApiContext apiContext;
|
||||||
private RemoteFetcher remoteFetcher;
|
private RemoteFetcher remoteFetcher;
|
||||||
|
private ConfigLoader configLoader;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public ResearcherManager(ApiContext apiContext) {
|
public ResearcherManager(ApiContext apiContext, ConfigLoader configLoader) {
|
||||||
this.apiContext = apiContext;
|
this.apiContext = apiContext;
|
||||||
this.remoteFetcher = apiContext.getOperationsContext().getRemoteFetcher();
|
this.remoteFetcher = apiContext.getOperationsContext().getRemoteFetcher();
|
||||||
|
this.configLoader = configLoader;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Researcher create(eu.eudat.models.data.researcher.Researcher researcher, Principal principal) throws Exception {
|
public Researcher create(eu.eudat.models.data.researcher.Researcher researcher, Principal principal) throws Exception {
|
||||||
|
@ -46,6 +49,13 @@ public class ResearcherManager {
|
||||||
QueryableList<eu.eudat.data.entities.Researcher> items = apiContext.getOperationsContext().getDatabaseRepository().getResearcherDao().getWithCriteria(researcherCriteriaRequest.getCriteria());
|
QueryableList<eu.eudat.data.entities.Researcher> items = apiContext.getOperationsContext().getDatabaseRepository().getResearcherDao().getWithCriteria(researcherCriteriaRequest.getCriteria());
|
||||||
items.where((builder, root) -> builder.equal(root.get("creationUser").get("id"), principal.getId()));
|
items.where((builder, root) -> builder.equal(root.get("creationUser").get("id"), principal.getId()));
|
||||||
List<eu.eudat.models.data.dmp.Researcher> researchers = items.select(item -> new eu.eudat.models.data.dmp.Researcher().fromDataModel(item));
|
List<eu.eudat.models.data.dmp.Researcher> researchers = items.select(item -> new eu.eudat.models.data.dmp.Researcher().fromDataModel(item));
|
||||||
|
Map<String, String> keyToSourceMap = configLoader.getKeyToSourceMap();
|
||||||
|
for (eu.eudat.models.data.dmp.Researcher item : researchers) {
|
||||||
|
if (item.getKey().equals("Internal"))
|
||||||
|
item.setTag(item.getKey());
|
||||||
|
else
|
||||||
|
item.setTag(keyToSourceMap.get(item.getKey()));
|
||||||
|
}
|
||||||
ExternalUrlCriteria externalUrlCriteria = new ExternalUrlCriteria(researcherCriteriaRequest.getCriteria().getName());
|
ExternalUrlCriteria externalUrlCriteria = new ExternalUrlCriteria(researcherCriteriaRequest.getCriteria().getName());
|
||||||
List<Map<String, String>> remoteRepos = remoteFetcher.getResearchers(externalUrlCriteria,null);
|
List<Map<String, String>> remoteRepos = remoteFetcher.getResearchers(externalUrlCriteria,null);
|
||||||
ResearchersExternalSourcesModel researchersExternalSourcesModel = new ResearchersExternalSourcesModel().fromExternalItem(remoteRepos);
|
ResearchersExternalSourcesModel researchersExternalSourcesModel = new ResearchersExternalSourcesModel().fromExternalItem(remoteRepos);
|
||||||
|
@ -53,8 +63,10 @@ public class ResearcherManager {
|
||||||
eu.eudat.models.data.dmp.Researcher researcher = apiContext.getOperationsContext().getBuilderFactory().getBuilder(ResearcherBuilder.class)
|
eu.eudat.models.data.dmp.Researcher researcher = apiContext.getOperationsContext().getBuilderFactory().getBuilder(ResearcherBuilder.class)
|
||||||
.label(externalListingItem.getAbbreviation())
|
.label(externalListingItem.getAbbreviation())
|
||||||
.id(externalListingItem.getId())
|
.id(externalListingItem.getId())
|
||||||
|
.reference(externalListingItem.getRemoteId())
|
||||||
.name(externalListingItem.getName())
|
.name(externalListingItem.getName())
|
||||||
.tag(externalListingItem.getTag())
|
.tag(externalListingItem.getTag())
|
||||||
|
.key(externalListingItem.getKey())
|
||||||
.build();
|
.build();
|
||||||
researchers.add(researcher);
|
researchers.add(researcher);
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,18 +4,20 @@ import eu.eudat.models.DataModel;
|
||||||
import eu.eudat.logic.utilities.helpers.LabelGenerator;
|
import eu.eudat.logic.utilities.helpers.LabelGenerator;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
public class Researcher implements DataModel<eu.eudat.data.entities.Researcher, Researcher>, LabelGenerator {
|
public class Researcher implements DataModel<eu.eudat.data.entities.Researcher, Researcher>, LabelGenerator {
|
||||||
private String label;
|
private String label;
|
||||||
private String name;
|
private String name;
|
||||||
private String id;
|
private String id;
|
||||||
|
private String reference;
|
||||||
private int status;
|
private int status;
|
||||||
private String tag;
|
private String tag;
|
||||||
|
private String key;
|
||||||
|
|
||||||
public String getLabel() {
|
public String getLabel() {
|
||||||
return label;
|
return label;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLabel(String label) {
|
public void setLabel(String label) {
|
||||||
this.label = label;
|
this.label = label;
|
||||||
}
|
}
|
||||||
|
@ -23,7 +25,6 @@ public class Researcher implements DataModel<eu.eudat.data.entities.Researcher,
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setName(String name) {
|
public void setName(String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
@ -31,15 +32,20 @@ public class Researcher implements DataModel<eu.eudat.data.entities.Researcher,
|
||||||
public String getId() {
|
public String getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setId(String id) {
|
public void setId(String id) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getReference() {
|
||||||
|
return reference;
|
||||||
|
}
|
||||||
|
public void setReference(String reference) {
|
||||||
|
this.reference = reference;
|
||||||
|
}
|
||||||
|
|
||||||
public int getStatus() {
|
public int getStatus() {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setStatus(int status) {
|
public void setStatus(int status) {
|
||||||
this.status = status;
|
this.status = status;
|
||||||
}
|
}
|
||||||
|
@ -47,38 +53,61 @@ public class Researcher implements DataModel<eu.eudat.data.entities.Researcher,
|
||||||
public String getTag() {
|
public String getTag() {
|
||||||
return tag;
|
return tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTag(String tag) {
|
public void setTag(String tag) {
|
||||||
this.tag = tag;
|
this.tag = tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getKey() {
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
public void setKey(String key) {
|
||||||
|
this.key = key;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Researcher fromDataModel(eu.eudat.data.entities.Researcher entity) {
|
public Researcher fromDataModel(eu.eudat.data.entities.Researcher entity) {
|
||||||
this.id = entity.getReference();
|
this.id = entity.getId().toString();
|
||||||
this.label = entity.getUri();
|
this.label = entity.getUri();
|
||||||
this.name = entity.getLabel();
|
this.name = entity.getLabel();
|
||||||
this.status = entity.getStatus();
|
this.status = entity.getStatus();
|
||||||
|
this.reference = entity.getReference();
|
||||||
if (entity.getReference().contains(":cristin")) {
|
|
||||||
this.tag = "cristin";
|
|
||||||
} else {
|
|
||||||
String source = entity.getReference().substring(0, entity.getReference().indexOf(":"));
|
String source = entity.getReference().substring(0, entity.getReference().indexOf(":"));
|
||||||
if (source.equals("dmp"))
|
if (source.equals("dmp"))
|
||||||
this.tag = "Internal";
|
this.key = "Internal";
|
||||||
else
|
else
|
||||||
this.tag = source;
|
this.key = source;
|
||||||
}
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public eu.eudat.data.entities.Researcher toDataModel() {
|
public eu.eudat.data.entities.Researcher toDataModel() {
|
||||||
eu.eudat.data.entities.Researcher researcher = new eu.eudat.data.entities.Researcher();
|
eu.eudat.data.entities.Researcher researcher = new eu.eudat.data.entities.Researcher();
|
||||||
if (this.tag.toLowerCase().equals("internal") || this.tag.equals(this.id.substring(0, this.tag.length()))) {
|
if (this.id == null) {
|
||||||
researcher.setReference(this.id);
|
this.id = UUID.randomUUID().toString();
|
||||||
} else {
|
|
||||||
researcher.setReference(this.tag.toLowerCase() + ":" + this.id);
|
|
||||||
}
|
}
|
||||||
|
researcher.setId(UUID.fromString(this.id));
|
||||||
|
if (this.key != null) {
|
||||||
|
if (this.key.toLowerCase().equals("internal")) {
|
||||||
|
if (this.reference != null && "dmp".equals(this.reference.substring(0, 3))) {
|
||||||
|
researcher.setReference(this.reference);
|
||||||
|
} else {
|
||||||
|
researcher.setReference("dmp:" + this.id);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if ((this.key + ":").equals(this.reference.substring(0, this.key.length() + 1))) {
|
||||||
|
researcher.setReference(this.reference);
|
||||||
|
} else {
|
||||||
|
researcher.setReference(this.key + ":" + this.reference);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
throw new Exception("Researcher has no key value");
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
researcher.setLabel(this.name);
|
researcher.setLabel(this.name);
|
||||||
researcher.setUri(this.label);
|
researcher.setUri(this.label);
|
||||||
researcher.setCreated(new Date());
|
researcher.setCreated(new Date());
|
||||||
|
@ -108,6 +137,6 @@ public class Researcher implements DataModel<eu.eudat.data.entities.Researcher,
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return id.hashCode();
|
return reference.hashCode();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ public class ExternalSourcesItemModel {
|
||||||
private String abbreviation;
|
private String abbreviation;
|
||||||
private String tag;
|
private String tag;
|
||||||
private String source;
|
private String source;
|
||||||
|
private String key;
|
||||||
|
|
||||||
public String getId() {
|
public String getId() {
|
||||||
return id;
|
return id;
|
||||||
|
@ -74,4 +75,11 @@ public class ExternalSourcesItemModel {
|
||||||
public void setSource(String source) {
|
public void setSource(String source) {
|
||||||
this.source = source;
|
this.source = source;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getKey() {
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
public void setKey(String key) {
|
||||||
|
this.key = key;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,10 +9,11 @@ public class ResearchersExternalSourcesModel extends ExternalListingItem<Researc
|
||||||
public ResearchersExternalSourcesModel fromExternalItem(List<Map<String, String>> values) {
|
public ResearchersExternalSourcesModel fromExternalItem(List<Map<String, String>> values) {
|
||||||
for (Map<String, String> item : values) {
|
for (Map<String, String> item : values) {
|
||||||
ExternalSourcesItemModel model = new ExternalSourcesItemModel();
|
ExternalSourcesItemModel model = new ExternalSourcesItemModel();
|
||||||
model.setId(item.get("pid"));
|
model.setRemoteId(item.get("pid"));
|
||||||
model.setUri(item.get("uri"));
|
model.setUri(item.get("uri"));
|
||||||
model.setName(item.get("name"));
|
model.setName(item.get("name"));
|
||||||
model.setTag(item.get("tag"));
|
model.setTag(item.get("tag"));
|
||||||
|
model.setKey(item.get("key"));
|
||||||
this.add(model);
|
this.add(model);
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
export interface ResearcherModel {
|
export interface ResearcherModel {
|
||||||
id: String;
|
id: String;
|
||||||
name: String;
|
name: String;
|
||||||
|
reference: String;
|
||||||
lastName: String;
|
lastName: String;
|
||||||
uri: String;
|
uri: String;
|
||||||
email: String;
|
email: String;
|
||||||
|
|
|
@ -159,9 +159,9 @@ export class GeneralTabComponent extends BaseComponent implements OnInit {
|
||||||
const newItem = {
|
const newItem = {
|
||||||
label: null,
|
label: null,
|
||||||
name: fullName,
|
name: fullName,
|
||||||
id: "dmp:" + fullName,
|
id: null,
|
||||||
status: 0,
|
status: 0,
|
||||||
tag: "Internal",
|
key: "Internal",
|
||||||
};
|
};
|
||||||
const researchersArray = this.formGroup.get('researchers').value || [];
|
const researchersArray = this.formGroup.get('researchers').value || [];
|
||||||
researchersArray.push(newItem);
|
researchersArray.push(newItem);
|
||||||
|
|
Loading…
Reference in New Issue