use of eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter in project CzechIdMng by bcvsolutions.
the class ProcessAllAutomaticRoleByAttributeTaskExecutor method processAutomaticRoleForContract.
/**
* Start recalculation for automatic role. All identity roles (newly added and removed) will be added by {@link IdmRoleRequestDto}.
* But role request is created for each contract twice. One for newly added and one for newly removed. This is now only solutions.
*
* @param automaticRolAttributeDto
*/
private void processAutomaticRoleForContract(IdmAutomaticRoleAttributeDto automaticRolAttributeDto) {
UUID automaticRoleId = automaticRolAttributeDto.getId();
//
// process contracts
List<UUID> newPassedContracts = automaticRoleAttributeService.getContractsForAutomaticRole(automaticRoleId, true, null).getContent();
List<UUID> newNotPassedContracts = automaticRoleAttributeService.getContractsForAutomaticRole(automaticRoleId, false, null).getContent();
//
boolean canContinue = true;
for (UUID contractId : newPassedContracts) {
// Concepts that will be added
List<IdmConceptRoleRequestDto> concepts = new ArrayList<IdmConceptRoleRequestDto>();
//
IdmIdentityContractDto contract = identityContractService.get(contractId);
//
IdmConceptRoleRequestDto concept = new IdmConceptRoleRequestDto();
concept.setIdentityContract(contract.getId());
concept.setValidFrom(contract.getValidFrom());
concept.setValidTill(contract.getValidTill());
concept.setRole(automaticRolAttributeDto.getRole());
concept.setAutomaticRole(automaticRoleId);
concept.setOperation(ConceptRoleRequestOperation.ADD);
concepts.add(concept);
IdmRoleRequestDto roleRequest = new IdmRoleRequestDto();
roleRequest.setConceptRoles(concepts);
roleRequest.setApplicant(contract.getIdentity());
roleRequest = roleRequestService.startConcepts(new RoleRequestEvent(RoleRequestEventType.EXCECUTE, roleRequest), null);
canContinue = updateState();
if (!canContinue) {
break;
}
}
//
if (canContinue) {
for (UUID contractId : newNotPassedContracts) {
// Identity id is get from embedded identity role. This is little speedup.
UUID identityId = null;
//
IdmIdentityRoleFilter filter = new IdmIdentityRoleFilter();
filter.setIdentityContractId(contractId);
filter.setAutomaticRoleId(automaticRoleId);
List<IdmIdentityRoleDto> identityRoles = identityRoleService.find(filter, null).getContent();
// Concepts that will be added
List<IdmConceptRoleRequestDto> concepts = new ArrayList<>(identityRoles.size());
for (IdmIdentityRoleDto identityRole : identityRoles) {
IdmConceptRoleRequestDto concept = new IdmConceptRoleRequestDto();
concept.setIdentityContract(contractId);
concept.setRole(automaticRolAttributeDto.getRole());
concept.setAutomaticRole(automaticRoleId);
concept.setIdentityRole(identityRole.getId());
concept.setOperation(ConceptRoleRequestOperation.REMOVE);
concepts.add(concept);
if (identityId == null) {
IdmIdentityContractDto contractDto = DtoUtils.getEmbedded(identityRole, IdmIdentityRole_.identityContract, IdmIdentityContractDto.class, null);
identityId = contractDto.getIdentity();
}
}
IdmRoleRequestDto roleRequest = new IdmRoleRequestDto();
roleRequest.setConceptRoles(concepts);
roleRequest.setApplicant(identityId);
roleRequest = roleRequestService.startConcepts(new RoleRequestEvent(RoleRequestEventType.EXCECUTE, roleRequest), null);
canContinue = updateState();
if (!canContinue) {
break;
}
}
}
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter in project CzechIdMng by bcvsolutions.
the class ProcessSkippedAutomaticRoleByTreeForContractTaskExecutor method removeAllAutomaticRoles.
private void removeAllAutomaticRoles(IdmIdentityContractDto invalidContract) {
UUID contractId = invalidContract.getId();
UUID identityId = invalidContract.getIdentity();
//
IdmIdentityRoleFilter filter = new IdmIdentityRoleFilter();
filter.setIdentityContractId(contractId);
filter.setAutomaticRole(Boolean.TRUE);
filter.setDirectRole(Boolean.TRUE);
//
List<IdmIdentityRoleDto> contractRoles = identityRoleService.find(filter, null).getContent();
List<IdmConceptRoleRequestDto> concepts = new ArrayList<>(contractRoles.size());
for (IdmIdentityRoleDto identityRole : contractRoles) {
IdmConceptRoleRequestDto conceptRoleRequest = new IdmConceptRoleRequestDto();
conceptRoleRequest.setIdentityRole(identityRole.getId());
conceptRoleRequest.setAutomaticRole(identityRole.getAutomaticRole());
conceptRoleRequest.setRole(identityRole.getRole());
conceptRoleRequest.setOperation(ConceptRoleRequestOperation.REMOVE);
conceptRoleRequest.setIdentityContract(contractId);
//
concepts.add(conceptRoleRequest);
}
if (concepts.isEmpty()) {
LOG.debug("invalid contract [{}] does not have assigned roles.", contractId);
//
return;
}
IdmRoleRequestDto roleRequest = new IdmRoleRequestDto();
roleRequest.setState(RoleRequestState.CONCEPT);
// without approval
roleRequest.setExecuteImmediately(true);
roleRequest.setApplicant(identityId);
roleRequest.setRequestedByType(RoleRequestedByType.AUTOMATICALLY);
roleRequest = roleRequestService.save(roleRequest);
//
for (IdmConceptRoleRequestDto concept : concepts) {
concept.setRoleRequest(roleRequest.getId());
//
conceptRoleRequestService.save(concept);
}
//
// start event with skip check authorities
RoleRequestEvent requestEvent = new RoleRequestEvent(RoleRequestEventType.EXCECUTE, roleRequest);
requestEvent.getProperties().put(IdmIdentityRoleService.SKIP_CHECK_AUTHORITIES, Boolean.TRUE);
// prevent to start asynchronous event before previous update event is completed.
requestEvent.setSuperOwnerId(identityId);
//
roleRequestService.startRequestInternal(requestEvent);
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter in project CzechIdMng by bcvsolutions.
the class DefaultIdmContractPositionServiceIntegrationTest method testAssignSameAutomaticRoleAsContract.
@Test
public void testAssignSameAutomaticRoleAsContract() {
// create automatic role on tree node
IdmRoleDto role = getHelper().createRole();
IdmTreeNodeDto node = getHelper().createTreeNode();
IdmRoleTreeNodeDto automaticRoleTwo = getHelper().createAutomaticRole(role, node);
// create identity
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
IdmIdentityContractDto contract = getHelper().createContract(identity, node);
getHelper().createContractPosition(contract, node);
//
IdmIdentityRoleFilter filter = new IdmIdentityRoleFilter();
filter.setIdentityId(identity.getId());
List<IdmIdentityRoleDto> assignedRoles = identityRoleService.find(filter, null).getContent();
Assert.assertEquals(2, assignedRoles.size());
Assert.assertTrue(assignedRoles.stream().allMatch(ir -> ir.getAutomaticRole().equals(automaticRoleTwo.getId())));
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter in project CzechIdMng by bcvsolutions.
the class DefaultIdmAutomaticRoleAttributeServiceIntegrationTest method testRecalculationWithManyIdentitiesProcessAll.
@Test
public void testRecalculationWithManyIdentitiesProcessAll() {
String description = getHelper().createName();
List<IdmIdentityDto> identities = new ArrayList<IdmIdentityDto>();
try {
for (int index = 0; index < 241; index++) {
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
identity.setDescription(description);
identityService.save(identity);
identities.add(identity);
}
assertEquals(241, identities.size());
IdmRoleDto role = getHelper().createRole();
IdmAutomaticRoleAttributeDto automaticRole = getHelper().createAutomaticRole(role.getId());
getHelper().createAutomaticRoleRule(automaticRole.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.IDENTITY, IdmIdentity_.description.getName(), null, description);
ProcessAllAutomaticRoleByAttributeTaskExecutor automaticRoleTask = AutowireHelper.createBean(ProcessAllAutomaticRoleByAttributeTaskExecutor.class);
longRunningTaskManager.executeSync(automaticRoleTask);
IdmIdentityRoleFilter filter = new IdmIdentityRoleFilter();
filter.setAutomaticRoleId(automaticRole.getId());
List<IdmIdentityRoleDto> identityRoles = identityRoleService.find(filter, null).getContent();
assertEquals(241, identityRoles.size());
for (IdmIdentityDto identity : identities) {
List<IdmIdentityRoleDto> allByIdentity = identityRoleService.findAllByIdentity(identity.getId());
assertEquals(1, allByIdentity.size());
}
} finally {
identityService.deleteAll(identities);
}
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter in project CzechIdMng by bcvsolutions.
the class IdentityContractExpirationTaskExecutorIntegrationTest method testExpiredRole.
@Test
public void testExpiredRole() {
getHelper().disable(IdentityContractEndProcessor.class);
//
try {
IdmIdentityDto identity = getHelper().createIdentity();
IdmIdentityContractDto contract = getHelper().getPrimeContract(identity);
//
// normal and business role
IdmRoleDto roleOne = getHelper().createRole();
IdmRoleDto roleRoot = getHelper().createRole();
IdmRoleDto roleSub = getHelper().createRole();
getHelper().createRoleComposition(roleRoot, roleSub);
//
// assign roles
getHelper().assignRoles(contract, roleRoot, roleOne);
//
// expire contract
contract.setValidTill(LocalDate.now().minusDays(2));
contract = getHelper().getService(IdmIdentityContractService.class).save(contract);
//
// test after create before lrt is executed
IdmIdentityRoleFilter filter = new IdmIdentityRoleFilter();
filter.setIdentityContractId(contract.getId());
List<IdmIdentityRoleDto> assignedRoles = identityRoleService.find(filter, null).getContent();
//
Assert.assertEquals(3, assignedRoles.size());
Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> ir.getRole().equals(roleOne.getId())));
Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> ir.getRole().equals(roleRoot.getId())));
Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> ir.getRole().equals(roleSub.getId())));
//
IdentityContractExpirationTaskExecutor lrt = new IdentityContractExpirationTaskExecutor();
lrt.init(null);
lrtManager.executeSync(lrt);
//
assignedRoles = identityRoleService.find(filter, null).getContent();
//
Assert.assertTrue(assignedRoles.isEmpty());
} finally {
getHelper().enable(IdentityContractEndProcessor.class);
}
}
Aggregations