Fetching and building researchers for dmps for public API

This commit is contained in:
Thomas Georgios Giannos 2023-11-28 15:05:51 +02:00
parent 92956f6598
commit df2086a0a7
4 changed files with 27 additions and 49 deletions

View File

@ -2,10 +2,12 @@ package eu.eudat.model.mapper.publicapi;
import eu.eudat.model.Dmp;
import eu.eudat.model.publicapi.listingmodels.DataManagementPlanPublicListingModel;
import eu.eudat.model.publicapi.researcher.ResearcherPublicModel;
import eu.eudat.model.publicapi.user.UserInfoPublicModel;
import org.springframework.stereotype.Component;
import java.sql.Date;
import java.util.Objects;
@Component
public class DmpToPublicApiDmpListingMapper {
@ -18,6 +20,7 @@ public class DmpToPublicApiDmpListingMapper {
model.setGroupId(dmp.getGroupId());
model.setUsers(dmp.getDmpUsers().stream().map(UserInfoPublicModel::fromDmpUser).toList());
model.setResearchers(dmp.getDmpReferences().stream().map(ResearcherPublicModel::fromDmpReference).filter(Objects::isNull).toList());
model.setCreatedAt(Date.from(dmp.getCreatedAt()));
model.setModifiedAt(Date.from(dmp.getUpdatedAt()));

View File

@ -2,10 +2,12 @@ package eu.eudat.model.mapper.publicapi;
import eu.eudat.model.Dmp;
import eu.eudat.model.publicapi.overviewmodels.DataManagementPlanPublicModel;
import eu.eudat.model.publicapi.researcher.ResearcherPublicModel;
import eu.eudat.model.publicapi.user.UserInfoPublicModel;
import org.springframework.stereotype.Component;
import java.sql.Date;
import java.util.Objects;
@Component
public class DmpToPublicApiDmpMapper {
@ -19,6 +21,7 @@ public class DmpToPublicApiDmpMapper {
model.setGroupId(dmp.getGroupId());
model.setUsers(dmp.getDmpUsers().stream().map(UserInfoPublicModel::fromDmpUser).toList());
model.setResearchers(dmp.getDmpReferences().stream().map(ResearcherPublicModel::fromDmpReference).filter(Objects::isNull).toList());
model.setCreatedAt(Date.from(dmp.getCreatedAt()));
model.setModifiedAt(Date.from(dmp.getUpdatedAt()));

View File

@ -1,7 +1,9 @@
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 org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -68,55 +70,21 @@ public class ResearcherPublicModel {
this.key = key;
}
public ResearcherPublicModel fromDataModel(Researcher entity) {
this.id = entity.getId().toString();
this.label = entity.getUri();
this.name = entity.getLabel();
this.status = entity.getStatus();
this.reference = entity.getReference();
String[] refParts = entity.getReference().split(":");
public static ResearcherPublicModel fromDmpReference(DmpReference dmpReference) {
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());
String[] refParts = dmpReference.getReference().getReference().split(":");
String source = refParts[0];
if (source.equals("dmp"))
this.key = "Internal";
model.setKey("Internal");
else
this.key = source;
return this;
}
model.setKey(source);
public Researcher toDataModel() {
Researcher researcher = new Researcher();
if (this.id == null) {
this.id = UUID.randomUUID().toString();
}
researcher.setId(UUID.fromString(this.id));
if (this.key != null) {
if (this.key.equalsIgnoreCase("internal")) {
if (this.reference != null && !this.reference.startsWith("dmp:")) {
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);
researcher.setUri(this.label);
researcher.setCreated(new Date());
researcher.setStatus((short) this.status);
return researcher;
return model;
}
}

View File

@ -7,9 +7,7 @@ import eu.eudat.controllers.publicapi.request.dmp.DataManagmentPlanPublicTableRe
import eu.eudat.controllers.publicapi.response.DataTableData;
import eu.eudat.data.DmpEntity;
import eu.eudat.logic.services.ApiContext;
import eu.eudat.model.Dmp;
import eu.eudat.model.DmpUser;
import eu.eudat.model.User;
import eu.eudat.model.*;
import eu.eudat.model.builder.DmpBuilder;
import eu.eudat.model.mapper.publicapi.DmpToPublicApiDmpListingMapper;
import eu.eudat.model.mapper.publicapi.DmpToPublicApiDmpMapper;
@ -116,6 +114,9 @@ public class PublicDmpsDocumentation extends BaseController {
String.join(".", Dmp._dmpUsers, String.join(".", DmpUser._user, User._id)),
String.join(".", Dmp._dmpUsers, String.join(".", DmpUser._user, User._name)),
String.join(".", Dmp._dmpUsers, DmpUser._role),
String.join(".", Dmp._dmpReferences, String.join(".", DmpReference._reference, Reference._id)),
String.join(".", Dmp._dmpReferences, String.join(".", DmpReference._reference, Reference._reference)),
String.join(".", Dmp._dmpReferences, String.join(".", DmpReference._reference, Reference._label)),
Dmp._dmpReferences,
Dmp._createdAt,
Dmp._updatedAt,
@ -157,6 +158,9 @@ public class PublicDmpsDocumentation extends BaseController {
String.join(".", Dmp._dmpUsers, String.join(".", DmpUser._user, User._id)),
String.join(".", Dmp._dmpUsers, String.join(".", DmpUser._user, User._name)),
String.join(".", Dmp._dmpUsers, DmpUser._role),
String.join(".", Dmp._dmpReferences, String.join(".", DmpReference._reference, Reference._id)),
String.join(".", Dmp._dmpReferences, String.join(".", DmpReference._reference, Reference._reference)),
String.join(".", Dmp._dmpReferences, String.join(".", DmpReference._reference, Reference._label)),
Dmp._createdAt,
Dmp._updatedAt,
Dmp._finalizedAt