Search in sources :

Example 1 with IdmIdentityContract

use of eu.bcvsolutions.idm.core.model.entity.IdmIdentityContract in project CzechIdMng by bcvsolutions.

the class DefaultIdmAutomaticRoleAttributeService method getCriteriaForRulesByContract.

/**
 * Return all criteria for given rules by contract
 * Compose all specification for identity/contract and rules
 *
 * @param automaticRoleId
 * @param rules
 * @param onlyNew
 * @param passed
 * @param identityId
 * @param contractId
 * @return
 */
private Specification<IdmIdentityContract> getCriteriaForRulesByContract(UUID automaticRoleId, List<IdmAutomaticRoleAttributeRuleDto> rules, boolean passed, UUID contractId) {
    Specification<IdmIdentityContract> criteria = new Specification<IdmIdentityContract>() {

        @Override
        public Predicate toPredicate(Root<IdmIdentityContract> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
            List<Predicate> predicates = new ArrayList<>();
            // 
            if (contractId != null) {
                predicates.add(cb.equal(root.get(AbstractEntity_.id), contractId));
            }
            // 
            Subquery<IdmIdentityRole> subquery = query.subquery(IdmIdentityRole.class);
            Root<IdmIdentityRole> subRoot = subquery.from(IdmIdentityRole.class);
            subquery.select(subRoot);
            subquery.where(cb.and(// correlation attr
            cb.equal(subRoot.get(IdmIdentityRole_.identityContract), root), cb.equal(subRoot.get(IdmIdentityRole_.automaticRole).get(IdmAutomaticRole_.id), automaticRoleId)));
            // 
            if (passed) {
                predicates.add(cb.isNull(subquery));
            } else {
                predicates.add(cb.exists(subquery));
            }
            // 
            List<Predicate> predicatesFromRules = new ArrayList<>();
            for (IdmAutomaticRoleAttributeRuleDto rule : rules) {
                // compose all predicate from rules
                Predicate predicate = DefaultIdmAutomaticRoleAttributeService.this.getPredicateForRuleByContract(rule, root, query, cb, passed);
                predicatesFromRules.add(predicate);
            }
            // 
            if (!predicatesFromRules.isEmpty()) {
                if (!passed) {
                    // if we find all rules that not pass is necessary add 'or' statement between predicates from rules
                    Predicate or = cb.or(predicatesFromRules.toArray(new Predicate[predicatesFromRules.size()]));
                    predicates.add(or);
                } else {
                    predicates.addAll(predicatesFromRules);
                }
            }
            return query.where(predicates.toArray(new Predicate[predicates.size()])).getRestriction();
        }
    };
    return criteria;
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Root(javax.persistence.criteria.Root) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) ArrayList(java.util.ArrayList) Specification(org.springframework.data.jpa.domain.Specification) Predicate(javax.persistence.criteria.Predicate) IdmIdentityRole(eu.bcvsolutions.idm.core.model.entity.IdmIdentityRole) IdmAutomaticRoleAttributeRuleDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleDto) IdmIdentityContract(eu.bcvsolutions.idm.core.model.entity.IdmIdentityContract)

Example 2 with IdmIdentityContract

use of eu.bcvsolutions.idm.core.model.entity.IdmIdentityContract in project CzechIdMng by bcvsolutions.

the class DefaultIdmAutomaticRoleAttributeService method getRulesForContract.

@Override
public Set<AbstractIdmAutomaticRoleDto> getRulesForContract(boolean pass, AutomaticRoleAttributeRuleType type, UUID contractId) {
    Set<AbstractIdmAutomaticRoleDto> automaticRoles = new HashSet<>();
    // 
    // iterate trough all automatic role that has at least one rule and isn't in concept state
    Page<IdmAutomaticRoleAttributeDto> automaticRolesToProcess = this.findAllToProcess(type, new PageRequest(0, PROCESS_ROLE_SIZE));
    while (automaticRolesToProcess.hasContent()) {
        // all found roles it will has rules and will not be in concept state
        for (IdmAutomaticRoleAttributeDto automaticRole : automaticRolesToProcess) {
            List<IdmAutomaticRoleAttributeRuleDto> allRulesForAutomaticRole = automaticRoleAttributeRuleService.findAllRulesForAutomaticRole(automaticRole.getId());
            // 
            Specification<IdmIdentityContract> criteria = this.getCriteriaForRulesByContract(automaticRole.getId(), allRulesForAutomaticRole, pass, contractId);
            boolean result = !identityContractRepository.findAll(criteria).isEmpty();
            if (result) {
                automaticRoles.add(automaticRole);
            }
        }
        // 
        if (automaticRolesToProcess.hasNext()) {
            automaticRolesToProcess = this.findAllToProcess(type, automaticRolesToProcess.nextPageable());
        } else {
            break;
        }
    }
    // 
    return automaticRoles;
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) AbstractIdmAutomaticRoleDto(eu.bcvsolutions.idm.core.api.dto.AbstractIdmAutomaticRoleDto) IdmAutomaticRoleAttributeRuleDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleDto) IdmIdentityContract(eu.bcvsolutions.idm.core.model.entity.IdmIdentityContract) HashSet(java.util.HashSet) IdmAutomaticRoleAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto)

Example 3 with IdmIdentityContract

use of eu.bcvsolutions.idm.core.model.entity.IdmIdentityContract in project CzechIdMng by bcvsolutions.

the class IdentityContractSecurityTest method deleteWorkPositions.

@Test
public void deleteWorkPositions() {
    SecurityMockMvcRequestPostProcessors.securityContext(null);
    IdmIdentityDto user = identityService.getByUsername("kopr");
    List<IdmIdentityContract> pages = identityContractRepository.findAllByIdentity_Id(user.getId(), null);
    Serializable positionId = null;
    for (IdmIdentityContract position : pages) {
        positionId = position.getId();
        break;
    }
    int status = 0;
    Exception ex = null;
    try {
        status = getMockMvc().perform(delete(BaseDtoController.BASE_PATH + "/identity-contracts/" + positionId).contentType(MediaType.APPLICATION_JSON)).andReturn().getResponse().getStatus();
    } catch (Exception e) {
        ex = e;
    }
    assertNull(ex);
    assertEquals(403, status);
    ex = null;
    status = 0;
    try {
        status = getMockMvc().perform(delete(BaseDtoController.BASE_PATH + "/identity-contracts/" + positionId).contentType(MediaType.APPLICATION_JSON).with(authentication(getAuthentication()))).andReturn().getResponse().getStatus();
    } catch (Exception e) {
        ex = e;
    }
    assertNull(ex);
    assertEquals(204, status);
    logout();
}
Also used : Serializable(java.io.Serializable) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityContract(eu.bcvsolutions.idm.core.model.entity.IdmIdentityContract) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) AbstractRestTest(eu.bcvsolutions.idm.test.api.AbstractRestTest) Test(org.junit.Test)

Example 4 with IdmIdentityContract

use of eu.bcvsolutions.idm.core.model.entity.IdmIdentityContract in project CzechIdMng by bcvsolutions.

the class DefaultIdmIdentityContractServiceUnitTest method testPrimeContractWithWorkingPosition.

@Test
public void testPrimeContractWithWorkingPosition() {
    List<IdmIdentityContract> contracts = new ArrayList<>();
    IdmIdentityContract contractWithPosition = new IdmIdentityContract(UUID.randomUUID());
    contractWithPosition.setMain(false);
    IdmTreeNode workPosition = new IdmTreeNode();
    workPosition.setTreeType(new IdmTreeType());
    contractWithPosition.setWorkPosition(workPosition);
    // 
    IdmIdentityContract otherContract = new IdmIdentityContract(UUID.randomUUID());
    otherContract.setMain(false);
    contracts.add(contractWithPosition);
    contracts.add(otherContract);
    // 
    when(repository.findAllByIdentity_Id(any(UUID.class), any())).thenReturn(contracts);
    when(treeConfiguration.getDefaultType()).thenReturn(null);
    // 
    Assert.assertEquals(contractWithPosition.getId(), service.getPrimeContract(UUID.randomUUID()).getId());
}
Also used : IdmTreeNode(eu.bcvsolutions.idm.core.model.entity.IdmTreeNode) ArrayList(java.util.ArrayList) UUID(java.util.UUID) IdmIdentityContract(eu.bcvsolutions.idm.core.model.entity.IdmIdentityContract) IdmTreeType(eu.bcvsolutions.idm.core.model.entity.IdmTreeType) Test(org.junit.Test) AbstractUnitTest(eu.bcvsolutions.idm.test.api.AbstractUnitTest)

Example 5 with IdmIdentityContract

use of eu.bcvsolutions.idm.core.model.entity.IdmIdentityContract in project CzechIdMng by bcvsolutions.

the class DefaultIdmIdentityContractServiceUnitTest method testOtherMainContractByFilledValidFrom.

@Test
public void testOtherMainContractByFilledValidFrom() {
    List<IdmIdentityContract> contracts = new ArrayList<>();
    IdmIdentityContract oneContract = new IdmIdentityContract(UUID.randomUUID());
    oneContract.setValidFrom(new LocalDate());
    oneContract.setMain(false);
    IdmIdentityContract twoContract = new IdmIdentityContract(UUID.randomUUID());
    twoContract.setMain(false);
    contracts.add(twoContract);
    contracts.add(oneContract);
    // 
    when(repository.findAllByIdentity_Id(any(UUID.class), any())).thenReturn(contracts);
    when(treeConfiguration.getDefaultType()).thenReturn(null);
    // 
    Assert.assertEquals(oneContract.getId(), service.getPrimeContract(UUID.randomUUID()).getId());
}
Also used : ArrayList(java.util.ArrayList) UUID(java.util.UUID) LocalDate(org.joda.time.LocalDate) IdmIdentityContract(eu.bcvsolutions.idm.core.model.entity.IdmIdentityContract) Test(org.junit.Test) AbstractUnitTest(eu.bcvsolutions.idm.test.api.AbstractUnitTest)

Aggregations

IdmIdentityContract (eu.bcvsolutions.idm.core.model.entity.IdmIdentityContract)14 ArrayList (java.util.ArrayList)9 Test (org.junit.Test)9 AbstractUnitTest (eu.bcvsolutions.idm.test.api.AbstractUnitTest)8 UUID (java.util.UUID)8 IdmIdentity (eu.bcvsolutions.idm.core.model.entity.IdmIdentity)3 LocalDate (org.joda.time.LocalDate)3 IdmAutomaticRoleAttributeRuleDto (eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleDto)2 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)2 IdmAuthorityChange (eu.bcvsolutions.idm.core.model.entity.IdmAuthorityChange)2 IdmTreeNode (eu.bcvsolutions.idm.core.model.entity.IdmTreeNode)2 IdmTreeType (eu.bcvsolutions.idm.core.model.entity.IdmTreeType)2 Predicate (javax.persistence.criteria.Predicate)2 Root (javax.persistence.criteria.Root)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 AbstractIdmAutomaticRoleDto (eu.bcvsolutions.idm.core.api.dto.AbstractIdmAutomaticRoleDto)1 IdmAutomaticRoleAttributeDto (eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto)1 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)1 IdmTreeTypeDto (eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto)1 IdmFormAttributeDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto)1