dmp export

This commit is contained in:
Efstratios Giannopoulos 2024-04-29 14:56:32 +03:00
parent f89074b695
commit e8be226a0b
26 changed files with 871 additions and 149 deletions

View File

@ -7,7 +7,7 @@ public class ExternalIdentifierEntity {
private String type;
public String getIdentifier() {
return identifier;
return this.identifier;
}
public void setIdentifier(String identifier) {
@ -15,7 +15,7 @@ public class ExternalIdentifierEntity {
}
public String getType() {
return type;
return this.type;
}
public void setType(String type) {

View File

@ -11,7 +11,7 @@ public class FieldEntity {
private ExternalIdentifierEntity externalIdentifier;
public String getTextValue() {
return textValue;
return this.textValue;
}
public void setTextValue(String textValue) {
@ -19,7 +19,7 @@ public class FieldEntity {
}
public List<String> getTextListValue() {
return textListValue;
return this.textListValue;
}
public void setTextListValue(List<String> textListValue) {
@ -27,7 +27,7 @@ public class FieldEntity {
}
public Instant getDateValue() {
return dateValue;
return this.dateValue;
}
public void setDateValue(Instant dateValue) {
@ -35,7 +35,7 @@ public class FieldEntity {
}
public ExternalIdentifierEntity getExternalIdentifier() {
return externalIdentifier;
return this.externalIdentifier;
}
public void setExternalIdentifier(ExternalIdentifierEntity externalIdentifier) {

View File

@ -6,7 +6,7 @@ public class PropertyDefinitionEntity {
private Map<String, PropertyDefinitionFieldSetEntity> fieldSets;
public Map<String, PropertyDefinitionFieldSetEntity> getFieldSets() {
return fieldSets;
return this.fieldSets;
}
public void setFieldSets(Map<String, PropertyDefinitionFieldSetEntity> fieldSets) {

View File

@ -6,7 +6,7 @@ public class PropertyDefinitionFieldSetEntity {
private List<PropertyDefinitionFieldSetItemEntity> items;
public List<PropertyDefinitionFieldSetItemEntity> getItems() {
return items;
return this.items;
}
public void setItems(List<PropertyDefinitionFieldSetItemEntity> items) {

View File

@ -8,7 +8,7 @@ public class PropertyDefinitionFieldSetItemEntity {
private int ordinal;
public Map<String, FieldEntity> getFields() {
return fields;
return this.fields;
}
public void setFields(Map<String, FieldEntity> fields) {
@ -16,7 +16,7 @@ public class PropertyDefinitionFieldSetItemEntity {
}
public String getComment() {
return comment;
return this.comment;
}
public void setComment(String comment) {
@ -24,7 +24,7 @@ public class PropertyDefinitionFieldSetItemEntity {
}
public int getOrdinal() {
return ordinal;
return this.ordinal;
}
public void setOrdinal(int ordinal) {

View File

@ -13,7 +13,7 @@ public class DmpContactEntity {
private String email;
public UUID getUserId() {
return userId;
return this.userId;
}
public void setUserId(UUID userId) {
@ -21,7 +21,7 @@ public class DmpContactEntity {
}
public String getFirstName() {
return firstName;
return this.firstName;
}
public void setFirstName(String firstName) {
@ -29,7 +29,7 @@ public class DmpContactEntity {
}
public String getLastName() {
return lastName;
return this.lastName;
}
public void setLastName(String lastName) {
@ -37,7 +37,7 @@ public class DmpContactEntity {
}
public String getEmail() {
return email;
return this.email;
}
public void setEmail(String email) {

View File

@ -9,7 +9,7 @@ public class DmpPropertiesEntity {
private List<DmpContactEntity> contacts;
public List<DmpBlueprintValueEntity> getDmpBlueprintValues() {
return dmpBlueprintValues;
return this.dmpBlueprintValues;
}
public void setDmpBlueprintValues(List<DmpBlueprintValueEntity> dmpBlueprintValues) {
@ -17,7 +17,7 @@ public class DmpPropertiesEntity {
}
public List<DmpContactEntity> getContacts() {
return contacts;
return this.contacts;
}
public void setContacts(List<DmpContactEntity> contacts) {

View File

@ -0,0 +1,35 @@
package org.opencdmp.commons.types.dmp.importexport;
import jakarta.xml.bind.annotation.XmlAccessType;
import jakarta.xml.bind.annotation.XmlAccessorType;
import jakarta.xml.bind.annotation.XmlAttribute;
import jakarta.xml.bind.annotation.XmlElement;
import java.util.UUID;
@XmlAccessorType(XmlAccessType.FIELD)
public class DmpBlueprintValueImportExport {
@XmlElement(name = "fieldId")
private UUID fieldId;
@XmlElement(name = "value")
private String value;
public UUID getFieldId() {
return this.fieldId;
}
public void setFieldId(UUID fieldId) {
this.fieldId = fieldId;
}
public String getValue() {
return this.value;
}
public void setValue(String value) {
this.value = value;
}
}

View File

@ -0,0 +1,66 @@
package org.opencdmp.commons.types.dmp.importexport;
import jakarta.xml.bind.annotation.XmlAccessType;
import jakarta.xml.bind.annotation.XmlAccessorType;
import jakarta.xml.bind.annotation.XmlElement;
import java.util.UUID;
@XmlAccessorType(XmlAccessType.FIELD)
public class DmpContactImportExport {
@XmlElement(name = "userId")
private UUID userId;
@XmlElement(name = "name")
private String name;
@XmlElement(name = "firstName")
private String firstName;
@XmlElement(name = "lastName")
private String lastName;
@XmlElement(name = "email")
private String email;
public UUID getUserId() {
return this.userId;
}
public void setUserId(UUID userId) {
this.userId = userId;
}
public String getFirstName() {
return this.firstName;
}
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return this.lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getEmail() {
return this.email;
}
public void setEmail(String email) {
this.email = email;
}
}

View File

@ -0,0 +1,33 @@
package org.opencdmp.commons.types.dmp.importexport;
import jakarta.xml.bind.annotation.XmlAccessType;
import jakarta.xml.bind.annotation.XmlAccessorType;
import jakarta.xml.bind.annotation.XmlElement;
import java.util.UUID;
@XmlAccessorType(XmlAccessType.FIELD)
public class DmpDescriptionTemplateImportExport {
@XmlElement(name = "descriptionTemplateGroupId")
private UUID descriptionTemplateGroupId;
@XmlElement(name = "sectionId")
private UUID sectionId;
public UUID getDescriptionTemplateGroupId() {
return this.descriptionTemplateGroupId;
}
public void setDescriptionTemplateGroupId(UUID descriptionTemplateGroupId) {
this.descriptionTemplateGroupId = descriptionTemplateGroupId;
}
public UUID getSectionId() {
return this.sectionId;
}
public void setSectionId(UUID sectionId) {
this.sectionId = sectionId;
}
}

View File

@ -0,0 +1,164 @@
package org.opencdmp.commons.types.dmp.importexport;
import jakarta.xml.bind.annotation.*;
import org.opencdmp.commons.enums.DmpAccessType;
import org.opencdmp.commons.types.dmpblueprint.importexport.BlueprintImportExport;
import java.time.Instant;
import java.util.List;
import java.util.UUID;
@XmlRootElement(name = "dmp")
@XmlAccessorType(XmlAccessType.FIELD)
public class DmpImportExport {
@XmlElement(name = "id")
private UUID id;
@XmlElement(name = "description")
private String description;
@XmlElement(name = "title")
private String title;
@XmlElement(name = "language")
private String language;
@XmlElement(name = "access")
private DmpAccessType access;
@XmlElementWrapper(name = "contacts")
@XmlElement(name = "contact")
private List<DmpContactImportExport> contacts;
@XmlElementWrapper(name = "users")
@XmlElement(name = "user")
private List<DmpUserImportExport> users;
@XmlElement(name = "finalizedAt")
private Instant finalizedAt;
@XmlElement(name = "publicAfter")
private Instant publicAfter;
@XmlElement(name = "blueprint")
private BlueprintImportExport blueprint;
@XmlElementWrapper(name = "blueprintValues")
@XmlElement(name = "blueprintValue")
private List<DmpBlueprintValueImportExport> blueprintValues;
@XmlElementWrapper(name = "descriptionTemplates")
@XmlElement(name = "descriptionTemplate")
private List<DmpDescriptionTemplateImportExport> descriptionTemplates;
@XmlElementWrapper(name = "references")
@XmlElement(name = "reference")
private List<DmpReferenceImportExport> references;
public UUID getId() {
return this.id;
}
public void setId(UUID id) {
this.id = id;
}
public String getDescription() {
return this.description;
}
public void setDescription(String description) {
this.description = description;
}
public String getTitle() {
return this.title;
}
public void setTitle(String title) {
this.title = title;
}
public String getLanguage() {
return this.language;
}
public void setLanguage(String language) {
this.language = language;
}
public DmpAccessType getAccess() {
return this.access;
}
public void setAccess(DmpAccessType access) {
this.access = access;
}
public List<DmpContactImportExport> getContacts() {
return this.contacts;
}
public void setContacts(List<DmpContactImportExport> contacts) {
this.contacts = contacts;
}
public List<DmpUserImportExport> getUsers() {
return this.users;
}
public void setUsers(List<DmpUserImportExport> users) {
this.users = users;
}
public Instant getFinalizedAt() {
return this.finalizedAt;
}
public void setFinalizedAt(Instant finalizedAt) {
this.finalizedAt = finalizedAt;
}
public Instant getPublicAfter() {
return this.publicAfter;
}
public void setPublicAfter(Instant publicAfter) {
this.publicAfter = publicAfter;
}
public BlueprintImportExport getBlueprint() {
return this.blueprint;
}
public void setBlueprint(BlueprintImportExport blueprint) {
this.blueprint = blueprint;
}
public List<DmpBlueprintValueImportExport> getBlueprintValues() {
return this.blueprintValues;
}
public void setBlueprintValues(List<DmpBlueprintValueImportExport> blueprintValues) {
this.blueprintValues = blueprintValues;
}
public List<DmpDescriptionTemplateImportExport> getDescriptionTemplates() {
return this.descriptionTemplates;
}
public void setDescriptionTemplates(List<DmpDescriptionTemplateImportExport> descriptionTemplates) {
this.descriptionTemplates = descriptionTemplates;
}
public List<DmpReferenceImportExport> getReferences() {
return this.references;
}
public void setReferences(List<DmpReferenceImportExport> references) {
this.references = references;
}
}

View File

@ -0,0 +1,62 @@
package org.opencdmp.commons.types.dmp.importexport;
import jakarta.xml.bind.annotation.XmlAccessType;
import jakarta.xml.bind.annotation.XmlAccessorType;
import jakarta.xml.bind.annotation.XmlElement;
import java.util.UUID;
@XmlAccessorType(XmlAccessType.FIELD)
public class DmpReferenceImportExport {
@XmlElement(name = "id")
private UUID id;
@XmlElement(name = "label")
private String label;
@XmlElement(name = "reference")
private String reference;
@XmlElement(name = "fieldId")
private UUID fieldId;
@XmlElement(name = "type")
private DmpReferenceTypeImportExport type;
public UUID getId() {
return this.id;
}
public void setId(UUID id) {
this.id = id;
}
public String getLabel() {
return this.label;
}
public void setLabel(String label) {
this.label = label;
}
public String getReference() {
return this.reference;
}
public void setReference(String reference) {
this.reference = reference;
}
public DmpReferenceTypeImportExport getType() {
return this.type;
}
public void setType(DmpReferenceTypeImportExport type) {
this.type = type;
}
public UUID getFieldId() {
return this.fieldId;
}
public void setFieldId(UUID fieldId) {
this.fieldId = fieldId;
}
}

View File

@ -0,0 +1,45 @@
package org.opencdmp.commons.types.dmp.importexport;
import jakarta.xml.bind.annotation.XmlAccessType;
import jakarta.xml.bind.annotation.XmlAccessorType;
import jakarta.xml.bind.annotation.XmlAttribute;
import jakarta.xml.bind.annotation.XmlElement;
import org.opencdmp.commons.enums.DmpUserRole;
import java.util.UUID;
@XmlAccessorType(XmlAccessType.FIELD)
public class DmpReferenceTypeImportExport {
@XmlElement(name = "id")
private UUID id;
@XmlElement(name = "name")
private String name;
@XmlElement(name = "code")
private String code;
public UUID getId() {
return this.id;
}
public void setId(UUID id) {
this.id = id;
}
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
public String getCode() {
return this.code;
}
public void setCode(String code) {
this.code = code;
}
}

View File

@ -0,0 +1,56 @@
package org.opencdmp.commons.types.dmp.importexport;
import jakarta.xml.bind.annotation.XmlAccessType;
import jakarta.xml.bind.annotation.XmlAccessorType;
import jakarta.xml.bind.annotation.XmlElement;
import org.opencdmp.commons.enums.DmpUserRole;
import java.util.UUID;
@XmlAccessorType(XmlAccessType.FIELD)
public class DmpUserImportExport {
@XmlElement(name = "id")
private UUID id;
@XmlElement(name = "name")
private String name;
@XmlElement(name = "role")
private DmpUserRole role;
@XmlElement(name = "sectionId")
private UUID sectionId;
public UUID getId() {
return this.id;
}
public void setId(UUID id) {
this.id = id;
}
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
public DmpUserRole getRole() {
return this.role;
}
public void setRole(DmpUserRole role) {
this.role = role;
}
public UUID getSectionId() {
return this.sectionId;
}
public void setSectionId(UUID sectionId) {
this.sectionId = sectionId;
}
}

View File

@ -1,19 +1,46 @@
package org.opencdmp.commons.types.dmpblueprint.importexport;
import jakarta.persistence.Column;
import jakarta.persistence.Id;
import jakarta.xml.bind.annotation.XmlAccessType;
import jakarta.xml.bind.annotation.XmlAccessorType;
import jakarta.xml.bind.annotation.XmlElement;
import jakarta.xml.bind.annotation.XmlRootElement;
import org.opencdmp.data.DmpBlueprintEntity;
import java.util.UUID;
@XmlRootElement(name = "root")
@XmlAccessorType(XmlAccessType.FIELD)
public class BlueprintImportExport {
@XmlElement(name = "id")
private UUID id;
@XmlElement(name = "label")
private String label;
@XmlElement(name = "definition")
private DefinitionImportExport dmpBlueprintDefinition;
public UUID getId() {
return this.id;
}
public void setId(UUID id) {
this.id = id;
}
public String getLabel() {
return this.label;
}
public void setLabel(String label) {
this.label = label;
}
public DefinitionImportExport getDmpBlueprintDefinition() {
return dmpBlueprintDefinition;
return this.dmpBlueprintDefinition;
}
public void setDmpBlueprintDefinition(DefinitionImportExport dmpBlueprintDefinition) {

View File

@ -26,7 +26,7 @@ public class DmpDescriptionTemplatePersist {
public static final String _sectionId = "sectionId";
public UUID getDescriptionTemplateGroupId() {
return descriptionTemplateGroupId;
return this.descriptionTemplateGroupId;
}
public void setDescriptionTemplateGroupId(UUID descriptionTemplateGroupId) {
@ -34,7 +34,7 @@ public class DmpDescriptionTemplatePersist {
}
public UUID getSectionId() {
return sectionId;
return this.sectionId;
}
public void setSectionId(UUID sectionId) {
@ -66,10 +66,10 @@ public class DmpDescriptionTemplatePersist {
return Arrays.asList(
this.spec()
.must(() -> this.isValidGuid(item.getDescriptionTemplateGroupId()))
.failOn(DmpDescriptionTemplatePersist._descriptionTemplateGroupId).failWith(messageSource.getMessage("Validation_Required", new Object[]{DmpDescriptionTemplatePersist._descriptionTemplateGroupId}, LocaleContextHolder.getLocale())),
.failOn(DmpDescriptionTemplatePersist._descriptionTemplateGroupId).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{DmpDescriptionTemplatePersist._descriptionTemplateGroupId}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> this.isValidGuid(item.getSectionId()))
.failOn(DmpDescriptionTemplatePersist._sectionId).failWith(messageSource.getMessage("Validation_Required", new Object[]{DmpDescriptionTemplatePersist._sectionId}, LocaleContextHolder.getLocale()))
.failOn(DmpDescriptionTemplatePersist._sectionId).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{DmpDescriptionTemplatePersist._sectionId}, LocaleContextHolder.getLocale()))
);
}

View File

@ -74,7 +74,7 @@ public class DmpPersist {
public static final String _hash = "hash";
public UUID getId() {
return id;
return this.id;
}
public void setId(UUID id) {
@ -82,7 +82,7 @@ public class DmpPersist {
}
public String getLabel() {
return label;
return this.label;
}
public void setLabel(String label) {
@ -90,7 +90,7 @@ public class DmpPersist {
}
public DmpStatus getStatus() {
return status;
return this.status;
}
public void setStatus(DmpStatus status) {
@ -98,7 +98,7 @@ public class DmpPersist {
}
public DmpPropertiesPersist getProperties() {
return properties;
return this.properties;
}
public void setProperties(DmpPropertiesPersist properties) {
@ -106,7 +106,7 @@ public class DmpPersist {
}
public String getDescription() {
return description;
return this.description;
}
public void setDescription(String description) {
@ -114,7 +114,7 @@ public class DmpPersist {
}
public String getLanguage() {
return language;
return this.language;
}
public void setLanguage(String language) {
@ -122,7 +122,7 @@ public class DmpPersist {
}
public UUID getBlueprint() {
return blueprint;
return this.blueprint;
}
public void setBlueprint(UUID blueprint) {
@ -130,7 +130,7 @@ public class DmpPersist {
}
public DmpAccessType getAccessType() {
return accessType;
return this.accessType;
}
public void setAccessType(DmpAccessType accessType) {
@ -138,7 +138,7 @@ public class DmpPersist {
}
public List<DmpDescriptionTemplatePersist> getDescriptionTemplates() {
return descriptionTemplates;
return this.descriptionTemplates;
}
public void setDescriptionTemplates(List<DmpDescriptionTemplatePersist> descriptionTemplates) {
@ -146,7 +146,7 @@ public class DmpPersist {
}
public List<DmpUserPersist> getUsers() {
return users;
return this.users;
}
public void setUsers(List<DmpUserPersist> users) {
@ -154,7 +154,7 @@ public class DmpPersist {
}
public String getHash() {
return hash;
return this.hash;
}
public void setHash(String hash) {
@ -212,34 +212,34 @@ public class DmpPersist {
this.spec()
.iff(() -> this.isValidGuid(item.getId()))
.must(() -> this.isValidHash(item.getHash()))
.failOn(DmpPersist._hash).failWith(messageSource.getMessage("Validation_Required", new Object[]{DmpPersist._hash}, LocaleContextHolder.getLocale())),
.failOn(DmpPersist._hash).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{DmpPersist._hash}, LocaleContextHolder.getLocale())),
this.spec()
.iff(() -> !this.isValidGuid(item.getId()))
.must(() -> !this.isValidHash(item.getHash()))
.failOn(DmpPersist._hash).failWith(messageSource.getMessage("Validation_OverPosting", new Object[]{}, LocaleContextHolder.getLocale())),
.failOn(DmpPersist._hash).failWith(this.messageSource.getMessage("Validation_OverPosting", new Object[]{}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getLabel()))
.failOn(DmpPersist._label).failWith(messageSource.getMessage("Validation_Required", new Object[]{DmpPersist._label}, LocaleContextHolder.getLocale())),
.failOn(DmpPersist._label).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{DmpPersist._label}, LocaleContextHolder.getLocale())),
this.spec()
.iff(() -> !this.isEmpty(item.getLabel()))
.must(() -> this.lessEqualLength(item.getLabel(), DmpEntity._labelLength))
.failOn(DmpPersist._label).failWith(messageSource.getMessage("Validation_MaxLength", new Object[]{DmpPersist._label}, LocaleContextHolder.getLocale())),
.failOn(DmpPersist._label).failWith(this.messageSource.getMessage("Validation_MaxLength", new Object[]{DmpPersist._label}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isNull(item.getStatus()))
.failOn(DmpPersist._status).failWith(messageSource.getMessage("Validation_Required", new Object[]{DmpPersist._status}, LocaleContextHolder.getLocale())),
.failOn(DmpPersist._status).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{DmpPersist._status}, LocaleContextHolder.getLocale())),
this.spec()
.iff(() -> item.getStatus() == DmpStatus.Finalized)
.must(() -> this.isValidGuid(item.getBlueprint()))
.failOn(DmpPersist._blueprint).failWith(messageSource.getMessage("Validation_Required", new Object[]{DmpPersist._blueprint}, LocaleContextHolder.getLocale())),
.failOn(DmpPersist._blueprint).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{DmpPersist._blueprint}, LocaleContextHolder.getLocale())),
this.spec()
.iff(() -> item.getStatus() == DmpStatus.Finalized)
.must(() -> !this.isNull(item.getProperties()))
.failOn(DmpPersist._properties).failWith(messageSource.getMessage("Validation_Required", new Object[]{DmpPersist._properties}, LocaleContextHolder.getLocale())),
.failOn(DmpPersist._properties).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{DmpPersist._properties}, LocaleContextHolder.getLocale())),
this.spec()
.iff(() -> item.getStatus() == DmpStatus.Finalized)
.must(() -> this.isDescriptionTemplateMultiplicityValid(finalDmpBlueprintEntity, item.getId()))
.failOn(DmpPersist._descriptionTemplates).failWith(messageSource.getMessage("Validation.InvalidDescriptionTemplateMultiplicityOnDMP", new Object[]{DmpPersist._descriptionTemplates}, LocaleContextHolder.getLocale())),
.failOn(DmpPersist._descriptionTemplates).failWith(this.messageSource.getMessage("Validation.InvalidDescriptionTemplateMultiplicityOnDMP", new Object[]{DmpPersist._descriptionTemplates}, LocaleContextHolder.getLocale())),
this.refSpec()
.iff(() -> !this.isNull(item.getProperties()))
.on(DmpPersist._properties)
@ -248,15 +248,15 @@ public class DmpPersist {
this.spec()
.iff(() -> item.getStatus() == DmpStatus.Finalized)
.must(() -> !this.isNull(item.getLanguage()))
.failOn(DmpPersist._language).failWith(messageSource.getMessage("Validation_Required", new Object[]{languageFieldLabel != null ? languageFieldLabel : DmpBlueprintSystemFieldType.Language.name()}, LocaleContextHolder.getLocale())),
.failOn(DmpPersist._language).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{languageFieldLabel != null ? languageFieldLabel : DmpBlueprintSystemFieldType.Language.name()}, LocaleContextHolder.getLocale())),
this.spec()
.iff(() -> item.getStatus() == DmpStatus.Finalized)
.must(() -> !this.isNull(item.getAccessType()))
.failOn(DmpPersist._accessType).failWith(messageSource.getMessage("Validation_Required", new Object[]{accessFieldLabel != null ? accessFieldLabel : DmpBlueprintSystemFieldType.AccessRights.name()}, LocaleContextHolder.getLocale())),
.failOn(DmpPersist._accessType).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{accessFieldLabel != null ? accessFieldLabel : DmpBlueprintSystemFieldType.AccessRights.name()}, LocaleContextHolder.getLocale())),
this.spec()
.iff(() -> item.getStatus() == DmpStatus.Finalized)
.must(() -> !this.isListNullOrEmpty(item.getDescriptionTemplates()))
.failOn(DmpPersist._descriptionTemplates).failWith(messageSource.getMessage("Validation_Required", new Object[]{DmpPersist._descriptionTemplates}, LocaleContextHolder.getLocale())),
.failOn(DmpPersist._descriptionTemplates).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{DmpPersist._descriptionTemplates}, LocaleContextHolder.getLocale())),
this.navSpec()
.iff(() -> !this.isListNullOrEmpty(item.getDescriptionTemplates()))
.on(DmpPersist._descriptionTemplates)

View File

@ -37,7 +37,7 @@ public class DmpBlueprintValuePersist {
public static final String _reference = "reference";
public UUID getFieldId() {
return fieldId;
return this.fieldId;
}
public void setFieldId(UUID fieldId) {
@ -45,7 +45,7 @@ public class DmpBlueprintValuePersist {
}
public String getFieldValue() {
return fieldValue;
return this.fieldValue;
}
public void setFieldValue(String fieldValue) {
@ -53,7 +53,7 @@ public class DmpBlueprintValuePersist {
}
public List<ReferencePersist> getReferences() {
return references;
return this.references;
}
public void setReferences(List<ReferencePersist> references) {
@ -61,7 +61,7 @@ public class DmpBlueprintValuePersist {
}
public ReferencePersist getReference() {
return reference;
return this.reference;
}
public void setReference(ReferencePersist reference) {
@ -95,29 +95,29 @@ public class DmpBlueprintValuePersist {
@Override
protected List<Specification> specifications(DmpBlueprintValuePersist item) {
fieldEntity = definition != null && this.isValidGuid(item.getFieldId())? definition.getFieldById(item.getFieldId()).stream().findFirst().orElse(null) : null;
boolean required = fieldEntity != null && fieldEntity.isRequired();
this.fieldEntity = this.definition != null && this.isValidGuid(item.getFieldId())? this.definition.getFieldById(item.getFieldId()).stream().findFirst().orElse(null) : null;
boolean required = this.fieldEntity != null && this.fieldEntity.isRequired();
return Arrays.asList(
this.spec()
.must(() -> this.isValidGuid(item.getFieldId()))
.failOn(DmpBlueprintValuePersist._fieldId).failWith(messageSource.getMessage("Validation_Required", new Object[]{DmpBlueprintValuePersist._fieldId}, LocaleContextHolder.getLocale())),
.failOn(DmpBlueprintValuePersist._fieldId).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{DmpBlueprintValuePersist._fieldId}, LocaleContextHolder.getLocale())),
this.spec()
.iff(() -> fieldEntity.getCategory().equals(DmpBlueprintFieldCategory.Extra) && this.isListNullOrEmpty(item.getReferences()) && required)
.iff(() -> this.fieldEntity.getCategory().equals(DmpBlueprintFieldCategory.Extra) && this.isListNullOrEmpty(item.getReferences()) && required)
.must(() -> !this.isEmpty(item.getFieldValue()))
.failOn(DmpBlueprintValuePersist._fieldValue).failWith(messageSource.getMessage("Validation_Required", new Object[]{fieldEntity.getLabel()}, LocaleContextHolder.getLocale())),
.failOn(DmpBlueprintValuePersist._fieldValue).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{this.fieldEntity.getLabel()}, LocaleContextHolder.getLocale())),
this.spec()
.iff(() -> fieldEntity.getCategory().equals(DmpBlueprintFieldCategory.ReferenceType) && this.isEmpty(item.getFieldValue()) && ((ReferenceTypeFieldEntity)fieldEntity).getMultipleSelect() && required)
.iff(() -> this.fieldEntity.getCategory().equals(DmpBlueprintFieldCategory.ReferenceType) && this.isEmpty(item.getFieldValue()) && ((ReferenceTypeFieldEntity) this.fieldEntity).getMultipleSelect() && required)
.must(() -> !this.isListNullOrEmpty(item.getReferences()))
// TODO: Cast Exception
// .failOn(DmpBlueprintValuePersist._references).failWith(messageSource.getMessage("Validation_Required", new Object[]{!this.isEmpty(fieldEntity.getLabel()) ? fieldEntity.getLabel() : this.getReferenceTypeName(fieldEntity)}, LocaleContextHolder.getLocale())),
.failOn(DmpBlueprintValuePersist._references).failWith(messageSource.getMessage("Validation_Required", new Object[]{!this.isEmpty(fieldEntity.getLabel()) ? fieldEntity.getLabel() : DmpBlueprintValuePersist._references}, LocaleContextHolder.getLocale())),
.failOn(DmpBlueprintValuePersist._references).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{!this.isEmpty(this.fieldEntity.getLabel()) ? this.fieldEntity.getLabel() : DmpBlueprintValuePersist._references}, LocaleContextHolder.getLocale())),
this.spec()
.iff(() -> fieldEntity.getCategory().equals(DmpBlueprintFieldCategory.ReferenceType) && this.isEmpty(item.getFieldValue()) && !((ReferenceTypeFieldEntity)fieldEntity).getMultipleSelect() && required)
.iff(() -> this.fieldEntity.getCategory().equals(DmpBlueprintFieldCategory.ReferenceType) && this.isEmpty(item.getFieldValue()) && !((ReferenceTypeFieldEntity) this.fieldEntity).getMultipleSelect() && required)
.must(() -> !this.isNull(item.getReference()))
// TODO: Cast Exception
// .failOn(DmpBlueprintValuePersist._references).failWith(messageSource.getMessage("Validation_Required", new Object[]{!this.isEmpty(fieldEntity.getLabel()) ? fieldEntity.getLabel() : this.getReferenceTypeName(fieldEntity)}, LocaleContextHolder.getLocale())),
.failOn(DmpBlueprintValuePersist._reference).failWith(messageSource.getMessage("Validation_Required", new Object[]{!this.isEmpty(fieldEntity.getLabel()) ? fieldEntity.getLabel() : DmpBlueprintValuePersist._reference}, LocaleContextHolder.getLocale())),
.failOn(DmpBlueprintValuePersist._reference).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{!this.isEmpty(this.fieldEntity.getLabel()) ? this.fieldEntity.getLabel() : DmpBlueprintValuePersist._reference}, LocaleContextHolder.getLocale())),
this.navSpec()
.iff(() -> !this.isListNullOrEmpty(item.getReferences()))
.on(DmpBlueprintValuePersist._references)

View File

@ -1,5 +1,6 @@
package org.opencdmp.service.dmp;
import org.opencdmp.commons.types.dmp.importexport.DmpImportExport;
import org.opencdmp.model.Dmp;
import org.opencdmp.model.DmpUser;
import org.opencdmp.model.DmpValidationResult;
@ -11,6 +12,7 @@ import gr.cite.tools.exception.MyValidationException;
import gr.cite.tools.fieldset.FieldSet;
import jakarta.xml.bind.JAXBException;
import org.springframework.http.ResponseEntity;
import org.xml.sax.SAXException;
import javax.crypto.BadPaddingException;
import javax.crypto.IllegalBlockSizeException;
@ -50,4 +52,7 @@ public interface DmpService {
void dmpInvitationAccept(String token) throws InvalidApplicationException, IOException;
}
DmpImportExport exportXmlEntity(UUID id) throws MyForbiddenException, MyNotFoundException, JAXBException, ParserConfigurationException, IOException, InstantiationException, IllegalAccessException, SAXException, InvalidApplicationException;
ResponseEntity<byte[]> exportXml(UUID id) throws MyForbiddenException, MyNotFoundException, JAXBException, ParserConfigurationException, IOException, InstantiationException, IllegalAccessException, SAXException, InvalidApplicationException;
}

View File

@ -14,6 +14,7 @@ import org.opencdmp.commons.types.actionconfirmation.DmpInvitationEntity;
import org.opencdmp.commons.types.dmp.DmpBlueprintValueEntity;
import org.opencdmp.commons.types.dmp.DmpContactEntity;
import org.opencdmp.commons.types.dmp.DmpPropertiesEntity;
import org.opencdmp.commons.types.dmp.importexport.*;
import org.opencdmp.commons.types.dmpblueprint.ReferenceTypeFieldEntity;
import org.opencdmp.commons.types.dmpblueprint.SectionEntity;
import org.opencdmp.commons.types.dmpreference.DmpReferenceDataEntity;
@ -47,6 +48,7 @@ import org.opencdmp.model.persist.referencedefinition.FieldPersist;
import org.opencdmp.query.*;
import org.opencdmp.service.actionconfirmation.ActionConfirmationService;
import org.opencdmp.service.description.DescriptionService;
import org.opencdmp.service.dmpblueprint.DmpBlueprintService;
import org.opencdmp.service.elastic.ElasticService;
import org.opencdmp.service.filetransformer.FileTransformerService;
import gr.cite.commons.web.authz.service.AuthorizationService;
@ -66,6 +68,7 @@ import gr.cite.tools.validation.ValidationFailure;
import gr.cite.tools.validation.ValidatorFactory;
import jakarta.xml.bind.JAXBException;
import org.jetbrains.annotations.NotNull;
import org.opencdmp.service.responseutils.ResponseUtilsService;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
@ -75,11 +78,13 @@ import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.xml.sax.SAXException;
import javax.crypto.BadPaddingException;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import javax.management.InvalidApplicationException;
import javax.xml.parsers.ParserConfigurationException;
import java.io.IOException;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
@ -135,6 +140,8 @@ public class DmpServiceImpl implements DmpService {
private final AnnotationEntityRemovalIntegrationEventHandler annotationEntityRemovalIntegrationEventHandler;
private final AuthorizationContentResolver authorizationContentResolver;
private final TenantScope tenantScope;
private final ResponseUtilsService responseUtilsService;
private final DmpBlueprintService dmpBlueprintService;
@Autowired
public DmpServiceImpl(
TenantEntityManager entityManager,
@ -156,7 +163,7 @@ public class DmpServiceImpl implements DmpService {
FileTransformerService fileTransformerService,
ValidatorFactory validatorFactory,
ElasticService elasticService,
AnnotationEntityTouchedIntegrationEventHandler annotationEntityTouchedIntegrationEventHandler, AnnotationEntityRemovalIntegrationEventHandler annotationEntityRemovalIntegrationEventHandler, AuthorizationContentResolver authorizationContentResolver, TenantScope tenantScope) {
AnnotationEntityTouchedIntegrationEventHandler annotationEntityTouchedIntegrationEventHandler, AnnotationEntityRemovalIntegrationEventHandler annotationEntityRemovalIntegrationEventHandler, AuthorizationContentResolver authorizationContentResolver, TenantScope tenantScope, ResponseUtilsService responseUtilsService, DmpBlueprintService dmpBlueprintService) {
this.entityManager = entityManager;
this.authorizationService = authorizationService;
this.deleterFactory = deleterFactory;
@ -180,6 +187,8 @@ public class DmpServiceImpl implements DmpService {
this.annotationEntityRemovalIntegrationEventHandler = annotationEntityRemovalIntegrationEventHandler;
this.authorizationContentResolver = authorizationContentResolver;
this.tenantScope = tenantScope;
this.responseUtilsService = responseUtilsService;
this.dmpBlueprintService = dmpBlueprintService;
}
public Dmp persist(DmpPersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException, JAXBException, IOException {
@ -191,9 +200,9 @@ public class DmpServiceImpl implements DmpService {
DmpEntity data = this.patchAndSave(model);
DmpBlueprintEntity blueprintEntity = this.entityManager.find(DmpBlueprintEntity.class, data.getBlueprintId());
if (blueprintEntity == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{data.getBlueprintId(), DmpBlueprint.class.getSimpleName()}, LocaleContextHolder.getLocale()));
if (blueprintEntity == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{data.getBlueprintId(), DmpBlueprint.class.getSimpleName()}, LocaleContextHolder.getLocale()));
org.opencdmp.commons.types.dmpblueprint.DefinitionEntity definition = this.xmlHandlingService.fromXmlSafe(org.opencdmp.commons.types.dmpblueprint.DefinitionEntity.class, blueprintEntity.getDefinition());
if (definition == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{data.getBlueprintId(), org.opencdmp.commons.types.dmpblueprint.DefinitionEntity.class.getSimpleName()}, LocaleContextHolder.getLocale()));
if (definition == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{data.getBlueprintId(), org.opencdmp.commons.types.dmpblueprint.DefinitionEntity.class.getSimpleName()}, LocaleContextHolder.getLocale()));
this.patchAndSaveReferences(this.buildDmpReferencePersists(model.getProperties()), data.getId(), definition);
@ -201,7 +210,7 @@ public class DmpServiceImpl implements DmpService {
this.patchAndSaveTemplates(data.getId(), model.getDescriptionTemplates());
if (!isUpdate && userScope.isSet()) {
if (!isUpdate && this.userScope.isSet()) {
this.addOwner(data);
if (model.getUsers() == null) model.setUsers(new ArrayList<>());
if (model.getUsers().stream().noneMatch(x-> x.getUser() != null && x.getUser().equals(this.userScope.getUserIdSafe()) && DmpUserRole.Owner.equals(x.getRole()))) model.getUsers().add(this.createOwnerPersist());
@ -233,7 +242,7 @@ public class DmpServiceImpl implements DmpService {
private DmpUserPersist createOwnerPersist() {
DmpUserPersist persist = new DmpUserPersist();
persist.setRole(DmpUserRole.Owner);
persist.setUser(userScope.getUserIdSafe());
persist.setUser(this.userScope.getUserIdSafe());
return persist;
}
@ -244,7 +253,7 @@ public class DmpServiceImpl implements DmpService {
data.setCreatedAt(Instant.now());
data.setUpdatedAt(Instant.now());
data.setRole(DmpUserRole.Owner);
data.setUserId(userScope.getUserId());
data.setUserId(this.userScope.getUserId());
data.setDmpId(dmpEntity.getId());
this.entityManager.persist(data);
@ -279,7 +288,7 @@ public class DmpServiceImpl implements DmpService {
List<ContactPair> contactPairs = new ArrayList<>();
contactPairs.add(new ContactPair(ContactInfoType.Email, query.first().getValue()));
NotificationContactData contactData = new NotificationContactData(contactPairs, null, null);
event.setContactHint(jsonHandlingService.toJsonSafe(contactData));
event.setContactHint(this.jsonHandlingService.toJsonSafe(contactData));
this.applyNotificationType(dmp.getStatus(), event);
NotificationFieldData data = new NotificationFieldData();
@ -289,18 +298,18 @@ public class DmpServiceImpl implements DmpService {
fieldInfoList.add(new FieldInfo("{name}", DataType.String, dmp.getLabel()));
fieldInfoList.add(new FieldInfo("{id}", DataType.String, dmp.getId().toString()));
data.setFields(fieldInfoList);
event.setData(jsonHandlingService.toJsonSafe(data));
event.setData(this.jsonHandlingService.toJsonSafe(data));
eventHandler.handle(event);
this.eventHandler.handle(event);
}
private void applyNotificationType(DmpStatus status, NotifyIntegrationEvent event) {
switch (status) {
case Draft:
event.setNotificationType(notificationProperties.getDmpModifiedType());
event.setNotificationType(this.notificationProperties.getDmpModifiedType());
break;
case Finalized:
event.setNotificationType(notificationProperties.getDmpFinalisedType());
event.setNotificationType(this.notificationProperties.getDmpFinalisedType());
break;
default:
throw new MyApplicationException("Unsupported Dmp Status.");
@ -313,7 +322,7 @@ public class DmpServiceImpl implements DmpService {
this.authorizationService.authorizeAtLeastOneForce(List.of(this.authorizationContentResolver.dmpAffiliation(id)), Permission.DeleteDmp);
DmpEntity data = this.entityManager.find(DmpEntity.class, id);
if (data == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{id, Dmp.class.getSimpleName()}, LocaleContextHolder.getLocale()));
if (data == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{id, Dmp.class.getSimpleName()}, LocaleContextHolder.getLocale()));
EntityDoiQuery entityDoiQuery = this.queryFactory.query(EntityDoiQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).types(EntityType.DMP).entityIds(data.getId());
if (entityDoiQuery.count() > 0) throw new MyApplicationException("DMP is deposited can not deleted");
@ -349,7 +358,7 @@ public class DmpServiceImpl implements DmpService {
this.authorizationService.authorizeAtLeastOneForce(List.of(this.authorizationContentResolver.dmpAffiliation( model.getId())), Permission.CreateNewVersionDmp);
DmpEntity oldDmpEntity = this.entityManager.find(DmpEntity.class, model.getId());
if (oldDmpEntity == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{model.getId(), Dmp.class.getSimpleName()}, LocaleContextHolder.getLocale()));
if (oldDmpEntity == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{model.getId(), Dmp.class.getSimpleName()}, LocaleContextHolder.getLocale()));
if (!this.conventionService.hashValue(oldDmpEntity.getUpdatedAt()).equals(model.getHash())) throw new MyValidationException(this.errors.getHashConflict().getCode(), this.errors.getHashConflict().getMessage());
List<DmpEntity> latestVersionDmps = this.queryFactory.query(DmpQuery.class)
@ -500,7 +509,7 @@ public class DmpServiceImpl implements DmpService {
DmpEntity existingDmpEntity = this.queryFactory.query(DmpQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).ids(model.getId()).firstAs(fields);
if (!this.conventionService.isValidGuid(model.getId()) || existingDmpEntity == null)
throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{model.getId(), Dmp.class.getSimpleName()}, LocaleContextHolder.getLocale()));
throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{model.getId(), Dmp.class.getSimpleName()}, LocaleContextHolder.getLocale()));
DmpEntity newDmp = new DmpEntity();
newDmp.setId(UUID.randomUUID());
@ -582,7 +591,7 @@ public class DmpServiceImpl implements DmpService {
DmpEntity resultingDmpEntity = this.queryFactory.query(DmpQuery.class).ids(newDmp.getId()).firstAs(fields);
if (!this.conventionService.isListNullOrEmpty(model.getDescriptions())){
for (UUID description: model.getDescriptions()) {
descriptionService.clone(newDmp.getId(), description);
this.descriptionService.clone(newDmp.getId(), description);
}
}
return this.builderFactory.builder(DmpBuilder.class).build(fields, resultingDmpEntity);
@ -595,7 +604,7 @@ public class DmpServiceImpl implements DmpService {
if (!disableDelete && (model == null || model.stream().noneMatch(x-> x.getUser() != null && DmpUserRole.Owner.equals(x.getRole())))) throw new MyApplicationException("At least one owner required");
DmpEntity dmpEntity = this.entityManager.find(DmpEntity.class, dmpId);
if (dmpEntity == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{dmpId, Dmp.class.getSimpleName()}, LocaleContextHolder.getLocale()));
if (dmpEntity == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{dmpId, Dmp.class.getSimpleName()}, LocaleContextHolder.getLocale()));
List<DmpUserEntity> existingUsers = this.queryFactory.query(DmpUserQuery.class)
.dmpIds(dmpId)
@ -641,7 +650,7 @@ public class DmpServiceImpl implements DmpService {
public Dmp removeUser(DmpUserRemovePersist model, FieldSet fields) throws InvalidApplicationException, IOException {
this.authorizationService.authorizeAtLeastOneForce(List.of(this.authorizationContentResolver.dmpAffiliation(model.getDmpId())), Permission.AssignDmpUsers);
DmpEntity data = this.entityManager.find(DmpEntity.class, model.getDmpId());
if (data == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{model.getId(), Dmp.class.getSimpleName()}, LocaleContextHolder.getLocale()));
if (data == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{model.getId(), Dmp.class.getSimpleName()}, LocaleContextHolder.getLocale()));
List<DmpUserEntity> existingUsers = this.queryFactory.query(DmpUserQuery.class)
.dmpIds(model.getDmpId()).ids(model.getId()).userRoles(model.getRole())
@ -652,7 +661,7 @@ public class DmpServiceImpl implements DmpService {
this.entityManager.flush();
DmpEntity dmpEntity = this.entityManager.find(DmpEntity.class, model.getDmpId());
if (dmpEntity == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{model.getDmpId(), Dmp.class.getSimpleName()}, LocaleContextHolder.getLocale()));
if (dmpEntity == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{model.getDmpId(), Dmp.class.getSimpleName()}, LocaleContextHolder.getLocale()));
this.elasticService.persistDmp(dmpEntity);
this.annotationEntityTouchedIntegrationEventHandler.handleDmp(dmpEntity.getId());
@ -677,7 +686,7 @@ public class DmpServiceImpl implements DmpService {
DmpEntity data;
if (isUpdate) {
data = this.entityManager.find(DmpEntity.class, model.getId());
if (data == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{model.getId(), Dmp.class.getSimpleName()}, LocaleContextHolder.getLocale()));
if (data == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{model.getId(), Dmp.class.getSimpleName()}, LocaleContextHolder.getLocale()));
if (!this.conventionService.hashValue(data.getUpdatedAt()).equals(model.getHash())) throw new MyValidationException(this.errors.getHashConflict().getCode(), this.errors.getHashConflict().getMessage());
if (model.getStatus() != null && model.getStatus() == DmpStatus.Finalized && data.getStatus() != DmpStatus.Finalized) {
this.authorizationService.authorizeAtLeastOneForce(List.of(this.authorizationContentResolver.dmpAffiliation(model.getId())), Permission.FinalizeDmp);
@ -691,7 +700,7 @@ public class DmpServiceImpl implements DmpService {
data.setVersion((short) 1);
data.setStatus(DmpStatus.Draft);
data.setVersionStatus(DmpVersionStatus.NotFinalized);
data.setCreatorId(userScope.getUserId());
data.setCreatorId(this.userScope.getUserId());
data.setBlueprintId(model.getBlueprint());
data.setIsActive(IsActive.Active);
data.setCreatedAt(Instant.now());
@ -804,10 +813,10 @@ public class DmpServiceImpl implements DmpService {
ReferenceEntity referenceEntity;
if (this.conventionService.isValidGuid(referencePersist.getId())){
referenceEntity = this.entityManager.find(ReferenceEntity.class, referencePersist.getId());
if (referenceEntity == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{referencePersist.getId(), Reference.class.getSimpleName()}, LocaleContextHolder.getLocale()));
if (referenceEntity == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{referencePersist.getId(), Reference.class.getSimpleName()}, LocaleContextHolder.getLocale()));
} else {
ReferenceTypeFieldEntity fieldEntity = blueprintDefinition.getFieldById(model.getData().getBlueprintFieldId()).stream().filter(x-> x.getCategory().equals(DmpBlueprintFieldCategory.ReferenceType)).map(x-> (ReferenceTypeFieldEntity)x).findFirst().orElse(null);
if (fieldEntity == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{model.getData().getBlueprintFieldId(), ReferenceTypeFieldEntity.class.getSimpleName()}, LocaleContextHolder.getLocale()));
if (fieldEntity == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{model.getData().getBlueprintFieldId(), ReferenceTypeFieldEntity.class.getSimpleName()}, LocaleContextHolder.getLocale()));
referenceEntity = this.queryFactory.query(ReferenceQuery.class).sourceTypes(referencePersist.getSourceType()).typeIds(fieldEntity.getReferenceTypeId()).sources(referencePersist.getSource()).isActive(IsActive.Active).references(referencePersist.getReference()).first();
if (referenceEntity == null){
@ -826,14 +835,14 @@ public class DmpServiceImpl implements DmpService {
referenceEntity.setSourceType(referencePersist.getSourceType());
try {
ReferenceTypeEntity referenceType = this.queryFactory.query(ReferenceTypeQuery.class).ids(fieldEntity.getReferenceTypeId()).firstAs(new BaseFieldSet().ensure(ReferenceType._id).ensure(ReferenceTypeEntity._tenantId));
if (referenceType == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{fieldEntity.getReferenceTypeId(), ReferenceType.class.getSimpleName()}, LocaleContextHolder.getLocale()));
if (referenceType == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{fieldEntity.getReferenceTypeId(), ReferenceType.class.getSimpleName()}, LocaleContextHolder.getLocale()));
if (referenceEntity.getSourceType().equals(ReferenceSourceType.External) && !this.tenantScope.isDefaultTenant() && referenceType.getTenantId() == null){
this.tenantScope.setTempTenant(this.entityManager.getEntityManager(), null, this.tenantScope.getDefaultTenantCode());
}
this.entityManager.persist(referenceEntity);
} finally {
tenantScope.removeTempTenant(this.entityManager.getEntityManager());
this.tenantScope.removeTempTenant(this.entityManager.getEntityManager());
}
}
}
@ -930,7 +939,7 @@ public class DmpServiceImpl implements DmpService {
DmpEntity dmp = this.queryFactory.query(DmpQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).ids(id).isActive(IsActive.Active).first();
if (dmp == null){
throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{id, Dmp.class.getSimpleName()}, LocaleContextHolder.getLocale()));
throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{id, Dmp.class.getSimpleName()}, LocaleContextHolder.getLocale()));
}
if (dmp.getStatus().equals(DmpStatus.Finalized)){
@ -985,7 +994,7 @@ public class DmpServiceImpl implements DmpService {
this.authorizationService.authorizeAtLeastOneForce(List.of(this.authorizationContentResolver.dmpAffiliation(id)), Permission.UndoFinalizeDmp);
DmpEntity dmp = this.queryFactory.query(DmpQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).ids(id).isActive(IsActive.Active).firstAs(fields);
if (dmp == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{id, Dmp.class.getSimpleName()}, LocaleContextHolder.getLocale()));
if (dmp == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{id, Dmp.class.getSimpleName()}, LocaleContextHolder.getLocale()));
if (!dmp.getStatus().equals(DmpStatus.Finalized)) throw new MyApplicationException("DMP is already drafted");
@ -1009,7 +1018,7 @@ public class DmpServiceImpl implements DmpService {
DmpEntity dmp = this.queryFactory.query(DmpQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).ids(id).isActive(IsActive.Active).first();
if (dmp == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{id, Dmp.class.getSimpleName()}, LocaleContextHolder.getLocale()));
if (dmp == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{id, Dmp.class.getSimpleName()}, LocaleContextHolder.getLocale()));
DmpValidationResult dmpValidationResult = new DmpValidationResult(dmp.getId(), DmpValidationOutput.Invalid);
@ -1028,7 +1037,7 @@ public class DmpServiceImpl implements DmpService {
if (data == null) return persist;
DmpBlueprintEntity dmpBlueprintEntity = this.entityManager.find(DmpBlueprintEntity.class, data.getBlueprintId());
if (dmpBlueprintEntity == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{data.getBlueprintId(), DmpBlueprint.class.getSimpleName()}, LocaleContextHolder.getLocale()));
if (dmpBlueprintEntity == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{data.getBlueprintId(), DmpBlueprint.class.getSimpleName()}, LocaleContextHolder.getLocale()));
persist.setId(data.getId());
persist.setHash(data.getId().toString());
@ -1046,9 +1055,9 @@ public class DmpServiceImpl implements DmpService {
for (DmpUserEntity user: dmpUserEntities) {
persist.getUsers().add(this.buildDmpUserPersist(user));
}
};
}
List<DmpReferenceEntity> dmpReferenceEntities = this.queryFactory.query(DmpReferenceQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).dmpIds(data.getId()).isActives(IsActive.Active).collect();
List<DmpReferenceEntity> dmpReferenceEntities = this.queryFactory.query(DmpReferenceQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).dmpIds(data.getId()).isActives(IsActive.Active).collect();
org.opencdmp.commons.types.dmpblueprint.DefinitionEntity definition = this.xmlHandlingService.fromXmlSafe(org.opencdmp.commons.types.dmpblueprint.DefinitionEntity.class, dmpBlueprintEntity.getDefinition());
@ -1058,8 +1067,8 @@ public class DmpServiceImpl implements DmpService {
for (DmpDescriptionTemplateEntity descriptionTemplateEntity: dmpDescriptionTemplateEntities) {
persist.getDescriptionTemplates().add(this.buildDmpDescriptionTemplatePersists(descriptionTemplateEntity, definition.getSections()));
}
};
persist.setProperties(this.buildDmpPropertyDefinitionPersist( this.jsonHandlingService.fromJsonSafe(DmpPropertiesEntity.class, data.getProperties()), dmpReferenceEntities, definition.getSections()));
}
persist.setProperties(this.buildDmpPropertyDefinitionPersist( this.jsonHandlingService.fromJsonSafe(DmpPropertiesEntity.class, data.getProperties()), dmpReferenceEntities, definition.getSections()));
return persist;
}
@ -1250,8 +1259,8 @@ public class DmpServiceImpl implements DmpService {
List<ContactPair> contactPairs = new ArrayList<>();
contactPairs.add(new ContactPair(ContactInfoType.Email, email));
NotificationContactData contactData = new NotificationContactData(contactPairs, null, null);
event.setContactHint(jsonHandlingService.toJsonSafe(contactData));
event.setNotificationType(notificationProperties.getDmpInvitationExistingUserType());
event.setContactHint(this.jsonHandlingService.toJsonSafe(contactData));
event.setNotificationType(this.notificationProperties.getDmpInvitationExistingUserType());
NotificationFieldData data = new NotificationFieldData();
List<FieldInfo> fieldInfoList = new ArrayList<>();
fieldInfoList.add(new FieldInfo("{recipient}", DataType.String, recipient.getName()));
@ -1260,8 +1269,8 @@ public class DmpServiceImpl implements DmpService {
fieldInfoList.add(new FieldInfo("{dmprole}", DataType.String, role.toString()));
fieldInfoList.add(new FieldInfo("{id}", DataType.String, dmp.getId().toString()));
data.setFields(fieldInfoList);
event.setData(jsonHandlingService.toJsonSafe(data));
eventHandler.handle(event);
event.setData(this.jsonHandlingService.toJsonSafe(data));
this.eventHandler.handle(event);
}
private void sendDmpInvitationExternalUser(String email, DmpEntity dmp, DmpUserRole role) throws JAXBException, InvalidApplicationException {
@ -1272,9 +1281,9 @@ public class DmpServiceImpl implements DmpService {
List<ContactPair> contactPairs = new ArrayList<>();
contactPairs.add(new ContactPair(ContactInfoType.Email, email));
NotificationContactData contactData = new NotificationContactData(contactPairs, null, null);
event.setContactHint(jsonHandlingService.toJsonSafe(contactData));
event.setContactHint(this.jsonHandlingService.toJsonSafe(contactData));
event.setContactTypeHint(NotificationContactType.EMAIL);
event.setNotificationType(notificationProperties.getDmpInvitationExternalUserType());
event.setNotificationType(this.notificationProperties.getDmpInvitationExternalUserType());
NotificationFieldData data = new NotificationFieldData();
List<FieldInfo> fieldInfoList = new ArrayList<>();
fieldInfoList.add(new FieldInfo("{recipient}", DataType.String, email));
@ -1282,8 +1291,8 @@ public class DmpServiceImpl implements DmpService {
fieldInfoList.add(new FieldInfo("{dmpname}", DataType.String, dmp.getLabel()));
fieldInfoList.add(new FieldInfo("{dmprole}", DataType.String, role.toString()));
data.setFields(fieldInfoList);
event.setData(jsonHandlingService.toJsonSafe(data));
eventHandler.handle(event);
event.setData(this.jsonHandlingService.toJsonSafe(data));
this.eventHandler.handle(event);
}
private String createActionConfirmation(String email, DmpEntity dmp, DmpUserRole role) throws JAXBException, InvalidApplicationException {
@ -1293,7 +1302,7 @@ public class DmpServiceImpl implements DmpService {
persist.setToken(UUID.randomUUID().toString());
persist.setDmpInvitation(new DmpInvitationPersist(email, dmp.getId(), role));
persist.setExpiresAt(Instant.now().plusSeconds(this.notificationProperties.getEmailExpirationTimeSeconds()));
validatorFactory.validator(ActionConfirmationPersist.ActionConfirmationPersistValidator.class).validateForce(persist);
this.validatorFactory.validator(ActionConfirmationPersist.ActionConfirmationPersistValidator.class).validateForce(persist);
this.actionConfirmationService.persist(persist, null);
return persist.getToken();
@ -1330,4 +1339,180 @@ public class DmpServiceImpl implements DmpService {
this.annotationEntityTouchedIntegrationEventHandler.handleDmp(dmpInvitation.getDmpId());
}
//region Export
@Override
public DmpImportExport exportXmlEntity(UUID id) throws MyForbiddenException, MyNotFoundException, JAXBException, ParserConfigurationException, IOException, InstantiationException, IllegalAccessException, SAXException, InvalidApplicationException {
logger.debug(new MapLogEntry("export xml").And("id", id));
this.authorizationService.authorizeForce(Permission.ExportDmp);
DmpEntity data = this.entityManager.find(DmpEntity.class, id);
if (data == null)
throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{id, Dmp.class.getSimpleName()}, LocaleContextHolder.getLocale()));
DmpPropertiesEntity definition = this.jsonHandlingService.fromJson(DmpPropertiesEntity.class, data.getProperties());
return this.definitionXmlToExport(data, definition);
}
@Override
public ResponseEntity<byte[]> exportXml(UUID id) throws MyForbiddenException, MyNotFoundException, JAXBException, ParserConfigurationException, IOException, InstantiationException, IllegalAccessException, SAXException, InvalidApplicationException {
logger.debug(new MapLogEntry("export xml").And("id", id));
this.authorizationService.authorizeForce(Permission.ExportDmp);
DmpEntity data = this.entityManager.find(DmpEntity.class, id);
if (data == null)
throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{id, Dmp.class.getSimpleName()}, LocaleContextHolder.getLocale()));
String xml = this.xmlHandlingService.toXml(this.exportXmlEntity(data.getId()));
return this.responseUtilsService.buildResponseFileFromText(xml, data.getLabel() + ".xml");
}
private DmpImportExport definitionXmlToExport(DmpEntity data, DmpPropertiesEntity propertiesEntity) throws InvalidApplicationException, JAXBException, ParserConfigurationException, IOException, InstantiationException, IllegalAccessException, SAXException {
DmpImportExport xml = new DmpImportExport();
xml.setId(data.getId());
xml.setDescription(data.getDescription());
xml.setTitle(data.getLabel());
xml.setLanguage(data.getLanguage());
xml.setAccess(data.getAccessType());
xml.setFinalizedAt(data.getFinalizedAt());
xml.setPublicAfter(data.getPublicAfter());
if (propertiesEntity != null && !this.conventionService.isListNullOrEmpty(propertiesEntity.getContacts())) {
List<DmpContactImportExport> dmpContactImportExports = new LinkedList<>();
List<UserEntity> users = this.queryFactory.query(UserQuery.class).ids(propertiesEntity.getContacts().stream().filter(x-> x.getUserId() != null).map(DmpContactEntity::getUserId).distinct().toList()).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).isActive(IsActive.Active).collect();
Map<UUID, UserEntity> usersMap = users == null ? new HashMap<>() : users.stream().collect(Collectors.toMap(UserEntity::getId, x-> x));
for (DmpContactEntity contactEntity : propertiesEntity.getContacts()) {
dmpContactImportExports.add(this.dmpContactToExport(contactEntity, usersMap));
}
xml.setContacts(dmpContactImportExports);
}
List<DmpUserEntity> dmpUsers = this.queryFactory.query(DmpUserQuery.class).dmpIds(data.getId()).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).isActives(IsActive.Active).collect();
if (!this.conventionService.isListNullOrEmpty(dmpUsers)) {
List<UserEntity> users = this.queryFactory.query(UserQuery.class).ids(dmpUsers.stream().map(DmpUserEntity::getUserId).distinct().toList()).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).isActive(IsActive.Active).collect();
Map<UUID, UserEntity> usersMap = users == null ? new HashMap<>() : users.stream().collect(Collectors.toMap(UserEntity::getId, x-> x));
List<DmpUserImportExport> dmpUserImportExports = new LinkedList<>();
for (DmpUserEntity dmpUserEntity : dmpUsers) {
dmpUserImportExports.add(this.dmpUserToExport(dmpUserEntity, usersMap));
}
xml.setUsers(dmpUserImportExports);
}
DmpBlueprintEntity blueprintEntity = this.queryFactory.query(DmpBlueprintQuery.class).ids(data.getBlueprintId()).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).isActive(IsActive.Active).first();
if (blueprintEntity != null) {
xml.setBlueprint(this.dmpBlueprintService.getExportXmlEntity(blueprintEntity.getId()));
}
List<DmpDescriptionTemplateEntity> dmpDescriptionTemplateEntities = this.queryFactory.query(DmpDescriptionTemplateQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).dmpIds(data.getId()).isActive(IsActive.Active).collect();
if (!this.conventionService.isListNullOrEmpty(dmpDescriptionTemplateEntities)) {
List<DmpDescriptionTemplateImportExport> dmpDescriptionTemplateImportExports = new LinkedList<>();
for (DmpDescriptionTemplateEntity descriptionTemplateEntity : dmpDescriptionTemplateEntities) {
dmpDescriptionTemplateImportExports.add(this.dmpDescriptionTemplateToExport(descriptionTemplateEntity));
}
xml.setDescriptionTemplates(dmpDescriptionTemplateImportExports);
}
if (propertiesEntity != null && !this.conventionService.isListNullOrEmpty(propertiesEntity.getDmpBlueprintValues())) {
List<DmpBlueprintValueImportExport> dmpDescriptionTemplateImportExports = new LinkedList<>();
for (DmpBlueprintValueEntity dmpBlueprintValueEntity : propertiesEntity.getDmpBlueprintValues()) {
dmpDescriptionTemplateImportExports.add(this.dmpBlueprintValueToExport(dmpBlueprintValueEntity));
}
xml.setBlueprintValues(dmpDescriptionTemplateImportExports);
}
List<DmpReferenceEntity> dmpReferences = this.queryFactory.query(DmpReferenceQuery.class).dmpIds(data.getId()).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).isActives(IsActive.Active).collect();
if (!this.conventionService.isListNullOrEmpty(dmpReferences)) {
List<ReferenceEntity> references = this.queryFactory.query(ReferenceQuery.class).ids(dmpReferences.stream().map(DmpReferenceEntity::getReferenceId).distinct().toList()).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).isActive(IsActive.Active).collect();
Map<UUID, ReferenceEntity> referenceEntityMap = references == null ? new HashMap<>() : references.stream().collect(Collectors.toMap(ReferenceEntity::getId, x-> x));
List<ReferenceTypeEntity> referenceTypes = references == null ? new ArrayList<>() : this.queryFactory.query(ReferenceTypeQuery.class).ids(references.stream().map(ReferenceEntity::getTypeId).distinct().toList()).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).isActive(IsActive.Active).collect();
Map<UUID, ReferenceTypeEntity> referenceTypeEntityMap = referenceTypes == null ? new HashMap<>() : referenceTypes.stream().collect(Collectors.toMap(ReferenceTypeEntity::getId, x-> x));
List<DmpReferenceImportExport> dmpReferenceImportExports = new LinkedList<>();
for (DmpReferenceEntity descriptionTemplateEntity : dmpReferences) {
dmpReferenceImportExports.add(this.dmpReferenceToExport(descriptionTemplateEntity, referenceEntityMap, referenceTypeEntityMap));
}
xml.setReferences(dmpReferenceImportExports);
}
return xml;
}
private DmpReferenceImportExport dmpReferenceToExport(DmpReferenceEntity entity, Map<UUID, ReferenceEntity> referenceEntityMap, Map<UUID, ReferenceTypeEntity> referenceTypeEntityMap) {
DmpReferenceImportExport xml = new DmpReferenceImportExport();
if (entity == null) return xml;
DmpReferenceDataEntity referenceData = this.jsonHandlingService.fromJsonSafe(DmpReferenceDataEntity.class, entity.getData());
if (referenceData != null) xml.setFieldId(referenceData.getBlueprintFieldId());
ReferenceEntity reference = referenceEntityMap.getOrDefault(entity.getReferenceId(), null);
if (reference != null){
xml.setId(reference.getId());
xml.setLabel(reference.getLabel());
xml.setReference(reference.getReference());
ReferenceTypeEntity referenceType = referenceTypeEntityMap.getOrDefault(reference.getTypeId(), null);
if (referenceType != null) xml.setType(this.dmpReferenceTypeToExport(referenceType));
}
return xml;
}
private DmpReferenceTypeImportExport dmpReferenceTypeToExport(ReferenceTypeEntity entity) {
DmpReferenceTypeImportExport xml = new DmpReferenceTypeImportExport();
if (entity == null) return xml;
xml.setId(entity.getId());
xml.setCode(entity.getCode());
xml.setName(entity.getName());
return xml;
}
private DmpBlueprintValueImportExport dmpBlueprintValueToExport(DmpBlueprintValueEntity entity) {
DmpBlueprintValueImportExport xml = new DmpBlueprintValueImportExport();
if (entity == null) return xml;
xml.setFieldId(entity.getFieldId());
xml.setValue(entity.getValue());
return xml;
}
private DmpDescriptionTemplateImportExport dmpDescriptionTemplateToExport(DmpDescriptionTemplateEntity entity) {
DmpDescriptionTemplateImportExport xml = new DmpDescriptionTemplateImportExport();
if (entity == null) return xml;
xml.setDescriptionTemplateGroupId(entity.getDescriptionTemplateGroupId());
xml.setSectionId(entity.getSectionId());
return xml;
}
private DmpUserImportExport dmpUserToExport(DmpUserEntity entity, Map<UUID, UserEntity> usersMap) {
DmpUserImportExport xml = new DmpUserImportExport();
if (entity == null) return xml;
xml.setId(entity.getUserId());
UserEntity userEntity = usersMap.getOrDefault(entity.getUserId(), null);
if (userEntity != null){
xml.setName(userEntity.getName());
}
xml.setRole(entity.getRole());
xml.setSectionId(entity.getSectionId());
return xml;
}
private DmpContactImportExport dmpContactToExport(DmpContactEntity entity, Map<UUID, UserEntity> usersMap) {
DmpContactImportExport xml = new DmpContactImportExport();
if (entity == null) return xml;
UserEntity userEntity = entity.getUserId() == null ? null : usersMap.getOrDefault(entity.getUserId(), null);
if (userEntity != null){
xml.setName(userEntity.getName());
}
xml.setUserId(entity.getUserId());
xml.setEmail(entity.getEmail());
xml.setFirstName(entity.getFirstName());
xml.setLastName(entity.getLastName());
return xml;
}
//endregion
}

View File

@ -2,6 +2,7 @@ package org.opencdmp.service.dmpblueprint;
import com.fasterxml.jackson.core.JsonProcessingException;
import org.opencdmp.commons.enums.DmpBlueprintSystemFieldType;
import org.opencdmp.commons.types.dmpblueprint.importexport.BlueprintImportExport;
import org.opencdmp.data.DmpBlueprintEntity;
import org.opencdmp.model.DmpBlueprint;
import org.opencdmp.model.persist.DmpBlueprintPersist;
@ -34,6 +35,8 @@ public interface DmpBlueprintService {
DmpBlueprint createNewVersion(NewVersionDmpBlueprintPersist model, FieldSet fieldSet) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException, JAXBException, ParserConfigurationException, JsonProcessingException, TransformerException;
BlueprintImportExport getExportXmlEntity(UUID id) throws MyForbiddenException, MyNotFoundException, InvalidApplicationException, JAXBException, ParserConfigurationException, IOException, InstantiationException, IllegalAccessException, SAXException;
ResponseEntity<byte[]> exportXml(UUID id) throws MyForbiddenException, MyNotFoundException, JAXBException, ParserConfigurationException, IOException, InstantiationException, IllegalAccessException, SAXException, TransformerException, InvalidApplicationException;
DmpBlueprint importXml(byte[] bytes, String label, FieldSet fields) throws MyForbiddenException, MyNotFoundException, JAXBException, ParserConfigurationException, TransformerException, InvalidApplicationException, IOException, InstantiationException, IllegalAccessException, SAXException;
}

View File

@ -120,7 +120,7 @@ public class DmpBlueprintServiceImpl implements DmpBlueprintService {
if (isUpdate) {
data = this.entityManager.find(DmpBlueprintEntity.class, model.getId());
if (data == null)
throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{model.getId(), DmpBlueprint.class.getSimpleName()}, LocaleContextHolder.getLocale()));
throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{model.getId(), DmpBlueprint.class.getSimpleName()}, LocaleContextHolder.getLocale()));
if (!this.conventionService.hashValue(data.getUpdatedAt()).equals(model.getHash()))
throw new MyValidationException(this.errors.getHashConflict().getCode(), this.errors.getHashConflict().getMessage());
if (data.getStatus().equals(DmpBlueprintStatus.Finalized))
@ -138,7 +138,7 @@ public class DmpBlueprintServiceImpl implements DmpBlueprintService {
DmpBlueprintStatus previousStatus = data.getStatus();
if (model.getDefinition() != null && !model.getDefinition().getSections().stream().anyMatch(x -> x.getHasTemplates())) {
if (model.getDefinition() != null && model.getDefinition().getSections().stream().noneMatch(SectionPersist::getHasTemplates)) {
throw new MyValidationException(this.errors.getDmpBlueprintHasNoDescriptionTemplates().getCode(), this.errors.getDmpBlueprintHasNoDescriptionTemplates().getMessage());
}
@ -323,7 +323,7 @@ public class DmpBlueprintServiceImpl implements DmpBlueprintService {
public boolean fieldInBlueprint(UUID id, DmpBlueprintSystemFieldType type) throws InvalidApplicationException {
DmpBlueprintEntity data = this.entityManager.find(DmpBlueprintEntity.class, id);
if (data == null)
throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{id, DmpBlueprint.class.getSimpleName()}, LocaleContextHolder.getLocale()));
throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{id, DmpBlueprint.class.getSimpleName()}, LocaleContextHolder.getLocale()));
return this.fieldInBlueprint(data, type);
}
@ -339,7 +339,7 @@ public class DmpBlueprintServiceImpl implements DmpBlueprintService {
DmpBlueprintQuery query = this.queryFactory.query(DmpBlueprintQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).ids(id);
DmpBlueprint model = this.builderFactory.builder(DmpBlueprintBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(fields, query.firstAs(fields));
if (model == null)
throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{id, DmpBlueprint.class.getSimpleName()}, LocaleContextHolder.getLocale()));
throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{id, DmpBlueprint.class.getSimpleName()}, LocaleContextHolder.getLocale()));
model.setLabel(model.getLabel() + " new ");
model.setId(null);
@ -391,7 +391,7 @@ public class DmpBlueprintServiceImpl implements DmpBlueprintService {
DmpBlueprintEntity oldDmpBlueprintEntity = this.entityManager.find(DmpBlueprintEntity.class, model.getId());
if (oldDmpBlueprintEntity == null)
throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{model.getId(), DmpBlueprint.class.getSimpleName()}, LocaleContextHolder.getLocale()));
throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{model.getId(), DmpBlueprint.class.getSimpleName()}, LocaleContextHolder.getLocale()));
if (!this.conventionService.hashValue(oldDmpBlueprintEntity.getUpdatedAt()).equals(model.getHash()))
throw new MyValidationException(this.errors.getHashConflict().getCode(), this.errors.getHashConflict().getMessage());
if (!this.tenantScope.isSet() || !Objects.equals(oldDmpBlueprintEntity.getTenantId(), this.tenantScope.getTenant())) throw new MyForbiddenException(this.errors.getTenantTampering().getCode(), this.errors.getTenantTampering().getMessage());
@ -443,19 +443,44 @@ public class DmpBlueprintServiceImpl implements DmpBlueprintService {
//region Export
public ResponseEntity<byte[]> exportXml(UUID id) throws MyForbiddenException, MyNotFoundException, JAXBException, ParserConfigurationException, IOException, InstantiationException, IllegalAccessException, SAXException, TransformerException, InvalidApplicationException {
logger.debug(new MapLogEntry("persisting data").And("id", id));
@Override
public BlueprintImportExport getExportXmlEntity(UUID id) throws MyForbiddenException, MyNotFoundException, InvalidApplicationException, JAXBException, ParserConfigurationException, IOException, InstantiationException, IllegalAccessException, SAXException {
logger.debug(new MapLogEntry("export xml").And("id", id));
this.authorizationService.authorizeForce(Permission.ExportDmpBlueprint);
DmpBlueprintEntity data = this.entityManager.find(DmpBlueprintEntity.class, id);
if (data == null)
throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{id, DmpBlueprint.class.getSimpleName()}, LocaleContextHolder.getLocale()));
throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{id, DmpBlueprint.class.getSimpleName()}, LocaleContextHolder.getLocale()));
DefinitionEntity dmpDefinition = this.xmlHandlingService.fromXml(DefinitionEntity.class, data.getDefinition());
String xml = this.xmlHandlingService.toXml(this.definitionXmlToExport(dmpDefinition));
return this.definitionXmlToExport(data);
}
@Override
public ResponseEntity<byte[]> exportXml(UUID id) throws MyForbiddenException, MyNotFoundException, JAXBException, ParserConfigurationException, IOException, InstantiationException, IllegalAccessException, SAXException, TransformerException, InvalidApplicationException {
logger.debug(new MapLogEntry("export xml").And("id", id));
DmpBlueprintEntity data = this.entityManager.find(DmpBlueprintEntity.class, id);
if (data == null)
throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{id, DmpBlueprint.class.getSimpleName()}, LocaleContextHolder.getLocale()));
String xml = this.xmlHandlingService.toXml(this.getExportXmlEntity(id));
return this.responseUtilsService.buildResponseFileFromText(xml, data.getLabel() + ".xml");
}
private BlueprintImportExport definitionXmlToExport(DmpBlueprintEntity entity) throws JAXBException, ParserConfigurationException, IOException, InstantiationException, IllegalAccessException, SAXException {
if (entity == null)
return null;
BlueprintImportExport xml = new BlueprintImportExport();
xml.setId(entity.getId());
xml.setLabel(entity.getLabel());
DefinitionEntity dmpDefinition = this.xmlHandlingService.fromXml(DefinitionEntity.class, entity.getDefinition());
xml.setDmpBlueprintDefinition(this.definitionXmlToExport(dmpDefinition));
return xml;
}
private DefinitionImportExport definitionXmlToExport(DefinitionEntity entity) {
if (entity == null)
return null;
@ -572,8 +597,18 @@ public class DmpBlueprintServiceImpl implements DmpBlueprintService {
persist.setStatus(DmpBlueprintStatus.Draft);
BlueprintImportExport dmpDefinition = this.xmlHandlingService.fromXml(BlueprintImportExport.class, new String(bytes, StandardCharsets.UTF_8));
if (dmpDefinition != null)
if (dmpDefinition != null) {
persist.setDefinition(this.xmlDefinitionToPersist(dmpDefinition.getDmpBlueprintDefinition()));
if (dmpDefinition.getId() != null) {
persist.setId(dmpDefinition.getId());
DmpBlueprintEntity data = this.entityManager.find(DmpBlueprintEntity.class, dmpDefinition.getId());
if (data == null) {
throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{dmpDefinition.getId(), DmpBlueprint.class.getSimpleName()}, LocaleContextHolder.getLocale()));
}
persist.setHash(this.conventionService.hashValue(data.getUpdatedAt()));
}
persist.setLabel(dmpDefinition.getLabel());
}
this.validatorFactory.validator(DmpBlueprintPersist.DmpBlueprintPersistValidator.class).validateForce(persist);
return this.persist(persist, fields);

