Description export

This commit is contained in:
Efstratios Giannopoulos 2024-04-29 17:08:24 +03:00
parent 30d338bbbd
commit 85b2258e19
36 changed files with 924 additions and 230 deletions

View File

@ -109,6 +109,7 @@ public final class Permission {
public static String FinalizeDescription = "FinalizeDescription";
public static String DeleteDescription = "DeleteDescription";
public static String CloneDescription = "CloneDescription";
public static String ExportDescription = "ExportDescription";
//DescriptionTag
public static String BrowseDescriptionTag = "BrowseDescriptionTag";

View File

@ -0,0 +1,32 @@
package org.opencdmp.commons.types.description.importexport;
import jakarta.xml.bind.annotation.XmlAccessType;
import jakarta.xml.bind.annotation.XmlAccessorType;
import jakarta.xml.bind.annotation.XmlElement;
@XmlAccessorType(XmlAccessType.FIELD)
public class DescriptionExternalIdentifierImportExport {
@XmlElement(name = "identifier")
private String identifier;
@XmlElement(name = "type")
private String type;
public String getIdentifier() {
return this.identifier;
}
public void setIdentifier(String identifier) {
this.identifier = identifier;
}
public String getType() {
return this.type;
}
public void setType(String type) {
this.type = type;
}
}

View File

@ -0,0 +1,66 @@
package org.opencdmp.commons.types.description.importexport;
import jakarta.xml.bind.annotation.XmlAccessType;
import jakarta.xml.bind.annotation.XmlAccessorType;
import jakarta.xml.bind.annotation.XmlElement;
import jakarta.xml.bind.annotation.XmlElementWrapper;
import java.time.Instant;
import java.util.List;
@XmlAccessorType(XmlAccessType.FIELD)
public class DescriptionFieldImportExport {
@XmlElement(name = "fieldId")
private String fieldId;
@XmlElement(name = "textValue")
private String textValue;
@XmlElementWrapper(name = "textListValues")
@XmlElement(name = "textListValue")
private List<String> textListValue;
@XmlElement(name = "dateValue")
private Instant dateValue;
@XmlElement(name = "externalIdentifier")
private DescriptionExternalIdentifierImportExport externalIdentifier;
public String getFieldId() {
return this.fieldId;
}
public void setFieldId(String fieldId) {
this.fieldId = fieldId;
}
public String getTextValue() {
return this.textValue;
}
public void setTextValue(String textValue) {
this.textValue = textValue;
}
public List<String> getTextListValue() {
return this.textListValue;
}
public void setTextListValue(List<String> textListValue) {
this.textListValue = textListValue;
}
public Instant getDateValue() {
return this.dateValue;
}
public void setDateValue(Instant dateValue) {
this.dateValue = dateValue;
}
public DescriptionExternalIdentifierImportExport getExternalIdentifier() {
return this.externalIdentifier;
}
public void setExternalIdentifier(DescriptionExternalIdentifierImportExport externalIdentifier) {
this.externalIdentifier = externalIdentifier;
}
}

View File

@ -0,0 +1,103 @@
package org.opencdmp.commons.types.description.importexport;
import jakarta.xml.bind.annotation.*;
import org.opencdmp.commons.types.descriptiontemplate.importexport.DescriptionTemplateImportExport;
import java.time.Instant;
import java.util.List;
import java.util.UUID;
@XmlRootElement(name = "description")
@XmlAccessorType(XmlAccessType.FIELD)
public class DescriptionImportExport {
@XmlElement(name = "id")
private UUID id;
@XmlElement(name = "description")
private String description;
@XmlElement(name = "label")
private String label;
@XmlElement(name = "finalizedAt")
private Instant finalizedAt;
@XmlElement(name = "sectionId")
private UUID sectionId;
@XmlElement(name = "descriptionTemplate")
private DescriptionTemplateImportExport descriptionTemplate;
@XmlElementWrapper(name = "references")
@XmlElement(name = "reference")
private List<DescriptionReferenceImportExport> references;
@XmlElement(name = "properties")
private DescriptionPropertyDefinitionImportExport properties;
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 getLabel() {
return this.label;
}
public void setLabel(String label) {
this.label = label;
}
public Instant getFinalizedAt() {
return this.finalizedAt;
}
public void setFinalizedAt(Instant finalizedAt) {
this.finalizedAt = finalizedAt;
}
public UUID getSectionId() {
return this.sectionId;
}
public void setSectionId(UUID sectionId) {
this.sectionId = sectionId;
}
public DescriptionTemplateImportExport getDescriptionTemplate() {
return this.descriptionTemplate;
}
public void setDescriptionTemplate(DescriptionTemplateImportExport descriptionTemplate) {
this.descriptionTemplate = descriptionTemplate;
}
public List<DescriptionReferenceImportExport> getReferences() {
return this.references;
}
public void setReferences(List<DescriptionReferenceImportExport> references) {
this.references = references;
}
public DescriptionPropertyDefinitionImportExport getProperties() {
return this.properties;
}
public void setProperties(DescriptionPropertyDefinitionImportExport properties) {
this.properties = properties;
}
}

View File

@ -0,0 +1,34 @@
package org.opencdmp.commons.types.description.importexport;
import jakarta.xml.bind.annotation.XmlAccessType;
import jakarta.xml.bind.annotation.XmlAccessorType;
import jakarta.xml.bind.annotation.XmlElement;
import jakarta.xml.bind.annotation.XmlElementWrapper;
import java.util.List;
@XmlAccessorType(XmlAccessType.FIELD)
public class DescriptionPropertyDefinitionFieldSetImportExport {
@XmlElement(name = "fieldSetId")
private String fieldSetId;
@XmlElementWrapper(name = "items")
@XmlElement(name = "item")
private List<DescriptionPropertyDefinitionFieldSetItemImportExport> items;
public List<DescriptionPropertyDefinitionFieldSetItemImportExport> getItems() {
return this.items;
}
public void setItems(List<DescriptionPropertyDefinitionFieldSetItemImportExport> items) {
this.items = items;
}
public String getFieldSetId() {
return this.fieldSetId;
}
public void setFieldSetId(String fieldSetId) {
this.fieldSetId = fieldSetId;
}
}

View File

@ -0,0 +1,45 @@
package org.opencdmp.commons.types.description.importexport;
import jakarta.xml.bind.annotation.XmlAccessType;
import jakarta.xml.bind.annotation.XmlAccessorType;
import jakarta.xml.bind.annotation.XmlElement;
import jakarta.xml.bind.annotation.XmlElementWrapper;
import java.util.List;
@XmlAccessorType(XmlAccessType.FIELD)
public class DescriptionPropertyDefinitionFieldSetItemImportExport {
@XmlElementWrapper(name = "fields")
@XmlElement(name = "field")
private List<DescriptionFieldImportExport> fields;
@XmlElement(name = "comment")
private String comment;
@XmlElement(name = "ordinal")
private int ordinal;
public List<DescriptionFieldImportExport> getFields() {
return this.fields;
}
public void setFields(List<DescriptionFieldImportExport> fields) {
this.fields = fields;
}
public String getComment() {
return this.comment;
}
public void setComment(String comment) {
this.comment = comment;
}
public int getOrdinal() {
return this.ordinal;
}
public void setOrdinal(int ordinal) {
this.ordinal = ordinal;
}
}

View File

@ -0,0 +1,27 @@
package org.opencdmp.commons.types.description.importexport;
import jakarta.xml.bind.annotation.XmlAccessType;
import jakarta.xml.bind.annotation.XmlAccessorType;
import jakarta.xml.bind.annotation.XmlElement;
import jakarta.xml.bind.annotation.XmlElementWrapper;
import java.util.List;
@XmlAccessorType(XmlAccessType.FIELD)
public class DescriptionPropertyDefinitionImportExport {
@XmlElementWrapper(name = "fieldSets")
@XmlElement(name = "fieldSet")
private List<DescriptionPropertyDefinitionFieldSetImportExport> fieldSets;
public List<DescriptionPropertyDefinitionFieldSetImportExport> getFieldSets() {
return this.fieldSets;
}
public void setFieldSets(List<DescriptionPropertyDefinitionFieldSetImportExport> fieldSets) {
this.fieldSets = fieldSets;
}
}

View File

@ -0,0 +1,62 @@
package org.opencdmp.commons.types.description.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 DescriptionReferenceImportExport {
@XmlElement(name = "id")
private UUID id;
@XmlElement(name = "label")
private String label;
@XmlElement(name = "reference")
private String reference;
@XmlElement(name = "fieldId")
private String fieldId;
@XmlElement(name = "type")
private DescriptionReferenceTypeImportExport 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 DescriptionReferenceTypeImportExport getType() {
return this.type;
}
public void setType(DescriptionReferenceTypeImportExport type) {
this.type = type;
}
public String getFieldId() {
return this.fieldId;
}
public void setFieldId(String fieldId) {
this.fieldId = fieldId;
}
}

View File

@ -0,0 +1,43 @@
package org.opencdmp.commons.types.description.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 DescriptionReferenceTypeImportExport {
@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

@ -5,7 +5,7 @@ import jakarta.xml.bind.annotation.XmlAccessorType;
import jakarta.xml.bind.annotation.XmlAttribute;
@XmlAccessorType(XmlAccessType.FIELD)
public class ExternalIdentifierImportExport {
public class DescriptionTemplateExternalIdentifierImportExport {
@XmlAttribute(name="identifier")
private String identifier;

View File

@ -8,7 +8,7 @@ import jakarta.xml.bind.annotation.*;
import java.util.List;
@XmlAccessorType(XmlAccessType.FIELD)
public class FieldImportExport {
public class DescriptionTemplateFieldImportExport {
@XmlAttribute(name = "id")
private String id;
@ -28,7 +28,7 @@ public class FieldImportExport {
@XmlElementWrapper(name = "visibilityRules")
@XmlElement(name = "visibilityRule")
private List<RuleImportExport> visibilityRules;
private List<DescriptionTemplateRuleImportExport> visibilityRules;
@XmlElement(name = "fieldType")
private FieldType fieldType;
@ -111,11 +111,11 @@ public class FieldImportExport {
this.schematics = schematics;
}
public List<RuleImportExport> getVisibilityRules() {
public List<DescriptionTemplateRuleImportExport> getVisibilityRules() {
return visibilityRules;
}
public void setVisibilityRules(List<RuleImportExport> visibilityRules) {
public void setVisibilityRules(List<DescriptionTemplateRuleImportExport> visibilityRules) {
this.visibilityRules = visibilityRules;
}

View File

@ -5,7 +5,7 @@ import jakarta.xml.bind.annotation.*;
import java.util.List;
@XmlAccessorType(XmlAccessType.FIELD)
public class FieldSetImportExport {
public class DescriptionTemplateFieldSetImportExport {
@XmlAttribute(name="id")
private String id;
@ -14,7 +14,7 @@ public class FieldSetImportExport {
@XmlElementWrapper(name = "fields")
@XmlElement(name = "field")
private List<FieldImportExport> fields;
private List<DescriptionTemplateFieldImportExport> fields;
@XmlAttribute(name="numbering")
private String numbering;
@XmlAttribute(name="title")
@ -26,7 +26,7 @@ public class FieldSetImportExport {
@XmlAttribute(name="additionalInformation")
private String additionalInformation;
@XmlElement(name="multiplicity")
private MultiplicityImportExport multiplicity;
private DescriptionTemplateMultiplicityImportExport multiplicity;
@XmlAttribute(name="hasMultiplicity")
private boolean hasMultiplicity;
@ -49,11 +49,11 @@ public class FieldSetImportExport {
this.ordinal = ordinal;
}
public List<FieldImportExport> getFields() {
public List<DescriptionTemplateFieldImportExport> getFields() {
return fields;
}
public void setFields(List<FieldImportExport> fields) {
public void setFields(List<DescriptionTemplateFieldImportExport> fields) {
this.fields = fields;
}
@ -72,11 +72,11 @@ public class FieldSetImportExport {
this.hasCommentField = hasCommentField;
}
public MultiplicityImportExport getMultiplicity() {
public DescriptionTemplateMultiplicityImportExport getMultiplicity() {
return multiplicity;
}
public void setMultiplicity(MultiplicityImportExport multiplicity) {
public void setMultiplicity(DescriptionTemplateMultiplicityImportExport multiplicity) {
this.multiplicity = multiplicity;
}

View File

@ -1,23 +1,17 @@
package org.opencdmp.commons.types.descriptiontemplate.importexport;
import org.opencdmp.commons.enums.DescriptionTemplateStatus;
import org.opencdmp.model.persist.DescriptionTemplatePersist;
import org.opencdmp.model.persist.NewVersionDescriptionTemplatePersist;
import org.opencdmp.model.persist.descriptiontemplatedefinition.DefinitionPersist;
import org.opencdmp.model.persist.descriptiontemplatedefinition.PagePersist;
import org.opencdmp.model.persist.descriptiontemplatedefinition.SectionPersist;
import org.opencdmp.service.fielddatahelper.FieldDataHelperServiceProvider;
import jakarta.xml.bind.annotation.*;
import java.util.LinkedList;
import java.util.List;
import java.util.UUID;
@XmlRootElement(name = "root")
@XmlRootElement(name = "descriptionTemplate")
@XmlAccessorType(XmlAccessType.FIELD)
public class DescriptionTemplateImportExport {
@XmlElement(name = "id")
private UUID id;
@XmlAttribute(name = "description")
private String description;
@XmlAttribute(name = "language")
@ -26,20 +20,27 @@ public class DescriptionTemplateImportExport {
private UUID type;
@XmlElementWrapper(name = "pages")
@XmlElement(name = "page")
private List<PageImportExport> pages;
private List<DescriptionTemplatePageImportExport> pages;
public List<PageImportExport> getPages() {
return pages;
public UUID getId() {
return this.id;
}
public void setPages(List<PageImportExport> pages) {
public void setId(UUID id) {
this.id = id;
}
public List<DescriptionTemplatePageImportExport> getPages() {
return this.pages;
}
public void setPages(List<DescriptionTemplatePageImportExport> pages) {
this.pages = pages;
}
public String getDescription() {
return description;
return this.description;
}
public void setDescription(String description) {
@ -48,7 +49,7 @@ public class DescriptionTemplateImportExport {
public String getLanguage() {
return language;
return this.language;
}
public void setLanguage(String language) {
@ -57,7 +58,7 @@ public class DescriptionTemplateImportExport {
public UUID getType() {
return type;
return this.type;
}
public void setType(UUID type) {

View File

@ -6,7 +6,7 @@ import jakarta.xml.bind.annotation.XmlAttribute;
@XmlAccessorType(XmlAccessType.FIELD)
public class MultiplicityImportExport {
public class DescriptionTemplateMultiplicityImportExport {
@XmlAttribute(name="min")
private int min;
@XmlAttribute(name="max")

View File

@ -1,14 +1,11 @@
package org.opencdmp.commons.types.descriptiontemplate.importexport;
import org.opencdmp.model.persist.descriptiontemplatedefinition.PagePersist;
import org.opencdmp.model.persist.descriptiontemplatedefinition.SectionPersist;
import org.opencdmp.service.fielddatahelper.FieldDataHelperServiceProvider;
import jakarta.xml.bind.annotation.*;
import java.util.List;
@XmlAccessorType(XmlAccessType.FIELD)
public class PageImportExport {
public class DescriptionTemplatePageImportExport {
@XmlAttribute(name = "id")
private String id;
@XmlAttribute(name = "ordinal")
@ -18,7 +15,7 @@ public class PageImportExport {
private String title;
@XmlElementWrapper(name = "sections")
@XmlElement(name = "section")
private List<SectionImportExport> sections;
private List<DescriptionTemplateSectionImportExport> sections;
public String getId() {
@ -44,11 +41,11 @@ public class PageImportExport {
this.title = title;
}
public List<SectionImportExport> getSections() {
public List<DescriptionTemplateSectionImportExport> getSections() {
return sections;
}
public void setSections(List<SectionImportExport> sections) {
public void setSections(List<DescriptionTemplateSectionImportExport> sections) {
this.sections = sections;
}

View File

@ -6,7 +6,7 @@ import java.time.Instant;
import java.util.List;
@XmlAccessorType(XmlAccessType.FIELD)
public class RuleImportExport {
public class DescriptionTemplateRuleImportExport {
@XmlAttribute(name="target")
private String target;
@ -20,7 +20,7 @@ public class RuleImportExport {
private Instant dateValue;
@XmlElement(name="externalIdentifier")
private ExternalIdentifierImportExport externalIdentifier;
private DescriptionTemplateExternalIdentifierImportExport externalIdentifier;
public String getTarget() {
return target;
@ -54,11 +54,11 @@ public class RuleImportExport {
this.dateValue = dateValue;
}
public ExternalIdentifierImportExport getExternalIdentifier() {
public DescriptionTemplateExternalIdentifierImportExport getExternalIdentifier() {
return externalIdentifier;
}
public void setExternalIdentifier(ExternalIdentifierImportExport externalIdentifier) {
public void setExternalIdentifier(DescriptionTemplateExternalIdentifierImportExport externalIdentifier) {
this.externalIdentifier = externalIdentifier;
}
}

View File

@ -5,7 +5,7 @@ import jakarta.xml.bind.annotation.*;
import java.util.List;
@XmlAccessorType(XmlAccessType.FIELD)
public class SectionImportExport {
public class DescriptionTemplateSectionImportExport {
@XmlAttribute(name = "id")
private String id;
@XmlAttribute(name = "ordinal")
@ -14,7 +14,7 @@ public class SectionImportExport {
private Boolean defaultVisibility;
@XmlElementWrapper(name = "fieldSets")
@XmlElement(name = "fieldSet")
private List<FieldSetImportExport> fieldSets;
private List<DescriptionTemplateFieldSetImportExport> fieldSets;
@XmlElement(name = "numbering")
private String numbering;
@XmlElement(name = "description")
@ -23,7 +23,7 @@ public class SectionImportExport {
private String title;
@XmlElementWrapper(name = "sections")
@XmlElement(name = "section")
private List<SectionImportExport> sections;
private List<DescriptionTemplateSectionImportExport> sections;
@XmlAttribute(name = "multiplicity")
private Boolean multiplicity;
@ -51,11 +51,11 @@ public class SectionImportExport {
this.defaultVisibility = defaultVisibility;
}
public List<FieldSetImportExport> getFieldSets() {
public List<DescriptionTemplateFieldSetImportExport> getFieldSets() {
return fieldSets;
}
public void setFieldSets(List<FieldSetImportExport> fieldSets) {
public void setFieldSets(List<DescriptionTemplateFieldSetImportExport> fieldSets) {
this.fieldSets = fieldSets;
}
@ -83,11 +83,11 @@ public class SectionImportExport {
this.title = title;
}
public List<SectionImportExport> getSections() {
public List<DescriptionTemplateSectionImportExport> getSections() {
return sections;
}
public void setSections(List<SectionImportExport> sections) {
public void setSections(List<DescriptionTemplateSectionImportExport> sections) {
this.sections = sections;
}

View File

@ -2,6 +2,7 @@ package org.opencdmp.commons.types.dmp.importexport;
import jakarta.xml.bind.annotation.*;
import org.opencdmp.commons.enums.DmpAccessType;
import org.opencdmp.commons.types.description.importexport.DescriptionImportExport;
import org.opencdmp.commons.types.dmpblueprint.importexport.BlueprintImportExport;
import java.time.Instant;
@ -56,6 +57,10 @@ public class DmpImportExport {
@XmlElement(name = "reference")
private List<DmpReferenceImportExport> references;
@XmlElementWrapper(name = "descriptions")
@XmlElement(name = "description")
private List<DescriptionImportExport> descriptions;
public UUID getId() {
return this.id;
}
@ -160,5 +165,13 @@ public class DmpImportExport {
public void setReferences(List<DmpReferenceImportExport> references) {
this.references = references;
}
public List<DescriptionImportExport> getDescriptions() {
return this.descriptions;
}
public void setDescriptions(List<DescriptionImportExport> descriptions) {
this.descriptions = descriptions;
}
}

View File

@ -6,17 +6,17 @@ import java.util.List;
@XmlRootElement(name = "root")
@XmlAccessorType(XmlAccessType.FIELD)
public class DefinitionImportExport {
public class BlueprintDefinitionImportExport {
@XmlElementWrapper(name = "sections")
@XmlElement(name = "section")
private List<SectionImportExport> sections;
private List<BlueprintSectionImportExport> sections;
public List<SectionImportExport> getSections() {
public List<BlueprintSectionImportExport> getSections() {
return sections;
}
public void setSections(List<SectionImportExport> sections) {
public void setSections(List<BlueprintSectionImportExport> sections) {
this.sections = sections;
}
}

View File

@ -7,8 +7,7 @@ import jakarta.xml.bind.annotation.XmlAttribute;
import java.util.UUID;
@XmlAccessorType(XmlAccessType.FIELD)
public class DescriptionTemplateImportExport {
public class BlueprintDescriptionTemplateImportExport {
@XmlAttribute(name = "descriptionTemplateGroupId")
private UUID descriptionTemplateGroupId;
@XmlAttribute(name = "label")
@ -19,7 +18,7 @@ public class DescriptionTemplateImportExport {
private int maxMultiplicity;
public UUID getDescriptionTemplateGroupId() {
return descriptionTemplateGroupId;
return this.descriptionTemplateGroupId;
}
public void setDescriptionTemplateGroupId(UUID descriptionTemplateGroupId) {
@ -27,7 +26,7 @@ public class DescriptionTemplateImportExport {
}
public String getLabel() {
return label;
return this.label;
}
public void setLabel(String label) {
@ -35,7 +34,7 @@ public class DescriptionTemplateImportExport {
}
public int getMinMultiplicity() {
return minMultiplicity;
return this.minMultiplicity;
}
public void setMinMultiplicity(int minMultiplicity) {
@ -43,12 +42,10 @@ public class DescriptionTemplateImportExport {
}
public int getMaxMultiplicity() {
return maxMultiplicity;
return this.maxMultiplicity;
}
public void setMaxMultiplicity(int maxMultiplicity) {
this.maxMultiplicity = maxMultiplicity;
}
}

View File

@ -1,7 +1,6 @@
package org.opencdmp.commons.types.dmpblueprint.importexport;
import org.opencdmp.commons.enums.DmpBlueprintExtraFieldDataType;
import org.opencdmp.commons.enums.DmpBlueprintSystemFieldType;
import jakarta.xml.bind.annotation.XmlAccessType;
import jakarta.xml.bind.annotation.XmlAccessorType;
import jakarta.xml.bind.annotation.XmlAttribute;
@ -9,7 +8,7 @@ import jakarta.xml.bind.annotation.XmlAttribute;
import java.util.UUID;
@XmlAccessorType(XmlAccessType.FIELD)
public class ExtraFieldImportExport {
public class BlueprintExtraFieldImportExport {
@XmlAttribute(name = "id")
private UUID id;

View File

@ -1,12 +1,9 @@
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;
@ -21,7 +18,7 @@ public class BlueprintImportExport {
private String label;
@XmlElement(name = "definition")
private DefinitionImportExport dmpBlueprintDefinition;
private BlueprintDefinitionImportExport dmpBlueprintDefinition;
public UUID getId() {
return this.id;
@ -39,11 +36,11 @@ public class BlueprintImportExport {
this.label = label;
}
public DefinitionImportExport getDmpBlueprintDefinition() {
public BlueprintDefinitionImportExport getDmpBlueprintDefinition() {
return this.dmpBlueprintDefinition;
}
public void setDmpBlueprintDefinition(DefinitionImportExport dmpBlueprintDefinition) {
public void setDmpBlueprintDefinition(BlueprintDefinitionImportExport dmpBlueprintDefinition) {
this.dmpBlueprintDefinition = dmpBlueprintDefinition;
}
}

View File

@ -7,7 +7,7 @@ import jakarta.xml.bind.annotation.XmlAttribute;
import java.util.UUID;
@XmlAccessorType(XmlAccessType.FIELD)
public class ReferenceTypeFieldImportExport {
public class BlueprintReferenceTypeFieldImportExport {
@XmlAttribute(name = "id")
private UUID id;

View File

@ -6,7 +6,7 @@ import java.util.List;
import java.util.UUID;
@XmlAccessorType(XmlAccessType.FIELD)
public class SectionImportExport {
public class BlueprintSectionImportExport {
@XmlAttribute(name = "id")
private UUID id;
@ -18,18 +18,18 @@ public class SectionImportExport {
private int ordinal;
@XmlElementWrapper(name = "systemFields")
@XmlElement(name = "systemField")
private List<SystemFieldImportExport> systemFields;
private List<BlueprintSystemFieldImportExport> systemFields;
@XmlElementWrapper(name = "extraFields")
@XmlElement(name = "extraField")
private List<ExtraFieldImportExport> extraFields;
private List<BlueprintExtraFieldImportExport> extraFields;
@XmlElementWrapper(name = "referenceFields")
@XmlElement(name = "referenceField")
private List<ReferenceTypeFieldImportExport> referenceFields;
private List<BlueprintReferenceTypeFieldImportExport> referenceFields;
@XmlAttribute(name = "hasTemplates")
private boolean hasTemplates;
@XmlElementWrapper(name = "descriptionTemplates")
@XmlElement(name = "descriptionTemplate")
private List<DescriptionTemplateImportExport> descriptionTemplates;
private List<BlueprintDescriptionTemplateImportExport> descriptionTemplates;
public UUID getId() {
return id;
@ -63,27 +63,27 @@ public class SectionImportExport {
this.ordinal = ordinal;
}
public List<SystemFieldImportExport> getSystemFields() {
public List<BlueprintSystemFieldImportExport> getSystemFields() {
return systemFields;
}
public void setSystemFields(List<SystemFieldImportExport> systemFields) {
public void setSystemFields(List<BlueprintSystemFieldImportExport> systemFields) {
this.systemFields = systemFields;
}
public List<ExtraFieldImportExport> getExtraFields() {
public List<BlueprintExtraFieldImportExport> getExtraFields() {
return extraFields;
}
public void setExtraFields(List<ExtraFieldImportExport> extraFields) {
public void setExtraFields(List<BlueprintExtraFieldImportExport> extraFields) {
this.extraFields = extraFields;
}
public List<ReferenceTypeFieldImportExport> getReferenceFields() {
public List<BlueprintReferenceTypeFieldImportExport> getReferenceFields() {
return referenceFields;
}
public void setReferenceFields(List<ReferenceTypeFieldImportExport> referenceFields) {
public void setReferenceFields(List<BlueprintReferenceTypeFieldImportExport> referenceFields) {
this.referenceFields = referenceFields;
}
@ -95,11 +95,11 @@ public class SectionImportExport {
this.hasTemplates = hasTemplates;
}
public List<DescriptionTemplateImportExport> getDescriptionTemplates() {
public List<BlueprintDescriptionTemplateImportExport> getDescriptionTemplates() {
return descriptionTemplates;
}
public void setDescriptionTemplates(List<DescriptionTemplateImportExport> descriptionTemplates) {
public void setDescriptionTemplates(List<BlueprintDescriptionTemplateImportExport> descriptionTemplates) {
this.descriptionTemplates = descriptionTemplates;
}

View File

@ -8,7 +8,7 @@ import jakarta.xml.bind.annotation.XmlAttribute;
import java.util.UUID;
@XmlAccessorType(XmlAccessType.FIELD)
public class SystemFieldImportExport {
public class BlueprintSystemFieldImportExport {
@XmlAttribute(name = "id")
private UUID id;

View File

@ -1,5 +1,6 @@
package org.opencdmp.service.description;
import org.opencdmp.commons.types.description.importexport.DescriptionImportExport;
import org.opencdmp.data.StorageFileEntity;
import org.opencdmp.model.Description;
import org.opencdmp.model.DescriptionValidationResult;
@ -14,11 +15,13 @@ import jakarta.xml.bind.JAXBException;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.multipart.MultipartFile;
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;
@ -45,4 +48,8 @@ public interface DescriptionService {
StorageFile uploadFieldFile(DescriptionFieldFilePersist model, MultipartFile file, FieldSet fields) throws IOException;
StorageFileEntity getFieldFile(UUID descriptionId, UUID storageFileId);
void updateDescriptionTemplate(UpdateDescriptionTemplatePersist model) throws InvalidApplicationException, IOException, JAXBException;
DescriptionImportExport 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

@ -10,10 +10,14 @@ import org.opencdmp.commons.enums.*;
import org.opencdmp.commons.scope.tenant.TenantScope;
import org.opencdmp.commons.scope.user.UserScope;
import org.opencdmp.commons.types.description.*;
import org.opencdmp.commons.types.description.importexport.*;
import org.opencdmp.commons.types.descriptionreference.DescriptionReferenceDataEntity;
import org.opencdmp.commons.types.descriptiontemplate.FieldSetEntity;
import org.opencdmp.commons.types.descriptiontemplate.fielddata.ReferenceTypeDataEntity;
import org.opencdmp.commons.types.descriptiontemplate.fielddata.UploadDataEntity;
import org.opencdmp.commons.types.dmp.DmpBlueprintValueEntity;
import org.opencdmp.commons.types.dmp.DmpContactEntity;
import org.opencdmp.commons.types.dmp.importexport.*;
import org.opencdmp.commons.types.notification.*;
import org.opencdmp.commons.types.reference.DefinitionEntity;
import org.opencdmp.commons.notification.NotificationProperties;
@ -37,7 +41,9 @@ import org.opencdmp.model.persist.descriptionproperties.*;
import org.opencdmp.model.persist.descriptionreference.DescriptionReferenceDataPersist;
import org.opencdmp.model.persist.referencedefinition.DefinitionPersist;
import org.opencdmp.query.*;
import org.opencdmp.service.descriptiontemplate.DescriptionTemplateService;
import org.opencdmp.service.elastic.ElasticService;
import org.opencdmp.service.responseutils.ResponseUtilsService;
import org.opencdmp.service.storage.StorageFileProperties;
import org.opencdmp.service.storage.StorageFileService;
import org.opencdmp.service.filetransformer.FileTransformerService;
@ -66,11 +72,13 @@ import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.util.unit.DataSize;
import org.springframework.web.multipart.MultipartFile;
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.net.URLConnection;
import java.security.InvalidAlgorithmParameterException;
@ -108,6 +116,8 @@ public class DescriptionServiceImpl implements DescriptionService {
private final AnnotationEntityTouchedIntegrationEventHandler annotationEntityTouchedIntegrationEventHandler;
private final AnnotationEntityRemovalIntegrationEventHandler annotationEntityRemovalIntegrationEventHandler;
private final TenantScope tenantScope;
private final ResponseUtilsService responseUtilsService;
private final DescriptionTemplateService descriptionTemplateService;
@Autowired
public DescriptionServiceImpl(
@ -122,7 +132,7 @@ public class DescriptionServiceImpl implements DescriptionService {
QueryFactory queryFactory,
JsonHandlingService jsonHandlingService,
UserScope userScope,
XmlHandlingService xmlHandlingService, NotifyIntegrationEventHandler eventHandler, NotificationProperties notificationProperties, FileTransformerService fileTransformerService, ElasticService elasticService, ValidatorFactory validatorFactory, StorageFileProperties storageFileConfig, StorageFileService storageFileService, AuthorizationContentResolver authorizationContentResolver, AnnotationEntityTouchedIntegrationEventHandler annotationEntityTouchedIntegrationEventHandler, AnnotationEntityRemovalIntegrationEventHandler annotationEntityRemovalIntegrationEventHandler, TenantScope tenantScope) {
XmlHandlingService xmlHandlingService, NotifyIntegrationEventHandler eventHandler, NotificationProperties notificationProperties, FileTransformerService fileTransformerService, ElasticService elasticService, ValidatorFactory validatorFactory, StorageFileProperties storageFileConfig, StorageFileService storageFileService, AuthorizationContentResolver authorizationContentResolver, AnnotationEntityTouchedIntegrationEventHandler annotationEntityTouchedIntegrationEventHandler, AnnotationEntityRemovalIntegrationEventHandler annotationEntityRemovalIntegrationEventHandler, TenantScope tenantScope, ResponseUtilsService responseUtilsService, DescriptionTemplateService descriptionTemplateService) {
this.entityManager = entityManager;
this.authorizationService = authorizationService;
this.deleterFactory = deleterFactory;
@ -146,6 +156,8 @@ public class DescriptionServiceImpl implements DescriptionService {
this.annotationEntityTouchedIntegrationEventHandler = annotationEntityTouchedIntegrationEventHandler;
this.annotationEntityRemovalIntegrationEventHandler = annotationEntityRemovalIntegrationEventHandler;
this.tenantScope = tenantScope;
this.responseUtilsService = responseUtilsService;
this.descriptionTemplateService = descriptionTemplateService;
}
@Override
@ -175,7 +187,7 @@ public class DescriptionServiceImpl implements DescriptionService {
Boolean isUpdate = this.conventionService.isValidGuid(model.getId());
DmpDescriptionTemplateEntity dmpDescriptionTemplate = this.entityManager.find(DmpDescriptionTemplateEntity.class, model.getDmpDescriptionTemplateId());
if (dmpDescriptionTemplate == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{model.getDmpDescriptionTemplateId(), DmpDescriptionTemplate.class.getSimpleName()}, LocaleContextHolder.getLocale()));
if (dmpDescriptionTemplate == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{model.getDmpDescriptionTemplateId(), DmpDescriptionTemplate.class.getSimpleName()}, LocaleContextHolder.getLocale()));
if (isUpdate) this.authorizationService.authorizeAtLeastOneForce(List.of(this.authorizationContentResolver.descriptionAffiliation(model.getId())), Permission.EditDescription);
else this.authorizationService.authorizeAtLeastOneForce(List.of(this.authorizationContentResolver.descriptionsAffiliationBySection(model.getDmpId(), dmpDescriptionTemplate.getSectionId())), Permission.EditDescription);
@ -183,7 +195,7 @@ public class DescriptionServiceImpl implements DescriptionService {
DescriptionEntity data;
if (isUpdate) {
data = this.entityManager.find(DescriptionEntity.class, model.getId());
if (data == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{model.getId(), Description.class.getSimpleName()}, LocaleContextHolder.getLocale()));
if (data == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{model.getId(), Description.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(DescriptionStatus.Finalized)) throw new MyValidationException(this.errors.getDescriptionIsFinalized().getCode(), this.errors.getDescriptionIsFinalized().getMessage());
if (!data.getDmpId().equals(model.getDmpId())) throw new MyValidationException(this.errors.getDmpCanNotChange().getCode(), this.errors.getDmpCanNotChange().getMessage());
@ -199,12 +211,12 @@ public class DescriptionServiceImpl implements DescriptionService {
}
DescriptionTemplateEntity descriptionTemplateEntity = this.entityManager.find(DescriptionTemplateEntity.class, model.getDescriptionTemplateId());
if (descriptionTemplateEntity == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{model.getDescriptionTemplateId(), DescriptionTemplate.class.getSimpleName()}, LocaleContextHolder.getLocale()));
if (descriptionTemplateEntity == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{model.getDescriptionTemplateId(), DescriptionTemplate.class.getSimpleName()}, LocaleContextHolder.getLocale()));
if (!dmpDescriptionTemplate.getDescriptionTemplateGroupId().equals(descriptionTemplateEntity.getGroupId())) throw new MyValidationException(this.errors.getInvalidDescriptionTemplate().getCode(), this.errors.getInvalidDescriptionTemplate().getMessage());
DmpEntity dmp = this.entityManager.find(DmpEntity.class, data.getDmpId());
if (dmp == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{data.getDmpId(), Dmp.class.getSimpleName()}, LocaleContextHolder.getLocale()));
if (dmp == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{data.getDmpId(), Dmp.class.getSimpleName()}, LocaleContextHolder.getLocale()));
if (dmp.getStatus().equals(DmpStatus.Finalized) && isUpdate) throw new MyValidationException(this.errors.getDmpIsFinalized().getCode(), this.errors.getDmpIsFinalized().getMessage());
@ -251,14 +263,14 @@ public class DescriptionServiceImpl implements DescriptionService {
this.authorizationService.authorizeAtLeastOneForce(List.of(this.authorizationContentResolver.descriptionAffiliation(model.getId())), Permission.EditDescription);
DescriptionEntity data = this.entityManager.find(DescriptionEntity.class, model.getId());
if (data == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{model.getId(), Description.class.getSimpleName()}, LocaleContextHolder.getLocale()));
if (data == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{model.getId(), Description.class.getSimpleName()}, LocaleContextHolder.getLocale()));
if (!this.conventionService.hashValue(data.getUpdatedAt()).equals(model.getHash())) throw new MyValidationException(this.errors.getHashConflict().getCode(), this.errors.getHashConflict().getMessage());
DescriptionTemplateEntity oldDescriptionTemplateEntity = this.entityManager.find(DescriptionTemplateEntity.class, data.getDescriptionTemplateId());
if (oldDescriptionTemplateEntity == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{data.getDescriptionTemplateId(), DescriptionTemplate.class.getSimpleName()}, LocaleContextHolder.getLocale()));
if (oldDescriptionTemplateEntity == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{data.getDescriptionTemplateId(), DescriptionTemplate.class.getSimpleName()}, LocaleContextHolder.getLocale()));
DmpDescriptionTemplateEntity dmpDescriptionTemplateEntity = this.entityManager.find(DmpDescriptionTemplateEntity.class, data.getDmpDescriptionTemplateId());
if (dmpDescriptionTemplateEntity == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{data.getDmpDescriptionTemplateId(), DmpDescriptionTemplate.class.getSimpleName()}, LocaleContextHolder.getLocale()));
if (dmpDescriptionTemplateEntity == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{data.getDmpDescriptionTemplateId(), DmpDescriptionTemplate.class.getSimpleName()}, LocaleContextHolder.getLocale()));
List<DescriptionTemplateEntity> latestVersionDescriptionTemplates = this.queryFactory.query(DescriptionTemplateQuery.class)
@ -367,9 +379,9 @@ public class DescriptionServiceImpl implements DescriptionService {
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));
event = this.applyNotificationType(description.getStatus(), event);
this.applyNotificationType(description.getStatus(), event);
NotificationFieldData data = new NotificationFieldData();
List<FieldInfo> fieldInfoList = new ArrayList<>();
fieldInfoList.add(new FieldInfo("{recipient}", DataType.String, user.getName()));
@ -377,18 +389,18 @@ public class DescriptionServiceImpl implements DescriptionService {
fieldInfoList.add(new FieldInfo("{name}", DataType.String, description.getLabel()));
fieldInfoList.add(new FieldInfo("{id}", DataType.String, description.getId().toString()));
data.setFields(fieldInfoList);
event.setData(jsonHandlingService.toJsonSafe(data));
event.setData(this.jsonHandlingService.toJsonSafe(data));
eventHandler.handle(event);
this.eventHandler.handle(event);
}
private NotifyIntegrationEvent applyNotificationType(DescriptionStatus status, NotifyIntegrationEvent event) {
switch (status) {
case Draft:
event.setNotificationType(notificationProperties.getDescriptionModifiedType());
event.setNotificationType(this.notificationProperties.getDescriptionModifiedType());
break;
case Finalized:
event.setNotificationType(notificationProperties.getDescriptionFinalisedType());
event.setNotificationType(this.notificationProperties.getDescriptionFinalisedType());
break;
default:
throw new MyApplicationException("Unsupported Description Status.");
@ -403,13 +415,13 @@ public class DescriptionServiceImpl implements DescriptionService {
this.authorizationService.authorizeAtLeastOneForce(List.of(this.authorizationContentResolver.descriptionAffiliation(model.getId())), Permission.EditDescription);
DescriptionEntity data = this.entityManager.find(DescriptionEntity.class, model.getId());
if (data == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{model.getId(), Description.class.getSimpleName()}, LocaleContextHolder.getLocale()));
if (data == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{model.getId(), Description.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(model.getStatus())){
if (data.getStatus().equals(DescriptionStatus.Finalized)){
this.authorizationService.authorizeAtLeastOneForce(List.of(this.authorizationContentResolver.descriptionAffiliation(model.getId())), Permission.FinalizeDescription);
DmpEntity dmpEntity = this.entityManager.find(DmpEntity.class, data.getDmpId());
if (dmpEntity == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{data.getDmpId(), DmpEntity.class.getSimpleName()}, LocaleContextHolder.getLocale()));
if (dmpEntity == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{data.getDmpId(), DmpEntity.class.getSimpleName()}, LocaleContextHolder.getLocale()));
if(!dmpEntity.getStatus().equals(DmpStatus.Draft)) throw new MyValidationException(this.errors.getDmpIsFinalized().getCode(), this.errors.getDmpIsFinalized().getMessage());
}
@ -442,7 +454,7 @@ public class DescriptionServiceImpl implements DescriptionService {
DescriptionPersist.DescriptionPersistValidator validator = this.validatorFactory.validator(DescriptionPersist.DescriptionPersistValidator.class);
validator.validate(this.buildDescriptionPersist(description));
if (validator.result().isValid()) descriptionValidationResult.setResult(DescriptionValidationOutput.Valid);;
if (validator.result().isValid()) descriptionValidationResult.setResult(DescriptionValidationOutput.Valid);
descriptionValidationResults.add(descriptionValidationResult);
}
@ -523,10 +535,10 @@ public class DescriptionServiceImpl implements DescriptionService {
if (!this.conventionService.isListNullOrEmpty(persist.getTextListValue())) persist.getTextListValue().stream().map(UUID::fromString).toList();
else if (!this.conventionService.isNullOrEmpty(persist.getTextValue())) ids.add(UUID.fromString(persist.getTextValue()));
if (ids.size() > 0){
if (!ids.isEmpty()){
Set<UUID> existingIds = this.queryFactory.query(DmpQuery.class).ids(ids).collectAs(new BaseFieldSet().ensure(Dmp._id)).stream().map(DmpEntity::getId).collect(Collectors.toSet());
for (UUID id : ids){
if (!existingIds.contains(id)) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{id, Dmp.class.getSimpleName()}, LocaleContextHolder.getLocale()));
if (!existingIds.contains(id)) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{id, Dmp.class.getSimpleName()}, LocaleContextHolder.getLocale()));
}
}
@ -534,10 +546,10 @@ public class DescriptionServiceImpl implements DescriptionService {
if ( !this.conventionService.isListNullOrEmpty(persist.getTextListValue())) ids = persist.getTextListValue().stream().map(UUID::fromString).toList();
else if (!this.conventionService.isNullOrEmpty(persist.getTextValue())) ids.add(UUID.fromString(persist.getTextValue()));
if (ids.size() > 0) {
if (!ids.isEmpty()) {
Set<UUID> existingIds = this.queryFactory.query(DescriptionQuery.class).ids(ids).collectAs(new BaseFieldSet().ensure(Description._id)).stream().map(DescriptionEntity::getId).collect(Collectors.toSet());
for (UUID id : ids){
if (!existingIds.contains(id)) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{id, Description.class.getSimpleName()}, LocaleContextHolder.getLocale()));
if (!existingIds.contains(id)) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{id, Description.class.getSimpleName()}, LocaleContextHolder.getLocale()));
}
}
}
@ -581,7 +593,7 @@ public class DescriptionServiceImpl implements DescriptionService {
if (definitionFieldSetItemPersist.getFields() != null && !definitionFieldSetItemPersist.getFields().isEmpty()) {
for (String key : definitionFieldSetItemPersist.getFields().keySet()) {
FieldPersist fieldPersist = definitionFieldSetItemPersist.getFields().get(key);
BuildDescriptionReferencePersist(key, fieldPersist, descriptionReferencePersists);
this.BuildDescriptionReferencePersist(key, fieldPersist, descriptionReferencePersists);
}
}
}
@ -634,10 +646,10 @@ public class DescriptionServiceImpl implements DescriptionService {
ReferenceEntity referenceEntity = null;
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 {
ReferenceTypeDataEntity fieldEntity = definition.getFieldById(model.getData().getFieldId()).stream().filter(x-> x.getData() != null && x.getData().getFieldType().equals(FieldType.REFERENCE_TYPES)).map(x-> (ReferenceTypeDataEntity)x.getData()).findFirst().orElse(null);
if (fieldEntity == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{model.getData().getFieldId(), ReferenceTypeDataEntity.class.getSimpleName()}, LocaleContextHolder.getLocale()));
if (fieldEntity == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{model.getData().getFieldId(), ReferenceTypeDataEntity.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){
@ -656,14 +668,14 @@ public class DescriptionServiceImpl implements DescriptionService {
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());
}
}
}
@ -816,7 +828,7 @@ public class DescriptionServiceImpl implements DescriptionService {
newDescription.setDmpId(dmpId);
newDescription.setDmpDescriptionTemplateId(existing.getDmpDescriptionTemplateId());
newDescription.setDescriptionTemplateId(existing.getDescriptionTemplateId());
newDescription.setCreatedById(userScope.getUserId());
newDescription.setCreatedById(this.userScope.getUserId());
newDescription.setCreatedAt(Instant.now());
newDescription.setUpdatedAt(Instant.now());
newDescription.setIsActive(IsActive.Active);
@ -889,13 +901,13 @@ public class DescriptionServiceImpl implements DescriptionService {
this.authorizationService.authorizeForce(Permission.EditDescription);//TODO: Missing Description or dmp for authz
DescriptionTemplateEntity descriptionTemplate = this.queryFactory.query(DescriptionTemplateQuery.class).ids(model.getDescriptionTemplateId()).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).first();
if (descriptionTemplate == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{model.getDescriptionTemplateId(), DescriptionTemplate.class.getSimpleName()}, LocaleContextHolder.getLocale()));
if (descriptionTemplate == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{model.getDescriptionTemplateId(), DescriptionTemplate.class.getSimpleName()}, LocaleContextHolder.getLocale()));
org.opencdmp.commons.types.descriptiontemplate.DefinitionEntity definition = this.xmlHandlingService.fromXmlSafe(org.opencdmp.commons.types.descriptiontemplate.DefinitionEntity.class, descriptionTemplate.getDefinition());
if (definition == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{model.getDescriptionTemplateId(), org.opencdmp.commons.types.descriptiontemplate.DefinitionEntity.class.getSimpleName()}, LocaleContextHolder.getLocale()));
if (definition == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{model.getDescriptionTemplateId(), org.opencdmp.commons.types.descriptiontemplate.DefinitionEntity.class.getSimpleName()}, LocaleContextHolder.getLocale()));
org.opencdmp.commons.types.descriptiontemplate.FieldEntity fieldEntity = definition.getFieldById(model.getFieldId()).stream().filter(x -> x != null && x.getData() != null && x.getData().getFieldType().equals(FieldType.UPLOAD)).findFirst().orElse(null);
if (fieldEntity == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{model.getFieldId(), org.opencdmp.commons.types.descriptiontemplate.FieldEntity.class.getSimpleName()}, LocaleContextHolder.getLocale()));
if (fieldEntity == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{model.getFieldId(), org.opencdmp.commons.types.descriptiontemplate.FieldEntity.class.getSimpleName()}, LocaleContextHolder.getLocale()));
UploadDataEntity uploadDataEntity = (UploadDataEntity)fieldEntity.getData();
if (DataSize.ofBytes(file.getSize()).equals(DataSize.ofMegabytes(uploadDataEntity.getMaxFileSizeInMB()))) {
@ -929,13 +941,13 @@ public class DescriptionServiceImpl implements DescriptionService {
this.authorizationService.authorizeAtLeastOneForce(List.of(this.authorizationContentResolver.descriptionAffiliation(descriptionId)), Permission.BrowseDescription);
DescriptionEntity descriptionEntity = this.queryFactory.query(DescriptionQuery.class).isActive(IsActive.Active).ids(descriptionId).first();
if (descriptionEntity == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{descriptionId, Description.class.getSimpleName()}, LocaleContextHolder.getLocale()));
if (descriptionEntity == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{descriptionId, Description.class.getSimpleName()}, LocaleContextHolder.getLocale()));
DmpDescriptionTemplateEntity dmpDescriptionTemplateEntity = this.queryFactory.query(DmpDescriptionTemplateQuery.class).ids(descriptionEntity.getDmpDescriptionTemplateId()).isActive(IsActive.Active).first();
if (dmpDescriptionTemplateEntity == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{descriptionEntity.getDmpDescriptionTemplateId(), DmpDescriptionTemplate.class.getSimpleName()}, LocaleContextHolder.getLocale()));
if (dmpDescriptionTemplateEntity == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{descriptionEntity.getDmpDescriptionTemplateId(), DmpDescriptionTemplate.class.getSimpleName()}, LocaleContextHolder.getLocale()));
DmpEntity dmpEntity = this.queryFactory.query(DmpQuery.class).ids(dmpDescriptionTemplateEntity.getDmpId()).isActive(IsActive.Active).first();
if (dmpEntity == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{dmpDescriptionTemplateEntity.getDmpId(), Dmp.class.getSimpleName()}, LocaleContextHolder.getLocale()));
if (dmpEntity == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{dmpDescriptionTemplateEntity.getDmpId(), Dmp.class.getSimpleName()}, LocaleContextHolder.getLocale()));
if (!dmpEntity.getAccessType().equals(DmpAccessType.Public))
{
@ -944,7 +956,7 @@ public class DescriptionServiceImpl implements DescriptionService {
}
StorageFileEntity storageFile = this.queryFactory.query(StorageFileQuery.class).ids(storageFileId).first();
if (storageFile == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{storageFileId, StorageFile.class.getSimpleName()}, LocaleContextHolder.getLocale()));
if (storageFile == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{storageFileId, StorageFile.class.getSimpleName()}, LocaleContextHolder.getLocale()));
return storageFile;
}
@ -957,7 +969,7 @@ public class DescriptionServiceImpl implements DescriptionService {
if (data == null) return persist;
DescriptionTemplateEntity descriptionTemplateEntity = this.entityManager.find(DescriptionTemplateEntity.class, data.getDescriptionTemplateId());
if (descriptionTemplateEntity == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{data.getDescriptionTemplateId(), DescriptionTemplate.class.getSimpleName()}, LocaleContextHolder.getLocale()));
if (descriptionTemplateEntity == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{data.getDescriptionTemplateId(), DescriptionTemplate.class.getSimpleName()}, LocaleContextHolder.getLocale()));
persist.setLabel(data.getLabel());
persist.setStatus(DescriptionStatus.Finalized);
@ -997,12 +1009,12 @@ public class DescriptionServiceImpl implements DescriptionService {
if (data.getFieldSets() != null && !data.getFieldSets().isEmpty()){
for (PropertyDefinitionFieldSetEntity fieldSet: data.getFieldSets().values()) {
if (!this.conventionService.isListNullOrEmpty(fieldSet.getItems()));
if (!this.conventionService.isListNullOrEmpty(fieldSet.getItems())){
for (PropertyDefinitionFieldSetItemEntity item: fieldSet.getItems()) {
if (item.getFields() != null && !item.getFields().isEmpty());
for (String key: item.getFields().keySet()) {
if (definition.getFieldById(key).getFirst() != null && FieldType.isReferenceType(definition.getFieldById(key).getFirst().getData().getFieldType())){
if (!this.conventionService.isListNullOrEmpty(item.getFields().get(key).getTextListValue())){
if (item.getFields() != null && !item.getFields().isEmpty()) {
for (String key : item.getFields().keySet()) {
if (definition.getFieldById(key).getFirst() != null && FieldType.isReferenceType(definition.getFieldById(key).getFirst().getData().getFieldType())) {
if (!this.conventionService.isListNullOrEmpty(item.getFields().get(key).getTextListValue())) {
referenceIds.addAll(item.getFields().get(key).getTextListValue());
}
}
@ -1010,10 +1022,12 @@ public class DescriptionServiceImpl implements DescriptionService {
}
}
}
}
}
if (!this.conventionService.isListNullOrEmpty(referenceIds)) {
referenceIds = referenceIds.stream().distinct().collect(Collectors.toList());
return referenceIds.stream().filter(x -> this.conventionService.isValidGuid(UUID.fromString(x))).collect(Collectors.toList()).stream().map(x -> UUID.fromString(x)).collect(Collectors.toList());
return referenceIds.stream().filter(x -> this.conventionService.isValidGuid(UUID.fromString(x))).toList().stream().map(UUID::fromString).collect(Collectors.toList());
}
@ -1059,7 +1073,7 @@ public class DescriptionServiceImpl implements DescriptionService {
else if (FieldType.isExternalIdentifierType(fieldType) && data.getExternalIdentifier() != null) persist.setExternalIdentifier(this.buildExternalIdentifierPersist(data.getExternalIdentifier()));
else if (FieldType.isReferenceType(fieldType) && fieldEntity != null ) {
if (!this.conventionService.isListNullOrEmpty(data.getTextListValue()) && !this.conventionService.isListNullOrEmpty(references)){
List<UUID> referenceIdsInField = data.getTextListValue().stream().filter(x -> this.conventionService.isValidGuid(UUID.fromString(x))).collect(Collectors.toList()).stream().map(x -> UUID.fromString(x)).collect(Collectors.toList());
List<UUID> referenceIdsInField = data.getTextListValue().stream().filter(x -> this.conventionService.isValidGuid(UUID.fromString(x))).toList().stream().map(UUID::fromString).collect(Collectors.toList());
if (!this.conventionService.isListNullOrEmpty(referenceIdsInField)){
List<ReferenceEntity> referencesInField = references.stream().filter(x -> referenceIdsInField.contains(x.getId())).collect(Collectors.toList());
if (!this.conventionService.isListNullOrEmpty(referencesInField)){
@ -1101,4 +1115,167 @@ public class DescriptionServiceImpl implements DescriptionService {
return referencesPersist;
}
//region Export
@Override
public DescriptionImportExport 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.ExportDescription);
DescriptionEntity data = this.entityManager.find(DescriptionEntity.class, id);
if (data == null)
throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{id, Description.class.getSimpleName()}, LocaleContextHolder.getLocale()));
PropertyDefinitionEntity definition = this.jsonHandlingService.fromJson(PropertyDefinitionEntity.class, data.getProperties());
return this.toExport(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.ExportDescription);
DescriptionEntity data = this.entityManager.find(DescriptionEntity.class, id);
if (data == null)
throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{id, Description.class.getSimpleName()}, LocaleContextHolder.getLocale()));
String xml = this.xmlHandlingService.toXml(this.exportXmlEntity(data.getId()));
return this.responseUtilsService.buildResponseFileFromText(xml, data.getLabel() + ".xml");
}
private DescriptionImportExport toExport(DescriptionEntity data, PropertyDefinitionEntity propertiesEntity) throws InvalidApplicationException, JAXBException, ParserConfigurationException, IOException, InstantiationException, IllegalAccessException, SAXException {
DescriptionImportExport xml = new DescriptionImportExport();
xml.setId(data.getId());
xml.setDescription(data.getDescription());
xml.setLabel(data.getLabel());
xml.setFinalizedAt(data.getFinalizedAt());
DescriptionTemplateEntity blueprintEntity = this.queryFactory.query(DescriptionTemplateQuery.class).ids(data.getDescriptionTemplateId()).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).isActive(IsActive.Active).first();
if (blueprintEntity != null) {
xml.setDescriptionTemplate(this.descriptionTemplateService.exportXmlEntity(blueprintEntity.getId()));
}
if (propertiesEntity != null) {
xml.setProperties(this.descriptionPropertyDefinitionToExport(propertiesEntity));
}
List<DescriptionReferenceEntity> dmpReferences = this.queryFactory.query(DescriptionReferenceQuery.class).descriptionIds(data.getId()).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).isActive(IsActive.Active).collect();
if (!this.conventionService.isListNullOrEmpty(dmpReferences)) {
List<ReferenceEntity> references = this.queryFactory.query(ReferenceQuery.class).ids(dmpReferences.stream().map(DescriptionReferenceEntity::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<DescriptionReferenceImportExport> dmpReferenceImportExports = new LinkedList<>();
for (DescriptionReferenceEntity descriptionTemplateEntity : dmpReferences) {
dmpReferenceImportExports.add(this.descriptionReferenceToExport(descriptionTemplateEntity, referenceEntityMap, referenceTypeEntityMap));
}
xml.setReferences(dmpReferenceImportExports);
}
return xml;
}
private DescriptionReferenceImportExport descriptionReferenceToExport(DescriptionReferenceEntity entity, Map<UUID, ReferenceEntity> referenceEntityMap, Map<UUID, ReferenceTypeEntity> referenceTypeEntityMap) {
DescriptionReferenceImportExport xml = new DescriptionReferenceImportExport();
if (entity == null) return xml;
DescriptionReferenceDataEntity referenceData = this.jsonHandlingService.fromJsonSafe(DescriptionReferenceDataEntity.class, entity.getData());
if (referenceData != null) xml.setFieldId(referenceData.getFieldId());
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.descriptionReferenceTypeToExport(referenceType));
}
return xml;
}
private DescriptionReferenceTypeImportExport descriptionReferenceTypeToExport(ReferenceTypeEntity entity) {
DescriptionReferenceTypeImportExport xml = new DescriptionReferenceTypeImportExport();
if (entity == null) return xml;
xml.setId(entity.getId());
xml.setCode(entity.getCode());
xml.setName(entity.getName());
return xml;
}
private DescriptionPropertyDefinitionImportExport descriptionPropertyDefinitionToExport(PropertyDefinitionEntity entity) {
DescriptionPropertyDefinitionImportExport xml = new DescriptionPropertyDefinitionImportExport();
if (entity == null) return xml;
if (entity.getFieldSets() != null && !entity.getFieldSets().isEmpty()) {
List<DescriptionPropertyDefinitionFieldSetImportExport> exports = new LinkedList<>();
for (Map.Entry<String, PropertyDefinitionFieldSetEntity> fieldSetEntityEntry : entity.getFieldSets().entrySet()) {
exports.add(this.descriptionPropertyDefinitionFieldSetToExport(fieldSetEntityEntry.getValue(), fieldSetEntityEntry.getKey()));
}
xml.setFieldSets(exports);
}
return xml;
}
private DescriptionPropertyDefinitionFieldSetImportExport descriptionPropertyDefinitionFieldSetToExport(PropertyDefinitionFieldSetEntity entity, String fieldSetId) {
DescriptionPropertyDefinitionFieldSetImportExport xml = new DescriptionPropertyDefinitionFieldSetImportExport();
xml.setFieldSetId(fieldSetId);
if (entity == null) return xml;
if (entity.getItems() != null && !entity.getItems().isEmpty()) {
List<DescriptionPropertyDefinitionFieldSetItemImportExport> exports = new LinkedList<>();
for (PropertyDefinitionFieldSetItemEntity propertyDefinitionFieldSetItemEntity : entity.getItems()) {
exports.add(this.descriptionPropertyDefinitionFieldSetItemToExport(propertyDefinitionFieldSetItemEntity));
}
xml.setItems(exports);
}
return xml;
}
private DescriptionPropertyDefinitionFieldSetItemImportExport descriptionPropertyDefinitionFieldSetItemToExport(PropertyDefinitionFieldSetItemEntity entity) {
DescriptionPropertyDefinitionFieldSetItemImportExport xml = new DescriptionPropertyDefinitionFieldSetItemImportExport();
if (entity == null) return xml;
xml.setComment(entity.getComment());
xml.setOrdinal(entity.getOrdinal());
if (entity.getFields() != null && !entity.getFields().isEmpty()) {
List<DescriptionFieldImportExport> exports = new LinkedList<>();
for (Map.Entry<String, FieldEntity> fieldSetEntityEntry : entity.getFields().entrySet()) {
exports.add(this.descriptionFieldImportExportToExport(fieldSetEntityEntry.getValue(), fieldSetEntityEntry.getKey()));
}
xml.setFields(exports);
}
return xml;
}
private DescriptionFieldImportExport descriptionFieldImportExportToExport(FieldEntity entity, String fieldId) {
DescriptionFieldImportExport xml = new DescriptionFieldImportExport();
xml.setFieldId(fieldId);
if (entity == null) return xml;
xml.setDateValue(entity.getDateValue());
xml.setTextValue(entity.getTextValue());
xml.setTextListValue(entity.getTextListValue());
if (entity.getExternalIdentifier() != null) {
xml.setExternalIdentifier(this.descriptionExternalIdentifierToExport(entity.getExternalIdentifier()));
}
return xml;
}
private DescriptionExternalIdentifierImportExport descriptionExternalIdentifierToExport(ExternalIdentifierEntity entity) {
DescriptionExternalIdentifierImportExport xml = new DescriptionExternalIdentifierImportExport();
if (entity == null) return xml;
xml.setIdentifier(entity.getIdentifier());
xml.setType(entity.getType());
return xml;
}
//endregion
}

View File

@ -1,6 +1,7 @@
package org.opencdmp.service.descriptiontemplate;
import com.fasterxml.jackson.core.JsonProcessingException;
import org.opencdmp.commons.types.descriptiontemplate.importexport.DescriptionTemplateImportExport;
import org.opencdmp.model.DescriptionTemplate;
import org.opencdmp.model.persist.DescriptionTemplatePersist;
import org.opencdmp.model.persist.NewVersionDescriptionTemplatePersist;
@ -26,6 +27,9 @@ public interface DescriptionTemplateService {
DescriptionTemplate buildClone(UUID id, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException;
DescriptionTemplate createNewVersion(NewVersionDescriptionTemplatePersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException, JAXBException, ParserConfigurationException, JsonProcessingException, TransformerException;
DescriptionTemplate importXml(byte[] bytes, UUID id, String label, FieldSet fields) throws MyForbiddenException, MyNotFoundException, JAXBException, ParserConfigurationException, TransformerException, InvalidApplicationException, IOException, InstantiationException, IllegalAccessException, SAXException;
DescriptionTemplateImportExport 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, TransformerException, InvalidApplicationException;
}

View File

@ -6,7 +6,6 @@ import org.opencdmp.authorization.Permission;
import org.opencdmp.commons.JsonHandlingService;
import org.opencdmp.commons.XmlHandlingService;
import org.opencdmp.commons.enums.*;
import org.opencdmp.commons.enums.notification.NotificationContactType;
import org.opencdmp.commons.scope.tenant.TenantScope;
import org.opencdmp.commons.scope.user.UserScope;
import org.opencdmp.commons.types.descriptiontemplate.*;
@ -158,7 +157,7 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic
if (isUpdate) {
data = this.entityManager.find(DescriptionTemplateEntity.class, model.getId());
if (data == null)
throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{model.getId(), DescriptionTemplate.class.getSimpleName()}, LocaleContextHolder.getLocale()));
throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{model.getId(), DescriptionTemplate.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(DescriptionTemplateStatus.Finalized))
@ -260,11 +259,11 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic
UserEntity user = this.entityManager.find(UserEntity.class, userDescriptionTemplate.getUserId());
if (user == null){
throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{userDescriptionTemplate.getUserId(), User.class.getSimpleName()}, LocaleContextHolder.getLocale()));
throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{userDescriptionTemplate.getUserId(), User.class.getSimpleName()}, LocaleContextHolder.getLocale()));
}
DescriptionTemplateEntity descriptionTemplate = this.queryFactory.query(DescriptionTemplateQuery.class).isActive(IsActive.Active).ids(userDescriptionTemplate.getDescriptionTemplateId()).first();
if (descriptionTemplate == null){
throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{userDescriptionTemplate.getDescriptionTemplateId(), DescriptionTemplate.class.getSimpleName()}, LocaleContextHolder.getLocale()));
throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{userDescriptionTemplate.getDescriptionTemplateId(), DescriptionTemplate.class.getSimpleName()}, LocaleContextHolder.getLocale()));
}
event.setUserId(user.getId());
UserContactInfoQuery query = this.queryFactory.query(UserContactInfoQuery.class).userIds(user.getId());
@ -273,16 +272,16 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic
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.setNotificationType(notificationProperties.getDescriptionTemplateInvitationType());
event.setContactHint(this.jsonHandlingService.toJsonSafe(contactData));
event.setNotificationType(this.notificationProperties.getDescriptionTemplateInvitationType());
NotificationFieldData data = new NotificationFieldData();
List<FieldInfo> fieldInfoList = new ArrayList<>();
fieldInfoList.add(new FieldInfo("{recipient}", DataType.String, user.getName()));
fieldInfoList.add(new FieldInfo("{templateName}", DataType.String, descriptionTemplate.getLabel()));
fieldInfoList.add(new FieldInfo("{templateID}", DataType.String, descriptionTemplate.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 addOwner(DescriptionTemplateEntity descriptionTemplateEntity) throws InvalidApplicationException {
@ -292,7 +291,7 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic
data.setCreatedAt(Instant.now());
data.setUpdatedAt(Instant.now());
data.setRole(UserDescriptionTemplateRole.Owner);
data.setUserId(userScope.getUserId());
data.setUserId(this.userScope.getUserId());
data.setDescriptionTemplateId(descriptionTemplateEntity.getId());
this.entityManager.persist(data);
}
@ -418,13 +417,13 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic
List<UUID> ids = persist.getTextListValue().stream().map(UUID::fromString).toList();
Set<UUID> existingIds = this.queryFactory.query(DmpQuery.class).ids(ids).isActive(IsActive.Active).collectAs(new BaseFieldSet().ensure(Dmp._id)).stream().map(DmpEntity::getId).collect(Collectors.toSet());
for (UUID id : ids){
if (!existingIds.contains(id)) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{id, Dmp.class.getSimpleName()}, LocaleContextHolder.getLocale()));
if (!existingIds.contains(id)) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{id, Dmp.class.getSimpleName()}, LocaleContextHolder.getLocale()));
}
} if (FieldType.INTERNAL_ENTRIES_DESCRIPTIONS.equals(fieldType) && !this.conventionService.isListNullOrEmpty(persist.getTextListValue())){
List<UUID> ids = persist.getTextListValue().stream().map(UUID::fromString).toList();
Set<UUID> existingIds = this.queryFactory.query(DescriptionQuery.class).ids(ids).isActive(IsActive.Active).collectAs(new BaseFieldSet().ensure(Description._id)).stream().map(DescriptionEntity::getId).collect(Collectors.toSet());
for (UUID id : ids){
if (!existingIds.contains(id)) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{id, Description.class.getSimpleName()}, LocaleContextHolder.getLocale()));
if (!existingIds.contains(id)) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{id, Description.class.getSimpleName()}, LocaleContextHolder.getLocale()));
}
}
data.setTextListValue(persist.getTextListValue());
@ -456,7 +455,7 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic
ReferenceEntity data;
if (this.conventionService.isValidGuid(model.getId())){
data = this.entityManager.find(ReferenceEntity.class, model.getId());
if (data == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{model.getId(), Reference.class.getSimpleName()}, LocaleContextHolder.getLocale()));
if (data == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{model.getId(), Reference.class.getSimpleName()}, LocaleContextHolder.getLocale()));
} else {
ReferenceTypeDataEntity referenceTypeDataEntity = ((ReferenceTypeDataEntity)fieldEntity.getData());
data = this.queryFactory.query(ReferenceQuery.class).sourceTypes(model.getSourceType()).typeIds(referenceTypeDataEntity.getReferenceTypeId()).sources(model.getSource()).isActive(IsActive.Active).references(model.getReference()).first();
@ -476,14 +475,14 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic
try {
ReferenceTypeEntity referenceType = this.queryFactory.query(ReferenceTypeQuery.class).ids(referenceTypeDataEntity.getReferenceTypeId()).firstAs(new BaseFieldSet().ensure(ReferenceType._id).ensure(ReferenceTypeEntity._tenantId));
if (referenceType == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{referenceTypeDataEntity.getReferenceTypeId(), ReferenceType.class.getSimpleName()}, LocaleContextHolder.getLocale()));
if (referenceType == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{referenceTypeDataEntity.getReferenceTypeId(), ReferenceType.class.getSimpleName()}, LocaleContextHolder.getLocale()));
if (data.getSourceType().equals(ReferenceSourceType.External) && !this.tenantScope.isDefaultTenant() && referenceType.getTenantId() == null){
this.tenantScope.setTempTenant(this.entityManager.getEntityManager(), null, this.tenantScope.getDefaultTenantCode());
}
this.entityManager.persist(data);
} finally {
tenantScope.removeTempTenant(this.entityManager.getEntityManager());
this.tenantScope.removeTempTenant(this.entityManager.getEntityManager());
}
}
}
@ -562,7 +561,7 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic
this.authorizationService.authorizeForce(Permission.DeleteDescriptionTemplate);
DescriptionTemplateEntity data = this.entityManager.find(DescriptionTemplateEntity.class, id);
if (data == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{id, DescriptionTemplate.class.getSimpleName()}, LocaleContextHolder.getLocale()));
if (data == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{id, DescriptionTemplate.class.getSimpleName()}, LocaleContextHolder.getLocale()));
if (data.getVersionStatus().equals(DescriptionTemplateVersionStatus.Current)){
DescriptionTemplateQuery descriptionTemplateQuery = this.queryFactory.query(DescriptionTemplateQuery.class)
@ -597,7 +596,7 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic
DescriptionTemplateQuery query = this.queryFactory.query(DescriptionTemplateQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).ids(id);
DescriptionTemplate model = this.builderFactory.builder(DescriptionTemplateBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(fields, query.firstAs(fields));
if (model == null)
throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{id, DescriptionTemplate.class.getSimpleName()}, LocaleContextHolder.getLocale()));
throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{id, DescriptionTemplate.class.getSimpleName()}, LocaleContextHolder.getLocale()));
model.setLabel(model.getLabel() + " new ");
model.setId(null);
@ -678,7 +677,7 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic
DescriptionTemplateEntity oldDescriptionTemplateEntity = this.entityManager.find(DescriptionTemplateEntity.class, model.getId());
if (oldDescriptionTemplateEntity == null)
throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{model.getId(), DescriptionTemplate.class.getSimpleName()}, LocaleContextHolder.getLocale()));
throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{model.getId(), DescriptionTemplate.class.getSimpleName()}, LocaleContextHolder.getLocale()));
if (!this.conventionService.hashValue(oldDescriptionTemplateEntity.getUpdatedAt()).equals(model.getHash()))
throw new MyValidationException(this.errors.getHashConflict().getCode(), this.errors.getHashConflict().getMessage());
@ -742,6 +741,7 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic
this.authorizationService.authorizeForce(Permission.ImportDescriptionTemplate);
DescriptionTemplateImportExport importXml = this.xmlHandlingService.fromXml(DescriptionTemplateImportExport.class, new String(bytes, StandardCharsets.UTF_8));
if (id == null) id = importXml.getId();
if (id == null) {
DescriptionTemplatePersist persist = new DescriptionTemplatePersist();
persist.setLabel(label);
@ -764,7 +764,7 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic
DescriptionTemplateEntity oldDescriptionTemplateEntity = this.entityManager.find(DescriptionTemplateEntity.class, id);
if (oldDescriptionTemplateEntity == null)
throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{id, DescriptionTemplate.class.getSimpleName()}, LocaleContextHolder.getLocale()));
throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{id, DescriptionTemplate.class.getSimpleName()}, LocaleContextHolder.getLocale()));
persist.setHash(this.conventionService.hashValue(oldDescriptionTemplateEntity.getUpdatedAt()));
this.validatorFactory.validator(DescriptionTemplatePersist.DescriptionTemplatePersistValidator.class).validateForce(persist);
return this.createNewVersion(persist, fields);
@ -778,7 +778,7 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic
List<PagePersist> pagesDatasetEntity = new LinkedList<>();
if (!this.conventionService.isListNullOrEmpty(importExport.getPages())) {
for (PageImportExport xmlPage : importExport.getPages()) {
for (DescriptionTemplatePageImportExport xmlPage : importExport.getPages()) {
pagesDatasetEntity.add(this.xmlPageToPersist(xmlPage));
}
}
@ -787,14 +787,14 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic
return definitionPersist;
}
public PagePersist xmlPageToPersist(PageImportExport importExport) {
public PagePersist xmlPageToPersist(DescriptionTemplatePageImportExport importExport) {
PagePersist pageEntity = new PagePersist();
pageEntity.setId(importExport.getId());
pageEntity.setOrdinal(importExport.getOrdinal());
pageEntity.setTitle(importExport.getTitle());
if (!this.conventionService.isListNullOrEmpty(importExport.getSections())) {
List<SectionPersist> sectionsListEntity = new LinkedList<>();
for (SectionImportExport xmlSection : importExport.getSections()) {
for (DescriptionTemplateSectionImportExport xmlSection : importExport.getSections()) {
sectionsListEntity.add(this.xmlSectionToPersist(xmlSection));
}
pageEntity.setSections(sectionsListEntity);
@ -803,12 +803,12 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic
return pageEntity;
}
public SectionPersist xmlSectionToPersist(SectionImportExport importExport) {
public SectionPersist xmlSectionToPersist(DescriptionTemplateSectionImportExport importExport) {
SectionPersist sectionEntity = new SectionPersist();
List<SectionPersist> sectionsListEntity = new LinkedList<>();
if (!this.conventionService.isListNullOrEmpty(importExport.getSections())) {
for (SectionImportExport xmlSection : importExport.getSections()) {
for (DescriptionTemplateSectionImportExport xmlSection : importExport.getSections()) {
sectionsListEntity.add(this.xmlSectionToPersist(xmlSection));
}
}
@ -818,7 +818,7 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic
sectionEntity.setDescription(importExport.getDescription());
List<FieldSetPersist> fieldSetEntity = new LinkedList<>();
if (!this.conventionService.isListNullOrEmpty(importExport.getFieldSets())) {
for (FieldSetImportExport xmlFieldSet : importExport.getFieldSets()) {
for (DescriptionTemplateFieldSetImportExport xmlFieldSet : importExport.getFieldSets()) {
fieldSetEntity.add(this.toFieldSetModel(xmlFieldSet));
}
}
@ -829,7 +829,7 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic
return sectionEntity;
}
public FieldSetPersist toFieldSetModel(FieldSetImportExport importExport) {
public FieldSetPersist toFieldSetModel(DescriptionTemplateFieldSetImportExport importExport) {
FieldSetPersist fieldSet1Entity = new FieldSetPersist();
fieldSet1Entity.setId(importExport.getId());
fieldSet1Entity.setOrdinal(importExport.getOrdinal());
@ -843,7 +843,7 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic
List<FieldPersist> fieldsEntity = new LinkedList<>();
if (!this.conventionService.isListNullOrEmpty(importExport.getFields())) {
for (FieldImportExport xmlField : importExport.getFields()) {
for (DescriptionTemplateFieldImportExport xmlField : importExport.getFields()) {
fieldsEntity.add(this.xmlFieldToPersist(xmlField));
}
}
@ -851,7 +851,7 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic
return fieldSet1Entity;
}
public FieldPersist xmlFieldToPersist(FieldImportExport importExport) {
public FieldPersist xmlFieldToPersist(DescriptionTemplateFieldImportExport importExport) {
FieldPersist fieldEntity = new FieldPersist();
fieldEntity.setId(importExport.getId());
fieldEntity.setOrdinal(importExport.getOrdinal());
@ -859,7 +859,7 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic
fieldEntity.setDefaultValue(importExport.getDefaultValue());
List<RulePersist> rulePersists = new ArrayList<>();
if (importExport.getVisibilityRules() != null) {
for (RuleImportExport xmlRule : importExport.getVisibilityRules()) {
for (DescriptionTemplateRuleImportExport xmlRule : importExport.getVisibilityRules()) {
rulePersists.add(this.toRuleModel(xmlRule));
}
}
@ -874,7 +874,7 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic
return fieldEntity;
}
public RulePersist toRuleModel(RuleImportExport importExport) {
public RulePersist toRuleModel(DescriptionTemplateRuleImportExport importExport) {
RulePersist ruleEntity = new RulePersist();
ruleEntity.setTarget(importExport.getTarget());
ruleEntity.setDateValue(importExport.getDateValue());
@ -884,7 +884,7 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic
return ruleEntity;
}
public MultiplicityPersist xmlMultiplicityToPersist(MultiplicityImportExport importXml) {
public MultiplicityPersist xmlMultiplicityToPersist(DescriptionTemplateMultiplicityImportExport importXml) {
MultiplicityPersist multiplicityEntity = new MultiplicityPersist();
multiplicityEntity.setMax(importXml.getMax());
multiplicityEntity.setMin(importXml.getMin());
@ -898,25 +898,41 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic
//region Export
@Override
public ResponseEntity<byte[]> exportXml(UUID id) throws MyForbiddenException, MyNotFoundException, JAXBException, ParserConfigurationException, IOException, InstantiationException, IllegalAccessException, SAXException, InvalidApplicationException {
logger.debug(new MapLogEntry("persisting data").And("id", id));
public DescriptionTemplateImportExport exportXmlEntity(UUID id) throws MyForbiddenException, MyNotFoundException, JAXBException, ParserConfigurationException, IOException, InstantiationException, IllegalAccessException, SAXException, InvalidApplicationException {
logger.debug(new MapLogEntry("exportXml").And("id", id));
this.authorizationService.authorizeForce(Permission.ExportDescriptionTemplate);
DescriptionTemplateEntity data = this.entityManager.find(DescriptionTemplateEntity.class, id);
if (data == null)
throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{id, DescriptionTemplate.class.getSimpleName()}, LocaleContextHolder.getLocale()));
throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{id, DescriptionTemplate.class.getSimpleName()}, LocaleContextHolder.getLocale()));
DefinitionEntity definition = this.xmlHandlingService.fromXml(DefinitionEntity.class, data.getDefinition());
String xml = this.xmlHandlingService.toXml(this.definitionXmlToExport(data, definition));
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("exportXml").And("id", id));
this.authorizationService.authorizeForce(Permission.ExportDescriptionTemplate);
DescriptionTemplateEntity data = this.entityManager.find(DescriptionTemplateEntity.class, id);
if (data == null)
throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{id, DescriptionTemplate.class.getSimpleName()}, LocaleContextHolder.getLocale()));
DefinitionEntity definition = this.xmlHandlingService.fromXml(DefinitionEntity.class, data.getDefinition());
String xml = this.xmlHandlingService.toXml(this.exportXmlEntity(id));
return this.responseUtilsService.buildResponseFileFromText(xml, data.getLabel() + ".xml");
}
private DescriptionTemplateImportExport definitionXmlToExport(DescriptionTemplateEntity data, DefinitionEntity entity) {
DescriptionTemplateImportExport xml = new DescriptionTemplateImportExport();
xml.setId(data.getId());
xml.setType(data.getTypeId());
xml.setType(data.getTypeId());
xml.setLanguage(data.getLanguage());
xml.setDescription(data.getDescription());
List<PageImportExport> pagesDatasetEntity = new LinkedList<>();
List<DescriptionTemplatePageImportExport> pagesDatasetEntity = new LinkedList<>();
for (PageEntity xmlPage : entity.getPages()) {
pagesDatasetEntity.add(this.pageXmlToExport(xmlPage));
}
@ -925,12 +941,12 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic
return xml;
}
private PageImportExport pageXmlToExport(PageEntity entity) {
PageImportExport xml = new PageImportExport();
private DescriptionTemplatePageImportExport pageXmlToExport(PageEntity entity) {
DescriptionTemplatePageImportExport xml = new DescriptionTemplatePageImportExport();
xml.setId(entity.getId());
xml.setOrdinal(entity.getOrdinal());
xml.setTitle(entity.getTitle());
List<SectionImportExport> sectionsListEntity = new LinkedList<>();
List<DescriptionTemplateSectionImportExport> sectionsListEntity = new LinkedList<>();
if (!this.conventionService.isListNullOrEmpty(entity.getSections())) {
for (SectionEntity section : entity.getSections()) {
sectionsListEntity.add(this.sectionXmlToExport(section));
@ -941,9 +957,9 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic
return xml;
}
private SectionImportExport sectionXmlToExport(SectionEntity entity) {
SectionImportExport xml = new SectionImportExport();
List<SectionImportExport> sectionsListEntity = new LinkedList<>();
private DescriptionTemplateSectionImportExport sectionXmlToExport(SectionEntity entity) {
DescriptionTemplateSectionImportExport xml = new DescriptionTemplateSectionImportExport();
List<DescriptionTemplateSectionImportExport> sectionsListEntity = new LinkedList<>();
if (!this.conventionService.isListNullOrEmpty(entity.getSections())) {
for (SectionEntity xmlSection : entity.getSections()) {
@ -956,7 +972,7 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic
xml.setOrdinal(entity.getOrdinal());
xml.setTitle(entity.getTitle());
xml.setDescription(entity.getDescription());
List<FieldSetImportExport> fieldSetEntity = new LinkedList<>();
List<DescriptionTemplateFieldSetImportExport> fieldSetEntity = new LinkedList<>();
if (!this.conventionService.isListNullOrEmpty(entity.getFieldSets())) {
for (FieldSetEntity xmlFieldSet : entity.getFieldSets()) {
fieldSetEntity.add(this.fieldSetXmlToExport(xmlFieldSet));
@ -968,8 +984,8 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic
return xml;
}
private FieldSetImportExport fieldSetXmlToExport(FieldSetEntity entity) {
FieldSetImportExport fieldSet1Entity = new FieldSetImportExport();
private DescriptionTemplateFieldSetImportExport fieldSetXmlToExport(FieldSetEntity entity) {
DescriptionTemplateFieldSetImportExport fieldSet1Entity = new DescriptionTemplateFieldSetImportExport();
fieldSet1Entity.setId(entity.getId());
fieldSet1Entity.setOrdinal(entity.getOrdinal());
fieldSet1Entity.setHasCommentField(entity.getHasCommentField());
@ -980,7 +996,7 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic
fieldSet1Entity.setExtendedDescription(entity.getExtendedDescription());
fieldSet1Entity.setAdditionalInformation(entity.getAdditionalInformation());
List<FieldImportExport> fieldsEntity = new LinkedList<>();
List<DescriptionTemplateFieldImportExport> fieldsEntity = new LinkedList<>();
if (entity.getFields() != null) {
for (FieldEntity xmlField : entity.getFields()) {
fieldsEntity.add(this.fieldXmlToExport(xmlField));
@ -990,13 +1006,13 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic
return fieldSet1Entity;
}
private FieldImportExport fieldXmlToExport(FieldEntity entity) {
FieldImportExport xml = new FieldImportExport();
private DescriptionTemplateFieldImportExport fieldXmlToExport(FieldEntity entity) {
DescriptionTemplateFieldImportExport xml = new DescriptionTemplateFieldImportExport();
xml.setId(entity.getId());
xml.setOrdinal(entity.getOrdinal());
xml.setValidations(entity.getValidations());
xml.setDefaultValue(entity.getDefaultValue());
List<RuleImportExport> rulePersists = new ArrayList<>();
List<DescriptionTemplateRuleImportExport> rulePersists = new ArrayList<>();
if (!this.conventionService.isListNullOrEmpty(entity.getVisibilityRules())) {
for (RuleEntity xmlRule : entity.getVisibilityRules()) {
rulePersists.add(this.toRuleModel(xmlRule));
@ -1013,22 +1029,22 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic
return xml;
}
private RuleImportExport toRuleModel(RuleEntity entity) {
RuleImportExport xml = new RuleImportExport();
private DescriptionTemplateRuleImportExport toRuleModel(RuleEntity entity) {
DescriptionTemplateRuleImportExport xml = new DescriptionTemplateRuleImportExport();
xml.setTarget(entity.getTarget());
xml.setDateValue(entity.getDateValue());
xml.setTextListValue(entity.getTextListValue());
xml.setTextValue(entity.getTextValue());
if (entity.getExternalIdentifier() != null){
xml.setExternalIdentifier(new ExternalIdentifierImportExport());
xml.setExternalIdentifier(new DescriptionTemplateExternalIdentifierImportExport());
xml.getExternalIdentifier().setIdentifier(entity.getExternalIdentifier().getIdentifier());
xml.getExternalIdentifier().setType(entity.getExternalIdentifier().getType());
}
return xml;
}
private MultiplicityImportExport multiplicityXmlToExport(MultiplicityEntity entity) {
MultiplicityImportExport xml = new MultiplicityImportExport();
private DescriptionTemplateMultiplicityImportExport multiplicityXmlToExport(MultiplicityEntity entity) {
DescriptionTemplateMultiplicityImportExport xml = new DescriptionTemplateMultiplicityImportExport();
xml.setMax(entity.getMax());
xml.setMin(entity.getMin());
xml.setPlaceholder(entity.getPlaceholder());

View File

@ -11,6 +11,7 @@ import org.opencdmp.commons.enums.notification.NotificationContactType;
import org.opencdmp.commons.scope.tenant.TenantScope;
import org.opencdmp.commons.scope.user.UserScope;
import org.opencdmp.commons.types.actionconfirmation.DmpInvitationEntity;
import org.opencdmp.commons.types.description.importexport.DescriptionImportExport;
import org.opencdmp.commons.types.dmp.DmpBlueprintValueEntity;
import org.opencdmp.commons.types.dmp.DmpContactEntity;
import org.opencdmp.commons.types.dmp.DmpPropertiesEntity;
@ -142,6 +143,7 @@ public class DmpServiceImpl implements DmpService {
private final TenantScope tenantScope;
private final ResponseUtilsService responseUtilsService;
private final DmpBlueprintService dmpBlueprintService;
@Autowired
public DmpServiceImpl(
TenantEntityManager entityManager,
@ -231,8 +233,8 @@ public class DmpServiceImpl implements DmpService {
private void checkIfDescriptionTemplateIsUse (List<DmpDescriptionTemplatePersist> descriptionTemplates, UUID id){
List<DmpDescriptionTemplateEntity> existingDmpDescriptionTemplates = this.queryFactory.query(DmpDescriptionTemplateQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).dmpIds(id).isActive(IsActive.Active).collect();
List<DmpDescriptionTemplateEntity> removedDescriptionTemplates = existingDmpDescriptionTemplates.stream().filter(x -> descriptionTemplates.stream().noneMatch(y -> y.getDescriptionTemplateGroupId().equals(x.getDescriptionTemplateGroupId()))).collect(Collectors.toList());
DmpDescriptionTemplateQuery dmpDescriptionTemplateQuery = this.queryFactory.query(DmpDescriptionTemplateQuery.class).isActive(IsActive.Active).dmpIds(id).descriptionTemplateGroupIds(removedDescriptionTemplates.stream().map(x -> x.getDescriptionTemplateGroupId()).collect(Collectors.toList()));
List<DmpDescriptionTemplateEntity> removedDescriptionTemplates = existingDmpDescriptionTemplates.stream().filter(x -> descriptionTemplates.stream().noneMatch(y -> y.getDescriptionTemplateGroupId().equals(x.getDescriptionTemplateGroupId()))).toList();
DmpDescriptionTemplateQuery dmpDescriptionTemplateQuery = this.queryFactory.query(DmpDescriptionTemplateQuery.class).isActive(IsActive.Active).dmpIds(id).descriptionTemplateGroupIds(removedDescriptionTemplates.stream().map(DmpDescriptionTemplateEntity::getDescriptionTemplateGroupId).collect(Collectors.toList()));
DescriptionQuery query = this.queryFactory.query(DescriptionQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).dmpDescriptionTemplateSubQuery(dmpDescriptionTemplateQuery).isActive(IsActive.Active);
if (query != null && query.count() > 0) throw new MyValidationException(this.errors.getDmpDescriptionTemplateCanNotRemove().getCode(), this.errors.getDmpDescriptionTemplateCanNotRemove().getMessage());
@ -1066,7 +1068,7 @@ public class DmpServiceImpl implements DmpService {
if (!this.conventionService.isListNullOrEmpty(dmpDescriptionTemplateEntities)){
persist.setDescriptionTemplates(new ArrayList<>());
for (DmpDescriptionTemplateEntity descriptionTemplateEntity: dmpDescriptionTemplateEntities) {
persist.getDescriptionTemplates().add(this.buildDmpDescriptionTemplatePersists(descriptionTemplateEntity, definition.getSections()));
persist.getDescriptionTemplates().add(this.buildDmpDescriptionTemplatePersists(descriptionTemplateEntity));
}
}
persist.setProperties(this.buildDmpPropertyDefinitionPersist( this.jsonHandlingService.fromJsonSafe(DmpPropertiesEntity.class, data.getProperties()), dmpReferenceEntities, definition.getSections()));
@ -1100,7 +1102,7 @@ public class DmpServiceImpl implements DmpService {
for (DmpReferenceEntity dmpReferenceEntity : dmpReferenceEntities) {
DmpReferenceData referenceData = this.jsonHandlingService.fromJsonSafe(DmpReferenceData.class, dmpReferenceEntity.getData());
ReferenceEntity reference = referencesFromAllFields.stream().filter(x -> x.getId().equals(dmpReferenceEntity.getReferenceId())).collect(Collectors.toList()).getFirst();
ReferenceEntity reference = referencesFromAllFields.stream().filter(x -> x.getId().equals(dmpReferenceEntity.getReferenceId())).toList().getFirst();
if (referenceData.getBlueprintFieldId().equals(fieldEntity.getId()) && reference != null) {
referencePersists.add(this.buildReferencePersist(reference));
}
@ -1152,7 +1154,7 @@ public class DmpServiceImpl implements DmpService {
return persist;
}
private @NotNull DmpDescriptionTemplatePersist buildDmpDescriptionTemplatePersists(DmpDescriptionTemplateEntity data, List<SectionEntity> sectionEntities){
private @NotNull DmpDescriptionTemplatePersist buildDmpDescriptionTemplatePersists(DmpDescriptionTemplateEntity data){
DmpDescriptionTemplatePersist persist = new DmpDescriptionTemplatePersist();
if (data == null) return persist;
@ -1234,7 +1236,7 @@ public class DmpServiceImpl implements DmpService {
if (userId != null){
user.setUser(userId);
usersToAssign.add(user);
if (this.userScope.getUserId() != userId && !existingUsers.stream().map(x -> x.getUserId()).collect(Collectors.toList()).contains(userId)){
if (this.userScope.getUserId() != userId && !existingUsers.stream().map(DmpUserEntity::getUserId).toList().contains(userId)){
this.sendDmpInvitationExistingUser(user.getUser(), dmp, user.getRole());
}
}else if (user.getEmail() != null) {
@ -1380,7 +1382,7 @@ public class DmpServiceImpl implements DmpService {
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();
List<UserEntity> users = this.queryFactory.query(UserQuery.class).ids(propertiesEntity.getContacts().stream().map(DmpContactEntity::getUserId).filter(Objects::nonNull).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));
@ -1432,6 +1434,14 @@ public class DmpServiceImpl implements DmpService {
}
xml.setReferences(dmpReferenceImportExports);
}
List<DescriptionEntity> descriptions = this.queryFactory.query(DescriptionQuery.class).dmpIds(data.getId()).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).dmpIds(data.getId()).isActive(IsActive.Active).collect();
if (!this.conventionService.isListNullOrEmpty(descriptions)) {
List<DescriptionImportExport> descriptionImportExports = new LinkedList<>();
for (DescriptionEntity description : descriptions) {
descriptionImportExports.add(this.descriptionService.exportXmlEntity(description.getId()));
}
xml.setDescriptions(descriptionImportExports);
}
return xml;
}

View File

@ -481,11 +481,11 @@ public class DmpBlueprintServiceImpl implements DmpBlueprintService {
return xml;
}
private DefinitionImportExport definitionXmlToExport(DefinitionEntity entity) {
private BlueprintDefinitionImportExport definitionXmlToExport(DefinitionEntity entity) {
if (entity == null)
return null;
DefinitionImportExport xml = new DefinitionImportExport();
List<SectionImportExport> dmpBlueprintSections = new ArrayList<>();
BlueprintDefinitionImportExport xml = new BlueprintDefinitionImportExport();
List<BlueprintSectionImportExport> dmpBlueprintSections = new ArrayList<>();
if (!this.conventionService.isListNullOrEmpty(entity.getSections())) {
for (SectionEntity section : entity.getSections()) {
dmpBlueprintSections.add(this.sectionXmlToExport(section));
@ -495,14 +495,14 @@ public class DmpBlueprintServiceImpl implements DmpBlueprintService {
return xml;
}
private SectionImportExport sectionXmlToExport(SectionEntity entity) {
SectionImportExport xml = new SectionImportExport();
private BlueprintSectionImportExport sectionXmlToExport(SectionEntity entity) {
BlueprintSectionImportExport xml = new BlueprintSectionImportExport();
xml.setId(entity.getId());
xml.setLabel(entity.getLabel());
xml.setDescription(entity.getDescription());
xml.setOrdinal(entity.getOrdinal());
xml.setHasTemplates(entity.getHasTemplates());
List<SystemFieldImportExport> dmpBlueprintSystemFieldModels = new LinkedList<>();
List<BlueprintSystemFieldImportExport> dmpBlueprintSystemFieldModels = new LinkedList<>();
if (!this.conventionService.isListNullOrEmpty(entity.getFields())) {
for (SystemFieldEntity systemField : entity.getFields().stream().filter(x -> x.getCategory() == DmpBlueprintFieldCategory.System).map(x -> (SystemFieldEntity) x).toList()) {
dmpBlueprintSystemFieldModels.add(this.systemFieldXmlToExport(systemField));
@ -510,7 +510,7 @@ public class DmpBlueprintServiceImpl implements DmpBlueprintService {
}
xml.setSystemFields(dmpBlueprintSystemFieldModels);
List<ExtraFieldImportExport> dmpBlueprintExtraFieldModels = new LinkedList<>();
List<BlueprintExtraFieldImportExport> dmpBlueprintExtraFieldModels = new LinkedList<>();
if (!this.conventionService.isListNullOrEmpty(entity.getFields())) {
for (ExtraFieldEntity systemField : entity.getFields().stream().filter(x -> x.getCategory() == DmpBlueprintFieldCategory.Extra).map(x -> (ExtraFieldEntity) x).toList()) {
dmpBlueprintExtraFieldModels.add(this.extraFieldXmlToExport(systemField));
@ -518,7 +518,7 @@ public class DmpBlueprintServiceImpl implements DmpBlueprintService {
}
xml.setExtraFields(dmpBlueprintExtraFieldModels);
List<ReferenceTypeFieldImportExport> dmpBlueprintReferenceFieldModels = new LinkedList<>();
List<BlueprintReferenceTypeFieldImportExport> dmpBlueprintReferenceFieldModels = new LinkedList<>();
if (!this.conventionService.isListNullOrEmpty(entity.getFields())) {
for (ReferenceTypeFieldEntity referenceTypeFieldEntity : entity.getFields().stream().filter(x -> x.getCategory() == DmpBlueprintFieldCategory.ReferenceType).map(x -> (ReferenceTypeFieldEntity) x).toList()) {
dmpBlueprintReferenceFieldModels.add(this.referenceFieldXmlToExport(referenceTypeFieldEntity));
@ -526,7 +526,7 @@ public class DmpBlueprintServiceImpl implements DmpBlueprintService {
}
xml.setReferenceFields(dmpBlueprintReferenceFieldModels);
List<DescriptionTemplateImportExport> dmpBlueprintDescriptionTemplates = new LinkedList<>();
List<BlueprintDescriptionTemplateImportExport> dmpBlueprintDescriptionTemplates = new LinkedList<>();
if (!this.conventionService.isListNullOrEmpty(entity.getDescriptionTemplates())) {
for (DescriptionTemplateEntity descriptionTemplate : entity.getDescriptionTemplates()) {
dmpBlueprintDescriptionTemplates.add(this.descriptionTemplateXmlToExport(descriptionTemplate));
@ -536,8 +536,8 @@ public class DmpBlueprintServiceImpl implements DmpBlueprintService {
return xml;
}
private DescriptionTemplateImportExport descriptionTemplateXmlToExport(DescriptionTemplateEntity entity) {
DescriptionTemplateImportExport xml = new DescriptionTemplateImportExport();
private BlueprintDescriptionTemplateImportExport descriptionTemplateXmlToExport(DescriptionTemplateEntity entity) {
BlueprintDescriptionTemplateImportExport xml = new BlueprintDescriptionTemplateImportExport();
xml.setDescriptionTemplateGroupId(entity.getDescriptionTemplateGroupId());
xml.setLabel(entity.getLabel());
if (entity.getMinMultiplicity() != null ) xml.setMinMultiplicity(entity.getMinMultiplicity());
@ -545,8 +545,8 @@ public class DmpBlueprintServiceImpl implements DmpBlueprintService {
return xml;
}
private ExtraFieldImportExport extraFieldXmlToExport(ExtraFieldEntity entity) {
ExtraFieldImportExport xml = new ExtraFieldImportExport();
private BlueprintExtraFieldImportExport extraFieldXmlToExport(ExtraFieldEntity entity) {
BlueprintExtraFieldImportExport xml = new BlueprintExtraFieldImportExport();
xml.setId(entity.getId());
xml.setType(entity.getType());
xml.setLabel(entity.getLabel());
@ -557,8 +557,8 @@ public class DmpBlueprintServiceImpl implements DmpBlueprintService {
return xml;
}
private ReferenceTypeFieldImportExport referenceFieldXmlToExport(ReferenceTypeFieldEntity entity) {
ReferenceTypeFieldImportExport xml = new ReferenceTypeFieldImportExport();
private BlueprintReferenceTypeFieldImportExport referenceFieldXmlToExport(ReferenceTypeFieldEntity entity) {
BlueprintReferenceTypeFieldImportExport xml = new BlueprintReferenceTypeFieldImportExport();
xml.setId(entity.getId());
xml.setReferenceTypeId(entity.getReferenceTypeId());
xml.setLabel(entity.getLabel());
@ -570,8 +570,8 @@ public class DmpBlueprintServiceImpl implements DmpBlueprintService {
return xml;
}
private SystemFieldImportExport systemFieldXmlToExport(SystemFieldEntity entity) {
SystemFieldImportExport xml = new SystemFieldImportExport();
private BlueprintSystemFieldImportExport systemFieldXmlToExport(SystemFieldEntity entity) {
BlueprintSystemFieldImportExport xml = new BlueprintSystemFieldImportExport();
xml.setId(entity.getId());
xml.setType(entity.getType());
xml.setLabel(entity.getLabel());
@ -614,13 +614,13 @@ public class DmpBlueprintServiceImpl implements DmpBlueprintService {
return this.persist(persist, fields);
}
private DefinitionPersist xmlDefinitionToPersist(DefinitionImportExport importXml) {
private DefinitionPersist xmlDefinitionToPersist(BlueprintDefinitionImportExport importXml) {
if (importXml == null)
return null;
DefinitionPersist persist = new DefinitionPersist();
List<SectionPersist> dmpBlueprintSections = new ArrayList<>();
if (!this.conventionService.isListNullOrEmpty(importXml.getSections())) {
for (SectionImportExport section : importXml.getSections()) {
for (BlueprintSectionImportExport section : importXml.getSections()) {
dmpBlueprintSections.add(this.xmlSectionToPersist(section));
}
}
@ -628,7 +628,7 @@ public class DmpBlueprintServiceImpl implements DmpBlueprintService {
return persist;
}
private SectionPersist xmlSectionToPersist(SectionImportExport importXml) {
private SectionPersist xmlSectionToPersist(BlueprintSectionImportExport importXml) {
SectionPersist persist = new SectionPersist();
persist.setId(importXml.getId());
persist.setLabel(importXml.getLabel());
@ -637,24 +637,24 @@ public class DmpBlueprintServiceImpl implements DmpBlueprintService {
persist.setHasTemplates(importXml.isHasTemplates());
List<FieldPersist> dmpBlueprintFieldModels = new LinkedList<>();
if (!this.conventionService.isListNullOrEmpty(importXml.getSystemFields())) {
for (SystemFieldImportExport systemField : importXml.getSystemFields()) {
for (BlueprintSystemFieldImportExport systemField : importXml.getSystemFields()) {
dmpBlueprintFieldModels.add(this.xmlSystemFieldToPersist(systemField));
}
}
if (!this.conventionService.isListNullOrEmpty(importXml.getReferenceFields())) {
for (ReferenceTypeFieldImportExport referenceField : importXml.getReferenceFields()) {
for (BlueprintReferenceTypeFieldImportExport referenceField : importXml.getReferenceFields()) {
dmpBlueprintFieldModels.add(this.xmlReferenceFieldToPersist(referenceField));
}
}
if (!this.conventionService.isListNullOrEmpty(importXml.getExtraFields())) {
for (ExtraFieldImportExport extraField : importXml.getExtraFields()) {
for (BlueprintExtraFieldImportExport extraField : importXml.getExtraFields()) {
dmpBlueprintFieldModels.add(this.xmlExtraFieldToPersist(extraField));
}
}
persist.setFields(dmpBlueprintFieldModels);
List<DescriptionTemplatePersist> dmpBlueprintDescriptionTemplates = new LinkedList<>();
if (!this.conventionService.isListNullOrEmpty(importXml.getDescriptionTemplates())) {
for (DescriptionTemplateImportExport descriptionTemplate : importXml.getDescriptionTemplates()) {
for (BlueprintDescriptionTemplateImportExport descriptionTemplate : importXml.getDescriptionTemplates()) {
dmpBlueprintDescriptionTemplates.add(this.xmlDescriptionTemplateToPersist(descriptionTemplate));
}
}
@ -662,7 +662,7 @@ public class DmpBlueprintServiceImpl implements DmpBlueprintService {
return persist;
}
private DescriptionTemplatePersist xmlDescriptionTemplateToPersist(DescriptionTemplateImportExport importXml) {
private DescriptionTemplatePersist xmlDescriptionTemplateToPersist(BlueprintDescriptionTemplateImportExport importXml) {
DescriptionTemplatePersist persist = new DescriptionTemplatePersist();
persist.setDescriptionTemplateGroupId(importXml.getDescriptionTemplateGroupId());
persist.setLabel(importXml.getLabel());
@ -671,7 +671,7 @@ public class DmpBlueprintServiceImpl implements DmpBlueprintService {
return persist;
}
private FieldPersist xmlExtraFieldToPersist(ExtraFieldImportExport importXml) {
private FieldPersist xmlExtraFieldToPersist(BlueprintExtraFieldImportExport importXml) {
ExtraFieldPersist persist = new ExtraFieldPersist();
persist.setId(importXml.getId());
persist.setCategory(DmpBlueprintFieldCategory.Extra);
@ -684,7 +684,7 @@ public class DmpBlueprintServiceImpl implements DmpBlueprintService {
return persist;
}
private FieldPersist xmlSystemFieldToPersist(SystemFieldImportExport importXml) {
private FieldPersist xmlSystemFieldToPersist(BlueprintSystemFieldImportExport importXml) {
SystemFieldPersist persist = new SystemFieldPersist();
persist.setId(importXml.getId());
persist.setCategory(DmpBlueprintFieldCategory.System);
@ -697,7 +697,7 @@ public class DmpBlueprintServiceImpl implements DmpBlueprintService {
return persist;
}
private FieldPersist xmlReferenceFieldToPersist(ReferenceTypeFieldImportExport importXml) {
private FieldPersist xmlReferenceFieldToPersist(BlueprintReferenceTypeFieldImportExport importXml) {
ReferenceTypeFieldPersist persist = new ReferenceTypeFieldPersist();
persist.setId(importXml.getId());
persist.setCategory(DmpBlueprintFieldCategory.ReferenceType);

View File

@ -46,11 +46,13 @@ import org.springframework.http.ResponseEntity;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
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;
@ -121,7 +123,7 @@ public class DescriptionController {
DescriptionQuery query = this.queryFactory.query(DescriptionQuery.class).authorize(EnumSet.of(Public)).ids(id).dmpSubQuery(this.queryFactory.query(DmpQuery.class).isActive(IsActive.Active).statuses(DmpStatus.Finalized).accessTypes(DmpAccessType.Public));
PublicDescription model = this.builderFactory.builder(PublicDescriptionBuilder.class).authorize(EnumSet.of(Public)).build(fieldSet, query.firstAs(fieldSet));
if (model == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{id, PublicDescription.class.getSimpleName()}, LocaleContextHolder.getLocale()));
if (model == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{id, PublicDescription.class.getSimpleName()}, LocaleContextHolder.getLocale()));
this.auditService.track(AuditableAction.Description_PublicLookup, Map.ofEntries(
new AbstractMap.SimpleEntry<String, Object>("id", id),
@ -154,7 +156,7 @@ public class DescriptionController {
DescriptionQuery query = this.queryFactory.query(DescriptionQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).ids(id);
Description model = this.builderFactory.builder(DescriptionBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(fieldSet, query.firstAs(fieldSet));
if (model == null)
throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{id, Description.class.getSimpleName()}, LocaleContextHolder.getLocale()));
throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{id, Description.class.getSimpleName()}, LocaleContextHolder.getLocale()));
this.auditService.track(AuditableAction.Description_Lookup, Map.ofEntries(
new AbstractMap.SimpleEntry<String, Object>("id", id),
@ -208,7 +210,7 @@ public class DescriptionController {
}
@GetMapping("validate")
public List<DescriptionValidationResult> validate(@RequestParam(value="descriptionIds") List<UUID> descriptionIds) throws MyApplicationException, MyForbiddenException, MyNotFoundException, InvalidApplicationException {
public List<DescriptionValidationResult> validate(@RequestParam("descriptionIds") List<UUID> descriptionIds) throws MyApplicationException, MyForbiddenException, MyNotFoundException, InvalidApplicationException {
logger.debug(new MapLogEntry("validating" + Description.class.getSimpleName()).And("descriptionIds", descriptionIds));
this.censorFactory.censor(DescriptionCensor.class).censor(null, null);
@ -261,7 +263,7 @@ public class DescriptionController {
StorageFileEntity storageFile = this.descriptionService.getFieldFile(id, fileId);
byte[] file = this.storageFileService.readAsBytesSafe(id);
if (file == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{id, StorageFile.class.getSimpleName()}, LocaleContextHolder.getLocale()));
if (file == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{id, StorageFile.class.getSimpleName()}, LocaleContextHolder.getLocale()));
this.auditService.track(AuditableAction.Description_GetFieldFile, Map.ofEntries(
new AbstractMap.SimpleEntry<String, Object>("id", id)
@ -289,4 +291,16 @@ public class DescriptionController {
return true;
}
@RequestMapping(method = RequestMethod.GET, value = {"/xml/export/{id}"}, produces = "application/xml")
public @ResponseBody ResponseEntity<byte[]> getXml(@PathVariable UUID id) throws JAXBException, ParserConfigurationException, IOException, InstantiationException, IllegalAccessException, SAXException, InvalidApplicationException {
logger.debug(new MapLogEntry("export" + DmpBlueprint.class.getSimpleName()).And("id", id));
ResponseEntity<byte[]> response = this.descriptionService.exportXml(id);
this.auditService.track(AuditableAction.DmpBlueprint_GetXml, Map.ofEntries(
new AbstractMap.SimpleEntry<String, Object>("id", id)
));
return response;
}
}

View File

@ -34,6 +34,7 @@ import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.http.ResponseEntity;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import org.xml.sax.SAXException;
import javax.crypto.BadPaddingException;
import javax.crypto.IllegalBlockSizeException;
@ -331,4 +332,16 @@ public class DmpController {
return true;
}
@RequestMapping(method = RequestMethod.GET, value = {"/xml/export/{id}"}, produces = "application/xml")
public @ResponseBody ResponseEntity<byte[]> getXml(@PathVariable UUID id) throws JAXBException, ParserConfigurationException, IOException, InstantiationException, IllegalAccessException, SAXException, InvalidApplicationException {
logger.debug(new MapLogEntry("export" + DmpBlueprint.class.getSimpleName()).And("id", id));
ResponseEntity<byte[]> response = this.dmpService.exportXml(id);
this.auditService.track(AuditableAction.DmpBlueprint_GetXml, Map.ofEntries(
new AbstractMap.SimpleEntry<String, Object>("id", id)
));
return response;
}
}

View File

@ -221,6 +221,18 @@ permissions:
clients: [ ]
allowAnonymous: false
allowAuthenticated: false
ExportDescription:
roles:
- TenantAdmin
dmp:
roles:
- Owner
- User
- DescriptionContributor
- Reviewer
clients: [ ]
allowAnonymous: false
allowAuthenticated: false
# Tag
BrowseTag:
roles:

View File

@ -105,6 +105,18 @@ export class DescriptionService {
catchError((error: any) => throwError(error)));
}
downloadXML(id: Guid): Observable<HttpResponse<Blob>> {
const url = `${this.apiBase}/xml/export/${id}`;
let headerXml: HttpHeaders = this.headers.set('Content-Type', 'application/xml');
const params = new BaseHttpParams();
params.interceptorContext = {
excludedInterceptors: [InterceptorType.JSONContentType]
};
return this.httpClient.get(url, { params: params, responseType: 'blob', observe: 'response', headers: headerXml });
}
// public downloadPDF(id: string): Observable<HttpResponse<Blob>> {
// return this.httpClient.get(`${this.apiBase}/${id}/export/Pdf`, { responseType: 'blob', observe: 'response', headers: this.headers });
// }

View File

@ -10,6 +10,7 @@ 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';
import { DescriptionService } from '../description/description.service';
@Injectable()
export class FileTransformerService extends BaseService {
@ -19,6 +20,7 @@ export class FileTransformerService extends BaseService {
private matomoService: MatomoService,
private fileUtils: FileUtils,
private dmpService: DmpService,
private descriptionService: DescriptionService,
private authentication: AuthService,
) { super(); }
@ -94,6 +96,15 @@ export class FileTransformerService extends BaseService {
exportDescription(id: Guid, repositoryId: string, format: string) {
this._loading = true;
if (repositoryId == this.xmlExportRepo.repositoryId) {
this.descriptionService.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);
});
} else {
this.fileTransformerHttpService.exportDescription(id, repositoryId, format).pipe(takeUntil(this._destroyed), catchError((error) => {
this._loading = false;
return null;
@ -107,4 +118,5 @@ export class FileTransformerService extends BaseService {
}
});
}
}
}