use of eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto in project CzechIdMng by bcvsolutions.
the class RemoveAutomaticRoleTaskExecutor method end.
@Override
protected Boolean end(Boolean result, Exception ex) {
Boolean ended = super.end(result, ex);
//
if (BooleanUtils.isTrue(ended)) {
IdmRoleDto role = DtoUtils.getEmbedded(getAutomaticRole(), IdmRoleTreeNode_.role, IdmRoleDto.class);
//
long assignedRoles = identityRoleService.findByAutomaticRole(getAutomaticRoleId(), new PageRequest(0, 1)).getTotalElements();
if (assignedRoles != 0) {
LOG.debug("Remove role [{}] by automatic role [{}] is not complete, some roles [{}] remains assigned to identities.", role.getCode(), getAutomaticRole().getId(), assignedRoles);
return ended;
}
//
LOG.debug("Remove role [{}] by automatic role [{}]", role.getCode(), getAutomaticRole().getId());
try {
//
// Find all concepts and remove relation on role tree
IdmConceptRoleRequestFilter conceptRequestFilter = new IdmConceptRoleRequestFilter();
conceptRequestFilter.setAutomaticRole(getAutomaticRoleId());
//
List<IdmConceptRoleRequestDto> concepts = conceptRequestService.find(conceptRequestFilter, null).getContent();
for (IdmConceptRoleRequestDto concept : concepts) {
IdmRoleRequestDto request = roleRequestService.get(concept.getRoleRequest());
String message = null;
if (concept.getState().isTerminatedState()) {
message = MessageFormat.format("Role tree node [{0}] (reqested in concept [{1}]) was deleted (not from this role request)!", getAutomaticRoleId(), concept.getId());
} else {
message = MessageFormat.format("Request change in concept [{0}], was not executed, because requested RoleTreeNode [{1}] was deleted (not from this role request)!", concept.getId(), getAutomaticRoleId());
concept.setState(RoleRequestState.CANCELED);
}
roleRequestService.addToLog(request, message);
conceptRequestService.addToLog(concept, message);
concept.setAutomaticRole(null);
roleRequestService.save(request);
conceptRequestService.save(concept);
}
// Find all automatic role requests and remove relation on automatic role
if (automaticRoleId != null) {
IdmAutomaticRoleRequestFilter automaticRoleRequestFilter = new IdmAutomaticRoleRequestFilter();
automaticRoleRequestFilter.setAutomaticRoleId(automaticRoleId);
automaticRoleRequestService.find(automaticRoleRequestFilter, null).getContent().forEach(request -> {
request.setAutomaticRole(null);
automaticRoleRequestService.save(request);
// WFs cannot be cancel here, because this method can be called from the same WF
// automaticRoleRequestService.cancel(request);
});
}
// by default is this allowed
if (this.isDeleteEntity()) {
// delete entity
if (getAutomaticRole() instanceof IdmRoleTreeNodeDto) {
roleTreeNodeService.deleteInternalById(getAutomaticRole().getId());
} else {
// remove all rules
automaticRoleAttributeRuleService.deleteAllByAttribute(getAutomaticRole().getId());
automaticRoleAttributeService.deleteInternalById(getAutomaticRole().getId());
}
}
//
LOG.debug("End: Remove role [{}] by automatic role [{}].", role.getCode(), getAutomaticRole().getId());
//
} catch (Exception O_o) {
LOG.debug("Remove role [{}] by automatic role [{}] failed", role.getCode(), getAutomaticRole().getId(), O_o);
//
IdmLongRunningTaskDto task = longRunningTaskService.get(getLongRunningTaskId());
ResultModel resultModel = new DefaultResultModel(CoreResultCode.LONG_RUNNING_TASK_FAILED, ImmutableMap.of("taskId", getLongRunningTaskId(), "taskType", task.getTaskType(), "instanceId", task.getInstanceId()));
saveResult(resultModel, OperationState.EXCEPTION, O_o);
}
}
//
return ended;
}
use of eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto in project CzechIdMng by bcvsolutions.
the class AbstractLongRunningTaskExecutor method end.
/**
* TODO: save result into long running task - blob, text?
*
* @param result
* @param ex
* @return
*/
protected V end(V result, Exception ex) {
Assert.notNull(longRunningTaskId);
IdmLongRunningTaskDto task = longRunningTaskService.get(longRunningTaskId);
Assert.notNull(task, "Long running task has to be prepared before task is ended");
LOG.debug("Long running task ends [{}] with result [{}].", longRunningTaskId, result);
//
setStateProperties(task);
//
if (ex != null) {
ResultModel resultModel;
if (ex instanceof ResultCodeException) {
resultModel = ((ResultCodeException) ex).getError().getError();
} else {
resultModel = new DefaultResultModel(CoreResultCode.LONG_RUNNING_TASK_FAILED, ImmutableMap.of("taskId", longRunningTaskId, "taskType", task.getTaskType(), "instanceId", task.getInstanceId()));
}
LOG.error(resultModel.toString(), ex);
task.setResult(new OperationResult.Builder(OperationState.EXCEPTION).setModel(resultModel).setCause(ex).build());
} else if (OperationState.isRunnable(task.getResultState())) {
// executed standardly
LOG.debug("Long running task ended [{}] standardly, previous state [{}], result [{}].", longRunningTaskId, task.getResultState(), result);
task.setResult(new OperationResult.Builder(OperationState.EXECUTED).build());
}
//
// publish event - LRT ended
// TODO: result is not persisted - propagate him in event?
entityEventManager.publishEvent(new LongRunningTaskEvent(LongRunningTaskEventType.END, task));
//
return result;
}
use of eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmLongRunningTaskServiceTest method typeFilterTest.
@Test
public void typeFilterTest() {
IdmLongRunningTaskFilter filter = new IdmLongRunningTaskFilter();
String expectedResult = "TEST_SUCCESS_03_M";
// set tasks
LongRunningTaskExecutor<String> taskExecutor = new TestSimpleLongRunningTaskExecutor(expectedResult);
assertNull(taskExecutor.getLongRunningTaskId());
manager.executeSync(taskExecutor);
IdmLongRunningTaskDto task1 = idmLongRunningTaskService.get(taskExecutor.getLongRunningTaskId());
task1.setTaskType("Type0001");
idmLongRunningTaskService.save(task1);
filter.setTaskType(task1.getTaskType());
Page<IdmLongRunningTaskDto> result = idmLongRunningTaskService.find(filter, null);
assertEquals("Wrong TaskType", task1.getId(), result.getContent().get(0).getId());
}
use of eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmLongRunningTaskServiceTest method runningFilterTest.
@Test
public void runningFilterTest() {
IdmLongRunningTaskFilter filter = new IdmLongRunningTaskFilter();
String expectedResult = "TEST_SUCCESS_02_M";
// set tasks
LongRunningTaskExecutor<String> taskExecutor = new TestSimpleLongRunningTaskExecutor(expectedResult);
assertNull(taskExecutor.getLongRunningTaskId());
manager.executeSync(taskExecutor);
IdmLongRunningTaskDto task1 = idmLongRunningTaskService.get(taskExecutor.getLongRunningTaskId());
task1.setRunning(true);
idmLongRunningTaskService.save(task1);
// set filter
filter.setTaskType(task1.getTaskType());
filter.setRunning(task1.isRunning());
Page<IdmLongRunningTaskDto> result = idmLongRunningTaskService.find(filter, null);
assertEquals("Wrong Running", task1.getId(), result.getContent().get(0).getId());
}
use of eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmLongRunningTaskServiceTest method operationStateFilterTest.
@Test
public void operationStateFilterTest() {
IdmLongRunningTaskFilter filter = new IdmLongRunningTaskFilter();
String expectedResult = "TEST_SUCCESS_06_M";
// set tasks
LongRunningTaskExecutor<String> taskExecutor = new TestSimpleLongRunningTaskExecutor(expectedResult);
assertNull(taskExecutor.getLongRunningTaskId());
manager.executeSync(taskExecutor);
IdmLongRunningTaskDto task1 = idmLongRunningTaskService.get(taskExecutor.getLongRunningTaskId());
// set filter
filter.setOperationState(task1.getResultState());
Page<IdmLongRunningTaskDto> result = idmLongRunningTaskService.find(filter, null);
assertEquals("Wrong operationState id", true, result.getContent().contains(task1));
}
Aggregations