Search in sources :

Example 6 with EntityNotFoundException

use of eu.bcvsolutions.idm.core.api.exception.EntityNotFoundException in project CzechIdMng by bcvsolutions.

the class SysRemoteServerController method getConnectorTypes.

/**
 * Returns connector types registered on given remote server.
 *
 * @return connector types
 */
@ResponseBody
@RequestMapping(method = RequestMethod.GET, value = "/{backendId}/connector-types")
@PreAuthorize("hasAuthority('" + AccGroupPermission.REMOTESERVER_READ + "')")
@ApiOperation(value = "Get supported connector types", nickname = "getConnectorTypes", tags = { SysRemoteServerController.TAG }, authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = AccGroupPermission.REMOTESERVER_READ, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = AccGroupPermission.REMOTESERVER_READ, description = "") }) })
public Resources<ConnectorTypeDto> getConnectorTypes(@ApiParam(value = "Remote server uuid identifier or code.", required = true) @PathVariable @NotNull String backendId) {
    SysConnectorServerDto connectorServer = getDto(backendId);
    if (connectorServer == null) {
        throw new EntityNotFoundException(getService().getEntityClass(), backendId);
    }
    // 
    try {
        List<IcConnectorInfo> connectorInfos = Lists.newArrayList();
        for (IcConfigurationService config : icConfiguration.getIcConfigs().values()) {
            connectorServer.setPassword(remoteServerService.getPassword(connectorServer.getId()));
            Set<IcConnectorInfo> availableRemoteConnectors = config.getAvailableRemoteConnectors(connectorServer);
            if (CollectionUtils.isNotEmpty(availableRemoteConnectors)) {
                connectorInfos.addAll(availableRemoteConnectors);
            }
        }
        // Find connector types for existing connectors.
        List<ConnectorTypeDto> connectorTypes = connectorManager.getSupportedTypes().stream().filter(connectorType -> {
            return connectorInfos.stream().anyMatch(connectorInfo -> connectorType.getConnectorName().equals(connectorInfo.getConnectorKey().getConnectorName()));
        }).map(connectorType -> {
            // Find connector info and set version to the connectorTypeDto.
            IcConnectorInfo info = connectorInfos.stream().filter(connectorInfo -> connectorType.getConnectorName().equals(connectorInfo.getConnectorKey().getConnectorName())).findFirst().orElse(null);
            ConnectorTypeDto connectorTypeDto = connectorManager.convertTypeToDto(connectorType);
            connectorTypeDto.setLocal(true);
            if (info != null) {
                connectorTypeDto.setVersion(info.getConnectorKey().getBundleVersion());
                connectorTypeDto.setName(info.getConnectorDisplayName());
            }
            return connectorTypeDto;
        }).collect(Collectors.toList());
        // Find connectors without extension (specific connector type).
        List<ConnectorTypeDto> defaultConnectorTypes = connectorInfos.stream().map(info -> {
            ConnectorTypeDto connectorTypeDto = connectorManager.convertIcConnectorInfoToDto(info);
            connectorTypeDto.setLocal(true);
            return connectorTypeDto;
        }).filter(type -> {
            return !connectorTypes.stream().anyMatch(supportedType -> supportedType.getConnectorName().equals(type.getConnectorName()) && supportedType.isHideParentConnector());
        }).collect(Collectors.toList());
        connectorTypes.addAll(defaultConnectorTypes);
        return new Resources<>(connectorTypes.stream().sorted(Comparator.comparing(ConnectorTypeDto::getOrder)).collect(Collectors.toList()));
    } catch (IcInvalidCredentialException e) {
        throw new ResultCodeException(AccResultCode.REMOTE_SERVER_INVALID_CREDENTIAL, ImmutableMap.of("server", e.getHost() + ":" + e.getPort()), e);
    } catch (IcServerNotFoundException e) {
        throw new ResultCodeException(AccResultCode.REMOTE_SERVER_NOT_FOUND, ImmutableMap.of("server", e.getHost() + ":" + e.getPort()), e);
    } catch (IcCantConnectException e) {
        throw new ResultCodeException(AccResultCode.REMOTE_SERVER_CANT_CONNECT, ImmutableMap.of("server", e.getHost() + ":" + e.getPort()), e);
    } catch (IcRemoteServerException e) {
        throw new ResultCodeException(AccResultCode.REMOTE_SERVER_UNEXPECTED_ERROR, ImmutableMap.of("server", e.getHost() + ":" + e.getPort()), e);
    }
}
Also used : PathVariable(org.springframework.web.bind.annotation.PathVariable) RequestParam(org.springframework.web.bind.annotation.RequestParam) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) IcRemoteServerException(eu.bcvsolutions.idm.ic.exception.IcRemoteServerException) Autowired(org.springframework.beans.factory.annotation.Autowired) Enabled(eu.bcvsolutions.idm.core.security.api.domain.Enabled) ApiParam(io.swagger.annotations.ApiParam) SysConnectorServerDto(eu.bcvsolutions.idm.acc.dto.SysConnectorServerDto) IcInvalidCredentialException(eu.bcvsolutions.idm.ic.exception.IcInvalidCredentialException) Valid(javax.validation.Valid) ApiOperation(io.swagger.annotations.ApiOperation) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) Map(java.util.Map) SysRemoteServerService(eu.bcvsolutions.idm.acc.service.api.SysRemoteServerService) Pageable(org.springframework.data.domain.Pageable) AuthorizationScope(io.swagger.annotations.AuthorizationScope) IcCantConnectException(eu.bcvsolutions.idm.ic.exception.IcCantConnectException) IcConfigurationFacade(eu.bcvsolutions.idm.ic.service.api.IcConfigurationFacade) EntityNotFoundException(eu.bcvsolutions.idm.core.api.exception.EntityNotFoundException) ImmutableMap(com.google.common.collect.ImmutableMap) MediaType(org.springframework.http.MediaType) Set(java.util.Set) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) NotNull(javax.validation.constraints.NotNull) Collectors(java.util.stream.Collectors) RestController(org.springframework.web.bind.annotation.RestController) List(java.util.List) ConnectorManager(eu.bcvsolutions.idm.acc.service.api.ConnectorManager) IcConnectorInfo(eu.bcvsolutions.idm.ic.api.IcConnectorInfo) SysRemoteServerFilter(eu.bcvsolutions.idm.acc.dto.filter.SysRemoteServerFilter) AccResultCode(eu.bcvsolutions.idm.acc.domain.AccResultCode) ResultModels(eu.bcvsolutions.idm.core.api.dto.ResultModels) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) HashMap(java.util.HashMap) CollectionUtils(org.apache.commons.collections4.CollectionUtils) RequestBody(org.springframework.web.bind.annotation.RequestBody) HttpServletRequest(javax.servlet.http.HttpServletRequest) Lists(com.google.common.collect.Lists) AbstractReadWriteDtoController(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoController) SwaggerConfig(eu.bcvsolutions.idm.core.api.config.swagger.SwaggerConfig) AccGroupPermission(eu.bcvsolutions.idm.acc.domain.AccGroupPermission) IcConfigurationService(eu.bcvsolutions.idm.ic.service.api.IcConfigurationService) ConnectorTypeDto(eu.bcvsolutions.idm.acc.dto.ConnectorTypeDto) Api(io.swagger.annotations.Api) AccModuleDescriptor(eu.bcvsolutions.idm.acc.AccModuleDescriptor) IcServerNotFoundException(eu.bcvsolutions.idm.ic.exception.IcServerNotFoundException) MultiValueMap(org.springframework.util.MultiValueMap) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) HttpMessageNotReadableException(org.springframework.http.converter.HttpMessageNotReadableException) HttpStatus(org.springframework.http.HttpStatus) IdmBulkActionDto(eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto) BaseController(eu.bcvsolutions.idm.core.api.rest.BaseController) BaseDtoController(eu.bcvsolutions.idm.core.api.rest.BaseDtoController) PageableDefault(org.springframework.data.web.PageableDefault) Resources(org.springframework.hateoas.Resources) ResponseEntity(org.springframework.http.ResponseEntity) Comparator(java.util.Comparator) Authorization(io.swagger.annotations.Authorization) IcServerNotFoundException(eu.bcvsolutions.idm.ic.exception.IcServerNotFoundException) IcInvalidCredentialException(eu.bcvsolutions.idm.ic.exception.IcInvalidCredentialException) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) EntityNotFoundException(eu.bcvsolutions.idm.core.api.exception.EntityNotFoundException) ConnectorTypeDto(eu.bcvsolutions.idm.acc.dto.ConnectorTypeDto) IcConnectorInfo(eu.bcvsolutions.idm.ic.api.IcConnectorInfo) IcConfigurationService(eu.bcvsolutions.idm.ic.service.api.IcConfigurationService) IcCantConnectException(eu.bcvsolutions.idm.ic.exception.IcCantConnectException) IcRemoteServerException(eu.bcvsolutions.idm.ic.exception.IcRemoteServerException) Resources(org.springframework.hateoas.Resources) SysConnectorServerDto(eu.bcvsolutions.idm.acc.dto.SysConnectorServerDto) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 7 with EntityNotFoundException

