build description persist model for validate endpoint
This commit is contained in:
parent
b49975931b
commit
ed3f3ebb27
|
@ -208,12 +208,12 @@ public class DescriptionPersist {
|
||||||
.iff(() -> !this.isNull(item.getProperties()))
|
.iff(() -> !this.isNull(item.getProperties()))
|
||||||
.on(DescriptionPersist._properties)
|
.on(DescriptionPersist._properties)
|
||||||
.over(item.getProperties())
|
.over(item.getProperties())
|
||||||
.using(() -> this.validatorFactory.validator(PropertyDefinitionPersist.PropertyDefinitionPersistValidator.class).setStatus(item.getStatus()).withDefinition(definition)),
|
.using(() -> this.validatorFactory.validator(PropertyDefinitionPersist.PropertyDefinitionPersistValidator.class).setStatus(item.getStatus()).withDefinition(definition))
|
||||||
this.navSpec()
|
// this.navSpec()
|
||||||
.iff(() -> !this.isNull(item.getTags()))
|
// .iff(() -> !this.isNull(item.getTags()))
|
||||||
.on(DescriptionPersist._tags)
|
// .on(DescriptionPersist._tags)
|
||||||
.over(item.getTags())
|
// .over(item.getTags())
|
||||||
.using((itm) -> this.validatorFactory.validator(TagPersist.TagPersistValidator.class))
|
// .using((itm) -> this.validatorFactory.validator(TagPersist.TagPersistValidator.class))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -103,9 +103,11 @@ public class PropertyDefinitionPersist {
|
||||||
boolean requiredAtLeastOneFieldSet = fieldSet.getMultiplicity() != null && fieldSet.getMultiplicity().getMin() > 0;
|
boolean requiredAtLeastOneFieldSet = fieldSet.getMultiplicity() != null && fieldSet.getMultiplicity().getMin() > 0;
|
||||||
if (requiredAtLeastOneFieldSet) {
|
if (requiredAtLeastOneFieldSet) {
|
||||||
if (item == null || item.getFieldSets() == null) missingMultipleFieldSets.add(fieldSet);
|
if (item == null || item.getFieldSets() == null) missingMultipleFieldSets.add(fieldSet);
|
||||||
|
if (item.getFieldSets() != null) {
|
||||||
PropertyDefinitionFieldSetPersist fieldSetPersist = item.getFieldSets().getOrDefault(fieldSet.getId(), null);
|
PropertyDefinitionFieldSetPersist fieldSetPersist = item.getFieldSets().getOrDefault(fieldSet.getId(), null);
|
||||||
if (fieldSetPersist == null) missingMultipleFieldSets.add(fieldSet);
|
if (fieldSetPersist == null) missingMultipleFieldSets.add(fieldSet);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return missingMultipleFieldSets;
|
return missingMultipleFieldSets;
|
||||||
|
|
|
@ -380,9 +380,8 @@ public class DescriptionServiceImpl implements DescriptionService {
|
||||||
for (DescriptionEntity description: descriptions) {
|
for (DescriptionEntity description: descriptions) {
|
||||||
DescriptionValidationResult descriptionValidationResult = new DescriptionValidationResult(description.getId(), DescriptionValidationOutput.Invalid);
|
DescriptionValidationResult descriptionValidationResult = new DescriptionValidationResult(description.getId(), DescriptionValidationOutput.Invalid);
|
||||||
|
|
||||||
// // TODO Persist
|
|
||||||
DescriptionPersist.DescriptionPersistValidator validator = this.validatorFactory.validator(DescriptionPersist.DescriptionPersistValidator.class);
|
DescriptionPersist.DescriptionPersistValidator validator = this.validatorFactory.validator(DescriptionPersist.DescriptionPersistValidator.class);
|
||||||
validator.validate(new DescriptionPersist());
|
validator.validate(this.buildDescriptionPersist(description));
|
||||||
if (validator.result().isValid()) descriptionValidationResult.setResult(DescriptionValidationOutput.Valid);;
|
if (validator.result().isValid()) descriptionValidationResult.setResult(DescriptionValidationOutput.Valid);;
|
||||||
descriptionValidationResults.add(descriptionValidationResult);
|
descriptionValidationResults.add(descriptionValidationResult);
|
||||||
|
|
||||||
|
@ -836,4 +835,91 @@ public class DescriptionServiceImpl implements DescriptionService {
|
||||||
|
|
||||||
return storageFile;
|
return storageFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//region build persist
|
||||||
|
|
||||||
|
private @NotNull DescriptionPersist buildDescriptionPersist(DescriptionEntity data){
|
||||||
|
DescriptionPersist persist = new DescriptionPersist();
|
||||||
|
if (data == null) return persist;
|
||||||
|
|
||||||
|
DescriptionTemplateEntity descriptionTemplateEntity = this.entityManager.find(DescriptionTemplateEntity.class, data.getDescriptionTemplateId());
|
||||||
|
if (descriptionTemplateEntity == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{data.getDescriptionTemplateId(), DescriptionTemplate.class.getSimpleName()}, LocaleContextHolder.getLocale()));
|
||||||
|
|
||||||
|
persist.setLabel(data.getLabel());
|
||||||
|
persist.setStatus(data.getStatus());
|
||||||
|
persist.setDescription(data.getDescription());
|
||||||
|
persist.setDescriptionTemplateId(data.getDescriptionTemplateId());
|
||||||
|
persist.setDmpId(data.getDmpId());
|
||||||
|
persist.setDmpDescriptionTemplateId(data.getDmpDescriptionTemplateId());
|
||||||
|
|
||||||
|
eu.eudat.commons.types.descriptiontemplate.DefinitionEntity definition = this.xmlHandlingService.fromXmlSafe(eu.eudat.commons.types.descriptiontemplate.DefinitionEntity.class, descriptionTemplateEntity.getDefinition());
|
||||||
|
|
||||||
|
persist.setProperties(this.buildPropertyDefinitionPersist( this.jsonHandlingService.fromJsonSafe(PropertyDefinitionEntity.class, data.getProperties()), definition));
|
||||||
|
|
||||||
|
return persist;
|
||||||
|
}
|
||||||
|
|
||||||
|
private @NotNull PropertyDefinitionPersist buildPropertyDefinitionPersist(PropertyDefinitionEntity data, eu.eudat.commons.types.descriptiontemplate.DefinitionEntity definition){
|
||||||
|
PropertyDefinitionPersist persist = new PropertyDefinitionPersist();
|
||||||
|
if (data == null) return persist;
|
||||||
|
if (data.getFieldSets() != null && !data.getFieldSets().isEmpty()){
|
||||||
|
persist.setFieldSets(new HashMap<>());
|
||||||
|
for (String key: data.getFieldSets().keySet()) {
|
||||||
|
FieldSetEntity fieldSetEntity = definition != null ? definition.getFieldSetById(key).stream().findFirst().orElse(null) : null;
|
||||||
|
persist.getFieldSets().put(key, this.buildPropertyDefinitionFieldSetPersist(data.getFieldSets().get(key), fieldSetEntity));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return persist;
|
||||||
|
}
|
||||||
|
|
||||||
|
private @NotNull PropertyDefinitionFieldSetPersist buildPropertyDefinitionFieldSetPersist(PropertyDefinitionFieldSetEntity data, FieldSetEntity fieldSetEntity){
|
||||||
|
PropertyDefinitionFieldSetPersist persist = new PropertyDefinitionFieldSetPersist();
|
||||||
|
if (data == null) return persist;
|
||||||
|
if (!this.conventionService.isListNullOrEmpty(data.getItems())){
|
||||||
|
persist.setItems(new ArrayList<>());
|
||||||
|
for (PropertyDefinitionFieldSetItemEntity itemsPersist: data.getItems()) {
|
||||||
|
persist.getItems().add(this.buildPropertyDefinitionFieldSetItemPersist(itemsPersist, fieldSetEntity));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return persist;
|
||||||
|
}
|
||||||
|
|
||||||
|
private @NotNull PropertyDefinitionFieldSetItemPersist buildPropertyDefinitionFieldSetItemPersist(PropertyDefinitionFieldSetItemEntity data, FieldSetEntity fieldSetEntity){
|
||||||
|
PropertyDefinitionFieldSetItemPersist persist = new PropertyDefinitionFieldSetItemPersist();
|
||||||
|
if (data == null) return persist;
|
||||||
|
if (data.getFields() != null && !data.getFields().isEmpty()){
|
||||||
|
persist.setOrdinal(data.getOrdinal());
|
||||||
|
persist.setComment(data.getComment());
|
||||||
|
persist.setFields(new HashMap<>());
|
||||||
|
for (String key: data.getFields().keySet()) {
|
||||||
|
eu.eudat.commons.types.descriptiontemplate.FieldEntity fieldEntity = fieldSetEntity != null ? fieldSetEntity.getAllField().stream().findFirst().orElse(null) : null;
|
||||||
|
persist.getFields().put(key, this.buildFieldPersist(data.getFields().get(key), fieldEntity));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return persist;
|
||||||
|
}
|
||||||
|
|
||||||
|
private @NotNull FieldPersist buildFieldPersist(FieldEntity data, eu.eudat.commons.types.descriptiontemplate.FieldEntity fieldEntity) {
|
||||||
|
FieldType fieldType = fieldEntity != null && fieldEntity.getData() != null ? fieldEntity.getData().getFieldType() : FieldType.FREE_TEXT;
|
||||||
|
|
||||||
|
FieldPersist persist = new FieldPersist();
|
||||||
|
if (data == null) return persist;
|
||||||
|
|
||||||
|
if (FieldType.isTextType(fieldType)) persist.setTextValue(data.getTextValue());
|
||||||
|
else if (FieldType.isTextListType(fieldType)) persist.setTextListValue(data.getTextListValue());
|
||||||
|
else if (FieldType.isDateType(fieldType)) persist.setDateValue(persist.getDateValue());
|
||||||
|
else if (FieldType.isExternalIdentifierType(fieldType) && data.getExternalIdentifier() != null) persist.setExternalIdentifier(this.buildExternalIdentifierPersist(data.getExternalIdentifier()));
|
||||||
|
else if (FieldType.isReferenceType(fieldType) && fieldEntity != null ) persist.setTextListValue(data.getTextListValue());
|
||||||
|
|
||||||
|
return persist;
|
||||||
|
}
|
||||||
|
|
||||||
|
private @NotNull ExternalIdentifierPersist buildExternalIdentifierPersist(ExternalIdentifierEntity data){
|
||||||
|
ExternalIdentifierPersist persist = new ExternalIdentifierPersist();
|
||||||
|
if (data == null) return persist;
|
||||||
|
|
||||||
|
persist.setIdentifier(data.getIdentifier());
|
||||||
|
persist.setType(data.getType());
|
||||||
|
return persist;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -836,6 +836,9 @@ public class DmpServiceImpl implements DmpService {
|
||||||
if (description.getStatus().equals(DescriptionStatus.Finalized)){
|
if (description.getStatus().equals(DescriptionStatus.Finalized)){
|
||||||
throw new MyApplicationException("Description is already finalized");
|
throw new MyApplicationException("Description is already finalized");
|
||||||
}
|
}
|
||||||
|
if (this.descriptionService.validate(List.of(description.getId())).get(0).getResult().equals(DescriptionValidationOutput.Invalid)){
|
||||||
|
throw new MyApplicationException("Description is invalid");
|
||||||
|
}
|
||||||
description.setStatus(DescriptionStatus.Finalized);
|
description.setStatus(DescriptionStatus.Finalized);
|
||||||
description.setUpdatedAt(Instant.now());
|
description.setUpdatedAt(Instant.now());
|
||||||
description.setFinalizedAt(Instant.now());
|
description.setFinalizedAt(Instant.now());
|
||||||
|
|
|
@ -36,7 +36,7 @@
|
||||||
</ng-container>
|
</ng-container>
|
||||||
:</span>
|
:</span>
|
||||||
{{ description.label }}
|
{{ description.label }}
|
||||||
<i *ngIf="isDescriptionValid(description.id)" class="fa fa-spinner fa-spin" ></i>
|
<i *ngIf="!isDescriptionValid(description.id)" class="fa fa-spinner fa-spin" ></i>
|
||||||
</h4>
|
</h4>
|
||||||
<h4 *ngIf="description.status == descriptionStatusEnum.Finalized" class="col-11 ml-auto mt-1 mb-4">{{ description.label }}</h4>
|
<h4 *ngIf="description.status == descriptionStatusEnum.Finalized" class="col-11 ml-auto mt-1 mb-4">{{ description.label }}</h4>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue