Search in sources :

Example 1 with FormableFilter

use of eu.bcvsolutions.idm.core.api.dto.filter.FormableFilter in project CzechIdMng by bcvsolutions.

the class AbstractFormableService method applyContext.

/**
 * Apply context on given dto.
 *
 * If has filter sets field "Add EAV metadata" to True, then we will load the
 * form instance for every result.
 *
 * @param dto
 * @param context
 * @param permission
 *
 * @return
 * @since 10.2.0
 */
@Override
protected DTO applyContext(DTO dto, F context, BasePermission... permission) {
    dto = super.applyContext(dto, context, permission);
    if (dto == null) {
        return null;
    }
    // 
    if (!(context instanceof FormableFilter)) {
        return dto;
    }
    FormableFilter formableContext = (FormableFilter) context;
    if (formableContext.isAddBasicFields()) {
        IdmFormDefinitionDto basicFields = formProjectionManager.getBasicFieldsDefinition(dto);
        if (basicFields != null) {
            dto.setEavs(Lists.newArrayList(new IdmFormInstanceDto(dto, basicFields, new ArrayList<>())));
        } else {
            dto.setEavs(Lists.newArrayList());
        }
    } else {
        dto.setEavs(Lists.newArrayList());
    }
    // load other for definitions and values
    if (BooleanUtils.isNotTrue(formableContext.getAddEavMetadata()) && CollectionUtils.isEmpty(formableContext.getFormDefinitionAttributes())) {
        return dto;
    }
    // load or find other form instances
    List<IdmFormInstanceDto> formInstances;
    if (CollectionUtils.isEmpty(formableContext.getFormDefinitionAttributes())) {
        // backward compatible -> method is overriden e.g. for role attributes
        formInstances = this.getFormInstances(dto, permission);
    } else {
        formInstances = this.findFormInstances(dto, formableContext, permission);
    }
    if (CollectionUtils.isNotEmpty(formInstances)) {
        dto.getEavs().addAll(formInstances);
    }
    // 
    return dto;
}
Also used : IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) FormableFilter(eu.bcvsolutions.idm.core.api.dto.filter.FormableFilter)

Example 2 with FormableFilter

use of eu.bcvsolutions.idm.core.api.dto.filter.FormableFilter in project CzechIdMng by bcvsolutions.

the class DefaultFormService method findFormInstances.

