Refactors how researchers are fetched from external sources and saved in general.

This commit is contained in:
gkolokythas 2020-01-14 12:33:48 +02:00
parent 9d627a11da
commit ff9aa14047
8 changed files with 99 additions and 31 deletions

View File

@ -19,8 +19,8 @@ import java.util.UUID;
public class Researcher implements DataEntity<Researcher, UUID> {
@Id
@GeneratedValue
@GenericGenerator(name = "uuid2", strategy = "uuid2")
/*@GeneratedValue
@GenericGenerator(name = "uuid2", strategy = "uuid2")*/
@Column(name = "\"ID\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
private UUID id;

View File

@ -3,15 +3,14 @@ package eu.eudat.logic.builders.model.models;
import eu.eudat.logic.builders.Builder;
import eu.eudat.models.data.dmp.Researcher;
/**
* Created by ikalyvas on 3/6/2018.
*/
public class ResearcherBuilder extends Builder<Researcher> {
private String label;
private String name;
private String id;
private String reference;
private int status;
private String tag;
private String key;
public String getLabel() {
return label;
@ -40,6 +39,13 @@ public class ResearcherBuilder extends Builder<Researcher> {
return this;
}
public String getReference() { return reference; }
public ResearcherBuilder reference(String reference) {
this.reference = reference;
return this;
}
public int getStatus() {
return status;
}
@ -58,14 +64,25 @@ public class ResearcherBuilder extends Builder<Researcher> {
return this;
}
public String getKey() {
return key;
}
public ResearcherBuilder key(String key) {
this.key = key;
return this;
}
@Override
public Researcher build() {
Researcher researcher = new Researcher();
researcher.setId(id);
researcher.setReference(reference);
researcher.setLabel(label);
researcher.setName(name);
researcher.setStatus(status);
researcher.setTag(tag);
researcher.setKey(key);
return researcher;
}
}

View File

@ -3,6 +3,8 @@ package eu.eudat.logic.managers;
import eu.eudat.logic.builders.model.models.ResearcherBuilder;
import eu.eudat.data.entities.Researcher;
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.ResearchersExternalSourcesModel;
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.Map;
import java.util.UUID;
import java.util.stream.Collectors;
/**
@ -28,11 +29,13 @@ public class ResearcherManager {
private ApiContext apiContext;
private RemoteFetcher remoteFetcher;
private ConfigLoader configLoader;
@Autowired
public ResearcherManager(ApiContext apiContext) {
public ResearcherManager(ApiContext apiContext, ConfigLoader configLoader) {
this.apiContext = apiContext;
this.remoteFetcher = apiContext.getOperationsContext().getRemoteFetcher();
this.configLoader = configLoader;
}
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());
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));
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());
List<Map<String, String>> remoteRepos = remoteFetcher.getResearchers(externalUrlCriteria,null);
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)
.label(externalListingItem.getAbbreviation())
.id(externalListingItem.getId())
.reference(externalListingItem.getRemoteId())
.name(externalListingItem.getName())
.tag(externalListingItem.getTag())
.key(externalListingItem.getKey())
.build();
researchers.add(researcher);
}

View File

@ -4,18 +4,20 @@ import eu.eudat.models.DataModel;
import eu.eudat.logic.utilities.helpers.LabelGenerator;
import java.util.Date;
import java.util.UUID;
public class Researcher implements DataModel<eu.eudat.data.entities.Researcher, Researcher>, LabelGenerator {
private String label;
private String name;
private String id;
private String reference;
private int status;
private String tag;
private String key;
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
@ -23,7 +25,6 @@ public class Researcher implements DataModel<eu.eudat.data.entities.Researcher,
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@ -31,15 +32,20 @@ public class Researcher implements DataModel<eu.eudat.data.entities.Researcher,
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getReference() {
return reference;
}
public void setReference(String reference) {
this.reference = reference;
}
public int getStatus() {
return status;
}
public void setStatus(int status) {
this.status = status;
}
@ -47,38 +53,61 @@ public class Researcher implements DataModel<eu.eudat.data.entities.Researcher,
public String getTag() {
return tag;
}
public void setTag(String tag) {
this.tag = tag;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
@Override
public Researcher fromDataModel(eu.eudat.data.entities.Researcher entity) {
this.id = entity.getReference();
this.id = entity.getId().toString();
this.label = entity.getUri();
this.name = entity.getLabel();
this.status = entity.getStatus();
if (entity.getReference().contains(":cristin")) {
this.tag = "cristin";
} else {
this.reference = entity.getReference();
String source = entity.getReference().substring(0, entity.getReference().indexOf(":"));
if (source.equals("dmp"))
this.tag = "Internal";
this.key = "Internal";
else
this.tag = source;
}
this.key = source;
return this;
}
@Override
public eu.eudat.data.entities.Researcher toDataModel() {
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()))) {
researcher.setReference(this.id);
} else {
researcher.setReference(this.tag.toLowerCase() + ":" + this.id);
if (this.id == null) {
this.id = UUID.randomUUID().toString();
}
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.setUri(this.label);
researcher.setCreated(new Date());
@ -108,6 +137,6 @@ public class Researcher implements DataModel<eu.eudat.data.entities.Researcher,
@Override
public int hashCode() {
return id.hashCode();
return reference.hashCode();
}
}

View File

@ -11,6 +11,7 @@ public class ExternalSourcesItemModel {
private String abbreviation;
private String tag;
private String source;
private String key;
public String getId() {
return id;
@ -74,4 +75,11 @@ public class ExternalSourcesItemModel {
public void setSource(String source) {
this.source = source;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
}

View File

@ -9,10 +9,11 @@ public class ResearchersExternalSourcesModel extends ExternalListingItem<Researc
public ResearchersExternalSourcesModel fromExternalItem(List<Map<String, String>> values) {
for (Map<String, String> item : values) {
ExternalSourcesItemModel model = new ExternalSourcesItemModel();
model.setId(item.get("pid"));
model.setRemoteId(item.get("pid"));
model.setUri(item.get("uri"));
model.setName(item.get("name"));
model.setTag(item.get("tag"));
model.setKey(item.get("key"));
this.add(model);
}
return this;

View File

@ -1,6 +1,7 @@
export interface ResearcherModel {
id: String;
name: String;
reference: String;
lastName: String;
uri: String;
email: String;

View File

@ -159,9 +159,9 @@ export class GeneralTabComponent extends BaseComponent implements OnInit {
const newItem = {
label: null,
name: fullName,
id: "dmp:" + fullName,
id: null,
status: 0,
tag: "Internal",
key: "Internal",
};
const researchersArray = this.formGroup.get('researchers').value || [];
researchersArray.push(newItem);