use of eu.bcvsolutions.idm.core.eav.api.dto.FormDefinitionAttributes in project CzechIdMng by bcvsolutions.
the class DefaultFormService method toValueFilter.
/**
* Construct value filter for find form values.
*
* @param ownerEntity owner
* @param formDefinition form definition
* @param filter only some attributes can be found only
* @return
* @since 10.3.0
*/
protected IdmFormValueFilter<FormableEntity> toValueFilter(FormableEntity ownerEntity, IdmFormDefinitionDto formDefinition, FormableFilter filter) {
IdmFormValueFilter<FormableEntity> valueFilter = new IdmFormValueFilter<>();
valueFilter.setOwner(ownerEntity);
valueFilter.setDefinitionId(formDefinition.getId());
valueFilter.setAddSecredProxyString(true);
if (filter == null) {
// filter is not given => all attributes
return valueFilter;
}
//
// apply formable filter with given parameters
List<FormDefinitionAttributes> formDefinitionAttributes = filter.getFormDefinitionAttributes();
if (CollectionUtils.isEmpty(formDefinitionAttributes)) {
// filter is given, but empty => all attributes
return valueFilter;
}
//
UUID formDefinitionId = formDefinition.getId();
FormDefinitionAttributes attributes = formDefinitionAttributes.stream().filter(a -> formDefinitionId.equals(a.getDefinition())).findFirst().orElse(null);
if (attributes == null) {
// filter is given, but without processed definition => all attributes
return valueFilter;
}
//
List<UUID> attributeIds = attributes.getAttributes();
if (CollectionUtils.isEmpty(attributeIds)) {
// filter for processed definition is given, but without attributes => all attributes
return valueFilter;
}
// set attributes by filter
valueFilter.setAttributeIds(attributes.getAttributes());
//
return valueFilter;
}
use of eu.bcvsolutions.idm.core.eav.api.dto.FormDefinitionAttributes 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());
}
use of eu.bcvsolutions.idm.core.eav.api.dto.FormDefinitionAttributes in project CzechIdMng by bcvsolutions.
the class DefaultIdentityProjectionManager method setAddEavMetadata.
/**
* Load extended attributes, if needed by projection.
*
* @param context
* @param identity
*/
protected void setAddEavMetadata(FormableFilter context, IdmIdentityDto identity) {
if (identity.getFormProjection() == null) {
// load all form instances => ~ full form projection as default, when no projection is specified
context.setAddEavMetadata(Boolean.TRUE);
return;
}
//
IdmFormProjectionDto formProjection = lookupService.lookupEmbeddedDto(identity, IdmIdentity_.formProjection);
String formDefinitions = formProjection.getFormDefinitions();
if (StringUtils.isEmpty(formDefinitions)) {
// form instances are not needed - not configured in this projection
return;
}
//
try {
List<FormDefinitionAttributes> attributes = mapper.readValue(formDefinitions, new TypeReference<List<FormDefinitionAttributes>>() {
});
if (!attributes.isEmpty()) {
context.setFormDefinitionAttributes(attributes);
} else {
LOG.debug("Extended attribute values is not needed by form projection [{}], will not be loaded.");
}
} catch (IOException ex) {
LOG.warn("Form projection [{}] is wrongly configured. Fix configured form definitions. " + "All eav attributes will be loaded as default.", formProjection.getCode(), ex);
context.setAddEavMetadata(Boolean.TRUE);
}
}
use of eu.bcvsolutions.idm.core.eav.api.dto.FormDefinitionAttributes in project CzechIdMng by bcvsolutions.
the class DefaultIdentityProjectionManagerIntegrationTest method testAssignAutomaticRoleIdentityAndContractEav.
@Test
public void testAssignAutomaticRoleIdentityAndContractEav() throws Exception {
UUID identityId = null;
try {
getHelper().enableAsynchronousProcessing();
// create form definition, roles, automatic role etc.
IdmRoleDto role = getHelper().createRole();
IdmRoleDto subRole = getHelper().createRole();
getHelper().createRoleComposition(role, subRole);
IdmRoleDto roleContract = getHelper().createRole();
IdmRoleDto subRoleContract = getHelper().createRole();
getHelper().createRoleComposition(roleContract, subRoleContract);
//
IdmFormAttributeDto formAttributeOne = new IdmFormAttributeDto(getHelper().createName());
IdmFormDefinitionDto formDefinition = formService.createDefinition(IdmIdentityDto.class, getHelper().createName(), Lists.newArrayList(formAttributeOne));
formAttributeOne = formDefinition.getMappedAttributeByCode(formAttributeOne.getCode());
//
IdmFormAttributeDto formAttributeContract = new IdmFormAttributeDto(getHelper().createName());
IdmFormDefinitionDto formDefinitionContract = formService.createDefinition(IdmIdentityContractDto.class, getHelper().createName(), Lists.newArrayList(formAttributeContract));
formAttributeContract = formDefinitionContract.getMappedAttributeByCode(formAttributeContract.getCode());
//
IdmAutomaticRoleAttributeDto automaticRole = getHelper().createAutomaticRole(role.getId());
getHelper().createAutomaticRoleRule(automaticRole.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.IDENTITY_EAV, null, formAttributeOne.getId(), "mockOne");
IdmAutomaticRoleAttributeDto automaticRoleContract = getHelper().createAutomaticRole(roleContract.getId());
getHelper().createAutomaticRoleRule(automaticRoleContract.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.CONTRACT_EAV, null, formAttributeContract.getId(), "mockContract");
// form projection
IdmFormProjectionDto formProjection = new IdmFormProjectionDto();
formProjection.setCode(getHelper().createName());
formProjection.setOwnerType(lookupService.getOwnerType(IdmIdentityDto.class));
formProjection.getProperties().put(IdentityFormProjectionRoute.PARAMETER_LOAD_ASSIGNED_ROLES, false);
formProjection.getProperties().put(IdentityFormProjectionRoute.PARAMETER_ALL_CONTRACTS, true);
FormDefinitionAttributes attributes = new FormDefinitionAttributes();
attributes.setDefinition(formDefinition.getId());
attributes.getAttributes().add(formAttributeOne.getId());
FormDefinitionAttributes attributesContract = new FormDefinitionAttributes();
attributesContract.setDefinition(formDefinitionContract.getId());
attributesContract.getAttributes().add(formAttributeContract.getId());
formProjection.setCode(getHelper().createName());
formProjection.setOwnerType(lookupService.getOwnerType(IdmIdentityDto.class));
formProjection.setFormDefinitions(mapper.writeValueAsString(Lists.newArrayList(attributes, attributesContract)));
formProjection = projectionService.save(formProjection);
//
// prepare identity projection with two contract
IdmIdentityDto identity = new IdmIdentityDto(getHelper().createName());
identity.setFormProjection(formProjection.getId());
IdmFormValueDto formValue = new IdmFormValueDto(formAttributeOne);
formValue.setValue("mockOne");
identity.getEavs().add(new IdmFormInstanceDto(identity, formDefinition, Lists.newArrayList(formValue)));
IdmIdentityContractDto contractOne = new IdmIdentityContractDto();
contractOne.setPosition(getHelper().createName());
IdmIdentityContractDto contractTwo = new IdmIdentityContractDto();
contractTwo.setPosition(getHelper().createName());
IdmFormValueDto formValueContract = new IdmFormValueDto(formAttributeContract);
formValueContract.setValue("mockContract");
contractTwo.getEavs().add(new IdmFormInstanceDto(contractTwo, formDefinitionContract, Lists.newArrayList(formValueContract)));
IdmIdentityProjectionDto projection = new IdmIdentityProjectionDto(identity);
projection.setContract(contractOne);
projection.setOtherContracts(Lists.newArrayList(contractTwo));
//
// create by projection
projection = manager.publish(new IdentityProjectionEvent(IdentityProjectionEventType.CREATE, projection)).getContent();
IdmIdentityProjectionDto createdProjection = manager.get(projection);
identityId = createdProjection.getIdentity().getId();
Assert.assertEquals(identity.getUsername(), createdProjection.getIdentity().getUsername());
IdmIdentityContractDto primeContract = createdProjection.getContract();
Assert.assertNotNull(primeContract);
Assert.assertEquals(contractOne.getPosition(), primeContract.getPosition());
Assert.assertEquals(1, createdProjection.getOtherContracts().size());
IdmIdentityContractDto otherContract = createdProjection.getOtherContracts().get(0);
Assert.assertEquals(contractTwo.getPosition(), otherContract.getPosition());
//
// 6 roles
IdmIdentityRoleFilter filter = new IdmIdentityRoleFilter();
filter.setIdentityId(createdProjection.getIdentity().getId());
getHelper().waitForResult(res -> {
return identityRoleService.find(filter, null).getContent().size() != 6;
});
List<IdmIdentityRoleDto> identityRoles = Lists.newArrayList(identityRoleService.find(filter, null).getContent());
Assert.assertEquals(6, identityRoles.size());
Assert.assertEquals(2, identityRoles.stream().filter(ir -> ir.getRole().equals(role.getId())).count());
Assert.assertEquals(2, identityRoles.stream().filter(ir -> ir.getRole().equals(subRole.getId())).count());
Assert.assertEquals(1, identityRoles.stream().filter(ir -> ir.getRole().equals(roleContract.getId())).count());
Assert.assertEquals(1, identityRoles.stream().filter(ir -> ir.getRole().equals(subRoleContract.getId())).count());
//
// change eav value => remove all automatic roles
formValue.setValue("mockUpdate");
createdProjection.getIdentity().getEavs().clear();
createdProjection.getIdentity().getEavs().add(new IdmFormInstanceDto(identity, formDefinition, Lists.newArrayList(formValue)));
manager.publish(new IdentityProjectionEvent(IdentityProjectionEventType.UPDATE, createdProjection)).getContent();
getHelper().waitForResult(res -> {
return identityRoleService.find(filter, null).getContent().size() != 2;
});
//
identityRoles = Lists.newArrayList(identityRoleService.find(filter, null).getContent());
Assert.assertEquals(2, identityRoles.size());
Assert.assertEquals(1, identityRoles.stream().filter(ir -> ir.getRole().equals(roleContract.getId())).count());
Assert.assertEquals(1, identityRoles.stream().filter(ir -> ir.getRole().equals(subRoleContract.getId())).count());
} finally {
getHelper().disableAsynchronousProcessing();
getHelper().deleteIdentity(identityId);
}
}
use of eu.bcvsolutions.idm.core.eav.api.dto.FormDefinitionAttributes in project CzechIdMng by bcvsolutions.
the class DefaultIdentityProjectionManagerIntegrationTest method testLoadProjectionDefinedEavsOnly.
@Test
@Transactional
public void testLoadProjectionDefinedEavsOnly() throws Exception {
//
// create definition with two attributes
IdmFormAttributeDto formAttributeOne = new IdmFormAttributeDto(getHelper().createName());
IdmFormAttributeDto formAttributeTwo = new IdmFormAttributeDto(getHelper().createName());
IdmFormDefinitionDto formDefinition = formService.createDefinition(IdmIdentityDto.class, getHelper().createName(), Lists.newArrayList(formAttributeOne, formAttributeTwo));
formAttributeOne = formDefinition.getMappedAttributeByCode(formAttributeOne.getCode());
formAttributeTwo = formDefinition.getMappedAttributeByCode(formAttributeTwo.getCode());
//
// create projection with one attribute
FormDefinitionAttributes attributes = new FormDefinitionAttributes();
attributes.setDefinition(formDefinition.getId());
attributes.getAttributes().add(formAttributeOne.getId());
IdmFormProjectionDto projection = new IdmFormProjectionDto();
projection.setCode(getHelper().createName());
projection.setOwnerType(lookupService.getOwnerType(IdmIdentityDto.class));
projection.setFormDefinitions(mapper.writeValueAsString(Lists.newArrayList(attributes)));
projection = projectionService.save(projection);
//
// create identity with projection is defined
IdmIdentityDto identity = new IdmIdentityDto(getHelper().createName());
identity.setFormProjection(projection.getId());
identity = identityService.save(identity);
//
// save some values
IdmFormValueDto formValueOne = new IdmFormValueDto(formAttributeOne);
formValueOne.setValue(getHelper().createName());
IdmFormValueDto formValueTwo = new IdmFormValueDto(formAttributeTwo);
formValueTwo.setValue(getHelper().createName());
List<IdmFormValueDto> formValues = Lists.newArrayList(formValueOne, formValueTwo);
identity.setEavs(Lists.newArrayList(new IdmFormInstanceDto(identity, formDefinition, formValues)));
manager.publish(new IdentityProjectionEvent(IdentityProjectionEventType.UPDATE, new IdmIdentityProjectionDto(identity)));
//
IdmIdentityProjectionDto identityProjection = manager.get(identity.getId());
//
Assert.assertEquals(1, identityProjection.getIdentity().getEavs().size());
Assert.assertEquals(1, identityProjection.getIdentity().getEavs().get(0).getValues().size());
Assert.assertEquals(formValueOne.getValue(), identityProjection.getIdentity().getEavs().get(0).getValues().get(0).getValue());
}
Aggregations