use of eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto in project CzechIdMng by bcvsolutions.
the class IdentityContractSyncTest method checkContractInvalidTest.
@Test
public /**
* HR process are not executed during sync. If contract is invalid, then HR
* process disable the Identity. But in the sync we need skip this
* functionality.
*/
void checkContractInvalidTest() {
SysSystemDto system = initData();
Assert.assertNotNull(system);
AbstractSysSyncConfigDto config = doCreateSyncConfig(system);
Assert.assertTrue(config instanceof SysSyncContractConfigDto);
((SysSyncContractConfigDto) config).setStartOfHrProcesses(false);
syncConfigService.save(config);
IdmIdentityDto ownerOne = helper.createIdentity(CONTRACT_OWNER_ONE);
IdmIdentityDto ownerTwo = helper.createIdentity(CONTRACT_OWNER_TWO);
helper.createIdentity(CONTRACT_LEADER_ONE);
contractService.findAllByIdentity(ownerOne.getId()).forEach(contract -> {
IdentityContractEvent event = new IdentityContractEvent(IdentityContractEventType.DELETE, contract);
event.getProperties().put(IdmIdentityContractService.SKIP_HR_PROCESSES, Boolean.TRUE);
contractService.publish(event);
});
contractService.findAllByIdentity(ownerTwo.getId()).forEach(contract -> {
IdentityContractEvent event = new IdentityContractEvent(IdentityContractEventType.DELETE, contract);
event.getProperties().put(IdmIdentityContractService.SKIP_HR_PROCESSES, Boolean.TRUE);
contractService.publish(event);
});
IdmIdentityContractFilter contractFilter = new IdmIdentityContractFilter();
contractFilter.setProperty(IdmIdentityContract_.position.getName());
contractFilter.setValue("1");
Assert.assertEquals(0, contractService.find(contractFilter, null).getTotalElements());
contractFilter.setValue("2");
Assert.assertEquals(0, contractService.find(contractFilter, null).getTotalElements());
// Change resources (set to invalid) .. must be call in transaction
this.getBean().initContractCheckInvalidTest();
synchornizationService.setSynchronizationConfigId(config.getId());
synchornizationService.process();
SysSyncLogDto log = checkSyncLog(config, SynchronizationActionType.CREATE_ENTITY, 2);
Assert.assertFalse(log.isRunning());
Assert.assertFalse(log.isContainsError());
contractFilter.setValue("1");
List<IdmIdentityContractDto> contractsOne = contractService.find(contractFilter, null).getContent();
Assert.assertEquals(1, contractsOne.size());
Assert.assertFalse(contractsOne.get(0).isValid());
contractFilter.setValue("3");
List<IdmIdentityContractDto> contractsThree = contractService.find(contractFilter, null).getContent();
Assert.assertEquals(1, contractsThree.size());
Assert.assertTrue(contractsThree.get(0).isValid());
// HR processes was not started, identity have to be in "incorrect" state
ownerOne = identityService.getByUsername(CONTRACT_OWNER_ONE);
Assert.assertFalse(ownerOne.isDisabled());
ownerTwo = identityService.getByUsername(CONTRACT_OWNER_TWO);
Assert.assertFalse(ownerTwo.isDisabled());
// Delete log
syncLogService.delete(log);
}
use of eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto in project CzechIdMng by bcvsolutions.
the class IdentityContractSyncTest method testLinkAndUpdateContract.
@Test
public void testLinkAndUpdateContract() {
String position1 = "test-link-update-1-" + System.currentTimeMillis();
String position2 = "test-link-update-2-" + System.currentTimeMillis();
String position3 = "test-link-update-3-" + System.currentTimeMillis();
IdmIdentityDto leader = helper.createIdentity();
IdmTreeNodeDto workPosition = helper.createTreeNode();
SysSystemDto system = initData();
AbstractSysSyncConfigDto config = doCreateSyncConfig(system);
this.getBean().deleteAllResourceData();
config.setUnlinkedAction(SynchronizationUnlinkedActionType.LINK_AND_UPDATE_ENTITY);
config = (SysSyncContractConfigDto) syncConfigService.save(config);
IdmIdentityDto identity1 = helper.createIdentity();
IdmIdentityDto identity2 = helper.createIdentity();
IdmIdentityDto identity3 = helper.createIdentity();
IdmIdentityContractDto contrac1 = helper.getPrimeContract(identity1.getId());
IdmIdentityContractDto contrac2 = helper.getPrimeContract(identity2.getId());
IdmIdentityContractDto contrac3 = helper.getPrimeContract(identity3.getId());
contrac1.setPosition(position1);
contrac1.setDescription(position1);
contrac2.setPosition(position2);
contrac2.setDescription(position2);
contrac3.setPosition(position3);
contrac3.setDescription(position3);
contrac1 = contractService.save(contrac1);
contrac2 = contractService.save(contrac2);
contrac3 = contractService.save(contrac3);
// check empty guarantee
IdmContractGuaranteeFilter guaranteeFilter = new IdmContractGuaranteeFilter();
guaranteeFilter.setIdentityContractId(contrac1.getId());
List<IdmContractGuaranteeDto> gurantees = guaranteeService.find(guaranteeFilter, null).getContent();
assertTrue(gurantees.isEmpty());
guaranteeFilter.setIdentityContractId(contrac2.getId());
gurantees = guaranteeService.find(guaranteeFilter, null).getContent();
assertTrue(gurantees.isEmpty());
guaranteeFilter.setIdentityContractId(contrac3.getId());
gurantees = guaranteeService.find(guaranteeFilter, null).getContent();
assertTrue(gurantees.isEmpty());
assertNull(contrac1.getState());
assertNull(contrac2.getState());
assertNull(contrac3.getState());
this.getBean().createContractData(position1, identity1.getUsername(), leader.getUsername(), Boolean.TRUE.toString(), workPosition.getId().toString(), "10", Boolean.FALSE.toString());
this.getBean().createContractData(position2, identity2.getUsername(), leader.getUsername(), Boolean.TRUE.toString(), workPosition.getId().toString(), "10", Boolean.FALSE.toString());
this.getBean().createContractData(position3, identity3.getUsername(), leader.getUsername(), Boolean.TRUE.toString(), workPosition.getId().toString(), "10", Boolean.FALSE.toString());
// Start sync
synchornizationService.setSynchronizationConfigId(config.getId());
synchornizationService.process();
contractService.findAllByIdentity(identity1.getId());
SysSyncLogDto log = checkSyncLog(config, SynchronizationActionType.LINK_AND_UPDATE_ENTITY, 3);
Assert.assertFalse(log.isRunning());
Assert.assertFalse(log.isContainsError());
IdmIdentityContractDto updatedContract1 = helper.getPrimeContract(identity1.getId());
IdmIdentityContractDto updatedContract2 = helper.getPrimeContract(identity2.getId());
IdmIdentityContractDto updatedContract3 = helper.getPrimeContract(identity3.getId());
assertNotEquals(updatedContract1.getModified(), contrac1.getModified());
assertNotEquals(updatedContract2.getModified(), contrac2.getModified());
assertNotEquals(updatedContract3.getModified(), contrac3.getModified());
assertNotEquals(updatedContract1.getState(), contrac1.getState());
assertNotEquals(updatedContract2.getState(), contrac2.getState());
assertNotEquals(updatedContract3.getState(), contrac3.getState());
assertEquals(ContractState.EXCLUDED, updatedContract1.getState());
assertEquals(ContractState.EXCLUDED, updatedContract2.getState());
assertEquals(ContractState.EXCLUDED, updatedContract3.getState());
assertEquals(contrac1.getId(), updatedContract1.getId());
assertEquals(contrac2.getId(), updatedContract2.getId());
assertEquals(contrac3.getId(), updatedContract3.getId());
guaranteeFilter.setIdentityContractId(contrac1.getId());
gurantees = guaranteeService.find(guaranteeFilter, null).getContent();
assertFalse(gurantees.isEmpty());
assertEquals(leader.getId(), gurantees.get(0).getGuarantee());
guaranteeFilter.setIdentityContractId(contrac2.getId());
gurantees = guaranteeService.find(guaranteeFilter, null).getContent();
assertFalse(gurantees.isEmpty());
assertEquals(leader.getId(), gurantees.get(0).getGuarantee());
guaranteeFilter.setIdentityContractId(contrac3.getId());
gurantees = guaranteeService.find(guaranteeFilter, null).getContent();
assertFalse(gurantees.isEmpty());
assertEquals(leader.getId(), gurantees.get(0).getGuarantee());
}
use of eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto in project CzechIdMng by bcvsolutions.
the class IdentityContractSyncTest method defaultTreeTest.
@Test
public void defaultTreeTest() {
SysSystemDto system = initData();
Assert.assertNotNull(system);
AbstractSysSyncConfigDto config = doCreateSyncConfig(system);
Assert.assertTrue(config instanceof SysSyncContractConfigDto);
helper.createIdentity(CONTRACT_OWNER_ONE);
helper.createIdentity(CONTRACT_OWNER_TWO);
helper.createIdentity(CONTRACT_LEADER_ONE);
helper.createIdentity(CONTRACT_LEADER_TWO);
// Set default tree type to sync configuration
IdmTreeTypeDto treeType = treeTypeService.getByCode(InitApplicationData.DEFAULT_TREE_TYPE);
Assert.assertNotNull(treeType);
SysSyncContractConfigDto configContract = (SysSyncContractConfigDto) config;
configContract.setDefaultTreeType(treeType.getId());
config = syncConfigService.save(configContract);
IdmIdentityContractFilter contractFilter = new IdmIdentityContractFilter();
contractFilter.setProperty(IdmIdentityContract_.position.getName());
// Start sync
synchornizationService.setSynchronizationConfigId(config.getId());
synchornizationService.process();
SysSyncLogDto log = checkSyncLog(config, SynchronizationActionType.CREATE_ENTITY, 3);
Assert.assertFalse(log.isRunning());
Assert.assertFalse(log.isContainsError());
// None work positions can be found
contractFilter.setValue("1");
List<IdmIdentityContractDto> contractsOne = contractService.find(contractFilter, null).getContent();
Assert.assertEquals(1, contractsOne.size());
Assert.assertEquals(null, contractsOne.get(0).getWorkPosition());
contractFilter.setValue("2");
List<IdmIdentityContractDto> contractsTwo = contractService.find(contractFilter, null).getContent();
Assert.assertEquals(1, contractsTwo.size());
Assert.assertEquals(null, contractsTwo.get(0).getWorkPosition());
contractFilter.setValue("3");
List<IdmIdentityContractDto> contractsThree = contractService.find(contractFilter, null).getContent();
Assert.assertEquals(1, contractsThree.size());
Assert.assertEquals(null, contractsThree.get(0).getWorkPosition());
// Delete log
syncLogService.delete(log);
// Set work positions to resources
this.getBean().initContractDefaultTreeTest();
// Start sync again (we want to see some work positions)
synchornizationService.setSynchronizationConfigId(config.getId());
synchornizationService.process();
log = checkSyncLog(config, SynchronizationActionType.UPDATE_ENTITY, 3);
Assert.assertFalse(log.isRunning());
Assert.assertFalse(log.isContainsError());
// For contract One must be found workposition (one)
contractFilter.setValue("1");
contractsOne = contractService.find(contractFilter, null).getContent();
Assert.assertEquals(1, contractsOne.size());
IdmTreeNodeDto workposition = DtoUtils.getEmbedded(contractsOne.get(0), IdmIdentityContract_.workPosition, IdmTreeNodeDto.class);
Assert.assertEquals("one", workposition.getCode());
// For contract Two must not be found workposition (WRONG node is not in
// default
// tree)
contractFilter.setValue("2");
contractsTwo = contractService.find(contractFilter, null).getContent();
Assert.assertEquals(1, contractsTwo.size());
Assert.assertEquals(null, contractsTwo.get(0).getWorkPosition());
contractFilter.setValue("3");
contractsThree = contractService.find(contractFilter, null).getContent();
Assert.assertEquals(1, contractsThree.size());
Assert.assertEquals(null, contractsThree.get(0).getWorkPosition());
// Delete log
syncLogService.delete(log);
}
use of eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto 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.AbstractSysSyncConfigDto in project CzechIdMng by bcvsolutions.
the class AbstractSynchronizationExecutor method startItemSynchronization.
/**
* Main method for synchronization item. This method is call form "custom
* filter" and "connector sync" mode.
*
* @param uid
* @param icObject
* @param type
* @param entityType
* @param itemLog
* @param config
* @param system
* @param mappedAttributes
* @param log
* @param actionsLog
* @return
*/
protected boolean startItemSynchronization(SynchronizationContext itemContext) {
String uid = itemContext.getUid();
AbstractSysSyncConfigDto config = itemContext.getConfig();
SystemEntityType entityType = itemContext.getEntityType();
SysSyncLogDto log = itemContext.getLog();
SysSyncItemLogDto itemLog = itemContext.getLogItem();
List<SysSyncActionLogDto> actionsLog = new ArrayList<>();
try {
SysSyncActionLogFilter actionFilter = new SysSyncActionLogFilter();
actionFilter.setSynchronizationLogId(log.getId());
actionsLog.addAll(syncActionLogService.find(actionFilter, null).getContent());
itemContext.addActionLogs(actionsLog);
// Default setting for log item
itemLog.setIdentification(uid);
itemLog.setDisplayName(uid);
itemLog.setType(entityType.getEntityType().getSimpleName());
// Do synchronization for one item (produces item)
// Start in new Transaction
CoreEvent<SysSyncItemLogDto> event = new CoreEvent<SysSyncItemLogDto>(SynchronizationEventType.START_ITEM, itemLog);
event.getProperties().put(SynchronizationService.WRAPPER_SYNC_ITEM, itemContext);
EventResult<SysSyncItemLogDto> lastResult = entityEventManager.process(event).getLastResult();
boolean result = false;
if (lastResult != null && lastResult.getEvent().getProperties().containsKey(SynchronizationService.RESULT_SYNC_ITEM)) {
result = (boolean) lastResult.getEvent().getProperties().get(SynchronizationService.RESULT_SYNC_ITEM);
}
return result;
} catch (Exception ex) {
Pair<SysSyncActionLogDto, SysSyncItemLogDto> actionWithItemLog = getActionLogThatContains(actionsLog, itemLog);
if (actionWithItemLog != null) {
// We have to decrement count and log as error
itemLog = actionWithItemLog.getRight();
SysSyncActionLogDto actionLogDto = actionWithItemLog.getLeft();
actionLogDto.setOperationCount(actionLogDto.getOperationCount() - 1);
actionLogDto.getLogItems().remove(itemLog);
loggingException(actionLogDto.getSyncAction(), log, itemLog, actionsLog, uid, ex);
} else {
loggingException(SynchronizationActionType.UNKNOWN, log, itemLog, actionsLog, uid, ex);
}
return true;
} finally {
config = synchronizationConfigService.save(config);
boolean existingItemLog = existItemLogInActions(actionsLog, itemLog);
actionsLog = saveActionLogs(actionsLog, log.getId());
//
if (!existingItemLog) {
addToItemLog(itemLog, MessageFormat.format("Missing action log for UID {0}!", uid));
initSyncActionLog(SynchronizationActionType.UNKNOWN, OperationResultType.ERROR, itemLog, log, actionsLog);
itemLog = syncItemLogService.save(itemLog);
}
}
}
Aggregations