dmp import changes

This commit is contained in:
Efstratios Giannopoulos 2024-06-12 17:57:29 +03:00
parent 41583745be
commit 7fe36e6337
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.XmlAccessorType;
import jakarta.xml.bind.annotation.XmlElement;
import org.opencdmp.commons.enums.ReferenceSourceType;
import java.util.UUID;
@ -19,6 +20,10 @@ public class DmpReferenceImportExport {
private UUID fieldId;
@XmlElement(name = "type")
private DmpReferenceTypeImportExport type;
@XmlElement(name = "source")
private String source;
@XmlElement(name = "sourceType")
private ReferenceSourceType sourceType;
public UUID getId() {
return this.id;
@ -59,4 +64,20 @@ public class DmpReferenceImportExport {
public void setFieldId(UUID 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;
public UUID getBlueprintFieldId() {
return blueprintFieldId;
return this.blueprintFieldId;
}
public void setBlueprintFieldId(UUID blueprintFieldId) {

View File

@ -1,9 +1,9 @@
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.specification.Specification;
import org.opencdmp.commons.enums.ReferenceSourceType;
import org.opencdmp.commons.validation.BaseValidator;
import org.opencdmp.convention.ConventionService;
import org.opencdmp.data.ReferenceEntity;
import org.opencdmp.errorcode.ErrorThesaurusProperties;
@ -57,7 +57,7 @@ public class ReferencePersist {
public static final String _hash = "hash";
public UUID getId() {
return id;
return this.id;
}
public void setId(UUID id) {
@ -65,7 +65,7 @@ public class ReferencePersist {
}
public String getLabel() {
return label;
return this.label;
}
public void setLabel(String label) {
@ -73,7 +73,7 @@ public class ReferencePersist {
}
public UUID getTypeId() {
return typeId;
return this.typeId;
}
public void setTypeId(UUID typeId) {
@ -81,7 +81,7 @@ public class ReferencePersist {
}
public String getDescription() {
return description;
return this.description;
}
public void setDescription(String description) {
@ -89,7 +89,7 @@ public class ReferencePersist {
}
public DefinitionPersist getDefinition() {
return definition;
return this.definition;
}
public void setDefinition(DefinitionPersist definition) {
@ -97,7 +97,7 @@ public class ReferencePersist {
}
public String getReference() {
return reference;
return this.reference;
}
public void setReference(String reference) {
@ -105,7 +105,7 @@ public class ReferencePersist {
}
public String getAbbreviation() {
return abbreviation;
return this.abbreviation;
}
public void setAbbreviation(String abbreviation) {
@ -113,7 +113,7 @@ public class ReferencePersist {
}
public String getSource() {
return source;
return this.source;
}
public void setSource(String source) {
@ -121,7 +121,7 @@ public class ReferencePersist {
}
public ReferenceSourceType getSourceType() {
return sourceType;
return this.sourceType;
}
public void setSourceType(ReferenceSourceType sourceType) {
@ -129,7 +129,7 @@ public class ReferencePersist {
}
public String getHash() {
return hash;
return this.hash;
}
public void setHash(String hash) {
@ -163,42 +163,42 @@ public class ReferencePersist {
this.spec()
.iff(() -> this.isValidGuid(item.getId()))
.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()
.iff(() -> !this.isValidGuid(item.getId()))
.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()
.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()
.iff(() -> !this.isEmpty(item.getLabel()))
.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()
.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()
.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()
.iff(() -> !this.isEmpty(item.getReference()))
.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()
.iff(() -> !this.isEmpty(item.getAbbreviation()))
.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()
.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()
.iff(() -> !this.isEmpty(item.getSource()))
.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()
.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()
.iff(() -> !this.isNull(item.getDefinition()))
.on(ReferencePersist._definition)
@ -234,32 +234,32 @@ public class ReferencePersist {
return Arrays.asList(
this.spec()
.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()
.iff(() -> !this.isEmpty(item.getLabel()))
.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()
.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()
.iff(() -> !this.isEmpty(item.getReference()))
.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()
.iff(() -> !this.isEmpty(item.getAbbreviation()))
.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()
.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()
.iff(() -> !this.isEmpty(item.getSource()))
.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()
.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()
.iff(() -> !this.isNull(item.getDefinition()))
.on(ReferencePersist._definition)

View File

@ -63,7 +63,7 @@ public class DmpBlueprintValuePersist {
}
public Instant getDateValue() {
return dateValue;
return this.dateValue;
}
public void setDateValue(Instant dateValue) {
@ -71,7 +71,7 @@ public class DmpBlueprintValuePersist {
}
public Double getNumberValue() {
return numberValue;
return this.numberValue;
}
public void setNumberValue(Double numberValue) {
@ -124,22 +124,22 @@ public class DmpBlueprintValuePersist {
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;
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(
this.spec()
.must(() -> this.isValidGuid(item.getFieldId()))
.failOn(DmpBlueprintValuePersist._fieldId).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{DmpBlueprintValuePersist._fieldId}, LocaleContextHolder.getLocale())),
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()))
.failOn(DmpBlueprintValuePersist._fieldValue).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{this.fieldEntity.getLabel()}, LocaleContextHolder.getLocale())),
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()))
.failOn(DmpBlueprintValuePersist._dateValue).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{this.fieldEntity.getLabel()}, LocaleContextHolder.getLocale())),
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()))
.failOn(DmpBlueprintValuePersist._numberValue).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{this.fieldEntity.getLabel()}, LocaleContextHolder.getLocale())),
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;
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 ;

View File

@ -3,7 +3,6 @@ package org.opencdmp.service.description;
import gr.cite.commons.web.authz.service.AuthorizationService;
import gr.cite.tools.data.builder.BuilderFactory;
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.exception.*;
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.DescriptionTemplateImportExport;
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.convention.ConventionService;
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.notification.NotifyIntegrationEvent;
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.deleter.DescriptionDeleter;
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.descriptiontemplate.DescriptionTemplate;
import org.opencdmp.model.dmp.Dmp;
import org.opencdmp.model.dmpblueprint.DmpBlueprint;
import org.opencdmp.model.file.FileEnvelope;
import org.opencdmp.model.persist.*;
import org.opencdmp.model.persist.descriptionproperties.*;
@ -1281,28 +1286,19 @@ public class DescriptionServiceImpl implements DescriptionService {
//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 (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();
persist.setLabel(descriptionXml.getLabel());
persist.setDescription(descriptionXml.getDescription());
persist.setStatus(DescriptionStatus.Draft);
persist.setDmpId(dmpId);
if (descriptionXml.getDescriptionTemplate() != null) {
persist.setDescriptionTemplateId(descriptionXml.getDescriptionTemplate().getId());
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.setDescriptionTemplateId(this.xmlToDescriptionTemplatePersist(descriptionXml));
persist.setDmpDescriptionTemplateId(this.xmlToDmpDescriptionTemplatePersist(descriptionXml, dmpId));
persist.setTags(descriptionXml.getTags());
persist.setProperties(this.xmlToPropertyDefinitionToPersist(descriptionXml));
@ -1311,6 +1307,44 @@ public class DescriptionServiceImpl implements DescriptionService {
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) {
if (descriptionXml == null)

View File

@ -26,6 +26,9 @@ public interface DescriptionTemplateService {
void deleteAndSave(UUID id) throws MyForbiddenException, InvalidApplicationException;
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(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;
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.commons.JsonHandlingService;
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.scope.tenant.TenantScope;
import org.opencdmp.commons.scope.user.UserScope;
import org.opencdmp.commons.types.descriptiontemplate.*;
import org.opencdmp.commons.types.descriptiontemplate.fielddata.BaseFieldDataEntity;
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.data.DescriptionTemplateEntity;
import org.opencdmp.data.TenantEntityManager;
@ -38,7 +43,6 @@ import org.opencdmp.data.UserEntity;
import org.opencdmp.errorcode.ErrorThesaurusProperties;
import org.opencdmp.integrationevent.outbox.notification.NotifyIntegrationEvent;
import org.opencdmp.integrationevent.outbox.notification.NotifyIntegrationEventHandler;
import org.opencdmp.model.UserContactInfo;
import org.opencdmp.model.builder.descriptiontemplate.DescriptionTemplateBuilder;
import org.opencdmp.model.deleter.DescriptionTemplateDeleter;
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.user.User;
import org.opencdmp.query.DescriptionTemplateQuery;
import org.opencdmp.query.UserContactInfoQuery;
import org.opencdmp.query.UserDescriptionTemplateQuery;
import org.opencdmp.service.fielddatahelper.FieldDataHelperService;
import org.opencdmp.service.fielddatahelper.FieldDataHelperServiceProvider;
@ -664,19 +667,19 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic
//region Import
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));
@Override
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);
DescriptionTemplateImportExport importXml = this.xmlHandlingService.fromXml(DescriptionTemplateImportExport.class, new String(bytes, StandardCharsets.UTF_8));
if (groupId == null) groupId = importXml.getGroupId();
long activeDescriptionTemplatesForTheGroup = groupId != null ? this.queryFactory.query(DescriptionTemplateQuery.class).disableTracking()
.isActive(IsActive.Active)
.groupIds(groupId)
.count() : 0;
if (activeDescriptionTemplatesForTheGroup == 0) {
DescriptionTemplatePersist persist = new DescriptionTemplatePersist();
persist.setLabel(label);
@ -689,13 +692,13 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic
return this.persist(persist, groupId, fields);
} else {
DescriptionTemplateEntity latestVersionDescriptionTemplate = this.queryFactory.query(DescriptionTemplateQuery.class).disableTracking()
.versionStatuses(DescriptionTemplateVersionStatus.Current)
.isActive(IsActive.Active)
.statuses(DescriptionTemplateStatus.Finalized)
.groupIds(groupId)
.first();
.versionStatuses(DescriptionTemplateVersionStatus.Current)
.isActive(IsActive.Active)
.statuses(DescriptionTemplateStatus.Finalized)
.groupIds(groupId)
.first();
if (latestVersionDescriptionTemplate == null) throw new MyValidationException(this.errors.getDescriptionTemplateIsNotFinalized().getCode(), this.errors.getDescriptionTemplateIsNotFinalized().getMessage());
NewVersionDescriptionTemplatePersist persist = new NewVersionDescriptionTemplatePersist();
persist.setId(latestVersionDescriptionTemplate.getId());
persist.setLabel(label);
@ -705,12 +708,23 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic
persist.setDefinition(this.xmlDefinitionToPersist(importXml));
persist.setType(importXml.getType());
persist.setHash(this.conventionService.hashValue(latestVersionDescriptionTemplate.getUpdatedAt()));
this.validatorFactory.validator(NewVersionDescriptionTemplatePersist.NewVersionDescriptionTemplatePersistValidator.class).validateForce(persist);
return this.createNewVersion(persist, fields);
}
}
@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) {
DefinitionPersist definitionPersist = new DefinitionPersist();
if (importExport == null)

View File

@ -361,7 +361,7 @@ public class DmpServiceImpl implements DmpService {
.groupIds(data.getGroupId());
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.getStatus().equals(DmpStatus.Finalized)) previousDmp.setVersionStatus(DmpVersionStatus.Current);
else previousDmp.setVersionStatus(DmpVersionStatus.NotFinalized);
@ -493,12 +493,12 @@ public class DmpServiceImpl implements DmpService {
if (!oldDmpEntity.getBlueprintId().equals(blueprintEntity.getId())){
// 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)){
for (SectionEntity section: sections) {
if (!this.conventionService.isListNullOrEmpty(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);
if (existingBlueprintDescriptionTemplateEntity == null){
DmpDescriptionTemplateEntity newTemplate = new DmpDescriptionTemplateEntity();
@ -814,7 +814,7 @@ public class DmpServiceImpl implements DmpService {
private void checkDuplicateDmpUser(List<DmpUserPersist> model){
for (DmpUserPersist user: model) {
List<DmpUserPersist> duplicateUser = null;
List<DmpUserPersist> duplicateUser;
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());
} else {
@ -950,8 +950,7 @@ public class DmpServiceImpl implements DmpService {
if (fieldEntity.getCategory().equals(DmpBlueprintFieldCategory.Extra)) {
ExtraFieldEntity extraFieldEntity = (ExtraFieldEntity) fieldEntity;
if (extraFieldEntity == null) return data;
if (DmpBlueprintExtraFieldDataType.isDateType(extraFieldEntity.getType())){
if (DmpBlueprintExtraFieldDataType.isDateType(extraFieldEntity.getType())){
data.setDateValue(persist.getDateValue());
} else if (DmpBlueprintExtraFieldDataType.isNumberType(extraFieldEntity.getType())){
data.setNumberValue(persist.getNumberValue());
@ -1215,7 +1214,7 @@ public class DmpServiceImpl implements DmpService {
.groupIds(dmp.getGroupId());
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.getStatus().equals(DmpStatus.Finalized)) previousDmp.setVersionStatus(DmpVersionStatus.Current);
else previousDmp.setVersionStatus(DmpVersionStatus.NotFinalized);
@ -1593,8 +1592,11 @@ public class DmpServiceImpl implements DmpService {
String xml = this.xmlHandlingService.toXml(this.exportXmlEntity(data.getId(), false));
return this.responseUtilsService.buildResponseFileFromText(xml, data.getLabel() + ".xml");
}
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();
xml.setId(data.getId());
xml.setDescription(data.getDescription());
@ -1604,48 +1606,30 @@ public class DmpServiceImpl implements DmpService {
xml.setFinalizedAt(data.getFinalizedAt());
xml.setPublicAfter(data.getPublicAfter());
xml.setVersion(data.getVersion());
if (propertiesEntity != null && !this.conventionService.isListNullOrEmpty(propertiesEntity.getContacts())) {
List<DmpContactImportExport> dmpContactImportExports = new LinkedList<>();
for (DmpContactEntity contactEntity : propertiesEntity.getContacts()) {
dmpContactImportExports.add(this.dmpContactToExport(contactEntity));
}
xml.setContacts(dmpContactImportExports);
}
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));
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 xml;
}
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.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 descriptionImportExports;
}
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();
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();
@ -1656,17 +1640,9 @@ public class DmpServiceImpl implements DmpService {
for (DmpReferenceEntity descriptionTemplateEntity : dmpReferences) {
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();
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;
return null;
}
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){
xml.setId(reference.getId());
xml.setLabel(reference.getLabel());
xml.setSource(reference.getSource());
xml.setSourceType(reference.getSourceType());
xml.setReference(reference.getReference());
ReferenceTypeEntity referenceType = referenceTypeEntityMap.getOrDefault(reference.getTypeId(), null);
if (referenceType != null) xml.setType(this.dmpReferenceTypeToExport(referenceType));
@ -1697,6 +1675,18 @@ public class DmpServiceImpl implements DmpService {
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) {
DmpBlueprintValueImportExport xml = new DmpBlueprintValueImportExport();
if (entity == null) return xml;
@ -1706,7 +1696,6 @@ public class DmpServiceImpl implements DmpService {
if (fieldEntity.getCategory().equals(DmpBlueprintFieldCategory.Extra)) {
ExtraFieldEntity extraFieldEntity = (ExtraFieldEntity) fieldEntity;
if (extraFieldEntity == null) return xml;
if (DmpBlueprintExtraFieldDataType.isDateType(extraFieldEntity.getType())){
xml.setDateValue(entity.getDateValue());
} else if (DmpBlueprintExtraFieldDataType.isNumberType(extraFieldEntity.getType())){
@ -1720,6 +1709,19 @@ public class DmpServiceImpl implements DmpService {
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) {
DmpDescriptionTemplateImportExport xml = new DmpDescriptionTemplateImportExport();
if (entity == null) return xml;
@ -1730,6 +1732,20 @@ public class DmpServiceImpl implements DmpService {
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) {
DmpUserImportExport xml = new DmpUserImportExport();
if (entity == null) return xml;
@ -1745,6 +1761,17 @@ public class DmpServiceImpl implements DmpService {
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) {
DmpContactImportExport xml = new DmpContactImportExport();
if (entity == null) return xml;
@ -1760,7 +1787,7 @@ public class DmpServiceImpl implements DmpService {
//region Import Xml
public Dmp importXml(byte[] bytes, 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));
@ -1776,128 +1803,148 @@ public class DmpServiceImpl implements DmpService {
persist.setDescription(dmpXml.getDescription());
persist.setAccessType(dmpXml.getAccess());
persist.setLanguage(dmpXml.getLanguage());
persist.setUsers(this.xmlToDmpUsersPersist(dmpXml)); //TODO ignore users not exists. by id betters solution
persist.setProperties(this.xmlToDmpPropertiesPersist(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(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());
}
persist.setDescriptionTemplates(this.xmlDmpDescriptionTemplatesToPersist(dmpXml)); //TODO maybe we should create templates if not exists
persist.setBlueprint(this.xmlDmpBlueprintToPersist(dmpXml));
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 (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()){
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;
}
private DmpPropertiesPersist xmlToDmpPropertiesPersist(DmpImportExport importXml) {
if (importXml == null)
return null;
DmpPropertiesPersist persist = new DmpPropertiesPersist();
List<DmpContactPersist> contacts = new ArrayList<>();
if (!this.conventionService.isListNullOrEmpty(importXml.getContacts())) {
for (DmpContactImportExport contact : importXml.getContacts()) {
contacts.add(this.xmlDmpContactToPersist(contact));
private UUID xmlDmpBlueprintToPersist(DmpImportExport dmpXml) throws JAXBException, InvalidApplicationException, ParserConfigurationException, IOException, TransformerException, InstantiationException, IllegalAccessException, SAXException {
if (dmpXml.getBlueprint() != 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();
if (dmpBlueprintEntity != null){
return dmpBlueprintEntity.getId();
} else {
DmpBlueprint persisted = this.dmpBlueprintService.importXml(dmpXml.getBlueprint(), null, dmpXml.getBlueprint().getLabel(), new BaseFieldSet().ensure(DmpBlueprint._label).ensure(DmpBlueprint._hash));
return persisted.getId();
}
}
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();
if (!this.conventionService.isListNullOrEmpty(sections)){
for (BlueprintSectionImportExport section : importXml.getBlueprint().getDmpBlueprintDefinition().getSections()) {
// reference
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));
}
}
}
// 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));
}
}
}
this.xmlToDmpBlueprintExtraFieldValuePersist(importXml, section, dmpBlueprintValues);
this.xmlToDmpBlueprintReferenceFieldValuePersist(importXml, section, dmpBlueprintValues);
}
}
return dmpBlueprintValues;
}
return null;
}
persist.setContacts(contacts);
persist.setDmpBlueprintValues(dmpBlueprintValues);
private void xmlToDmpBlueprintExtraFieldValuePersist(DmpImportExport importXml, BlueprintSectionImportExport section, Map<UUID, DmpBlueprintValuePersist> 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)));
}
}
}
}
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));
}
}
}
}
return persist;
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) {
if (blueprintReferenceTypeFieldImportXml == null || this.conventionService.isListNullOrEmpty(dmpReferencesImportXml))
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();
persist.setFieldId(blueprintReferenceTypeFieldImportXml.getId());
if (blueprintReferenceTypeFieldImportXml.getMultipleSelect()){
List<ReferencePersist> references = new ArrayList<>();
for (DmpReferenceImportExport dmpReference : dmpReferencesImportXml) {
references.add(this.xmlDmpReferenceToReferencePersist(dmpReference));
references.add(this.xmlDmpReferenceToReferencePersist(dmpReference, referenceTypeEntity));
}
persist.setReferences(references);
} else {
persist.setReference(this.xmlDmpReferenceToReferencePersist(dmpReferencesImportXml.stream().findFirst().orElse(null)));
persist.setReference(this.xmlDmpReferenceToReferencePersist(dmpReferencesImportXml.stream().findFirst().orElse(null), referenceTypeEntity));
}
return persist;
}
private ReferencePersist xmlDmpReferenceToReferencePersist(DmpReferenceImportExport importXml) {
private ReferencePersist xmlDmpReferenceToReferencePersist(DmpReferenceImportExport importXml, ReferenceTypeEntity referenceTypeEntity) {
if (importXml == 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();
persist.setId(importXml.getId());
persist.setLabel(importXml.getLabel());
persist.setReference(importXml.getReference());
if (referenceEntity == null) {
persist.setLabel(importXml.getLabel());
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;
}
@ -1908,17 +1955,27 @@ public class DmpServiceImpl implements DmpService {
DmpBlueprintValuePersist persist = new DmpBlueprintValuePersist();
persist.setFieldId(importXml.getFieldId());
if (DmpBlueprintExtraFieldDataType.isDateType(extraFieldImportExport.getType())){
persist.setDateValue(importXml.getDateValue());
}else if (DmpBlueprintExtraFieldDataType.isNumberType(extraFieldImportExport.getType())){
persist.setNumberValue(importXml.getNumberValue());
} else {
persist.setFieldValue(importXml.getValue());
switch (extraFieldImportExport.getType()){
case Date -> persist.setDateValue(importXml.getDateValue());
case Number -> persist.setNumberValue(importXml.getNumberValue());
case Text, RichTex -> persist.setFieldValue(importXml.getValue());
default -> throw new MyApplicationException("unrecognized type " + extraFieldImportExport.getType());
}
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) {
if (importXml == null)
return null;
@ -1931,6 +1988,20 @@ public class DmpServiceImpl implements DmpService {
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) {
if (importXml == null)
return null;
@ -1987,8 +2058,8 @@ public class DmpServiceImpl implements DmpService {
persist.setProperties(this.commonDmpPropertiesToPersist(model));
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<UUID> userIds = users == null ? new ArrayList<>() : users.stream().map(x -> x.getId()).collect(Collectors.toList());
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(UserEntity::getId).collect(Collectors.toList());
List<DmpUserPersist> dmpUsers = new ArrayList<>();
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())){
for (FieldModel field : section.getFields()) {
// reference
if (field.getCategory().equals(DmpBlueprintFieldCategory.ReferenceType)){
if (field.getCategory().equals(org.opencdmp.commonmodels.enums.DmpBlueprintFieldCategory.ReferenceType)){
ReferenceTypeFieldModel referenceField = (ReferenceTypeFieldModel) field;
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)){
@ -2057,10 +2128,10 @@ public class DmpServiceImpl implements DmpService {
}
} else {
// 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);
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);
} else {
persist.setReference(this.commonDmpReferenceToReferencePersist(dmpReferences.get(0).getReference()));
persist.setReference(this.commonDmpReferenceToReferencePersist(dmpReferences.getFirst().getReference()));
}
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;
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;
}

View File

@ -621,19 +621,19 @@ public class DmpBlueprintServiceImpl implements DmpBlueprintService {
//region Import
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));
@Override
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);
BlueprintImportExport dmpDefinition = this.xmlHandlingService.fromXml(BlueprintImportExport.class, new String(bytes, StandardCharsets.UTF_8));
if (groupId == null) groupId = dmpDefinition.getGroupId();
long activeBlueprintForTheGroup = groupId != null ? this.queryFactory.query(DmpBlueprintQuery.class).disableTracking()
.isActive(IsActive.Active)
.groupIds(groupId)
.count() : 0;
if (activeBlueprintForTheGroup == 0) {
DmpBlueprintPersist persist = new DmpBlueprintPersist();
@ -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) {
if (importXml == null)
return null;