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.Dmp;
import eu.eudat.model.publicapi.listingmodels.DataManagementPlanPublicListingModel; import eu.eudat.model.publicapi.listingmodels.DataManagementPlanPublicListingModel;
import eu.eudat.model.publicapi.researcher.ResearcherPublicModel;
import eu.eudat.model.publicapi.user.UserInfoPublicModel; import eu.eudat.model.publicapi.user.UserInfoPublicModel;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.sql.Date; import java.sql.Date;
import java.util.Objects;
@Component @Component
public class DmpToPublicApiDmpListingMapper { public class DmpToPublicApiDmpListingMapper {
@ -18,6 +20,7 @@ public class DmpToPublicApiDmpListingMapper {
model.setGroupId(dmp.getGroupId()); model.setGroupId(dmp.getGroupId());
model.setUsers(dmp.getDmpUsers().stream().map(UserInfoPublicModel::fromDmpUser).toList()); 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.setCreatedAt(Date.from(dmp.getCreatedAt()));
model.setModifiedAt(Date.from(dmp.getUpdatedAt())); 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.Dmp;
import eu.eudat.model.publicapi.overviewmodels.DataManagementPlanPublicModel; import eu.eudat.model.publicapi.overviewmodels.DataManagementPlanPublicModel;
import eu.eudat.model.publicapi.researcher.ResearcherPublicModel;
import eu.eudat.model.publicapi.user.UserInfoPublicModel; import eu.eudat.model.publicapi.user.UserInfoPublicModel;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.sql.Date; import java.sql.Date;
import java.util.Objects;
@Component @Component
public class DmpToPublicApiDmpMapper { public class DmpToPublicApiDmpMapper {
@ -19,6 +21,7 @@ public class DmpToPublicApiDmpMapper {
model.setGroupId(dmp.getGroupId()); model.setGroupId(dmp.getGroupId());
model.setUsers(dmp.getDmpUsers().stream().map(UserInfoPublicModel::fromDmpUser).toList()); 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.setCreatedAt(Date.from(dmp.getCreatedAt()));
model.setModifiedAt(Date.from(dmp.getUpdatedAt())); model.setModifiedAt(Date.from(dmp.getUpdatedAt()));

View File

@ -1,7 +1,9 @@
package eu.eudat.model.publicapi.researcher; package eu.eudat.model.publicapi.researcher;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import eu.eudat.commons.enums.ReferenceType;
import eu.eudat.data.old.Researcher; import eu.eudat.data.old.Researcher;
import eu.eudat.model.DmpReference;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -68,55 +70,21 @@ public class ResearcherPublicModel {
this.key = key; this.key = key;
} }
public ResearcherPublicModel fromDataModel(Researcher entity) { public static ResearcherPublicModel fromDmpReference(DmpReference dmpReference) {
this.id = entity.getId().toString(); if (dmpReference.getReference().getType() != ReferenceType.Researcher)
this.label = entity.getUri(); return null;
this.name = entity.getLabel(); ResearcherPublicModel model = new ResearcherPublicModel();
this.status = entity.getStatus(); model.setId(dmpReference.getReference().getId().toString());
this.reference = entity.getReference(); model.setReference(dmpReference.getReference().getReference());
String[] refParts = entity.getReference().split(":"); model.setLabel(dmpReference.getReference().getLabel());
model.setName(dmpReference.getReference().getLabel());
String[] refParts = dmpReference.getReference().getReference().split(":");
String source = refParts[0]; String source = refParts[0];
if (source.equals("dmp")) if (source.equals("dmp"))
this.key = "Internal"; model.setKey("Internal");
else else
this.key = source; model.setKey(source);
return this;
}
public Researcher toDataModel() { return model;
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;
} }
} }

View File

@ -7,9 +7,7 @@ import eu.eudat.controllers.publicapi.request.dmp.DataManagmentPlanPublicTableRe
import eu.eudat.controllers.publicapi.response.DataTableData; import eu.eudat.controllers.publicapi.response.DataTableData;
import eu.eudat.data.DmpEntity; import eu.eudat.data.DmpEntity;
import eu.eudat.logic.services.ApiContext; import eu.eudat.logic.services.ApiContext;
import eu.eudat.model.Dmp; import eu.eudat.model.*;
import eu.eudat.model.DmpUser;
import eu.eudat.model.User;
import eu.eudat.model.builder.DmpBuilder; import eu.eudat.model.builder.DmpBuilder;
import eu.eudat.model.mapper.publicapi.DmpToPublicApiDmpListingMapper; import eu.eudat.model.mapper.publicapi.DmpToPublicApiDmpListingMapper;
import eu.eudat.model.mapper.publicapi.DmpToPublicApiDmpMapper; 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._id)),
String.join(".", Dmp._dmpUsers, String.join(".", DmpUser._user, User._name)), String.join(".", Dmp._dmpUsers, String.join(".", DmpUser._user, User._name)),
String.join(".", Dmp._dmpUsers, DmpUser._role), 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._dmpReferences,
Dmp._createdAt, Dmp._createdAt,
Dmp._updatedAt, 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._id)),
String.join(".", Dmp._dmpUsers, String.join(".", DmpUser._user, User._name)), String.join(".", Dmp._dmpUsers, String.join(".", DmpUser._user, User._name)),
String.join(".", Dmp._dmpUsers, DmpUser._role), 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._createdAt,
Dmp._updatedAt, Dmp._updatedAt,
Dmp._finalizedAt Dmp._finalizedAt