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;
}
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());
}
Aggregations