use of eu.bcvsolutions.idm.core.api.dto.DefaultResultModel in project CzechIdMng by bcvsolutions.
the class DefaultLongRunningTaskManager method createTaskExecutor.
/**
* Create new LongRunningTaskExecutor from given LRT.
* Handles exceptions, when task already processed, task type is removed or task initialization failed
*
* @param task
* @return
*/
protected LongRunningTaskExecutor<?> createTaskExecutor(IdmLongRunningTaskDto task) {
Assert.notNull(task, "Long running task instance is required!");
if (!OperationState.isRunnable(task.getResultState())) {
throw new ResultCodeException(CoreResultCode.LONG_RUNNING_TASK_IS_PROCESSED, ImmutableMap.of("taskId", task.getId()));
}
//
LongRunningTaskExecutor<?> taskExecutor = null;
ResultModel resultModel = null;
Exception ex = null;
try {
taskExecutor = (LongRunningTaskExecutor<?>) AutowireHelper.createBean(Class.forName(task.getTaskType()));
taskExecutor.setLongRunningTaskId(task.getId());
taskExecutor.init((Map<String, Object>) task.getTaskProperties());
} catch (ClassNotFoundException e) {
ex = e;
resultModel = new DefaultResultModel(CoreResultCode.LONG_RUNNING_TASK_NOT_FOUND, ImmutableMap.of("taskId", task.getId(), "taskType", task.getTaskType(), ConfigurationService.PROPERTY_INSTANCE_ID, task.getInstanceId()));
} catch (ResultCodeException e) {
ex = e;
resultModel = ((ResultCodeException) e).getError().getError();
} catch (Exception e) {
ex = e;
}
if (ex != null) {
if (resultModel == null) {
resultModel = new DefaultResultModel(CoreResultCode.LONG_RUNNING_TASK_INIT_FAILED, ImmutableMap.of("taskId", task.getId(), "taskType", task.getTaskType(), ConfigurationService.PROPERTY_INSTANCE_ID, task.getInstanceId()));
}
//
LOG.error(resultModel.toString(), ex);
task.setResult(new OperationResult.Builder(OperationState.EXCEPTION).setModel(resultModel).setCause(ex).build());
service.save(task);
return null;
} else {
return taskExecutor;
}
}
use of eu.bcvsolutions.idm.core.api.dto.DefaultResultModel in project CzechIdMng by bcvsolutions.
the class AddNewAutomaticRoleForPositionTaskExecutor method processItem.
@Override
public Optional<OperationResult> processItem(IdmContractPositionDto contractPosition) {
IdmIdentityContractDto contract = DtoUtils.getEmbedded(contractPosition, IdmContractPosition_.identityContract);
//
try {
if (!contract.isValidNowOrInFuture()) {
IdmIdentityDto identity = getIdentity(contract);
IdmRoleDto role = DtoUtils.getEmbedded(getRoleTreeNode(), IdmRoleTreeNode_.role);
return Optional.of(new OperationResult.Builder(OperationState.NOT_EXECUTED).setModel(new DefaultResultModel(CoreResultCode.AUTOMATIC_ROLE_CONTRACT_IS_NOT_VALID, ImmutableMap.of("role", role.getCode(), "roleTreeNode", getRoleTreeNode().getId(), "identity", identity.getUsername()))).build());
}
List<IdmIdentityRoleDto> allByPosition = identityRoleService.findAllByContractPosition(contractPosition.getId());
// skip already assigned automatic roles
for (IdmIdentityRoleDto roleByContract : allByPosition) {
if (ObjectUtils.equals(roleByContract.getAutomaticRole(), getRoleTreeNode().getId())) {
IdmIdentityDto identity = getIdentity(contract);
IdmRoleDto role = DtoUtils.getEmbedded(getRoleTreeNode(), IdmRoleTreeNode_.role);
return Optional.of(new OperationResult.Builder(OperationState.NOT_EXECUTED).setModel(new DefaultResultModel(CoreResultCode.AUTOMATIC_ROLE_ALREADY_ASSIGNED, ImmutableMap.of("role", role.getCode(), "roleTreeNode", getRoleTreeNode().getId(), "identity", identity.getUsername()))).build());
}
}
//
// automatic role by tree node is added directly trough identity role
IdmRoleTreeNodeDto autoRole = getRoleTreeNode();
IdmConceptRoleRequestDto conceptRoleRequest = new IdmConceptRoleRequestDto();
conceptRoleRequest.setIdentityContract(contract.getId());
conceptRoleRequest.setContractPosition(contractPosition.getId());
conceptRoleRequest.setValidFrom(contract.getValidFrom());
conceptRoleRequest.setValidTill(contract.getValidTill());
conceptRoleRequest.setRole(autoRole.getRole());
conceptRoleRequest.setAutomaticRole(autoRole.getId());
conceptRoleRequest.setOperation(ConceptRoleRequestOperation.ADD);
roleRequestService.executeConceptsImmediate(contract.getIdentity(), Lists.newArrayList(conceptRoleRequest));
//
return Optional.of(new OperationResult.Builder(OperationState.EXECUTED).build());
} catch (Exception ex) {
IdmIdentityDto identity = getIdentity(contract);
IdmRoleDto role = DtoUtils.getEmbedded(getRoleTreeNode(), IdmRoleTreeNode_.role);
//
LOG.error("Adding role [{}] by automatic role [{}] for identity [{}] failed", role.getCode(), getRoleTreeNode().getId(), identity.getUsername(), ex);
//
return Optional.of(new OperationResult.Builder(OperationState.EXCEPTION).setModel(new DefaultResultModel(CoreResultCode.AUTOMATIC_ROLE_ASSIGN_TASK_NOT_COMPLETE, ImmutableMap.of("role", role.getCode(), "roleTreeNode", getRoleTreeNode().getId(), "identity", identity.getUsername()))).setCause(ex).build());
}
}
use of eu.bcvsolutions.idm.core.api.dto.DefaultResultModel in project CzechIdMng by bcvsolutions.
the class AddNewAutomaticRoleTaskExecutor method processItem.
@Override
public Optional<OperationResult> processItem(IdmIdentityContractDto contract) {
try {
if (!contract.isValidNowOrInFuture()) {
IdmIdentityDto identity = DtoUtils.getEmbedded(contract, IdmIdentityContract_.identity);
IdmRoleDto role = DtoUtils.getEmbedded(getRoleTreeNode(), IdmRoleTreeNode_.role);
return Optional.of(new OperationResult.Builder(OperationState.NOT_EXECUTED).setModel(new DefaultResultModel(CoreResultCode.AUTOMATIC_ROLE_CONTRACT_IS_NOT_VALID, ImmutableMap.of("role", role.getCode(), "roleTreeNode", getRoleTreeNode().getId(), "identity", identity.getUsername()))).build());
}
List<IdmIdentityRoleDto> allByContract = identityRoleService.findAllByContract(contract.getId());
// skip already assigned automatic roles
for (IdmIdentityRoleDto roleByContract : allByContract) {
if (ObjectUtils.equals(roleByContract.getAutomaticRole(), getRoleTreeNode().getId())) {
IdmIdentityDto identity = DtoUtils.getEmbedded(contract, IdmIdentityContract_.identity);
IdmRoleDto role = DtoUtils.getEmbedded(getRoleTreeNode(), IdmRoleTreeNode_.role);
return Optional.of(new OperationResult.Builder(OperationState.NOT_EXECUTED).setModel(new DefaultResultModel(CoreResultCode.AUTOMATIC_ROLE_ALREADY_ASSIGNED, ImmutableMap.of("role", role.getCode(), "roleTreeNode", getRoleTreeNode().getId(), "identity", identity.getUsername()))).build());
}
}
//
// automatic role by tree node is added directly trough identity role
IdmRoleTreeNodeDto autoRole = getRoleTreeNode();
IdmConceptRoleRequestDto conceptRoleRequest = new IdmConceptRoleRequestDto();
conceptRoleRequest.setIdentityContract(contract.getId());
conceptRoleRequest.setValidFrom(contract.getValidFrom());
conceptRoleRequest.setValidTill(contract.getValidTill());
conceptRoleRequest.setRole(autoRole.getRole());
conceptRoleRequest.setAutomaticRole(autoRole.getId());
conceptRoleRequest.setOperation(ConceptRoleRequestOperation.ADD);
roleRequestService.executeConceptsImmediate(contract.getIdentity(), Lists.newArrayList(conceptRoleRequest));
//
return Optional.of(new OperationResult.Builder(OperationState.EXECUTED).build());
} catch (Exception ex) {
IdmIdentityDto identity = DtoUtils.getEmbedded(contract, IdmIdentityContract_.identity);
IdmRoleDto role = DtoUtils.getEmbedded(getRoleTreeNode(), IdmRoleTreeNode_.role);
//
LOG.error("Adding role [{}] by automatic role [{}] for identity [{}] failed", role.getCode(), getRoleTreeNode().getId(), identity.getUsername(), ex);
//
return Optional.of(new OperationResult.Builder(OperationState.EXCEPTION).setModel(new DefaultResultModel(CoreResultCode.AUTOMATIC_ROLE_ASSIGN_TASK_NOT_COMPLETE, ImmutableMap.of("role", role.getCode(), "roleTreeNode", getRoleTreeNode().getId(), "identity", identity.getUsername()))).setCause(ex).build());
}
}
use of eu.bcvsolutions.idm.core.api.dto.DefaultResultModel in project CzechIdMng by bcvsolutions.
the class DefaultEntityStateManagerIntergationTest method testSaveState.
@Test
public void testSaveState() {
IdmIdentityDto owner = getHelper().createIdentity((GuardedString) null);
IdmIdentityDto ownerTwo = getHelper().createIdentity((GuardedString) null);
//
IdmEntityStateDto state = new IdmEntityStateDto();
state.setResult(new OperationResultDto.Builder(OperationState.RUNNING).setModel(new DefaultResultModel(CoreResultCode.DELETED)).build());
state = manager.saveState(owner, state);
IdmEntityStateDto stateOther = new IdmEntityStateDto();
stateOther.setResult(new OperationResultDto.Builder(OperationState.RUNNING).setModel(new DefaultResultModel(CoreResultCode.DELETED)).build());
manager.saveState(ownerTwo, stateOther);
List<IdmEntityStateDto> states = manager.findStates(owner, null).getContent();
Assert.assertEquals(1, states.size());
IdmEntityStateDto persistedState = states.get(0);
//
Assert.assertEquals(owner.getId(), persistedState.getOwnerId());
Assert.assertEquals(manager.getOwnerType(owner), persistedState.getOwnerType());
Assert.assertEquals(OperationState.RUNNING, persistedState.getResult().getState());
//
manager.deleteState(state);
//
Assert.assertTrue(manager.findStates(owner, PageRequest.of(0, 1)).getTotalElements() == 0);
}
use of eu.bcvsolutions.idm.core.api.dto.DefaultResultModel in project CzechIdMng by bcvsolutions.
the class AdUserConnectorType method createEntityStateWithTestUser.
/**
* Create entity state for wizard test user
*/
private IdmEntityStateDto createEntityStateWithTestUser(SysSystemDto systemDto, String createdUserDN) {
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("entityId", systemDto.getId());
// Mark state with created user DN.
parameters.put(TEST_CREATED_USER_DN_KEY, createdUserDN);
DefaultResultModel resultModel = new DefaultResultModel(AccResultCode.WIZARD_AD_CREATED_TEST_USER_DN, parameters);
IdmEntityStateDto entityStateDto = new IdmEntityStateDto();
entityStateDto.setResult(new OperationResultDto.Builder(OperationState.CREATED).setModel(resultModel).build());
return entityStateManager.saveState(systemDto, entityStateDto);
}
Aggregations