Merge branch 'dmp-refactoring' of https://code-repo.d4science.org/MaDgiK-CITE/argos into dmp-refactoring

This commit is contained in:
Diamantis Tziotzios 2024-03-21 10:33:12 +02:00
commit 0dffbec480
5 changed files with 72 additions and 4 deletions

View File

@ -50,7 +50,7 @@
<dependency>
<groupId>gr.cite.opendmp</groupId>
<artifactId>common-models</artifactId>
<version>0.0.4</version>
<version>0.0.5</version>
</dependency>
<dependency>
<groupId>gr.cite.opendmp</groupId>

View File

@ -21,6 +21,7 @@ import eu.eudat.model.builder.commonmodels.CommonModelBuilderItemResponse;
import eu.eudat.model.builder.commonmodels.dmp.DmpCommonModelBuilder;
import eu.eudat.model.builder.commonmodels.descriptiontemplate.DescriptionTemplateCommonModelBuilder;
import eu.eudat.query.*;
import eu.eudat.service.visibility.VisibilityService;
import eu.eudat.service.visibility.VisibilityServiceImpl;
import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.data.query.QueryFactory;
@ -101,10 +102,11 @@ public class DescriptionCommonModelBuilder extends BaseCommonModelBuilder<Descri
if (dmpDescriptionTemplateSections != null && d.getDmpDescriptionTemplateId() != null && dmpDescriptionTemplateSections.containsKey(d.getDmpDescriptionTemplateId())) m.setSectionId(dmpDescriptionTemplateSections.get(d.getDmpDescriptionTemplateId()));
if (descriptionTemplates != null && d.getDescriptionTemplateId() != null && descriptionTemplates.containsKey(d.getDescriptionTemplateId())) m.setDescriptionTemplate(descriptionTemplates.get(d.getDescriptionTemplateId()));
if (d.getProperties() != null){
//TODO Update with the new logic of property definition
PropertyDefinitionEntity propertyDefinition = this.jsonHandlingService.fromJsonSafe(PropertyDefinitionEntity.class, d.getProperties());
m.setProperties(this.builderFactory.builder(PropertyDefinitionCommonModelBuilder.class).useSharedStorage(useSharedStorage).withDefinition(definitionEntityMap != null ? definitionEntityMap.getOrDefault(d.getDescriptionTemplateId(), null) : null).authorize(this.authorize).build(propertyDefinition));
//VisibilityServiceImpl visibilityService = new VisibilityServiceImpl(propertyDefinition);
DefinitionEntity definition = definitionEntityMap != null ? definitionEntityMap.getOrDefault(d.getDescriptionTemplateId(), null) : null;
m.setProperties(this.builderFactory.builder(PropertyDefinitionCommonModelBuilder.class).useSharedStorage(useSharedStorage).withDefinition(definition).authorize(this.authorize).build(propertyDefinition));
VisibilityService visibilityService = new VisibilityServiceImpl(definition, propertyDefinition);
m.setVisibilityStates(this.builderFactory.builder(VisibilityStateModelBuilder.class).authorize(this.authorize).build(visibilityService.getVisibilityStates().entrySet().stream().toList()));
}
models.add(new CommonModelBuilderItemResponse<>(m, d));
}

View File

@ -0,0 +1,56 @@
package eu.eudat.model.builder.commonmodels.description;
import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.commonmodels.models.description.VisibilityStateModel;
import eu.eudat.convention.ConventionService;
import eu.eudat.model.builder.commonmodels.BaseCommonModelBuilder;
import eu.eudat.model.builder.commonmodels.CommonModelBuilderItemResponse;
import eu.eudat.service.visibility.FieldKey;
import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.logging.LoggerService;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.util.*;
@Component("commonmodels.VisibilityStateModelBuilder")
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class VisibilityStateModelBuilder extends BaseCommonModelBuilder<VisibilityStateModel, Map.Entry<FieldKey, Boolean>> {
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
@Autowired
public VisibilityStateModelBuilder(
ConventionService conventionService
) {
super(conventionService, new LoggerService(LoggerFactory.getLogger(VisibilityStateModelBuilder.class)));
}
public VisibilityStateModelBuilder authorize(EnumSet<AuthorizationFlags> values) {
this.authorize = values;
return this;
}
@Override
protected List<CommonModelBuilderItemResponse<VisibilityStateModel, Map.Entry<FieldKey, Boolean>>> buildInternal(List<Map.Entry<FieldKey, Boolean>> data) throws MyApplicationException {
this.logger.debug("building for {}", Optional.ofNullable(data).map(List::size).orElse(0));
if (data == null || data.isEmpty()) return new ArrayList<>();
List<CommonModelBuilderItemResponse<VisibilityStateModel, Map.Entry<FieldKey, Boolean>>> models = new ArrayList<>();
for (Map.Entry<FieldKey, Boolean> d : data) {
VisibilityStateModel m = new VisibilityStateModel();
if (d.getKey() != null) {
m.setFieldId(d.getKey().getFieldId());
m.setOrdinal(d.getKey().getOrdinal());
}
m.setVisible(d.getValue());
models.add(new CommonModelBuilderItemResponse<>(m, d));
}
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
return models;
}
}

View File

@ -1,5 +1,9 @@
package eu.eudat.service.visibility;
import java.util.Map;
public interface VisibilityService {
boolean isVisible(String id, Integer ordinal);
Map<FieldKey, Boolean> getVisibilityStates();
}

View File

@ -46,6 +46,12 @@ public class VisibilityServiceImpl implements VisibilityService {
return this.visibility.getOrDefault(fieldKey, false);
}
@Override
public Map<FieldKey, Boolean> getVisibilityStates() {
this.calculateVisibility();
return visibility;
}
private void calculateVisibility(){
if (visibility != null) return;