use of eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto in project CzechIdMng by bcvsolutions.
the class IdentityContractSyncTest method testContractPositions.
@Test
public void testContractPositions() {
SysSystemDto system = initData();
Assert.assertNotNull(system);
AbstractSysSyncConfigDto config = doCreateSyncConfig(system);
Assert.assertTrue(config instanceof SysSyncContractConfigDto);
helper.createIdentity(CONTRACT_OWNER_THREE);
// 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());
// Set work positions to resources
this.getBean().initContractPositionTest();
// Start sync again (we want to see some work positions)
helper.startSynchronization(config);
SysSyncLogDto log = checkSyncLog(config, SynchronizationActionType.CREATE_ENTITY, 1);
Assert.assertFalse(log.isRunning());
Assert.assertFalse(log.isContainsError());
// For contract One must be found workposition (one)
contractFilter.setValue("1");
IdmIdentityContractDto contractOne = contractService.find(contractFilter, null).getContent().get(0);
Assert.assertNotNull(contractOne);
//
IdmContractPositionFilter positionFitler = new IdmContractPositionFilter();
positionFitler.setIdentityContractId(contractOne.getId());
List<IdmContractPositionDto> positions = contractPositionService.find(positionFitler, null).getContent();
Assert.assertEquals(1, positions.size());
Assert.assertEquals("one", DtoUtils.getEmbedded(positions.get(0), IdmContractPosition_.workPosition, IdmTreeNodeDto.class).getCode());
// Delete log
syncLogService.delete(log);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto in project CzechIdMng by bcvsolutions.
the class IdentityContractSyncTest method testDifferentSyncChangePositions.
@Test
public void testDifferentSyncChangePositions() {
SysSystemDto system = initData();
Assert.assertNotNull(system);
AbstractSysSyncConfigDto config = doCreateSyncConfig(system);
Assert.assertTrue(config instanceof SysSyncContractConfigDto);
helper.createIdentity(CONTRACT_OWNER_THREE);
// 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());
// Set work positions to resources
this.getBean().initContractPositionTest();
helper.startSynchronization(config);
SysSyncLogDto log = checkSyncLog(config, SynchronizationActionType.CREATE_ENTITY, 1);
Assert.assertFalse(log.isRunning());
Assert.assertFalse(log.isContainsError());
// For contract One must be found workposition (one)
contractFilter.setValue("1");
IdmIdentityContractDto contractOne = contractService.find(contractFilter, null).getContent().get(0);
Assert.assertNotNull(contractOne);
IdmContractPositionFilter positionFitler = new IdmContractPositionFilter();
positionFitler.setIdentityContractId(contractOne.getId());
List<IdmContractPositionDto> positions = contractPositionService.find(positionFitler, null).getContent();
Assert.assertEquals(1, positions.size());
Assert.assertEquals("one", DtoUtils.getEmbedded(positions.get(0), IdmContractPosition_.workPosition, IdmTreeNodeDto.class).getCode());
// Enable different sync.
config.setDifferentialSync(true);
config = syncConfigService.save(config);
Assert.assertTrue(config.isDifferentialSync());
// Start sync with enable different sync - no change was made on so only ignore update should be made.
helper.startSynchronization(config);
log = helper.checkSyncLog(config, SynchronizationActionType.UPDATE_ENTITY, 1, OperationResultType.IGNORE);
Assert.assertFalse(log.isRunning());
Assert.assertFalse(log.isContainsError());
// Delete position name
contractPositionService.delete(positions.get(0));
// Start sync with enable different sync - position name was changed, standard update should be made.
helper.startSynchronization(config);
log = helper.checkSyncLog(config, SynchronizationActionType.UPDATE_ENTITY, 1, OperationResultType.SUCCESS);
Assert.assertFalse(log.isRunning());
Assert.assertFalse(log.isContainsError());
// For contract One must be found workposition (one)
contractFilter.setValue("1");
contractOne = contractService.find(contractFilter, null).getContent().get(0);
Assert.assertNotNull(contractOne);
positionFitler = new IdmContractPositionFilter();
positionFitler.setIdentityContractId(contractOne.getId());
positions = contractPositionService.find(positionFitler, null).getContent();
Assert.assertEquals(1, positions.size());
Assert.assertEquals("one", DtoUtils.getEmbedded(positions.get(0), IdmContractPosition_.workPosition, IdmTreeNodeDto.class).getCode());
// Delete log
syncLogService.delete(log);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto 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
helper.startSynchronization(config);
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)
helper.startSynchronization(config);
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);
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.core.api.dto.IdmTreeTypeDto in project CzechIdMng by bcvsolutions.
the class InitDemoDataProcessor method process.
@Override
public EventResult<ModuleDescriptorDto> process(EntityEvent<ModuleDescriptorDto> event) {
LOG.info("Creating demo data.");
//
// form attributes at first => identity will be created with default values
createFormAttributes();
//
// get default tree type and root (by init data defensively)
IdmTreeTypeDto treeType = treeTypeService.getByCode(InitApplicationData.DEFAULT_TREE_TYPE);
Page<IdmTreeNodeDto> rootsList = treeNodeService.findRoots(treeType.getId(), PageRequest.of(0, 1));
IdmTreeNodeDto rootOrganization = null;
if (!rootsList.getContent().isEmpty()) {
rootOrganization = rootsList.getContent().get(0);
} else {
rootOrganization = new IdmTreeNodeDto();
rootOrganization.setCode("root");
rootOrganization.setName("Organization");
rootOrganization.setTreeType(treeTypeService.getByCode(InitOrganizationProcessor.DEFAULT_TREE_TYPE).getId());
rootOrganization = treeNodeService.save(rootOrganization);
}
//
IdmRoleDto role2 = createRequestableCustomRole();
//
IdmRoleDto userManagerRole = roleConfiguration.getUserManagerRole();
if (userManagerRole == null) {
userManagerRole = new IdmRoleDto();
userManagerRole.setCode("userManagerRole");
userManagerRole.setCanBeRequested(true);
userManagerRole = roleService.save(userManagerRole);
//
LOG.info("Role created [id: {}]", userManagerRole.getId());
}
//
IdmIdentityDto identity = new IdmIdentityDto();
identity.setUsername("john");
identity.setPassword(new GuardedString("john"));
identity.setFirstName("John");
identity.setLastName("Doe");
identity.setEmail("john.doe@bcvsolutions.eu");
identity = identityService.save(identity);
List<IdmFormValueDto> values = new ArrayList<>();
IdmFormValueDto phoneValue = new IdmFormValueDto();
phoneValue.setFormAttribute(formService.getAttribute(identity.getClass(), FORM_ATTRIBUTE_PHONE).getId());
phoneValue.setStringValue("12345679");
values.add(phoneValue);
formService.saveValues(identity.getId(), IdmIdentity.class, null, values);
LOG.info("Identity created [id: {}]", identity.getId());
//
// create prime contract
IdmIdentityContractDto identityContract = identityContractService.getPrimeContract(identity.getId());
if (identityContract == null) {
identityContract = identityContractService.prepareMainContract(identity.getId());
identityContract = identityContractService.save(identityContract);
}
//
IdmIdentityRoleDto identityRole = new IdmIdentityRoleDto();
identityRole.setIdentityContract(identityContract.getId());
identityRole.setRole(role2.getId());
identityRole = identityRoleService.save(identityRole);
//
IdmIdentityDto identity2 = new IdmIdentityDto();
identity2.setUsername("jane");
identity2.setFirstName("Jane");
identity2.setPassword(new GuardedString("jane"));
identity2.setLastName("Doe");
identity2.setEmail("jane.doe@bcvsolutions.eu");
identity2 = identityService.save(identity2);
LOG.info("Identity created [id: {}]", identity2.getId());
//
IdmIdentityDto identity3 = new IdmIdentityDto();
identity3.setUsername("novak");
identity3.setFirstName("Jan");
identity3.setPassword(new GuardedString("novak"));
identity3.setLastName("Novák");
identity3.setEmail("jan.novak@bcvsolutions.eu");
identity3 = identityService.save(identity3);
LOG.info("Identity created [id: {}]", identity3.getId());
//
IdmTreeNodeDto organization1 = new IdmTreeNodeDto();
organization1.setCode("one");
organization1.setName("Organization One");
organization1.setParent(rootOrganization.getId());
organization1.setTreeType(treeType.getId());
organization1 = treeNodeService.save(organization1);
//
IdmTreeNodeDto organization2 = new IdmTreeNodeDto();
organization2.setCode("two");
organization2.setName("Organization Two");
organization2.setParent(rootOrganization.getId());
organization2.setTreeType(treeType.getId());
organization2 = treeNodeService.save(organization2);
//
// form projection for externe user
IdmFormProjectionDto externeProjection = new IdmFormProjectionDto();
externeProjection.setOwnerType(lookupService.getOwnerType(IdmIdentity.class));
externeProjection.setCode("identity-externe");
externeProjection.setRoute(IdentityFormProjectionRoute.PROJECTION_NAME);
try {
// TODO: better setter
externeProjection.setBasicFields(mapper.writeValueAsString(Lists.newArrayList(IdmIdentity_.username.getName(), IdmIdentity_.firstName.getName(), IdmIdentity_.lastName.getName())));
} catch (Exception ex) {
LOG.warn("Demo form proction will show all basic attributes.", ex);
}
// not available now in product projection
externeProjection.getProperties().put(IdentityFormProjectionRoute.PARAMETER_LOAD_ASSIGNED_ROLES, false);
externeProjection = formProjectionService.save(externeProjection);
IdmIdentityDto externeIdentity = new IdmIdentityDto();
externeIdentity.setUsername("externeUser");
externeIdentity.setFirstName("František");
externeIdentity.setPassword(new GuardedString("externeUser"));
externeIdentity.setLastName("Nový");
externeIdentity.setEmail("frantisek.novy@bcvsolutions.eu");
externeIdentity.setFormProjection(externeProjection.getId());
externeIdentity = identityService.save(externeIdentity);
LOG.info("Externe identity created [id: {}]", externeIdentity.getId());
//
// helpdesk
IdmRoleDto helpdeskRole = roleConfiguration.getHelpdeskRole();
if (helpdeskRole != null) {
identity = new IdmIdentityDto();
identity.setUsername("helpdesk");
identity.setPassword(new GuardedString("helpdesk"));
identity.setFirstName("Helpdesk");
identity.setLastName("User");
identity.setEmail("hepldesk@bcvsolutions.eu");
identity.setDescription("Helpdesk - can read other users and change passwords.");
identity = identityService.save(identity);
// create prime contract
identityContract = identityContractService.getPrimeContract(identity.getId());
if (identityContract == null) {
identityContract = identityContractService.prepareMainContract(identity.getId());
identityContract = identityContractService.save(identityContract);
}
//
identityRole = new IdmIdentityRoleDto();
identityRole.setIdentityContract(identityContract.getId());
identityRole.setRole(helpdeskRole.getId());
identityRole = identityRoleService.save(identityRole);
}
//
// user manager - role created defensively above
identity = new IdmIdentityDto();
identity.setUsername("manager");
identity.setPassword(new GuardedString("manager"));
identity.setFirstName("Manager");
identity.setLastName("User");
identity.setEmail("manager@bcvsolutions.eu");
identity.setDescription("Manager with subordinates (externeUser)");
identity = identityService.save(identity);
// create prime contract
identityContract = identityContractService.getPrimeContract(identity.getId());
if (identityContract == null) {
identityContract = identityContractService.prepareMainContract(identity.getId());
identityContract = identityContractService.save(identityContract);
}
//
identityRole = new IdmIdentityRoleDto();
identityRole.setIdentityContract(identityContract.getId());
identityRole.setRole(userManagerRole.getId());
identityRole = identityRoleService.save(identityRole);
//
identityContract = identityContractService.getPrimeContract(externeIdentity.getId());
if (identityContract == null) {
identityContract = identityContractService.prepareMainContract(identity.getId());
identityContract.setExterne(true);
identityContract = identityContractService.save(identityContract);
} else {
identityContract.setExterne(true);
identityContract = identityContractService.save(identityContract);
}
// externe - set manager
IdmContractGuaranteeDto guarantee = new IdmContractGuaranteeDto();
guarantee.setIdentityContract(identityContract.getId());
guarantee.setGuarantee(identity.getId());
contractGuaranteeService.save(guarantee);
//
// role manager
IdmRoleDto roleManagerRole = roleConfiguration.getRoleManagerRole();
if (roleManagerRole != null) {
identity = new IdmIdentityDto();
identity.setUsername("roleManager");
identity.setPassword(new GuardedString("roleManager"));
identity.setFirstName("Role");
identity.setLastName("Manager");
identity.setEmail("role.manager@bcvsolutions.eu");
identity.setDescription("Role manager - can edit managed roles.");
identity = identityService.save(identity);
// create prime contract
identityContract = identityContractService.getPrimeContract(identity.getId());
if (identityContract == null) {
identityContract = identityContractService.prepareMainContract(identity.getId());
identityContract = identityContractService.save(identityContract);
}
//
identityRole = new IdmIdentityRoleDto();
identityRole.setIdentityContract(identityContract.getId());
identityRole.setRole(roleManagerRole.getId());
identityRole = identityRoleService.save(identityRole);
}
//
LOG.info("Demo data was created.");
//
configurationService.setBooleanValue(PARAMETER_DEMO_DATA_CREATED, true);
//
return new DefaultEventResult<>(event, this);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmTreeNodeService method rebuildIndexes.
@Override
@Transactional
public UUID rebuildIndexes(UUID treeTypeId) {
Assert.notNull(treeTypeId, "Tree type identifier is required.");
IdmTreeTypeDto treeType = treeTypeService.get(treeTypeId);
Assert.notNull(treeType, "Tree type is required");
//
String treeTypeCode = treeType.getCode();
RebuildTreeNodeIndexTaskExecutor rebuildTask = AutowireHelper.createBean(RebuildTreeNodeIndexTaskExecutor.class);
rebuildTask.setTreeTypeCode(treeTypeCode);
UUID longRunningTaskId = longRunningTaskManager.execute(rebuildTask).getExecutor().getLongRunningTaskId();
// wee need long running task related to index rebuild immediately
configurationService.setValue(treeTypeService.getConfigurationPropertyName(treeTypeCode, IdmTreeTypeService.CONFIGURATION_PROPERTY_REBUILD), longRunningTaskId.toString());
return longRunningTaskId;
}
Aggregations