78 lines
2.4 KiB
Java
78 lines
2.4 KiB
Java
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.*;
|
|
|
|
@XmlRootElement(name = "profile")
|
|
@XmlAccessorType(XmlAccessType.FIELD)
|
|
public class AssociatedProfilePublicModel {
|
|
@XmlAttribute(name="profileId")
|
|
private UUID id;
|
|
@XmlAttribute(name="descriptionTemplateId")
|
|
private UUID descriptionTemplateId;
|
|
@XmlAttribute(name="label")
|
|
private String label;
|
|
@XmlElement(name="data")
|
|
private Map<String, Object> data;
|
|
|
|
public UUID getId() {
|
|
return id;
|
|
}
|
|
|
|
public void setId(UUID id) {
|
|
this.id = id;
|
|
}
|
|
|
|
public UUID getDescriptionTemplateId() {
|
|
return descriptionTemplateId;
|
|
}
|
|
|
|
public void setDescriptionTemplateId(UUID descriptionTemplateId) {
|
|
this.descriptionTemplateId = descriptionTemplateId;
|
|
}
|
|
|
|
public String getLabel() {
|
|
return label;
|
|
}
|
|
|
|
public void setLabel(String label) {
|
|
this.label = label;
|
|
}
|
|
|
|
public Map<String, Object> getData() {
|
|
return data;
|
|
}
|
|
|
|
public void setData(Map<String, Object> data) {
|
|
this.data = data;
|
|
}
|
|
|
|
public static AssociatedProfilePublicModel fromDmpDescriptionTemplate(DmpDescriptionTemplate dmpDescriptionTemplate, DmpBlueprint dmpBlueprint) {
|
|
DescriptionTemplate currentDescriptionTemplate = dmpDescriptionTemplate.getCurrentDescriptionTemplate();
|
|
UUID sectionId = dmpDescriptionTemplate.getSectionId();
|
|
|
|
AssociatedProfilePublicModel model = new AssociatedProfilePublicModel();
|
|
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;
|
|
}
|
|
}
|