use of eu.bcvsolutions.idm.core.api.exception.EntityNotFoundException in project CzechIdMng by bcvsolutions.

the class DefaultLongRunningTaskManager method recover.

@Override
@Transactional
public LongRunningFutureTask<?> recover(UUID longRunningTaskId) {
    LOG.info("Processing task [{}] again", longRunningTaskId);
    // 
    IdmLongRunningTaskDto task = service.get(longRunningTaskId);
    if (task == null) {
        throw new EntityNotFoundException(IdmLongRunningTask.class, longRunningTaskId);
    }
    if (task.isRunning() || OperationState.RUNNING == task.getResultState()) {
        throw new ResultCodeException(CoreResultCode.LONG_RUNNING_TASK_IS_RUNNING, ImmutableMap.of("taskId", task.getId()));
    }
    if (!task.isRecoverable()) {
        throw new TaskNotRecoverableException(CoreResultCode.LONG_RUNNING_TASK_NOT_RECOVERABLE, task);
    }
    // 
    // clean previous state and create new LRT instance
    DtoUtils.clearAuditFields(task);
    // clear previous transaction context
    task.getTaskProperties().remove(LongRunningTaskExecutor.PARAMETER_TRANSACTION_CONTEXT);
    // new record
    task.setId(null);
    // clear state
    task.clearState();
    // prevent to execute created task redundantly by asynchronous job
    task.setResult(new OperationResult(OperationState.RUNNING));
    // persist new task
    task = service.save(task);
    // 
    LongRunningTaskExecutor<?> taskExecutor = createTaskExecutor(task);
    if (taskExecutor == null) {
        return null;
    }
    return execute(taskExecutor);
}
Also used : IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) EntityNotFoundException(eu.bcvsolutions.idm.core.api.exception.EntityNotFoundException) TaskNotRecoverableException(eu.bcvsolutions.idm.core.scheduler.exception.TaskNotRecoverableException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 8 with EntityNotFoundException

use of eu.bcvsolutions.idm.core.api.exception.EntityNotFoundException in project CzechIdMng by bcvsolutions.

the class DefaultLongRunningTaskManager method getAttachment.

@Override
public IdmAttachmentDto getAttachment(UUID longRunningTaskId, UUID attachmentId, BasePermission... permission) {
    Assert.notNull(longRunningTaskId, "Task identifier is required.");
    Assert.notNull(attachmentId, "Attachment identifier is required");
    IdmLongRunningTaskDto longRunningTaskDto = service.get(longRunningTaskId, permission);
    if (longRunningTaskDto == null) {
        throw new EntityNotFoundException(service.getEntityClass(), longRunningTaskId);
    }
    IdmAttachmentDto attachmentDto = attachmentManager.get(attachmentId, permission);
    if (attachmentDto == null) {
        throw new EntityNotFoundException(IdmAttachment.class, attachmentId);
    }
    if (!ObjectUtils.isEmpty(PermissionUtils.trimNull(permission)) && !attachmentDto.getOwnerId().equals(longRunningTaskDto.getId())) {
        throw new ForbiddenEntityException((Serializable) attachmentId, PermissionUtils.trimNull(permission));
    }
    // 
    return attachmentDto;
}
Also used : IdmAttachmentDto(eu.bcvsolutions.idm.core.ecm.api.dto.IdmAttachmentDto) IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) EntityNotFoundException(eu.bcvsolutions.idm.core.api.exception.EntityNotFoundException) ForbiddenEntityException(eu.bcvsolutions.idm.core.api.exception.ForbiddenEntityException)

