use of eu.bcvsolutions.idm.core.eav.api.dto.filter.IdmFormValueFilter in project CzechIdMng by bcvsolutions.
the class IdmFormValueControllerRestTest method testFindByDateValueTill.
@Test
public void testFindByDateValueTill() {
IdmFormValueDto value = prepareDto(PersistentType.DATETIME);
ZonedDateTime now = ZonedDateTime.now();
value.setDateValue(now);
IdmFormValueDto valueOne = createDto(value);
value = prepareDto(PersistentType.DATETIME);
value.setDateValue(now.plusDays(2));
createDto(value);
//
IdmFormValueFilter<?> filter = new IdmFormValueFilter<>();
filter.setDateValueTill(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())));
}
use of eu.bcvsolutions.idm.core.eav.api.dto.filter.IdmFormValueFilter in project CzechIdMng by bcvsolutions.
the class IdmFormValueControllerRestTest method testFindByShortTextValueLike.
@Test
public void testFindByShortTextValueLike() {
IdmFormValueDto value = prepareDto(PersistentType.SHORTTEXT);
String suffix = getHelper().createName();
value.setValue(getHelper().createName() + suffix);
IdmFormValueDto valueOne = createDto(value);
// other
createDto();
//
IdmFormValueFilter<?> filter = new IdmFormValueFilter<>();
filter.setShortTextValueLike(suffix);
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 testFindByPersistentType.
@Test
public void testFindByPersistentType() {
IdmFormValueDto value = prepareDto(PersistentType.TEXT);
String text = getHelper().createName();
value.setValue(text);
IdmFormValueDto valueOne = createDto(value);
// other
createDto();
//
IdmFormValueFilter<?> filter = new IdmFormValueFilter<>();
filter.setStringValue(text);
filter.setPersistentType(PersistentType.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 DefaultIdmFormAttributeService method deleteInternal.
@Override
@Transactional
@SuppressWarnings({ "rawtypes", "unchecked" })
public void deleteInternal(IdmFormAttributeDto dto) {
Assert.notNull(dto, "DTO is required.");
// attribute with filled values cannot be deleted
IdmFormValueFilter filter = new IdmFormValueFilter();
filter.setAttributeId(dto.getId());
formValueServices.getPlugins().forEach(formValueService -> {
if (formValueService.find(filter, PageRequest.of(0, 1)).getTotalElements() > 0) {
throw new ResultCodeException(CoreResultCode.FORM_ATTRIBUTE_DELETE_FAILED_HAS_VALUES, ImmutableMap.of("formAttribute", dto.getCode()));
}
});
//
// check rules for automatic role attributes
IdmAutomaticRoleAttributeRuleFilter automaticRoleRuleFilter = new IdmAutomaticRoleAttributeRuleFilter();
automaticRoleRuleFilter.setFormAttributeId(dto.getId());
long totalElements = automaticRoleAttributeService.find(automaticRoleRuleFilter, PageRequest.of(0, 1)).getTotalElements();
if (totalElements > 0) {
// some automatic roles use this attribute
throw new ResultCodeException(CoreResultCode.FORM_ATTRIBUTE_DELETE_FAILED_AUTOMATIC_ROLE_RULE_ASSIGNED, ImmutableMap.of("formAttribute", dto.getId()));
}
// Check on using this attribute on role (sub-definition)
if (dto.getId() != null) {
IdmRoleFormAttributeFilter roleFormAttributeFilter = new IdmRoleFormAttributeFilter();
roleFormAttributeFilter.setFormAttribute(dto.getId());
List<IdmRoleFormAttributeDto> attributes = roleFormAttributeService.find(roleFormAttributeFilter, PageRequest.of(0, 1)).getContent();
if (attributes.size() > 0) {
IdmRoleDto roleDto = DtoUtils.getEmbedded(attributes.get(0), IdmRoleFormAttribute_.role.getName(), IdmRoleDto.class);
throw new ResultCodeException(CoreResultCode.FORM_ATTRIBUTE_DELETE_FAILED_ROLE_ATTRIBUTE, ImmutableMap.of("definition", dto.getCode(), "role", roleDto.getCode()));
}
}
//
// Check rules requests for automatic role attributes. Deletes relation on this form attribute.
IdmAutomaticRoleAttributeRuleRequestFilter automaticRoleRuleRequestFilter = new IdmAutomaticRoleAttributeRuleRequestFilter();
automaticRoleRuleRequestFilter.setFormAttributeId(dto.getId());
List<IdmAutomaticRoleAttributeRuleRequestDto> ruleRequests = automaticRoleAttributeRequestService.find(automaticRoleRuleRequestFilter, null).getContent();
ruleRequests.forEach(rule -> {
rule.setFormAttribute(null);
automaticRoleAttributeRequestService.save(rule);
});
//
super.deleteInternal(dto);
}
use of eu.bcvsolutions.idm.core.eav.api.dto.filter.IdmFormValueFilter in project CzechIdMng by bcvsolutions.
the class DefaultFormServiceIntegrationTest method prepareDataAndFind.
private long prepareDataAndFind(Class<? extends AbstractEntity> type, AbstractDto owner) {
//
// create attribute
IdmFormAttributeDto attribute = new IdmFormAttributeDto();
String attributeName = getHelper().createName();
attribute.setCode(attributeName);
attribute.setName(attribute.getCode());
attribute.setPersistentType(PersistentType.SHORTTEXT);
//
// create definition
IdmFormDefinitionDto definition = formService.createDefinition(type, getHelper().createName(), Lists.newArrayList(attribute));
attribute = definition.getMappedAttributeByCode(attribute.getCode());
//
// save value
formService.saveValues(owner.getId(), type, attribute, Lists.newArrayList(FORM_VALUE_ONE));
//
// find
IdmFormValueFilter<?> filter = new IdmFormValueFilter<>();
filter.setDefinitionId(definition.getId());
Page<IdmFormValueDto> result = formService.findValues(filter, PageRequest.of(0, Integer.MAX_VALUE));
return result.getTotalElements();
}
Aggregations