Search in sources :

Example 1 with IdmRoleFormValue

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());
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) Root(javax.persistence.criteria.Root) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) Specification(org.springframework.data.jpa.domain.Specification) Predicate(javax.persistence.criteria.Predicate) Pageable(org.springframework.data.domain.Pageable) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) IdmRole(eu.bcvsolutions.idm.core.model.entity.IdmRole) IdmRoleFormValue(eu.bcvsolutions.idm.core.model.entity.eav.IdmRoleFormValue) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Aggregations

IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)1 IdmFormAttributeDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto)1 IdmFormDefinitionDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto)1 IdmRole (eu.bcvsolutions.idm.core.model.entity.IdmRole)1 IdmRoleFormValue (eu.bcvsolutions.idm.core.model.entity.eav.IdmRoleFormValue)1 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)1 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)1 CriteriaQuery (javax.persistence.criteria.CriteriaQuery)1 Predicate (javax.persistence.criteria.Predicate)1 Root (javax.persistence.criteria.Root)1 Test (org.junit.Test)1 Pageable (org.springframework.data.domain.Pageable)1 Specification (org.springframework.data.jpa.domain.Specification)1