use of eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto in project CzechIdMng by bcvsolutions.
the class IdentityFindPositionsTest method testFindManagers.
@Test
public void testFindManagers() {
FilterBuilder<IdmIdentity, DataFilter> filterBuilderSubordinates = filterManager.getBuilder(IdmIdentity.class, IdmIdentityFilter.PARAMETER_SUBORDINATES_FOR);
FilterBuilder<IdmIdentity, DataFilter> filterBuilderManagers = filterManager.getBuilder(IdmIdentity.class, IdmIdentityFilter.PARAMETER_MANAGERS_FOR);
FilterBuilder<IdmIdentityContract, DataFilter> filterBuilderContractByManager = filterManager.getBuilder(IdmIdentityContract.class, IdmIdentityContractFilter.PARAMETER_SUBORDINATES_FOR);
Assert.assertEquals(DefaultManagersFilter.FILTER_NAME, filterBuilderManagers.getId());
Assert.assertEquals(DefaultSubordinatesFilter.FILTER_NAME, filterBuilderSubordinates.getId());
Assert.assertEquals(DefaultContractByManagerFilter.FILTER_NAME, filterBuilderContractByManager.getId());
Assert.assertFalse(filterBuilderSubordinates.isDisabled());
Assert.assertFalse(filterBuilderManagers.isDisabled());
Assert.assertFalse(filterBuilderContractByManager.isDisabled());
//
IdmIdentityDto user = getHelper().createIdentity((GuardedString) null);
IdmIdentityDto user2 = getHelper().createIdentity((GuardedString) null);
IdmIdentityDto user3 = getHelper().createIdentity((GuardedString) null);
IdmIdentityDto user4 = getHelper().createIdentity((GuardedString) null);
IdmTreeTypeDto treeTypeFirst = getHelper().createTreeType();
IdmTreeTypeDto treeTypeSecond = getHelper().createTreeType();
// create root for second type
getHelper().createTreeNode(treeTypeSecond, null);
// create root for first type
IdmTreeNodeDto nodeRoot = getHelper().createTreeNode(treeTypeFirst, null);
// create one for first type
IdmTreeNodeDto nodeOne = getHelper().createTreeNode(treeTypeFirst, nodeRoot);
// create two for first type
IdmTreeNodeDto nodeTwo = getHelper().createTreeNode(treeTypeFirst, nodeOne);
createIdentityContract(user, null, nodeRoot);
createIdentityContract(user2, null, nodeOne);
createIdentityContract(user3, null, nodeOne);
createIdentityContract(user4, null, nodeTwo);
// createIdentityContract(user, manager3, null);
List<IdmIdentityDto> managersList = identityService.findAllManagers(user3.getId(), treeTypeFirst.getId());
assertEquals(1, managersList.size());
IdmIdentityDto manager = managersList.get(0);
assertEquals(user.getId(), manager.getId());
managersList = identityService.findAllManagers(user4.getId(), treeTypeFirst.getId(), Boolean.TRUE);
assertEquals(2, managersList.size());
managersList = identityService.findAllManagers(user.getId(), treeTypeFirst.getId());
assertEquals(1, managersList.size());
createIdentityContract(user, null, nodeTwo);
managersList = identityService.findAllManagers(user.getId(), treeTypeFirst.getId());
assertEquals(2, managersList.size());
List<IdmIdentityDto> managersListSec = identityService.findAllManagers(user.getId(), treeTypeSecond.getId());
// user with superAdminRole
assertEquals(1, managersListSec.size());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto in project CzechIdMng by bcvsolutions.
the class ComplexHrProcessIntegrationTest method createHrContractSystem.
private void createHrContractSystem() {
getBean().deleteAllResourceData(TestContractResource.TABLE_NAME);
// create new system
SysSystemDto system = accTestHelper.createSystem(TestContractResource.TABLE_NAME, contractSysName, null, "ID");
system.setReadonly(true);
system.setDisabledProvisioning(true);
system = systemService.save(system);
List<IdmFormValueDto> values = new ArrayList<IdmFormValueDto>();
IdmFormDefinitionDto savedFormDefinition = systemService.getConnectorFormDefinition(system);
IdmFormValueDto changeLogColumnValue = new IdmFormValueDto(savedFormDefinition.getMappedAttributeByCode("changeLogColumn"));
changeLogColumnValue.setValue("MODIFIED");
values.add(changeLogColumnValue);
formService.saveValues(system, savedFormDefinition, values);
// generate schema for system
List<SysSchemaObjectClassDto> objectClasses = systemService.generateSchema(system);
// Create synchronization mapping
SysSystemMappingDto syncSystemMapping = new SysSystemMappingDto();
syncSystemMapping.setName(getHelper().createName());
syncSystemMapping.setEntityType(SystemEntityType.CONTRACT);
syncSystemMapping.setOperationType(SystemOperationType.SYNCHRONIZATION);
syncSystemMapping.setObjectClass(objectClasses.get(0).getId());
syncSystemMapping = systemMappingService.save(syncSystemMapping);
SysSchemaAttributeFilter schemaAttributeFilter = new SysSchemaAttributeFilter();
schemaAttributeFilter.setSystemId(system.getId());
List<SysSchemaAttributeDto> schemaAttributes = schemaAttributeService.find(schemaAttributeFilter, null).getContent();
for (SysSchemaAttributeDto schemaAttr : schemaAttributes) {
SysSystemAttributeMappingDto attributeMapping = new SysSystemAttributeMappingDto();
attributeMapping.setSchemaAttribute(schemaAttr.getId());
attributeMapping.setSystemMapping(syncSystemMapping.getId());
attributeMapping.setEntityAttribute(true);
// just id, not mapped to attribute
if (StringUtils.equalsIgnoreCase("ID", schemaAttr.getName())) {
attributeMapping.setUid(true);
attributeMapping.setEntityAttribute(true);
// correlation attr
attributeMapping.setName(schemaAttr.getName().toLowerCase());
// used for storing contract id
attributeMapping.setIdmPropertyName("position");
} else if (StringUtils.equalsIgnoreCase("STATE", schemaAttr.getName())) {
attributeMapping.setName(schemaAttr.getName().toLowerCase());
attributeMapping.setIdmPropertyName("state");
} else if (StringUtils.equalsIgnoreCase("VALIDFROM", schemaAttr.getName())) {
attributeMapping.setName(schemaAttr.getName().toLowerCase());
attributeMapping.setIdmPropertyName("validFrom");
attributeMapping.setTransformFromResourceScript(getScriptCallExpression(stringToLocalDateScript));
attributeMapping.setCached(true);
} else if (StringUtils.equalsIgnoreCase("VALIDTILL", schemaAttr.getName())) {
attributeMapping.setName(schemaAttr.getName().toLowerCase());
attributeMapping.setIdmPropertyName("validTill");
attributeMapping.setTransformFromResourceScript(getScriptCallExpression(stringToLocalDateScript));
attributeMapping.setCached(true);
// this maps personalNumber to identity to which contract belongs; transformation script is used
} else if (StringUtils.equalsIgnoreCase("NAME", schemaAttr.getName())) {
// NAME used for personalNumber aka externalCode
attributeMapping.setName(schemaAttr.getName().toLowerCase());
// represents IdmIentityDto
attributeMapping.setIdmPropertyName("identity");
attributeMapping.setTransformFromResourceScript(getScriptCallExpression(getIdentityUuidByPersonalNumScript));
attributeMapping.setCached(true);
} else if (StringUtils.equalsIgnoreCase("WORKPOSITION", schemaAttr.getName())) {
attributeMapping.setName(schemaAttr.getName().toLowerCase());
attributeMapping.setIdmPropertyName("workPosition");
} else if (StringUtils.equalsIgnoreCase("POSITIONS", schemaAttr.getName())) {
attributeMapping.setName(schemaAttr.getName().toLowerCase());
attributeMapping.setIdmPropertyName(eavAutoRoleAttrName);
attributeMapping.setEntityAttribute(false);
attributeMapping.setExtendedAttribute(true);
} else {
// skip those undefined
continue;
}
attributeMapping = systemAttributeMappingService.save(attributeMapping);
}
// Create default synchronization config
SysSystemAttributeMappingFilter mapAttrFilt = new SysSystemAttributeMappingFilter();
mapAttrFilt.setSystemId(system.getId());
mapAttrFilt.setName("id");
SysSystemAttributeMappingDto correlationAttr = systemAttributeMappingService.find(mapAttrFilt, null).getContent().get(0);
IdmTreeTypeFilter typeFilt = new IdmTreeTypeFilter();
typeFilt.setCode(orgTreeTypeName);
IdmTreeTypeDto treeType = treeTypeService.find(typeFilt, null).getContent().get(0);
SysSyncContractConfigDto syncConfigCustom = new SysSyncContractConfigDto();
syncConfigCustom.setReconciliation(false);
syncConfigCustom.setCustomFilter(false);
syncConfigCustom.setSystemMapping(syncSystemMapping.getId());
syncConfigCustom.setCorrelationAttribute(correlationAttr.getId());
syncConfigCustom.setName(contractSysName + "-SYNC");
syncConfigCustom.setLinkedAction(SynchronizationLinkedActionType.UPDATE_ENTITY);
syncConfigCustom.setUnlinkedAction(SynchronizationUnlinkedActionType.LINK);
syncConfigCustom.setMissingEntityAction(SynchronizationMissingEntityActionType.CREATE_ENTITY);
syncConfigCustom.setMissingAccountAction(ReconciliationMissingAccountActionType.IGNORE);
syncConfigCustom.setStartOfHrProcesses(true);
syncConfigCustom.setStartAutoRoleRec(true);
syncConfigCustom.setDefaultTreeType(treeType.getId());
syncConfigCustom = (SysSyncContractConfigDto) sysSyncConfigService.save(syncConfigCustom);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto in project CzechIdMng by bcvsolutions.
the class SystemExportBulkActionIntegrationTest method testExportAndImportContractSyncAdvancedPairing.
@Test
public void testExportAndImportContractSyncAdvancedPairing() {
SysSystemDto system = createSystem();
List<SysSystemMappingDto> mappings = findMappings(system);
Assert.assertEquals(1, mappings.size());
SysSystemMappingDto originalMapping = mappings.get(0);
List<SysSystemAttributeMappingDto> originalAttributes = findAttributeMappings(system);
SysSystemAttributeMappingDto originalAttribute = originalAttributes.get(0);
IdmTreeTypeDto treeType = getHelper().createTreeType();
IdmTreeNodeDto treeNode = getHelper().createTreeNode(treeType, null);
SysSyncContractConfigDto originalSync = new SysSyncContractConfigDto();
originalSync.setSystemMapping(originalMapping.getId());
originalSync.setName(getHelper().createName());
originalSync.setCorrelationAttribute(originalAttribute.getId());
originalSync.setDefaultTreeType(treeType.getId());
originalSync.setDefaultTreeNode(treeNode.getId());
originalSync = (SysSyncContractConfigDto) synchronizationConfigService.save(originalSync);
// Make export, upload, delete system and import
IdmExportImportDto importBatch = executeExportAndImport(system, SystemExportBulkAction.NAME);
system = systemService.get(system.getId());
Assert.assertNotNull(system);
mappings = findMappings(system);
List<SysSystemAttributeMappingDto> attributes = findAttributeMappings(system);
Assert.assertEquals(1, mappings.size());
SysSystemMappingDto mapping = mappings.get(0);
Assert.assertEquals(originalMapping.getId(), mapping.getId());
Assert.assertEquals(originalAttributes.size(), attributes.size());
// Create redundant sync
SysSyncConfigDto redundantSync = new SysSyncConfigDto();
redundantSync.setSystemMapping(originalMapping.getId());
redundantSync.setName(getHelper().createName());
redundantSync.setCorrelationAttribute(originalAttribute.getId());
redundantSync = (SysSyncConfigDto) synchronizationConfigService.save(redundantSync);
// Clear tree type and tree node.
originalSync.setDefaultTreeType(null);
originalSync.setDefaultTreeNode(null);
originalSync = (SysSyncContractConfigDto) synchronizationConfigService.save(originalSync);
// Delete original tree-type and tree-node and create new with same code (test of advanced paring).
getHelper().deleteTreeNode(treeNode.getId());
getHelper().deleteTreeType(treeType.getId());
IdmTreeTypeDto treeTypeNew = getHelper().createTreeType(treeType.getCode());
IdmTreeNodeDto treeNodeNew = getHelper().createTreeNode(treeTypeNew, treeNode.getCode(), null);
// Execute import (check authoritative mode)
importBatch = importManager.executeImport(importBatch, false);
Assert.assertNotNull(importBatch);
Assert.assertEquals(ExportImportType.IMPORT, importBatch.getType());
Assert.assertEquals(OperationState.EXECUTED, importBatch.getResult().getState());
// Redundant sync had to be deleted!
redundantSync = (SysSyncConfigDto) synchronizationConfigService.get(redundantSync.getId());
Assert.assertNull(redundantSync);
// Check advanced paring for tree-type and tree-node.
originalSync = (SysSyncContractConfigDto) synchronizationConfigService.get(originalSync.getId());
Assert.assertNotNull(originalSync);
Assert.assertEquals(treeTypeNew.getId(), originalSync.getDefaultTreeType());
Assert.assertEquals(treeNodeNew.getId(), originalSync.getDefaultTreeNode());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto in project CzechIdMng by bcvsolutions.
the class TreeTypeDeleteProcessor method process.
@Override
public EventResult<IdmTreeTypeDto> process(EntityEvent<IdmTreeTypeDto> event) {
IdmTreeTypeDto treeType = event.getContent();
UUID treeTypeId = treeType.getId();
Assert.notNull(treeTypeId, "Tree type identifier is required.");
boolean forceDelete = getBooleanProperty(PROPERTY_FORCE_DELETE, event.getProperties());
//
if (!forceDelete) {
if (identityContractRepository.countByWorkPosition_TreeType_Id(treeTypeId) > 0) {
throw new TreeTypeException(CoreResultCode.TREE_TYPE_DELETE_FAILED_HAS_CONTRACTS, ImmutableMap.of("treeType", treeType.getCode()));
}
IdmTreeNodeFilter filter = new IdmTreeNodeFilter();
filter.setTreeTypeId(treeTypeId);
if (treeNodeService.count(filter) > 0) {
throw new TreeTypeException(CoreResultCode.TREE_TYPE_DELETE_FAILED_HAS_CHILDREN, ImmutableMap.of("treeType", treeType.getCode()));
}
} else {
// delete tree nodes
IdmTreeNodeFilter filter = new IdmTreeNodeFilter();
filter.setTreeTypeId(treeTypeId);
treeNodeService.find(filter, null).forEach(treeNode -> {
TreeNodeEvent treeNodeEvent = new TreeNodeEvent(TreeNodeEventType.DELETE, treeNode);
//
treeNodeService.publish(treeNodeEvent, event);
clearSession();
});
}
// deletes tree type at end
if (forceDelete) {
LOG.debug("Tree type [{}] should be deleted by caller after all asynchronous processes are completed.", treeTypeId);
//
// dirty flag only - will be processed after asynchronous events ends
IdmEntityStateDto stateDeleted = new IdmEntityStateDto();
stateDeleted.setEvent(event.getId());
stateDeleted.setResult(new OperationResultDto.Builder(OperationState.RUNNING).setModel(new DefaultResultModel(CoreResultCode.DELETED)).build());
entityStateManager.saveState(treeType, stateDeleted);
} else {
service.deleteInternal(treeType);
}
//
return new DefaultEventResult<>(event, this);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto in project CzechIdMng by bcvsolutions.
the class IdmTreeTypeController method getDefaultTreeType.
/**
* Returns default tree type or {@code null}, if no default tree type is defined
*
* @return
*/
@ResponseBody
@RequestMapping(value = "/search/default", method = RequestMethod.GET)
@PreAuthorize("hasAuthority('" + CoreGroupPermission.TREETYPE_AUTOCOMPLETE + "')" + " or hasAuthority('" + CoreGroupPermission.TREETYPE_READ + "')")
@ApiOperation(value = "Get default tree type detail", nickname = "getDefaultTreeType", response = IdmTreeTypeDto.class, tags = { IdmTreeTypeController.TAG }, authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = CoreGroupPermission.TREETYPE_AUTOCOMPLETE, description = ""), @AuthorizationScope(scope = CoreGroupPermission.TREETYPE_READ, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = CoreGroupPermission.TREETYPE_AUTOCOMPLETE, description = ""), @AuthorizationScope(scope = CoreGroupPermission.TREETYPE_READ, description = "") }) })
public ResponseEntity<?> getDefaultTreeType() {
IdmTreeTypeDto defaultTreeType = service.getDefaultTreeType();
if (defaultTreeType == null) {
throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("entity", "default tree type"));
}
Set<String> permissions = getService().getPermissions(defaultTreeType.getId());
if (!PermissionUtils.hasAnyPermission(permissions, IdmBasePermission.AUTOCOMPLETE, IdmBasePermission.READ)) {
throw new ForbiddenEntityException(defaultTreeType.getId(), IdmBasePermission.AUTOCOMPLETE, IdmBasePermission.READ);
}
return new ResponseEntity<>(toResource(defaultTreeType), HttpStatus.OK);
}
Aggregations