Compare commits

..

No commits in common. "5b44fa183aba110ccc0de7cfe0e623de6fd69f11" and "2d0fa5362d18321335ff1c2eae20a0c9e98287a8" have entirely different histories.

4 changed files with 47 additions and 54 deletions

View File

@ -1,12 +1,12 @@
package org.opencdmp.model.persist;
import gr.cite.tools.validation.ValidatorFactory;
import gr.cite.tools.validation.specification.Specification;
import org.opencdmp.commons.validation.BaseValidator;
import org.opencdmp.convention.ConventionService;
import org.opencdmp.errorcode.ErrorThesaurusProperties;
import org.opencdmp.model.persist.descriptionreference.DescriptionReferenceDataPersist;
import org.opencdmp.model.persist.dmpreference.DmpReferenceDataPersist;
import gr.cite.tools.validation.ValidatorFactory;
import gr.cite.tools.validation.specification.Specification;
import org.opencdmp.convention.ConventionService;
import org.opencdmp.errorcode.ErrorThesaurusProperties;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Scope;
@ -15,11 +15,12 @@ import org.springframework.stereotype.Component;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
public class DescriptionReferencePersist {
private ReferencePersist reference;
private ReferencePersist reference = null;
public static final String _reference = "reference";
@ -29,7 +30,7 @@ public class DescriptionReferencePersist {
public static final String _data = "data";
public ReferencePersist getReference() {
return this.reference;
return reference;
}
public void setReference(ReferencePersist reference) {
@ -37,7 +38,7 @@ public class DescriptionReferencePersist {
}
public DescriptionReferenceDataPersist getData() {
return this.data;
return data;
}
public void setData(DescriptionReferenceDataPersist data) {
@ -70,7 +71,7 @@ public class DescriptionReferencePersist {
return Arrays.asList(
this.spec()
.must(() -> !this.isNull(item.getReference()))
.failOn(DescriptionReferencePersist._reference).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{DescriptionReferencePersist._reference}, LocaleContextHolder.getLocale())),
.failOn(DescriptionReferencePersist._reference).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionReferencePersist._reference}, LocaleContextHolder.getLocale())),
this.refSpec()
.iff(() -> !this.isNull(item.getReference()))
.on(DescriptionReferencePersist._reference)
@ -78,7 +79,7 @@ public class DescriptionReferencePersist {
.using(() -> this.validatorFactory.validator(ReferencePersist.ReferencePersistValidator.class)),
this.spec()
.must(() -> !this.isNull(item.getData()))
.failOn(DescriptionReferencePersist._data).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{DescriptionReferencePersist._data}, LocaleContextHolder.getLocale())),
.failOn(DescriptionReferencePersist._data).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionReferencePersist._data}, LocaleContextHolder.getLocale())),
this.refSpec()
.iff(() -> !this.isNull(item.getData()))
.on(DescriptionReferencePersist._data)

View File

