Compare commits

...

2 Commits

11 changed files with 373 additions and 216 deletions

View File

@ -3,6 +3,7 @@ package org.opencdmp.commons.types.dmp.importexport;
import jakarta.xml.bind.annotation.XmlAccessType; import jakarta.xml.bind.annotation.XmlAccessType;
import jakarta.xml.bind.annotation.XmlAccessorType; import jakarta.xml.bind.annotation.XmlAccessorType;
import jakarta.xml.bind.annotation.XmlElement; import jakarta.xml.bind.annotation.XmlElement;
import org.opencdmp.commons.enums.ReferenceSourceType;
import java.util.UUID; import java.util.UUID;
@ -19,6 +20,10 @@ public class DmpReferenceImportExport {
private UUID fieldId; private UUID fieldId;
@XmlElement(name = "type") @XmlElement(name = "type")
private DmpReferenceTypeImportExport type; private DmpReferenceTypeImportExport type;
@XmlElement(name = "source")
private String source;
@XmlElement(name = "sourceType")
private ReferenceSourceType sourceType;
public UUID getId() { public UUID getId() {
return this.id; return this.id;
@ -59,4 +64,20 @@ public class DmpReferenceImportExport {
public void setFieldId(UUID fieldId) { public void setFieldId(UUID fieldId) {
this.fieldId = fieldId; this.fieldId = fieldId;
} }
public String getSource() {
return this.source;
}
public void setSource(String source) {
this.source = source;
}
public ReferenceSourceType getSourceType() {
return this.sourceType;
}
public void setSourceType(ReferenceSourceType sourceType) {
this.sourceType = sourceType;
}
} }

View File

@ -6,7 +6,7 @@ public class DmpReferenceDataEntity {
private UUID blueprintFieldId; private UUID blueprintFieldId;
public UUID getBlueprintFieldId() { public UUID getBlueprintFieldId() {
return blueprintFieldId; return this.blueprintFieldId;
} }
public void setBlueprintFieldId(UUID blueprintFieldId) { public void setBlueprintFieldId(UUID blueprintFieldId) {

View File

@ -1,9 +1,9 @@
package org.opencdmp.model.persist; package org.opencdmp.model.persist;
import org.opencdmp.commons.enums.ReferenceSourceType;
import org.opencdmp.commons.validation.BaseValidator;
import gr.cite.tools.validation.ValidatorFactory; import gr.cite.tools.validation.ValidatorFactory;
import gr.cite.tools.validation.specification.Specification; import gr.cite.tools.validation.specification.Specification;
import org.opencdmp.commons.enums.ReferenceSourceType;
import org.opencdmp.commons.validation.BaseValidator;
import org.opencdmp.convention.ConventionService; import org.opencdmp.convention.ConventionService;
import org.opencdmp.data.ReferenceEntity; import org.opencdmp.data.ReferenceEntity;
import org.opencdmp.errorcode.ErrorThesaurusProperties; import org.opencdmp.errorcode.ErrorThesaurusProperties;
@ -57,7 +57,7 @@ public class ReferencePersist {
public static final String _hash = "hash"; public static final String _hash = "hash";
public UUID getId() { public UUID getId() {
return id; return this.id;
} }
public void setId(UUID id) { public void setId(UUID id) {
@ -65,7 +65,7 @@ public class ReferencePersist {
} }
public String getLabel() { public String getLabel() {
return label; return this.label;
} }
public void setLabel(String label) { public void setLabel(String label) {
@ -73,7 +73,7 @@ public class ReferencePersist {
} }
public UUID getTypeId() { public UUID getTypeId() {
return typeId; return this.typeId;
} }
public void setTypeId(UUID typeId) { public void setTypeId(UUID typeId) {
@ -81,7 +81,7 @@ public class ReferencePersist {
} }
public String getDescription() { public String getDescription() {
return description; return this.description;
} }
public void setDescription(String description) { public void setDescription(String description) {
@ -89,7 +89,7 @@ public class ReferencePersist {
} }
public DefinitionPersist getDefinition() { public DefinitionPersist getDefinition() {
return definition; return this.definition;
} }
public void setDefinition(DefinitionPersist definition) { public void setDefinition(DefinitionPersist definition) {
@ -97,7 +97,7 @@ public class ReferencePersist {
} }
public String getReference() { public String getReference() {
return reference; return this.reference;
} }
public void setReference(String reference) { public void setReference(String reference) {
@ -105,7 +105,7 @@ public class ReferencePersist {
} }
public String getAbbreviation() { public String getAbbreviation() {
return abbreviation; return this.abbreviation;
} }
public void setAbbreviation(String abbreviation) { public void setAbbreviation(String abbreviation) {
@ -113,7 +113,7 @@ public class ReferencePersist {
} }
public String getSource() { public String getSource() {
return source; return this.source;
} }
public void setSource(String source) { public void setSource(String source) {
@ -121,7 +121,7 @@ public class ReferencePersist {
} }
public ReferenceSourceType getSourceType() { public ReferenceSourceType getSourceType() {
return sourceType; return this.sourceType;
} }
public void setSourceType(ReferenceSourceType sourceType) { public void setSourceType(ReferenceSourceType sourceType) {
@ -129,7 +129,7 @@ public class ReferencePersist {
} }
public String getHash() { public String getHash() {
return hash; return this.hash;
} }
public void setHash(String hash) { public void setHash(String hash) {
@ -163,42 +163,42 @@ public class ReferencePersist {
this.spec() this.spec()
.iff(() -> this.isValidGuid(item.getId())) .iff(() -> this.isValidGuid(item.getId()))
.must(() -> this.isValidHash(item.getHash())) .must(() -> this.isValidHash(item.getHash()))
.failOn(ReferencePersist._hash).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferencePersist._hash}, LocaleContextHolder.getLocale())), .failOn(ReferencePersist._hash).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{ReferencePersist._hash}, LocaleContextHolder.getLocale())),
this.spec() this.spec()
.iff(() -> !this.isValidGuid(item.getId())) .iff(() -> !this.isValidGuid(item.getId()))
.must(() -> !this.isValidHash(item.getHash())) .must(() -> !this.isValidHash(item.getHash()))
.failOn(ReferencePersist._hash).failWith(messageSource.getMessage("Validation_OverPosting", new Object[]{}, LocaleContextHolder.getLocale())), .failOn(ReferencePersist._hash).failWith(this.messageSource.getMessage("Validation_OverPosting", new Object[]{}, LocaleContextHolder.getLocale())),
this.spec() this.spec()
.must(() -> !this.isEmpty(item.getLabel())) .must(() -> !this.isEmpty(item.getLabel()))
.failOn(ReferencePersist._label).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferencePersist._label}, LocaleContextHolder.getLocale())), .failOn(ReferencePersist._label).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{ReferencePersist._label}, LocaleContextHolder.getLocale())),
this.spec() this.spec()
.iff(() -> !this.isEmpty(item.getLabel())) .iff(() -> !this.isEmpty(item.getLabel()))
.must(() -> this.lessEqualLength(item.getLabel(), ReferenceEntity._labelLength)) .must(() -> this.lessEqualLength(item.getLabel(), ReferenceEntity._labelLength))
.failOn(ReferencePersist._label).failWith(messageSource.getMessage("Validation_MaxLength", new Object[]{ReferencePersist._label}, LocaleContextHolder.getLocale())), .failOn(ReferencePersist._label).failWith(this.messageSource.getMessage("Validation_MaxLength", new Object[]{ReferencePersist._label}, LocaleContextHolder.getLocale())),
this.spec() this.spec()
.must(() -> this.isValidGuid(item.getTypeId())) .must(() -> this.isValidGuid(item.getTypeId()))
.failOn(ReferencePersist._typeId).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferencePersist._typeId}, LocaleContextHolder.getLocale())), .failOn(ReferencePersist._typeId).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{ReferencePersist._typeId}, LocaleContextHolder.getLocale())),
this.spec() this.spec()
.must(() -> !this.isEmpty(item.getReference())) .must(() -> !this.isEmpty(item.getReference()))
.failOn(ReferencePersist._reference).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferencePersist._reference}, LocaleContextHolder.getLocale())), .failOn(ReferencePersist._reference).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{ReferencePersist._reference}, LocaleContextHolder.getLocale())),
this.spec() this.spec()
.iff(() -> !this.isEmpty(item.getReference())) .iff(() -> !this.isEmpty(item.getReference()))
.must(() -> this.lessEqualLength(item.getReference(), ReferenceEntity._referenceLength)) .must(() -> this.lessEqualLength(item.getReference(), ReferenceEntity._referenceLength))
.failOn(ReferencePersist._reference).failWith(messageSource.getMessage("Validation_MaxLength", new Object[]{ReferencePersist._reference}, LocaleContextHolder.getLocale())), .failOn(ReferencePersist._reference).failWith(this.messageSource.getMessage("Validation_MaxLength", new Object[]{ReferencePersist._reference}, LocaleContextHolder.getLocale())),
this.spec() this.spec()
.iff(() -> !this.isEmpty(item.getAbbreviation())) .iff(() -> !this.isEmpty(item.getAbbreviation()))
.must(() -> this.lessEqualLength(item.getAbbreviation(), ReferenceEntity._abbreviationLength)) .must(() -> this.lessEqualLength(item.getAbbreviation(), ReferenceEntity._abbreviationLength))
.failOn(ReferencePersist._abbreviation).failWith(messageSource.getMessage("Validation_MaxLength", new Object[]{ReferencePersist._abbreviation}, LocaleContextHolder.getLocale())), .failOn(ReferencePersist._abbreviation).failWith(this.messageSource.getMessage("Validation_MaxLength", new Object[]{ReferencePersist._abbreviation}, LocaleContextHolder.getLocale())),
this.spec() this.spec()
.must(() -> !this.isEmpty(item.getSource())) .must(() -> !this.isEmpty(item.getSource()))
.failOn(ReferencePersist._source).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferencePersist._source}, LocaleContextHolder.getLocale())), .failOn(ReferencePersist._source).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{ReferencePersist._source}, LocaleContextHolder.getLocale())),
this.spec() this.spec()
.iff(() -> !this.isEmpty(item.getSource())) .iff(() -> !this.isEmpty(item.getSource()))
.must(() -> this.lessEqualLength(item.getSource(), ReferenceEntity._sourceLength)) .must(() -> this.lessEqualLength(item.getSource(), ReferenceEntity._sourceLength))
.failOn(ReferencePersist._source).failWith(messageSource.getMessage("Validation_MaxLength", new Object[]{ReferencePersist._source}, LocaleContextHolder.getLocale())), .failOn(ReferencePersist._source).failWith(this.messageSource.getMessage("Validation_MaxLength", new Object[]{ReferencePersist._source}, LocaleContextHolder.getLocale())),
this.spec() this.spec()
.must(() -> !this.isNull(item.getSourceType())) .must(() -> !this.isNull(item.getSourceType()))
.failOn(ReferencePersist._sourceType).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferencePersist._sourceType}, LocaleContextHolder.getLocale())), .failOn(ReferencePersist._sourceType).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{ReferencePersist._sourceType}, LocaleContextHolder.getLocale())),
this.refSpec() this.refSpec()
.iff(() -> !this.isNull(item.getDefinition())) .iff(() -> !this.isNull(item.getDefinition()))
.on(ReferencePersist._definition) .on(ReferencePersist._definition)
@ -234,32 +234,32 @@ public class ReferencePersist {
return Arrays.asList( return Arrays.asList(
this.spec() this.spec()
.must(() -> !this.isEmpty(item.getLabel())) .must(() -> !this.isEmpty(item.getLabel()))
.failOn(ReferencePersist._label).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferencePersist._label}, LocaleContextHolder.getLocale())), .failOn(ReferencePersist._label).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{ReferencePersist._label}, LocaleContextHolder.getLocale())),
this.spec() this.spec()
.iff(() -> !this.isEmpty(item.getLabel())) .iff(() -> !this.isEmpty(item.getLabel()))
.must(() -> this.lessEqualLength(item.getLabel(), ReferenceEntity._labelLength)) .must(() -> this.lessEqualLength(item.getLabel(), ReferenceEntity._labelLength))
.failOn(ReferencePersist._label).failWith(messageSource.getMessage("Validation_MaxLength", new Object[]{ReferencePersist._label}, LocaleContextHolder.getLocale())), .failOn(ReferencePersist._label).failWith(this.messageSource.getMessage("Validation_MaxLength", new Object[]{ReferencePersist._label}, LocaleContextHolder.getLocale())),
this.spec() this.spec()
.must(() -> !this.isEmpty(item.getReference())) .must(() -> !this.isEmpty(item.getReference()))
.failOn(ReferencePersist._reference).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferencePersist._reference}, LocaleContextHolder.getLocale())), .failOn(ReferencePersist._reference).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{ReferencePersist._reference}, LocaleContextHolder.getLocale())),
this.spec() this.spec()
.iff(() -> !this.isEmpty(item.getReference())) .iff(() -> !this.isEmpty(item.getReference()))
.must(() -> this.lessEqualLength(item.getReference(), ReferenceEntity._referenceLength)) .must(() -> this.lessEqualLength(item.getReference(), ReferenceEntity._referenceLength))
.failOn(ReferencePersist._reference).failWith(messageSource.getMessage("Validation_MaxLength", new Object[]{ReferencePersist._reference}, LocaleContextHolder.getLocale())), .failOn(ReferencePersist._reference).failWith(this.messageSource.getMessage("Validation_MaxLength", new Object[]{ReferencePersist._reference}, LocaleContextHolder.getLocale())),
this.spec() this.spec()
.iff(() -> !this.isEmpty(item.getAbbreviation())) .iff(() -> !this.isEmpty(item.getAbbreviation()))
.must(() -> this.lessEqualLength(item.getAbbreviation(), ReferenceEntity._abbreviationLength)) .must(() -> this.lessEqualLength(item.getAbbreviation(), ReferenceEntity._abbreviationLength))
.failOn(ReferencePersist._abbreviation).failWith(messageSource.getMessage("Validation_MaxLength", new Object[]{ReferencePersist._abbreviation}, LocaleContextHolder.getLocale())), .failOn(ReferencePersist._abbreviation).failWith(this.messageSource.getMessage("Validation_MaxLength", new Object[]{ReferencePersist._abbreviation}, LocaleContextHolder.getLocale())),
this.spec() this.spec()
.must(() -> !this.isEmpty(item.getSource())) .must(() -> !this.isEmpty(item.getSource()))
.failOn(ReferencePersist._source).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferencePersist._source}, LocaleContextHolder.getLocale())), .failOn(ReferencePersist._source).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{ReferencePersist._source}, LocaleContextHolder.getLocale())),
this.spec() this.spec()
.iff(() -> !this.isEmpty(item.getSource())) .iff(() -> !this.isEmpty(item.getSource()))
.must(() -> this.lessEqualLength(item.getSource(), ReferenceEntity._sourceLength)) .must(() -> this.lessEqualLength(item.getSource(), ReferenceEntity._sourceLength))
.failOn(ReferencePersist._source).failWith(messageSource.getMessage("Validation_MaxLength", new Object[]{ReferencePersist._source}, LocaleContextHolder.getLocale())), .failOn(ReferencePersist._source).failWith(this.messageSource.getMessage("Validation_MaxLength", new Object[]{ReferencePersist._source}, LocaleContextHolder.getLocale())),
this.spec() this.spec()
.must(() -> !this.isNull(item.getSourceType())) .must(() -> !this.isNull(item.getSourceType()))
.failOn(ReferencePersist._sourceType).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferencePersist._sourceType}, LocaleContextHolder.getLocale())), .failOn(ReferencePersist._sourceType).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{ReferencePersist._sourceType}, LocaleContextHolder.getLocale())),
this.refSpec() this.refSpec()
.iff(() -> !this.isNull(item.getDefinition())) .iff(() -> !this.isNull(item.getDefinition()))
.on(ReferencePersist._definition) .on(ReferencePersist._definition)

