use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormProjectionDto in project CzechIdMng by bcvsolutions.
the class AbstractFormProjectionLookup method getFormDefinition.
/**
* Get overriden / configured form definition by projection.
* @param dto projection owner
* @param formDefinition form definition to load
* @return overriden form definition
*
* @since 12.0.0
*/
protected IdmFormDefinitionDto getFormDefinition(DTO dto, IdmFormDefinitionDto formDefinition) {
IdmFormProjectionDto formProjection = lookupProjection(dto);
if (formProjection == null) {
return null;
}
String formValidations = formProjection.getFormValidations();
if (StringUtils.isEmpty(formValidations)) {
return null;
}
//
if (formDefinition == null) {
// ~ basic fields
formDefinition = new IdmFormDefinitionDto();
formDefinition.setCode(FormService.FORM_DEFINITION_CODE_BASIC_FIELDS);
}
// clone ~ prevent to change input (e.g. cache can be modified)
IdmFormDefinitionDto overridenDefinition = new IdmFormDefinitionDto();
overridenDefinition.setId(formDefinition.getId());
overridenDefinition.setCode(formDefinition.getCode());
// transform form attributes from json
try {
List<IdmFormAttributeDto> attributes = mapper.readValue(formValidations, new TypeReference<List<IdmFormAttributeDto>>() {
});
attributes.stream().filter(attribute -> Objects.equals(attribute.getFormDefinition(), overridenDefinition.getId())).forEach(attribute -> {
if (attribute.getId() == null) {
// we need artificial id to find attributes in definition / instance
attribute.setId(UUID.randomUUID());
}
overridenDefinition.addFormAttribute(attribute);
});
//
return overridenDefinition;
} catch (IOException ex) {
throw new ResultCodeException(CoreResultCode.FORM_PROJECTION_WRONG_VALIDATION_CONFIGURATION, ImmutableMap.of("formProjection", formProjection.getCode()), ex);
}
}
use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormProjectionDto in project CzechIdMng by bcvsolutions.
the class FormProjectionDeleteProcessor method process.
@Override
public EventResult<IdmFormProjectionDto> process(EntityEvent<IdmFormProjectionDto> event) {
IdmFormProjectionDto projection = event.getContent();
//
service.deleteInternal(projection);
//
return new DefaultEventResult<>(event, this);
}
use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormProjectionDto in project CzechIdMng by bcvsolutions.
the class IdentityProvisioningTest method testUserType.
@Test
public void testUserType() {
SysSystemDto systemDto = helper.createTestResourceSystem(true);
SysSystemMappingDto defaultMapping = helper.getDefaultMapping(systemDto);
SysSchemaAttributeFilter schemaAttributeFilter = new SysSchemaAttributeFilter();
schemaAttributeFilter.setSystemId(systemDto.getId());
List<SysSchemaAttributeDto> schemaAttributes = schemaAttributeService.find(schemaAttributeFilter, null).getContent();
SysSchemaAttributeDto descriptionSchemaAttribute = schemaAttributes.stream().filter(attribute -> TestHelper.ATTRIBUTE_MAPPING_DESCRIPTION.equalsIgnoreCase(attribute.getName())).findFirst().get();
SysSystemAttributeMappingDto attributeAssignedRoles = new SysSystemAttributeMappingDto();
attributeAssignedRoles.setUid(false);
attributeAssignedRoles.setEntityAttribute(true);
attributeAssignedRoles.setIdmPropertyName(IdmIdentity_.formProjection.getName());
attributeAssignedRoles.setTransformToResourceScript("if(attributeValue != null) " + System.lineSeparator() + "{return attributeValue.getCode();}");
attributeAssignedRoles.setName(descriptionSchemaAttribute.getName());
attributeAssignedRoles.setSchemaAttribute(descriptionSchemaAttribute.getId());
attributeAssignedRoles.setSystemMapping(defaultMapping.getId());
schemaAttributeMappingService.save(attributeAssignedRoles);
IdmRoleDto roleWithSystem = helper.createRole();
helper.createRoleSystem(roleWithSystem, systemDto);
IdmIdentityDto identity = helper.createIdentity();
// Create projection
IdmFormProjectionDto projection = new IdmFormProjectionDto();
projection.setOwnerType(IdmIdentity.class.getCanonicalName());
projection.setCode(getHelper().createName());
projection.setDisabled(false);
projection = formProjectionService.save(projection);
// Set projection to the identity
identity.setFormProjection(projection.getId());
identity = identityService.save(identity);
// Execute provisioning
helper.createIdentityRole(identity, roleWithSystem, null, null);
TestResource resource = helper.findResource(identity.getUsername());
assertNotNull(resource);
String valueOnResource = resource.getDescrip();
// Code of the projection must be on target system.
assertEquals(projection.getCode(), valueOnResource);
// Delete projection.
formProjectionService.delete(projection);
}
use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormProjectionDto in project CzechIdMng by bcvsolutions.
the class DefaultIdentityProjectionManager method saveContract.
/**
* Save the first ~ prime contract.
*
* @param event
* @param permission
* @return
*/
protected IdmIdentityContractDto saveContract(EntityEvent<IdmIdentityProjectionDto> event, BasePermission... permission) {
IdmIdentityProjectionDto dto = event.getContent();
IdmIdentityDto identity = dto.getIdentity();
//
IdmIdentityContractDto contract = dto.getContract();
if (contract == null) {
// prime contract was not sent => not save, but is needed in other processing
List<IdmIdentityContractDto> contracts = getContracts(dto, PermissionUtils.isEmpty(permission) ? null : IdmBasePermission.READ);
if (contracts.isEmpty()) {
return null;
}
// ~ prime contract
return contracts.get(0);
}
// check contract has to be saved
if (identity.getFormProjection() != null) {
IdmFormProjectionDto formProjection = lookupService.lookupEmbeddedDto(dto.getIdentity(), IdmIdentity_.formProjection);
if (!formProjection.getProperties().getBooleanValue(IdentityFormProjectionRoute.PARAMETER_ALL_CONTRACTS) && !formProjection.getProperties().getBooleanValue(IdentityFormProjectionRoute.PARAMETER_PRIME_CONTRACT)) {
LOG.debug("Projection [{}] doesn't save prime contract.", formProjection.getCode());
return contract;
}
}
contract.setIdentity(identity.getId());
IdentityContractEventType contractEventType = IdentityContractEventType.CREATE;
if (!contractService.isNew(contract)) {
contractEventType = IdentityContractEventType.UPDATE;
}
EntityEvent<IdmIdentityContractDto> contractEvent = new IdentityContractEvent(contractEventType, contract);
//
return contractService.publish(contractEvent, event, permission).getContent();
}
use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormProjectionDto in project CzechIdMng by bcvsolutions.
the class DefaultIdentityProjectionManager method saveOtherPositions.
protected List<IdmContractPositionDto> saveOtherPositions(EntityEvent<IdmIdentityProjectionDto> event, BasePermission... permission) {
IdmIdentityProjectionDto dto = event.getContent();
IdmIdentityProjectionDto previousProjection = event.getOriginalSource();
List<IdmContractPositionDto> savedPositions = new ArrayList<>(dto.getOtherPositions().size());
IdmIdentityContractDto contract = dto.getContract();
//
// check other contract position has to be saved
IdmIdentityDto identity = dto.getIdentity();
if (identity.getFormProjection() != null) {
IdmFormProjectionDto formProjection = lookupService.lookupEmbeddedDto(dto.getIdentity(), IdmIdentity_.formProjection);
if (!formProjection.getProperties().getBooleanValue(IdentityFormProjectionRoute.PARAMETER_OTHER_POSITION)) {
LOG.debug("Projection [{}] doesn't save other contract positions.", formProjection.getCode());
return savedPositions;
}
}
//
for (IdmContractPositionDto otherPosition : dto.getOtherPositions()) {
if (otherPosition.getIdentityContract() == null) {
if (contract == null) {
throw new ForbiddenEntityException("contract", IdmBasePermission.READ);
}
otherPosition.setIdentityContract(contract.getId());
}
ContractPositionEventType positionEventType = ContractPositionEventType.CREATE;
if (!contractPositionService.isNew(otherPosition)) {
positionEventType = ContractPositionEventType.UPDATE;
}
ContractPositionEvent positionEvent = new ContractPositionEvent(positionEventType, otherPosition);
//
savedPositions.add(contractPositionService.publish(positionEvent, event, permission).getContent());
if (previousProjection != null) {
previousProjection.getOtherPositions().removeIf(p -> {
return Objects.equals(p.getId(), otherPosition.getId());
});
}
}
// remove not sent positions, if previous exists
if (previousProjection != null) {
for (IdmContractPositionDto contractPosition : previousProjection.getOtherPositions()) {
ContractPositionEventType positionEventType = ContractPositionEventType.DELETE;
ContractPositionEvent positionEvent = new ContractPositionEvent(positionEventType, contractPosition);
//
contractPositionService.publish(positionEvent, event, PermissionUtils.isEmpty(permission) ? null : IdmBasePermission.DELETE);
}
}
//
return savedPositions;
}
Aggregations