Search in sources :

Example 16 with IdmGenerateValueDto

use of eu.bcvsolutions.idm.core.api.dto.IdmGenerateValueDto in project CzechIdMng by bcvsolutions.

the class ComplexHrProcessIntegrationTest method createGenerators.

/**
 * Configuration of necessary generators
 * 1) username generator
 * 2) email generator
 */
private void createGenerators() {
    Map<String, String> configUsername = ImmutableMap.of(IdentityUsernameGenerator.SEARCH_UNIQUE_USERNAME, Boolean.TRUE.toString(), IdentityUsernameGenerator.CONNECTING_CHARACTER, ".", IdentityUsernameGenerator.FIRST_NAME_FIRST, Boolean.TRUE.toString());
    IdmGenerateValueDto usernameGen = new IdmGenerateValueDto();
    usernameGen.setDtoType(IdmIdentityDto.class.getCanonicalName());
    usernameGen.setGeneratorType(IdentityUsernameGenerator.class.getCanonicalName());
    usernameGen.setSeq((short) 0);
    usernameGen.setUnmodifiable(false);
    usernameGen.setGeneratorProperties(new ConfigurationMap(configUsername));
    generatedAttributeService.save(usernameGen);
    Map<String, String> emailConfig = ImmutableMap.of(IdentityEmailGenerator.PROPERTY_UNIQUE_EMAIL, Boolean.TRUE.toString(), IdentityEmailGenerator.CONNECTING_CHARACTER, ".", IdentityEmailGenerator.EMAIL_SUFFIX, "company.cz");
    IdmGenerateValueDto emailGen = new IdmGenerateValueDto();
    emailGen.setDtoType(IdmIdentityDto.class.getCanonicalName());
    emailGen.setGeneratorType(IdentityEmailGenerator.class.getCanonicalName());
    emailGen.setSeq((short) 0);
    emailGen.setUnmodifiable(false);
    emailGen.setGeneratorProperties(new ConfigurationMap(emailConfig));
    generatedAttributeService.save(emailGen);
}
Also used : IdmGenerateValueDto(eu.bcvsolutions.idm.core.api.dto.IdmGenerateValueDto) IdentityUsernameGenerator(eu.bcvsolutions.idm.core.generator.identity.IdentityUsernameGenerator) IdentityEmailGenerator(eu.bcvsolutions.idm.core.generator.identity.IdentityEmailGenerator) ConfigurationMap(eu.bcvsolutions.idm.core.api.domain.ConfigurationMap) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)

Example 17 with IdmGenerateValueDto

use of eu.bcvsolutions.idm.core.api.dto.IdmGenerateValueDto in project CzechIdMng by bcvsolutions.

the class AbstractRoleParametrizationFormDefaultValueGenerator method getDefaultValuesByRoleDefinition.

protected IdmFormInstanceDto getDefaultValuesByRoleDefinition(IdmRoleDto roleDto, IdmGenerateValueDto valueGenerator, IdmFormInstanceDto existingEavs, DTO dto) {
    UUID formDefinitionId = roleDto.getIdentityRoleAttributeDefinition();
    // If form definition doesn't exist continue as normal
    if (formDefinitionId == null) {
        return null;
    }
    IdmFormDefinitionDto definition = roleService.getFormAttributeSubdefinition(roleDto);
    // Internal behavior #getValuesFromInstances wants default form value
    List<IdmFormValueDto> values = new ArrayList<>();
    for (IdmFormAttributeDto attribute : definition.getFormAttributes()) {
        String defaultValue = getDefaultValue(attribute, roleDto);
        // check if exists default values
        if (StringUtils.isEmpty(defaultValue)) {
            // Check given values
            List<IdmFormValueDto> existingValues = existingEavs == null ? null : // 
            existingEavs.getValues().stream().filter(existingEav -> {
                // 
                return existingEav.getFormAttribute().equals(attribute.getId());
            }).collect(// 
            Collectors.toList());
            if (existingValues != null && !existingValues.isEmpty()) {
                // Given value exist and default value doesn't exist
                values.addAll(existingValues);
            }
            continue;
        }
        if (valueGenerator.isRegenerateValue()) {
            // For regenerate just create values by default values
            String regex = this.getRegex(valueGenerator);
            String[] defaultValues = defaultValue.split(regex);
            for (String defValue : defaultValues) {
                IdmFormValueDto value = new IdmFormValueDto(attribute);
                value.setValue(defValue);
                values.add(value);
            }
        } else {
            if (existingEavs != null) {
                // With check existing values
                List<IdmFormValueDto> existingValues = existingEavs.getValues().stream().filter(existingVal -> {
                    // 
                    return existingVal.getFormAttribute().equals(attribute.getId());
                }).collect(// 
                Collectors.toList());
                if (!existingValues.isEmpty()) {
                    // If existing value isn't empty use it (given values)
                    existingValues.forEach(existingValue -> {
                        IdmFormValueDto value = new IdmFormValueDto(attribute);
                        value.setValue(existingValue.getValue(attribute.getPersistentType()));
                        values.add(value);
                    });
                    continue;
                }
            }
            // If given values is empty use default
            if (attribute.isMultiple()) {
                // Default value may be multiple, just iterate over value splited by regex
                String regex = this.getRegex(valueGenerator);
                String[] defaultValues = defaultValue.split(regex);
                for (String defValue : defaultValues) {
                    IdmFormValueDto value = new IdmFormValueDto(attribute);
                    value.setValue(defValue);
                    values.add(value);
                }
            } else {
                // If is value single valued use it as is it
                IdmFormValueDto value = new IdmFormValueDto(attribute);
                value.setValue(defaultValue);
                values.add(value);
            }
        }
    }
    return new IdmFormInstanceDto(dto, definition, values);
}
Also used : IdmRoleFormAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleFormAttributeDto) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) IdmRoleService(eu.bcvsolutions.idm.core.api.service.IdmRoleService) Autowired(org.springframework.beans.factory.annotation.Autowired) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) StringUtils(org.apache.commons.lang3.StringUtils) IdmRoleFormAttributeService(eu.bcvsolutions.idm.core.api.service.IdmRoleFormAttributeService) ArrayList(java.util.ArrayList) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) List(java.util.List) AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) IdmFormDefinitionService(eu.bcvsolutions.idm.core.eav.api.service.IdmFormDefinitionService) IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) IdmGenerateValueDto(eu.bcvsolutions.idm.core.api.dto.IdmGenerateValueDto) IdmRoleFormAttributeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleFormAttributeFilter) Assert(org.springframework.util.Assert) AbstractValueGenerator(eu.bcvsolutions.idm.core.api.generator.AbstractValueGenerator) IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) ArrayList(java.util.ArrayList) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) UUID(java.util.UUID)

