use of eu.bcvsolutions.idm.acc.dto.SyncIdentityContractDto in project CzechIdMng by bcvsolutions.
the class ContractSynchronizationExecutor method transformGuarantees.
private Object transformGuarantees(SynchronizationContext context, Object transformedValue) {
if (transformedValue != null) {
SyncIdentityContractDto syncContract = new SyncIdentityContractDto();
if (transformedValue instanceof List) {
((List<?>) transformedValue).stream().forEach(guarantee -> {
// Beware this DTO contains only identity ID, not
// contract ... must be save separately.
context.getLogItem().addToLog(MessageFormat.format("Finding guarantee [{0}].", guarantee));
IdmIdentityDto guarranteeDto = this.findIdentity(guarantee, context);
if (guarranteeDto != null) {
context.getLogItem().addToLog(MessageFormat.format("Guarantee [{0}] was found.", guarranteeDto.getCode()));
syncContract.getGuarantees().add(guarranteeDto);
}
});
} else {
// Beware this DTO contains only identity ID, not
// contract ... must be save separately.
context.getLogItem().addToLog(MessageFormat.format("Finding guarantee [{0}].", transformedValue));
IdmIdentityDto guarranteeDto = this.findIdentity(transformedValue, context);
if (guarranteeDto != null) {
context.getLogItem().addToLog(MessageFormat.format("Guarantee [{0}] was found.", guarranteeDto.getCode()));
syncContract.getGuarantees().add(guarranteeDto);
}
}
transformedValue = syncContract;
} else {
if (getConfig(context).getDefaultLeader() != null) {
UUID defaultLeader = ((SysSyncContractConfigDto) context.getConfig()).getDefaultLeader();
IdmIdentityDto identity = (IdmIdentityDto) lookupService.lookupDto(IdmIdentityDto.class, defaultLeader);
if (identity != null) {
SyncIdentityContractDto syncContract = new SyncIdentityContractDto();
syncContract.getGuarantees().add(identity);
transformedValue = syncContract;
context.getLogItem().addToLog(MessageFormat.format("Warning! - None leader was found for this realtion, we use default leader [{0}]!", identity.getCode()));
}
}
}
return transformedValue;
}
use of eu.bcvsolutions.idm.acc.dto.SyncIdentityContractDto in project CzechIdMng by bcvsolutions.
the class ContractSynchronizationExecutor method fillEntity.
/**
* Fill entity with attributes from IC module (by mapped attributes).
*
* @param mappedAttributes
* @param uid
* @param icAttributes
* @param entity
* @param create
* (is create or update entity situation)
* @param context
* @return
*/
protected IdmIdentityContractDto fillEntity(List<SysSystemAttributeMappingDto> mappedAttributes, String uid, List<IcAttribute> icAttributes, IdmIdentityContractDto dto, boolean create, SynchronizationContext context) {
mappedAttributes.stream().filter(attribute -> {
// Skip disabled attributes
// Skip extended attributes (we need update/ create entity first)
// Skip confidential attributes (we need update/ create entity
// first)
boolean fastResult = !attribute.isDisabledAttribute() && attribute.isEntityAttribute() && !attribute.isConfidentialAttribute();
if (!fastResult) {
return false;
}
// Can be value set by attribute strategy?
return this.canSetValue(uid, attribute, dto, create);
}).forEach(attribute -> {
String attributeProperty = attribute.getIdmPropertyName();
Object transformedValue = getValueByMappedAttribute(attribute, icAttributes, context);
// they), but to the embedded map.
if (CONTRACT_GUARANTEES_FIELD.equals(attributeProperty)) {
if (transformedValue instanceof SyncIdentityContractDto) {
dto.getEmbedded().put(SYNC_CONTRACT_FIELD, (SyncIdentityContractDto) transformedValue);
} else {
dto.getEmbedded().put(SYNC_CONTRACT_FIELD, new SyncIdentityContractDto());
}
return;
}
// Set transformed value from target system to entity
try {
EntityUtils.setEntityValue(dto, attributeProperty, transformedValue);
} catch (IntrospectionException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | ProvisioningException e) {
throw new ProvisioningException(AccResultCode.SYNCHRONIZATION_IDM_FIELD_NOT_SET, ImmutableMap.of("property", attributeProperty, "uid", uid), e);
}
});
return dto;
}
use of eu.bcvsolutions.idm.acc.dto.SyncIdentityContractDto in project CzechIdMng by bcvsolutions.
the class ContractSynchronizationExecutor method save.
/**
* Save entity
*
* @param entity
* @param skipProvisioning
* @return
*/
@Override
protected IdmIdentityContractDto save(IdmIdentityContractDto entity, boolean skipProvisioning) {
if (entity.getIdentity() == null) {
throw new ProvisioningException(AccResultCode.SYNCHRONIZATION_IDM_FIELD_CANNOT_BE_NULL, ImmutableMap.of("property", CONTRACT_IDENTITY_FIELD));
}
EntityEvent<IdmIdentityContractDto> event = new IdentityContractEvent(contractService.isNew(entity) ? IdentityContractEventType.CREATE : IdentityContractEventType.UPDATE, entity, ImmutableMap.of(ProvisioningService.SKIP_PROVISIONING, skipProvisioning));
// We do not want execute HR processes for every contract. We need start
// them for every identity only once.
// For this we skip them now. HR processes must be start after whole
// sync finished (by using dependent scheduled task)!
event.getProperties().put(IdmIdentityContractService.SKIP_HR_PROCESSES, Boolean.TRUE);
//
// We don't want recalculate automatic role by attribute recalculation for every contract.
// Recalculation will be started only once.
event.getProperties().put(IdmAutomaticRoleAttributeService.SKIP_RECALCULATION, Boolean.TRUE);
IdmIdentityContractDto contract = contractService.publish(event).getContent();
if (entity.getEmbedded().containsKey(SYNC_CONTRACT_FIELD)) {
SyncIdentityContractDto syncContract = (SyncIdentityContractDto) entity.getEmbedded().get(SYNC_CONTRACT_FIELD);
IdmContractGuaranteeFilter guaranteeFilter = new IdmContractGuaranteeFilter();
guaranteeFilter.setIdentityContractId(contract.getId());
List<IdmContractGuaranteeDto> currentGuarantees = guaranteeService.find(guaranteeFilter, null).getContent();
// Search guarantees to delete
List<IdmContractGuaranteeDto> guaranteesToDelete = currentGuarantees.stream().filter(sysImplementer -> {
return sysImplementer.getGuarantee() != null && !syncContract.getGuarantees().contains(new IdmIdentityDto(sysImplementer.getGuarantee()));
}).collect(Collectors.toList());
// Search guarantees to add
List<IdmIdentityDto> guaranteesToAdd = syncContract.getGuarantees().stream().filter(identity -> {
return !currentGuarantees.stream().filter(currentGuarrantee -> {
return identity.getId().equals(currentGuarrantee.getGuarantee());
}).findFirst().isPresent();
}).collect(Collectors.toList());
// Delete guarantees
guaranteesToDelete.forEach(guarantee -> {
EntityEvent<IdmContractGuaranteeDto> guaranteeEvent = new ContractGuaranteeEvent(ContractGuaranteeEventType.DELETE, guarantee, ImmutableMap.of(ProvisioningService.SKIP_PROVISIONING, skipProvisioning));
guaranteeService.publish(guaranteeEvent);
});
// Create new guarantees
guaranteesToAdd.forEach(identity -> {
IdmContractGuaranteeDto guarantee = new IdmContractGuaranteeDto();
guarantee.setIdentityContract(contract.getId());
guarantee.setGuarantee(identity.getId());
//
EntityEvent<IdmContractGuaranteeDto> guaranteeEvent = new ContractGuaranteeEvent(ContractGuaranteeEventType.CREATE, guarantee, ImmutableMap.of(ProvisioningService.SKIP_PROVISIONING, skipProvisioning));
guaranteeService.publish(guaranteeEvent);
});
}
return contract;
}
Aggregations