argos/dmp-backend/web/src/main/java/eu/eudat/models/data/dmp/Researcher.java

151 lines
4.1 KiB
Java
Raw Normal View History

2018-06-27 12:29:21 +02:00
package eu.eudat.models.data.dmp;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
2017-12-15 00:01:26 +01:00
import eu.eudat.models.DataModel;
2018-06-27 12:29:21 +02:00
import eu.eudat.logic.utilities.helpers.LabelGenerator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Date;
import java.util.UUID;
@JsonIgnoreProperties(ignoreUnknown = true)
2018-03-21 11:57:56 +01:00
public class Researcher implements DataModel<eu.eudat.data.entities.Researcher, Researcher>, LabelGenerator {
private static final Logger logger = LoggerFactory.getLogger(Researcher.class);
2017-12-20 15:52:09 +01:00
private String label;
private String name;
2017-12-20 15:52:09 +01:00
private String id;
private String reference;
private int status;
private String tag;
private String key;
2017-12-20 15:52:09 +01:00
public String getLabel() {
return label;
}
2017-12-20 15:52:09 +01:00
public void setLabel(String label) {
this.label = label;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
2017-12-20 15:52:09 +01:00
public String getId() {
return id;
}
2017-12-20 15:52:09 +01:00
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;
}
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
2018-03-21 11:57:56 +01:00
public Researcher fromDataModel(eu.eudat.data.entities.Researcher entity) {
this.id = entity.getId().toString();
2017-12-20 15:52:09 +01:00
this.label = entity.getUri();
this.name = entity.getLabel();
this.status = entity.getStatus();
this.reference = entity.getReference();
2020-03-30 14:38:10 +02:00
String refParts[] = entity.getReference().split(":");
String source = refParts[0];
if (source.equals("dmp"))
this.key = "Internal";
else
this.key = source;
2018-02-16 08:45:18 +01:00
return this;
}
@Override
2018-03-21 11:57:56 +01:00
public eu.eudat.data.entities.Researcher toDataModel() {
eu.eudat.data.entities.Researcher researcher = new eu.eudat.data.entities.Researcher();
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 && !this.reference.startsWith("dmp:")) {
2021-04-30 12:10:11 +02:00
researcher.setReference("dmp:" + this.reference);
} else if (this.reference == null) {
researcher.setReference("dmp:" + this.id);
} else {
researcher.setReference(this.reference);
}
} 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) {
logger.error(e.getMessage(), e);
}
}
researcher.setLabel(this.name);
2017-12-20 15:52:09 +01:00
researcher.setUri(this.label);
researcher.setCreated(new Date());
2018-02-16 11:34:02 +01:00
researcher.setStatus((short) this.status);
return researcher;
}
2017-12-19 15:09:49 +01:00
@Override
public String generateLabel() {
return this.getName();
}
2018-01-19 10:31:05 +01:00
@Override
public String getHint() {
return null;
}
2018-03-08 11:54:56 +01:00
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Researcher that = (Researcher) o;
return id.equals(that.id);
}
@Override
public int hashCode() {
return reference.hashCode();
2018-03-08 11:54:56 +01:00
}
}