Example 18 with IdmGenerateValueDto

use of eu.bcvsolutions.idm.core.api.dto.IdmGenerateValueDto in project CzechIdMng by bcvsolutions.

the class TreeNodeCodeGeneratorTest method testDiacritics.

@Test
public void testDiacritics() {
    IdmTreeTypeDto type = getHelper().createTreeType();
    IdmTreeNodeDto node = new IdmTreeNodeDto();
    node.setTreeType(type.getId());
    node.setName("abcdřřřžžžééé");
    IdmGenerateValueDto generator = this.createGenerator(getDtoType(), getGeneratorType(), null, 1, null);
    IdmTreeNodeDto generated = valueGeneratorManager.generate(node);
    assertNotNull(generated.getCode());
    assertEquals("abcdrrrzzzeee", generated.getCode());
    generatedAttributeService.delete(generator);
}
Also used : IdmTreeTypeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto) IdmGenerateValueDto(eu.bcvsolutions.idm.core.api.dto.IdmGenerateValueDto) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) Test(org.junit.Test) AbstractGeneratorTest(eu.bcvsolutions.idm.core.api.generator.AbstractGeneratorTest)

Example 19 with IdmGenerateValueDto

use of eu.bcvsolutions.idm.core.api.dto.IdmGenerateValueDto in project CzechIdMng by bcvsolutions.

the class IdentityUsernameGeneratorTest method generateWithMoreGeneratorAndDisable.

@Test
public void generateWithMoreGeneratorAndDisable() {
    String firstName = "firstName" + System.currentTimeMillis();
    String lastName = "lastName" + System.currentTimeMillis();
    String newFirstName = "f";
    String newLastName = "l";
    ValueGeneratorDto generator = getGenerator();
    // first - this generator will be generate username
    this.createGenerator(getDtoType(), getGeneratorType(), this.createConfiguration(generator.getFormDefinition(), ImmutableMap.of(IdentityUsernameGenerator.FIRST_NAME_CHARACTERS_COUNT, "1", IdentityUsernameGenerator.LAST_NAME_CHARACTERS_COUNT, "1", IdentityUsernameGenerator.CONNECTING_CHARACTER, "*", IdentityUsernameGenerator.FIRST_NAME_FIRST, Boolean.TRUE.toString())), 1, null);
    // second
    IdmGenerateValueDto createGenerator = this.createGenerator(getDtoType(), getGeneratorType(), this.createConfiguration(generator.getFormDefinition(), ImmutableMap.of(IdentityUsernameGenerator.FIRST_NAME_CHARACTERS_COUNT, "5", IdentityUsernameGenerator.CONNECTING_CHARACTER, "-", IdentityUsernameGenerator.FIRST_NAME_FIRST, Boolean.TRUE.toString())), 10, null);
    createGenerator.setDisabled(true);
    this.generatedAttributeService.save(createGenerator);
    // the last
    createGenerator = this.createGenerator(getDtoType(), getGeneratorType(), this.createConfiguration(generator.getFormDefinition(), ImmutableMap.of(IdentityUsernameGenerator.CONNECTING_CHARACTER, ".", IdentityUsernameGenerator.FIRST_NAME_FIRST, Boolean.TRUE.toString())), 20, null);
    createGenerator.setDisabled(true);
    this.generatedAttributeService.save(createGenerator);
    IdmIdentityDto identityDto = new IdmIdentityDto();
    identityDto.setFirstName(firstName.toString());
    identityDto.setLastName(lastName.toString());
    IdmIdentityDto generatedDto = identityService.save(identityDto);
    assertEquals(identityDto.getLastName(), generatedDto.getLastName());
    assertEquals(identityDto.getFirstName(), generatedDto.getFirstName());
    assertNotNull(generatedDto.getUsername());
    assertEquals(newFirstName + "*" + newLastName, generatedDto.getUsername());
}
Also used : ValueGeneratorDto(eu.bcvsolutions.idm.core.api.dto.ValueGeneratorDto) IdmGenerateValueDto(eu.bcvsolutions.idm.core.api.dto.IdmGenerateValueDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) Test(org.junit.Test) AbstractGeneratorTest(eu.bcvsolutions.idm.core.api.generator.AbstractGeneratorTest)