View File

@ -121,7 +121,7 @@ public class FileTransformerServiceImpl implements FileTransformerService {
String tenantCode = this.tenantScope.isSet() && this.tenantScope.isMultitenant() ? this.tenantScope.getTenantCode() : "";
FileTransformerSourcesCacheService.FileTransformerSourceCacheValue cacheValue = this.fileTransformerSourcesCacheService.lookup(this.fileTransformerSourcesCacheService.buildKey(tenantCode));
if (cacheValue == null) {
List<FileTransformerSourceEntity> fileTransformerSourceEntities = new ArrayList<>(fileTransformerProperties.getSources());
List<FileTransformerSourceEntity> fileTransformerSourceEntities = new ArrayList<>(this.fileTransformerProperties.getSources());
if (this.tenantScope.isSet() && this.tenantScope.isMultitenant()) {
TenantConfigurationQuery tenantConfigurationQuery = this.queryFactory.query(TenantConfigurationQuery.class).isActive(IsActive.Active).types(TenantConfigurationType.FileTransformerPlugins);
if (this.tenantScope.isDefaultTenant()) tenantConfigurationQuery.tenantIsSet(false);
@ -165,7 +165,7 @@ public class FileTransformerServiceImpl implements FileTransformerService {
item.setUrl(source.getUrl());
item.setIssuerUrl(source.getIssuerUrl());
item.setClientId(source.getClientId());
if (!this.conventionService.isNullOrEmpty(source.getClientSecret())) item.setClientSecret(this.encryptionService.decryptAES(source.getClientSecret(), tenantProperties.getConfigEncryptionAesKey(), tenantProperties.getConfigEncryptionAesIv()));
if (!this.conventionService.isNullOrEmpty(source.getClientSecret())) item.setClientSecret(this.encryptionService.decryptAES(source.getClientSecret(), this.tenantProperties.getConfigEncryptionAesKey(), this.tenantProperties.getConfigEncryptionAesIv()));
item.setScope(source.getScope());
items.add(item);
}
@ -201,8 +201,8 @@ public class FileTransformerServiceImpl implements FileTransformerService {
FileTransformerConfigurationCacheService.FileTransformerConfigurationCacheValue cacheValue = this.fileTransformerConfigurationCacheService.lookup(this.fileTransformerConfigurationCacheService.buildKey(transformerSource.getTransformerId(), tenantCode));
if (cacheValue == null){
try {
FileTransformerRepository fileTransformerRepository = getRepository(transformerSource.getTransformerId());
if (fileTransformerRepository == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{transformerSource.getTransformerId(), FileTransformerRepository.class.getSimpleName()}, LocaleContextHolder.getLocale()));
FileTransformerRepository fileTransformerRepository = this.getRepository(transformerSource.getTransformerId());
if (fileTransformerRepository == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{transformerSource.getTransformerId(), FileTransformerRepository.class.getSimpleName()}, LocaleContextHolder.getLocale()));
FileTransformerConfiguration configuration = fileTransformerRepository.getConfiguration();
cacheValue = new FileTransformerConfigurationCacheService.FileTransformerConfigurationCacheValue(transformerSource.getTransformerId(), tenantCode, configuration);
@ -223,17 +223,17 @@ public class FileTransformerServiceImpl implements FileTransformerService {
public org.opencdmp.model.file.FileEnvelope exportDmp(UUID dmpId, String repositoryId, String format) throws InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, InvalidApplicationException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException {
this.authorizationService.authorize(Permission.EditDmp);
//GK: First get the right client
FileTransformerRepository repository = getRepository(repositoryId);
if (repository == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{format, FileTransformerRepository.class.getSimpleName()}, LocaleContextHolder.getLocale()));
FileTransformerRepository repository = this.getRepository(repositoryId);
if (repository == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{format, FileTransformerRepository.class.getSimpleName()}, LocaleContextHolder.getLocale()));
//GK: Second get the Target Data Management Plan
DmpQuery query = this.queryFactory.query(DmpQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).ids(dmpId);
DmpModel dmpFileTransformerModel = this.builderFactory.builder(DmpCommonModelBuilder.class).useSharedStorage(repository.getConfiguration().isUseSharedStorage()).setRepositoryId(repository.getConfiguration().getFileTransformerId()).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(query.first());
if (dmpFileTransformerModel == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{dmpId, Dmp.class.getSimpleName()}, LocaleContextHolder.getLocale()));
if (dmpFileTransformerModel == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{dmpId, Dmp.class.getSimpleName()}, LocaleContextHolder.getLocale()));
FileEnvelopeModel fileEnvelope = repository.exportDmp(dmpFileTransformerModel, format);
org.opencdmp.model.file.FileEnvelope result = new org.opencdmp.model.file.FileEnvelope();
byte[] data = repository.getConfiguration().isUseSharedStorage() ? storageFileService.readByFileRefAsBytesSafe(fileEnvelope.getFileRef(), StorageType.Transformer) : fileEnvelope.getFile();
byte[] data = repository.getConfiguration().isUseSharedStorage() ? this.storageFileService.readByFileRefAsBytesSafe(fileEnvelope.getFileRef(), StorageType.Transformer) : fileEnvelope.getFile();
result.setFile(data);
result.setFilename(fileEnvelope.getFilename());
return result;
@ -243,17 +243,17 @@ public class FileTransformerServiceImpl implements FileTransformerService {
public org.opencdmp.model.file.FileEnvelope exportDescription(UUID descriptionId, String repositoryId, String format) throws InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, InvalidApplicationException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException {
this.authorizationService.authorize(Permission.EditDmp);
//GK: First get the right client
FileTransformerRepository repository = getRepository(repositoryId);
if (repository == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{format, FileTransformerRepository.class.getSimpleName()}, LocaleContextHolder.getLocale()));
FileTransformerRepository repository = this.getRepository(repositoryId);
if (repository == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{format, FileTransformerRepository.class.getSimpleName()}, LocaleContextHolder.getLocale()));
//GK: Second get the Target Data Management Plan
DescriptionQuery query = this.queryFactory.query(DescriptionQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).ids(descriptionId);
DescriptionModel descriptionFileTransformerModel = this.builderFactory.builder(DescriptionCommonModelBuilder.class).setRepositoryId(repository.getConfiguration().getFileTransformerId()).useSharedStorage(repository.getConfiguration().isUseSharedStorage()).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(query.first());
if (descriptionFileTransformerModel == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{descriptionId, Description.class.getSimpleName()}, LocaleContextHolder.getLocale()));
if (descriptionFileTransformerModel == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{descriptionId, Description.class.getSimpleName()}, LocaleContextHolder.getLocale()));
FileEnvelopeModel fileEnvelope = repository.exportDescription(descriptionFileTransformerModel, format);
org.opencdmp.model.file.FileEnvelope result = new org.opencdmp.model.file.FileEnvelope();
byte[] data = repository.getConfiguration().isUseSharedStorage() ? storageFileService.readByFileRefAsBytesSafe(fileEnvelope.getFileRef(), StorageType.Transformer) : fileEnvelope.getFile(); //TODO: shared storage should be per repository
byte[] data = repository.getConfiguration().isUseSharedStorage() ? this.storageFileService.readByFileRefAsBytesSafe(fileEnvelope.getFileRef(), StorageType.Transformer) : fileEnvelope.getFile(); //TODO: shared storage should be per repository
result.setFile(data);
result.setFilename(fileEnvelope.getFilename());
return result;

