use of eu.bcvsolutions.idm.core.api.dto.DefaultResultModel in project CzechIdMng by bcvsolutions.
the class AbstractMonitoringIgnoredBulkAction method processDto.
@Override
protected OperationResult processDto(DTO dto) {
IdmEntityStateDto state = new IdmEntityStateDto();
state.setResult(new OperationResultDto.Builder(OperationState.BLOCKED).setModel(new DefaultResultModel(CoreResultCode.MONITORING_IGNORED)).build());
entityStateManager.saveState(dto, state);
//
return new OperationResult.Builder(OperationState.EXECUTED).build();
}
use of eu.bcvsolutions.idm.core.api.dto.DefaultResultModel in project CzechIdMng by bcvsolutions.
the class ProcessAutomaticRoleByTreeTaskExecutor method processContract.
/**
* Assign automatic role for given contract. Already assigned automatic role is checked.
*
* @param contract
* @param automaticRole
* @return created assigned roles
*/
private Set<UUID> processContract(IdmIdentityContractDto contract, IdmRoleTreeNodeDto automaticRole) {
UUID contractId = contract.getId();
Set<UUID> processedRoleRequests = new HashSet<>();
UUID automaticRoleId = automaticRole.getId();
IdmIdentityDto identity = getLookupService().lookupEmbeddedDto(contract, IdmIdentityContract_.identity);
IdmRoleDto role = getLookupService().lookupEmbeddedDto(automaticRole, IdmRoleTreeNode_.role);
//
try {
List<IdmIdentityRoleDto> allByContract = identityRoleService.findAllByContract(contractId);
// skip already assigned automatic roles
for (IdmIdentityRoleDto roleByContract : allByContract) {
if (ObjectUtils.equals(roleByContract.getAutomaticRole(), automaticRoleId)) {
processedRoleRequests.add(roleByContract.getId());
ResultModel resultModel = new DefaultResultModel(CoreResultCode.AUTOMATIC_ROLE_ALREADY_ASSIGNED, ImmutableMap.of("role", role.getCode(), "roleTreeNode", automaticRoleId, "identity", identity.getUsername()));
saveItemResult(roleByContract, OperationState.NOT_EXECUTED, resultModel, null);
return processedRoleRequests;
}
}
//
// assign automatic role by tree node by role request
IdmConceptRoleRequestDto conceptRoleRequest = new IdmConceptRoleRequestDto();
conceptRoleRequest.setIdentityContract(contractId);
conceptRoleRequest.setValidFrom(contract.getValidFrom());
conceptRoleRequest.setValidTill(contract.getValidTill());
conceptRoleRequest.setRole(automaticRole.getRole());
conceptRoleRequest.setAutomaticRole(automaticRoleId);
conceptRoleRequest.setOperation(ConceptRoleRequestOperation.ADD);
//
IdmRoleRequestDto roleRequest = new IdmRoleRequestDto();
roleRequest.setConceptRoles(Lists.newArrayList(conceptRoleRequest));
roleRequest.setApplicant(contract.getIdentity());
RoleRequestEvent roleRequestEvent = new RoleRequestEvent(RoleRequestEventType.EXCECUTE, roleRequest);
roleRequest = roleRequestService.startConcepts(roleRequestEvent, null);
// load role concepts and add created role to processed
if (roleRequest != null) {
processedRoleRequests.add(roleRequest.getId());
}
// Log successfully assigned role
ResultModel resultModel = new DefaultResultModel(CoreResultCode.AUTOMATIC_ROLE_ASSIGN_TASK_ROLE_ASSIGNED, ImmutableMap.of("role", role.getCode(), "roleTreeNode", automaticRoleId, "identity", identity.getUsername()));
saveItemResult(contract, OperationState.EXECUTED, resultModel, null);
} catch (Exception ex) {
LOG.error("Adding role [{}] by automatic role [{}] for identity [{}] failed", role.getCode(), automaticRoleId, identity.getUsername(), ex);
//
ResultModel resultModel = new DefaultResultModel(CoreResultCode.AUTOMATIC_ROLE_ASSIGN_TASK_NOT_COMPLETE, ImmutableMap.of("role", role.getCode(), "roleTreeNode", automaticRoleId, "identity", identity.getUsername()));
saveItemResult(contract, OperationState.EXCEPTION, resultModel, ex);
}
//
return processedRoleRequests;
}
use of eu.bcvsolutions.idm.core.api.dto.DefaultResultModel in project CzechIdMng by bcvsolutions.
the class ProcessAutomaticRoleByTreeTaskExecutor method checkProcessedIdentityRole.
/**
* Check currently assigned role is processed by current automatic role definition.
* If not => assigned role will be removed by synchronous role request.
*
* @param processedIdentityRoles assigned roles processed by automatic role
* @param identityRole assigned role
* @param automaticRole automatic role definition (just for logging)
*/
private void checkProcessedIdentityRole(Set<UUID> processedIdentityRoles, IdmIdentityRoleDto identityRole, UUID automaticRoleId) {
UUID identityRoleId = identityRole.getId();
IdmIdentityContractDto identityContract = getLookupService().lookupEmbeddedDto(identityRole, IdmIdentityRole_.identityContract);
IdmIdentityDto identity = getLookupService().lookupEmbeddedDto(identityContract, IdmIdentityContract_.identity);
IdmRoleDto role = getLookupService().lookupEmbeddedDto(identityRole, IdmIdentityRole_.role);
//
if (!processedIdentityRoles.contains(identityRoleId)) {
// remove role by request
try {
IdmConceptRoleRequestDto conceptRoleRequest = new IdmConceptRoleRequestDto();
conceptRoleRequest.setIdentityRole(identityRole.getId());
conceptRoleRequest.setRole(identityRole.getRole());
conceptRoleRequest.setOperation(ConceptRoleRequestOperation.REMOVE);
conceptRoleRequest.setIdentityContract(identityRole.getIdentityContract());
//
IdmRoleRequestDto roleRequest = new IdmRoleRequestDto();
roleRequest.setConceptRoles(Lists.newArrayList(conceptRoleRequest));
roleRequest.setApplicant(identity.getId());
roleRequest = roleRequestService.startConcepts(new RoleRequestEvent(RoleRequestEventType.EXCECUTE, roleRequest), null);
// log successfully removed identity role
ResultModel resultModel = new DefaultResultModel(CoreResultCode.AUTOMATIC_ROLE_ASSIGN_TASK_ROLE_REMOVED, ImmutableMap.of("role", role.getCode(), "roleTreeNode", automaticRoleId, "identity", identity.getUsername()));
saveItemResult(identityRole, OperationState.EXECUTED, resultModel, null);
} catch (Exception ex) {
LOG.error("Remove role [{}] by automatic role [{}] failed", role.getCode(), automaticRoleId, ex);
//
ResultModel resultModel = new DefaultResultModel(CoreResultCode.AUTOMATIC_ROLE_REMOVE_TASK_NOT_COMPLETE, ImmutableMap.of("role", role.getCode(), "roleTreeNode", automaticRoleId, "identity", identity.getUsername()));
saveItemResult(identityRole, OperationState.EXCEPTION, resultModel, ex);
}
}
}
use of eu.bcvsolutions.idm.core.api.dto.DefaultResultModel in project CzechIdMng by bcvsolutions.
the class ProcessAutomaticRoleByTreeTaskExecutor method processItem.
@Override
public Optional<OperationResult> processItem(IdmRoleTreeNodeDto automaticRole) {
try {
// process contracts
Set<UUID> processedRoleRequestsByContract = processContracts(automaticRole);
if (processedRoleRequestsByContract == null) {
// task was canceled from the outside => not continue
return Optional.of(new OperationResult.Builder(OperationState.EXECUTED).build());
}
processedRoleRequests.addAll(processedRoleRequestsByContract);
//
// process contract positions
Set<UUID> processedRoleRequestsByPositions = processPositions(automaticRole);
if (processedRoleRequestsByPositions == null) {
// task was canceled from the outside => not continue
return Optional.of(new OperationResult.Builder(OperationState.EXECUTED).build());
}
processedRoleRequests.addAll(processedRoleRequestsByPositions);
//
// delete automatic role is skipped flag for already processed automatic role
entityStateManager.deleteStates(automaticRole, OperationState.BLOCKED, CoreResultCode.AUTOMATIC_ROLE_SKIPPED);
//
return Optional.of(new OperationResult.Builder(OperationState.EXECUTED).build());
} catch (Exception ex) {
// catch - just for sure, but all exception will be processed in new transaction to prevent whole automatic role fails.
IdmRoleDto role = getLookupService().lookupEmbeddedDto(automaticRole, IdmRoleTreeNode_.role);
//
return Optional.of(new OperationResult.Builder(OperationState.EXCEPTION).setModel(new DefaultResultModel(CoreResultCode.AUTOMATIC_ROLE_ASSIGN_TASK_NOT_COMPLETE, ImmutableMap.of("role", role.getCode(), "roleTreeNode", automaticRole.getId()))).setCause(ex).build());
}
}
use of eu.bcvsolutions.idm.core.api.dto.DefaultResultModel in project CzechIdMng by bcvsolutions.
the class ProcessAutomaticRoleByTreeTaskExecutor method processPosition.
/**
* Assign automatic role for given other. Already assigned automatic role is checked.
*
* @param contract
* @param automaticRole
* @return created assigned roles
*/
private Set<UUID> processPosition(IdmContractPositionDto position, IdmRoleTreeNodeDto automaticRole) {
UUID positionId = position.getId();
IdmIdentityContractDto contract = getLookupService().lookupEmbeddedDto(position, IdmContractPosition_.identityContract);
UUID contractId = contract.getId();
Set<UUID> processedRoleRequests = new HashSet<>();
UUID automaticRoleId = automaticRole.getId();
IdmIdentityDto identity = getLookupService().lookupEmbeddedDto(contract, IdmIdentityContract_.identity);
IdmRoleDto role = getLookupService().lookupEmbeddedDto(automaticRole, IdmRoleTreeNode_.role);
//
try {
List<IdmIdentityRoleDto> allByPosition = identityRoleService.findAllByContractPosition(positionId);
// skip already assigned automatic roles
for (IdmIdentityRoleDto roleByContract : allByPosition) {
if (ObjectUtils.equals(roleByContract.getAutomaticRole(), automaticRoleId)) {
processedRoleRequests.add(roleByContract.getId());
ResultModel resultModel = new DefaultResultModel(CoreResultCode.AUTOMATIC_ROLE_ALREADY_ASSIGNED, ImmutableMap.of("role", role.getCode(), "roleTreeNode", automaticRoleId, "identity", identity.getUsername()));
saveItemResult(roleByContract, OperationState.NOT_EXECUTED, resultModel, null);
return processedRoleRequests;
}
}
//
// automatic role by tree node is added directly trough identity role
IdmConceptRoleRequestDto conceptRoleRequest = new IdmConceptRoleRequestDto();
conceptRoleRequest.setIdentityContract(contractId);
conceptRoleRequest.setContractPosition(positionId);
conceptRoleRequest.setValidFrom(contract.getValidFrom());
conceptRoleRequest.setValidTill(contract.getValidTill());
conceptRoleRequest.setRole(automaticRole.getRole());
conceptRoleRequest.setAutomaticRole(automaticRoleId);
conceptRoleRequest.setOperation(ConceptRoleRequestOperation.ADD);
//
IdmRoleRequestDto roleRequest = new IdmRoleRequestDto();
roleRequest.setConceptRoles(Lists.newArrayList(conceptRoleRequest));
roleRequest.setApplicant(contract.getIdentity());
RoleRequestEvent roleRequestEvent = new RoleRequestEvent(RoleRequestEventType.EXCECUTE, roleRequest);
roleRequest = roleRequestService.startConcepts(roleRequestEvent, null);
// load role concepts and add created role to processed
if (roleRequest != null) {
processedRoleRequests.add(roleRequest.getId());
}
// Log successfully assigned role
ResultModel resultModel = new DefaultResultModel(CoreResultCode.AUTOMATIC_ROLE_ASSIGN_TASK_ROLE_ASSIGNED, ImmutableMap.of("role", role.getCode(), "roleTreeNode", automaticRoleId, "identity", identity.getUsername()));
saveItemResult(position, OperationState.EXECUTED, resultModel, null);
} catch (Exception ex) {
LOG.error("Adding role [{}] by automatic role [{}] for identity [{}] failed", role.getCode(), automaticRoleId, identity.getUsername(), ex);
//
ResultModel resultModel = new DefaultResultModel(CoreResultCode.AUTOMATIC_ROLE_ASSIGN_TASK_NOT_COMPLETE, ImmutableMap.of("role", role.getCode(), "roleTreeNode", automaticRoleId, "identity", identity.getUsername()));
saveItemResult(position, OperationState.EXCEPTION, resultModel, ex);
}
//
return processedRoleRequests;
}
Aggregations