Example 9 with EntityNotFoundException

use of eu.bcvsolutions.idm.core.api.exception.EntityNotFoundException 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 10 with EntityNotFoundException

use of eu.bcvsolutions.idm.core.api.exception.EntityNotFoundException in project CzechIdMng by bcvsolutions.

the class DefaultIdentityProjectionManager method getIdentity.

/**
 * Load identity.
 *
 * @param codeableIdentifier  uuid or username
 * @param permission
 * @return
 */
protected IdmIdentityDto getIdentity(Serializable codeableIdentifier, BasePermission... permission) {
    // codeable decorator
    IdmIdentityDto identity = lookupService.lookupDto(IdmIdentityDto.class, codeableIdentifier);
    if (identity == null) {
        throw new EntityNotFoundException(identityService.getEntityClass(), codeableIdentifier);
    }
    // 
    IdmIdentityFilter context = new IdmIdentityFilter();
    context.setAddPermissions(true);
    context.setAddBasicFields(true);
    // load (~filter) specified form definitions and attributes only
    setAddEavMetadata(context, identity);
    // evaluate access / load eavs
    identity = identityService.get(identity, context, permission);
    // 
    return identity;
}
Also used : IdmIdentityFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter) EntityNotFoundException(eu.bcvsolutions.idm.core.api.exception.EntityNotFoundException) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)

Aggregations

EntityNotFoundException (eu.bcvsolutions.idm.core.api.exception.EntityNotFoundException)30 ApiOperation (io.swagger.annotations.ApiOperation)15 ResponseEntity (org.springframework.http.ResponseEntity)12 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)11 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)10 UUID (java.util.UUID)10 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)9 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)9 IdmLongRunningTaskDto (eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto)7 ResourceSupport (org.springframework.hateoas.ResourceSupport)7 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)6 Transactional (org.springframework.transaction.annotation.Transactional)5 IdmAttachmentDto (eu.bcvsolutions.idm.core.ecm.api.dto.IdmAttachmentDto)4 IOException (java.io.IOException)4 IdmPasswordDto (eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto)3 IdmProfileDto (eu.bcvsolutions.idm.core.api.dto.IdmProfileDto)3 IdmRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto)3 IdmTokenDto (eu.bcvsolutions.idm.core.api.dto.IdmTokenDto)3 AcceptedException (eu.bcvsolutions.idm.core.api.exception.AcceptedException)3 IdmLongRunningTaskFilter (eu.bcvsolutions.idm.core.scheduler.api.dto.filter.IdmLongRunningTaskFilter)3