add visibility to models

This commit is contained in:
Efstratios Giannopoulos 2024-03-21 10:16:55 +02:00
parent ba33b29e41
commit 709fecf1f1
4 changed files with 16 additions and 4 deletions

View File

@ -50,7 +50,7 @@
<dependency> <dependency>
<groupId>gr.cite.opendmp</groupId> <groupId>gr.cite.opendmp</groupId>
<artifactId>common-models</artifactId> <artifactId>common-models</artifactId>
<version>0.0.4</version> <version>0.0.5</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>gr.cite.opendmp</groupId> <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.dmp.DmpCommonModelBuilder;
import eu.eudat.model.builder.commonmodels.descriptiontemplate.DescriptionTemplateCommonModelBuilder; import eu.eudat.model.builder.commonmodels.descriptiontemplate.DescriptionTemplateCommonModelBuilder;
import eu.eudat.query.*; import eu.eudat.query.*;
import eu.eudat.service.visibility.VisibilityService;
import eu.eudat.service.visibility.VisibilityServiceImpl; import eu.eudat.service.visibility.VisibilityServiceImpl;
import gr.cite.tools.data.builder.BuilderFactory; import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.data.query.QueryFactory; 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 (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 (descriptionTemplates != null && d.getDescriptionTemplateId() != null && descriptionTemplates.containsKey(d.getDescriptionTemplateId())) m.setDescriptionTemplate(descriptionTemplates.get(d.getDescriptionTemplateId()));
if (d.getProperties() != null){ if (d.getProperties() != null){
//TODO Update with the new logic of property definition
PropertyDefinitionEntity propertyDefinition = this.jsonHandlingService.fromJsonSafe(PropertyDefinitionEntity.class, d.getProperties()); 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)); DefinitionEntity definition = definitionEntityMap != null ? definitionEntityMap.getOrDefault(d.getDescriptionTemplateId(), null) : null;
//VisibilityServiceImpl visibilityService = new VisibilityServiceImpl(propertyDefinition); 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)); models.add(new CommonModelBuilderItemResponse<>(m, d));
} }

View File

@ -1,5 +1,9 @@
package eu.eudat.service.visibility; package eu.eudat.service.visibility;
import java.util.Map;
public interface VisibilityService { public interface VisibilityService {
boolean isVisible(String id, Integer ordinal); 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); return this.visibility.getOrDefault(fieldKey, false);
} }
@Override
public Map<FieldKey, Boolean> getVisibilityStates() {
this.calculateVisibility();
return visibility;
}
private void calculateVisibility(){ private void calculateVisibility(){
if (visibility != null) return; if (visibility != null) return;