use of eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto in project CzechIdMng by bcvsolutions.
the class ContractSliceSyncTest method unlinkAccountTest.
@Test
public void unlinkAccountTest() {
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);
IdmContractSliceFilter contractFilter = new IdmContractSliceFilter();
contractFilter.setProperty(IdmIdentityContract_.position.getName());
contractFilter.setValue("1");
Assert.assertEquals(0, contractSliceService.find(contractFilter, null).getTotalElements());
contractFilter.setValue("2");
Assert.assertEquals(0, contractSliceService.find(contractFilter, null).getTotalElements());
helper.startSynchronization(config);
SysSyncLogDto log = checkSyncLog(config, SynchronizationActionType.CREATE_ENTITY, 4);
Assert.assertFalse(log.isRunning());
Assert.assertFalse(log.isContainsError());
contractFilter.setValue("1");
List<IdmContractSliceDto> contractSlices = contractSliceService.find(contractFilter, null).getContent();
Assert.assertEquals(1, contractSlices.size());
// Find the account for this contract slice
IdmContractSliceDto slice = contractSlices.get(0);
AccContractSliceAccountFilter contractAccountFilter = new AccContractSliceAccountFilter();
contractAccountFilter.setSliceId(slice.getId());
contractAccountFilter.setSystemId(system.getId());
List<AccContractSliceAccountDto> contractAccounts = contractSliceAccountService.find(contractAccountFilter, null).getContent();
Assert.assertEquals(1, contractAccounts.size());
AccContractSliceAccountDto contractAccount = contractAccounts.get(0);
AccAccountDto account = accountService.get(contractAccount.getAccount());
Assert.assertNotNull(account);
// Delete log
syncLogService.delete(log);
// Change settings of sync and run
config.setLinkedAction(SynchronizationLinkedActionType.UNLINK);
config.setUnlinkedAction(SynchronizationUnlinkedActionType.IGNORE);
config.setMissingEntityAction(SynchronizationMissingEntityActionType.IGNORE);
config.setMissingAccountAction(ReconciliationMissingAccountActionType.IGNORE);
config = syncConfigService.save(config);
helper.startSynchronization(config);
log = checkSyncLog(config, SynchronizationActionType.UNLINK, 4);
Assert.assertFalse(log.isRunning());
Assert.assertFalse(log.isContainsError());
// Find the account for this contract slice ... unlink operation was executed,
// none relation can be found
contractAccountFilter = new AccContractSliceAccountFilter();
contractAccountFilter.setSliceId(slice.getId());
contractAccountFilter.setSystemId(system.getId());
contractAccounts = contractSliceAccountService.find(contractAccountFilter, null).getContent();
Assert.assertEquals(0, contractAccounts.size());
account = accountService.get(account.getId());
Assert.assertNull(account);
// Delete log
syncLogService.delete(log);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto in project CzechIdMng by bcvsolutions.
the class ContractSliceSyncTest method updateAccountTest.
@Test
public void updateAccountTest() {
SysSystemDto system = initData();
Assert.assertNotNull(system);
AbstractSysSyncConfigDto config = doCreateSyncConfig(system);
Assert.assertTrue(config instanceof SysSyncContractConfigDto);
config = syncConfigService.save(config);
helper.createIdentity(CONTRACT_OWNER_ONE);
helper.createIdentity(CONTRACT_OWNER_TWO);
helper.createIdentity(CONTRACT_LEADER_ONE);
IdmContractSliceFilter contractFilter = new IdmContractSliceFilter();
contractFilter.setProperty(IdmIdentityContract_.position.getName());
contractFilter.setValue("1");
Assert.assertEquals(0, contractSliceService.find(contractFilter, null).getTotalElements());
contractFilter.setValue("2");
Assert.assertEquals(0, contractSliceService.find(contractFilter, null).getTotalElements());
helper.startSynchronization(config);
SysSyncLogDto log = checkSyncLog(config, SynchronizationActionType.CREATE_ENTITY, 4);
Assert.assertFalse(log.isRunning());
Assert.assertFalse(log.isContainsError());
contractFilter.setValue("1");
List<IdmContractSliceDto> contractSlices = contractSliceService.find(contractFilter, null).getContent();
Assert.assertEquals(1, contractSlices.size());
// Find the account for this contract slice
IdmContractSliceDto slice = contractSlices.get(0);
AccContractSliceAccountFilter contractAccountFilter = new AccContractSliceAccountFilter();
contractAccountFilter.setSliceId(slice.getId());
contractAccountFilter.setSystemId(system.getId());
List<AccContractSliceAccountDto> contractAccounts = contractSliceAccountService.find(contractAccountFilter, null).getContent();
Assert.assertEquals(1, contractAccounts.size());
AccContractSliceAccountDto contractAccount = contractAccounts.get(0);
AccAccountDto account = accountService.get(contractAccount.getAccount());
Assert.assertNotNull(account);
// Delete log
syncLogService.delete(log);
TestContractSliceResource accountOnTargetSystem = this.getBean().findSliceOnTargetSystem("1");
Assert.assertNull(accountOnTargetSystem.getState());
// Set slice to disabled
slice.setState(ContractState.DISABLED);
// Change settings of sync and run
config.setLinkedAction(SynchronizationLinkedActionType.UPDATE_ACCOUNT);
config.setUnlinkedAction(SynchronizationUnlinkedActionType.IGNORE);
config.setMissingEntityAction(SynchronizationMissingEntityActionType.IGNORE);
config.setMissingAccountAction(ReconciliationMissingAccountActionType.IGNORE);
config = syncConfigService.save(config);
helper.startSynchronization(config);
log = checkSyncLog(config, SynchronizationActionType.UPDATE_ACCOUNT, 4);
Assert.assertFalse(log.isRunning());
Assert.assertFalse(log.isContainsError());
// Sync of slice does not supports provisioning now (account was not changed)!
accountOnTargetSystem = this.getBean().findSliceOnTargetSystem("1");
Assert.assertEquals(null, accountOnTargetSystem.getState());
// Delete log
syncLogService.delete(log);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto in project CzechIdMng by bcvsolutions.
the class ContractSliceSyncTest method setDirtyStateAndCheckIt.
@Test
public void setDirtyStateAndCheckIt() {
// create tree type and node, tree node is used as position in contrac slice synchronization
IdmTreeTypeDto treeType = this.getHelper().createTreeType();
IdmTreeNodeDto treeNode = this.getHelper().createTreeNode(treeType, null);
// create two roles, one role is used as automatic role by organization structure
// second role is used as manually added
IdmRoleDto roleOne = this.getHelper().createRole();
IdmRoleDto roleTwo = this.getHelper().createRole();
this.getHelper().createAutomaticRole(roleOne, treeNode);
// init system
SysSystemDto system = initData();
// set default tree type for synchronization
SysSyncContractConfigDto config = (SysSyncContractConfigDto) doCreateSyncConfig(system);
config.setDefaultTreeType(treeType.getId());
syncConfigService.save(config);
IdmIdentityDto identity = helper.createIdentity();
// for sure remove all contracts
contractService.findAllByIdentity(identity.getId()).forEach(contract -> {
contractService.delete(contract);
});
// check current delete audits record for identity (and their related entities)
IdmAuditFilter filter = new IdmAuditFilter();
filter.setOwnerId(identity.getId().toString());
filter.setModification("DELETE");
List<IdmAuditDto> audits = auditService.find(filter, null).getContent();
assertEquals(0, audits.size());
// check current slices
IdmContractSliceFilter contractSliceFilter = new IdmContractSliceFilter();
contractSliceFilter.setIdentity(identity.getId());
List<IdmContractSliceDto> slices = contractSliceService.find(contractSliceFilter, null).getContent();
assertEquals(0, slices.size());
// check current contracts
List<IdmIdentityContractDto> allByIdentity = contractService.findAllByIdentity(identity.getId());
assertEquals(0, allByIdentity.size());
// delete all data in resource
this.getBean().deleteAllResourceData();
// create step one data, please see inside method
this.getBean().createTestDataStepOne(identity.getUsername(), treeNode.getCode());
// start synchronization
helper.startSynchronization(config);
SysSyncLogDto log = checkSyncLog(config, SynchronizationActionType.CREATE_ENTITY, 1);
Assert.assertFalse(log.isRunning());
Assert.assertFalse(log.isContainsError());
// after first synchronization exists one contract
allByIdentity = contractService.findAllByIdentity(identity.getId());
assertEquals(1, allByIdentity.size());
// after first synchronization exists one slice
slices = contractSliceService.find(contractSliceFilter, null).getContent();
assertEquals(1, slices.size());
// after first synchronization exists one identity role - automatic role
List<IdmIdentityRoleDto> identityRoles = identityRoleService.findAllByIdentity(identity.getId());
assertEquals(1, identityRoles.size());
IdmIdentityRoleDto identityRoleDto = identityRoles.get(0);
// manually create identity account for check if identity account will be changed or deleted after second synchronization
// this state create two audit records for the identity account
AccIdentityAccountDto identityAccount = helper.createIdentityAccount(system, identity);
identityAccount.setIdentityRole(identityRoleDto.getId());
identityAccount = identityAccountService.save(identityAccount);
// add manually role
IdmIdentityContractDto identityContractDto = allByIdentity.get(0);
this.getHelper().createIdentityRole(identityContractDto, roleTwo);
// check current identity roles - one is automatic, second is manually added
identityRoles = identityRoleService.findAllByIdentity(identity.getId());
assertEquals(2, identityRoles.size());
// prepare data for second step
this.getBean().createTestDataStepTwo(identity.getUsername(), treeNode.getCode());
helper.startSynchronization(config);
Assert.assertFalse(log.isRunning());
Assert.assertFalse(log.isContainsError());
// after second synchronization still exists one contract
allByIdentity = contractService.findAllByIdentity(identity.getId());
assertEquals(1, allByIdentity.size());
// after second synchronization exists two slices
slices = contractSliceService.find(contractSliceFilter, null).getContent();
assertEquals(2, slices.size());
// after second synchronization must also exists both roles
identityRoles = identityRoleService.findAllByIdentity(identity.getId());
assertEquals(2, identityRoles.size());
// check delete operation for identity and their related entities
filter = new IdmAuditFilter();
filter.setOwnerId(identity.getId().toString());
filter.setModification("DELETE");
audits = auditService.find(filter, null).getContent();
assertEquals(0, audits.size());
// check audit for identity roles
for (IdmIdentityRoleDto identityRole : identityRoles) {
filter = new IdmAuditFilter();
filter.setEntityId(identityRole.getId());
List<IdmAuditDto> auditsForIdentityRole = auditService.find(filter, null).getContent();
if (identityRole.getAutomaticRole() == null) {
// manually added role, just create
assertEquals(1, auditsForIdentityRole.size());
} else {
// automatic role change validity
assertEquals(2, auditsForIdentityRole.size());
}
}
// Check audit records for identity account, exists three record, because helper
// create one and second create save with change identity role and third is
// delete of this identity-account (role does not mapping the system)
filter = new IdmAuditFilter();
filter.setEntityId(identityAccount.getId());
List<IdmAuditDto> auditsForIdentityAccount = auditService.find(filter, null).getContent();
assertEquals(3, auditsForIdentityAccount.size());
// some tests expect data as contract slice with id 1. Just for sure we clear test slices
slices = contractSliceService.find(contractSliceFilter, null).getContent();
slices.forEach(slice -> {
contractSliceService.delete(slice);
});
identityService.delete(identity);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto in project CzechIdMng by bcvsolutions.
the class ContractSliceSyncTest method addTwoNewAndDeleteFirstContractSlice.
@Test
public void addTwoNewAndDeleteFirstContractSlice() {
// init system
SysSystemDto system = initData();
this.getBean().deleteAllResourceData();
IdmIdentityDto identity = helper.createIdentity();
List<IdmIdentityContractDto> contracts = contractService.findAllByIdentity(identity.getId());
assertEquals(1, contracts.size());
contractService.delete(contracts.get(0));
// first valid slice
this.getBean().createSlice("1", identity.getUsername(), null, null, null, null, null, LocalDate.now().minusDays(20), null, LocalDate.now().minusDays(20), "ONE");
SysSyncContractConfigDto config = (SysSyncContractConfigDto) doCreateSyncConfig(system);
config.setStartOfHrProcesses(true);
config.setMissingAccountAction(ReconciliationMissingAccountActionType.DELETE_ENTITY);
config = (SysSyncContractConfigDto) syncConfigService.save(config);
// start sync
helper.startSynchronization(config);
IdmContractSliceFilter filter = new IdmContractSliceFilter();
filter.setIdentity(identity.getId());
List<IdmContractSliceDto> slices = contractSliceService.find(filter, null).getContent();
assertEquals(1, slices.size());
IdmContractSliceDto sliceDto = slices.get(0);
assertEquals(LocalDate.now().minusDays(20), sliceDto.getValidFrom());
assertEquals(null, sliceDto.getValidTill());
// create invalid slice
this.getBean().createSlice("2", identity.getUsername(), null, null, null, null, null, LocalDate.now().minusDays(20), LocalDate.now().minusDays(10), LocalDate.now().minusDays(10), "ONE");
// create valid slice
this.getBean().createSlice("3", identity.getUsername(), null, null, null, null, null, LocalDate.now().minusDays(10), null, LocalDate.now().minusDays(9), "ONE");
// delete first
this.getBean().deleteSlice("1");
// start sync
helper.startSynchronization(config);
slices = contractSliceService.find(filter, null).getContent();
assertEquals(2, slices.size());
for (IdmContractSliceDto slice : slices) {
if ("2".equals(slice.getDescription())) {
assertEquals(LocalDate.now().minusDays(10), slice.getValidFrom());
assertEquals(LocalDate.now().minusDays(9).minusDays(1), slice.getValidTill());
assertNotNull(slice.getParentContract());
} else if ("3".equals(slice.getDescription())) {
assertEquals(LocalDate.now().minusDays(9), slice.getValidFrom());
assertEquals(null, slice.getValidTill());
assertTrue(slice.isUsingAsContract());
assertNotNull(slice.getParentContract());
} else {
fail("Slice with bad id!");
}
}
contracts = contractService.findAllByIdentity(identity.getId());
assertEquals(1, contracts.size());
IdmIdentityContractDto contract = contracts.get(0);
assertEquals(LocalDate.now().minusDays(10), contract.getValidFrom());
assertEquals(null, contract.getValidTill());
// some tests expect data as contract slice with id 1. Just for sure we clear test slices
slices = contractSliceService.find(filter, null).getContent();
slices.forEach(slice -> {
contractSliceService.delete(slice);
});
identityService.delete(identity);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto in project CzechIdMng by bcvsolutions.
the class ContractSliceDeleteProcessor method process.
@Override
public EventResult<IdmContractSliceDto> process(EntityEvent<IdmContractSliceDto> event) {
IdmContractSliceDto slice = event.getContent();
// delete. Deleting is provided by ClearDirtyStateForContractSliceTaskExecutor!
if (this.getBooleanProperty(IdmContractSliceService.SET_DIRTY_STATE_CONTRACT_SLICE, event.getProperties())) {
// If is set slice as using as contract, set this flag to false
if (slice.isUsingAsContract()) {
slice.setUsingAsContract(false);
service.publish(new ContractSliceEvent(ContractSliceEventType.UPDATE, slice, ImmutableMap.of(IdmContractSliceService.SKIP_RECALCULATE_CONTRACT_SLICE, Boolean.TRUE)));
}
Map<String, Serializable> properties = new HashMap<>(event.getProperties());
// Creates new dirty states, dirty states must be process by executor
createDeleteDirtyState(slice, properties);
LOG.info("Property SET_DIRTY_STATE_CONTRACT_SLICE is true -> Slice [{}] is not deleted but only marked as DIRTY." + " Deleting will be processed in ClearDirtyStateForContractSliceTaskExecutor!", slice.toString());
return new DefaultEventResult<>(event, this);
}
// delete dirty states for contract slice
findAllDirtyStatesForSlices(slice.getId()).forEach(dirtyState -> {
entityStateManager.deleteState(dirtyState);
});
// delete contract slice guarantees
IdmContractSliceGuaranteeFilter filter = new IdmContractSliceGuaranteeFilter();
filter.setContractSliceId(slice.getId());
contractGuaranteeService.find(filter, null).forEach(guarantee -> {
contractGuaranteeService.delete(guarantee);
});
UUID contractId = slice.getParentContract();
if (contractId != null) {
List<IdmContractSliceDto> slices = contractSliceManager.findAllSlices(contractId);
if (slices.size() == 1) {
// Internal delete of slice
service.deleteInternal(slice);
// This slice is last for parent contract. We will also deleted the parent
// contract;
contractService.deleteById(contractId);
return new DefaultEventResult<>(event, this);
}
// Find next slice
IdmContractSliceDto nextSlice = contractSliceManager.findNextSlice(slice, slices);
// Internal delete of slice
service.deleteInternal(slice);
// If exists next slice, then update valid till on previous slice
if (nextSlice != null) {
contractSliceManager.updateValidTillOnPreviousSlice(nextSlice, contractSliceManager.findAllSlices(contractId));
} else {
// If next slice doesn't exists, then we need to find previous slice (last after deleting) and set valid till to infinity.
IdmContractSliceDto previousSlice = contractSliceManager.findPreviousSlice(slice, contractSliceManager.findAllSlices(contractId));
if (previousSlice != null) {
// Previous slice will be valid till infinity
previousSlice.setValidTill(null);
contractSliceService.publish(new ContractSliceEvent(ContractSliceEventType.UPDATE, previousSlice, ImmutableMap.of(IdmContractSliceService.SKIP_RECALCULATE_CONTRACT_SLICE, Boolean.TRUE)));
}
}
IdmContractSliceDto validSlice = contractSliceManager.findValidSlice(contractId);
if (validSlice != null) {
// Set next slice as is currently using in contract
contractSliceManager.setSliceAsCurrentlyUsing(validSlice, event.getProperties());
}
} else {
service.deleteInternal(slice);
}
return new DefaultEventResult<>(event, this);
}
Aggregations