@Override
@Transactional(readOnly = true)
public List<IdmFormInstanceDto> findFormInstances(Identifiable owner, FormableFilter filter, BasePermission... permission) {
    Assert.notNull(owner, "Form values owner is required.");
    // 
    // filter form definitions and form attributes, if given
    List<IdmFormDefinitionDto> formDefinitions;
    if (filter == null || CollectionUtils.isEmpty(filter.getFormDefinitionAttributes())) {
        // filter is not set => all form definitions
        formDefinitions = getDefinitions(owner, !PermissionUtils.isEmpty(permission) ? IdmBasePermission.AUTOCOMPLETE : null);
    } else {
        // used filter definitions only.
        IdmFormDefinitionFilter definitionFilter = new IdmFormDefinitionFilter();
        definitionFilter.setType(getDefaultDefinitionType(owner.getClass()));
        definitionFilter.setIds(filter.getFormDefinitionAttributes().stream().map(FormDefinitionAttributes::getDefinition).collect(Collectors.toList()));
        // 
        formDefinitions = formDefinitionService.find(definitionFilter, getDefinitionPageable(), !PermissionUtils.isEmpty(permission) ? IdmBasePermission.AUTOCOMPLETE : null).getContent();
    }
    // 
    return formDefinitions.stream().map(definition -> {
        return findFormInstance(owner, definition, filter, permission);
    }).collect(Collectors.toList());
}
Also used : AbstractFormValue_(eu.bcvsolutions.idm.core.eav.entity.AbstractFormValue_) Order(org.springframework.data.domain.Sort.Order) DtoUtils(eu.bcvsolutions.idm.core.api.utils.DtoUtils) ZonedDateTime(java.time.ZonedDateTime) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) PluginRegistry(org.springframework.plugin.core.PluginRegistry) FormProjectionManager(eu.bcvsolutions.idm.core.eav.api.service.FormProjectionManager) Autowired(org.springframework.beans.factory.annotation.Autowired) FormDefinitionCache(eu.bcvsolutions.idm.core.eav.api.domain.FormDefinitionCache) FormService(eu.bcvsolutions.idm.core.eav.api.service.FormService) StringUtils(org.apache.commons.lang3.StringUtils) BigDecimal(java.math.BigDecimal) CoreEvent(eu.bcvsolutions.idm.core.api.event.CoreEvent) Matcher(java.util.regex.Matcher) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) Map(java.util.Map) BasePermission(eu.bcvsolutions.idm.core.security.api.domain.BasePermission) IdmFormAttributeService(eu.bcvsolutions.idm.core.eav.api.service.IdmFormAttributeService) Pageable(org.springframework.data.domain.Pageable) Sort(org.springframework.data.domain.Sort) FormableFilter(eu.bcvsolutions.idm.core.api.dto.filter.FormableFilter) Method(java.lang.reflect.Method) ImmutableMap(com.google.common.collect.ImmutableMap) ConfigurationClassProperty(eu.bcvsolutions.idm.core.api.domain.ConfigurationClassProperty) Set(java.util.Set) PageRequest(org.springframework.data.domain.PageRequest) UUID(java.util.UUID) IdmFormAttributeFilter(eu.bcvsolutions.idm.core.eav.api.dto.filter.IdmFormAttributeFilter) Page(org.springframework.data.domain.Page) Collectors(java.util.stream.Collectors) IntrospectionException(java.beans.IntrospectionException) Serializable(java.io.Serializable) InvocationTargetException(java.lang.reflect.InvocationTargetException) List(java.util.List) PermissionUtils(eu.bcvsolutions.idm.core.security.api.utils.PermissionUtils) PropertyDescriptor(java.beans.PropertyDescriptor) LocalDate(java.time.LocalDate) Entry(java.util.Map.Entry) Identifiable(eu.bcvsolutions.idm.core.api.domain.Identifiable) Lazy(org.springframework.context.annotation.Lazy) Pattern(java.util.regex.Pattern) PageImpl(org.springframework.data.domain.PageImpl) FormableDto(eu.bcvsolutions.idm.core.api.dto.FormableDto) IdmFormAttribute_(eu.bcvsolutions.idm.core.eav.entity.IdmFormAttribute_) FormableEntity(eu.bcvsolutions.idm.core.eav.api.entity.FormableEntity) FormAttributeRendererDto(eu.bcvsolutions.idm.core.eav.api.dto.FormAttributeRendererDto) OrderAwarePluginRegistry(org.springframework.plugin.core.OrderAwarePluginRegistry) IdmAttachmentDto(eu.bcvsolutions.idm.core.ecm.api.dto.IdmAttachmentDto) HashMap(java.util.HashMap) ValueWrapper(eu.bcvsolutions.idm.core.api.config.cache.domain.ValueWrapper) MessageFormat(java.text.MessageFormat) ArrayList(java.util.ArrayList) PersistentType(eu.bcvsolutions.idm.core.eav.api.domain.PersistentType) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) IdmFormValueFilter(eu.bcvsolutions.idm.core.eav.api.dto.filter.IdmFormValueFilter) Introspector(java.beans.Introspector) IdmBasePermission(eu.bcvsolutions.idm.core.security.api.domain.IdmBasePermission) Lists(com.google.common.collect.Lists) LookupService(eu.bcvsolutions.idm.core.api.service.LookupService) CollectionUtils(org.apache.commons.collections.CollectionUtils) EntityUtils(eu.bcvsolutions.idm.core.api.utils.EntityUtils) IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) IdmExportImportDto(eu.bcvsolutions.idm.core.api.dto.IdmExportImportDto) EntityEvent(eu.bcvsolutions.idm.core.api.event.EntityEvent) ConfigurationClass(eu.bcvsolutions.idm.core.api.domain.ConfigurationClass) IdmFormDefinition_(eu.bcvsolutions.idm.core.eav.entity.IdmFormDefinition_) FormAttributeRenderer(eu.bcvsolutions.idm.core.eav.api.service.FormAttributeRenderer) IdmFormDefinitionFilter(eu.bcvsolutions.idm.core.eav.api.dto.filter.IdmFormDefinitionFilter) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) AttachmentManager(eu.bcvsolutions.idm.core.ecm.api.service.AttachmentManager) ObjectUtils(org.springframework.util.ObjectUtils) IdmCacheManager(eu.bcvsolutions.idm.core.api.service.IdmCacheManager) EnabledEvaluator(eu.bcvsolutions.idm.core.security.api.service.EnabledEvaluator) ApplicationContext(org.springframework.context.ApplicationContext) EventContext(eu.bcvsolutions.idm.core.api.event.EventContext) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) ExportDescriptorDto(eu.bcvsolutions.idm.core.api.dto.ExportDescriptorDto) CoreResultCode(eu.bcvsolutions.idm.core.api.domain.CoreResultCode) FormValueService(eu.bcvsolutions.idm.core.eav.api.service.FormValueService) IdmFormDefinitionService(eu.bcvsolutions.idm.core.eav.api.service.IdmFormDefinitionService) IdmForm(eu.bcvsolutions.idm.core.eav.entity.IdmForm) CoreEventType(eu.bcvsolutions.idm.core.api.event.CoreEvent.CoreEventType) BaseDto(eu.bcvsolutions.idm.core.api.dto.BaseDto) Comparator(java.util.Comparator) EntityEventManager(eu.bcvsolutions.idm.core.api.service.EntityEventManager) Transactional(org.springframework.transaction.annotation.Transactional) Assert(org.springframework.util.Assert) FormDefinitionAttributes(eu.bcvsolutions.idm.core.eav.api.dto.FormDefinitionAttributes) InvalidFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.InvalidFormAttributeDto) IdmFormDefinitionFilter(eu.bcvsolutions.idm.core.eav.api.dto.filter.IdmFormDefinitionFilter) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) FormDefinitionAttributes(eu.bcvsolutions.idm.core.eav.api.dto.FormDefinitionAttributes) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

