use of eu.bcvsolutions.idm.acc.dto.AccAccountDto in project CzechIdMng by bcvsolutions.
the class AbstractSynchronizationExecutor method startWorkflow.
/**
* Start workflow process by wfDefinitionKey. Create input variables and put
* them to the process. If log variable is present after the process started,
* then add the log to the synchronization log.
*
* @param wfDefinitionKey
* @param uid
* @param situation
* @param action
* @param icAttributes
* @param dto
* @param account
* @param entityType
* @param config
* @param log
* @param logItem
* @param actionLogs
*/
private void startWorkflow(String wfDefinitionKey, SynchronizationSituationType situation, SynchronizationActionType action, DTO dto, SynchronizationContext context) {
SystemEntityType entityType = context.getEntityType();
SysSyncLogDto log = context.getLog();
SysSyncItemLogDto logItem = context.getLogItem();
List<SysSyncActionLogDto> actionLogs = context.getActionLogs();
AccAccountDto account = context.getAccount();
String uid = context.getUid();
AbstractSysSyncConfigDto config = context.getConfig();
addToItemLog(logItem, MessageFormat.format("Workflow for {0} situation was found. We will start it.", situation));
Map<String, Object> variables = new HashMap<>();
variables.put(SynchronizationService.WF_VARIABLE_KEY_UID, uid);
variables.put(SynchronizationService.WF_VARIABLE_KEY_ENTITY_TYPE, entityType);
variables.put(SynchronizationService.WF_VARIABLE_KEY_SYNC_SITUATION, situation.name());
variables.put(SynchronizationService.WF_VARIABLE_KEY_IC_ATTRIBUTES, context.getIcObject().getAttributes());
variables.put(SynchronizationService.WF_VARIABLE_KEY_ACTION_TYPE, action.name());
variables.put(SynchronizationService.WF_VARIABLE_KEY_ENTITY_ID, dto != null ? dto.getId() : null);
variables.put(SynchronizationService.WF_VARIABLE_KEY_ACC_ACCOUNT_ID, account != null ? account.getId() : null);
variables.put(SynchronizationService.WF_VARIABLE_KEY_SYNC_CONFIG_ID, config.getId());
ProcessInstance processInstance = workflowProcessInstanceService.startProcess(wfDefinitionKey, SysSyncConfig.class.getSimpleName(), uid, config.getId().toString(), variables);
if (processInstance instanceof VariableScope) {
Object logItemObj = ((VariableScope) processInstance).getVariable(SynchronizationService.WF_VARIABLE_KEY_LOG_ITEM);
if (logItemObj instanceof String) {
addToItemLog(logItem, (String) logItemObj);
}
}
if (processInstance.isEnded()) {
addToItemLog(logItem, MessageFormat.format("Workflow (with id {0}) for missing entity situation ended.", processInstance.getId()));
initSyncActionLog(situation.getAction(), OperationResultType.WF, logItem, log, actionLogs);
} else {
addToItemLog(logItem, MessageFormat.format("Workflow (with id {0}) for missing entity situation not ended (will be ended asynchronously).", processInstance.getId()));
initSyncActionLog(situation.getAction(), OperationResultType.WF, logItem, log, actionLogs);
}
}
use of eu.bcvsolutions.idm.acc.dto.AccAccountDto in project CzechIdMng by bcvsolutions.
the class AbstractSynchronizationExecutor method doCreateIdmAccount.
/**
* Create new instance of ACC account
*
* @param uid
* @param system
* @return
*/
protected AccAccountDto doCreateIdmAccount(String uid, SysSystemDto system) {
AccAccountDto account = new AccAccountDto();
account.setSystem(system.getId());
account.setAccountType(AccountType.PERSONAL);
account.setUid(uid);
account.setEntityType(getEntityType());
return account;
}
use of eu.bcvsolutions.idm.acc.dto.AccAccountDto in project CzechIdMng by bcvsolutions.
the class DefaultAccAccountManagementService method createAccount.
private UUID createAccount(String uid, SysRoleSystemDto roleSystem) {
AccAccountDto account = new AccAccountDto();
account.setUid(uid);
account.setEntityType(SystemEntityType.IDENTITY);
account.setAccountType(AccountType.PERSONAL);
account.setSystem(roleSystem.getSystem());
account = accountService.save(account);
return account.getId();
}
use of eu.bcvsolutions.idm.acc.dto.AccAccountDto in project CzechIdMng by bcvsolutions.
the class DefaultAccAccountManagementService method createAccountByRoleSystem.
/**
* Create Account by given roleSystem
*
* @param identity
* @param roleSystem
* @param identityAccountsToCreate
* @return
*/
private UUID createAccountByRoleSystem(IdmIdentityDto identity, SysRoleSystemDto roleSystem, List<AccIdentityAccountDto> identityAccountsToCreate) {
String uid = generateUID(identity, roleSystem);
// We try find account for same uid on same system
// First we try search same account in list for create new accounts
Optional<AccIdentityAccountDto> sameAccountOptional = identityAccountsToCreate.stream().filter(ia -> {
AccAccountDto account = accountService.get(ia.getAccount());
return account.getUid().equals(uid) && roleSystem.getId().equals(ia.getRoleSystem());
}).findFirst();
if (sameAccountOptional.isPresent()) {
return sameAccountOptional.get().getAccount();
}
UUID accountId = null;
// If account is not in the list accounts to create, then we will search in
// database
// Account management - can be the account created? - execute the script on the
// system mapping
SysSystemDto system = DtoUtils.getEmbedded(roleSystem, SysRoleSystem_.system, SysSystemDto.class);
SysSystemMappingDto mapping = systemMappingService.findProvisioningMapping(system.getId(), SystemEntityType.IDENTITY);
if (mapping == null) {
return null;
}
if (!this.canBeAccountCreated(uid, identity, mapping, system)) {
LOG.info(MessageFormat.format("For entity [{0}] and entity type [{1}] cannot be created the account (on system [{2}])," + " because script \"Can be account created\" on the mapping returned \"false\"!", identity.getCode(), SystemEntityType.IDENTITY, system.getName()));
return null;
}
AccAccountFilter accountFilter = new AccAccountFilter();
accountFilter.setUid(uid);
accountFilter.setSystemId(roleSystem.getSystem());
List<AccAccountDto> sameAccounts = accountService.find(accountFilter, null).getContent();
if (CollectionUtils.isEmpty(sameAccounts)) {
// Create and persist new account
accountId = createAccount(uid, roleSystem);
} else {
// We use existed account
accountId = sameAccounts.get(0).getId();
}
return accountId;
}
use of eu.bcvsolutions.idm.acc.dto.AccAccountDto in project CzechIdMng by bcvsolutions.
the class DefaultAccAccountManagementService method resolveIdentityAccountForCreate.
/**
* Resolve Identity account - to create
*
* @param identity
* @param identityAccountList
* @param identityRoles
* @param identityAccountsToCreate
* @param identityAccountsToDelete
* @param resolvedRolesForCreate
*/
private void resolveIdentityAccountForCreate(IdmIdentityDto identity, List<AccIdentityAccountDto> identityAccountList, List<IdmIdentityRole> identityRoles, List<AccIdentityAccountDto> identityAccountsToCreate, List<AccIdentityAccountDto> identityAccountsToDelete) {
// Is role valid in this moment
identityRoles.stream().filter(identityRole -> {
return identityRole.isValid();
}).forEach(identityRole -> {
IdmRole role = identityRole.getRole();
SysRoleSystemFilter roleSystemFilter = new SysRoleSystemFilter();
roleSystemFilter.setRoleId(role.getId());
List<SysRoleSystemDto> roleSystems = roleSystemService.find(roleSystemFilter, null).getContent();
roleSystems.stream().filter(roleSystem -> {
// Filter out identity-accounts for same role-system, account (by UID)
return !identityAccountList.stream().filter(identityAccount -> {
if (roleSystem.getId().equals(identityAccount.getRoleSystem())) {
// Has identity account same uid as account?
String uid = generateUID(identity, roleSystem);
AccAccountDto account = AccIdentityAccountService.getEmbeddedAccount(identityAccount);
if (!uid.equals(account.getUid())) {
// We found identityAccount for same identity and roleSystem, but this
// identityAccount
// is link to Account with different UID. It's probably means definition of UID
// (transformation)\
// on roleSystem was changed. We have to delete this identityAccount.
identityAccountsToDelete.add(identityAccount);
}
}
return false;
}).findFirst().isPresent();
}).forEach(roleSystem -> {
// For this system we have to create new account
UUID accountId = createAccountByRoleSystem(identity, roleSystem, identityAccountsToCreate);
if (accountId == null) {
return;
}
// TODO: find the better place for this check
if (identityAccountList.stream().filter(identityAccount -> {
return identityAccount.getAccount().equals(accountId) && identityRole.getId().equals(identityAccount.getIdentityRole()) && roleSystem.getId().equals(identityAccount.getRoleSystem());
}).count() == 0) {
AccIdentityAccountDto identityAccount = new AccIdentityAccountDto();
identityAccount.setAccount(accountId);
identityAccount.setIdentity(identity.getId());
identityAccount.setIdentityRole(identityRole.getId());
identityAccount.setRoleSystem(roleSystem.getId());
// TODO: Add flag ownership to SystemRole and set here.
identityAccount.setOwnership(true);
identityAccountsToCreate.add(identityAccount);
}
});
});
}
Aggregations