IdentityFormDefaultValueGenerator extends AbstractValueGenerator<IdmIdentityDto> { private IdmFormDefinitionDto getFormDefinition(IdmGenerateValueDto valueGenerator) { UUID formDefinitionUuid = getFormDefinitionUuid(valueGenerator); if (formDefinitionUuid != null) { IdmFormDefinitionDto formDefinitionDto = formService.getDefinition(formDefinitionUuid); if (formDefinitionDto != null) { return formDefinitionDto; } } return null; }  @Override String getName(); @Override IdmIdentityDto generate(IdmIdentityDto dto, IdmGenerateValueDto valueGenerator); @Override List<String> getPropertyNames(); @Override List<IdmFormAttributeDto> getFormAttributes(); static final String GENERATOR_NAME; static String FORM_DEFINITION_UUID; static String REGEX_MULTIPLE_VALUES; }
@Test public void testGreenLineWithSave() { IdmIdentityDto identity = new IdmIdentityDto(); identity.setUsername(getHelper().createName()); IdmFormDefinitionDto formDefinition = createFormDefinition(); String attrCode1 = getHelper().createName(); String attrDefaultValue1 = "true"; IdmFormAttributeDto att1 = createAttribute(attrCode1, attrDefaultValue1, PersistentType.BOOLEAN, formDefinition.getId()); String attrCode2 = getHelper().createName(); String attrDefaultValue2 = "A"; IdmFormAttributeDto att2 = createAttribute(attrCode2, attrDefaultValue2, PersistentType.CHAR, formDefinition.getId()); List<IdmFormInstanceDto> eavs = identity.getEavs(); assertTrue(eavs.isEmpty()); ValueGeneratorDto generator = getGenerator(); this.createGenerator(getDtoType(), getGeneratorType(), this.createConfiguration(generator.getFormDefinition(), null), 1, null); identity = identityService.save(identity); eavs = identity.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()); }
@Test public void testOnlySpecificFormDefinition() { IdmIdentityDto identity = new IdmIdentityDto(); identity.setUsername(getHelper().createName()); IdmFormDefinitionDto formDefinition = createFormDefinition(); String attrCode1 = getHelper().createName(); String attrDefaultValue1 = "true"; IdmFormAttributeDto att1 = createAttribute(attrCode1, attrDefaultValue1, PersistentType.BOOLEAN, formDefinition.getId()); String attrCode2 = getHelper().createName(); String attrDefaultValue2 = "A"; IdmFormAttributeDto att2 = createAttribute(attrCode2, attrDefaultValue2, PersistentType.CHAR, formDefinition.getId()); List<IdmFormInstanceDto> eavs = identity.getEavs(); assertTrue(eavs.isEmpty()); ValueGeneratorDto generator = getGenerator(); this.createGenerator(getDtoType(), getGeneratorType(), this.createConfiguration(generator.getFormDefinition(), ImmutableMap.of( IdentityFormDefaultValueGenerator.FORM_DEFINITION_UUID, formDefinition.getId().toString())), 1, null); identity = identityService.save(identity); eavs = identity.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()); }
@Test public void testRegenerateOff() { IdmIdentityDto identity = new IdmIdentityDto(); identity.setUsername(getHelper().createName()); UUID formDefinitionId = createFormDefinition().getId(); String attrCode1 = getHelper().createName(); String attrDefaultValue1 = "true"; IdmFormAttributeDto att1 = createAttribute(attrCode1, attrDefaultValue1, PersistentType.BOOLEAN, formDefinitionId); String attrCode2 = getHelper().createName(); String attrDefaultValue2 = "A"; IdmFormAttributeDto att2 = createAttribute(attrCode2, attrDefaultValue2, PersistentType.CHAR, formDefinitionId); List<IdmFormInstanceDto> eavs = identity.getEavs(); assertTrue(eavs.isEmpty()); ValueGeneratorDto generator = getGenerator(); this.createGenerator(getDtoType(), getGeneratorType(), this.createConfiguration(generator.getFormDefinition(), null), 1, Boolean.FALSE); IdmFormDefinitionDto formDefinition = formDefinitionService.get(formDefinitionId); IdmFormInstanceDto formInstance = new IdmFormInstanceDto(); formInstance.setFormDefinition(formDefinition); String givenNewValue = "false"; List<IdmFormValueDto> givenValues = new ArrayList<>(); IdmFormValueDto givenValue = new IdmFormValueDto(att1); givenValue.setValue(givenNewValue); givenValues.add(givenValue); formInstance.setValues(givenValues); eavs.add(formInstance); identity.setEavs(eavs); identity = identityService.save(identity); eavs = identity.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(givenNewValue, 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()); }
@Test public void testRegenerateOn() { IdmIdentityDto identity = new IdmIdentityDto(); identity.setUsername(getHelper().createName()); IdmFormDefinitionDto formDefinition = createFormDefinition(); String attrCode1 = getHelper().createName(); String attrDefaultValue1 = UUID.randomUUID().toString(); IdmFormAttributeDto att1 = createAttribute(attrCode1, attrDefaultValue1, PersistentType.UUID, formDefinition.getId()); String attrCode2 = getHelper().createName(); String attrDefaultValue2 = "100"; IdmFormAttributeDto att2 = createAttribute(attrCode2, attrDefaultValue2, PersistentType.INT, formDefinition.getId()); List<IdmFormInstanceDto> eavs = identity.getEavs(); assertTrue(eavs.isEmpty()); ValueGeneratorDto generator = getGenerator(); this.createGenerator(getDtoType(), getGeneratorType(), this.createConfiguration(generator.getFormDefinition(), null), 1, null); IdmFormInstanceDto formInstance = new IdmFormInstanceDto(); formInstance.setFormDefinition(formDefinition); String givenNewValue = UUID.randomUUID().toString(); List<IdmFormValueDto> givenValues = new ArrayList<>(); IdmFormValueDto givenValue = new IdmFormValueDto(att1); givenValue.setValue(givenNewValue); givenValues.add(givenValue); formInstance.setValues(givenValues); eavs.add(formInstance); identity.setEavs(eavs); identity = identityService.save(identity); eavs = identity.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()); }
@Test public void testNoDefaultValues() { IdmIdentityDto identity = new IdmIdentityDto(); identity.setUsername(getHelper().createName()); UUID formDefinitionId = createFormDefinition().getId(); String attrCode1 = getHelper().createName(); IdmFormAttributeDto att1 = createAttribute(attrCode1, null, PersistentType.UUID, formDefinitionId); String attrCode2 = getHelper().createName(); IdmFormAttributeDto att2 = createAttribute(attrCode2, null, PersistentType.INT, formDefinitionId); List<IdmFormInstanceDto> eavs = identity.getEavs(); assertTrue(eavs.isEmpty()); ValueGeneratorDto generator = getGenerator(); this.createGenerator(getDtoType(), getGeneratorType(), this.createConfiguration(generator.getFormDefinition(), null), 1, null); IdmFormInstanceDto formInstance = new IdmFormInstanceDto(); IdmFormDefinitionDto formDefinition = formDefinitionService.get(formDefinitionId); formInstance.setFormDefinition(formDefinition); String givenNewValue = UUID.randomUUID().toString(); List<IdmFormValueDto> givenValues = new ArrayList<>(); IdmFormValueDto givenValue = new IdmFormValueDto(att1); givenValue.setValue(givenNewValue); givenValues.add(givenValue); formInstance.setValues(givenValues); eavs.add(formInstance); identity.setEavs(eavs); identity = identityService.save(identity); eavs = identity.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(givenNewValue, value.getValue().toString()); values = generatedEav.getValues().stream().filter(val -> val.getFormAttribute().equals(att2.getId())).collect(Collectors.toList()); assertEquals(0, values.size()); }