Fetching and building grants for dmps for public API
This commit is contained in:
parent
eb19b9a7d5
commit
693f1dba7f
|
@ -1,6 +1,7 @@
|
||||||
package eu.eudat.model.mapper.publicapi;
|
package eu.eudat.model.mapper.publicapi;
|
||||||
|
|
||||||
import eu.eudat.model.Dmp;
|
import eu.eudat.model.Dmp;
|
||||||
|
import eu.eudat.model.publicapi.grant.GrantPublicOverviewModel;
|
||||||
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.researcher.ResearcherPublicModel;
|
||||||
import eu.eudat.model.publicapi.user.UserInfoPublicModel;
|
import eu.eudat.model.publicapi.user.UserInfoPublicModel;
|
||||||
|
@ -22,6 +23,7 @@ public class DmpToPublicApiDmpMapper {
|
||||||
|
|
||||||
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.setResearchers(dmp.getDmpReferences().stream().map(ResearcherPublicModel::fromDmpReference).filter(Objects::isNull).toList());
|
||||||
|
model.setGrant(GrantPublicOverviewModel.fromDmpReferences(dmp.getDmpReferences()));
|
||||||
|
|
||||||
model.setCreatedAt(Date.from(dmp.getCreatedAt()));
|
model.setCreatedAt(Date.from(dmp.getCreatedAt()));
|
||||||
model.setModifiedAt(Date.from(dmp.getUpdatedAt()));
|
model.setModifiedAt(Date.from(dmp.getUpdatedAt()));
|
||||||
|
|
|
@ -1,9 +1,15 @@
|
||||||
package eu.eudat.model.publicapi.grant;
|
package eu.eudat.model.publicapi.grant;
|
||||||
|
|
||||||
|
import eu.eudat.commons.enums.ReferenceType;
|
||||||
import eu.eudat.data.old.Grant;
|
import eu.eudat.data.old.Grant;
|
||||||
|
import eu.eudat.model.DmpReference;
|
||||||
|
import eu.eudat.model.Reference;
|
||||||
import eu.eudat.model.publicapi.funder.FunderPublicOverviewModel;
|
import eu.eudat.model.publicapi.funder.FunderPublicOverviewModel;
|
||||||
|
import eu.eudat.model.referencedefinition.Field;
|
||||||
|
|
||||||
|
import java.time.Instant;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class GrantPublicOverviewModel {
|
public class GrantPublicOverviewModel {
|
||||||
|
@ -72,6 +78,28 @@ public class GrantPublicOverviewModel {
|
||||||
this.funder = funder;
|
this.funder = funder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static GrantPublicOverviewModel fromDmpReferences(List<DmpReference> dmpReferences) {
|
||||||
|
for (DmpReference dmpReference : dmpReferences) {
|
||||||
|
if (dmpReference.getReference().getType() != ReferenceType.Grants)
|
||||||
|
continue;
|
||||||
|
GrantPublicOverviewModel model = new GrantPublicOverviewModel();
|
||||||
|
Reference reference = dmpReference.getReference();
|
||||||
|
model.setId(reference.getId());
|
||||||
|
model.setDescription(reference.getDescription());
|
||||||
|
model.setAbbreviation(reference.getAbbreviation());
|
||||||
|
model.setLabel(reference.getLabel());
|
||||||
|
Field startDate = reference.getDefinition().getFields().stream().filter(x -> x.getCode().equals("startDate")).toList().get(0);
|
||||||
|
if (startDate != null) model.setStartDate(Date.from(Instant.parse(startDate.getValue())));
|
||||||
|
Field endDate = reference.getDefinition().getFields().stream().filter(x -> x.getCode().equals("endDate")).toList().get(0);
|
||||||
|
if (startDate != null) model.setEndDate(Date.from(Instant.parse(endDate.getValue())));
|
||||||
|
Field uri = reference.getDefinition().getFields().stream().filter(x -> x.getCode().equals("uri")).toList().get(0);
|
||||||
|
if (uri != null) model.setUri(uri.getValue());
|
||||||
|
|
||||||
|
return model;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public GrantPublicOverviewModel fromDataModel(Grant entity) {
|
public GrantPublicOverviewModel fromDataModel(Grant entity) {
|
||||||
this.id = entity.getId();
|
this.id = entity.getId();
|
||||||
this.label = entity.getLabel();
|
this.label = entity.getLabel();
|
||||||
|
|
|
@ -161,6 +161,9 @@ public class PublicDmpsDocumentation extends BaseController {
|
||||||
String.join(".", Dmp._dmpReferences, String.join(".", DmpReference._reference, Reference._id)),
|
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._reference)),
|
||||||
String.join(".", Dmp._dmpReferences, String.join(".", DmpReference._reference, Reference._label)),
|
String.join(".", Dmp._dmpReferences, String.join(".", DmpReference._reference, Reference._label)),
|
||||||
|
String.join(".", Dmp._dmpReferences, String.join(".", DmpReference._reference, Reference._abbreviation)),
|
||||||
|
String.join(".", Dmp._dmpReferences, String.join(".", DmpReference._reference, Reference._description)),
|
||||||
|
String.join(".", Dmp._dmpReferences, String.join(".", DmpReference._reference, Reference._definition)),
|
||||||
Dmp._createdAt,
|
Dmp._createdAt,
|
||||||
Dmp._updatedAt,
|
Dmp._updatedAt,
|
||||||
Dmp._finalizedAt
|
Dmp._finalizedAt
|
||||||
|
|
Loading…
Reference in New Issue