use of eu.bcvsolutions.idm.core.api.entity.OperationResult in project CzechIdMng by bcvsolutions.
the class LongRunningTaskExecuteDependentProcessor method process.
@Override
public EventResult<IdmLongRunningTaskDto> process(EntityEvent<IdmLongRunningTaskDto> event) {
IdmLongRunningTaskDto longRunningTask = event.getContent();
IdmScheduledTaskDto scheduledTask = service.findByLongRunningTaskId(longRunningTask.getId());
if (scheduledTask == null) {
LOG.debug("Ecexute dependent tasks is supported for scheduled tasks. LRT [{}] does not have scheduled task.", longRunningTask.getId());
return new DefaultEventResult.Builder<IdmLongRunningTaskDto>(event, this).setResult(new OperationResult(OperationState.NOT_EXECUTED)).build();
}
List<IdmDependentTaskTrigger> dependentTasks = dependentTaskTriggerRepository.findByInitiatorTaskId(scheduledTask.getQuartzTaskName());
if (dependentTasks.isEmpty()) {
LOG.trace("Task [{}] has not dependent tasks.", longRunningTask.getId());
return new DefaultEventResult.Builder<IdmLongRunningTaskDto>(event, this).setResult(new OperationResult(OperationState.NOT_EXECUTED)).build();
}
//
if (longRunningTask.getResultState() != OperationState.EXECUTED) {
LOG.debug("Task [{}] was not successfully executed. Dependent tasks [{}] will not be executed.", longRunningTask.getId(), dependentTasks.size());
return new DefaultEventResult.Builder<IdmLongRunningTaskDto>(event, this).setResult(new OperationResult(OperationState.NOT_EXECUTED)).build();
}
// find all triggers by quartz task name = job detail name. Default group is supported now only
dependentTaskTriggerRepository.findByInitiatorTaskId(scheduledTask.getQuartzTaskName()).forEach(dependentTaskTrigger -> {
LOG.info("Scheduled task [{}] ended. Dependent task [{}] will be executed in dryRun [{}].", dependentTaskTrigger.getInitiatorTaskId(), dependentTaskTrigger.getDependentTaskId(), longRunningTask.isDryRun());
schedulerManager.runTask(dependentTaskTrigger.getDependentTaskId(), longRunningTask.isDryRun());
});
return new DefaultEventResult.Builder<IdmLongRunningTaskDto>(event, this).setResult(new OperationResult(OperationState.EXECUTED)).build();
}
use of eu.bcvsolutions.idm.core.api.entity.OperationResult in project CzechIdMng by bcvsolutions.
the class AddNewAutomaticRoleTaskExecutor method processItem.
@Override
public Optional<OperationResult> processItem(IdmIdentityContractDto identityContract) {
try {
if (!identityContract.isValidNowOrInFuture()) {
IdmIdentityDto identity = DtoUtils.getEmbedded(identityContract, IdmIdentityContract_.identity, IdmIdentityDto.class);
IdmRoleDto role = DtoUtils.getEmbedded(getRoleTreeNode(), IdmRoleTreeNode_.role, IdmRoleDto.class);
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(identityContract.getId());
// skip already assigned automatic roles
for (IdmIdentityRoleDto roleByContract : allByContract) {
if (ObjectUtils.equals(roleByContract.getRoleTreeNode(), getRoleTreeNode().getId())) {
IdmIdentityDto identity = DtoUtils.getEmbedded(identityContract, IdmIdentityContract_.identity, IdmIdentityDto.class);
IdmRoleDto role = DtoUtils.getEmbedded(getRoleTreeNode(), IdmRoleTreeNode_.role, IdmRoleDto.class);
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
// TODO: why is role attribute service used? Role tree node service should be used.
automaticRoleAttributeService.addAutomaticRoles(identityContract, Sets.newHashSet(getRoleTreeNode()));
return Optional.of(new OperationResult.Builder(OperationState.EXECUTED).build());
} catch (Exception ex) {
IdmIdentityDto identity = DtoUtils.getEmbedded(identityContract, IdmIdentityContract_.identity, IdmIdentityDto.class);
IdmRoleDto role = DtoUtils.getEmbedded(getRoleTreeNode(), IdmRoleTreeNode_.role, IdmRoleDto.class);
//
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.entity.OperationResult in project CzechIdMng by bcvsolutions.
the class DefaultSysProvisioningArchiveServiceTest method createProvisioningArchive.
private SysProvisioningArchiveDto createProvisioningArchive(SystemEntityType type, SysSystemDto system) {
SysProvisioningArchiveDto provisioningArchive = new SysProvisioningArchiveDto();
provisioningArchive.setEntityType(type);
provisioningArchive.setOperationType(ProvisioningEventType.CREATE);
provisioningArchive.setProvisioningContext(new ProvisioningContext());
provisioningArchive.setSystem(system.getId());
provisioningArchive.setSystemEntityUid("SomeEntityUID" + UUID.randomUUID());
OperationResult result = new OperationResult();
result.setState(OperationState.RUNNING);
provisioningArchive.setResult(result);
return archiveService.save(provisioningArchive);
}
use of eu.bcvsolutions.idm.core.api.entity.OperationResult in project CzechIdMng by bcvsolutions.
the class DefaultSysProvisioningArchiveServiceTest method resultStateFilterTest.
@Test
public void resultStateFilterTest() {
IdmBasePermission permission = IdmBasePermission.ADMIN;
SystemEntityType entityType = SystemEntityType.IDENTITY;
SysSystemDto system = createRoleSystem();
OperationResult resultState = new OperationResult();
resultState.setState(OperationState.CREATED);
SysProvisioningArchiveDto provisioningArchive1 = createProvisioningArchive(entityType, system);
SysProvisioningArchiveDto provisioningArchive2 = createProvisioningArchive(entityType, system);
provisioningArchive2.setResult(resultState);
archiveService.save(provisioningArchive2);
SysProvisioningOperationFilter filter = new SysProvisioningOperationFilter();
filter.setResultState(OperationState.CREATED);
Page<SysProvisioningArchiveDto> result = archiveService.find(filter, null, permission);
assertEquals(1, result.getTotalElements());
assertFalse(result.getContent().contains(provisioningArchive1));
assertTrue(result.getContent().contains(provisioningArchive2));
}
use of eu.bcvsolutions.idm.core.api.entity.OperationResult in project CzechIdMng by bcvsolutions.
the class IdentityPasswordProvisioningProcessor method process.
@Override
public EventResult<IdmIdentityDto> process(EntityEvent<IdmIdentityDto> event) {
IdmIdentityDto identity = event.getContent();
PasswordChangeDto passwordChangeDto = (PasswordChangeDto) event.getProperties().get(IdentityPasswordProcessor.PROPERTY_PASSWORD_CHANGE_DTO);
Assert.notNull(passwordChangeDto);
//
LOG.debug("Call provisioning for identity password [{}]", event.getContent().getUsername());
List<OperationResult> results = provisioningService.changePassword(identity, passwordChangeDto);
//
return new DefaultEventResult.Builder<>(event, this).setResults(results).build();
}
Aggregations