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);
}
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);
}
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);
}
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());
}
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());
}
Aggregations