View File

@ -63,7 +63,7 @@ public class DmpBlueprintValuePersist {
} }
public Instant getDateValue() { public Instant getDateValue() {
return dateValue; return this.dateValue;
} }
public void setDateValue(Instant dateValue) { public void setDateValue(Instant dateValue) {
@ -71,7 +71,7 @@ public class DmpBlueprintValuePersist {
} }
public Double getNumberValue() { public Double getNumberValue() {
return numberValue; return this.numberValue;
} }
public void setNumberValue(Double numberValue) { public void setNumberValue(Double numberValue) {
@ -124,22 +124,22 @@ public class DmpBlueprintValuePersist {
protected List<Specification> specifications(DmpBlueprintValuePersist item) { protected List<Specification> specifications(DmpBlueprintValuePersist item) {
this.fieldEntity = this.definition != null && this.isValidGuid(item.getFieldId())? this.definition.getFieldById(item.getFieldId()).stream().findFirst().orElse(null) : null; this.fieldEntity = this.definition != null && this.isValidGuid(item.getFieldId())? this.definition.getFieldById(item.getFieldId()).stream().findFirst().orElse(null) : null;
boolean required = this.fieldEntity != null && this.fieldEntity.isRequired(); boolean required = this.fieldEntity != null && this.fieldEntity.isRequired();
if (this.fieldEntity.getCategory().equals(DmpBlueprintFieldCategory.Extra)) this.extraFieldEntity = (ExtraFieldEntity) fieldEntity; if (this.fieldEntity.getCategory().equals(DmpBlueprintFieldCategory.Extra)) this.extraFieldEntity = (ExtraFieldEntity) this.fieldEntity;
return Arrays.asList( return Arrays.asList(
this.spec() this.spec()
.must(() -> this.isValidGuid(item.getFieldId())) .must(() -> this.isValidGuid(item.getFieldId()))
.failOn(DmpBlueprintValuePersist._fieldId).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{DmpBlueprintValuePersist._fieldId}, LocaleContextHolder.getLocale())), .failOn(DmpBlueprintValuePersist._fieldId).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{DmpBlueprintValuePersist._fieldId}, LocaleContextHolder.getLocale())),
this.spec() this.spec()
.iff(() -> this.extraFieldEntity != null && DmpBlueprintExtraFieldDataType.isTextType(extraFieldEntity.getType()) && this.isListNullOrEmpty(item.getReferences()) && required) .iff(() -> this.extraFieldEntity != null && DmpBlueprintExtraFieldDataType.isTextType(this.extraFieldEntity.getType()) && this.isListNullOrEmpty(item.getReferences()) && required)
.must(() -> !this.isEmpty(item.getFieldValue())) .must(() -> !this.isEmpty(item.getFieldValue()))
.failOn(DmpBlueprintValuePersist._fieldValue).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{this.fieldEntity.getLabel()}, LocaleContextHolder.getLocale())), .failOn(DmpBlueprintValuePersist._fieldValue).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{this.fieldEntity.getLabel()}, LocaleContextHolder.getLocale())),
this.spec() this.spec()
.iff(() -> this.extraFieldEntity != null && DmpBlueprintExtraFieldDataType.isDateType(extraFieldEntity.getType()) && this.isListNullOrEmpty(item.getReferences()) && required) .iff(() -> this.extraFieldEntity != null && DmpBlueprintExtraFieldDataType.isDateType(this.extraFieldEntity.getType()) && this.isListNullOrEmpty(item.getReferences()) && required)
.must(() -> !this.isNull(item.getDateValue())) .must(() -> !this.isNull(item.getDateValue()))
.failOn(DmpBlueprintValuePersist._dateValue).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{this.fieldEntity.getLabel()}, LocaleContextHolder.getLocale())), .failOn(DmpBlueprintValuePersist._dateValue).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{this.fieldEntity.getLabel()}, LocaleContextHolder.getLocale())),
this.spec() this.spec()
.iff(() -> this.extraFieldEntity != null && DmpBlueprintExtraFieldDataType.isNumberType(extraFieldEntity.getType()) && this.isListNullOrEmpty(item.getReferences()) && required) .iff(() -> this.extraFieldEntity != null && DmpBlueprintExtraFieldDataType.isNumberType(this.extraFieldEntity.getType()) && this.isListNullOrEmpty(item.getReferences()) && required)
.must(() -> !this.isNull(item.getNumberValue())) .must(() -> !this.isNull(item.getNumberValue()))
.failOn(DmpBlueprintValuePersist._numberValue).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{this.fieldEntity.getLabel()}, LocaleContextHolder.getLocale())), .failOn(DmpBlueprintValuePersist._numberValue).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{this.fieldEntity.getLabel()}, LocaleContextHolder.getLocale())),
this.spec() this.spec()

View File

