add import description, fix import/export models

This commit is contained in:
amentis 2024-05-20 13:20:45 +03:00
parent 6b69078007
commit 6023f6fa31
11 changed files with 323 additions and 8 deletions

View File

@ -2,6 +2,7 @@ package org.opencdmp.commons.types.descriptiontemplate.importexport;
import jakarta.xml.bind.annotation.*; import jakarta.xml.bind.annotation.*;
import java.util.ArrayList;
import java.util.List; import java.util.List;
@XmlAccessorType(XmlAccessType.FIELD) @XmlAccessorType(XmlAccessType.FIELD)
@ -109,4 +110,12 @@ public class DescriptionTemplateFieldSetImportExport {
public void setHasMultiplicity(boolean hasMultiplicity) { public void setHasMultiplicity(boolean hasMultiplicity) {
this.hasMultiplicity = hasMultiplicity; this.hasMultiplicity = hasMultiplicity;
} }
public List<DescriptionTemplateFieldImportExport> getAllField() {
return this.getFields() == null ? new ArrayList<>() : this.getFields();
}
public List<DescriptionTemplateFieldImportExport> getFieldById(String id) {
return this.getAllField().stream().filter(x-> id.equals(x.getId())).toList();
}
} }

View File

@ -3,6 +3,7 @@ package org.opencdmp.commons.types.descriptiontemplate.importexport;
import jakarta.xml.bind.annotation.*; import jakarta.xml.bind.annotation.*;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
@ -18,6 +19,10 @@ public class DescriptionTemplateImportExport {
private String language; private String language;
@XmlAttribute(name = "type") @XmlAttribute(name = "type")
private UUID type; private UUID type;
@XmlAttribute(name = "version")
private Short version;
@XmlElement(name = "groupId")
private UUID groupId;
@XmlElementWrapper(name = "pages") @XmlElementWrapper(name = "pages")
@XmlElement(name = "page") @XmlElement(name = "page")
private List<DescriptionTemplatePageImportExport> pages; private List<DescriptionTemplatePageImportExport> pages;
@ -64,4 +69,48 @@ public class DescriptionTemplateImportExport {
public void setType(UUID type) { public void setType(UUID type) {
this.type = type; this.type = type;
} }
public Short getVersion() {
return version;
}
public void setVersion(Short version) {
this.version = version;
}
public UUID getGroupId() {
return groupId;
}
public void setGroupId(UUID groupId) {
this.groupId = groupId;
}
public List<DescriptionTemplateFieldSetImportExport> getAllFieldSets(){
List<DescriptionTemplateFieldSetImportExport> fieldSets = new ArrayList<>();
if (this.getPages() != null){
for (DescriptionTemplatePageImportExport page: this.getPages()) {
fieldSets.addAll(page.getAllFieldSets());
}
}
return fieldSets;
}
public List<DescriptionTemplateFieldImportExport> getAllField(){
List<DescriptionTemplateFieldImportExport> fields = new ArrayList<>();
if (this.getPages() != null){
for (DescriptionTemplatePageImportExport page: this.getPages()) {
fields.addAll(page.getAllField());
}
}
return fields;
}
public List<DescriptionTemplateFieldSetImportExport> getFieldSetById(String id) {
return this.getAllFieldSets().stream().filter(x-> id.equals(x.getId())).toList();
}
public List<DescriptionTemplateFieldImportExport> getFieldById(String id) {
return this.getAllField().stream().filter(x-> id.equals(x.getId())).toList();
}
} }

View File

@ -2,6 +2,7 @@ package org.opencdmp.commons.types.descriptiontemplate.importexport;
import jakarta.xml.bind.annotation.*; import jakarta.xml.bind.annotation.*;
import java.util.ArrayList;
import java.util.List; import java.util.List;
@XmlAccessorType(XmlAccessType.FIELD) @XmlAccessorType(XmlAccessType.FIELD)
@ -49,4 +50,23 @@ public class DescriptionTemplatePageImportExport {
this.sections = sections; this.sections = sections;
} }
public List<DescriptionTemplateFieldImportExport> getAllField(){
List<DescriptionTemplateFieldImportExport> fields = new ArrayList<>();
if (this.getSections() != null){
for (DescriptionTemplateSectionImportExport section: this.getSections()) {
fields.addAll(section.getAllField());
}
}
return fields;
}
public List<DescriptionTemplateFieldSetImportExport> getAllFieldSets(){
List<DescriptionTemplateFieldSetImportExport> fieldSets = new ArrayList<>();
if (this.getSections() != null){
for (DescriptionTemplateSectionImportExport section: this.getSections()) {
fieldSets.addAll(section.getAllFieldSets());
}
}
return fieldSets;
}
} }