@ -1,7 +1,5 @@
package org.opencdmp.model.persist.descriptionproperties;
import gr.cite.tools.validation.ValidatorFactory;
import gr.cite.tools.validation.specification.Specification;
import org.opencdmp.commons.enums.DescriptionStatus;
import org.opencdmp.commons.enums.FieldValidationType;
import org.opencdmp.commons.types.descriptiontemplate.DefinitionEntity;
@ -13,16 +11,15 @@ import org.opencdmp.errorcode.ErrorThesaurusProperties;
import org.opencdmp.model.persist.validation.StatusAware;
import org.opencdmp.service.visibility.VisibilityService;
import org.opencdmp.service.visibility.VisibilityServiceImpl;
import gr.cite.tools.validation.ValidatorFactory;
import gr.cite.tools.validation.specification.Specification;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Scope;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
public class PropertyDefinitionPersist {
@ -32,7 +29,7 @@ public class PropertyDefinitionPersist {
private Map<String, PropertyDefinitionFieldSetPersist> fieldSets;
public Map<String, PropertyDefinitionFieldSetPersist> getFieldSets() {
return this.fieldSets;
return fieldSets;
}
public void setFieldSets(Map<String, PropertyDefinitionFieldSetPersist> fieldSets) {
@ -70,21 +67,21 @@ public class PropertyDefinitionPersist {
this.spec()
.iff(() -> this.status == DescriptionStatus.Finalized)
.must(() -> !this.isNull(item.getFieldSets()) && !item.getFieldSets().isEmpty())
.failOn(PropertyDefinitionPersist._fieldSets).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{PropertyDefinitionPersist._fieldSets}, LocaleContextHolder.getLocale())),
.failOn(PropertyDefinitionPersist._fieldSets).failWith(messageSource.getMessage("Validation_Required", new Object[]{PropertyDefinitionPersist._fieldSets}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> this.isListNullOrEmpty(this.getMissingFieldSetEntity(item)))
.failOn(PropertyDefinitionPersist._fieldSets).failWith(this.messageSource.getMessage("Validation.MissingFields", new Object[]{this.serializeMissingFieldSets(this.getMissingFieldSetEntity(item))}, LocaleContextHolder.getLocale())),
.failOn(PropertyDefinitionPersist._fieldSets).failWith(messageSource.getMessage("Validation.MissingFields", new Object[]{this.serializeMissingFieldSets(this.getMissingFieldSetEntity(item))}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> this.isListNullOrEmpty(this.getMissingFieldsEntity(item)))
.failOn(PropertyDefinitionPersist._fieldSets).failWith(this.messageSource.getMessage("Validation.MissingFields", new Object[]{this.serializeMissingFields(this.getMissingFieldsEntity(item))}, LocaleContextHolder.getLocale())),
.failOn(PropertyDefinitionPersist._fieldSets).failWith(messageSource.getMessage("Validation.MissingFields", new Object[]{this.serializeMissingFields(this.getMissingFieldsEntity(item))}, LocaleContextHolder.getLocale())),
this.mapSpec()
.iff(() -> !this.isNull(item.getFieldSets()))
.on(PropertyDefinitionPersist._fieldSets)
.over(item.getFieldSets())
.mapKey((k) -> ((String)k))
.using((itm) -> {
FieldSetEntity fieldSetEntity = this.definition != null ? this.definition.getFieldSetById((String)itm.getKey()).stream().findFirst().orElse(null) : null;
return this.validatorFactory.validator(PropertyDefinitionFieldSetPersist.PersistValidator.class).withFieldSetEntity(fieldSetEntity).withVisibilityService(this.visibilityService).setStatus(this.status);
FieldSetEntity fieldSetEntity = definition != null ? definition.getFieldSetById((String)itm.getKey()).stream().findFirst().orElse(null) : null;
return this.validatorFactory.validator(PropertyDefinitionFieldSetPersist.PersistValidator.class).withFieldSetEntity(fieldSetEntity).withVisibilityService(visibilityService).setStatus(this.status);
})
);
}
@ -108,8 +105,8 @@ public class PropertyDefinitionPersist {
private List<FieldSetEntity> getMissingFieldSetEntity(PropertyDefinitionPersist item){
List<FieldSetEntity> missingMultipleFieldSets = new ArrayList<>();
if (this.definition == null || this.definition.getAllFieldSets() == null) return missingMultipleFieldSets;
for (FieldSetEntity fieldSet: this.definition.getAllFieldSets()) {
if (definition == null || definition.getAllFieldSets() == null) return missingMultipleFieldSets;
for (FieldSetEntity fieldSet: definition.getAllFieldSets()) {
boolean requiredAtLeastOneFieldSet = fieldSet.getMultiplicity() != null && fieldSet.getHasMultiplicity() && fieldSet.getMultiplicity().getMin() > 0;
if (requiredAtLeastOneFieldSet) {
@ -127,8 +124,8 @@ public class PropertyDefinitionPersist {
private List<FieldEntity> getMissingFieldsEntity(PropertyDefinitionPersist item){
List<FieldEntity> missingFields = new ArrayList<>();
if (this.definition == null || this.definition.getAllFieldSets() == null) return missingFields;
for (FieldSetEntity fieldSet: this.definition.getAllFieldSets()) {
if (definition == null || definition.getAllFieldSets() == null) return missingFields;
for (FieldSetEntity fieldSet: definition.getAllFieldSets()) {
if (fieldSet.getFields() == null) continue;
@ -166,12 +163,12 @@ public class PropertyDefinitionPersist {
private String serializeMissingFieldSets (List<FieldSetEntity> missingFieldSets){
if (missingFieldSets == null) return "";
return missingFieldSets.stream().map(FieldSetEntity::getId).collect(Collectors.joining(", "));
return missingFieldSets.stream().map(x -> x.getId()).collect(Collectors.joining(", "));
}
private String serializeMissingFields (List<FieldEntity> missingFields){
if (missingFields == null) return "";
return missingFields.stream().map(FieldEntity::getId).collect(Collectors.joining(", "));
return missingFields.stream().map(x -> x.getId()).collect(Collectors.joining(", "));
}
}

View File

@ -1,9 +1,9 @@
package org.opencdmp.model.persist.descriptionreference;
import gr.cite.tools.validation.specification.Specification;
import org.opencdmp.commons.validation.BaseValidator;
import org.opencdmp.convention.ConventionService;
import org.opencdmp.errorcode.ErrorThesaurusProperties;
import gr.cite.tools.validation.specification.Specification;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Scope;
@ -12,6 +12,7 @@ import org.springframework.stereotype.Component;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
public class DescriptionReferenceDataPersist {
@ -20,7 +21,7 @@ public class DescriptionReferenceDataPersist {
public static final String _fieldId = "fieldId";
public String getFieldId() {
return this.fieldId;
return fieldId;
}
public void setFieldId(String fieldId) {
@ -49,7 +50,7 @@ public class DescriptionReferenceDataPersist {
return Arrays.asList(
this.spec()
.must(() -> !this.isNull(item.getFieldId()))
.failOn(DescriptionReferenceDataPersist._fieldId).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{DescriptionReferenceDataPersist._fieldId}, LocaleContextHolder.getLocale()))
.failOn(DescriptionReferenceDataPersist._fieldId).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionReferenceDataPersist._fieldId}, LocaleContextHolder.getLocale()))
);
}
}

View File

@ -66,8 +66,6 @@ import org.opencdmp.service.filetransformer.FileTransformerService;
import org.opencdmp.service.responseutils.ResponseUtilsService;
import org.opencdmp.service.storage.StorageFileProperties;
import org.opencdmp.service.storage.StorageFileService;
import org.opencdmp.service.visibility.VisibilityService;
import org.opencdmp.service.visibility.VisibilityServiceImpl;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
@ -239,12 +237,11 @@ public class DescriptionServiceImpl implements DescriptionService {
this.entityManager.flush();
org.opencdmp.commons.types.descriptiontemplate.DefinitionEntity definition = this.xmlHandlingService.fromXmlSafe(org.opencdmp.commons.types.descriptiontemplate.DefinitionEntity.class, descriptionTemplateEntity.getDefinition());
VisibilityService visibilityService = new VisibilityServiceImpl(definition, model.getProperties());
Map<String, List<UUID>> fieldToReferenceMap = this.patchAndSaveReferences(this.buildDescriptionReferencePersists(visibilityService, model.getProperties()), data.getId(), definition);
Map<String, List<UUID>> fieldToReferenceMap = this.patchAndSaveReferences(this.buildDescriptionReferencePersists(model.getProperties()), data.getId(), definition);
this.entityManager.flush();
data.setProperties(this.jsonHandlingService.toJson(this.buildPropertyDefinitionEntity(visibilityService, model.getProperties(), definition, fieldToReferenceMap)));
data.setProperties(this.jsonHandlingService.toJson(this.buildPropertyDefinitionEntity(model.getProperties(), definition, fieldToReferenceMap)));
this.entityManager.merge(data);
@ -265,7 +262,7 @@ public class DescriptionServiceImpl implements DescriptionService {
return this.builderFactory.builder(DescriptionBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(BaseFieldSet.build(fields, Description._id), data);
}
@Override
public void updateDescriptionTemplate(UpdateDescriptionTemplatePersist model) throws InvalidApplicationException, IOException {
public void updateDescriptionTemplate(UpdateDescriptionTemplatePersist model) throws InvalidApplicationException, IOException, JAXBException {
logger.debug(new MapLogEntry("update description template").And("model", model));
this.authorizationService.authorizeAtLeastOneForce(List.of(this.authorizationContentResolver.descriptionAffiliation(model.getId())), Permission.EditDescription);
@ -402,7 +399,7 @@ public class DescriptionServiceImpl implements DescriptionService {
this.eventHandler.handle(event);
}
private void applyNotificationType(DescriptionStatus status, NotifyIntegrationEvent event) {
private NotifyIntegrationEvent applyNotificationType(DescriptionStatus status, NotifyIntegrationEvent event) {
switch (status) {
case Draft:
event.setNotificationType(this.notificationProperties.getDescriptionModifiedType());
@ -413,7 +410,7 @@ public class DescriptionServiceImpl implements DescriptionService {
default:
throw new MyApplicationException("Unsupported Description Status.");
}
return;
return event;
}
@Override
@ -463,39 +460,38 @@ public class DescriptionServiceImpl implements DescriptionService {
DescriptionPersist.DescriptionPersistValidator validator = this.validatorFactory.validator(DescriptionPersist.DescriptionPersistValidator.class);
validator.validate(this.buildDescriptionPersist(description));
if (validator.result().isValid()) descriptionValidationResult.setResult(DescriptionValidationOutput.Valid);
descriptionValidationResults.add(descriptionValidationResult);
descriptionValidationResults.add(descriptionValidationResult);
}
return descriptionValidationResults;
}
private @NotNull PropertyDefinitionEntity buildPropertyDefinitionEntity(VisibilityService visibilityService, PropertyDefinitionPersist persist, org.opencdmp.commons.types.descriptiontemplate.DefinitionEntity definition, Map<String, List<UUID>> fieldToReferenceMap) throws InvalidApplicationException {
private @NotNull PropertyDefinitionEntity buildPropertyDefinitionEntity(PropertyDefinitionPersist persist, org.opencdmp.commons.types.descriptiontemplate.DefinitionEntity definition, Map<String, List<UUID>> fieldToReferenceMap) throws InvalidApplicationException {
PropertyDefinitionEntity data = new PropertyDefinitionEntity();
if (persist == null) return data;
if (persist.getFieldSets() != null && !persist.getFieldSets().isEmpty()){
data.setFieldSets(new HashMap<>());
for (String key: persist.getFieldSets().keySet()) {
FieldSetEntity fieldSetEntity = definition != null ? definition.getFieldSetById(key).stream().findFirst().orElse(null) : null;
data.getFieldSets().put(key, this.buildPropertyDefinitionFieldSetEntity(persist.getFieldSets().get(key), fieldSetEntity, fieldToReferenceMap, visibilityService));
data.getFieldSets().put(key, this.buildPropertyDefinitionFieldSetEntity(persist.getFieldSets().get(key), fieldSetEntity, fieldToReferenceMap));
}
}
return data;
}
private @NotNull PropertyDefinitionFieldSetEntity buildPropertyDefinitionFieldSetEntity(PropertyDefinitionFieldSetPersist persist, FieldSetEntity fieldSetEntity, Map<String, List<UUID>> fieldToReferenceMap, VisibilityService visibilityService) throws InvalidApplicationException {
private @NotNull PropertyDefinitionFieldSetEntity buildPropertyDefinitionFieldSetEntity(PropertyDefinitionFieldSetPersist persist, FieldSetEntity fieldSetEntity, Map<String, List<UUID>> fieldToReferenceMap) throws InvalidApplicationException {
PropertyDefinitionFieldSetEntity data = new PropertyDefinitionFieldSetEntity();
if (persist == null) return data;
if (!this.conventionService.isListNullOrEmpty(persist.getItems())){
data.setItems(new ArrayList<>());
for (PropertyDefinitionFieldSetItemPersist itemsPersist: persist.getItems()) {
data.getItems().add(this.buildPropertyDefinitionFieldSetItemEntity(itemsPersist, fieldSetEntity, fieldToReferenceMap, visibilityService));
data.getItems().add(this.buildPropertyDefinitionFieldSetItemEntity(itemsPersist, fieldSetEntity, fieldToReferenceMap));
}
}
return data;
}
private @NotNull PropertyDefinitionFieldSetItemEntity buildPropertyDefinitionFieldSetItemEntity(PropertyDefinitionFieldSetItemPersist persist, FieldSetEntity fieldSetEntity, Map<String, List<UUID>> fieldToReferenceMap, VisibilityService visibilityService) throws InvalidApplicationException {
private @NotNull PropertyDefinitionFieldSetItemEntity buildPropertyDefinitionFieldSetItemEntity(PropertyDefinitionFieldSetItemPersist persist, FieldSetEntity fieldSetEntity, Map<String, List<UUID>> fieldToReferenceMap) throws InvalidApplicationException {
PropertyDefinitionFieldSetItemEntity data = new PropertyDefinitionFieldSetItemEntity();
if (persist == null) return data;
if (persist.getFields() != null && !persist.getFields().isEmpty()){
@ -504,17 +500,16 @@ public class DescriptionServiceImpl implements DescriptionService {
data.setFields(new HashMap<>());
for (String key: persist.getFields().keySet()) {
org.opencdmp.commons.types.descriptiontemplate.FieldEntity fieldEntity = fieldSetEntity != null ? fieldSetEntity.getFieldById(key).stream().findFirst().orElse(null) : null;
boolean isVisible = fieldEntity != null ? visibilityService.isVisible(fieldEntity.getId(), persist.getOrdinal()) : false;
data.getFields().put(key, this.buildFieldEntity(persist.getFields().get(key), fieldEntity, fieldToReferenceMap, isVisible));
data.getFields().put(key, this.buildFieldEntity(persist.getFields().get(key), fieldEntity, fieldToReferenceMap));
}
}
return data;
}
private @NotNull FieldEntity buildFieldEntity(FieldPersist persist, org.opencdmp.commons.types.descriptiontemplate.FieldEntity fieldEntity, Map<String, List<UUID>> fieldToReferenceMap, boolean isVisible) throws InvalidApplicationException {
private @NotNull FieldEntity buildFieldEntity(FieldPersist persist, org.opencdmp.commons.types.descriptiontemplate.FieldEntity fieldEntity, Map<String, List<UUID>> fieldToReferenceMap) throws InvalidApplicationException {
FieldType fieldType = fieldEntity != null && fieldEntity.getData() != null ? fieldEntity.getData().getFieldType() : FieldType.FREE_TEXT;
FieldEntity data = new FieldEntity();
if (persist == null || !isVisible) return data;
if (persist == null) return data;
if (FieldType.isTextType(fieldType)) {
if (FieldType.UPLOAD.equals(fieldType)){
@ -542,7 +537,7 @@ public class DescriptionServiceImpl implements DescriptionService {
else if (FieldType.isTextListType(fieldType)) {
List<UUID> ids = new ArrayList<>();
if (FieldType.INTERNAL_ENTRIES_DMPS.equals(fieldType)) {
if (!this.conventionService.isListNullOrEmpty(persist.getTextListValue())) ids = persist.getTextListValue().stream().map(UUID::fromString).toList();
if (!this.conventionService.isListNullOrEmpty(persist.getTextListValue())) persist.getTextListValue().stream().map(UUID::fromString).toList();
else if (!this.conventionService.isNullOrEmpty(persist.getTextValue())) ids.add(UUID.fromString(persist.getTextValue()));
if (!ids.isEmpty()){
@ -595,7 +590,7 @@ public class DescriptionServiceImpl implements DescriptionService {
return data;
}
private @NotNull List<DescriptionReferencePersist> buildDescriptionReferencePersists(VisibilityService visibilityService, PropertyDefinitionPersist persist){
private @NotNull List<DescriptionReferencePersist> buildDescriptionReferencePersists(PropertyDefinitionPersist persist){
List<DescriptionReferencePersist> descriptionReferencePersists = new ArrayList<>();
if (persist.getFieldSets() != null && !persist.getFieldSets().isEmpty()){
for (PropertyDefinitionFieldSetPersist propertyDefinitionFieldSetPersist: persist.getFieldSets().values()) {
@ -604,8 +599,7 @@ public class DescriptionServiceImpl implements DescriptionService {
if (definitionFieldSetItemPersist.getFields() != null && !definitionFieldSetItemPersist.getFields().isEmpty()) {
for (String key : definitionFieldSetItemPersist.getFields().keySet()) {
FieldPersist fieldPersist = definitionFieldSetItemPersist.getFields().get(key);
boolean isVisible = visibilityService.isVisible(key, definitionFieldSetItemPersist.getOrdinal());
if (isVisible) this.BuildDescriptionReferencePersist(key, fieldPersist, descriptionReferencePersists);
this.BuildDescriptionReferencePersist(key, fieldPersist, descriptionReferencePersists);
}
}
}
@ -655,7 +649,7 @@ public class DescriptionServiceImpl implements DescriptionService {
List<UUID> updatedCreatedIds = new ArrayList<>();
for (DescriptionReferencePersist model : models) {
ReferencePersist referencePersist = model.getReference();
ReferenceEntity referenceEntity;
ReferenceEntity referenceEntity = null;
if (this.conventionService.isValidGuid(referencePersist.getId())){
referenceEntity = this.entityManager.find(ReferenceEntity.class, referencePersist.getId());
if (referenceEntity == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{referencePersist.getId(), Reference.class.getSimpleName()}, LocaleContextHolder.getLocale()));