use of eu.bcvsolutions.idm.acc.dto.SysSyncLogDto 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.SysSyncLogDto in project CzechIdMng by bcvsolutions.
the class IdentitySyncTest method testSynchronizationCache.
@Test
public void testSynchronizationCache() {
SysSystemDto system = initData();
SysSyncIdentityConfigDto config = doCreateSyncConfig(system);
IdmRoleDto defaultRole = helper.createRole();
// Set default role to sync configuration
config.setDefaultRole(defaultRole.getId());
config = (SysSyncIdentityConfigDto) syncConfigService.save(config);
this.getBean().deleteAllResourceData();
String testLastName = "test-last-name-same-" + System.currentTimeMillis();
String testFirstName = "test-first-name";
String userOne = "test-1-" + System.currentTimeMillis();
this.getBean().setTestData(userOne, testFirstName, testLastName);
String userTwo = "test-2-" + System.currentTimeMillis();
this.getBean().setTestData(userTwo, testFirstName, testLastName);
SysSystemMappingFilter mappingFilter = new SysSystemMappingFilter();
mappingFilter.setEntityType(SystemEntityType.IDENTITY);
mappingFilter.setSystemId(system.getId());
mappingFilter.setOperationType(SystemOperationType.SYNCHRONIZATION);
List<SysSystemMappingDto> mappings = systemMappingService.find(mappingFilter, null).getContent();
Assert.assertEquals(1, mappings.size());
SysSystemMappingDto defaultMapping = mappings.get(0);
SysSystemAttributeMappingFilter attributeMappingFilter = new SysSystemAttributeMappingFilter();
attributeMappingFilter.setSystemMappingId(defaultMapping.getId());
List<SysSystemAttributeMappingDto> attributes = schemaAttributeMappingService.find(attributeMappingFilter, null).getContent();
SysSystemAttributeMappingDto firstNameAttribute = attributes.stream().filter(attribute -> {
return attribute.getIdmPropertyName().equals(IdmIdentity_.firstName.getName());
}).findFirst().orElse(null);
Assert.assertNotNull(firstNameAttribute);
StringBuilder scriptGenerateUuid = new StringBuilder();
scriptGenerateUuid.append("import java.util.UUID;");
scriptGenerateUuid.append(System.lineSeparator());
scriptGenerateUuid.append("return UUID.randomUUID();");
String scriptName = "generateUuid";
IdmScriptDto scriptUuid = new IdmScriptDto();
scriptUuid.setCategory(IdmScriptCategory.TRANSFORM_FROM);
scriptUuid.setCode(scriptName);
scriptUuid.setName(scriptName);
scriptUuid.setScript(scriptGenerateUuid.toString());
scriptUuid = scriptService.save(scriptUuid);
IdmScriptAuthorityDto scriptAuth = new IdmScriptAuthorityDto();
scriptAuth.setClassName("java.util.UUID");
scriptAuth.setType(ScriptAuthorityType.CLASS_NAME);
scriptAuth.setScript(scriptUuid.getId());
scriptAuth = scriptAuthrotityService.save(scriptAuth);
// we must call script
StringBuilder transformationScript = new StringBuilder();
transformationScript.append("return scriptEvaluator.evaluate(");
transformationScript.append(System.lineSeparator());
transformationScript.append("scriptEvaluator.newBuilder()");
transformationScript.append(System.lineSeparator());
transformationScript.append(".setScriptCode('" + scriptName + "')");
transformationScript.append(System.lineSeparator());
transformationScript.append(".build());");
transformationScript.append(System.lineSeparator());
firstNameAttribute.setTransformFromResourceScript(transformationScript.toString());
firstNameAttribute.setCached(true);
firstNameAttribute = schemaAttributeMappingService.save(firstNameAttribute);
synchornizationService.setSynchronizationConfigId(config.getId());
synchornizationService.process();
SysSyncLogDto log = checkSyncLog(config, SynchronizationActionType.CREATE_ENTITY, 2, OperationResultType.WARNING);
Assert.assertFalse(log.isRunning());
Assert.assertFalse(log.isContainsError());
IdmIdentityFilter filter = new IdmIdentityFilter();
filter.setLastName(testLastName);
List<IdmIdentityDto> identities = identityService.find(filter, null).getContent();
assertEquals(2, identities.size());
//
IdmIdentityDto identityOne = identities.get(0);
IdmIdentityDto identityTwo = identities.get(1);
//
assertNotEquals(identityOne.getFirstName(), identityTwo.getFirstName());
}
use of eu.bcvsolutions.idm.acc.dto.SysSyncLogDto in project CzechIdMng by bcvsolutions.
the class IdentitySyncTest method updateIdentityWithInvalidContractTest.
@Test
public void updateIdentityWithInvalidContractTest() {
SysSystemDto system = initData();
Assert.assertNotNull(system);
SysSyncIdentityConfigDto config = doCreateSyncConfig(system);
IdmRoleDto defaultRole = helper.createRole();
// Set default role to sync configuration
config.setDefaultRole(defaultRole.getId());
config = (SysSyncIdentityConfigDto) syncConfigService.save(config);
IdmIdentityDto identityOne = helper.createIdentity(IDENTITY_ONE);
IdmIdentityContractDto primeContract = contractService.getPrimeContract(identityOne.getId());
Assert.assertNotNull(primeContract);
primeContract.setValidTill(LocalDate.now().minusDays(10));
primeContract = contractService.save(primeContract);
IdmIdentityFilter identityFilter = new IdmIdentityFilter();
identityFilter.setUsername(IDENTITY_ONE);
synchornizationService.setSynchronizationConfigId(config.getId());
synchornizationService.process();
SysSyncLogDto log = checkSyncLog(config, SynchronizationActionType.LINK, 1, OperationResultType.WARNING);
Assert.assertFalse(log.isRunning());
Assert.assertFalse(log.isContainsError());
List<IdmIdentityRoleDto> roles = identityRoleService.findAllByIdentity(identityOne.getId());
Assert.assertEquals(0, roles.size());
// Delete log
syncLogService.delete(log);
}
use of eu.bcvsolutions.idm.acc.dto.SysSyncLogDto in project CzechIdMng by bcvsolutions.
the class IdentitySyncTest method testDisableAutomaticRoleDuringSynchronization.
@Test
public void testDisableAutomaticRoleDuringSynchronization() {
// default initialization of system and all necessary things
SysSystemDto system = initData();
SysSyncIdentityConfigDto config = doCreateSyncConfig(system);
IdmRoleDto defaultRole = helper.createRole();
// Set default role to sync configuration
config.setDefaultRole(defaultRole.getId());
// we want start recalculation after synchronization
config.setStartAutoRoleRec(false);
config = (SysSyncIdentityConfigDto) syncConfigService.save(config);
this.getBean().deleteAllResourceData();
String testLastName = "test-last-name-same-" + System.currentTimeMillis();
String testFirstName = "test-first-name";
String user1 = "test-1-" + System.currentTimeMillis();
this.getBean().setTestData(user1, testFirstName, testLastName);
String user2 = "test-2-" + System.currentTimeMillis();
this.getBean().setTestData(user2, testFirstName, testLastName);
String user3 = "test-3-" + System.currentTimeMillis();
this.getBean().setTestData(user3, testFirstName, testLastName);
IdmRoleDto role1 = helper.createRole();
IdmAutomaticRoleAttributeDto automaticRole = helper.createAutomaticRole(role1.getId());
helper.createAutomaticRoleRule(automaticRole.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.IDENTITY, IdmIdentity_.username.getName(), null, user1);
synchornizationService.setSynchronizationConfigId(config.getId());
synchornizationService.process();
SysSyncLogDto log = checkSyncLog(config, SynchronizationActionType.CREATE_ENTITY, 3, OperationResultType.WARNING);
Assert.assertFalse(log.isRunning());
Assert.assertFalse(log.isContainsError());
IdmIdentityDto identity1 = identityService.getByUsername(user1);
IdmIdentityDto identity2 = identityService.getByUsername(user2);
IdmIdentityDto identity3 = identityService.getByUsername(user3);
// we must change username, after create contract is also save identity (change state)
identity1.setUsername(user1 + System.currentTimeMillis());
identity1 = identityService.save(identity1);
helper.createIdentityContact(identity1);
helper.createIdentityContact(identity2);
helper.createIdentityContact(identity3);
List<IdmIdentityRoleDto> identityRoles1 = identityRoleService.findAllByIdentity(identity1.getId());
List<IdmIdentityRoleDto> identityRoles2 = identityRoleService.findAllByIdentity(identity2.getId());
List<IdmIdentityRoleDto> identityRoles3 = identityRoleService.findAllByIdentity(identity3.getId());
assertEquals(0, identityRoles1.size());
assertEquals(0, identityRoles2.size());
assertEquals(0, identityRoles3.size());
// enable test processor
testIdentityProcessor.enable();
synchornizationService.setSynchronizationConfigId(config.getId());
synchornizationService.process();
identityRoles1 = identityRoleService.findAllByIdentity(identity1.getId());
identityRoles2 = identityRoleService.findAllByIdentity(identity2.getId());
identityRoles3 = identityRoleService.findAllByIdentity(identity3.getId());
assertEquals(0, identityRoles1.size());
assertEquals(0, identityRoles2.size());
assertEquals(0, identityRoles3.size());
// synchronization immediately recalculate is disabled
int size = testIdentityProcessor.getRolesByUsername(user1).size();
assertEquals(0, size);
size = testIdentityProcessor.getRolesByUsername(user2).size();
assertEquals(0, size);
size = testIdentityProcessor.getRolesByUsername(user3).size();
assertEquals(0, size);
}
use of eu.bcvsolutions.idm.acc.dto.SysSyncLogDto in project CzechIdMng by bcvsolutions.
the class IdentitySyncTest method testLinkAndUpdateIdentity.
@Test
public void testLinkAndUpdateIdentity() {
SysSystemDto system = initData();
Assert.assertNotNull(system);
SysSyncIdentityConfigDto config = doCreateSyncConfig(system);
config.setUnlinkedAction(SynchronizationUnlinkedActionType.LINK_AND_UPDATE_ENTITY);
config = (SysSyncIdentityConfigDto) syncConfigService.save(config);
this.getBean().deleteAllResourceData();
String testLastName = "test-last-name-same-" + System.currentTimeMillis();
String testFirstName = "test-first-name-";
String user1 = "test-1-" + System.currentTimeMillis();
IdmIdentityDto identity1 = helper.createIdentity(user1);
this.getBean().setTestData(user1, testFirstName + 1, testLastName);
String user2 = "test-2-" + System.currentTimeMillis();
IdmIdentityDto identity2 = helper.createIdentity(user2);
this.getBean().setTestData(user2, testFirstName + 2, testLastName);
String user3 = "test-3-" + System.currentTimeMillis();
IdmIdentityDto identity3 = helper.createIdentity(user3);
this.getBean().setTestData(user3, testFirstName + 3, testLastName);
assertNotEquals(testFirstName + 1, identity1.getFirstName());
assertNotEquals(testFirstName + 2, identity2.getFirstName());
assertNotEquals(testFirstName + 3, identity3.getFirstName());
assertNotEquals(testLastName, identity1.getLastName());
assertNotEquals(testLastName, identity2.getLastName());
assertNotEquals(testLastName, identity3.getLastName());
testIdentityProcessor.enable();
synchornizationService.setSynchronizationConfigId(config.getId());
synchornizationService.process();
SysSyncLogDto log = checkSyncLog(config, SynchronizationActionType.LINK_AND_UPDATE_ENTITY, 3, OperationResultType.SUCCESS);
Assert.assertFalse(log.isRunning());
Assert.assertFalse(log.isContainsError());
IdmIdentityDto updatedIdentity1 = identityService.getByUsername(user1);
IdmIdentityDto updatedIdentity2 = identityService.getByUsername(user2);
IdmIdentityDto updatedIdentity3 = identityService.getByUsername(user3);
assertNotEquals(updatedIdentity1.getFirstName(), identity1.getFirstName());
assertNotEquals(updatedIdentity2.getFirstName(), identity2.getFirstName());
assertNotEquals(updatedIdentity3.getFirstName(), identity3.getFirstName());
assertNotEquals(updatedIdentity1.getLastName(), identity1.getLastName());
assertNotEquals(updatedIdentity2.getLastName(), identity2.getLastName());
assertNotEquals(updatedIdentity3.getLastName(), identity3.getLastName());
assertNotEquals(updatedIdentity1.getModified(), identity1.getModified());
assertNotEquals(updatedIdentity2.getModified(), identity2.getModified());
assertNotEquals(updatedIdentity3.getModified(), identity3.getModified());
assertEquals(testFirstName + 1, updatedIdentity1.getFirstName());
assertEquals(testFirstName + 2, updatedIdentity2.getFirstName());
assertEquals(testFirstName + 3, updatedIdentity3.getFirstName());
assertEquals(testLastName, updatedIdentity1.getLastName());
assertEquals(testLastName, updatedIdentity2.getLastName());
assertEquals(testLastName, updatedIdentity3.getLastName());
}
Aggregations