use of eu.bcvsolutions.idm.core.model.entity.eav.IdmRoleFormValue in project CzechIdMng by bcvsolutions.
the class DefaultFormServiceItegrationTest method findOwnerByCriteria.
@Test
public void findOwnerByCriteria() {
IdmRoleDto owner = helper.createRole();
IdmRoleDto ownerTwo = helper.createRole();
IdmFormDefinitionDto formDefinition = formService.getDefinition(IdmRole.class);
IdmFormAttributeDto attribute = formDefinition.getFormAttributes().get(0);
//
formService.saveValues(owner.getId(), IdmRole.class, attribute, Lists.newArrayList("test"));
formService.saveValues(ownerTwo.getId(), IdmRole.class, attribute, Lists.newArrayList("test2"));
Specification<IdmRole> criteria = new Specification<IdmRole>() {
public Predicate toPredicate(Root<IdmRole> root, CriteriaQuery<?> query, CriteriaBuilder builder) {
Subquery<IdmRoleFormValue> subquery = query.subquery(IdmRoleFormValue.class);
Root<IdmRoleFormValue> subRoot = subquery.from(IdmRoleFormValue.class);
subquery.select(subRoot);
Predicate predicate = builder.and(builder.equal(subRoot.get(IdmRoleFormValue_.owner), root), builder.equal(subRoot.get(IdmRoleFormValue_.formAttribute).get(IdmFormAttribute_.id), attribute.getId()), builder.equal(subRoot.get(IdmRoleFormValue_.stringValue), "test"));
subquery.where(predicate);
//
return query.where(builder.exists(subquery)).getRestriction();
}
};
List<IdmRole> roles = roleRepository.findAll(criteria, (Pageable) null).getContent();
assertEquals(1, roles.size());
assertEquals(owner.getId(), roles.get(0).getId());
}
Aggregations