View File

@ -2,6 +2,7 @@ package org.opencdmp.commons.types.descriptiontemplate.importexport;
import jakarta.xml.bind.annotation.*; import jakarta.xml.bind.annotation.*;
import java.util.ArrayList;
import java.util.List; import java.util.List;
@XmlAccessorType(XmlAccessType.FIELD) @XmlAccessorType(XmlAccessType.FIELD)
@ -69,4 +70,32 @@ public class DescriptionTemplateSectionImportExport {
this.sections = sections; this.sections = sections;
} }
public List<DescriptionTemplateFieldImportExport> getAllField(){
List<DescriptionTemplateFieldImportExport> fields = new ArrayList<>();
if (this.getFieldSets() != null){
for (DescriptionTemplateFieldSetImportExport fieldSet: this.getFieldSets()) {
fields.addAll(fieldSet.getAllField());
}
}
if (this.getSections() != null){
for (DescriptionTemplateSectionImportExport section: this.getSections()) {
fields.addAll(section.getAllField());
}
}
return fields;
}
public List<DescriptionTemplateFieldSetImportExport> getAllFieldSets(){
List<DescriptionTemplateFieldSetImportExport> fieldSets = new ArrayList<>();
if (this.getFieldSets() != null){
fieldSets.addAll(this.getFieldSets());
}
if (this.getSections() != null){
for (DescriptionTemplateSectionImportExport section: this.getSections()) {
fieldSets.addAll(section.getAllFieldSets());
}
}
return fieldSets;
}
} }

View File

@ -28,6 +28,9 @@ public class DmpImportExport {
@XmlElement(name = "access") @XmlElement(name = "access")
private DmpAccessType access; private DmpAccessType access;
@XmlElement(name = "version")
private Short version;
@XmlElementWrapper(name = "contacts") @XmlElementWrapper(name = "contacts")
@XmlElement(name = "contact") @XmlElement(name = "contact")
private List<DmpContactImportExport> contacts; private List<DmpContactImportExport> contacts;
@ -173,5 +176,13 @@ public class DmpImportExport {
public void setDescriptions(List<DescriptionImportExport> descriptions) { public void setDescriptions(List<DescriptionImportExport> descriptions) {
this.descriptions = descriptions; this.descriptions = descriptions;
} }
public Short getVersion() {
return version;
}
public void setVersion(Short version) {
this.version = version;
}
} }

View File

@ -7,6 +7,7 @@ import gr.cite.tools.exception.MyValidationException;
import gr.cite.tools.fieldset.FieldSet; import gr.cite.tools.fieldset.FieldSet;
import jakarta.xml.bind.JAXBException; import jakarta.xml.bind.JAXBException;
import org.opencdmp.commons.types.description.importexport.DescriptionImportExport; import org.opencdmp.commons.types.description.importexport.DescriptionImportExport;
import org.opencdmp.data.DmpDescriptionTemplateEntity;
import org.opencdmp.data.StorageFileEntity; import org.opencdmp.data.StorageFileEntity;
import org.opencdmp.model.DescriptionValidationResult; import org.opencdmp.model.DescriptionValidationResult;
import org.opencdmp.model.StorageFile; import org.opencdmp.model.StorageFile;
@ -21,6 +22,7 @@ import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException; import javax.crypto.NoSuchPaddingException;
import javax.management.InvalidApplicationException; import javax.management.InvalidApplicationException;
import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerException;
import java.io.IOException; import java.io.IOException;
import java.security.InvalidAlgorithmParameterException; import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException; import java.security.InvalidKeyException;
@ -49,4 +51,7 @@ public interface DescriptionService {
DescriptionImportExport exportXmlEntity(UUID id, boolean ignoreAuthorize) throws MyForbiddenException, MyNotFoundException, JAXBException, ParserConfigurationException, IOException, InstantiationException, IllegalAccessException, SAXException, InvalidApplicationException; DescriptionImportExport exportXmlEntity(UUID id, boolean ignoreAuthorize) 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; 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;
} }

