use of eu.bcvsolutions.idm.core.api.dto.DefaultResultModel in project CzechIdMng by bcvsolutions.
the class DuplicateRoleAutomaticByTreeProcessor method process.
@Override
public EventResult<IdmRoleDto> process(EntityEvent<IdmRoleDto> event) {
IdmRoleDto cloned = event.getContent();
IdmRoleDto originalSource = event.getOriginalSource();
IdmRoleTreeNodeFilter filter = new IdmRoleTreeNodeFilter();
filter.setRoleId(cloned.getId());
Set<UUID> usedAutomaticRoles = new HashSet<>();
List<IdmRoleTreeNodeDto> currentAutomaticRoles = roleTreeNodeService.find(filter, null).getContent();
//
filter.setRoleId(originalSource.getId());
roleTreeNodeService.find(filter, null).forEach(automaticRole -> {
UUID exists = exists(currentAutomaticRoles, automaticRole);
if (exists != null) {
usedAutomaticRoles.add(exists);
} else {
IdmRoleTreeNodeDto clonedAutomaticRole = new IdmRoleTreeNodeDto();
clonedAutomaticRole.setName(automaticRole.getName());
clonedAutomaticRole.setRole(cloned.getId());
clonedAutomaticRole.setTreeNode(automaticRole.getTreeNode());
clonedAutomaticRole.setRecursionType(automaticRole.getRecursionType());
//
RoleTreeNodeEvent automaticRoleEvent = new RoleTreeNodeEvent(RoleTreeNodeEventType.CREATE, clonedAutomaticRole);
// execute sync
automaticRoleEvent.setPriority(PriorityType.IMMEDIATE);
roleTreeNodeService.publish(automaticRoleEvent, event);
}
});
//
// remove not used originals
currentAutomaticRoles.stream().filter(automaticRole -> {
return !usedAutomaticRoles.contains(automaticRole.getId());
}).forEach(automaticRole -> {
// dirty flag automatic role only - will be processed after parent action ends
IdmEntityStateDto stateDeleted = new IdmEntityStateDto();
stateDeleted.setEvent(event.getId());
stateDeleted.setSuperOwnerId(cloned.getId());
stateDeleted.setResult(new OperationResultDto.Builder(OperationState.RUNNING).setModel(new DefaultResultModel(CoreResultCode.DELETED)).build());
entityStateManager.saveState(automaticRole, stateDeleted);
});
//
return new DefaultEventResult<>(event, this);
}
use of eu.bcvsolutions.idm.core.api.dto.DefaultResultModel in project CzechIdMng by bcvsolutions.
the class AddNewRoleCompositionTaskExecutor method processItem.
@Override
public Optional<OperationResult> processItem(IdmRoleDto superiorRole) {
try {
IdmIdentityRoleFilter filter = new IdmIdentityRoleFilter();
filter.setRoleId(superiorRole.getId());
//
identityRoleService.find(filter, null).forEach(identityRole -> {
IdmIdentityContractDto contract = lookupService.lookupEmbeddedDto(identityRole, IdmIdentityRole_.identityContract);
// find direct sub roles - other sub roles will be processed by role request automatically
IdmRoleCompositionFilter compositionFilter = new IdmRoleCompositionFilter();
compositionFilter.setSuperiorId(identityRole.getRole());
compositionFilter.setId(roleCompositionId);
//
List<IdmConceptRoleRequestDto> concepts = roleCompositionService.find(compositionFilter, null).stream().map(subRole -> {
IdmConceptRoleRequestDto conceptRoleRequest = new IdmConceptRoleRequestDto();
conceptRoleRequest.setOperation(ConceptRoleRequestOperation.ADD);
// from concept
conceptRoleRequest.setValidFrom(identityRole.getValidFrom());
conceptRoleRequest.setValidTill(identityRole.getValidTill());
conceptRoleRequest.setIdentityContract(identityRole.getIdentityContract());
conceptRoleRequest.setContractPosition(identityRole.getContractPosition());
// from assigned (~changed) sub role
conceptRoleRequest.setRole(subRole.getSub());
conceptRoleRequest.setDirectRole(identityRole.getId());
conceptRoleRequest.setRoleComposition(subRole.getId());
//
return conceptRoleRequest;
}).collect(Collectors.toList());
//
if (!concepts.isEmpty()) {
IdmRoleRequestDto roleRequest = new IdmRoleRequestDto();
roleRequest.setConceptRoles(concepts);
roleRequest.setApplicant(contract.getIdentity());
roleRequest = roleRequestService.startConcepts(new RoleRequestEvent(RoleRequestEventType.EXCECUTE, roleRequest), null);
}
});
//
return Optional.of(new OperationResult.Builder(OperationState.EXECUTED).build());
} catch (Exception ex) {
return Optional.of(new OperationResult.Builder(OperationState.EXCEPTION).setModel(new DefaultResultModel(CoreResultCode.ROLE_COMPOSITION_ASSIGN_ROLE_FAILED, ImmutableMap.of("role", superiorRole.getCode()))).setCause(ex).build());
}
}
use of eu.bcvsolutions.idm.core.api.dto.DefaultResultModel in project CzechIdMng by bcvsolutions.
the class ClearDirtyStateForContractSliceTaskExecutor method process.
@Override
public OperationResult process() {
boolean canContinue = true;
List<IdmEntityStateDto> dirtyStates = findAllDirtyStatesForSlices(null).getContent();
if (count == null) {
count = Long.valueOf(dirtyStates.size());
}
counter = 0l;
List<IdmEntityStateDto> updateDirtyStates = Lists.newArrayList();
List<IdmEntityStateDto> validDirtyStates = Lists.newArrayList();
List<IdmEntityStateDto> futureDirtyStates = Lists.newArrayList();
List<IdmEntityStateDto> unvalidDirtyStates = Lists.newArrayList();
List<IdmEntityStateDto> deleteDirtyStates = Lists.newArrayList();
dirtyStates.forEach(dirtyState -> {
ResultModel resultModel = dirtyState.getResult().getModel();
Map<String, Object> parameters = new HashMap<>();
if (resultModel != null) {
parameters = resultModel.getParameters();
}
boolean sliceIsToDelete = this.getBooleanProperty(ClearDirtyStateForContractSliceTaskExecutor.TO_DELETE, parameters);
if (sliceIsToDelete) {
deleteDirtyStates.add(dirtyState);
} else {
updateDirtyStates.add(dirtyState);
}
});
updateDirtyStates.forEach(dirtyState -> {
IdmContractSliceDto contractSliceDto = contractSliceService.get(dirtyState.getOwnerId());
if (contractSliceDto == null) {
DefaultResultModel model = new DefaultResultModel(CoreResultCode.NOT_FOUND, ImmutableMap.of("ownerId", dirtyState.getOwnerId()));
this.logItemProcessed(dirtyState, new OperationResult.Builder(OperationState.NOT_EXECUTED).setModel(model).build());
return;
}
// Temporary put current slice to the dirtyState
dirtyState.getEmbedded().put(CURRENT_SLICE, contractSliceDto);
// Divide slices by validity
IdmIdentityContractDto mockContract = new IdmIdentityContractDto();
contractSliceManager.convertSliceToContract(contractSliceDto, mockContract);
if (!mockContract.isValidNowOrInFuture()) {
unvalidDirtyStates.add(dirtyState);
} else if (mockContract.isValid()) {
validDirtyStates.add(dirtyState);
} else {
futureDirtyStates.add(dirtyState);
}
});
// Process for new and updated slices - valid
for (IdmEntityStateDto dirtyState : validDirtyStates) {
canContinue = processState(canContinue, dirtyState);
if (!canContinue) {
break;
}
}
// Process for new and updated slices - future valid
for (IdmEntityStateDto dirtyState : futureDirtyStates) {
canContinue = processState(canContinue, dirtyState);
if (!canContinue) {
break;
}
}
// Process for new and updated slices - invalid
for (IdmEntityStateDto dirtyState : unvalidDirtyStates) {
canContinue = processState(canContinue, dirtyState);
if (!canContinue) {
break;
}
}
// Process for slices to delete
for (IdmEntityStateDto dirtyState : deleteDirtyStates) {
Assert.notNull(dirtyState, "State (dirty) is required.");
Assert.notNull(dirtyState.getId(), "State identifier (dirty) is required.");
processItemToDelete(dirtyState);
counter++;
// clear it (same behavior as in stateful tasks)
if (getHibernateSession().isOpen()) {
getHibernateSession().flush();
getHibernateSession().clear();
}
canContinue &= this.updateState();
if (!canContinue) {
break;
}
}
return new OperationResult(OperationState.EXECUTED);
}
use of eu.bcvsolutions.idm.core.api.dto.DefaultResultModel in project CzechIdMng by bcvsolutions.
the class ClearDirtyStateForContractSliceTaskExecutor method processItemToDelete.
/**
* Process one dirty state for contract slice to delete
*
* @param dirtyState
*/
private void processItemToDelete(IdmEntityStateDto dirtyState) {
try {
if (dirtyState.getOwnerType() == null || !dirtyState.getOwnerType().equals(IdmContractSlice.class.getName())) {
this.logItemProcessed(dirtyState, new OperationResult.Builder(OperationState.NOT_EXECUTED).build());
return;
}
IdmContractSliceDto contractSliceDto = contractSliceService.get(dirtyState.getOwnerId());
;
if (contractSliceDto == null) {
DefaultResultModel model = new DefaultResultModel(CoreResultCode.NOT_FOUND, ImmutableMap.of("ownerId", dirtyState.getOwnerId()));
this.logItemProcessed(dirtyState, new OperationResult.Builder(OperationState.NOT_EXECUTED).setModel(model).build());
return;
}
ResultModel resultModel = dirtyState.getResult().getModel();
Map<String, Object> parameters = new HashMap<>();
if (resultModel != null) {
parameters = resultModel.getParameters();
}
// Transform saved parameters into map string and serializable value
Map<String, Serializable> transformedParameters = transformParameters(parameters);
EntityEvent<IdmContractSliceDto> event = new ContractSliceEvent(ContractSliceEventType.DELETE, contractSliceDto, transformedParameters);
// Delete slice (with recalculation)
contractSliceService.publish(event);
this.logItemProcessed(contractSliceDto, new OperationResult.Builder(OperationState.EXECUTED).build());
} catch (Exception e) {
this.logItemProcessed(dirtyState, new OperationResult.Builder(OperationState.EXCEPTION).setCause(e).build());
}
}
use of eu.bcvsolutions.idm.core.api.dto.DefaultResultModel in project CzechIdMng by bcvsolutions.
the class ProcessSkippedAutomaticRoleByTreeForContractTaskExecutor method processItem.
@Override
public Optional<OperationResult> processItem(IdmEntityStateDto state) {
UUID ownerId = state.getOwnerId();
if (processedOwnerIds.contains(ownerId)) {
LOG.debug("Automatic roles for owner [{}] was already processed, delete state only.", ownerId);
//
entityStateManager.deleteState(state);
// Item will be deleted only - we need some result - counter / count will match.
return Optional.of(new OperationResult.Builder(OperationState.EXECUTED).build());
}
// process automatic role on state owner
if (state.getOwnerType().equals(entityStateManager.getOwnerType(IdmIdentityContractDto.class))) {
// contract
LOG.debug("Process automatic roles for contract [{}].", ownerId);
//
IdmIdentityContractDto contract = lookupService.lookupDto(IdmIdentityContractDto.class, ownerId);
if (contract == null) {
getItemService().createLogItem(state, new OperationResult.Builder(OperationState.NOT_EXECUTED).setModel(new DefaultResultModel(CoreResultCode.CONTENT_DELETED, ImmutableMap.of("ownerId", ownerId, "ownerType", entityStateManager.getOwnerType(IdmIdentityContractDto.class)))).build(), this.getLongRunningTaskId());
} else if (!contract.isValidNowOrInFuture()) {
removeAllAutomaticRoles(contract);
//
getItemService().createLogItem(contract, new OperationResult.Builder(OperationState.EXECUTED).build(), this.getLongRunningTaskId());
} else {
EntityEvent<IdmIdentityContractDto> event = new IdentityContractEvent(IdentityContractEventType.NOTIFY, contract);
event.setOriginalSource((IdmIdentityContractDto) state.getResult().getModel().getParameters().get(EntityEvent.EVENT_PROPERTY_ORIGINAL_SOURCE));
contractProcessor.process(event);
//
getItemService().createLogItem(contract, new OperationResult.Builder(OperationState.EXECUTED).build(), this.getLongRunningTaskId());
}
} else {
// position
LOG.debug("Process automatic roles for position [{}].", ownerId);
//
IdmContractPositionDto position = lookupService.lookupDto(IdmContractPositionDto.class, ownerId);
if (position == null) {
getItemService().createLogItem(state, new OperationResult.Builder(OperationState.NOT_EXECUTED).setModel(new DefaultResultModel(CoreResultCode.CONTENT_DELETED, ImmutableMap.of("ownerId", ownerId, "ownerType", entityStateManager.getOwnerType(IdmIdentityContractDto.class)))).build(), this.getLongRunningTaskId());
} else {
EntityEvent<IdmContractPositionDto> event = new ContractPositionEvent(ContractPositionEventType.NOTIFY, position);
positionProcessor.process(event);
//
getItemService().createLogItem(position, new OperationResult.Builder(OperationState.EXECUTED).build(), this.getLongRunningTaskId());
}
}
processedOwnerIds.add(ownerId);
entityStateManager.deleteState(state);
// Log added manually above - log processed contract / position instead of deleted entity state.
return Optional.empty();
}
Aggregations