Added data field on AssociatedProfilePublicModel on public api

This commit is contained in:
Thomas Georgios Giannos 2024-02-01 12:53:02 +02:00
parent bd2a935606
commit 30abd31974
3 changed files with 27 additions and 9 deletions

View File

@ -46,7 +46,7 @@ public class DmpToPublicApiDmpMapper {
model.setGrant(GrantPublicOverviewModel.fromDmpReferences(dmp.getDmpReferences()));
model.setOrganisations(dmp.getDmpReferences().stream().map(OrganizationPublicModel::fromDmpReference).filter(Objects::nonNull).toList());
model.setDois(doiEntities.stream().map(DoiPublicModel::fromDataModel).toList());
model.setAssociatedProfiles(descriptionTemplates.stream().map(AssociatedProfilePublicModel::fromDmpDescriptionTemplate).toList());
model.setAssociatedProfiles(descriptionTemplates.stream().map(x -> AssociatedProfilePublicModel.fromDmpDescriptionTemplate(x, dmp.getBlueprint())).toList());
model.setCreatedAt(Date.from(dmp.getCreatedAt()));
model.setModifiedAt(Date.from(dmp.getUpdatedAt()));

View File

@ -1,11 +1,11 @@
package eu.eudat.model.publicapi.associatedprofile;
import eu.eudat.model.DescriptionTemplate;
import eu.eudat.model.DmpBlueprint;
import eu.eudat.model.DmpDescriptionTemplate;
import jakarta.xml.bind.annotation.*;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.*;
@XmlRootElement(name = "profile")
@XmlAccessorType(XmlAccessType.FIELD)
@ -51,12 +51,27 @@ public class AssociatedProfilePublicModel {
this.data = data;
}
public static AssociatedProfilePublicModel fromDmpDescriptionTemplate(DmpDescriptionTemplate dmpDescriptionTemplate) {
public static AssociatedProfilePublicModel fromDmpDescriptionTemplate(DmpDescriptionTemplate dmpDescriptionTemplate, DmpBlueprint dmpBlueprint) {
DescriptionTemplate currentDescriptionTemplate = dmpDescriptionTemplate.getCurrentDescriptionTemplate();
UUID sectionId = dmpDescriptionTemplate.getSectionId();
AssociatedProfilePublicModel model = new AssociatedProfilePublicModel();
model.setId(dmpDescriptionTemplate.getCurrentDescriptionTemplate().getId());
model.setDescriptionTemplateId(dmpDescriptionTemplate.getCurrentDescriptionTemplate().getId());
model.setLabel(dmpDescriptionTemplate.getCurrentDescriptionTemplate().getLabel());
model.setData(new HashMap<>());
model.setId(dmpDescriptionTemplate.getId());
model.setDescriptionTemplateId(currentDescriptionTemplate.getId());
model.setLabel(currentDescriptionTemplate.getLabel());
HashMap<String, Object> data = new HashMap<>();
data.put("dmpSectionIndex", getDmpSectionIndexes(dmpBlueprint, sectionId));
model.setData(data);
return model;
}
private static List<Integer> getDmpSectionIndexes(DmpBlueprint dmpBlueprint, UUID sectionId) {
ArrayList<Integer> indexes = new ArrayList<>();
dmpBlueprint.getDefinition().getSections().forEach(x -> {
if (Objects.equals(sectionId, x.getId()))
indexes.add(x.getOrdinal());
});
return indexes;
}
}

View File

@ -10,6 +10,7 @@ import eu.eudat.logic.services.ApiContext;
import eu.eudat.model.*;
import eu.eudat.model.builder.DmpBuilder;
import eu.eudat.model.builder.DmpDescriptionTemplateBuilder;
import eu.eudat.model.dmpblueprintdefinition.Section;
import eu.eudat.model.mapper.publicapi.DmpToPublicApiDmpListingMapper;
import eu.eudat.model.mapper.publicapi.DmpToPublicApiDmpMapper;
import eu.eudat.model.publicapi.listingmodels.DataManagementPlanPublicListingModel;
@ -181,6 +182,8 @@ public class PublicDmpsDocumentation extends BaseController {
String.join(".", Dmp._dmpReferences, DmpReference._reference, Reference._abbreviation),
String.join(".", Dmp._dmpReferences, DmpReference._reference, Reference._description),
String.join(".", Dmp._dmpReferences, DmpReference._reference, Reference._definition),
String.join(".", Dmp._blueprint, eu.eudat.model.dmpblueprintdefinition.Definition._sections, Section._id),
String.join(".", Dmp._blueprint, eu.eudat.model.dmpblueprintdefinition.Definition._sections, Section._ordinal),
Dmp._createdAt,
Dmp._updatedAt,
Dmp._finalizedAt