Merge branch 'dmp-refactoring' of https://code-repo.d4science.org/MaDgiK-CITE/argos into dmp-refactoring
This commit is contained in:
commit
14b2645539
|
@ -92,6 +92,7 @@ import org.opencdmp.model.referencetype.ReferenceType;
|
|||
import org.opencdmp.query.*;
|
||||
import org.opencdmp.service.actionconfirmation.ActionConfirmationService;
|
||||
import org.opencdmp.service.description.DescriptionService;
|
||||
import org.opencdmp.service.descriptiontemplate.DescriptionTemplateService;
|
||||
import org.opencdmp.service.dmpblueprint.DmpBlueprintService;
|
||||
import org.opencdmp.service.elastic.ElasticService;
|
||||
import org.opencdmp.service.filetransformer.FileTransformerService;
|
||||
|
@ -164,6 +165,7 @@ public class DmpServiceImpl implements DmpService {
|
|||
private final gr.cite.tools.validation.ValidatorFactory validatorFactory;
|
||||
|
||||
private final ElasticService elasticService;
|
||||
private final DescriptionTemplateService descriptionTemplateService;
|
||||
|
||||
|
||||
private final AnnotationEntityTouchedIntegrationEventHandler annotationEntityTouchedIntegrationEventHandler;
|
||||
|
@ -193,7 +195,7 @@ public class DmpServiceImpl implements DmpService {
|
|||
ActionConfirmationService actionConfirmationService,
|
||||
FileTransformerService fileTransformerService,
|
||||
ValidatorFactory validatorFactory,
|
||||
ElasticService elasticService,
|
||||
ElasticService elasticService, DescriptionTemplateService descriptionTemplateService,
|
||||
AnnotationEntityTouchedIntegrationEventHandler annotationEntityTouchedIntegrationEventHandler, AnnotationEntityRemovalIntegrationEventHandler annotationEntityRemovalIntegrationEventHandler, AuthorizationContentResolver authorizationContentResolver, TenantScope tenantScope, ResponseUtilsService responseUtilsService, DmpBlueprintService dmpBlueprintService) {
|
||||
this.entityManager = entityManager;
|
||||
this.authorizationService = authorizationService;
|
||||
|
@ -214,7 +216,8 @@ public class DmpServiceImpl implements DmpService {
|
|||
this.actionConfirmationService = actionConfirmationService;
|
||||
this.validatorFactory = validatorFactory;
|
||||
this.elasticService = elasticService;
|
||||
this.annotationEntityTouchedIntegrationEventHandler = annotationEntityTouchedIntegrationEventHandler;
|
||||
this.descriptionTemplateService = descriptionTemplateService;
|
||||
this.annotationEntityTouchedIntegrationEventHandler = annotationEntityTouchedIntegrationEventHandler;
|
||||
this.annotationEntityRemovalIntegrationEventHandler = annotationEntityRemovalIntegrationEventHandler;
|
||||
this.authorizationContentResolver = authorizationContentResolver;
|
||||
this.tenantScope = tenantScope;
|
||||
|
@ -1792,14 +1795,13 @@ public class DmpServiceImpl implements DmpService {
|
|||
logger.debug(new MapLogEntry("import data").And("bytes", bytes).And("label", label).And("fields", fields));
|
||||
|
||||
this.authorizationService.authorizeForce(Permission.NewDmp);
|
||||
DmpImportExport dmpXml = this.xmlHandlingService.fromXml(DmpImportExport.class, new String(bytes, StandardCharsets.UTF_8));
|
||||
|
||||
this.xmlEnsureDescriptionTemplates(dmpXml);
|
||||
|
||||
DmpPersist persist = new DmpPersist();
|
||||
|
||||
persist.setLabel(label);
|
||||
persist.setStatus(DmpStatus.Draft);
|
||||
|
||||
DmpImportExport dmpXml = this.xmlHandlingService.fromXml(DmpImportExport.class, new String(bytes, StandardCharsets.UTF_8));
|
||||
|
||||
persist.setDescription(dmpXml.getDescription());
|
||||
persist.setAccessType(dmpXml.getAccess());
|
||||
persist.setLanguage(dmpXml.getLanguage());
|
||||
|
@ -1814,8 +1816,6 @@ public class DmpServiceImpl implements DmpService {
|
|||
if (dmp == null) throw new MyApplicationException("Error creating dmp");
|
||||
|
||||
if (!this.conventionService.isListNullOrEmpty(dmpXml.getDescriptions())){
|
||||
|
||||
|
||||
for (DescriptionImportExport description: dmpXml.getDescriptions()){
|
||||
this.descriptionService.importXml(description, dmp.getId(), fields != null ? fields.extractPrefixed(this.conventionService.asPrefix(Dmp._description)) : null);
|
||||
}
|
||||
|
@ -1824,6 +1824,20 @@ public class DmpServiceImpl implements DmpService {
|
|||
return dmp;
|
||||
}
|
||||
|
||||
private void xmlEnsureDescriptionTemplates(DmpImportExport dmpImportExport) throws JAXBException, InvalidApplicationException, ParserConfigurationException, IOException, TransformerException, InstantiationException, IllegalAccessException, SAXException {
|
||||
if (!this.conventionService.isListNullOrEmpty(dmpImportExport.getDescriptions())){
|
||||
for (DescriptionImportExport descriptionXml: dmpImportExport.getDescriptions()) {
|
||||
if (descriptionXml.getDescriptionTemplate() != null) {
|
||||
org.opencdmp.data.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();
|
||||
if (descriptionTemplateEntity == null) {
|
||||
this.descriptionTemplateService.importXml(descriptionXml.getDescriptionTemplate(), null, descriptionXml.getDescriptionTemplate().getDescription(), new BaseFieldSet().ensure(DmpBlueprint._label).ensure(DmpBlueprint._hash));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
|
|
|
@ -262,19 +262,30 @@ public class DatasetMigrationService {
|
|||
}
|
||||
|
||||
this.addMultipleField(item, properties, descriptionTemplateDefinitionEntity, propertyDefinitionEntity, referenceTypeDefinitionEntityMap, referenceMap);
|
||||
|
||||
|
||||
List<DescriptionReferenceEntity> descriptionReferenceEntities = this.queryFactory.query(DescriptionReferenceQuery.class).descriptionIds(item.getId()).collect();
|
||||
Map<UUID, DescriptionReferenceEntity> descriptionReferenceEntitiesMap = descriptionReferenceEntities.stream().collect(Collectors.toMap(DescriptionReferenceEntity::getId, x-> x));
|
||||
Map<UUID, DescriptionReferenceDataEntity> descriptionReferenceDataEntityById = new HashMap<>();
|
||||
for (DescriptionReferenceEntity descriptionReferenceEntity : descriptionReferenceEntities){
|
||||
DescriptionReferenceDataEntity propertyDefinition = this.jsonHandlingService.fromJsonSafe(DescriptionReferenceDataEntity.class, descriptionReferenceEntity.getData());
|
||||
if (propertyDefinition != null) descriptionReferenceDataEntityById.put(descriptionReferenceEntity.getId(), propertyDefinition);
|
||||
}
|
||||
for (PropertyDefinitionFieldSetEntity fieldSetEntity : propertyDefinitionEntity.getFieldSets().values()){
|
||||
int newOrdinal = 0;
|
||||
PropertyDefinitionFieldSetItemEntity firstFieldSet = fieldSetEntity.getItems().stream().findFirst().filter(x-> x.getOrdinal() == SimpleFieldSetOrdinal).orElse(null);
|
||||
if (firstFieldSet != null){
|
||||
this.ensureDescriptionReferenceOrdinal(firstFieldSet, descriptionReferenceEntitiesMap, descriptionReferenceDataEntityById, newOrdinal);
|
||||
firstFieldSet.setOrdinal(newOrdinal);
|
||||
newOrdinal++;
|
||||
|
||||
}
|
||||
for (PropertyDefinitionFieldSetItemEntity propertyDefinitionFieldSetItemEntity : fieldSetEntity.getItems().stream().filter(x-> x.getOrdinal() >= 0 && x.getOrdinal() != SimpleFieldSetOrdinal).sorted(Comparator.comparingInt(PropertyDefinitionFieldSetItemEntity::getOrdinal)).toList()){
|
||||
this.ensureDescriptionReferenceOrdinal(propertyDefinitionFieldSetItemEntity, descriptionReferenceEntitiesMap, descriptionReferenceDataEntityById, newOrdinal);
|
||||
propertyDefinitionFieldSetItemEntity.setOrdinal(newOrdinal);
|
||||
newOrdinal++;
|
||||
}
|
||||
for (PropertyDefinitionFieldSetItemEntity propertyDefinitionFieldSetItemEntity : fieldSetEntity.getItems().stream().filter(x-> x.getOrdinal() < 0 && x.getOrdinal() != SimpleFieldSetOrdinal).sorted(Comparator.comparingInt(PropertyDefinitionFieldSetItemEntity::getOrdinal)).toList()){
|
||||
this.ensureDescriptionReferenceOrdinal(propertyDefinitionFieldSetItemEntity, descriptionReferenceEntitiesMap, descriptionReferenceDataEntityById, newOrdinal);
|
||||
propertyDefinitionFieldSetItemEntity.setOrdinal(newOrdinal);
|
||||
newOrdinal++;
|
||||
}
|
||||
|
@ -282,6 +293,19 @@ public class DatasetMigrationService {
|
|||
return propertyDefinitionEntity;
|
||||
}
|
||||
|
||||
private void ensureDescriptionReferenceOrdinal(PropertyDefinitionFieldSetItemEntity propertyDefinitionFieldSetItemEntity, Map<UUID, DescriptionReferenceEntity> descriptionReferenceEntitiesMap, Map<UUID, DescriptionReferenceDataEntity> descriptionReferenceDataEntityById, int newOrdinal){
|
||||
for (String key : propertyDefinitionFieldSetItemEntity.getFields().keySet()){
|
||||
for (Map.Entry<UUID, DescriptionReferenceDataEntity> entityMap : descriptionReferenceDataEntityById.entrySet()){
|
||||
if (entityMap.getValue().getOrdinal() == propertyDefinitionFieldSetItemEntity.getOrdinal() && entityMap.getValue().getFieldId().equals(key)){
|
||||
DescriptionReferenceEntity descriptionReferenceEntity = descriptionReferenceEntitiesMap.get(entityMap.getKey());
|
||||
descriptionReferenceEntity.setData(this.jsonHandlingService.toJsonSafe(this.buildDescriptionReferenceDataEntity(key, newOrdinal)));
|
||||
this.entityManager.merge(descriptionReferenceEntity);
|
||||
}
|
||||
}
|
||||
}
|
||||
this.entityManager.flush();
|
||||
}
|
||||
|
||||
private void addMultipleField(Dataset item, Map<String, Object> properties, org.opencdmp.commons.types.descriptiontemplate.DefinitionEntity descriptionTemplateDefinitionEntity, PropertyDefinitionEntity propertyDefinitionEntity, Map<UUID, ReferenceTypeDefinitionEntity> referenceTypeDefinitionEntityMap, Map<ReferenceKey, ReferenceEntity> referenceMap){
|
||||
Map<MultipleFieldKey, Integer> groupOrdinalMapping = new HashMap<>();
|
||||
for (String key : properties.keySet()) {
|
||||
|
@ -1054,13 +1078,13 @@ public class DatasetMigrationService {
|
|||
data.setCreatedAt(Instant.now());
|
||||
data.setUpdatedAt(Instant.now());
|
||||
data.setIsActive(IsActive.Active);
|
||||
data.setData(this.jsonHandlingService.toJsonSafe(this.buildDescriptionReferenceDataEntity(currentField, ordinal)));
|
||||
data.setData(this.jsonHandlingService.toJsonSafe(this.buildDescriptionReferenceDataEntity(currentField.getId(), ordinal)));
|
||||
this.entityManager.persist(data);
|
||||
}
|
||||
|
||||
private @NotNull DescriptionReferenceDataEntity buildDescriptionReferenceDataEntity(org.opencdmp.commons.types.descriptiontemplate.FieldEntity currentField, int ordinal){
|
||||
private @NotNull DescriptionReferenceDataEntity buildDescriptionReferenceDataEntity(String currentField, int ordinal){
|
||||
DescriptionReferenceDataEntity data = new DescriptionReferenceDataEntity();
|
||||
data.setFieldId(currentField.getId().trim());
|
||||
data.setFieldId(currentField.trim());
|
||||
data.setOrdinal(ordinal);
|
||||
return data;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue