Fetching and building organizations for dmps for public API
This commit is contained in:
parent
693f1dba7f
commit
b00b048632
|
@ -2,6 +2,7 @@ package eu.eudat.model.mapper.publicapi;
|
|||
|
||||
import eu.eudat.model.Dmp;
|
||||
import eu.eudat.model.publicapi.grant.GrantPublicOverviewModel;
|
||||
import eu.eudat.model.publicapi.organisation.OrganizationPublicModel;
|
||||
import eu.eudat.model.publicapi.overviewmodels.DataManagementPlanPublicModel;
|
||||
import eu.eudat.model.publicapi.researcher.ResearcherPublicModel;
|
||||
import eu.eudat.model.publicapi.user.UserInfoPublicModel;
|
||||
|
@ -24,6 +25,7 @@ public class DmpToPublicApiDmpMapper {
|
|||
model.setUsers(dmp.getDmpUsers().stream().map(UserInfoPublicModel::fromDmpUser).toList());
|
||||
model.setResearchers(dmp.getDmpReferences().stream().map(ResearcherPublicModel::fromDmpReference).filter(Objects::isNull).toList());
|
||||
model.setGrant(GrantPublicOverviewModel.fromDmpReferences(dmp.getDmpReferences()));
|
||||
model.setOrganisations(dmp.getDmpReferences().stream().map(OrganizationPublicModel::fromDmpReference).filter(Objects::isNull).toList());
|
||||
|
||||
model.setCreatedAt(Date.from(dmp.getCreatedAt()));
|
||||
model.setModifiedAt(Date.from(dmp.getUpdatedAt()));
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
package eu.eudat.model.publicapi.organisation;
|
||||
|
||||
import eu.eudat.commons.enums.ReferenceType;
|
||||
import eu.eudat.data.old.Organisation;
|
||||
import eu.eudat.model.DmpReference;
|
||||
import eu.eudat.model.Reference;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
|
@ -64,55 +67,18 @@ public class OrganizationPublicModel {
|
|||
this.key = key;
|
||||
}
|
||||
|
||||
public OrganizationPublicModel fromDataModel(Organisation entity) {
|
||||
this.id = entity.getId().toString();
|
||||
this.name = entity.getLabel();
|
||||
this.label = entity.getUri();
|
||||
if (entity.getReference() != null) {
|
||||
this.reference = entity.getReference();
|
||||
this.key = entity.getReference().substring(0, entity.getReference().indexOf(":"));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public Organisation toDataModel() {
|
||||
Organisation organisationEntity = new Organisation();
|
||||
if (this.key != null && this.reference != null) {
|
||||
if (this.reference.startsWith(this.key + ":")) {
|
||||
organisationEntity.setReference(this.reference);
|
||||
} else {
|
||||
organisationEntity.setReference(this.key + ":" + this.reference);
|
||||
}
|
||||
}
|
||||
if (this.id != null) {
|
||||
organisationEntity.setId(UUID.fromString(this.id));
|
||||
}
|
||||
organisationEntity.setLabel(this.name);
|
||||
organisationEntity.setUri(this.label);
|
||||
organisationEntity.setCreated(new Date());
|
||||
organisationEntity.setStatus((short) this.status);
|
||||
return organisationEntity;
|
||||
}
|
||||
|
||||
public static OrganizationPublicModel fromMap(HashMap<String, Object> map) {
|
||||
public static OrganizationPublicModel fromDmpReference(DmpReference dmpReference) {
|
||||
if (dmpReference.getReference().getType() != ReferenceType.Organizations)
|
||||
return null;
|
||||
OrganizationPublicModel model = new OrganizationPublicModel();
|
||||
if (map != null) {
|
||||
model.id = (String) map.get("id");
|
||||
model.key = (String) map.get("key");
|
||||
model.label = (String) map.get("label");
|
||||
model.name = (String) map.get("name");
|
||||
model.reference = (String) map.get("reference");
|
||||
model.status = (int) map.get("status");
|
||||
model.tag = (String) map.get("tag");
|
||||
}
|
||||
Reference reference = dmpReference.getReference();
|
||||
model.setId(reference.getId().toString());
|
||||
model.setReference(reference.getReference());
|
||||
model.setLabel(reference.getLabel());
|
||||
model.setName(reference.getLabel());
|
||||
if (reference.getReference() != null)
|
||||
model.setKey(reference.getReference().substring(0, reference.getReference().indexOf(":")));
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
public String generateLabel() {
|
||||
return this.getName();
|
||||
}
|
||||
|
||||
public String getHint() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,14 +2,11 @@ package eu.eudat.model.publicapi.researcher;
|
|||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import eu.eudat.commons.enums.ReferenceType;
|
||||
import eu.eudat.data.old.Researcher;
|
||||
import eu.eudat.model.DmpReference;
|
||||
import eu.eudat.model.Reference;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class ResearcherPublicModel {
|
||||
private static final Logger logger = LoggerFactory.getLogger(ResearcherPublicModel.class);
|
||||
|
@ -74,10 +71,11 @@ public class ResearcherPublicModel {
|
|||
if (dmpReference.getReference().getType() != ReferenceType.Researcher)
|
||||
return null;
|
||||
ResearcherPublicModel model = new ResearcherPublicModel();
|
||||
model.setId(dmpReference.getReference().getId().toString());
|
||||
model.setReference(dmpReference.getReference().getReference());
|
||||
model.setLabel(dmpReference.getReference().getLabel());
|
||||
model.setName(dmpReference.getReference().getLabel());
|
||||
Reference reference = dmpReference.getReference();
|
||||
model.setId(reference.getId().toString());
|
||||
model.setReference(reference.getReference());
|
||||
model.setLabel(reference.getLabel());
|
||||
model.setName(reference.getLabel());
|
||||
String[] refParts = dmpReference.getReference().getReference().split(":");
|
||||
String source = refParts[0];
|
||||
if (source.equals("dmp"))
|
||||
|
|
Loading…
Reference in New Issue