Search in sources :

Example 1 with OperationResult

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();
}
Also used : IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) IdmDependentTaskTrigger(eu.bcvsolutions.idm.core.scheduler.entity.IdmDependentTaskTrigger) IdmScheduledTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmScheduledTaskDto) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult)

Example 2 with OperationResult

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());
    }
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException)

Example 3 with OperationResult

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);
}
Also used : ProvisioningContext(eu.bcvsolutions.idm.acc.domain.ProvisioningContext) SysProvisioningArchiveDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningArchiveDto) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult)

Example 4 with OperationResult

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));
}
Also used : SysProvisioningOperationFilter(eu.bcvsolutions.idm.acc.dto.filter.SysProvisioningOperationFilter) IdmBasePermission(eu.bcvsolutions.idm.core.security.api.domain.IdmBasePermission) SystemEntityType(eu.bcvsolutions.idm.acc.domain.SystemEntityType) SysProvisioningArchiveDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningArchiveDto) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

Example 5 with OperationResult

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();
}
Also used : PasswordChangeDto(eu.bcvsolutions.idm.core.api.dto.PasswordChangeDto) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)

Aggregations

OperationResult (eu.bcvsolutions.idm.core.api.entity.OperationResult)32 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)14 Test (org.junit.Test)10 PasswordChangeDto (eu.bcvsolutions.idm.core.api.dto.PasswordChangeDto)7 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)6 SysProvisioningOperationDto (eu.bcvsolutions.idm.acc.dto.SysProvisioningOperationDto)5 UUID (java.util.UUID)5 ProvisioningContext (eu.bcvsolutions.idm.acc.domain.ProvisioningContext)4 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)4 AbstractDto (eu.bcvsolutions.idm.core.api.dto.AbstractDto)4 IdmAccountDto (eu.bcvsolutions.idm.core.api.dto.IdmAccountDto)4 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)4 IdentityEvent (eu.bcvsolutions.idm.core.model.event.IdentityEvent)4 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)4 AbstractRestTest (eu.bcvsolutions.idm.test.api.AbstractRestTest)4 ArrayList (java.util.ArrayList)4 SystemEntityType (eu.bcvsolutions.idm.acc.domain.SystemEntityType)3 SysSystemEntityDto (eu.bcvsolutions.idm.acc.dto.SysSystemEntityDto)3 IdentityState (eu.bcvsolutions.idm.core.api.domain.IdentityState)3 DefaultResultModel (eu.bcvsolutions.idm.core.api.dto.DefaultResultModel)3