View File

@ -173,10 +173,6 @@ export class DmpService {
return this.httpClient.get(`${this.apiBase}/${id}/export/${format}`, { responseType: 'blob', observe: 'response', headers: this.headers });
}
public downloadPDF(id: string): Observable<HttpResponse<Blob>> {
let headerPdf: HttpHeaders = this.headers.set('Content-Type', 'application/pdf')
return this.httpClient.get(`${this.apiBase}/${id}/export/Pdf`, { responseType: 'blob', observe: 'response', headers: headerPdf });
}
// public downloadJson(id: string): Observable<HttpResponse<Blob>> {
// return this.httpClient.get(this.actionUrl + 'rda/' + id, { responseType: 'blob', observe: 'response' });

View File

@ -9,6 +9,7 @@ import { FileUtils } from '../utilities/file-utils.service';
import { AuthService } from '../auth/auth.service';
import { RepositoryFileFormat } from '@app/core/model/file/file-format.model';
import { FileTransformerEntityType } from '@app/core/common/enum/file-transformer-entity-type';
import { DmpService } from '../dmp/dmp.service';
@Injectable()
export class FileTransformerService extends BaseService {
@ -17,12 +18,21 @@ export class FileTransformerService extends BaseService {
private fileTransformerHttpService: FileTransformerHttpService,
private matomoService: MatomoService,
private fileUtils: FileUtils,
private dmpService: DmpService,
private authentication: AuthService,
) { super(); }
private _initialized: boolean = false;
private _loading: boolean = false;
private xmlExportRepo: RepositoryFileFormat = {
entityTypes: [FileTransformerEntityType.Description, FileTransformerEntityType.Dmp],
format: "xml",
hasLogo: true,
icon: "fa-file-code-o",
repositoryId: "app_xml_export"
}
private _availableFormats: RepositoryFileFormat[] = [];
get availableFormats(): RepositoryFileFormat[] {
if (!this.authentication.currentAccountIsAuthenticated()){
@ -49,6 +59,7 @@ export class FileTransformerService extends BaseService {
return [];
})).subscribe(items => {
this._availableFormats = items;
this._availableFormats.push(this.xmlExportRepo)
this._loading = false;
this._initialized = true;
});
@ -56,18 +67,29 @@ export class FileTransformerService extends BaseService {
exportDmp(id: Guid, repositoryId: string, format: string) {
this._loading = true;
this.fileTransformerHttpService.exportDmp(id, repositoryId, format).pipe(takeUntil(this._destroyed), catchError((error) => {
this._loading = false;
return null;
})).subscribe(result => {
if (result !== null) {
const blob = new Blob([result.body], { type: 'application/octet-stream' });
const filename = this.fileUtils.getFilenameFromContentDispositionHeader(result.headers.get('Content-Disposition'));
if (repositoryId == this.xmlExportRepo.repositoryId) {
this.dmpService.downloadXML(id)
.pipe(takeUntil(this._destroyed))
.subscribe(response => {
const blob = new Blob([response.body], { type: 'application/xml' });
const filename = this.fileUtils.getFilenameFromContentDispositionHeader(response.headers.get('Content-Disposition'));
FileSaver.saveAs(blob, filename);
this.matomoService.trackDownload('dmps', format, id.toString());
}
});
});
} else {
this.fileTransformerHttpService.exportDmp(id, repositoryId, format).pipe(takeUntil(this._destroyed), catchError((error) => {
this._loading = false;
return null;
})).subscribe(result => {
if (result !== null) {
const blob = new Blob([result.body], { type: 'application/octet-stream' });
const filename = this.fileUtils.getFilenameFromContentDispositionHeader(result.headers.get('Content-Disposition'));
FileSaver.saveAs(blob, filename);
this.matomoService.trackDownload('dmps', format, id.toString());
}
});
}
}
exportDescription(id: Guid, repositoryId: string, format: string) {

View File

@ -434,18 +434,6 @@ export class DmpOverviewComponent extends BaseComponent implements OnInit {
});
}
downloadPDF(id: string) {
this.dmpService.downloadPDF(id)
.pipe(takeUntil(this._destroyed))
.subscribe(response => {
const blob = new Blob([response.body], { type: 'application/pdf' });
const filename = this.fileUtils.getFilenameFromContentDispositionHeader(response.headers.get('Content-Disposition'));
FileSaver.saveAs(blob, filename);
this.matomoService.trackDownload('dmps', "pdf", id);
});
}
downloadJson(id: string) {
//TODO: add this
// this.dmpService.downloadJson(id)