FormableFilter (eu.bcvsolutions.idm.core.api.dto.filter.FormableFilter)2 IdmFormDefinitionDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto)2 IdmFormInstanceDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Lists (com.google.common.collect.Lists)1 ValueWrapper (eu.bcvsolutions.idm.core.api.config.cache.domain.ValueWrapper)1 ConfigurationClass (eu.bcvsolutions.idm.core.api.domain.ConfigurationClass)1 ConfigurationClassProperty (eu.bcvsolutions.idm.core.api.domain.ConfigurationClassProperty)1 CoreResultCode (eu.bcvsolutions.idm.core.api.domain.CoreResultCode)1 Identifiable (eu.bcvsolutions.idm.core.api.domain.Identifiable)1 BaseDto (eu.bcvsolutions.idm.core.api.dto.BaseDto)1 ExportDescriptorDto (eu.bcvsolutions.idm.core.api.dto.ExportDescriptorDto)1 FormableDto (eu.bcvsolutions.idm.core.api.dto.FormableDto)1 IdmExportImportDto (eu.bcvsolutions.idm.core.api.dto.IdmExportImportDto)1 CoreEvent (eu.bcvsolutions.idm.core.api.event.CoreEvent)1 CoreEventType (eu.bcvsolutions.idm.core.api.event.CoreEvent.CoreEventType)1 EntityEvent (eu.bcvsolutions.idm.core.api.event.EntityEvent)1 EventContext (eu.bcvsolutions.idm.core.api.event.EventContext)1 CoreException (eu.bcvsolutions.idm.core.api.exception.CoreException)1 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)1