Search in sources :

Example 36 with DefaultResultModel

use of eu.bcvsolutions.idm.core.api.dto.DefaultResultModel in project CzechIdMng by bcvsolutions.

the class DisabledSystemProcessor method process.

@Override
public EventResult<SysProvisioningOperationDto> process(EntityEvent<SysProvisioningOperationDto> event) {
    SysProvisioningOperationDto provisioningOperation = event.getContent();
    SysSystemDto system = systemService.get(provisioningOperation.getSystem());
    // 
    boolean closed = false;
    if (system.isDisabled()) {
        String uid = provisioningOperationService.getByProvisioningOperation(provisioningOperation).getUid();
        ResultModel resultModel = new DefaultResultModel(AccResultCode.PROVISIONING_SYSTEM_DISABLED, ImmutableMap.of("name", uid, "system", system.getName()));
        provisioningOperation.setResult(new OperationResult.Builder(OperationState.NOT_EXECUTED).setModel(resultModel).build());
        // 
        provisioningOperation = provisioningOperationService.saveOperation(provisioningOperation);
        // 
        LOG.info(resultModel.toString());
        notificationManager.send(AccModuleDescriptor.TOPIC_PROVISIONING, new IdmMessageDto.Builder().setModel(resultModel).build());
        // 
        closed = true;
    }
    // set back to event content
    event.setContent(provisioningOperation);
    return new DefaultEventResult<>(event, this, closed);
}
Also used : DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) IdmMessageDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) ResultModel(eu.bcvsolutions.idm.core.api.dto.ResultModel) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) SysProvisioningOperationDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningOperationDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto)

Example 37 with DefaultResultModel

use of eu.bcvsolutions.idm.core.api.dto.DefaultResultModel in project CzechIdMng by bcvsolutions.

the class SynchronizationMonitoringEvaluator method evaluate.

@Override
public IdmMonitoringResultDto evaluate(IdmMonitoringDto monitoring) {
    SysSyncConfigFilter context = new SysSyncConfigFilter();
    context.setIncludeLastLog(Boolean.TRUE);
    UUID synchronizationId = getParameterConverter().toUuid(monitoring.getEvaluatorProperties(), PARAMETER_SYNCHRONIZATION);
    AbstractSysSyncConfigDto sync = syncConfigService.get(synchronizationId, context);
    if (sync == null) {
        throw new EntityNotFoundException(SysSyncConfig.class, synchronizationId);
    }
    // 
    SysSystemMappingDto mapping = DtoUtils.getEmbedded(sync, SysSyncConfig_.systemMapping.getName(), SysSystemMappingDto.class);
    SysSchemaObjectClassDto schema = DtoUtils.getEmbedded(mapping, SysSystemMapping_.objectClass.getName(), SysSchemaObjectClassDto.class);
    SysSystemDto system = systemService.get(schema.getSystem());
    // 
    IdmMonitoringResultDto result = new IdmMonitoringResultDto();
    result.setOwnerId(getLookupService().getOwnerId(sync));
    result.setOwnerType(getLookupService().getOwnerType(SysSyncConfig.class));
    // 
    ResultModel resultModel;
    SysSyncLogDto lastSyncLog = sync.getLastSyncLog();
    if (!sync.isEnabled()) {
        resultModel = new DefaultResultModel(AccResultCode.MONITORING_SYNCHRONIZATION_DISABLED, ImmutableMap.of("synchronizationName", sync.getName(), "systemName", system.getName(), "systemId", system.getId().toString()));
    } else if (lastSyncLog != null) {
        result.setOwnerId(getLookupService().getOwnerId(lastSyncLog));
        result.setOwnerType(getLookupService().getOwnerType(lastSyncLog));
        // 
        // count error and other (~success) operations
        int errorCounter = 0;
        int otherCounter = 0;
        for (SysSyncActionLogDto action : lastSyncLog.getSyncActionLogs()) {
            if (action.getOperationResult() == OperationResultType.ERROR) {
                errorCounter += action.getOperationCount();
            } else {
                otherCounter += action.getOperationCount();
            }
        }
        // 
        if (sync.getLastSyncLog().isContainsError() || errorCounter > 0) {
            result.setValue(String.valueOf(errorCounter));
            resultModel = new DefaultResultModel(AccResultCode.MONITORING_SYNCHRONIZATION_CONTAINS_ERROR, ImmutableMap.of("synchronizationName", sync.getName(), "systemName", system.getName(), "systemId", system.getId().toString(), "count", errorCounter));
        } else {
            result.setValue(String.valueOf(otherCounter));
            resultModel = new DefaultResultModel(AccResultCode.MONITORING_SYNCHRONIZATION_OK, ImmutableMap.of("synchronizationName", sync.getName(), "systemName", system.getName(), "systemId", system.getId().toString(), "count", otherCounter));
        }
    } else {
        resultModel = new DefaultResultModel(AccResultCode.MONITORING_SYNCHRONIZATION_NOT_EXECUTED, ImmutableMap.of("synchronizationName", sync.getName(), "systemName", system.getName(), "systemId", system.getId().toString()));
    }
    // 
    result.setResult(new OperationResultDto.Builder(OperationState.EXECUTED).setModel(resultModel).build());
    // 
    return result;
}
Also used : DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) ResultModel(eu.bcvsolutions.idm.core.api.dto.ResultModel) EntityNotFoundException(eu.bcvsolutions.idm.core.api.exception.EntityNotFoundException) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) SysSyncConfig(eu.bcvsolutions.idm.acc.entity.SysSyncConfig) SysSyncActionLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncActionLogDto) AbstractSysSyncConfigDto(eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto) SysSchemaObjectClassDto(eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto) SysSyncConfigFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSyncConfigFilter) UUID(java.util.UUID) SysSyncLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncLogDto) IdmMonitoringResultDto(eu.bcvsolutions.idm.core.monitoring.api.dto.IdmMonitoringResultDto)

