use of eu.bcvsolutions.idm.core.eav.api.dto.InvalidFormAttributeDto in project CzechIdMng by bcvsolutions.
the class DefaultFormServiceIntegrationTest method testMinMaxStringValidation.
@Test
public void testMinMaxStringValidation() {
// prepare form definition a test saving form values
IdmFormAttributeDto attributeShortText = new IdmFormAttributeDto();
String attributeShortTextCode = getHelper().createName();
attributeShortText.setCode(attributeShortTextCode);
attributeShortText.setName(attributeShortTextCode);
attributeShortText.setPersistentType(PersistentType.SHORTTEXT);
attributeShortText.setMin(new BigDecimal("3"));
attributeShortText.setMax(new BigDecimal("5"));
IdmFormAttributeDto attributeText = new IdmFormAttributeDto();
String attributeTextCode = getHelper().createName();
attributeText.setCode(attributeTextCode);
attributeText.setName(attributeTextCode);
attributeText.setPersistentType(PersistentType.TEXT);
attributeText.setMin(new BigDecimal("6"));
attributeText.setMax(new BigDecimal("8"));
IdmFormDefinitionDto formDefinitionOne = formService.createDefinition(IdmIdentity.class.getCanonicalName(), getHelper().createName(), Lists.newArrayList(attributeShortText, attributeText));
attributeShortText = formDefinitionOne.getMappedAttributeByCode(attributeShortText.getCode());
attributeText = formDefinitionOne.getMappedAttributeByCode(attributeText.getCode());
//
IdmFormValueDto valueShortText = new IdmFormValueDto(attributeShortText);
IdmFormValueDto valueText = new IdmFormValueDto(attributeText);
//
IdmFormInstanceDto formInstance = new IdmFormInstanceDto();
formInstance.setFormDefinition(formDefinitionOne);
formInstance.setValues(Lists.newArrayList(valueShortText, valueText));
//
List<InvalidFormAttributeDto> validationErrors = formService.validate(formInstance);
//
Assert.assertTrue(validationErrors.isEmpty());
//
valueShortText.setShortTextValue("xx");
valueText.setStringValue("xxxxx");
//
validationErrors = formService.validate(formInstance);
Assert.assertEquals(2, validationErrors.size());
Assert.assertTrue(validationErrors.stream().allMatch(e -> e.getMinValue() != null));
Assert.assertTrue(validationErrors.stream().anyMatch(e -> e.getMinValue().equals(new BigDecimal("3")) && e.getAttributeCode().equals(attributeShortTextCode)));
Assert.assertTrue(validationErrors.stream().anyMatch(e -> e.getMinValue().equals(new BigDecimal("6")) && e.getAttributeCode().equals(attributeTextCode)));
//
valueShortText.setShortTextValue("xxxxxx");
valueText.setStringValue("xxxxxxxxx");
//
validationErrors = formService.validate(formInstance);
Assert.assertEquals(2, validationErrors.size());
Assert.assertTrue(validationErrors.stream().allMatch(e -> e.getMaxValue() != null));
Assert.assertTrue(validationErrors.stream().anyMatch(e -> e.getMaxValue().equals(new BigDecimal("5")) && e.getAttributeCode().equals(attributeShortTextCode)));
Assert.assertTrue(validationErrors.stream().anyMatch(e -> e.getMaxValue().equals(new BigDecimal("8")) && e.getAttributeCode().equals(attributeTextCode)));
//
valueShortText.setShortTextValue("xxxxx");
valueText.setStringValue("xxxxxxxx");
//
validationErrors = formService.validate(formInstance);
Assert.assertTrue(validationErrors.isEmpty());
//
valueShortText.setShortTextValue("xxx");
valueText.setStringValue("xxxxxx");
//
validationErrors = formService.validate(formInstance);
Assert.assertTrue(validationErrors.isEmpty());
}
use of eu.bcvsolutions.idm.core.eav.api.dto.InvalidFormAttributeDto in project CzechIdMng by bcvsolutions.
the class DefaultFormServiceIntegrationTest method testMinMaxValidation.
@Test
public void testMinMaxValidation() {
// prepare form definition a test saving form values
IdmFormAttributeDto attributeDouble = new IdmFormAttributeDto();
String attributeDoubleName = getHelper().createName();
attributeDouble.setCode(attributeDoubleName);
attributeDouble.setName(attributeDoubleName);
attributeDouble.setPersistentType(PersistentType.DOUBLE);
attributeDouble.setMin(new BigDecimal("0.5"));
attributeDouble.setMax(new BigDecimal("0.7"));
IdmFormAttributeDto attributeLong = new IdmFormAttributeDto();
String attributeLongName = getHelper().createName();
attributeLong.setCode(attributeLongName);
attributeLong.setName(attributeLongName);
attributeLong.setPersistentType(PersistentType.LONG);
attributeLong.setMin(new BigDecimal("10"));
attributeLong.setMax(new BigDecimal("20"));
IdmFormAttributeDto attributeInt = new IdmFormAttributeDto();
String attributeIntName = getHelper().createName();
attributeInt.setCode(attributeIntName);
attributeInt.setName(attributeIntName);
attributeInt.setPersistentType(PersistentType.INT);
attributeInt.setMin(new BigDecimal("10.1"));
attributeInt.setMax(new BigDecimal("20"));
IdmFormDefinitionDto formDefinitionOne = formService.createDefinition(IdmIdentity.class.getCanonicalName(), getHelper().createName(), Lists.newArrayList(attributeDouble, attributeInt, attributeLong));
attributeDouble = formDefinitionOne.getMappedAttributeByCode(attributeDouble.getCode());
attributeInt = formDefinitionOne.getMappedAttributeByCode(attributeInt.getCode());
attributeLong = formDefinitionOne.getMappedAttributeByCode(attributeLong.getCode());
//
IdmFormValueDto valueDouble = new IdmFormValueDto(attributeDouble);
IdmFormValueDto valueInt = new IdmFormValueDto(attributeInt);
IdmFormValueDto valueLong = new IdmFormValueDto(attributeLong);
//
IdmFormInstanceDto formInstance = new IdmFormInstanceDto();
formInstance.setFormDefinition(formDefinitionOne);
formInstance.setValues(Lists.newArrayList(valueDouble, valueInt, valueLong));
//
List<InvalidFormAttributeDto> validationErrors = formService.validate(formInstance);
//
Assert.assertTrue(validationErrors.isEmpty());
//
valueDouble.setDoubleValue(new BigDecimal("0.4"));
valueInt.setLongValue(4L);
valueLong.setLongValue(4L);
//
validationErrors = formService.validate(formInstance);
Assert.assertEquals(3, validationErrors.size());
Assert.assertTrue(validationErrors.stream().allMatch(e -> e.getMinValue() != null));
Assert.assertTrue(validationErrors.stream().anyMatch(e -> e.getMinValue().equals(new BigDecimal("0.5")) && e.getAttributeCode().equals(attributeDoubleName)));
Assert.assertTrue(validationErrors.stream().anyMatch(e -> e.getMinValue().equals(new BigDecimal("10.1")) && e.getAttributeCode().equals(attributeIntName)));
Assert.assertTrue(validationErrors.stream().anyMatch(e -> e.getMinValue().equals(new BigDecimal("10")) && e.getAttributeCode().equals(attributeLongName)));
//
valueDouble.setDoubleValue(new BigDecimal("0.8"));
valueInt.setLongValue(40L);
valueLong.setLongValue(40L);
//
validationErrors = formService.validate(formInstance);
Assert.assertEquals(3, validationErrors.size());
Assert.assertTrue(validationErrors.stream().allMatch(e -> e.getMaxValue() != null));
Assert.assertTrue(validationErrors.stream().anyMatch(e -> e.getMaxValue().equals(new BigDecimal("0.7")) && e.getAttributeCode().equals(attributeDoubleName)));
Assert.assertTrue(validationErrors.stream().anyMatch(e -> e.getMaxValue().equals(new BigDecimal("20")) && e.getAttributeCode().equals(attributeIntName)));
Assert.assertTrue(validationErrors.stream().anyMatch(e -> e.getMaxValue().equals(new BigDecimal("20")) && e.getAttributeCode().equals(attributeLongName)));
//
valueDouble.setDoubleValue(new BigDecimal("0.5"));
valueInt.setLongValue(11L);
valueLong.setLongValue(10L);
//
validationErrors = formService.validate(formInstance);
Assert.assertTrue(validationErrors.isEmpty());
//
valueDouble.setDoubleValue(new BigDecimal("0.7"));
valueInt.setLongValue(20L);
valueLong.setLongValue(20L);
//
validationErrors = formService.validate(formInstance);
Assert.assertTrue(validationErrors.isEmpty());
//
valueDouble.setDoubleValue(new BigDecimal("0.6"));
valueInt.setLongValue(15L);
valueLong.setLongValue(15L);
//
validationErrors = formService.validate(formInstance);
Assert.assertTrue(validationErrors.isEmpty());
}
use of eu.bcvsolutions.idm.core.eav.api.dto.InvalidFormAttributeDto in project CzechIdMng by bcvsolutions.
the class FormableValidateBasicFieldsProcessor method process.
@Override
public EventResult<FormableDto> process(EntityEvent<FormableDto> event) {
// saved dto
FormableDto savedDto = event.getContent();
//
IdmFormInstanceDto basicFields = formProjectionManager.getBasicFieldsInstance(savedDto);
if (basicFields != null) {
List<InvalidFormAttributeDto> errors = formService.validate(basicFields);
if (!errors.isEmpty()) {
throw new InvalidFormException(errors);
}
}
//
return new DefaultEventResult<>(event, this);
}
Aggregations