@ -53,7 +53,7 @@ public interface DescriptionService {
ResponseEntity<byte[]> exportXml(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;
Description importXml(DescriptionImportExport descriptionXml, UUID dmpId, List<DmpDescriptionTemplateEntity> dmpDescriptionTemplates, FieldSet fields) throws MyForbiddenException, MyNotFoundException, JAXBException, ParserConfigurationException, TransformerException, InvalidApplicationException, IOException, InstantiationException, IllegalAccessException, SAXException; Description importXml(DescriptionImportExport descriptionXml, UUID dmpId, FieldSet fields) throws MyForbiddenException, MyNotFoundException, JAXBException, ParserConfigurationException, TransformerException, InvalidApplicationException, IOException, InstantiationException, IllegalAccessException, SAXException;
Description importJson(DescriptionModel model, UUID dmpId, List<DmpDescriptionTemplateEntity> dmpDescriptionTemplates, FieldSet fields) throws MyForbiddenException, MyNotFoundException, InvalidApplicationException, IOException ; Description importJson(DescriptionModel model, UUID dmpId, List<DmpDescriptionTemplateEntity> dmpDescriptionTemplates, FieldSet fields) throws MyForbiddenException, MyNotFoundException, InvalidApplicationException, IOException ;

View File

@ -3,7 +3,6 @@ package org.opencdmp.service.description;
import gr.cite.commons.web.authz.service.AuthorizationService; import gr.cite.commons.web.authz.service.AuthorizationService;
import gr.cite.tools.data.builder.BuilderFactory; import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.data.deleter.DeleterFactory; import gr.cite.tools.data.deleter.DeleterFactory;
import gr.cite.tools.data.query.Ordering;
import gr.cite.tools.data.query.QueryFactory; import gr.cite.tools.data.query.QueryFactory;
import gr.cite.tools.exception.*; import gr.cite.tools.exception.*;
import gr.cite.tools.fieldset.BaseFieldSet; import gr.cite.tools.fieldset.BaseFieldSet;
@ -37,7 +36,9 @@ import org.opencdmp.commons.types.descriptiontemplate.fielddata.UploadDataEntity
import org.opencdmp.commons.types.descriptiontemplate.importexport.DescriptionTemplateFieldImportExport; import org.opencdmp.commons.types.descriptiontemplate.importexport.DescriptionTemplateFieldImportExport;
import org.opencdmp.commons.types.descriptiontemplate.importexport.DescriptionTemplateImportExport; import org.opencdmp.commons.types.descriptiontemplate.importexport.DescriptionTemplateImportExport;
import org.opencdmp.commons.types.descriptiontemplate.importexport.fielddata.ReferenceTypeDataImportExport; import org.opencdmp.commons.types.descriptiontemplate.importexport.fielddata.ReferenceTypeDataImportExport;
import org.opencdmp.commons.types.notification.*; import org.opencdmp.commons.types.notification.DataType;
import org.opencdmp.commons.types.notification.FieldInfo;
import org.opencdmp.commons.types.notification.NotificationFieldData;
import org.opencdmp.commons.types.reference.DefinitionEntity; import org.opencdmp.commons.types.reference.DefinitionEntity;
import org.opencdmp.convention.ConventionService; import org.opencdmp.convention.ConventionService;
import org.opencdmp.data.*; import org.opencdmp.data.*;
@ -48,7 +49,10 @@ import org.opencdmp.integrationevent.outbox.annotationentityremoval.AnnotationEn
import org.opencdmp.integrationevent.outbox.annotationentitytouch.AnnotationEntityTouchedIntegrationEventHandler; import org.opencdmp.integrationevent.outbox.annotationentitytouch.AnnotationEntityTouchedIntegrationEventHandler;
import org.opencdmp.integrationevent.outbox.notification.NotifyIntegrationEvent; import org.opencdmp.integrationevent.outbox.notification.NotifyIntegrationEvent;
import org.opencdmp.integrationevent.outbox.notification.NotifyIntegrationEventHandler; import org.opencdmp.integrationevent.outbox.notification.NotifyIntegrationEventHandler;
import org.opencdmp.model.*; import org.opencdmp.model.DescriptionValidationResult;
import org.opencdmp.model.DmpDescriptionTemplate;
import org.opencdmp.model.StorageFile;
import org.opencdmp.model.Tag;
import org.opencdmp.model.builder.description.DescriptionBuilder; import org.opencdmp.model.builder.description.DescriptionBuilder;
import org.opencdmp.model.deleter.DescriptionDeleter; import org.opencdmp.model.deleter.DescriptionDeleter;
import org.opencdmp.model.deleter.DescriptionReferenceDeleter; import org.opencdmp.model.deleter.DescriptionReferenceDeleter;
@ -56,6 +60,7 @@ import org.opencdmp.model.deleter.DescriptionTagDeleter;
import org.opencdmp.model.description.Description; import org.opencdmp.model.description.Description;
import org.opencdmp.model.descriptiontemplate.DescriptionTemplate; import org.opencdmp.model.descriptiontemplate.DescriptionTemplate;
import org.opencdmp.model.dmp.Dmp; import org.opencdmp.model.dmp.Dmp;
import org.opencdmp.model.dmpblueprint.DmpBlueprint;
import org.opencdmp.model.file.FileEnvelope; import org.opencdmp.model.file.FileEnvelope;
import org.opencdmp.model.persist.*; import org.opencdmp.model.persist.*;
import org.opencdmp.model.persist.descriptionproperties.*; import org.opencdmp.model.persist.descriptionproperties.*;
@ -1281,28 +1286,19 @@ public class DescriptionServiceImpl implements DescriptionService {
//region Import xml //region Import xml
public Description importXml(DescriptionImportExport descriptionXml, UUID dmpId, List<DmpDescriptionTemplateEntity> dmpDescriptionTemplates, FieldSet fields) throws MyForbiddenException, MyNotFoundException, JAXBException, ParserConfigurationException, TransformerException, InvalidApplicationException, IOException, InstantiationException, IllegalAccessException, SAXException{ public Description importXml(DescriptionImportExport descriptionXml, UUID dmpId, FieldSet fields) throws MyForbiddenException, MyNotFoundException, JAXBException, ParserConfigurationException, TransformerException, InvalidApplicationException, IOException, InstantiationException, IllegalAccessException, SAXException{
if (descriptionXml == null) throw new MyNotFoundException("Description xml not found"); if (descriptionXml == null) throw new MyNotFoundException("Description xml not found");
if (this.conventionService.isListNullOrEmpty(dmpDescriptionTemplates)) throw new MyValidationException(this.errors.getImportDescriptionWithoutDmpDescriptionTemplate().getCode(), this.errors.getImportDescriptionWithoutDmpDescriptionTemplate().getMessage()); logger.debug(new MapLogEntry("import description").And("dmpId", dmpId).And("fields", fields));
logger.debug(new MapLogEntry("import description").And("dmpId", dmpId).And("fields", fields));
DescriptionPersist persist = new DescriptionPersist(); DescriptionPersist persist = new DescriptionPersist();
persist.setLabel(descriptionXml.getLabel()); persist.setLabel(descriptionXml.getLabel());
persist.setDescription(descriptionXml.getDescription()); persist.setDescription(descriptionXml.getDescription());
persist.setStatus(DescriptionStatus.Draft); persist.setStatus(DescriptionStatus.Draft);
persist.setDmpId(dmpId); persist.setDmpId(dmpId);
if (descriptionXml.getDescriptionTemplate() != null) { persist.setDescriptionTemplateId(this.xmlToDescriptionTemplatePersist(descriptionXml));
persist.setDescriptionTemplateId(descriptionXml.getDescriptionTemplate().getId()); persist.setDmpDescriptionTemplateId(this.xmlToDmpDescriptionTemplatePersist(descriptionXml, dmpId));
if (!this.conventionService.isListNullOrEmpty(dmpDescriptionTemplates) && descriptionXml.getSectionId() != null && descriptionXml.getDescriptionTemplate().getGroupId() != null){
DmpDescriptionTemplateEntity dmpDescriptionTemplate = dmpDescriptionTemplates.stream().filter(x -> x.getDmpId().equals(dmpId) &&
x.getDescriptionTemplateGroupId().equals(descriptionXml.getDescriptionTemplate().getGroupId()) &&
x.getSectionId().equals(descriptionXml.getSectionId())).findFirst().orElse(null);
if (dmpDescriptionTemplate != null) persist.setDmpDescriptionTemplateId(dmpDescriptionTemplate.getId());
}
}
persist.setTags(descriptionXml.getTags()); persist.setTags(descriptionXml.getTags());
persist.setProperties(this.xmlToPropertyDefinitionToPersist(descriptionXml)); persist.setProperties(this.xmlToPropertyDefinitionToPersist(descriptionXml));
@ -1312,6 +1308,44 @@ public class DescriptionServiceImpl implements DescriptionService {
return this.persist(persist, fields); return this.persist(persist, fields);
} }
private UUID xmlToDescriptionTemplatePersist(DescriptionImportExport descriptionXml) throws JAXBException, InvalidApplicationException, ParserConfigurationException, IOException, TransformerException, InstantiationException, IllegalAccessException, SAXException {
if (descriptionXml.getDescriptionTemplate() != null) {
DescriptionTemplateEntity descriptionTemplateEntity = this.queryFactory.query(DescriptionTemplateQuery.class).disableTracking().ids(descriptionXml.getDescriptionTemplate().getId()).first();
if (descriptionTemplateEntity == null) descriptionTemplateEntity = this.queryFactory.query(DescriptionTemplateQuery.class).disableTracking().groupIds(descriptionXml.getDescriptionTemplate().getGroupId()).versionStatuses(DescriptionTemplateVersionStatus.Current).isActive(IsActive.Active).statuses(DescriptionTemplateStatus.Finalized).first();
UUID descriptionTemplateId;
if (descriptionTemplateEntity != null){
descriptionTemplateId = descriptionTemplateEntity.getId();
} else {
DescriptionTemplate persisted = this.descriptionTemplateService.importXml(descriptionXml.getDescriptionTemplate(), null, descriptionXml.getDescriptionTemplate().getDescription(), new BaseFieldSet().ensure(DmpBlueprint._label).ensure(DmpBlueprint._hash));
descriptionTemplateId = persisted.getId();
}
return descriptionTemplateId;
}
return null;
}
private UUID xmlToDmpDescriptionTemplatePersist(DescriptionImportExport descriptionXml, UUID dmpId) {
if (descriptionXml.getDescriptionTemplate() != null) {
List<DmpDescriptionTemplateEntity> dmpDescriptionTemplates = this.queryFactory.query(DmpDescriptionTemplateQuery.class).disableTracking()
.isActive(IsActive.Active)
.dmpIds(dmpId)
.collect();
if (!this.conventionService.isListNullOrEmpty(dmpDescriptionTemplates) && descriptionXml.getSectionId() != null && descriptionXml.getDescriptionTemplate().getGroupId() != null){
DmpDescriptionTemplateEntity dmpDescriptionTemplate = dmpDescriptionTemplates.stream().filter(x ->
x.getDescriptionTemplateGroupId().equals(descriptionXml.getDescriptionTemplate().getGroupId()) &&
x.getSectionId().equals(descriptionXml.getSectionId())).findFirst().orElse(null);
if (dmpDescriptionTemplate == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{descriptionXml.getDescriptionTemplate().getGroupId(), DmpDescriptionTemplate.class.getSimpleName()}, LocaleContextHolder.getLocale()));
return dmpDescriptionTemplate.getId();
}
}
return null;
}
private PropertyDefinitionPersist xmlToPropertyDefinitionToPersist(DescriptionImportExport descriptionXml) { private PropertyDefinitionPersist xmlToPropertyDefinitionToPersist(DescriptionImportExport descriptionXml) {
if (descriptionXml == null) if (descriptionXml == null)
return null; return null;

View File

@ -26,6 +26,9 @@ public interface DescriptionTemplateService {
void deleteAndSave(UUID id) throws MyForbiddenException, InvalidApplicationException; void deleteAndSave(UUID id) throws MyForbiddenException, InvalidApplicationException;
DescriptionTemplate buildClone(UUID id, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException; 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 createNewVersion(NewVersionDescriptionTemplatePersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException, JAXBException, ParserConfigurationException, JsonProcessingException, TransformerException;
DescriptionTemplate importXml(DescriptionTemplateImportExport importXml, UUID groupId, String label, FieldSet fields) throws MyForbiddenException, MyNotFoundException, JAXBException, ParserConfigurationException, TransformerException, InvalidApplicationException, IOException, InstantiationException, IllegalAccessException, SAXException;
DescriptionTemplate importXml(byte[] bytes, UUID groupId, String label, FieldSet fields) throws MyForbiddenException, MyNotFoundException, JAXBException, ParserConfigurationException, TransformerException, InvalidApplicationException, IOException, InstantiationException, IllegalAccessException, SAXException; DescriptionTemplate importXml(byte[] bytes, UUID groupId, String label, FieldSet fields) throws MyForbiddenException, MyNotFoundException, JAXBException, ParserConfigurationException, TransformerException, InvalidApplicationException, IOException, InstantiationException, IllegalAccessException, SAXException;
DescriptionTemplateImportExport exportXmlEntity(UUID id, boolean ignoreAuthorize) throws MyForbiddenException, MyNotFoundException, JAXBException, ParserConfigurationException, IOException, InstantiationException, IllegalAccessException, SAXException, InvalidApplicationException; DescriptionTemplateImportExport exportXmlEntity(UUID id, boolean ignoreAuthorize) throws MyForbiddenException, MyNotFoundException, JAXBException, ParserConfigurationException, IOException, InstantiationException, IllegalAccessException, SAXException, InvalidApplicationException;

View File

@ -22,14 +22,19 @@ import org.opencdmp.authorization.AuthorizationFlags;
import org.opencdmp.authorization.Permission; import org.opencdmp.authorization.Permission;
import org.opencdmp.commons.JsonHandlingService; import org.opencdmp.commons.JsonHandlingService;
import org.opencdmp.commons.XmlHandlingService; import org.opencdmp.commons.XmlHandlingService;
import org.opencdmp.commons.enums.*; import org.opencdmp.commons.enums.DescriptionTemplateStatus;
import org.opencdmp.commons.enums.DescriptionTemplateVersionStatus;
import org.opencdmp.commons.enums.FieldType;
import org.opencdmp.commons.enums.IsActive;
import org.opencdmp.commons.notification.NotificationProperties; import org.opencdmp.commons.notification.NotificationProperties;
import org.opencdmp.commons.scope.tenant.TenantScope; import org.opencdmp.commons.scope.tenant.TenantScope;
import org.opencdmp.commons.scope.user.UserScope; import org.opencdmp.commons.scope.user.UserScope;
import org.opencdmp.commons.types.descriptiontemplate.*; import org.opencdmp.commons.types.descriptiontemplate.*;
import org.opencdmp.commons.types.descriptiontemplate.fielddata.BaseFieldDataEntity; import org.opencdmp.commons.types.descriptiontemplate.fielddata.BaseFieldDataEntity;
import org.opencdmp.commons.types.descriptiontemplate.importexport.*; import org.opencdmp.commons.types.descriptiontemplate.importexport.*;
import org.opencdmp.commons.types.notification.*; import org.opencdmp.commons.types.notification.DataType;
import org.opencdmp.commons.types.notification.FieldInfo;
import org.opencdmp.commons.types.notification.NotificationFieldData;
import org.opencdmp.convention.ConventionService; import org.opencdmp.convention.ConventionService;
import org.opencdmp.data.DescriptionTemplateEntity; import org.opencdmp.data.DescriptionTemplateEntity;
import org.opencdmp.data.TenantEntityManager; import org.opencdmp.data.TenantEntityManager;
@ -38,7 +43,6 @@ import org.opencdmp.data.UserEntity;
import org.opencdmp.errorcode.ErrorThesaurusProperties; import org.opencdmp.errorcode.ErrorThesaurusProperties;
import org.opencdmp.integrationevent.outbox.notification.NotifyIntegrationEvent; import org.opencdmp.integrationevent.outbox.notification.NotifyIntegrationEvent;
import org.opencdmp.integrationevent.outbox.notification.NotifyIntegrationEventHandler; import org.opencdmp.integrationevent.outbox.notification.NotifyIntegrationEventHandler;
import org.opencdmp.model.UserContactInfo;
import org.opencdmp.model.builder.descriptiontemplate.DescriptionTemplateBuilder; import org.opencdmp.model.builder.descriptiontemplate.DescriptionTemplateBuilder;
import org.opencdmp.model.deleter.DescriptionTemplateDeleter; import org.opencdmp.model.deleter.DescriptionTemplateDeleter;
import org.opencdmp.model.deleter.UserDescriptionTemplateDeleter; import org.opencdmp.model.deleter.UserDescriptionTemplateDeleter;
@ -50,7 +54,6 @@ import org.opencdmp.model.persist.descriptiontemplatedefinition.*;
import org.opencdmp.model.persist.descriptiontemplatedefinition.fielddata.BaseFieldDataPersist; import org.opencdmp.model.persist.descriptiontemplatedefinition.fielddata.BaseFieldDataPersist;
import org.opencdmp.model.user.User; import org.opencdmp.model.user.User;
import org.opencdmp.query.DescriptionTemplateQuery; import org.opencdmp.query.DescriptionTemplateQuery;
import org.opencdmp.query.UserContactInfoQuery;
import org.opencdmp.query.UserDescriptionTemplateQuery; import org.opencdmp.query.UserDescriptionTemplateQuery;
import org.opencdmp.service.fielddatahelper.FieldDataHelperService; import org.opencdmp.service.fielddatahelper.FieldDataHelperService;
import org.opencdmp.service.fielddatahelper.FieldDataHelperServiceProvider; import org.opencdmp.service.fielddatahelper.FieldDataHelperServiceProvider;
@ -664,12 +667,12 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic
//region Import //region Import
public DescriptionTemplate importXml(byte[] bytes, UUID groupId, String label, FieldSet fields) throws MyForbiddenException, MyNotFoundException, JAXBException, ParserConfigurationException, TransformerException, InvalidApplicationException, IOException, InstantiationException, IllegalAccessException, SAXException { @Override
logger.debug(new MapLogEntry("import data").And("bytes", bytes).And("fields", fields)); public DescriptionTemplate importXml(DescriptionTemplateImportExport importXml, UUID groupId, String label, FieldSet fields) throws MyForbiddenException, MyNotFoundException, JAXBException, ParserConfigurationException, TransformerException, InvalidApplicationException, IOException, InstantiationException, IllegalAccessException, SAXException {
logger.debug(new MapLogEntry("import data").And("importXml", importXml).And("fields", fields));
this.authorizationService.authorizeForce(Permission.ImportDescriptionTemplate); this.authorizationService.authorizeForce(Permission.ImportDescriptionTemplate);
DescriptionTemplateImportExport importXml = this.xmlHandlingService.fromXml(DescriptionTemplateImportExport.class, new String(bytes, StandardCharsets.UTF_8));
if (groupId == null) groupId = importXml.getGroupId(); if (groupId == null) groupId = importXml.getGroupId();
long activeDescriptionTemplatesForTheGroup = groupId != null ? this.queryFactory.query(DescriptionTemplateQuery.class).disableTracking() long activeDescriptionTemplatesForTheGroup = groupId != null ? this.queryFactory.query(DescriptionTemplateQuery.class).disableTracking()
@ -689,11 +692,11 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic
return this.persist(persist, groupId, fields); return this.persist(persist, groupId, fields);
} else { } else {
DescriptionTemplateEntity latestVersionDescriptionTemplate = this.queryFactory.query(DescriptionTemplateQuery.class).disableTracking() DescriptionTemplateEntity latestVersionDescriptionTemplate = this.queryFactory.query(DescriptionTemplateQuery.class).disableTracking()
.versionStatuses(DescriptionTemplateVersionStatus.Current) .versionStatuses(DescriptionTemplateVersionStatus.Current)
.isActive(IsActive.Active) .isActive(IsActive.Active)
.statuses(DescriptionTemplateStatus.Finalized) .statuses(DescriptionTemplateStatus.Finalized)
.groupIds(groupId) .groupIds(groupId)
.first(); .first();
if (latestVersionDescriptionTemplate == null) throw new MyValidationException(this.errors.getDescriptionTemplateIsNotFinalized().getCode(), this.errors.getDescriptionTemplateIsNotFinalized().getMessage()); if (latestVersionDescriptionTemplate == null) throw new MyValidationException(this.errors.getDescriptionTemplateIsNotFinalized().getCode(), this.errors.getDescriptionTemplateIsNotFinalized().getMessage());
NewVersionDescriptionTemplatePersist persist = new NewVersionDescriptionTemplatePersist(); NewVersionDescriptionTemplatePersist persist = new NewVersionDescriptionTemplatePersist();
@ -711,6 +714,17 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic
} }
} }
@Override
public DescriptionTemplate importXml(byte[] bytes, UUID groupId, String label, FieldSet fields) throws MyForbiddenException, MyNotFoundException, JAXBException, ParserConfigurationException, TransformerException, InvalidApplicationException, IOException, InstantiationException, IllegalAccessException, SAXException {
logger.debug(new MapLogEntry("import data").And("bytes", bytes).And("fields", fields));
this.authorizationService.authorizeForce(Permission.ImportDescriptionTemplate);
DescriptionTemplateImportExport importXml = this.xmlHandlingService.fromXml(DescriptionTemplateImportExport.class, new String(bytes, StandardCharsets.UTF_8));
return this.importXml(importXml, groupId, label, fields);
}
public DefinitionPersist xmlDefinitionToPersist(DescriptionTemplateImportExport importExport) { public DefinitionPersist xmlDefinitionToPersist(DescriptionTemplateImportExport importExport) {
DefinitionPersist definitionPersist = new DefinitionPersist(); DefinitionPersist definitionPersist = new DefinitionPersist();
if (importExport == null) if (importExport == null)

View File

@ -361,7 +361,7 @@ public class DmpServiceImpl implements DmpService {
.groupIds(data.getGroupId()); .groupIds(data.getGroupId());
dmpQuery.setOrder(new Ordering().addDescending(Dmp._version)); dmpQuery.setOrder(new Ordering().addDescending(Dmp._version));
previousDmp = dmpQuery.count() > 0 ? dmpQuery.collect().get(0) : null; previousDmp = dmpQuery.count() > 0 ? dmpQuery.collect().getFirst() : null;
if (previousDmp != null){ if (previousDmp != null){
if (previousDmp.getStatus().equals(DmpStatus.Finalized)) previousDmp.setVersionStatus(DmpVersionStatus.Current); if (previousDmp.getStatus().equals(DmpStatus.Finalized)) previousDmp.setVersionStatus(DmpVersionStatus.Current);
else previousDmp.setVersionStatus(DmpVersionStatus.NotFinalized); else previousDmp.setVersionStatus(DmpVersionStatus.NotFinalized);
@ -493,12 +493,12 @@ public class DmpServiceImpl implements DmpService {
if (!oldDmpEntity.getBlueprintId().equals(blueprintEntity.getId())){ if (!oldDmpEntity.getBlueprintId().equals(blueprintEntity.getId())){
// add description templates if exists in new blueprint // add description templates if exists in new blueprint
List<SectionEntity> sections = definition.getSections().stream().filter(x -> x.getHasTemplates()).collect(Collectors.toList()); List<SectionEntity> sections = definition.getSections().stream().filter(SectionEntity::getHasTemplates).collect(Collectors.toList());
if (!this.conventionService.isListNullOrEmpty(sections) && !this.conventionService.isListNullOrEmpty(dmpDescriptionTemplateEntities)){ if (!this.conventionService.isListNullOrEmpty(sections) && !this.conventionService.isListNullOrEmpty(dmpDescriptionTemplateEntities)){
for (SectionEntity section: sections) { for (SectionEntity section: sections) {
if (!this.conventionService.isListNullOrEmpty(section.getDescriptionTemplates())){ if (!this.conventionService.isListNullOrEmpty(section.getDescriptionTemplates())){
for (DescriptionTemplateEntity blueprintDescriptionTemplate: section.getDescriptionTemplates()) { for (DescriptionTemplateEntity blueprintDescriptionTemplate: section.getDescriptionTemplates()) {
if (model.getDescriptions().stream().map(x -> x.getBlueprintSectionId()).collect(Collectors.toList()).contains(section.getId())){ if (model.getDescriptions().stream().map(NewVersionDmpDescriptionPersist::getBlueprintSectionId).toList().contains(section.getId())){
DmpDescriptionTemplateEntity existingBlueprintDescriptionTemplateEntity = dmpDescriptionTemplateEntities.stream().filter(x -> x.getSectionId().equals(section.getId()) && x.getDescriptionTemplateGroupId().equals(blueprintDescriptionTemplate.getDescriptionTemplateGroupId())).findFirst().orElse(null); DmpDescriptionTemplateEntity existingBlueprintDescriptionTemplateEntity = dmpDescriptionTemplateEntities.stream().filter(x -> x.getSectionId().equals(section.getId()) && x.getDescriptionTemplateGroupId().equals(blueprintDescriptionTemplate.getDescriptionTemplateGroupId())).findFirst().orElse(null);
if (existingBlueprintDescriptionTemplateEntity == null){ if (existingBlueprintDescriptionTemplateEntity == null){
DmpDescriptionTemplateEntity newTemplate = new DmpDescriptionTemplateEntity(); DmpDescriptionTemplateEntity newTemplate = new DmpDescriptionTemplateEntity();
@ -814,7 +814,7 @@ public class DmpServiceImpl implements DmpService {
private void checkDuplicateDmpUser(List<DmpUserPersist> model){ private void checkDuplicateDmpUser(List<DmpUserPersist> model){
for (DmpUserPersist user: model) { for (DmpUserPersist user: model) {
List<DmpUserPersist> duplicateUser = null; List<DmpUserPersist> duplicateUser;
if (user.getUser() != null){ if (user.getUser() != null){
duplicateUser = model.stream().filter(x -> x.getUser().equals(user.getUser()) && x.getRole().equals(user.getRole()) && Objects.equals(user.getSectionId(), x.getSectionId())).collect(Collectors.toList()); duplicateUser = model.stream().filter(x -> x.getUser().equals(user.getUser()) && x.getRole().equals(user.getRole()) && Objects.equals(user.getSectionId(), x.getSectionId())).collect(Collectors.toList());
} else { } else {
@ -950,8 +950,7 @@ public class DmpServiceImpl implements DmpService {
if (fieldEntity.getCategory().equals(DmpBlueprintFieldCategory.Extra)) { if (fieldEntity.getCategory().equals(DmpBlueprintFieldCategory.Extra)) {
ExtraFieldEntity extraFieldEntity = (ExtraFieldEntity) fieldEntity; ExtraFieldEntity extraFieldEntity = (ExtraFieldEntity) fieldEntity;
if (extraFieldEntity == null) return data; if (DmpBlueprintExtraFieldDataType.isDateType(extraFieldEntity.getType())){
if (DmpBlueprintExtraFieldDataType.isDateType(extraFieldEntity.getType())){
data.setDateValue(persist.getDateValue()); data.setDateValue(persist.getDateValue());
} else if (DmpBlueprintExtraFieldDataType.isNumberType(extraFieldEntity.getType())){ } else if (DmpBlueprintExtraFieldDataType.isNumberType(extraFieldEntity.getType())){
data.setNumberValue(persist.getNumberValue()); data.setNumberValue(persist.getNumberValue());
@ -1215,7 +1214,7 @@ public class DmpServiceImpl implements DmpService {
.groupIds(dmp.getGroupId()); .groupIds(dmp.getGroupId());
dmpQuery.setOrder(new Ordering().addDescending(Dmp._version)); dmpQuery.setOrder(new Ordering().addDescending(Dmp._version));
DmpEntity previousDmp = dmpQuery.count() > 0 ? dmpQuery.collect().get(0) : null; DmpEntity previousDmp = dmpQuery.count() > 0 ? dmpQuery.collect().getFirst() : null;
if (previousDmp != null){ if (previousDmp != null){
if (previousDmp.getStatus().equals(DmpStatus.Finalized)) previousDmp.setVersionStatus(DmpVersionStatus.Current); if (previousDmp.getStatus().equals(DmpStatus.Finalized)) previousDmp.setVersionStatus(DmpVersionStatus.Current);
else previousDmp.setVersionStatus(DmpVersionStatus.NotFinalized); else previousDmp.setVersionStatus(DmpVersionStatus.NotFinalized);
@ -1595,6 +1594,9 @@ public class DmpServiceImpl implements DmpService {
} }
private DmpImportExport definitionXmlToExport(DmpEntity data, DmpPropertiesEntity propertiesEntity) throws InvalidApplicationException, JAXBException, ParserConfigurationException, IOException, InstantiationException, IllegalAccessException, SAXException { private DmpImportExport definitionXmlToExport(DmpEntity data, DmpPropertiesEntity propertiesEntity) throws InvalidApplicationException, JAXBException, ParserConfigurationException, IOException, InstantiationException, IllegalAccessException, SAXException {
DmpBlueprintEntity blueprintEntity = this.queryFactory.query(DmpBlueprintQuery.class).disableTracking().ids(data.getBlueprintId()).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).first();
if (blueprintEntity == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{data.getBlueprintId(), DmpBlueprint.class.getSimpleName()}, LocaleContextHolder.getLocale()));
DmpImportExport xml = new DmpImportExport(); DmpImportExport xml = new DmpImportExport();
xml.setId(data.getId()); xml.setId(data.getId());
xml.setDescription(data.getDescription()); xml.setDescription(data.getDescription());
@ -1604,48 +1606,30 @@ public class DmpServiceImpl implements DmpService {
xml.setFinalizedAt(data.getFinalizedAt()); xml.setFinalizedAt(data.getFinalizedAt());
xml.setPublicAfter(data.getPublicAfter()); xml.setPublicAfter(data.getPublicAfter());
xml.setVersion(data.getVersion()); xml.setVersion(data.getVersion());
xml.setContacts(this.dmpContactsToExport(propertiesEntity));
xml.setUsers(this.dmpUsersToExport(data));
xml.setBlueprint(this.dmpBlueprintService.getExportXmlEntity(blueprintEntity.getId(), true));
xml.setDescriptionTemplates(this.dmpDescriptionTemplatesToExport(data));
xml.setBlueprintValues(this.dmpBlueprintValuesToExport(propertiesEntity, blueprintEntity));
xml.setReferences(this.dmpReferencesToExport(data));
xml.setDescriptions(this.descriptionsToExport(data));
if (propertiesEntity != null && !this.conventionService.isListNullOrEmpty(propertiesEntity.getContacts())) { return xml;
List<DmpContactImportExport> dmpContactImportExports = new LinkedList<>(); }
for (DmpContactEntity contactEntity : propertiesEntity.getContacts()) {
dmpContactImportExports.add(this.dmpContactToExport(contactEntity)); private List<DescriptionImportExport> descriptionsToExport(DmpEntity data) throws JAXBException, InvalidApplicationException, ParserConfigurationException, IOException, InstantiationException, IllegalAccessException, SAXException {
List<DescriptionEntity> descriptions = this.queryFactory.query(DescriptionQuery.class).disableTracking().dmpIds(data.getId()).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).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(), true));
} }
xml.setContacts(dmpContactImportExports); return descriptionImportExports;
}
List<DmpUserEntity> dmpUsers = this.queryFactory.query(DmpUserQuery.class).disableTracking().dmpIds(data.getId()).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).isActives(IsActive.Active).collect();
if (!this.conventionService.isListNullOrEmpty(dmpUsers)) {
List<UserEntity> users = this.queryFactory.query(UserQuery.class).disableTracking().ids(dmpUsers.stream().map(DmpUserEntity::getUserId).distinct().toList()).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).isActive(IsActive.Active).collect();
Map<UUID, UserEntity> usersMap = users == null ? new HashMap<>() : users.stream().collect(Collectors.toMap(UserEntity::getId, x-> x));
List<DmpUserImportExport> dmpUserImportExports = new LinkedList<>();
for (DmpUserEntity dmpUserEntity : dmpUsers) {
dmpUserImportExports.add(this.dmpUserToExport(dmpUserEntity, usersMap));
}
xml.setUsers(dmpUserImportExports);
}
DmpBlueprintEntity blueprintEntity = this.queryFactory.query(DmpBlueprintQuery.class).disableTracking().ids(data.getBlueprintId()).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).isActive(IsActive.Active).first();
if (blueprintEntity != null) {
xml.setBlueprint(this.dmpBlueprintService.getExportXmlEntity(blueprintEntity.getId(), true));
}
List<DmpDescriptionTemplateEntity> dmpDescriptionTemplateEntities = this.queryFactory.query(DmpDescriptionTemplateQuery.class).disableTracking().authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).dmpIds(data.getId()).isActive(IsActive.Active).collect();
if (!this.conventionService.isListNullOrEmpty(dmpDescriptionTemplateEntities)) {
List<DmpDescriptionTemplateImportExport> dmpDescriptionTemplateImportExports = new LinkedList<>();
for (DmpDescriptionTemplateEntity descriptionTemplateEntity : dmpDescriptionTemplateEntities) {
dmpDescriptionTemplateImportExports.add(this.dmpDescriptionTemplateToExport(descriptionTemplateEntity));
}
xml.setDescriptionTemplates(dmpDescriptionTemplateImportExports);
}
if (propertiesEntity != null && !this.conventionService.isListNullOrEmpty(propertiesEntity.getDmpBlueprintValues())) {
List<DmpBlueprintValueImportExport> dmpBlueprintValueImportExports = new LinkedList<>();
org.opencdmp.commons.types.dmpblueprint.DefinitionEntity definition = this.xmlHandlingService.fromXmlSafe(org.opencdmp.commons.types.dmpblueprint.DefinitionEntity.class, blueprintEntity.getDefinition());
for (DmpBlueprintValueEntity dmpBlueprintValueEntity : propertiesEntity.getDmpBlueprintValues()) {
dmpBlueprintValueImportExports.add(this.dmpBlueprintValueToExport(dmpBlueprintValueEntity, definition));
}
xml.setBlueprintValues(dmpBlueprintValueImportExports);
} }
return null;
}
private List<DmpReferenceImportExport> dmpReferencesToExport(DmpEntity data){
List<DmpReferenceEntity> dmpReferences = this.queryFactory.query(DmpReferenceQuery.class).disableTracking().dmpIds(data.getId()).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).isActives(IsActive.Active).collect(); List<DmpReferenceEntity> dmpReferences = this.queryFactory.query(DmpReferenceQuery.class).disableTracking().dmpIds(data.getId()).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).isActives(IsActive.Active).collect();
if (!this.conventionService.isListNullOrEmpty(dmpReferences)) { if (!this.conventionService.isListNullOrEmpty(dmpReferences)) {
List<ReferenceEntity> references = this.queryFactory.query(ReferenceQuery.class).disableTracking().ids(dmpReferences.stream().map(DmpReferenceEntity::getReferenceId).distinct().toList()).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).isActive(IsActive.Active).collect(); List<ReferenceEntity> references = this.queryFactory.query(ReferenceQuery.class).disableTracking().ids(dmpReferences.stream().map(DmpReferenceEntity::getReferenceId).distinct().toList()).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).isActive(IsActive.Active).collect();
@ -1656,17 +1640,9 @@ public class DmpServiceImpl implements DmpService {
for (DmpReferenceEntity descriptionTemplateEntity : dmpReferences) { for (DmpReferenceEntity descriptionTemplateEntity : dmpReferences) {
dmpReferenceImportExports.add(this.dmpReferenceToExport(descriptionTemplateEntity, referenceEntityMap, referenceTypeEntityMap)); dmpReferenceImportExports.add(this.dmpReferenceToExport(descriptionTemplateEntity, referenceEntityMap, referenceTypeEntityMap));
} }
xml.setReferences(dmpReferenceImportExports); return dmpReferenceImportExports;
} }
List<DescriptionEntity> descriptions = this.queryFactory.query(DescriptionQuery.class).disableTracking().dmpIds(data.getId()).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).dmpIds(data.getId()).isActive(IsActive.Active).collect(); return null;
if (!this.conventionService.isListNullOrEmpty(descriptions)) {
List<DescriptionImportExport> descriptionImportExports = new LinkedList<>();
for (DescriptionEntity description : descriptions) {
descriptionImportExports.add(this.descriptionService.exportXmlEntity(description.getId(), true));
}
xml.setDescriptions(descriptionImportExports);
}
return xml;
} }
private DmpReferenceImportExport dmpReferenceToExport(DmpReferenceEntity entity, Map<UUID, ReferenceEntity> referenceEntityMap, Map<UUID, ReferenceTypeEntity> referenceTypeEntityMap) { private DmpReferenceImportExport dmpReferenceToExport(DmpReferenceEntity entity, Map<UUID, ReferenceEntity> referenceEntityMap, Map<UUID, ReferenceTypeEntity> referenceTypeEntityMap) {
@ -1679,6 +1655,8 @@ public class DmpServiceImpl implements DmpService {
if (reference != null){ if (reference != null){
xml.setId(reference.getId()); xml.setId(reference.getId());
xml.setLabel(reference.getLabel()); xml.setLabel(reference.getLabel());
xml.setSource(reference.getSource());
xml.setSourceType(reference.getSourceType());
xml.setReference(reference.getReference()); xml.setReference(reference.getReference());
ReferenceTypeEntity referenceType = referenceTypeEntityMap.getOrDefault(reference.getTypeId(), null); ReferenceTypeEntity referenceType = referenceTypeEntityMap.getOrDefault(reference.getTypeId(), null);
if (referenceType != null) xml.setType(this.dmpReferenceTypeToExport(referenceType)); if (referenceType != null) xml.setType(this.dmpReferenceTypeToExport(referenceType));
@ -1697,6 +1675,18 @@ public class DmpServiceImpl implements DmpService {
return xml; return xml;
} }
private List<DmpBlueprintValueImportExport> dmpBlueprintValuesToExport(DmpPropertiesEntity propertiesEntity, DmpBlueprintEntity blueprintEntity){
if (propertiesEntity != null && !this.conventionService.isListNullOrEmpty(propertiesEntity.getDmpBlueprintValues())) {
List<DmpBlueprintValueImportExport> dmpBlueprintValueImportExports = new LinkedList<>();
org.opencdmp.commons.types.dmpblueprint.DefinitionEntity definition = this.xmlHandlingService.fromXmlSafe(org.opencdmp.commons.types.dmpblueprint.DefinitionEntity.class, blueprintEntity.getDefinition());
for (DmpBlueprintValueEntity dmpBlueprintValueEntity : propertiesEntity.getDmpBlueprintValues()) {
dmpBlueprintValueImportExports.add(this.dmpBlueprintValueToExport(dmpBlueprintValueEntity, definition));
}
return dmpBlueprintValueImportExports;
}
return null;
}
private DmpBlueprintValueImportExport dmpBlueprintValueToExport(DmpBlueprintValueEntity entity, org.opencdmp.commons.types.dmpblueprint.DefinitionEntity definition) { private DmpBlueprintValueImportExport dmpBlueprintValueToExport(DmpBlueprintValueEntity entity, org.opencdmp.commons.types.dmpblueprint.DefinitionEntity definition) {
DmpBlueprintValueImportExport xml = new DmpBlueprintValueImportExport(); DmpBlueprintValueImportExport xml = new DmpBlueprintValueImportExport();
if (entity == null) return xml; if (entity == null) return xml;
@ -1706,7 +1696,6 @@ public class DmpServiceImpl implements DmpService {
if (fieldEntity.getCategory().equals(DmpBlueprintFieldCategory.Extra)) { if (fieldEntity.getCategory().equals(DmpBlueprintFieldCategory.Extra)) {
ExtraFieldEntity extraFieldEntity = (ExtraFieldEntity) fieldEntity; ExtraFieldEntity extraFieldEntity = (ExtraFieldEntity) fieldEntity;
if (extraFieldEntity == null) return xml;
if (DmpBlueprintExtraFieldDataType.isDateType(extraFieldEntity.getType())){ if (DmpBlueprintExtraFieldDataType.isDateType(extraFieldEntity.getType())){
xml.setDateValue(entity.getDateValue()); xml.setDateValue(entity.getDateValue());
} else if (DmpBlueprintExtraFieldDataType.isNumberType(extraFieldEntity.getType())){ } else if (DmpBlueprintExtraFieldDataType.isNumberType(extraFieldEntity.getType())){
@ -1720,6 +1709,19 @@ public class DmpServiceImpl implements DmpService {
return xml; return xml;
} }
private List<DmpDescriptionTemplateImportExport> dmpDescriptionTemplatesToExport(DmpEntity data){
List<DmpDescriptionTemplateEntity> dmpDescriptionTemplateEntities = this.queryFactory.query(DmpDescriptionTemplateQuery.class).disableTracking().authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).dmpIds(data.getId()).isActive(IsActive.Active).collect();
if (!this.conventionService.isListNullOrEmpty(dmpDescriptionTemplateEntities)) {
List<DmpDescriptionTemplateImportExport> dmpDescriptionTemplateImportExports = new LinkedList<>();
for (DmpDescriptionTemplateEntity descriptionTemplateEntity : dmpDescriptionTemplateEntities) {
dmpDescriptionTemplateImportExports.add(this.dmpDescriptionTemplateToExport(descriptionTemplateEntity));
}
return dmpDescriptionTemplateImportExports;
}
return null;
}
private DmpDescriptionTemplateImportExport dmpDescriptionTemplateToExport(DmpDescriptionTemplateEntity entity) { private DmpDescriptionTemplateImportExport dmpDescriptionTemplateToExport(DmpDescriptionTemplateEntity entity) {
DmpDescriptionTemplateImportExport xml = new DmpDescriptionTemplateImportExport(); DmpDescriptionTemplateImportExport xml = new DmpDescriptionTemplateImportExport();
if (entity == null) return xml; if (entity == null) return xml;
@ -1730,6 +1732,20 @@ public class DmpServiceImpl implements DmpService {
return xml; return xml;
} }
private List<DmpUserImportExport>dmpUsersToExport(DmpEntity data){
List<DmpUserEntity> dmpUsers = this.queryFactory.query(DmpUserQuery.class).disableTracking().dmpIds(data.getId()).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).isActives(IsActive.Active).collect();
if (!this.conventionService.isListNullOrEmpty(dmpUsers)) {
List<UserEntity> users = this.queryFactory.query(UserQuery.class).disableTracking().ids(dmpUsers.stream().map(DmpUserEntity::getUserId).distinct().toList()).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).isActive(IsActive.Active).collect();
Map<UUID, UserEntity> usersMap = users == null ? new HashMap<>() : users.stream().collect(Collectors.toMap(UserEntity::getId, x -> x));
List<DmpUserImportExport> dmpUserImportExports = new LinkedList<>();
for (DmpUserEntity dmpUserEntity : dmpUsers) {
dmpUserImportExports.add(this.dmpUserToExport(dmpUserEntity, usersMap));
}
return dmpUserImportExports;
}
return null;
}
private DmpUserImportExport dmpUserToExport(DmpUserEntity entity, Map<UUID, UserEntity> usersMap) { private DmpUserImportExport dmpUserToExport(DmpUserEntity entity, Map<UUID, UserEntity> usersMap) {
DmpUserImportExport xml = new DmpUserImportExport(); DmpUserImportExport xml = new DmpUserImportExport();
if (entity == null) return xml; if (entity == null) return xml;
@ -1745,6 +1761,17 @@ public class DmpServiceImpl implements DmpService {
return xml; return xml;
} }
private List<DmpContactImportExport> dmpContactsToExport(DmpPropertiesEntity propertiesEntity){
if (propertiesEntity != null && !this.conventionService.isListNullOrEmpty(propertiesEntity.getContacts())) {
List<DmpContactImportExport> dmpContactImportExports = new LinkedList<>();
for (DmpContactEntity contactEntity : propertiesEntity.getContacts()) {
dmpContactImportExports.add(this.dmpContactToExport(contactEntity));
}
return dmpContactImportExports;
}
return null;
}
private DmpContactImportExport dmpContactToExport(DmpContactEntity entity) { private DmpContactImportExport dmpContactToExport(DmpContactEntity entity) {
DmpContactImportExport xml = new DmpContactImportExport(); DmpContactImportExport xml = new DmpContactImportExport();
if (entity == null) return xml; if (entity == null) return xml;
@ -1776,128 +1803,148 @@ public class DmpServiceImpl implements DmpService {
persist.setDescription(dmpXml.getDescription()); persist.setDescription(dmpXml.getDescription());
persist.setAccessType(dmpXml.getAccess()); persist.setAccessType(dmpXml.getAccess());
persist.setLanguage(dmpXml.getLanguage()); persist.setLanguage(dmpXml.getLanguage());
persist.setUsers(this.xmlToDmpUsersPersist(dmpXml)); //TODO ignore users not exists. by id betters solution
persist.setProperties(this.xmlToDmpPropertiesPersist(dmpXml)); persist.setProperties(this.xmlToDmpPropertiesPersist(dmpXml));
persist.setDescriptionTemplates(this.xmlDmpDescriptionTemplatesToPersist(dmpXml)); //TODO maybe we should create templates if not exists
if (!this.conventionService.isListNullOrEmpty(dmpXml.getUsers())) { persist.setBlueprint(this.xmlDmpBlueprintToPersist(dmpXml));
List<UserEntity> users = this.queryFactory.query(UserQuery.class).disableTracking().ids(dmpXml.getUsers().stream().map(DmpUserImportExport::getId).filter(Objects::nonNull).distinct().toList()).isActive(IsActive.Active).collect();
List<UUID> userIds = users == null ? new ArrayList<>() : users.stream().map(x -> x.getId()).collect(Collectors.toList());
List<DmpUserPersist> dmpUsers = new ArrayList<>();
for (DmpUserImportExport user : dmpXml.getUsers()) {
dmpUsers.add(this.xmlDmpUserToPersist(user, userIds));
}
persist.setUsers(dmpUsers.stream().filter(Objects::nonNull).toList());
}
if (dmpXml.getBlueprint() != null) persist.setBlueprint(dmpXml.getBlueprint().getId());
if (!this.conventionService.isListNullOrEmpty(dmpXml.getDescriptionTemplates())) {
List<DmpDescriptionTemplatePersist> descriptionTemplates = new ArrayList<>();
for (DmpDescriptionTemplateImportExport descriptionTemplate : dmpXml.getDescriptionTemplates()) {
descriptionTemplates.add(this.xmlDmpDescriptionTemplateToPersist(descriptionTemplate));
}
persist.setDescriptionTemplates(descriptionTemplates.stream().filter(Objects::nonNull).toList());
}
this.validatorFactory.validator(DmpPersist.DmpPersistValidator.class).validateForce(persist); this.validatorFactory.validator(DmpPersist.DmpPersistValidator.class).validateForce(persist);
Dmp dmp = this.persist(persist, fields); Dmp dmp = this.persist(persist, BaseFieldSet.build(fields, Dmp._id, Dmp._hash));
if (dmp == null) throw new MyApplicationException("Error creating dmp");
if (!this.conventionService.isListNullOrEmpty(dmpXml.getDescriptions())){ if (!this.conventionService.isListNullOrEmpty(dmpXml.getDescriptions())){
if (dmp == null || dmp.getId() == null) throw new MyApplicationException("Error creating dmp");
List<DmpDescriptionTemplateEntity> dmpDescriptionTemplates = this.queryFactory.query(DmpDescriptionTemplateQuery.class).disableTracking()
.isActive(IsActive.Active)
.dmpIds(dmp.getId())
.collect();
for (DescriptionImportExport description: dmpXml.getDescriptions()){ for (DescriptionImportExport description: dmpXml.getDescriptions()){
this.descriptionService.importXml(description, dmp.getId(), dmpDescriptionTemplates, fields != null ? fields.extractPrefixed(this.conventionService.asPrefix(Dmp._description)) : null); this.descriptionService.importXml(description, dmp.getId(), fields != null ? fields.extractPrefixed(this.conventionService.asPrefix(Dmp._description)) : null);
} }
} }
return dmp; return dmp;
} }
private DmpPropertiesPersist xmlToDmpPropertiesPersist(DmpImportExport importXml) { private UUID xmlDmpBlueprintToPersist(DmpImportExport dmpXml) throws JAXBException, InvalidApplicationException, ParserConfigurationException, IOException, TransformerException, InstantiationException, IllegalAccessException, SAXException {
if (importXml == null) if (dmpXml.getBlueprint() != null){
return null; DmpBlueprintEntity dmpBlueprintEntity = this.queryFactory.query(DmpBlueprintQuery.class).disableTracking().ids(dmpXml.getBlueprint().getId()).first();
if (dmpBlueprintEntity == null) dmpBlueprintEntity = this.queryFactory.query(DmpBlueprintQuery.class).disableTracking().groupIds(dmpXml.getBlueprint().getGroupId()).versionStatuses(DmpBlueprintVersionStatus.Current).isActive(IsActive.Active).statuses(DmpBlueprintStatus.Finalized).first();
DmpPropertiesPersist persist = new DmpPropertiesPersist(); if (dmpBlueprintEntity != null){
return dmpBlueprintEntity.getId();
List<DmpContactPersist> contacts = new ArrayList<>(); } else {
if (!this.conventionService.isListNullOrEmpty(importXml.getContacts())) { DmpBlueprint persisted = this.dmpBlueprintService.importXml(dmpXml.getBlueprint(), null, dmpXml.getBlueprint().getLabel(), new BaseFieldSet().ensure(DmpBlueprint._label).ensure(DmpBlueprint._hash));
for (DmpContactImportExport contact : importXml.getContacts()) { return persisted.getId();
contacts.add(this.xmlDmpContactToPersist(contact));
} }
} }
return null;
}
Map<UUID, DmpBlueprintValuePersist> dmpBlueprintValues = new HashMap<>(); private DmpPropertiesPersist xmlToDmpPropertiesPersist(DmpImportExport importXml) {
if (importXml == null) return null;
if (!this.conventionService.isListNullOrEmpty(importXml.getBlueprint().getDmpBlueprintDefinition().getSections())) { DmpPropertiesPersist persist = new DmpPropertiesPersist();
persist.setContacts(this.xmlToDmpContactPersist(importXml));
persist.setDmpBlueprintValues(this.xmlToDmpBlueprintValuePersist(importXml));
return persist;
}
private Map<UUID, DmpBlueprintValuePersist> xmlToDmpBlueprintValuePersist(DmpImportExport importXml){
if (importXml.getBlueprint() != null && importXml.getBlueprint().getDmpBlueprintDefinition() != null && !this.conventionService.isListNullOrEmpty(importXml.getBlueprint().getDmpBlueprintDefinition().getSections())) {
Map<UUID, DmpBlueprintValuePersist> dmpBlueprintValues = new HashMap<>();
List<BlueprintSectionImportExport> sections = importXml.getBlueprint().getDmpBlueprintDefinition().getSections(); List<BlueprintSectionImportExport> sections = importXml.getBlueprint().getDmpBlueprintDefinition().getSections();
if (!this.conventionService.isListNullOrEmpty(sections)){ if (!this.conventionService.isListNullOrEmpty(sections)){
for (BlueprintSectionImportExport section : importXml.getBlueprint().getDmpBlueprintDefinition().getSections()) { for (BlueprintSectionImportExport section : importXml.getBlueprint().getDmpBlueprintDefinition().getSections()) {
// reference this.xmlToDmpBlueprintExtraFieldValuePersist(importXml, section, dmpBlueprintValues);
if (!this.conventionService.isListNullOrEmpty(section.getReferenceFields()) && !this.conventionService.isListNullOrEmpty(importXml.getReferences())){ this.xmlToDmpBlueprintReferenceFieldValuePersist(importXml, section, dmpBlueprintValues);
for (BlueprintReferenceTypeFieldImportExport blueprintReferenceTypeField : section.getReferenceFields()) {
List<DmpReferenceImportExport> dmpReferencesByField = importXml.getReferences().stream().filter(x -> x.getFieldId().equals(blueprintReferenceTypeField.getId())).collect(Collectors.toList());
if (!this.conventionService.isListNullOrEmpty(dmpReferencesByField)){
dmpBlueprintValues.put(blueprintReferenceTypeField.getId(), this.xmlReferenceFieldToDmpBlueprintValuePersist(blueprintReferenceTypeField, dmpReferencesByField));
}
}
}
// custom fields
if (!this.conventionService.isListNullOrEmpty(section.getExtraFields()) && !this.conventionService.isListNullOrEmpty(importXml.getBlueprintValues())){
for (DmpBlueprintValueImportExport value : importXml.getBlueprintValues()) {
if (value.getFieldId() != null ) {
BlueprintExtraFieldImportExport extraFieldImportExport = section.getExtraFields().stream().filter(x -> x.getId().equals(value.getFieldId())).findFirst().orElse(null);
if (extraFieldImportExport != null) dmpBlueprintValues.put(value.getFieldId(), this.xmlDmpBlueprintValueToPersist(value, extraFieldImportExport));
}
}
}
} }
} }
return dmpBlueprintValues;
} }
return null;
}
persist.setContacts(contacts); private void xmlToDmpBlueprintExtraFieldValuePersist(DmpImportExport importXml, BlueprintSectionImportExport section, Map<UUID, DmpBlueprintValuePersist> dmpBlueprintValues){
persist.setDmpBlueprintValues(dmpBlueprintValues); if (!this.conventionService.isListNullOrEmpty(section.getExtraFields()) && !this.conventionService.isListNullOrEmpty(importXml.getBlueprintValues())){
for (DmpBlueprintValueImportExport value : importXml.getBlueprintValues()) {
if (value.getFieldId() != null ) {
section.getExtraFields().stream().filter(x -> x.getId().equals(value.getFieldId())).findFirst().ifPresent(extraFieldImportExport -> dmpBlueprintValues.put(value.getFieldId(), this.xmlDmpBlueprintValueToPersist(value, extraFieldImportExport)));
}
}
}
}
return persist; private void xmlToDmpBlueprintReferenceFieldValuePersist(DmpImportExport importXml, BlueprintSectionImportExport section, Map<UUID, DmpBlueprintValuePersist> dmpBlueprintValues){
if (!this.conventionService.isListNullOrEmpty(section.getReferenceFields()) && !this.conventionService.isListNullOrEmpty(importXml.getReferences())){
for (BlueprintReferenceTypeFieldImportExport blueprintReferenceTypeField : section.getReferenceFields()) {
List<DmpReferenceImportExport> dmpReferencesByField = importXml.getReferences().stream().filter(x -> x.getFieldId().equals(blueprintReferenceTypeField.getId())).collect(Collectors.toList());
if (!this.conventionService.isListNullOrEmpty(dmpReferencesByField)){
dmpBlueprintValues.put(blueprintReferenceTypeField.getId(), this.xmlReferenceFieldToDmpBlueprintValuePersist(blueprintReferenceTypeField, dmpReferencesByField));
}
}
}
}
private List<DmpContactPersist> xmlToDmpContactPersist(DmpImportExport importXml){
if (!this.conventionService.isListNullOrEmpty(importXml.getContacts())) {
List<DmpContactPersist> contacts = new ArrayList<>();
for (DmpContactImportExport contact : importXml.getContacts()) {
contacts.add(this.xmlDmpContactToPersist(contact));
}
return contacts;
}
return null;
} }
private DmpBlueprintValuePersist xmlReferenceFieldToDmpBlueprintValuePersist(BlueprintReferenceTypeFieldImportExport blueprintReferenceTypeFieldImportXml, List<DmpReferenceImportExport> dmpReferencesImportXml) { private DmpBlueprintValuePersist xmlReferenceFieldToDmpBlueprintValuePersist(BlueprintReferenceTypeFieldImportExport blueprintReferenceTypeFieldImportXml, List<DmpReferenceImportExport> dmpReferencesImportXml) {
if (blueprintReferenceTypeFieldImportXml == null || this.conventionService.isListNullOrEmpty(dmpReferencesImportXml)) if (blueprintReferenceTypeFieldImportXml == null || this.conventionService.isListNullOrEmpty(dmpReferencesImportXml))
return null; return null;
ReferenceTypeEntity referenceTypeEntity = this.queryFactory.query(ReferenceTypeQuery.class).ids(blueprintReferenceTypeFieldImportXml.getReferenceTypeId()).first();//TODO: optimize
if (referenceTypeEntity == null) referenceTypeEntity = this.queryFactory.query(ReferenceTypeQuery.class).codes(blueprintReferenceTypeFieldImportXml.getReferenceTypeCode()).first();
if (referenceTypeEntity == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{blueprintReferenceTypeFieldImportXml.getReferenceTypeCode(), ReferenceType.class.getSimpleName()}, LocaleContextHolder.getLocale()));
DmpBlueprintValuePersist persist = new DmpBlueprintValuePersist(); DmpBlueprintValuePersist persist = new DmpBlueprintValuePersist();
persist.setFieldId(blueprintReferenceTypeFieldImportXml.getId()); persist.setFieldId(blueprintReferenceTypeFieldImportXml.getId());
if (blueprintReferenceTypeFieldImportXml.getMultipleSelect()){ if (blueprintReferenceTypeFieldImportXml.getMultipleSelect()){
List<ReferencePersist> references = new ArrayList<>(); List<ReferencePersist> references = new ArrayList<>();
for (DmpReferenceImportExport dmpReference : dmpReferencesImportXml) { for (DmpReferenceImportExport dmpReference : dmpReferencesImportXml) {
references.add(this.xmlDmpReferenceToReferencePersist(dmpReference)); references.add(this.xmlDmpReferenceToReferencePersist(dmpReference, referenceTypeEntity));
} }
persist.setReferences(references); persist.setReferences(references);
} else { } else {
persist.setReference(this.xmlDmpReferenceToReferencePersist(dmpReferencesImportXml.stream().findFirst().orElse(null))); persist.setReference(this.xmlDmpReferenceToReferencePersist(dmpReferencesImportXml.stream().findFirst().orElse(null), referenceTypeEntity));
} }
return persist; return persist;
} }
private ReferencePersist xmlDmpReferenceToReferencePersist(DmpReferenceImportExport importXml) { private ReferencePersist xmlDmpReferenceToReferencePersist(DmpReferenceImportExport importXml, ReferenceTypeEntity referenceTypeEntity) {
if (importXml == null) if (importXml == null)
return null; return null;
if (!referenceTypeEntity.getCode().equals(importXml.getType().getCode())) throw new MyApplicationException("Invalid reference for field " + importXml.getId());
ReferenceEntity referenceEntity = this.queryFactory.query(ReferenceQuery.class).ids(importXml.getId()).first(); //TODO: optimize
if (referenceEntity == null) referenceEntity = this.queryFactory.query(ReferenceQuery.class).references(importXml.getReference()).sources(importXml.getSource()).first();
ReferencePersist persist = new ReferencePersist(); ReferencePersist persist = new ReferencePersist();
persist.setId(importXml.getId()); if (referenceEntity == null) {
persist.setLabel(importXml.getLabel()); persist.setLabel(importXml.getLabel());
persist.setReference(importXml.getReference()); persist.setReference(importXml.getReference());
persist.setSource(importXml.getSource());
persist.setSourceType(ReferenceSourceType.External);
} else {
persist.setId(referenceEntity.getId());
persist.setLabel(referenceEntity.getLabel());
persist.setReference(referenceEntity.getReference());
persist.setSource(referenceEntity.getSource());
persist.setSourceType(referenceEntity.getSourceType());
persist.setAbbreviation(referenceEntity.getAbbreviation());
persist.setDescription(referenceEntity.getDescription());
persist.setHash(this.conventionService.hashValue(referenceEntity.getUpdatedAt()));
}
return persist; return persist;
} }
@ -1908,17 +1955,27 @@ public class DmpServiceImpl implements DmpService {
DmpBlueprintValuePersist persist = new DmpBlueprintValuePersist(); DmpBlueprintValuePersist persist = new DmpBlueprintValuePersist();
persist.setFieldId(importXml.getFieldId()); persist.setFieldId(importXml.getFieldId());
if (DmpBlueprintExtraFieldDataType.isDateType(extraFieldImportExport.getType())){ switch (extraFieldImportExport.getType()){
persist.setDateValue(importXml.getDateValue()); case Date -> persist.setDateValue(importXml.getDateValue());
}else if (DmpBlueprintExtraFieldDataType.isNumberType(extraFieldImportExport.getType())){ case Number -> persist.setNumberValue(importXml.getNumberValue());
persist.setNumberValue(importXml.getNumberValue()); case Text, RichTex -> persist.setFieldValue(importXml.getValue());
} else { default -> throw new MyApplicationException("unrecognized type " + extraFieldImportExport.getType());
persist.setFieldValue(importXml.getValue());
} }
return persist; return persist;
} }
private List<DmpDescriptionTemplatePersist> xmlDmpDescriptionTemplatesToPersist(DmpImportExport dmpXml){
if (!this.conventionService.isListNullOrEmpty(dmpXml.getDescriptionTemplates())) {
List<DmpDescriptionTemplatePersist> descriptionTemplates = new ArrayList<>();
for (DmpDescriptionTemplateImportExport descriptionTemplate : dmpXml.getDescriptionTemplates()) {
descriptionTemplates.add(this.xmlDmpDescriptionTemplateToPersist(descriptionTemplate));
}
return descriptionTemplates.stream().filter(Objects::nonNull).toList();
}
return null;
}
private DmpDescriptionTemplatePersist xmlDmpDescriptionTemplateToPersist(DmpDescriptionTemplateImportExport importXml) { private DmpDescriptionTemplatePersist xmlDmpDescriptionTemplateToPersist(DmpDescriptionTemplateImportExport importXml) {
if (importXml == null) if (importXml == null)
return null; return null;
@ -1931,6 +1988,20 @@ public class DmpServiceImpl implements DmpService {
return persist; return persist;
} }
private List<DmpUserPersist> xmlToDmpUsersPersist(DmpImportExport dmpXml){
if (!this.conventionService.isListNullOrEmpty(dmpXml.getUsers())) {
List<UserEntity> users = this.queryFactory.query(UserQuery.class).disableTracking().ids(dmpXml.getUsers().stream().map(DmpUserImportExport::getId).filter(Objects::nonNull).distinct().toList()).isActive(IsActive.Active).collect();
List<UUID> userIds = users == null ? new ArrayList<>() : users.stream().map(UserEntity::getId).collect(Collectors.toList());
List<DmpUserPersist> dmpUsers = new ArrayList<>();
for (DmpUserImportExport user : dmpXml.getUsers()) {
dmpUsers.add(this.xmlDmpUserToPersist(user, userIds));
}
return dmpUsers.stream().filter(Objects::nonNull).toList();
}
return null;
}
private DmpUserPersist xmlDmpUserToPersist(DmpUserImportExport importXml, List<UUID> userIds) { private DmpUserPersist xmlDmpUserToPersist(DmpUserImportExport importXml, List<UUID> userIds) {
if (importXml == null) if (importXml == null)
return null; return null;
@ -1987,8 +2058,8 @@ public class DmpServiceImpl implements DmpService {
persist.setProperties(this.commonDmpPropertiesToPersist(model)); persist.setProperties(this.commonDmpPropertiesToPersist(model));
if (!this.conventionService.isListNullOrEmpty(model.getUsers())) { if (!this.conventionService.isListNullOrEmpty(model.getUsers())) {
List<UserEntity> users = this.queryFactory.query(UserQuery.class).disableTracking().ids(model.getUsers().stream().map(x -> x.getUser()).collect(Collectors.toList()).stream().map(UserModel::getId).filter(Objects::nonNull).distinct().toList()).isActive(IsActive.Active).collect(); List<UserEntity> users = this.queryFactory.query(UserQuery.class).disableTracking().ids(model.getUsers().stream().map(DmpUserModel::getUser).toList().stream().map(UserModel::getId).filter(Objects::nonNull).distinct().toList()).isActive(IsActive.Active).collect();
List<UUID> userIds = users == null ? new ArrayList<>() : users.stream().map(x -> x.getId()).collect(Collectors.toList()); List<UUID> userIds = users == null ? new ArrayList<>() : users.stream().map(UserEntity::getId).collect(Collectors.toList());
List<DmpUserPersist> dmpUsers = new ArrayList<>(); List<DmpUserPersist> dmpUsers = new ArrayList<>();
for (DmpUserModel user : model.getUsers()) { for (DmpUserModel user : model.getUsers()) {
@ -2049,7 +2120,7 @@ public class DmpServiceImpl implements DmpService {
if (!this.conventionService.isListNullOrEmpty(section.getFields()) && !this.conventionService.isListNullOrEmpty(model.getReferences())){ if (!this.conventionService.isListNullOrEmpty(section.getFields()) && !this.conventionService.isListNullOrEmpty(model.getReferences())){
for (FieldModel field : section.getFields()) { for (FieldModel field : section.getFields()) {
// reference // reference
if (field.getCategory().equals(DmpBlueprintFieldCategory.ReferenceType)){ if (field.getCategory().equals(org.opencdmp.commonmodels.enums.DmpBlueprintFieldCategory.ReferenceType)){
ReferenceTypeFieldModel referenceField = (ReferenceTypeFieldModel) field; ReferenceTypeFieldModel referenceField = (ReferenceTypeFieldModel) field;
List<DmpReferenceModel> dmpReferencesByField = model.getReferences().stream().filter(x -> x.getData() != null && x.getData().getBlueprintFieldId().equals(referenceField.getId())).collect(Collectors.toList()); List<DmpReferenceModel> dmpReferencesByField = model.getReferences().stream().filter(x -> x.getData() != null && x.getData().getBlueprintFieldId().equals(referenceField.getId())).collect(Collectors.toList());
if (!this.conventionService.isListNullOrEmpty(dmpReferencesByField)){ if (!this.conventionService.isListNullOrEmpty(dmpReferencesByField)){
@ -2057,10 +2128,10 @@ public class DmpServiceImpl implements DmpService {
} }
} else { } else {
// custom fields // custom fields
if (field.getCategory().equals(DmpBlueprintFieldCategory.Extra) && model.getProperties() != null && this.conventionService.isListNullOrEmpty(model.getProperties().getDmpBlueprintValues())){ if (field.getCategory().equals(org.opencdmp.commonmodels.enums.DmpBlueprintFieldCategory.Extra) && model.getProperties() != null && this.conventionService.isListNullOrEmpty(model.getProperties().getDmpBlueprintValues())){
DmpBlueprintValueModel dmpBlueprintValueModel = model.getProperties().getDmpBlueprintValues().stream().filter(x -> x.getFieldId().equals(field.getId())).findFirst().orElse(null); DmpBlueprintValueModel dmpBlueprintValueModel = model.getProperties().getDmpBlueprintValues().stream().filter(x -> x.getFieldId().equals(field.getId())).findFirst().orElse(null);
ExtraFieldModel extraFieldModel = (ExtraFieldModel) field; ExtraFieldModel extraFieldModel = (ExtraFieldModel) field;
if (dmpBlueprintValueModel != null && extraFieldModel != null) dmpBlueprintValues.put(dmpBlueprintValueModel.getFieldId(), this.commonDmpBlueprintValueToPersist(dmpBlueprintValueModel, extraFieldModel)); if (dmpBlueprintValueModel != null) dmpBlueprintValues.put(dmpBlueprintValueModel.getFieldId(), this.commonDmpBlueprintValueToPersist(dmpBlueprintValueModel, extraFieldModel));
} }
} }
} }
@ -2090,7 +2161,7 @@ public class DmpServiceImpl implements DmpService {
} }
persist.setReferences(references); persist.setReferences(references);
} else { } else {
persist.setReference(this.commonDmpReferenceToReferencePersist(dmpReferences.get(0).getReference())); persist.setReference(this.commonDmpReferenceToReferencePersist(dmpReferences.getFirst().getReference()));
} }
return persist; return persist;

View File

@ -38,5 +38,8 @@ public interface DmpBlueprintService {
BlueprintImportExport getExportXmlEntity(UUID id, boolean ignoreAuthorize) throws MyForbiddenException, MyNotFoundException, InvalidApplicationException, JAXBException, ParserConfigurationException, IOException, InstantiationException, IllegalAccessException, SAXException; BlueprintImportExport getExportXmlEntity(UUID id, boolean ignoreAuthorize) throws MyForbiddenException, MyNotFoundException, InvalidApplicationException, JAXBException, ParserConfigurationException, IOException, InstantiationException, IllegalAccessException, SAXException;
ResponseEntity<byte[]> exportXml(UUID id) throws MyForbiddenException, MyNotFoundException, JAXBException, ParserConfigurationException, IOException, InstantiationException, IllegalAccessException, SAXException, TransformerException, InvalidApplicationException; ResponseEntity<byte[]> exportXml(UUID id) throws MyForbiddenException, MyNotFoundException, JAXBException, ParserConfigurationException, IOException, InstantiationException, IllegalAccessException, SAXException, TransformerException, InvalidApplicationException;
DmpBlueprint importXml(BlueprintImportExport dmpDefinition, UUID groupId, String label, FieldSet fields) throws MyForbiddenException, MyNotFoundException, JAXBException, ParserConfigurationException, TransformerException, InvalidApplicationException, IOException, InstantiationException, IllegalAccessException, SAXException;
DmpBlueprint importXml(byte[] bytes, UUID groupId, String label, FieldSet fields) throws MyForbiddenException, MyNotFoundException, JAXBException, ParserConfigurationException, TransformerException, InvalidApplicationException, IOException, InstantiationException, IllegalAccessException, SAXException; DmpBlueprint importXml(byte[] bytes, UUID groupId, String label, FieldSet fields) throws MyForbiddenException, MyNotFoundException, JAXBException, ParserConfigurationException, TransformerException, InvalidApplicationException, IOException, InstantiationException, IllegalAccessException, SAXException;
} }

View File

@ -621,12 +621,12 @@ public class DmpBlueprintServiceImpl implements DmpBlueprintService {
//region Import //region Import
public DmpBlueprint importXml(byte[] bytes, UUID groupId, String label, FieldSet fields) throws MyForbiddenException, MyNotFoundException, JAXBException, ParserConfigurationException, TransformerException, InvalidApplicationException, IOException, InstantiationException, IllegalAccessException, SAXException { @Override
logger.debug(new MapLogEntry("import data").And("bytes", bytes).And("label", label).And("fields", fields)); public DmpBlueprint importXml(BlueprintImportExport dmpDefinition, UUID groupId, String label, FieldSet fields) throws MyForbiddenException, MyNotFoundException, JAXBException, ParserConfigurationException, TransformerException, InvalidApplicationException, IOException, InstantiationException, IllegalAccessException, SAXException {
logger.debug(new MapLogEntry("import data").And("dmpDefinition", dmpDefinition).And("label", label).And("fields", fields));
this.authorizationService.authorizeForce(Permission.ImportDmpBlueprint); this.authorizationService.authorizeForce(Permission.ImportDmpBlueprint);
BlueprintImportExport dmpDefinition = this.xmlHandlingService.fromXml(BlueprintImportExport.class, new String(bytes, StandardCharsets.UTF_8));
if (groupId == null) groupId = dmpDefinition.getGroupId(); if (groupId == null) groupId = dmpDefinition.getGroupId();
long activeBlueprintForTheGroup = groupId != null ? this.queryFactory.query(DmpBlueprintQuery.class).disableTracking() long activeBlueprintForTheGroup = groupId != null ? this.queryFactory.query(DmpBlueprintQuery.class).disableTracking()
@ -664,6 +664,17 @@ public class DmpBlueprintServiceImpl implements DmpBlueprintService {
} }
} }
@Override
public DmpBlueprint importXml(byte[] bytes, UUID groupId, String label, FieldSet fields) throws MyForbiddenException, MyNotFoundException, JAXBException, ParserConfigurationException, TransformerException, InvalidApplicationException, IOException, InstantiationException, IllegalAccessException, SAXException {
logger.debug(new MapLogEntry("import data").And("bytes", bytes).And("label", label).And("fields", fields));
this.authorizationService.authorizeForce(Permission.ImportDmpBlueprint);
BlueprintImportExport dmpDefinition = this.xmlHandlingService.fromXml(BlueprintImportExport.class, new String(bytes, StandardCharsets.UTF_8));
return this.importXml(dmpDefinition, groupId, label, fields);
}
private DefinitionPersist xmlDefinitionToPersist(BlueprintDefinitionImportExport importXml) { private DefinitionPersist xmlDefinitionToPersist(BlueprintDefinitionImportExport importXml) {
if (importXml == null) if (importXml == null)
return null; return null;