Example 38 with DefaultResultModel

use of eu.bcvsolutions.idm.core.api.dto.DefaultResultModel in project CzechIdMng by bcvsolutions.

the class ProvisioningUniformPasswordNotificationProcessor method process.

@Override
@SuppressWarnings("unchecked")
public EventResult<SysProvisioningOperationDto> process(EntityEvent<SysProvisioningOperationDto> event) {
    SysProvisioningOperationDto provisioningOperation = event.getContent();
    IdmIdentityDto identityDto = null;
    if (provisioningOperation.getEntityIdentifier() != null && SystemEntityType.IDENTITY == provisioningOperation.getEntityType()) {
        identityDto = identityService.get(provisioningOperation.getEntityIdentifier());
    }
    if (identityDto != null && identityDto.getState() != IdentityState.CREATED) {
        // Notification will be send after end of sync.
        if (identityDto.getId() != null) {
            IdmEntityStateDto uniformPasswordState = uniformPasswordManager.getEntityState(identityDto.getId(), identityDto.getClass(), provisioningOperation.getTransactionId());
            UUID systemId = provisioningOperation.getSystem();
            if (systemId != null) {
                AccUniformPasswordDto uniformPasswordBySystem = uniformPasswordManager.getUniformPasswordBySystem(systemId);
                if (uniformPasswordBySystem != null && uniformPasswordState != null) {
                    // Add name of uniform password group to the entity state.
                    uniformPasswordManager.addSystemNameToEntityState(uniformPasswordState, uniformPasswordBySystem.getCode());
                    ResultModel model = uniformPasswordState.getResult().getModel();
                    // Create new parameters for entity state.
                    HashMap<String, Object> newParameters = Maps.newHashMap(model.getParameters());
                    // Add system entity ID to entity state for uniform password (could be used in bulk notification).
                    UUID systemEntityId = provisioningOperation.getSystemEntity();
                    if (systemEntityId != null) {
                        Object successSystemEntitiesObj = model.getParameters().get(UniformPasswordManager.SUCCESS_SYSTEM_ENTITIES);
                        Set<UUID> successSystemEntities = null;
                        if (successSystemEntitiesObj instanceof Set) {
                            successSystemEntities = (Set<UUID>) successSystemEntitiesObj;
                        } else {
                            successSystemEntities = Sets.newHashSet();
                        }
                        successSystemEntities.add(systemEntityId);
                        newParameters.put(UniformPasswordManager.SUCCESS_SYSTEM_ENTITIES, successSystemEntities);
                    }
                    // Save entity state with new parameters.
                    uniformPasswordState.getResult().setModel(new DefaultResultModel(CoreResultCode.IDENTITY_UNIFORM_PASSWORD, newParameters));
                    entityStateManager.saveState(null, uniformPasswordState);
                }
            }
        }
    }
    return new DefaultEventResult<>(event, this);
}
Also used : IdmEntityStateDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto) Set(java.util.Set) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) AccUniformPasswordDto(eu.bcvsolutions.idm.acc.dto.AccUniformPasswordDto) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) ResultModel(eu.bcvsolutions.idm.core.api.dto.ResultModel) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) UUID(java.util.UUID) SysProvisioningOperationDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningOperationDto)

