use of eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto in project CzechIdMng by bcvsolutions.
the class ScriptEvaluatorTest method testEvaluateScriptWithCreateEntity.
@Test
public void testEvaluateScriptWithCreateEntity() {
IdmScriptDto subScript = new IdmScriptDto();
subScript.setCategory(IdmScriptCategory.DEFAULT);
subScript.setCode(getHelper().createName());
subScript.setName(getHelper().createName());
//
subScript.setScript(createTreeNodeScript(TREE_TYPE_CODE, TREE_TYPE_NAME));
//
subScript = scriptService.save(subScript);
//
createAuthority(subScript.getId(), ScriptAuthorityType.CLASS_NAME, IdmTreeTypeDto.class.getName(), null);
//
createAuthority(subScript.getId(), ScriptAuthorityType.SERVICE, DefaultIdmTreeTypeService.class.getCanonicalName(), "treeTypeService");
//
IdmScriptDto parent = new IdmScriptDto();
parent.setCategory(IdmScriptCategory.DEFAULT);
parent.setCode(getHelper().createName());
parent.setName(getHelper().createName());
//
parent.setScript(createScriptThatCallAnother(subScript, IdmScriptCategory.DEFAULT, null, true));
parent = scriptService.save(parent);
//
Object uuid = groovyScriptService.evaluate(parent.getScript(), createParametersWithEvaluator(IdmScriptCategory.DEFAULT), createExtraAllowedClass());
//
assertNotNull(uuid);
//
IdmTreeTypeDto treeType = this.treeTypeService.get(UUID.fromString(uuid.toString()));
//
assertNotNull(treeType);
assertEquals(this.TREE_TYPE_CODE, treeType.getCode());
assertEquals(this.TREE_TYPE_NAME, treeType.getName());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto in project CzechIdMng by bcvsolutions.
the class AbstractConnectorType method executeMappingStep.
/**
* Execute simple mapping step.
*
* @param connectorTypeDto
*/
private void executeMappingStep(ConnectorTypeDto connectorTypeDto) {
String schemaId = connectorTypeDto.getMetadata().get(SCHEMA_ID);
SysSchemaObjectClassDto schemaDto = null;
if (schemaId != null) {
schemaDto = schemaService.get(UUID.fromString(schemaId), IdmBasePermission.READ);
} else {
String systemId = connectorTypeDto.getMetadata().get(SYSTEM_DTO_KEY);
SysSchemaObjectClassFilter filter = new SysSchemaObjectClassFilter();
Assert.isTrue(Strings.isNotBlank(systemId), "System ID cannot be empty!");
filter.setSystemId(UUID.fromString(systemId));
List<SysSchemaObjectClassDto> schemas = schemaService.find(filter, null, IdmBasePermission.READ).getContent().stream().sorted(Comparator.comparing(SysSchemaObjectClassDto::getCreated)).collect(Collectors.toList());
if (!schemas.isEmpty()) {
schemaDto = schemas.get(0);
}
}
Assert.notNull(schemaDto, "System schema must exists!");
String entityType = connectorTypeDto.getMetadata().get(ENTITY_TYPE);
SystemEntityType systemEntityType = SystemEntityType.valueOf(entityType);
Assert.notNull(systemEntityType, "Entity type cannot be null!");
// For tree type have to be filled tree type ID too.
IdmTreeTypeDto treeTypeDto = null;
if (SystemEntityType.TREE == systemEntityType) {
String treeTypeId = connectorTypeDto.getMetadata().get(TREE_TYPE_ID);
Assert.notNull(treeTypeId, "Tree type ID cannot be null for TREE entity type!");
treeTypeDto = treeTypeService.get(UUID.fromString(treeTypeId));
Assert.notNull(treeTypeDto, "Tree type DTO cannot be null for TREE entity type!");
}
String operationType = connectorTypeDto.getMetadata().get(OPERATION_TYPE);
SystemOperationType systemOperationType = SystemOperationType.valueOf(operationType);
Assert.notNull(systemOperationType, "Operation type cannot be null!");
// Load existing mapping or create new one.
String mappingId = connectorTypeDto.getMetadata().get(MAPPING_ID);
SysSystemMappingDto mappingDto = new SysSystemMappingDto();
mappingDto.setName("Mapping");
boolean isNew = true;
if (mappingId != null) {
SysSystemMappingDto mappingExisted = systemMappingService.get(mappingId, IdmBasePermission.READ);
if (mappingExisted != null) {
isNew = false;
mappingDto = mappingExisted;
}
}
// For tree type have to be filled tree type ID too.
if (SystemEntityType.TREE == systemEntityType) {
mappingDto.setTreeType(treeTypeDto.getId());
}
mappingDto.setEntityType(systemEntityType);
mappingDto.setOperationType(systemOperationType);
mappingDto.setObjectClass(schemaDto.getId());
// Save mapping. Event must be publish with property for enable automatic mapping.
mappingDto = systemMappingService.publish(new SystemMappingEvent(isNew ? SystemMappingEvent.SystemMappingEventType.CREATE : SystemMappingEvent.SystemMappingEventType.UPDATE, mappingDto, ImmutableMap.of(SysSystemMappingService.ENABLE_AUTOMATIC_CREATION_OF_MAPPING, Boolean.TRUE)), isNew ? IdmBasePermission.CREATE : IdmBasePermission.UPDATE).getContent();
connectorTypeDto.getEmbedded().put(MAPPING_DTO_KEY, mappingDto);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto in project CzechIdMng by bcvsolutions.
the class TreeTypeDeleteBulkActionIntegrationTest method testForceDelete.
@Test
public void testForceDelete() {
logout();
loginAsAdmin();
// create sub tree nodes, automatic roles, contract, contract positions, system mapping and sync
IdmTreeTypeDto treeType = getHelper().createTreeType();
SysSystemDto system = getHelper().createTestResourceSystem(true, getHelper().createName());
SysSystemMappingFilter filter = new SysSystemMappingFilter();
filter.setSystemId(system.getId());
SysSystemMappingDto mapping = systemMappingService.find(filter, null).getContent().get(0);
mapping.setTreeType(treeType.getId());
mapping = systemMappingService.save(mapping);
SysSyncConfigDto syncConfig = new SysSyncConfigDto();
syncConfig.setName(getHelper().createName());
syncConfig.setSystemMapping(mapping.getId());
// finds mapped attributes in existing system
SysSystemAttributeMappingFilter attributeFilter = new SysSystemAttributeMappingFilter();
attributeFilter.setSystemId(system.getId());
attributeFilter.setName(TestHelper.ATTRIBUTE_MAPPING_NAME);
SysSystemAttributeMappingDto attribute = attributeMappingService.find(attributeFilter, null).getContent().get(0);
syncConfig.setCorrelationAttribute(attribute.getId());
syncConfig = (SysSyncConfigDto) syncService.save(syncConfig);
IdmRoleDto role = getHelper().createRole();
getHelper().createRoleSystem(role, system);
//
IdmTreeNodeDto treeNode = getHelper().createTreeNode(treeType, null, null);
IdmTreeNodeDto subTreeNode = getHelper().createTreeNode(treeType, (String) null, treeNode);
IdmTreeNodeDto subSubTreeNode = getHelper().createTreeNode(treeType, (String) null, subTreeNode);
IdmTreeNodeDto otherTreeNode = getHelper().createTreeNode();
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
IdmIdentityContractDto contract = getHelper().createContract(identity, subTreeNode);
IdmContractPositionDto contractPosition = getHelper().createContractPosition(contract, subSubTreeNode);
IdmIdentityRoleDto assignedRoleOne = getHelper().createIdentityRole(contract, role);
IdmIdentityRoleDto assignedRoleTwo = getHelper().createIdentityRole(contractPosition, role);
IdmIdentityRoleDto assignedRoleOther = getHelper().createIdentityRole(getHelper().getPrimeContract(identity), role);
IdmRoleTreeNodeDto automaticRole = getHelper().createRoleTreeNode(role, treeNode, RecursionType.DOWN, false);
//
// 3 manual, 2 automatic
Assert.assertEquals(5, identityRoleService.findAllByIdentity(identity.getId()).size());
//
// remove tree type
Map<String, Object> properties = new HashMap<>();
properties.put(EntityEventProcessor.PROPERTY_FORCE_DELETE, Boolean.TRUE);
// delete by bulk action
IdmBulkActionDto bulkAction = this.findBulkAction(IdmTreeType.class, TreeTypeDeleteBulkAction.NAME);
bulkAction.setIdentifiers(Sets.newHashSet(treeType.getId()));
bulkAction.setProperties(properties);
IdmBulkActionDto processAction = bulkActionManager.processAction(bulkAction);
//
checkResultLrt(processAction, 1l, 0l, 0l);
//
Assert.assertNull(treeTypeService.get(treeType));
Assert.assertNull(treeNodeService.get(treeNode));
Assert.assertNull(treeNodeService.get(subTreeNode));
Assert.assertNull(treeNodeService.get(subSubTreeNode));
Assert.assertNull(treeNodeService.get(subSubTreeNode));
Assert.assertNotNull(identityRoleService.get(assignedRoleOne));
Assert.assertNotNull(identityRoleService.get(assignedRoleTwo));
Assert.assertNull(identityContractService.get(contract).getWorkPosition());
Assert.assertNull(contractPositionService.get(contractPosition).getWorkPosition());
Assert.assertNull(roleTreeNodeService.get(automaticRole));
Assert.assertNull(systemMappingService.get(mapping));
Assert.assertNull(attributeMappingService.get(attribute));
Assert.assertNull(syncService.get(syncConfig));
//
Assert.assertNotNull(treeNodeService.get(otherTreeNode));
Assert.assertNotNull(getHelper().getPrimeContract(identity));
Assert.assertNotNull(identityRoleService.get(assignedRoleOther));
}
use of eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto in project CzechIdMng by bcvsolutions.
the class TreeTypeDeleteBulkActionIntegrationTest method testWithoutForceDelete.
@Test(expected = TreeTypeException.class)
public void testWithoutForceDelete() {
// create sub tree nodes, automatic roles, contract, contract positions, system mapping and sync
IdmTreeTypeDto treeType = getHelper().createTreeType();
SysSystemDto system = getHelper().createTestResourceSystem(true, getHelper().createName());
SysSystemMappingFilter filter = new SysSystemMappingFilter();
filter.setSystemId(system.getId());
SysSystemMappingDto mapping = systemMappingService.find(filter, null).getContent().get(0);
mapping.setTreeType(treeType.getId());
mapping = systemMappingService.save(mapping);
//
treeTypeService.delete(treeType);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto 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);
}
Aggregations