Example 20 with IdmGenerateValueDto

use of eu.bcvsolutions.idm.core.api.dto.IdmGenerateValueDto in project CzechIdMng by bcvsolutions.

the class IdentityEmailGeneratorIntegrationTest method testDisable.

@Test
public void testDisable() {
    String emailSuffix = "ex.tld";
    String emailSuffix1 = "@test.tld";
    String emailSuffix2 = "bcvsolutions.tld";
    String username = this.getHelper().createName();
    IdmIdentityDto identityDto = new IdmIdentityDto();
    identityDto.setFirstName(this.getHelper().createName());
    identityDto.setLastName(this.getHelper().createName());
    identityDto.setUsername(username);
    ValueGeneratorDto generator = getGenerator();
    // first - this generator will be generate email
    this.createGenerator(getDtoType(), getGeneratorType(), this.createConfiguration(generator.getFormDefinition(), ImmutableMap.of(IdentityEmailGenerator.EMAIL_SUFFIX, emailSuffix, IdentityEmailGenerator.GENERATE_FROM_USERNAME, Boolean.TRUE.toString())), 10, null);
    // second
    IdmGenerateValueDto createGenerator = this.createGenerator(getDtoType(), getGeneratorType(), this.createConfiguration(generator.getFormDefinition(), ImmutableMap.of(IdentityEmailGenerator.EMAIL_SUFFIX, emailSuffix1, IdentityEmailGenerator.GENERATE_FROM_USERNAME, Boolean.TRUE.toString())), 20, null);
    createGenerator.setDisabled(true);
    this.generatedAttributeService.save(createGenerator);
    // the last
    createGenerator = this.createGenerator(getDtoType(), getGeneratorType(), this.createConfiguration(generator.getFormDefinition(), ImmutableMap.of(IdentityEmailGenerator.EMAIL_SUFFIX, emailSuffix2)), 30, null);
    createGenerator.setDisabled(true);
    this.generatedAttributeService.save(createGenerator);
    IdmIdentityDto generatedDto = valueGeneratorManager.generate(identityDto);
    assertNotNull(generatedDto.getEmail());
    assertEquals(username + "@" + emailSuffix, generatedDto.getEmail());
}
Also used : ValueGeneratorDto(eu.bcvsolutions.idm.core.api.dto.ValueGeneratorDto) IdmGenerateValueDto(eu.bcvsolutions.idm.core.api.dto.IdmGenerateValueDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) Test(org.junit.Test) AbstractGeneratorTest(eu.bcvsolutions.idm.core.api.generator.AbstractGeneratorTest)

Aggregations

IdmGenerateValueDto (eu.bcvsolutions.idm.core.api.dto.IdmGenerateValueDto)20 AbstractGeneratorTest (eu.bcvsolutions.idm.core.api.generator.AbstractGeneratorTest)10 Test (org.junit.Test)10 IdmTreeNodeDto (eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto)8 IdmTreeTypeDto (eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto)8 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)6 ValueGeneratorDto (eu.bcvsolutions.idm.core.api.dto.ValueGeneratorDto)2 AbstractValueGenerator (eu.bcvsolutions.idm.core.api.generator.AbstractValueGenerator)2 IdmFormAttributeDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto)2 IdentityFormDefaultValueGenerator (eu.bcvsolutions.idm.core.generator.identity.IdentityFormDefaultValueGenerator)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 StringUtils (org.apache.commons.lang3.StringUtils)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 Assert (org.springframework.util.Assert)2 ConfigurationMap (eu.bcvsolutions.idm.core.api.domain.ConfigurationMap)1 CoreResultCode (eu.bcvsolutions.idm.core.api.domain.CoreResultCode)1 AbstractDto (eu.bcvsolutions.idm.core.api.dto.AbstractDto)1 IdmConceptRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto)1