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);
}
}
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);
}
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;
}
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;
}
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;
}
Aggregations