Example 39 with DefaultResultModel

use of eu.bcvsolutions.idm.core.api.dto.DefaultResultModel in project CzechIdMng by bcvsolutions.

the class ReadonlySystemProcessor method process.

@Override
public EventResult<SysProvisioningOperationDto> process(EntityEvent<SysProvisioningOperationDto> event) {
    SysProvisioningOperationDto provisioningOperation = event.getContent();
    SysSystemDto system = systemService.get(provisioningOperation.getSystem());
    boolean closed = false;
    if (system.isReadonly()) {
        String uid = provisioningOperationService.getByProvisioningOperation(provisioningOperation).getUid();
        ResultModel resultModel = new DefaultResultModel(AccResultCode.PROVISIONING_SYSTEM_READONLY, ImmutableMap.of("name", uid, "system", system.getName()));
        provisioningOperation.setResult(new OperationResult.Builder(OperationState.NOT_EXECUTED).setModel(resultModel).build());
        // 
        provisioningOperation = provisioningOperationService.saveOperation(provisioningOperation);
        // 
        LOG.info(resultModel.toString());
        notificationManager.send(AccModuleDescriptor.TOPIC_PROVISIONING, new IdmMessageDto.Builder().setModel(resultModel).build());
        // 
        closed = true;
    }
    // set back to event content
    event.setContent(provisioningOperation);
    return new DefaultEventResult<>(event, this, closed);
}
Also used : DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) IdmMessageDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) ResultModel(eu.bcvsolutions.idm.core.api.dto.ResultModel) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) SysProvisioningOperationDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningOperationDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto)

Example 40 with DefaultResultModel

use of eu.bcvsolutions.idm.core.api.dto.DefaultResultModel in project CzechIdMng by bcvsolutions.

the class ProvisioningOperationMonitoringEvaluator method evaluate.

@Override
public IdmMonitoringResultDto evaluate(IdmMonitoringDto monitoring) {
    IdmMonitoringResultDto result = new IdmMonitoringResultDto();
    ResultModel resultModel;
    // 
    SysProvisioningOperationFilter filter = new SysProvisioningOperationFilter();
    filter.setResultState(OperationState.EXCEPTION);
    filter.setMonitoringIgnored(Boolean.FALSE);
    Long givenNumberOfDays = getParameterConverter().toLong(monitoring.getEvaluatorProperties(), PARAMETER_NUMBER_OF_DAYS);
    if (givenNumberOfDays != null) {
        filter.setCreatedFrom(ZonedDateTime.now().truncatedTo(ChronoUnit.DAYS).minusDays(givenNumberOfDays));
    }
    long count = provisioningOperationService.count(filter);
    // 
    if (count > 0) {
        resultModel = new DefaultResultModel(AccResultCode.MONITORING_PROVISIONING_OPERATION_ERROR, ImmutableMap.of("count", Long.toString(count)));
    } else {
        resultModel = new DefaultResultModel(CoreResultCode.OK);
    }
    // 
    result.setResult(new OperationResultDto.Builder(OperationState.EXECUTED).setModel(resultModel).build());
    result.setValue(String.valueOf(count));
    // 
    return result;
}
Also used : DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) SysProvisioningOperationFilter(eu.bcvsolutions.idm.acc.dto.filter.SysProvisioningOperationFilter) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) ResultModel(eu.bcvsolutions.idm.core.api.dto.ResultModel) IdmMonitoringResultDto(eu.bcvsolutions.idm.core.monitoring.api.dto.IdmMonitoringResultDto)

Aggregations

DefaultResultModel (eu.bcvsolutions.idm.core.api.dto.DefaultResultModel)104 ResultModel (eu.bcvsolutions.idm.core.api.dto.ResultModel)52 UUID (java.util.UUID)48 OperationResultDto (eu.bcvsolutions.idm.core.api.dto.OperationResultDto)40 OperationResult (eu.bcvsolutions.idm.core.api.entity.OperationResult)35 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)25 IdmEntityStateDto (eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto)24 DefaultEventResult (eu.bcvsolutions.idm.core.api.event.DefaultEventResult)21 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)19 HashMap (java.util.HashMap)19 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)18 OperationState (eu.bcvsolutions.idm.core.api.domain.OperationState)16 IdmRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto)16 Autowired (org.springframework.beans.factory.annotation.Autowired)16 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)15 List (java.util.List)15 IdmConceptRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto)14 Set (java.util.Set)14 ImmutableMap (com.google.common.collect.ImmutableMap)13 CoreResultCode (eu.bcvsolutions.idm.core.api.domain.CoreResultCode)13