use of eu.bcvsolutions.idm.acc.dto.filter.SysSystemAttributeMappingFilter in project CzechIdMng by bcvsolutions.
the class DefaultSysSystemServiceTest method duplicateSystemWithSynchronization.
@Test
public void duplicateSystemWithSynchronization() {
String syncName = "test-sync-config";
// create test system
SysSystemDto system = helper.createTestResourceSystem(true);
SysSchemaAttributeFilter schemaAttributeFilter = new SysSchemaAttributeFilter();
schemaAttributeFilter.setSystemId(system.getId());
// Number of schema attributes on original system
int numberOfSchemaAttributesOrig = schemaAttributeService.find(schemaAttributeFilter, null).getContent().size();
SysSystemMappingDto mappingOrig = helper.getDefaultMapping(system);
// Number of mapping attributes on original system
int numberOfMappingAttributesOrig = systemAttributeMappingService.findBySystemMapping(mappingOrig).size();
SysSystemAttributeMappingFilter attributeMappingFilter = new SysSystemAttributeMappingFilter();
attributeMappingFilter.setSystemMappingId(mappingOrig.getId());
List<SysSystemAttributeMappingDto> attributes = schemaAttributeMappingService.find(attributeMappingFilter, null).getContent();
SysSystemAttributeMappingDto nameAttribute = attributes.stream().filter(attribute -> {
return attribute.getName().equals(TestHelper.ATTRIBUTE_MAPPING_NAME);
}).findFirst().get();
SysSystemAttributeMappingDto firstNameAttribute = attributes.stream().filter(attribute -> {
return attribute.getName().equals(TestHelper.ATTRIBUTE_MAPPING_FIRSTNAME);
}).findFirst().get();
SysSystemAttributeMappingDto emailAttribute = attributes.stream().filter(attribute -> {
return attribute.getName().equals(TestHelper.ATTRIBUTE_MAPPING_EMAIL);
}).findFirst().get();
// create synchronization config
AbstractSysSyncConfigDto syncConfigDuplicate = new SysSyncIdentityConfigDto();
syncConfigDuplicate.setCustomFilter(true);
syncConfigDuplicate.setSystemMapping(mappingOrig.getId());
syncConfigDuplicate.setCorrelationAttribute(nameAttribute.getId());
syncConfigDuplicate.setTokenAttribute(firstNameAttribute.getId());
syncConfigDuplicate.setFilterAttribute(emailAttribute.getId());
syncConfigDuplicate.setReconciliation(true);
syncConfigDuplicate.setName(syncName);
syncConfigDuplicate.setLinkedAction(SynchronizationLinkedActionType.IGNORE);
syncConfigDuplicate.setUnlinkedAction(SynchronizationUnlinkedActionType.IGNORE);
syncConfigDuplicate.setMissingEntityAction(SynchronizationMissingEntityActionType.CREATE_ENTITY);
syncConfigDuplicate.setMissingAccountAction(ReconciliationMissingAccountActionType.IGNORE);
syncConfigDuplicate = syncConfigService.save(syncConfigDuplicate);
SysSystemDto duplicatedSystem = systemService.duplicate(system.getId());
// check duplicate
systemService.checkSystem(duplicatedSystem);
Assert.assertNotEquals(system.getId(), duplicatedSystem.getId());
schemaAttributeFilter.setSystemId(duplicatedSystem.getId());
// Number of schema attributes on duplicated system
int numberOfSchemaAttributes = schemaAttributeService.find(schemaAttributeFilter, null).getContent().size();
Assert.assertEquals(numberOfSchemaAttributesOrig, numberOfSchemaAttributes);
SysSystemMappingDto mapping = helper.getDefaultMapping(duplicatedSystem);
// Number of mapping attributes on duplicated system
int numberOfMappingAttributes = systemAttributeMappingService.findBySystemMapping(mapping).size();
Assert.assertEquals(numberOfMappingAttributesOrig, numberOfMappingAttributes);
// check synchronization config
SysSyncConfigFilter syncFilter = new SysSyncConfigFilter();
syncFilter.setSystemId(duplicatedSystem.getId());
List<AbstractSysSyncConfigDto> configs = syncConfigService.find(syncFilter, null).getContent();
Assert.assertEquals(1, configs.size());
Assert.assertEquals(1, configs.size());
AbstractSysSyncConfigDto configNew = configs.get(0);
Assert.assertFalse(configNew.isEnabled());
Assert.assertTrue(configNew.isReconciliation());
Assert.assertEquals(syncName, configNew.getName());
Assert.assertTrue(configNew.isCustomFilter());
Assert.assertEquals(syncConfigDuplicate.getLinkedAction(), configNew.getLinkedAction());
Assert.assertEquals(syncConfigDuplicate.getUnlinkedAction(), configNew.getUnlinkedAction());
Assert.assertEquals(syncConfigDuplicate.getMissingEntityAction(), configNew.getMissingEntityAction());
Assert.assertEquals(syncConfigDuplicate.getMissingAccountAction(), configNew.getMissingAccountAction());
SysSystemAttributeMappingDto correlationAtt = schemaAttributeMappingService.get(configNew.getCorrelationAttribute());
SysSystemAttributeMappingDto tokenAtt = schemaAttributeMappingService.get(configNew.getTokenAttribute());
SysSystemAttributeMappingDto filterAtt = schemaAttributeMappingService.get(configNew.getFilterAttribute());
Assert.assertEquals(nameAttribute.getName(), correlationAtt.getName());
Assert.assertEquals(nameAttribute.getIdmPropertyName(), correlationAtt.getIdmPropertyName());
Assert.assertEquals(firstNameAttribute.getName(), tokenAtt.getName());
Assert.assertEquals(firstNameAttribute.getIdmPropertyName(), tokenAtt.getIdmPropertyName());
Assert.assertEquals(emailAttribute.getName(), filterAtt.getName());
Assert.assertEquals(emailAttribute.getIdmPropertyName(), filterAtt.getIdmPropertyName());
}
use of eu.bcvsolutions.idm.acc.dto.filter.SysSystemAttributeMappingFilter in project CzechIdMng by bcvsolutions.
the class DefaultSysSystemServiceTest method testReferentialIntegrity.
@Test
public void testReferentialIntegrity() {
SysSystemDto system = new SysSystemDto();
String systemName = "t_s_" + System.currentTimeMillis();
system.setName(systemName);
system = systemService.save(system);
// object class
SysSchemaObjectClassDto objectClass = new SysSchemaObjectClassDto();
objectClass.setSystem(system.getId());
objectClass.setObjectClassName("obj_class");
objectClass = schemaObjectClassService.save(objectClass);
SysSchemaObjectClassFilter objectClassFilter = new SysSchemaObjectClassFilter();
objectClassFilter.setSystemId(system.getId());
// schema attribute
SysSchemaAttributeDto schemaAttribute = new SysSchemaAttributeDto();
schemaAttribute.setObjectClass(objectClass.getId());
schemaAttribute.setName("name");
schemaAttribute.setClassType("class");
schemaAttribute = schemaAttributeService.save(schemaAttribute);
SysSchemaAttributeFilter schemaAttributeFilter = new SysSchemaAttributeFilter();
schemaAttributeFilter.setSystemId(system.getId());
// system entity handling
SysSystemMappingDto systemMapping = new SysSystemMappingDto();
systemMapping.setName("default_" + System.currentTimeMillis());
systemMapping.setObjectClass(objectClass.getId());
systemMapping.setOperationType(SystemOperationType.PROVISIONING);
systemMapping.setEntityType(SystemEntityType.IDENTITY);
systemMapping = systemMappingService.save(systemMapping);
SysSystemMappingFilter entityHandlingFilter = new SysSystemMappingFilter();
entityHandlingFilter.setSystemId(system.getId());
// schema attribute handling
SysSystemAttributeMappingDto schemaAttributeHandling = new SysSystemAttributeMappingDto();
schemaAttributeHandling.setSchemaAttribute(schemaAttribute.getId());
schemaAttributeHandling.setSystemMapping(systemMapping.getId());
schemaAttributeHandling.setName("name");
schemaAttributeHandling.setIdmPropertyName("name");
schemaAttributeHandling = systemAttributeMappingService.save(schemaAttributeHandling);
SysSystemAttributeMappingFilter schemaAttributeHandlingFilter = new SysSystemAttributeMappingFilter();
schemaAttributeHandlingFilter.setSystemId(system.getId());
// role system
IdmRoleDto role = helper.createRole();
SysRoleSystemDto roleSystem = new SysRoleSystemDto();
roleSystem.setSystem(system.getId());
roleSystem.setRole(role.getId());
roleSystem.setSystemMapping(systemMapping.getId());
roleSystem = roleSystemService.save(roleSystem);
SysRoleSystemFilter roleSystemFilter = new SysRoleSystemFilter();
roleSystemFilter.setRoleId(role.getId());
// role system attributes
SysRoleSystemAttributeDto roleSystemAttribute = new SysRoleSystemAttributeDto();
roleSystemAttribute.setRoleSystem(roleSystem.getId());
roleSystemAttribute.setSystemAttributeMapping(schemaAttributeHandling.getId());
roleSystemAttribute.setName("name");
roleSystemAttribute.setIdmPropertyName("name");
roleSystemAttribute = roleSystemAttributeService.save(roleSystemAttribute);
assertEquals(systemName, systemService.getByCode(systemName).getName());
assertEquals(1, schemaObjectClassService.find(objectClassFilter, null).getTotalElements());
assertEquals(1, schemaAttributeService.find(schemaAttributeFilter, null).getTotalElements());
assertEquals(1, systemMappingService.find(entityHandlingFilter, null).getTotalElements());
assertEquals(1, systemAttributeMappingService.find(schemaAttributeHandlingFilter, null).getTotalElements());
assertEquals(1, roleSystemService.find(roleSystemFilter, null).getTotalElements());
assertNotNull(roleSystemAttributeService.get(roleSystemAttribute.getId()));
systemService.delete(system);
assertNull(systemService.getByCode(systemName));
assertEquals(0, schemaObjectClassService.find(objectClassFilter, null).getTotalElements());
assertEquals(0, schemaAttributeService.find(schemaAttributeFilter, null).getTotalElements());
assertEquals(0, systemMappingService.find(entityHandlingFilter, null).getTotalElements());
assertEquals(0, systemAttributeMappingService.find(schemaAttributeHandlingFilter, null).getTotalElements());
assertEquals(0, roleSystemService.find(roleSystemFilter, null).getTotalElements());
assertNull(roleSystemAttributeService.get(roleSystemAttribute.getId()));
}
use of eu.bcvsolutions.idm.acc.dto.filter.SysSystemAttributeMappingFilter in project CzechIdMng by bcvsolutions.
the class DefaultSysSystemService method duplicateMapping.
/**
* Duplication of mapping attributes. Is not in attribute mapping service, because we need use IDs cache (Old vs New IDs)
* @param id
* @param schema
* @param schemaAttributesIds
* @param mappedAttributesIds
* @return
*/
private SysSystemMappingDto duplicateMapping(UUID id, SysSchemaObjectClassDto schema, Map<UUID, UUID> schemaAttributesIds, Map<UUID, UUID> mappedAttributesIds) {
Assert.notNull(id, "Id of duplication mapping, must be filled!");
Assert.notNull(schema, "Parent schema must be filled!");
SysSystemMappingDto clonedMapping = systemMappingService.clone(id);
clonedMapping.setObjectClass(schema.getId());
SysSystemMappingDto mapping = this.systemMappingService.save(clonedMapping);
// Clone mapped attributes
SysSystemAttributeMappingFilter attributesFilter = new SysSystemAttributeMappingFilter();
attributesFilter.setSystemMappingId(id);
systemAttributeMappingService.find(attributesFilter, null).forEach(attribute -> {
UUID originalAttributeId = attribute.getId();
SysSystemAttributeMappingDto clonedAttribute = systemAttributeMappingService.clone(originalAttributeId);
// Find cloned schema attribute in cache (by original Id)
SysSchemaAttributeDto clonedSchemaAttribute = attributeService.get(schemaAttributesIds.get(clonedAttribute.getSchemaAttribute()));
clonedAttribute.setSystemMapping(mapping.getId());
clonedAttribute.setSchemaAttribute(clonedSchemaAttribute.getId());
clonedAttribute = systemAttributeMappingService.save(clonedAttribute);
// Put original and new id to cache
mappedAttributesIds.put(originalAttributeId, clonedAttribute.getId());
});
return mapping;
}
use of eu.bcvsolutions.idm.acc.dto.filter.SysSystemAttributeMappingFilter in project CzechIdMng by bcvsolutions.
the class SystemExportBulkActionIntegrationTest method testExportAndImportSystemWithDeletedAttributes.
@Test
public void testExportAndImportSystemWithDeletedAttributes() {
SysSystemDto system = helper.createVirtualSystem(helper.createName());
Assert.assertNotNull(system);
Assert.assertFalse(system.isDisabled());
List<String> attrsToDelete = Arrays.asList(ATTRIBUTE_TO_DELETE1, ATTRIBUTE_TO_DELETE2);
// delete mapping attributes
SysSystemAttributeMappingFilter mappingFilter = new SysSystemAttributeMappingFilter();
mappingFilter.setSystemId(system.getId());
for (String name : attrsToDelete) {
mappingFilter.setName(name);
List<SysSystemAttributeMappingDto> mappings = systemAttributeMappingService.find(mappingFilter, null).getContent();
Assert.assertEquals(1, mappings.size());
systemAttributeMappingService.delete(mappings.get(0));
;
}
// delete attributes from schema
SysSchemaAttributeFilter schemaFilter = new SysSchemaAttributeFilter();
schemaFilter.setSystemId(system.getId());
for (String name : attrsToDelete) {
schemaFilter.setName(name);
List<SysSchemaAttributeDto> schemaAttrs = schemaAttributeService.find(schemaFilter, null).getContent();
Assert.assertEquals(1, schemaAttrs.size());
schemaAttributeService.delete(schemaAttrs.get(0));
}
// remove attribute from the connector form definition
IdmFormDefinitionDto connectorFormDefinition = systemService.getConnectorFormDefinition(system);
List<IdmFormValueDto> formValues = formService.getValues(system, connectorFormDefinition, VsSystemService.ATTRIBUTES_PROPERTY);
formValues.stream().filter(formValue -> attrsToDelete.contains(formValue.getStringValue())).forEach(formValue -> formService.deleteValue(formValue));
// VS Account form attribute
String vsType = VsAccount.class.getName();
String vsKey = vsSystemService.createVsFormDefinitionKey(system);
IdmFormDefinitionDto definition = formService.getDefinition(vsType, vsKey);
for (String name : attrsToDelete) {
IdmFormAttributeDto attrToDelete = formAttributeService.findAttribute(vsType, vsKey, name);
formService.deleteAttribute(attrToDelete);
}
// Make export, upload and import
executeExportAndImport(system, SystemExportBulkAction.NAME);
// Right attribute is correctly imported
IdmFormAttributeDto rightFormAttr = formService.getAttribute(definition, RIGHTS_VS_ATTRIBUTE);
Assert.assertTrue(rightFormAttr.isMultiple());
// no previously deleted form attributes are created during the import
for (String name : attrsToDelete) {
IdmFormAttributeDto attrToDelete = formAttributeService.findAttribute(vsType, vsKey, name);
Assert.assertNull(attrToDelete);
}
// no previously deleted form values from connector definition are created during the import
formValues = formService.getValues(system, connectorFormDefinition, VsSystemService.ATTRIBUTES_PROPERTY);
long formValueCount = formValues.stream().filter(formValue -> attrsToDelete.contains(formValue.getStringValue())).count();
Assert.assertEquals(0, formValueCount);
// previously deleted schema attribute is not created during the import
schemaFilter = new SysSchemaAttributeFilter();
schemaFilter.setSystemId(system.getId());
for (String name : attrsToDelete) {
schemaFilter.setName(name);
List<SysSchemaAttributeDto> schemaAttrs = schemaAttributeService.find(schemaFilter, null).getContent();
Assert.assertEquals(0, schemaAttrs.size());
}
// deleted attribute mapping attributes is not created during the import
mappingFilter = new SysSystemAttributeMappingFilter();
mappingFilter.setSystemId(system.getId());
for (String name : attrsToDelete) {
mappingFilter.setName(name);
List<SysSystemAttributeMappingDto> mappings = systemAttributeMappingService.find(mappingFilter, null).getContent();
Assert.assertEquals(0, mappings.size());
}
system = systemService.get(system.getId());
Assert.assertNotNull(system);
Assert.assertTrue(system.isDisabled());
}
use of eu.bcvsolutions.idm.acc.dto.filter.SysSystemAttributeMappingFilter in project CzechIdMng by bcvsolutions.
the class DefaultLdapTestHelper method getAttributeMappingMemberOfAttributeForSystem.
@Override
public SysSystemAttributeMappingDto getAttributeMappingMemberOfAttributeForSystem(SysSystemDto system, SysSchemaAttributeDto memberOfAttributeForSystem) {
SysSystemAttributeMappingFilter filter = new SysSystemAttributeMappingFilter();
filter.setSystemId(system.getId());
filter.setSchemaAttributeId(memberOfAttributeForSystem.getId());
List<SysSystemAttributeMappingDto> attributes = attributeMappingService.find(filter, null).getContent();
return attributes.get(0);
}
Aggregations