IdentityRoleFormDefaultValueGenerator extends AbstractRoleParametrizationFormDefaultValueGenerator<IdmIdentityRoleDto> { @Override public IdmIdentityRoleDto generate(IdmIdentityRoleDto dto, IdmGenerateValueDto valueGenerator) { Assert.notNull(dto, "DTO is required."); Assert.notNull(valueGenerator, "Value generator is required."); UUID roleId = dto.getRole(); IdmRoleDto roleDto = null; if (roleId == null) { return dto; } else { roleDto = roleService.get(roleId); } if (roleDto == null) { return dto; } List<IdmFormInstanceDto> existingEavs = dto.getEavs(); IdmFormInstanceDto eavs = getDefaultValuesByRoleDefinition(roleDto, valueGenerator, existingEavs.isEmpty() ? null : existingEavs.get(0), dto); if (eavs == null) { return dto; } dto.getEavs().clear(); dto.getEavs().add(eavs); return dto; }  @Override String getName(); @Override IdmIdentityRoleDto generate(IdmIdentityRoleDto dto, IdmGenerateValueDto valueGenerator); static final String GENERATOR_NAME; }
@Test public void testGreenLine() { IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null); IdmRoleDto role = getHelper().createRole(); IdmIdentityContractDto primeContract = getHelper().getPrimeContract(identity); IdmFormDefinitionDto formDefinition = createFormDefinition(); role.setIdentityRoleAttributeDefinition(formDefinition.getId()); role = roleService.save(role); String attrCode1 = getHelper().createName(); String attrDefaultValue1 = "100200"; IdmFormAttributeDto att1 = createAttribute(attrCode1, attrDefaultValue1, PersistentType.LONG, formDefinition.getId()); roleFormAttributeService.addAttributeToSubdefintion(role, att1); String attrCode2 = getHelper().createName(); String attrDefaultValue2 = getHelper().createName() + getHelper().createName(); IdmFormAttributeDto att2 = createAttribute(attrCode2, attrDefaultValue2, PersistentType.SHORTTEXT, formDefinition.getId()); roleFormAttributeService.addAttributeToSubdefintion(role, att2); String attrCode3 = getHelper().createName(); IdmFormAttributeDto att3 = createAttribute(attrCode3, null, PersistentType.SHORTTEXT, formDefinition.getId()); roleFormAttributeService.addAttributeToSubdefintion(role, att3); IdmIdentityRoleDto identityRole = new IdmIdentityRoleDto(); identityRole.setIdentityContract(primeContract.getId()); identityRole.setRole(role.getId()); List<IdmFormInstanceDto> eavs = identityRole.getEavs(); assertTrue(eavs.isEmpty()); createGenerator(); identityRole = this.valueGeneratorManager.generate(identityRole); eavs = identityRole.getEavs(); assertFalse(eavs.isEmpty()); IdmFormInstanceDto generatedEav = eavs.stream() .filter(eav -> eav.getFormDefinition().getCode().equals(formDefinition.getCode())).findFirst() .orElse(null); assertNotNull(generatedEav); List<IdmFormValueDto> values = generatedEav.getValues().stream() .filter(val -> val.getFormAttribute().equals(att1.getId())).collect(Collectors.toList()); assertEquals(1, values.size()); IdmFormValueDto value = values.get(0); assertEquals(attrDefaultValue1, value.getValue().toString()); values = generatedEav.getValues().stream().filter(val -> val.getFormAttribute().equals(att2.getId())) .collect(Collectors.toList()); assertEquals(1, values.size()); value = values.get(0); assertEquals(attrDefaultValue2, value.getValue().toString()); values = generatedEav.getValues().stream().filter(val -> val.getFormAttribute().equals(att3.getId())) .collect(Collectors.toList()); assertEquals(0, values.size()); }
@Test public void testGivenValue() { String overrideValue = "text-" + System.currentTimeMillis(); IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null); IdmRoleDto role = getHelper().createRole(); IdmIdentityContractDto primeContract = getHelper().getPrimeContract(identity); IdmFormDefinitionDto formDefinition = createFormDefinition(); role.setIdentityRoleAttributeDefinition(formDefinition.getId()); role = roleService.save(role); String attrCode1 = getHelper().createName(); String attrDefaultValue1 = "666"; IdmFormAttributeDto att1 = createAttribute(attrCode1, attrDefaultValue1, PersistentType.LONG, formDefinition.getId()); roleFormAttributeService.addAttributeToSubdefintion(role, att1); String attrCode2 = getHelper().createName(); String attrDefaultValue2 = getHelper().createName() + getHelper().createName(); IdmFormAttributeDto att2 = createAttribute(attrCode2, attrDefaultValue2, PersistentType.SHORTTEXT, formDefinition.getId()); roleFormAttributeService.addAttributeToSubdefintion(role, att2); String attrCode3 = getHelper().createName(); IdmFormAttributeDto att3 = createAttribute(attrCode3, null, PersistentType.SHORTTEXT, formDefinition.getId()); roleFormAttributeService.addAttributeToSubdefintion(role, att3); IdmIdentityRoleDto identityRole = new IdmIdentityRoleDto(); identityRole.setIdentityContract(primeContract.getId()); identityRole.setRole(role.getId()); IdmFormInstanceDto formInstanceDto = new IdmFormInstanceDto(); formInstanceDto.setFormDefinition(formDefinition); IdmFormValueDto formValueDto = new IdmFormValueDto(); formValueDto.setFormAttribute(att2.getId()); formValueDto.setShortTextValue(overrideValue); formInstanceDto.setValues(Lists.newArrayList(formValueDto)); identityRole.getEavs().clear(); identityRole.getEavs().add(formInstanceDto); List<IdmFormInstanceDto> eavs = identityRole.getEavs(); assertFalse(eavs.isEmpty()); createGenerator(); identityRole = this.valueGeneratorManager.generate(identityRole); eavs = identityRole.getEavs(); assertFalse(eavs.isEmpty()); IdmFormInstanceDto generatedEav = eavs.stream() .filter(eav -> eav.getFormDefinition().getCode().equals(formDefinition.getCode())).findFirst() .orElse(null); assertNotNull(generatedEav); List<IdmFormValueDto> values = generatedEav.getValues().stream() .filter(val -> val.getFormAttribute().equals(att1.getId())).collect(Collectors.toList()); assertEquals(1, values.size()); IdmFormValueDto value = values.get(0); assertEquals(attrDefaultValue1, value.getValue().toString()); values = generatedEav.getValues().stream().filter(val -> val.getFormAttribute().equals(att2.getId())) .collect(Collectors.toList()); assertEquals(1, values.size()); value = values.get(0); assertNotEquals(attrDefaultValue2, value.getValue().toString()); assertEquals(overrideValue, value.getValue().toString()); values = generatedEav.getValues().stream().filter(val -> val.getFormAttribute().equals(att3.getId())) .collect(Collectors.toList()); assertEquals(0, values.size()); }