rda import support
This commit is contained in:
parent
c01fddf534
commit
a17dfe5683
|
@ -7,6 +7,7 @@ import gr.cite.tools.exception.MyNotFoundException;
|
|||
import gr.cite.tools.exception.MyValidationException;
|
||||
import gr.cite.tools.fieldset.FieldSet;
|
||||
import jakarta.xml.bind.JAXBException;
|
||||
import org.opencdmp.commonmodels.models.dmpblueprint.DmpBlueprintModel;
|
||||
import org.opencdmp.commons.enums.DmpBlueprintSystemFieldType;
|
||||
import org.opencdmp.commons.types.dmpblueprint.importexport.BlueprintImportExport;
|
||||
import org.opencdmp.data.DmpBlueprintEntity;
|
||||
|
@ -42,4 +43,5 @@ public interface DmpBlueprintService {
|
|||
DmpBlueprint importXml(BlueprintImportExport dmpDefinition, UUID groupId, String label, FieldSet fields) throws MyForbiddenException, MyNotFoundException, JAXBException, ParserConfigurationException, TransformerException, InvalidApplicationException, IOException, InstantiationException, IllegalAccessException, SAXException;
|
||||
|
||||
DmpBlueprint importXml(byte[] bytes, UUID groupId, String label, FieldSet fields) throws MyForbiddenException, MyNotFoundException, JAXBException, ParserConfigurationException, TransformerException, InvalidApplicationException, IOException, InstantiationException, IllegalAccessException, SAXException;
|
||||
DmpBlueprint importCommonModel(DmpBlueprintModel dmpDefinition, FieldSet fields) throws MyForbiddenException, MyNotFoundException, JAXBException, ParserConfigurationException, TransformerException, InvalidApplicationException, IOException, InstantiationException, IllegalAccessException, SAXException;
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ import jakarta.xml.bind.JAXBException;
|
|||
import org.jetbrains.annotations.NotNull;
|
||||
import org.opencdmp.authorization.AuthorizationFlags;
|
||||
import org.opencdmp.authorization.Permission;
|
||||
import org.opencdmp.commonmodels.models.dmpblueprint.*;
|
||||
import org.opencdmp.commons.XmlHandlingService;
|
||||
import org.opencdmp.commons.enums.*;
|
||||
import org.opencdmp.commons.scope.tenant.TenantScope;
|
||||
|
@ -804,5 +805,188 @@ public class DmpBlueprintServiceImpl implements DmpBlueprintService {
|
|||
}
|
||||
|
||||
//endregion
|
||||
|
||||
//region Import RDA Json
|
||||
|
||||
@Override
|
||||
public DmpBlueprint importCommonModel(DmpBlueprintModel dmpDefinition, FieldSet fields) throws MyForbiddenException, MyNotFoundException, JAXBException, ParserConfigurationException, TransformerException, InvalidApplicationException, IOException, InstantiationException, IllegalAccessException, SAXException {
|
||||
logger.debug(new MapLogEntry("import data").And("dmpDefinition", dmpDefinition).And("fields", fields));
|
||||
|
||||
this.authorizationService.authorizeForce(Permission.ImportDmpBlueprint);
|
||||
|
||||
long activeBlueprintForTheGroup = dmpDefinition.getGroupId() != null ? this.queryFactory.query(DmpBlueprintQuery.class).disableTracking()
|
||||
.isActive(IsActive.Active)
|
||||
.groupIds(dmpDefinition.getGroupId())
|
||||
.count() : 0;
|
||||
|
||||
if (activeBlueprintForTheGroup == 0) {
|
||||
DmpBlueprintPersist persist = new DmpBlueprintPersist();
|
||||
|
||||
persist.setLabel(dmpDefinition.getLabel());
|
||||
persist.setStatus(DmpBlueprintStatus.Draft);
|
||||
persist.setDefinition(this.commonModelDefinitionToPersist(dmpDefinition.getDefinition()));
|
||||
|
||||
this.validatorFactory.validator(DmpBlueprintPersist.DmpBlueprintPersistValidator.class).validateForce(persist);
|
||||
return this.persist(persist, dmpDefinition.getGroupId(), fields);
|
||||
} else {
|
||||
DmpBlueprintEntity latestVersionDmpBlueprint = this.queryFactory.query(DmpBlueprintQuery.class)
|
||||
.disableTracking()
|
||||
.versionStatuses(DmpBlueprintVersionStatus.Current)
|
||||
.isActive(IsActive.Active)
|
||||
.statuses(DmpBlueprintStatus.Finalized)
|
||||
.groupIds(dmpDefinition.getGroupId())
|
||||
.first();
|
||||
if (latestVersionDmpBlueprint == null) throw new MyValidationException(this.errors.getDmpIsNotFinalized().getCode(), this.errors.getDmpIsNotFinalized().getMessage());
|
||||
NewVersionDmpBlueprintPersist persist = new NewVersionDmpBlueprintPersist();
|
||||
persist.setId(latestVersionDmpBlueprint.getId());
|
||||
persist.setLabel(dmpDefinition.getLabel());
|
||||
persist.setStatus(DmpBlueprintStatus.Draft);
|
||||
persist.setDefinition(this.commonModelDefinitionToPersist(dmpDefinition.getDefinition()));
|
||||
persist.setHash(this.conventionService.hashValue(latestVersionDmpBlueprint.getUpdatedAt()));
|
||||
|
||||
this.validatorFactory.validator(NewVersionDmpBlueprintPersist.NewVersionDmpBlueprintPersistValidator.class).validateForce(persist);
|
||||
return this.createNewVersion(persist, fields);
|
||||
}
|
||||
}
|
||||
|
||||
private DefinitionPersist commonModelDefinitionToPersist(DefinitionModel commonModel) {
|
||||
if (commonModel == null)
|
||||
return null;
|
||||
DefinitionPersist persist = new DefinitionPersist();
|
||||
List<SectionPersist> dmpBlueprintSections = new ArrayList<>();
|
||||
if (!this.conventionService.isListNullOrEmpty(commonModel.getSections())) {
|
||||
for (SectionModel section : commonModel.getSections()) {
|
||||
dmpBlueprintSections.add(this.commonModelSectionToPersist(section));
|
||||
}
|
||||
}
|
||||
persist.setSections(dmpBlueprintSections);
|
||||
return persist;
|
||||
}
|
||||
|
||||
private SectionPersist commonModelSectionToPersist(SectionModel commonModel) {
|
||||
SectionPersist persist = new SectionPersist();
|
||||
persist.setId(commonModel.getId());
|
||||
persist.setLabel(commonModel.getLabel());
|
||||
persist.setDescription(commonModel.getDescription());
|
||||
persist.setOrdinal(commonModel.getOrdinal());
|
||||
persist.setHasTemplates(commonModel.getHasTemplates());
|
||||
List<FieldPersist> dmpBlueprintFieldModels = new LinkedList<>();
|
||||
if (!this.conventionService.isListNullOrEmpty(commonModel.getFields())) {
|
||||
for (SystemFieldModel systemField : commonModel.getFields().stream().filter(x-> org.opencdmp.commonmodels.enums.DmpBlueprintFieldCategory.System.equals(x.getCategory())).map(x-> (SystemFieldModel)x).toList()) {
|
||||
dmpBlueprintFieldModels.add(this.commonModelSystemFieldToPersist(systemField));
|
||||
}
|
||||
for (ReferenceTypeFieldModel referenceField : commonModel.getFields().stream().filter(x-> org.opencdmp.commonmodels.enums.DmpBlueprintFieldCategory.ReferenceType.equals(x.getCategory())).map(x-> (ReferenceTypeFieldModel)x).toList()) {
|
||||
dmpBlueprintFieldModels.add(this.commonModelReferenceFieldToPersist(referenceField));
|
||||
}
|
||||
for (ExtraFieldModel extraField : commonModel.getFields().stream().filter(x-> org.opencdmp.commonmodels.enums.DmpBlueprintFieldCategory.Extra.equals(x.getCategory())).map(x-> (ExtraFieldModel)x).toList()) {
|
||||
dmpBlueprintFieldModels.add(this.commonExtraFieldToPersist(extraField));
|
||||
}
|
||||
}
|
||||
persist.setFields(dmpBlueprintFieldModels);
|
||||
// List<DescriptionTemplatePersist> dmpBlueprintDescriptionTemplates = new LinkedList<>();
|
||||
// if (!this.conventionService.isListNullOrEmpty(importXml.getDescriptionTemplates())) {
|
||||
// for (BlueprintDescriptionTemplateImportExport descriptionTemplate : importXml.getDescriptionTemplates()) {
|
||||
// dmpBlueprintDescriptionTemplates.add(this.xmlDescriptionTemplateToPersist(descriptionTemplate));
|
||||
// }
|
||||
// }
|
||||
// persist.setDescriptionTemplates(dmpBlueprintDescriptionTemplates);
|
||||
//
|
||||
// List<UUID> prefillingSources = new LinkedList<>();
|
||||
// if (!this.conventionService.isListNullOrEmpty(importXml.getPrefillingSources())) {
|
||||
// for (BlueprintPrefillingSourceImportExport prefillingSource : importXml.getPrefillingSources()) {
|
||||
// prefillingSources.add(this.xmlPrefillingSourceToPersist(prefillingSource));
|
||||
// }
|
||||
// }
|
||||
// persist.setPrefillingSourcesIds(prefillingSources);
|
||||
return persist;
|
||||
}
|
||||
|
||||
// private DescriptionTemplatePersist xmlDescriptionTemplateToPersist(BlueprintDescriptionTemplateImportExport importXml) {
|
||||
// org.opencdmp.data.DescriptionTemplateEntity data = importXml.getDescriptionTemplateGroupId() != null ? this.queryFactory.query(DescriptionTemplateQuery.class).disableTracking().groupIds(importXml.getDescriptionTemplateGroupId()).disableTracking().firstAs(new BaseFieldSet().ensure(DescriptionTemplate._groupId)) : null;
|
||||
// if (data == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{importXml.getDescriptionTemplateGroupId(), DescriptionTemplate.class.getSimpleName()}, LocaleContextHolder.getLocale()));
|
||||
//
|
||||
// DescriptionTemplatePersist persist = new DescriptionTemplatePersist();
|
||||
// persist.setDescriptionTemplateGroupId(importXml.getDescriptionTemplateGroupId());
|
||||
// persist.setLabel(importXml.getLabel());
|
||||
// persist.setMinMultiplicity(importXml.getMinMultiplicity());
|
||||
// persist.setMaxMultiplicity(importXml.getMaxMultiplicity());
|
||||
// return persist;
|
||||
// }
|
||||
//
|
||||
// private UUID xmlPrefillingSourceToPersist(BlueprintPrefillingSourceImportExport importXml) {
|
||||
// org.opencdmp.data.PrefillingSourceEntity data = importXml.getId() != null ? this.queryFactory.query(PrefillingSourceQuery.class).disableTracking().ids(importXml.getId()).disableTracking().firstAs(new BaseFieldSet().ensure(PrefillingSource._id)) : null;
|
||||
// if (data == null) {
|
||||
// if (!this.conventionService.isNullOrEmpty(importXml.getCode())) data = this.queryFactory.query(PrefillingSourceQuery.class).disableTracking().codes(importXml.getCode()).disableTracking().firstAs(new BaseFieldSet().ensure(PrefillingSource._id));
|
||||
// if (data == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{importXml.getId(), DescriptionTemplate.class.getSimpleName()}, LocaleContextHolder.getLocale()));
|
||||
// }
|
||||
//
|
||||
// return data.getId();
|
||||
// }
|
||||
|
||||
private FieldPersist commonExtraFieldToPersist(ExtraFieldModel commonModel) {
|
||||
ExtraFieldPersist persist = new ExtraFieldPersist();
|
||||
persist.setId(commonModel.getId());
|
||||
persist.setCategory(DmpBlueprintFieldCategory.Extra);
|
||||
switch (commonModel.getDataType()){
|
||||
case Text -> persist.setDataType(DmpBlueprintExtraFieldDataType.Text);
|
||||
case Date -> persist.setDataType(DmpBlueprintExtraFieldDataType.Date);
|
||||
case Number -> persist.setDataType(DmpBlueprintExtraFieldDataType.Number);
|
||||
case RichTex -> persist.setDataType(DmpBlueprintExtraFieldDataType.RichTex);
|
||||
default -> throw new InternalError("unknown type: " + commonModel.getDataType());
|
||||
}
|
||||
persist.setLabel(commonModel.getLabel());
|
||||
persist.setPlaceholder(commonModel.getPlaceholder());
|
||||
persist.setDescription(commonModel.getDescription());
|
||||
persist.setOrdinal(commonModel.getOrdinal());
|
||||
persist.setRequired(commonModel.getRequired());
|
||||
persist.setSemantics(commonModel.getSemantics());
|
||||
return persist;
|
||||
}
|
||||
|
||||
private FieldPersist commonModelSystemFieldToPersist(SystemFieldModel commonModel) {
|
||||
SystemFieldPersist persist = new SystemFieldPersist();
|
||||
persist.setId(commonModel.getId());
|
||||
persist.setCategory(DmpBlueprintFieldCategory.System);
|
||||
switch (commonModel.getSystemFieldType()){
|
||||
case User -> persist.setSystemFieldType(DmpBlueprintSystemFieldType.User);
|
||||
case AccessRights -> persist.setSystemFieldType(DmpBlueprintSystemFieldType.AccessRights);
|
||||
case Contact -> persist.setSystemFieldType(DmpBlueprintSystemFieldType.Contact);
|
||||
case Description -> persist.setSystemFieldType(DmpBlueprintSystemFieldType.Description);
|
||||
case Language -> persist.setSystemFieldType(DmpBlueprintSystemFieldType.Language);
|
||||
case Title -> persist.setSystemFieldType(DmpBlueprintSystemFieldType.Title);
|
||||
default -> throw new InternalError("unknown type: " + commonModel.getSystemFieldType());
|
||||
}
|
||||
persist.setLabel(commonModel.getLabel());
|
||||
persist.setPlaceholder(commonModel.getPlaceholder());
|
||||
persist.setDescription(commonModel.getDescription());
|
||||
persist.setOrdinal(commonModel.getOrdinal());
|
||||
persist.setRequired(commonModel.getRequired());
|
||||
persist.setSemantics(commonModel.getSemantics());
|
||||
return persist;
|
||||
}
|
||||
|
||||
private FieldPersist commonModelReferenceFieldToPersist(ReferenceTypeFieldModel commonModel) {
|
||||
|
||||
ReferenceTypeEntity data = commonModel.getReferenceType() != null && commonModel.getReferenceType().getId() != null ? this.queryFactory.query(ReferenceTypeQuery.class).disableTracking().ids(commonModel.getReferenceType().getId()).disableTracking().firstAs(new BaseFieldSet().ensure(ReferenceType._id)) : null;
|
||||
if (data == null){
|
||||
if (commonModel.getReferenceType() != null && !this.conventionService.isNullOrEmpty(commonModel.getReferenceType().getCode())) data = this.queryFactory.query(ReferenceTypeQuery.class).disableTracking().codes(commonModel.getReferenceType().getCode()).disableTracking().firstAs(new BaseFieldSet().ensure(ReferenceType._id));
|
||||
if (data == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{commonModel.getReferenceType().getCode(), ReferenceType.class.getSimpleName()}, LocaleContextHolder.getLocale()));
|
||||
}
|
||||
|
||||
ReferenceTypeFieldPersist persist = new ReferenceTypeFieldPersist();
|
||||
persist.setId(commonModel.getId());
|
||||
persist.setCategory(DmpBlueprintFieldCategory.ReferenceType);
|
||||
persist.setReferenceTypeId(data.getId());
|
||||
persist.setLabel(commonModel.getLabel());
|
||||
persist.setPlaceholder(commonModel.getPlaceholder());
|
||||
persist.setDescription(commonModel.getDescription());
|
||||
persist.setOrdinal(commonModel.getOrdinal());
|
||||
persist.setRequired(commonModel.getRequired());
|
||||
persist.setMultipleSelect(commonModel.getMultipleSelect());
|
||||
persist.setSemantics(commonModel.getSemantics());
|
||||
return persist;
|
||||
}
|
||||
|
||||
//endregion
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue