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;
}
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;
}
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();
}
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());
}
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());
}
Aggregations