use of eu.bcvsolutions.idm.core.eav.api.dto.filter.IdmFormValueFilter in project CzechIdMng by bcvsolutions.
the class FormAttributeValidateProcessor method process.
@Override
public EventResult<IdmFormAttributeDto> process(EntityEvent<IdmFormAttributeDto> event) {
IdmFormAttributeDto dto = event.getContent();
IdmFormAttributeDto original = event.getOriginalSource();
// just for sure - wrong event type can be provided manually
if (original == null) {
return new DefaultEventResult<>(event, this);
}
//
boolean persistentTypeChanged = original.getPersistentType() != dto.getPersistentType();
boolean confidentialChanged = original.isConfidential() != dto.isConfidential();
if (!persistentTypeChanged && !confidentialChanged) {
return new DefaultEventResult<>(event, this);
}
//
// Change persistent type is possible, only if no form values for this attribute is persisted.
IdmFormValueFilter<FormableEntity> filter = new IdmFormValueFilter<>();
filter.setAttributeId(dto.getId());
try {
if (formService.findValues(filter, PageRequest.of(0, 1)).getTotalElements() > 0) {
throwException(dto.getCode(), persistentTypeChanged, confidentialChanged, null);
}
} catch (ResultCodeException ex) {
// some form definition cannot have owner specified - drop and create attribute is supported only
throwException(dto.getCode(), persistentTypeChanged, confidentialChanged, ex);
}
//
return new DefaultEventResult<>(event, this);
}
use of eu.bcvsolutions.idm.core.eav.api.dto.filter.IdmFormValueFilter in project CzechIdMng by bcvsolutions.
the class IdmFormValueControllerRestTest method testFindByBooleanValue.
@Test
public void testFindByBooleanValue() {
IdmFormValueDto value = prepareDto(PersistentType.BOOLEAN);
value.setBooleanValue(true);
IdmFormValueDto valueOne = createDto(value);
value = prepareDto(PersistentType.BOOLEAN);
value.setBooleanValue(false);
// other
createDto(value);
//
IdmFormValueFilter<?> filter = new IdmFormValueFilter<>();
filter.setBooleanValue(true);
filter.setTransactionId(TransactionContextHolder.getContext().getTransactionId());
List<IdmFormValueDto> results = find(filter);
//
Assert.assertEquals(1, results.size());
Assert.assertTrue(results.stream().anyMatch(r -> r.getId().equals(valueOne.getId())));
}
use of eu.bcvsolutions.idm.core.eav.api.dto.filter.IdmFormValueFilter in project CzechIdMng by bcvsolutions.
the class IdmFormValueControllerRestTest method testFindByLongValue.
@Test
public void testFindByLongValue() {
IdmFormValueDto value = prepareDto(PersistentType.LONG);
value.setLongValue(1L);
IdmFormValueDto valueOne = createDto(value);
value = prepareDto(PersistentType.LONG);
value.setLongValue(2L);
// other
createDto(value);
//
IdmFormValueFilter<?> filter = new IdmFormValueFilter<>();
filter.setLongValue(1L);
filter.setTransactionId(TransactionContextHolder.getContext().getTransactionId());
List<IdmFormValueDto> results = find(filter);
//
Assert.assertEquals(1, results.size());
Assert.assertTrue(results.stream().anyMatch(r -> r.getId().equals(valueOne.getId())));
}
use of eu.bcvsolutions.idm.core.eav.api.dto.filter.IdmFormValueFilter in project CzechIdMng by bcvsolutions.
the class IdmFormValueControllerRestTest method testFindByShortTextValue.
@Test
public void testFindByShortTextValue() {
IdmFormValueDto value = prepareDto(PersistentType.SHORTTEXT);
String text = getHelper().createName();
value.setValue(text);
IdmFormValueDto valueOne = createDto(value);
// other
createDto();
//
IdmFormValueFilter<?> filter = new IdmFormValueFilter<>();
filter.setShortTextValue(text);
List<IdmFormValueDto> results = find(filter);
//
Assert.assertEquals(1, results.size());
Assert.assertTrue(results.stream().anyMatch(r -> r.getId().equals(valueOne.getId())));
}
use of eu.bcvsolutions.idm.core.eav.api.dto.filter.IdmFormValueFilter in project CzechIdMng by bcvsolutions.
the class IdmFormValueControllerRestTest method testFindByDateValueFrom.
@Test
public void testFindByDateValueFrom() {
IdmFormValueDto value = prepareDto(PersistentType.DATETIME);
ZonedDateTime now = ZonedDateTime.now();
value.setDateValue(now);
createDto(value);
value = prepareDto(PersistentType.DATETIME);
value.setDateValue(now.plusDays(2));
IdmFormValueDto valueOne = createDto(value);
//
IdmFormValueFilter<?> filter = new IdmFormValueFilter<>();
filter.setDateValueFrom(now.plusDays(1));
filter.setTransactionId(TransactionContextHolder.getContext().getTransactionId());
List<IdmFormValueDto> results = find(filter);
//
Assert.assertEquals(1, results.size());
Assert.assertTrue(results.stream().anyMatch(r -> r.getId().equals(valueOne.getId())));
}
Aggregations