View File

@ -30,6 +30,8 @@ import org.opencdmp.commons.types.descriptionreference.DescriptionReferenceDataE
import org.opencdmp.commons.types.descriptiontemplate.FieldSetEntity; import org.opencdmp.commons.types.descriptiontemplate.FieldSetEntity;
import org.opencdmp.commons.types.descriptiontemplate.fielddata.ReferenceTypeDataEntity; import org.opencdmp.commons.types.descriptiontemplate.fielddata.ReferenceTypeDataEntity;
import org.opencdmp.commons.types.descriptiontemplate.fielddata.UploadDataEntity; import org.opencdmp.commons.types.descriptiontemplate.fielddata.UploadDataEntity;
import org.opencdmp.commons.types.descriptiontemplate.importexport.*;
import org.opencdmp.commons.types.descriptiontemplate.importexport.fielddata.ReferenceTypeDataImportExport;
import org.opencdmp.commons.types.notification.*; import org.opencdmp.commons.types.notification.*;
import org.opencdmp.commons.types.reference.DefinitionEntity; import org.opencdmp.commons.types.reference.DefinitionEntity;
import org.opencdmp.convention.ConventionService; import org.opencdmp.convention.ConventionService;
@ -86,6 +88,7 @@ import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException; import javax.crypto.NoSuchPaddingException;
import javax.management.InvalidApplicationException; import javax.management.InvalidApplicationException;
import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerException;
import java.io.IOException; import java.io.IOException;
import java.net.URLConnection; import java.net.URLConnection;
import java.security.InvalidAlgorithmParameterException; import java.security.InvalidAlgorithmParameterException;
@ -1096,9 +1099,12 @@ public class DescriptionServiceImpl implements DescriptionService {
xml.setLabel(data.getLabel()); xml.setLabel(data.getLabel());
xml.setFinalizedAt(data.getFinalizedAt()); xml.setFinalizedAt(data.getFinalizedAt());
DescriptionTemplateEntity blueprintEntity = this.queryFactory.query(DescriptionTemplateQuery.class).disableTracking().ids(data.getDescriptionTemplateId()).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).isActive(IsActive.Active).first(); DmpDescriptionTemplateEntity dmpDescriptionTemplateEntity = this.queryFactory.query(DmpDescriptionTemplateQuery.class).disableTracking().ids(data.getDmpDescriptionTemplateId()).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).isActive(IsActive.Active).first();
if (blueprintEntity != null) { if (dmpDescriptionTemplateEntity != null) xml.setSectionId(dmpDescriptionTemplateEntity.getSectionId());
xml.setDescriptionTemplate(this.descriptionTemplateService.exportXmlEntity(blueprintEntity.getId(), true));
DescriptionTemplateEntity descriptionTemplateEntity = this.queryFactory.query(DescriptionTemplateQuery.class).disableTracking().ids(data.getDescriptionTemplateId()).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).isActive(IsActive.Active).first();
if (descriptionTemplateEntity != null) {
xml.setDescriptionTemplate(this.descriptionTemplateService.exportXmlEntity(descriptionTemplateEntity.getId(), true));
} }
if (propertiesEntity != null) { if (propertiesEntity != null) {
@ -1112,8 +1118,8 @@ public class DescriptionServiceImpl implements DescriptionService {
List<ReferenceTypeEntity> referenceTypes = references == null ? new ArrayList<>() : this.queryFactory.query(ReferenceTypeQuery.class).disableTracking().ids(references.stream().map(ReferenceEntity::getTypeId).distinct().toList()).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).isActive(IsActive.Active).collect(); List<ReferenceTypeEntity> referenceTypes = references == null ? new ArrayList<>() : this.queryFactory.query(ReferenceTypeQuery.class).disableTracking().ids(references.stream().map(ReferenceEntity::getTypeId).distinct().toList()).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).isActive(IsActive.Active).collect();
Map<UUID, ReferenceTypeEntity> referenceTypeEntityMap = referenceTypes == null ? new HashMap<>() : referenceTypes.stream().collect(Collectors.toMap(ReferenceTypeEntity::getId, x-> x)); Map<UUID, ReferenceTypeEntity> referenceTypeEntityMap = referenceTypes == null ? new HashMap<>() : referenceTypes.stream().collect(Collectors.toMap(ReferenceTypeEntity::getId, x-> x));
List<DescriptionReferenceImportExport> dmpReferenceImportExports = new LinkedList<>(); List<DescriptionReferenceImportExport> dmpReferenceImportExports = new LinkedList<>();
for (DescriptionReferenceEntity descriptionTemplateEntity : dmpReferences) { for (DescriptionReferenceEntity descriptionReferenceEntity : dmpReferences) {
dmpReferenceImportExports.add(this.descriptionReferenceToExport(descriptionTemplateEntity, referenceEntityMap, referenceTypeEntityMap)); dmpReferenceImportExports.add(this.descriptionReferenceToExport(descriptionReferenceEntity, referenceEntityMap, referenceTypeEntityMap));
} }
xml.setReferences(dmpReferenceImportExports); xml.setReferences(dmpReferenceImportExports);
} }
@ -1224,4 +1230,165 @@ public class DescriptionServiceImpl implements DescriptionService {
} }
//endregion //endregion
//region Import
public Description importXml(DescriptionImportExport descriptionXml, UUID dmpId, List<DmpDescriptionTemplateEntity> dmpDescriptionTemplates, FieldSet fields) throws MyForbiddenException, MyNotFoundException, JAXBException, ParserConfigurationException, TransformerException, InvalidApplicationException, IOException, InstantiationException, IllegalAccessException, SAXException{
if (descriptionXml == null) throw new MyNotFoundException("Description xml not found");
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.setProperties(this.xmlToPropertyDefinitionToPersist(descriptionXml));
this.validatorFactory.validator(DescriptionPersist.DescriptionPersistValidator.class).validateForce(persist);
return this.persist(persist, fields);
}
private PropertyDefinitionPersist xmlToPropertyDefinitionToPersist(DescriptionImportExport descriptionXml) {
if (descriptionXml == null)
return null;
PropertyDefinitionPersist persist = new PropertyDefinitionPersist();
Map<String, PropertyDefinitionFieldSetPersist> fieldSetsMap = new HashMap<>();
if (!this.conventionService.isListNullOrEmpty(descriptionXml.getDescriptionTemplate().getPages())) {
if (descriptionXml.getProperties() != null && !this.conventionService.isListNullOrEmpty(descriptionXml.getProperties().getFieldSets())){
for (DescriptionPropertyDefinitionFieldSetImportExport fieldSet: descriptionXml.getProperties().getFieldSets()){
fieldSetsMap.put(fieldSet.getFieldSetId(), this.xmlPropertyDefinitionFieldSetToPersist(fieldSet, descriptionXml.getReferences(), descriptionXml.getDescriptionTemplate()));
}
}
}
persist.setFieldSets(fieldSetsMap);
return persist;
}
private PropertyDefinitionFieldSetPersist xmlPropertyDefinitionFieldSetToPersist(DescriptionPropertyDefinitionFieldSetImportExport importXml, List<DescriptionReferenceImportExport> references, DescriptionTemplateImportExport descriptionTemplate) {
if (importXml == null)
return null;
PropertyDefinitionFieldSetPersist persist = new PropertyDefinitionFieldSetPersist();
if (!this.conventionService.isListNullOrEmpty(importXml.getItems())){
List<PropertyDefinitionFieldSetItemPersist> items = new ArrayList<>();
for (DescriptionPropertyDefinitionFieldSetItemImportExport fieldSetItem: importXml.getItems()) {
items.add(this.xmlPropertyDefinitionFieldSetItemToPersist(fieldSetItem, references, descriptionTemplate));
}
persist.setItems(items);
return persist;
}
return null;
}
private PropertyDefinitionFieldSetItemPersist xmlPropertyDefinitionFieldSetItemToPersist(DescriptionPropertyDefinitionFieldSetItemImportExport importXml, List<DescriptionReferenceImportExport> references, DescriptionTemplateImportExport descriptionTemplate) {
if (importXml == null)
return null;
PropertyDefinitionFieldSetItemPersist persist = new PropertyDefinitionFieldSetItemPersist();
persist.setComment(importXml.getComment());
persist.setOrdinal(importXml.getOrdinal());
Map<String, FieldPersist> fields = new HashMap<>();
if (!this.conventionService.isListNullOrEmpty(importXml.getFields())){
for (DescriptionFieldImportExport field: importXml.getFields()) {
fields.put(field.getFieldId(), this.xmlFieldToPersist(field, references, descriptionTemplate));
}
}
persist.setFields(fields);
return persist;
}
private FieldPersist xmlFieldToPersist(DescriptionFieldImportExport importXml, List<DescriptionReferenceImportExport> references, DescriptionTemplateImportExport descriptionTemplate) {
if (importXml == null || descriptionTemplate == null)
return null;
DescriptionTemplateFieldImportExport descriptionTemplateField = descriptionTemplate.getFieldById(importXml.getFieldId()).stream().findFirst().orElse(null);
if (descriptionTemplateField == null){
return null;
}
FieldPersist persist = new FieldPersist();
if (!this.conventionService.isListNullOrEmpty(references) && descriptionTemplateField.getData().getFieldType().equals(FieldType.REFERENCE_TYPES)){
ReferenceTypeDataImportExport referenceTypeDataImportExport = (ReferenceTypeDataImportExport) descriptionTemplateField.getData();
if (referenceTypeDataImportExport != null){
List<DescriptionReferenceImportExport> referencesByField = references.stream().filter(x -> x.getFieldId().equals(importXml.getFieldId())).collect(Collectors.toList());
if (!this.conventionService.isListNullOrEmpty(referencesByField)){
if (referenceTypeDataImportExport.getMultipleSelect()){
List<ReferencePersist> referencePersists = new ArrayList<>();
for (DescriptionReferenceImportExport referenceImportExport: referencesByField) {
referencePersists.add(this.xmlDescriptionReferenceToPersist(referenceImportExport));
}
persist.setReferences(referencePersists);
}else {
persist.setReference(this.xmlDescriptionReferenceToPersist(referencesByField.stream().findFirst().orElse(null)));
}
}
}
}else {
persist.setBooleanValue(importXml.getBooleanValue());
persist.setDateValue(importXml.getDateValue());
persist.setTextValue(importXml.getTextValue());
persist.setTextListValue(importXml.getTextListValue());
if (importXml.getExternalIdentifier() != null){
persist.setExternalIdentifier(this.xmlExternalIdentifierToPersist(importXml.getExternalIdentifier()));
}
}
return persist;
}
private ReferencePersist xmlDescriptionReferenceToPersist(DescriptionReferenceImportExport importXml) {
if (importXml == null)
return null;
ReferencePersist persist = new ReferencePersist();
persist.setId(importXml.getId());
persist.setLabel(importXml.getLabel());
persist.setReference(importXml.getReference());
return persist;
}
private ExternalIdentifierPersist xmlExternalIdentifierToPersist(DescriptionExternalIdentifierImportExport importXml) {
if (importXml == null)
return null;
ExternalIdentifierPersist persist = new ExternalIdentifierPersist();
persist.setType(importXml.getType());
persist.setIdentifier(importXml.getIdentifier());
return persist;
}
//endregion
} }

