protected OAuthAuthenticator getAuthenticator(String oauthProviderName) throws NotFoundException { OAuthAuthenticator oauth = providers.getAuthenticator(oauthProviderName); if (oauth == null) { LOG.warn("Unsupported OAuth provider {} ", oauthProviderName); throw new NotFoundException("Unsupported OAuth provider " + oauthProviderName); } return oauth; } }
/** * Gets a logger, if checkLevel is true and if logger has no level defined it will return a * NameNotFound exception */ protected Logger getLogger(String name, boolean checkLevel) throws NotFoundException { LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory(); Logger log = loggerContext.getLogger(name); if (checkLevel && log.getLevel() == null) { throw new NotFoundException("The logger with name " + name + " is not existing."); } return log; } }
@Transactional protected void doRemove(String owner, String service, String name) throws NotFoundException { EntityManager manager = managerProvider.get(); SshPairImpl entity = manager.find(SshPairImpl.class, new SshPairPrimaryKey(owner, service, name)); if (entity == null) { throw new NotFoundException( format("Ssh pair with service '%s' and name '%s' was not found.", service, name)); } manager.remove(entity); manager.flush(); }
@Override protected WorkerImpl getEntity(String userId, String instanceId) throws NotFoundException, ServerException { try { return doGet(userId, instanceId); } catch (NoResultException e) { throw new NotFoundException( format("Worker of workspace '%s' with id '%s' was not found.", instanceId, userId)); } catch (RuntimeException e) { throw new ServerException(e.getMessage(), e); } }
@Override protected StackPermissionsImpl getEntity(String userId, String instanceId) throws NotFoundException, ServerException { try { return doGet(userId, instanceId); } catch (NoResultException e) { throw new NotFoundException( format("Permissions on stack '%s' of user '%s' was not found.", instanceId, userId)); } catch (RuntimeException e) { throw new ServerException(e.getMessage(), e); } }
private InternalEnvironment getInternalEnvironment(Environment environment) throws InfrastructureException, ValidationException, NotFoundException { final String recipeType = environment.getRecipe().getType(); final InternalEnvironmentFactory factory = environmentFactories.get(recipeType); if (factory == null) { throw new NotFoundException( format("InternalEnvironmentFactory is not configured for recipe type: '%s'", recipeType)); } return factory.create(environment); } }
@Override @Transactional public SignatureKeyPairImpl get(String workspaceId) throws NotFoundException, ServerException { final EntityManager manager = managerProvider.get(); try { return new SignatureKeyPairImpl( manager .createNamedQuery("SignKeyPair.getAll", SignatureKeyPairImpl.class) .setParameter("workspaceId", workspaceId) .getSingleResult()); } catch (NoResultException x) { throw new NotFoundException( format("Signature key pair for workspace '%s' doesn't exist", workspaceId)); } catch (RuntimeException ex) { throw new ServerException(ex.getMessage(), ex); } }
@Override @Transactional public StackImpl getById(String id) throws NotFoundException, ServerException { requireNonNull(id, "Required non-null id"); try { final StackImpl stack = managerProvider.get().find(StackImpl.class, id); if (stack == null) { throw new NotFoundException(format("Stack with id '%s' doesn't exist", id)); } return new StackImpl(stack); } catch (RuntimeException x) { throw new ServerException(x.getLocalizedMessage(), x); } }
public void validate(Environment environment) throws NotFoundException, InfrastructureException, ValidationException { String type = environment.getRecipe().getType(); if (!infrastructure.getRecipeTypes().contains(type)) { throw new NotFoundException("Infrastructure not found for type: " + type); } // try to create internal environment to check if the specified environment is valid createInternalEnvironment(environment, emptyMap(), emptyList()); }
@Override @Transactional public WorkspaceImpl get(String id) throws NotFoundException, ServerException { requireNonNull(id, "Required non-null id"); try { final WorkspaceImpl workspace = managerProvider.get().find(WorkspaceImpl.class, id); if (workspace == null) { throw new NotFoundException(format("Workspace with id '%s' doesn't exist", id)); } return new WorkspaceImpl(workspace); } catch (RuntimeException x) { throw new ServerException(x.getLocalizedMessage(), x); } }
@Override @Transactional public StackImpl getById(String id) throws NotFoundException, ServerException { requireNonNull(id, "Required non-null id"); try { final StackImpl stack = managerProvider.get().find(StackImpl.class, id); if (stack == null) { throw new NotFoundException(format("Stack with id '%s' doesn't exist", id)); } return new StackImpl(stack); } catch (RuntimeException x) { throw new ServerException(x.getLocalizedMessage(), x); } }
@Override @Transactional public WorkspaceImpl get(String id) throws NotFoundException, ServerException { requireNonNull(id, "Required non-null id"); try { final WorkspaceImpl workspace = managerProvider.get().find(WorkspaceImpl.class, id); if (workspace == null) { throw new NotFoundException(format("Workspace with id '%s' doesn't exist", id)); } return new WorkspaceImpl(workspace); } catch (RuntimeException x) { throw new ServerException(x.getLocalizedMessage(), x); } }
@Transactional protected StackImpl doUpdate(StackImpl update) throws NotFoundException { final EntityManager manager = managerProvider.get(); if (manager.find(StackImpl.class, update.getId()) == null) { throw new NotFoundException(format("Workspace with id '%s' doesn't exist", update.getId())); } if (update.getWorkspaceConfig() != null) { update.getWorkspaceConfig().getProjects().forEach(ProjectConfigImpl::prePersistAttributes); } StackImpl merged = manager.merge(update); manager.flush(); return merged; } }
@Override @Transactional public WorkspaceImpl get(String name, String namespace) throws NotFoundException, ServerException { requireNonNull(name, "Required non-null name"); requireNonNull(namespace, "Required non-null namespace"); try { return new WorkspaceImpl( managerProvider .get() .createNamedQuery("Workspace.getByName", WorkspaceImpl.class) .setParameter("namespace", namespace) .setParameter("name", name) .getSingleResult()); } catch (NoResultException noResEx) { throw new NotFoundException( format("Workspace with name '%s' in namespace '%s' doesn't exist", name, namespace)); } catch (RuntimeException x) { throw new ServerException(x.getLocalizedMessage(), x); } }
@Transactional protected WorkspaceImpl doUpdate(WorkspaceImpl update) throws NotFoundException { EntityManager manager = managerProvider.get(); if (manager.find(WorkspaceImpl.class, update.getId()) == null) { throw new NotFoundException(format("Workspace with id '%s' doesn't exist", update.getId())); } if (update.getConfig() != null) { update.getConfig().getProjects().forEach(ProjectConfigImpl::prePersistAttributes); } WorkspaceImpl merged = manager.merge(update); manager.flush(); return merged; }
@Transactional protected WorkspaceImpl doUpdate(WorkspaceImpl update) throws NotFoundException { EntityManager manager = managerProvider.get(); if (manager.find(WorkspaceImpl.class, update.getId()) == null) { throw new NotFoundException(format("Workspace with id '%s' doesn't exist", update.getId())); } if (update.getConfig() != null) { update.getConfig().getProjects().forEach(ProjectConfigImpl::prePersistAttributes); } WorkspaceImpl merged = manager.merge(update); manager.flush(); return merged; }
@Override @Transactional public FreeResourcesLimitImpl get(String accountId) throws NotFoundException, ServerException { requireNonNull(accountId, "Required non-null account id"); try { return new FreeResourcesLimitImpl(doGet(accountId)); } catch (NoResultException e) { throw new NotFoundException( "Free resources limit for account '" + accountId + "' was not found"); } catch (RuntimeException e) { throw new ServerException(e.getMessage(), e); } }
@Transactional protected StackImpl doUpdate(StackImpl update) throws NotFoundException { final EntityManager manager = managerProvider.get(); if (manager.find(StackImpl.class, update.getId()) == null) { throw new NotFoundException(format("Workspace with id '%s' doesn't exist", update.getId())); } if (update.getWorkspaceConfig() != null) { update.getWorkspaceConfig().getProjects().forEach(ProjectConfigImpl::prePersistAttributes); } StackImpl merged = manager.merge(update); manager.flush(); return merged; } }
@Override public VcsStatus getStatus(String wsPath) throws ServerException { try { ProjectConfig project = projectManager .getClosest(wsPath) .orElseThrow(() -> new NotFoundException("Can't find project")); String projectFsPath = pathTransformer.transform(project.getPath()).toString(); wsPath = wsPath.substring(wsPath.startsWith(SEPARATOR) ? 1 : 0); String itemPath = wsPath.substring(wsPath.indexOf(SEPARATOR) + 1); Status status = gitConnectionFactory.getConnection(projectFsPath).status(singletonList(itemPath)); if (status.getUntracked().contains(itemPath)) { return UNTRACKED; } else if (status.getAdded().contains(itemPath)) { return ADDED; } else if (status.getModified().contains(itemPath) || status.getChanged().contains(itemPath)) { return MODIFIED; } else { return NOT_MODIFIED; } } catch (GitException | NotFoundException e) { throw new ServerException(e.getMessage()); } }
@DELETE @Path("repository") public void deleteRepository(@Context UriInfo uriInfo) throws ApiException { ProjectConfig project = projectManager .get(projectPath) .orElseThrow(() -> new NotFoundException("Can't find project")); String dotGitWsPath = resolve(absolutize(projectPath), ".git"); fsManager.delete(dotGitWsPath); eventService.publish( newDto(GitRepositoryDeletedEvent.class) .withProjectName(project.getName()) .withProjectPath(projectPath)); }