use of eu.bcvsolutions.idm.acc.exception.ProvisioningException in project CzechIdMng by bcvsolutions.
the class DefaultSysProvisioningBreakConfigService method save.
@Override
public SysProvisioningBreakConfigDto save(SysProvisioningBreakConfigDto dto, BasePermission... permission) {
// check global configuration
if (dto.getGlobalConfiguration() != null && dto.getGlobalConfiguration()) {
throw new ProvisioningException(AccResultCode.PROVISIONING_BREAK_GLOBAL_CONFIG_SAVE, ImmutableMap.of("operationType", dto.getOperationType()));
}
// check if for same system doesn't exist same operation type
SysProvisioningBreakConfigFilter filter = new SysProvisioningBreakConfigFilter();
filter.setSystemId(dto.getSystem());
filter.setOperationType(dto.getOperationType());
List<SysProvisioningBreakConfigDto> similarConfigs = this.find(filter, null).getContent();
boolean existSimilar = similarConfigs.stream().filter(config -> !config.getId().equals(dto.getId())).findFirst().isPresent();
if (!existSimilar) {
return super.save(dto, permission);
}
throw new ProvisioningException(AccResultCode.PROVISIONING_BREAK_OPERATION_EXISTS, ImmutableMap.of("operationType", dto.getOperationType(), "systemId", dto.getSystem()));
}
use of eu.bcvsolutions.idm.acc.exception.ProvisioningException in project CzechIdMng by bcvsolutions.
the class AbstractSynchronizationExecutor method findAccount.
private AccAccountDto findAccount(SynchronizationContext context) {
String uid = context.getUid();
SysSystemDto system = context.getSystem();
SysSyncItemLogDto logItem = context.getLogItem();
SysSystemEntityDto systemEntity = context.getSystemEntity();
AccAccountFilter accountFilter = new AccAccountFilter();
accountFilter.setSystemId(system.getId());
List<AccAccountDto> accounts = null;
if (systemEntity != null) {
// System entity for this uid was found. We will find account
// for this system entity.
addToItemLog(logItem, MessageFormat.format("System entity [{1}] for this UID [{0}] was found. We try to find account for this system entity", uid, systemEntity.getId()));
accountFilter.setSystemEntityId(systemEntity.getId());
accounts = accountService.find(accountFilter, null).getContent();
}
if (CollectionUtils.isEmpty(accounts)) {
// System entity was not found. We will find account by generated UID directly.
// Generate UID value from mapped attribute marked as UID (Unique ID).
// UID mapped attribute must exist and returned value must be not null
// and must be String
String attributeUid = this.generateUID(context);
addToItemLog(logItem, MessageFormat.format("Account was not found. We try to find account for UID [{0}] (generated from the mapped attribute marked as Identifier)", attributeUid));
accountFilter.setUid(attributeUid);
accountFilter.setSystemEntityId(null);
accounts = accountService.find(accountFilter, null).getContent();
}
if (accounts != null && accounts.size() > 1) {
throw new ProvisioningException(AccResultCode.SYNCHRONIZATION_TO_MANY_ACC_ACCOUNT, uid);
}
if (accounts != null && !accounts.isEmpty()) {
return accounts.get(0);
}
return null;
}
use of eu.bcvsolutions.idm.acc.exception.ProvisioningException 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, SynchronizationContext context) {
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(AutomaticRoleManager.SKIP_RECALCULATION, Boolean.TRUE);
EventContext<IdmIdentityContractDto> publishContext = contractService.publish(event);
IdmIdentityContractDto contract = publishContext.getContent();
// We need to flag recalculation for contract immediately to prevent synchronization ends before flag is created by NOTIFY event asynchronously.
Map<String, Serializable> properties = new HashMap<>();
EventResult<IdmIdentityContractDto> lastResult = publishContext.getLastResult();
if (lastResult != null) {
// original contract as property
properties.put(EntityEvent.EVENT_PROPERTY_ORIGINAL_SOURCE, lastResult.getEvent().getOriginalSource());
}
if (contract.isValidNowOrInFuture()) {
entityStateManager.createState(contract, OperationState.BLOCKED, CoreResultCode.AUTOMATIC_ROLE_SKIPPED, properties);
} else {
entityStateManager.createState(contract, OperationState.BLOCKED, CoreResultCode.AUTOMATIC_ROLE_SKIPPED_INVALID_CONTRACT, properties);
}
//
if (entity.getEmbedded().containsKey(SYNC_CONTRACT_FIELD)) {
SyncIdentityContractDto syncContract = (SyncIdentityContractDto) entity.getEmbedded().get(SYNC_CONTRACT_FIELD);
// Positions
IdmContractPositionFilter positionFilter = new IdmContractPositionFilter();
positionFilter.setIdentityContractId(contract.getId());
List<IdmContractPositionDto> currentPositions = contractPositionService.find(positionFilter, null).getContent();
// Search positions to delete
List<IdmContractPositionDto> positionsToDelete = currentPositions.stream().filter(position -> {
return position.getWorkPosition() != null && !syncContract.getPositions().contains(new IdmTreeNodeDto(position.getWorkPosition()));
}).collect(Collectors.toList());
// Search positions to add
List<IdmTreeNodeDto> positionsToAdd = syncContract.getPositions().stream().filter(position -> {
return !currentPositions.stream().filter(currentPosition -> {
return position.getId().equals(currentPosition.getWorkPosition());
}).findFirst().isPresent();
}).collect(Collectors.toList());
// Create new positions
positionsToAdd.forEach(position -> {
IdmContractPositionDto contractPosition = new IdmContractPositionDto();
contractPosition.setIdentityContract(contract.getId());
contractPosition.setWorkPosition(position.getId());
//
EntityEvent<IdmContractPositionDto> positionEvent = new ContractPositionEvent(ContractPositionEventType.CREATE, contractPosition, ImmutableMap.of(ProvisioningService.SKIP_PROVISIONING, skipProvisioning, AutomaticRoleManager.SKIP_RECALCULATION, Boolean.TRUE));
contractPosition = contractPositionService.publish(positionEvent).getContent();
// We need to flag recalculation for contract immediately to prevent synchronization ends before flag is created by NOTIFY event asynchronously.
if (contract.isValidNowOrInFuture()) {
entityStateManager.createState(contractPosition, OperationState.BLOCKED, CoreResultCode.AUTOMATIC_ROLE_SKIPPED, null);
}
});
// Delete positions - should be after new positions are created (prevent to drop and create => delete is sync).
positionsToDelete.forEach(position -> {
EntityEvent<IdmContractPositionDto> positionEvent = new ContractPositionEvent(ContractPositionEventType.DELETE, position, ImmutableMap.of(ProvisioningService.SKIP_PROVISIONING, skipProvisioning, AutomaticRoleManager.SKIP_RECALCULATION, Boolean.TRUE));
contractPositionService.publish(positionEvent);
});
// Guarantees
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;
}
use of eu.bcvsolutions.idm.acc.exception.ProvisioningException in project CzechIdMng by bcvsolutions.
the class ContractSynchronizationExecutor method getValueByMappedAttribute.
@Override
protected Object getValueByMappedAttribute(AttributeMapping attribute, List<IcAttribute> icAttributes, SynchronizationContext context) {
Object transformedValue = super.getValueByMappedAttribute(attribute, icAttributes, context);
// Transform contract state enumeration from string
if (CONTRACT_STATE_FIELD.equals(attribute.getIdmPropertyName()) && transformedValue instanceof String && attribute.isEntityAttribute()) {
return ContractState.valueOf((String) transformedValue);
}
// Transform contract guarantees
if (CONTRACT_GUARANTEES_FIELD.equals(attribute.getIdmPropertyName()) && attribute.isEntityAttribute()) {
return transformGuarantees(context, transformedValue);
}
// Transform other positions
if (CONTRACT_POSITIONS_FIELD.equals(attribute.getIdmPropertyName()) && attribute.isEntityAttribute()) {
return transformPositions(context, transformedValue);
}
// Transform work position (tree node)
if (CONTRACT_WORK_POSITION_FIELD.equals(attribute.getIdmPropertyName()) && attribute.isEntityAttribute()) {
if (transformedValue != null) {
IdmTreeNodeDto workposition = this.findTreeNode(transformedValue, context);
if (workposition != null) {
return workposition.getId();
}
return null;
} else {
if (getConfig(context).getDefaultTreeNode() != null) {
UUID defaultNode = ((SysSyncContractConfigDto) context.getConfig()).getDefaultTreeNode();
IdmTreeNodeDto node = (IdmTreeNodeDto) lookupService.lookupDto(IdmTreeNodeDto.class, defaultNode);
if (node != null) {
context.getLogItem().addToLog(MessageFormat.format("Warning! - None workposition was defined for this realtion, we use default workposition [{0}]!", node.getCode()));
return node.getId();
}
}
}
}
// Transform contract owner
if (transformedValue != null && CONTRACT_IDENTITY_FIELD.equals(attribute.getIdmPropertyName()) && attribute.isEntityAttribute()) {
context.getLogItem().addToLog(MessageFormat.format("Finding contract owner [{0}].", transformedValue));
IdmIdentityDto identity = this.findIdentity(transformedValue, context);
if (identity == null) {
throw new ProvisioningException(AccResultCode.SYNCHRONIZATION_IDM_FIELD_CANNOT_BE_NULL, ImmutableMap.of("property", CONTRACT_IDENTITY_FIELD));
}
return identity.getId();
}
return transformedValue;
}
use of eu.bcvsolutions.idm.acc.exception.ProvisioningException in project CzechIdMng by bcvsolutions.
the class DefaultSysSystemAttributeMappingService method getUidValueFromResource.
@Override
public String getUidValueFromResource(List<IcAttribute> icAttributes, List<SysSystemAttributeMappingDto> mappedAttributes, SysSystemDto system) {
SysSystemAttributeMappingDto uidAttribute = this.getUidAttribute(mappedAttributes, system);
Object uid = this.getValueByMappedAttribute(uidAttribute, icAttributes);
if (uid == null) {
SysSystemDto systemEntity = getSystemFromAttributeMapping(uidAttribute);
throw new ProvisioningException(AccResultCode.PROVISIONING_GENERATED_UID_IS_NULL, ImmutableMap.of("system", systemEntity.getName()));
}
if (!(uid instanceof String)) {
SysSystemDto systemEntity = getSystemFromAttributeMapping(uidAttribute);
throw new ProvisioningException(AccResultCode.PROVISIONING_ATTRIBUTE_UID_IS_NOT_STRING, ImmutableMap.of("uid", uid.getClass(), "system", systemEntity.getName()));
}
return (String) uid;
}
Aggregations