View File

@ -926,6 +926,9 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic
xml.setType(data.getTypeId()); xml.setType(data.getTypeId());
xml.setLanguage(data.getLanguage()); xml.setLanguage(data.getLanguage());
xml.setDescription(data.getDescription()); xml.setDescription(data.getDescription());
xml.setGroupId(data.getGroupId());
xml.setVersion(data.getVersion());
List<DescriptionTemplatePageImportExport> pagesDatasetEntity = new LinkedList<>(); List<DescriptionTemplatePageImportExport> pagesDatasetEntity = new LinkedList<>();
for (PageEntity xmlPage : entity.getPages()) { for (PageEntity xmlPage : entity.getPages()) {
pagesDatasetEntity.add(this.pageXmlToExport(xmlPage)); pagesDatasetEntity.add(this.pageXmlToExport(xmlPage));

View File

@ -1477,7 +1477,8 @@ public class DmpServiceImpl implements DmpService {
xml.setAccess(data.getAccessType()); xml.setAccess(data.getAccessType());
xml.setFinalizedAt(data.getFinalizedAt()); xml.setFinalizedAt(data.getFinalizedAt());
xml.setPublicAfter(data.getPublicAfter()); xml.setPublicAfter(data.getPublicAfter());
xml.setVersion(data.getVersion());
if (propertiesEntity != null && !this.conventionService.isListNullOrEmpty(propertiesEntity.getContacts())) { if (propertiesEntity != null && !this.conventionService.isListNullOrEmpty(propertiesEntity.getContacts())) {
List<DmpContactImportExport> dmpContactImportExports = new LinkedList<>(); List<DmpContactImportExport> dmpContactImportExports = new LinkedList<>();
List<UserEntity> users = this.queryFactory.query(UserQuery.class).disableTracking().ids(propertiesEntity.getContacts().stream().map(DmpContactEntity::getUserId).filter(Objects::nonNull).distinct().toList()).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).isActive(IsActive.Active).collect(); List<UserEntity> users = this.queryFactory.query(UserQuery.class).disableTracking().ids(propertiesEntity.getContacts().stream().map(DmpContactEntity::getUserId).filter(Objects::nonNull).distinct().toList()).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).isActive(IsActive.Active).collect();
@ -1668,7 +1669,22 @@ public class DmpServiceImpl implements DmpService {
this.validatorFactory.validator(DmpPersist.DmpPersistValidator.class).validateForce(persist); this.validatorFactory.validator(DmpPersist.DmpPersistValidator.class).validateForce(persist);
return this.persist(persist, fields); Dmp dmp = this.persist(persist, fields);
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);
}
}
return dmp;
} }
private DmpPropertiesPersist xmlToDmpPropertiesPersist(DmpImportExport importXml) { private DmpPropertiesPersist xmlToDmpPropertiesPersist(DmpImportExport importXml) {

View File

@ -340,7 +340,7 @@ public class DmpController {
@RequestMapping(method = RequestMethod.GET, value = "/xml/export/{id}", produces = "application/xml") @RequestMapping(method = RequestMethod.GET, value = "/xml/export/{id}", produces = "application/xml")
public @ResponseBody ResponseEntity<byte[]> getXml(@PathVariable UUID id) throws JAXBException, ParserConfigurationException, IOException, InstantiationException, IllegalAccessException, SAXException, InvalidApplicationException { public @ResponseBody ResponseEntity<byte[]> getXml(@PathVariable UUID id) throws JAXBException, ParserConfigurationException, IOException, InstantiationException, IllegalAccessException, SAXException, InvalidApplicationException {
logger.debug(new MapLogEntry("export" + DmpBlueprint.class.getSimpleName()).And("id", id)); logger.debug(new MapLogEntry("export" + Dmp.class.getSimpleName()).And("id", id));
ResponseEntity<byte[]> response = this.dmpService.exportXml(id); ResponseEntity<byte[]> response = this.dmpService.exportXml(id);

View File

@ -197,6 +197,12 @@ export class DmpService {
const formData = new FormData(); const formData = new FormData();
formData.append('file', file); formData.append('file', file);
formData.append('label', label); formData.append('label', label);
if (reqFields.length > 0){
for (var i = 0; i < reqFields.length; i++) {
formData.append('field[]', reqFields[i]);
}
}
return this.http.post(url, formData, { params: params }).pipe( return this.http.post(url, formData, { params: params }).pipe(
catchError((error: any) => throwError(error)));; catchError((error: any) => throwError(error)));;
} }