use of org.eclipse.che.api.core.NotFoundException in project che by eclipse.
the class JpaAccountDao method getById.
@Override
@Transactional
public AccountImpl getById(String id) throws NotFoundException, ServerException {
requireNonNull(id, "Required non-null account id");
final EntityManager manager = managerProvider.get();
try {
AccountImpl account = manager.find(AccountImpl.class, id);
if (account == null) {
throw new NotFoundException(format("Account with id '%s' was not found", id));
}
return account;
} catch (RuntimeException x) {
throw new ServerException(x.getLocalizedMessage(), x);
}
}
use of org.eclipse.che.api.core.NotFoundException in project che by eclipse.
the class RemoteOAuthTokenProvider method getToken.
/** {@inheritDoc} */
@Override
public OAuthToken getToken(String oauthProviderName, String userId) throws IOException {
if (userId.isEmpty()) {
return null;
}
try {
UriBuilder ub = UriBuilder.fromUri(apiEndpoint).path(OAuthAuthenticationService.class).path(OAuthAuthenticationService.class, "token").queryParam("oauth_provider", oauthProviderName);
Link getTokenLink = DtoFactory.newDto(Link.class).withHref(ub.build().toString()).withMethod("GET");
return httpJsonRequestFactory.fromLink(getTokenLink).request().asDto(OAuthToken.class);
} catch (NotFoundException ne) {
LOG.warn("Token not found for user {}", userId);
return null;
} catch (ServerException | UnauthorizedException | ForbiddenException | ConflictException | BadRequestException e) {
LOG.warn("Exception on token retrieval, message : {}", e.getLocalizedMessage());
return null;
}
}
use of org.eclipse.che.api.core.NotFoundException in project che by eclipse.
the class ExtensionCasesTest method setUp.
@Before
public void setUp() throws Exception {
super.setUp();
new File(root, "/project1").mkdir();
List<ProjectConfig> projects = new ArrayList<>();
projects.add(DtoFactory.newDto(ProjectConfigDto.class).withPath("/project1").withName("project1Name").withType("primary1"));
workspaceHolder = new TestWorkspaceHolder(projects);
ProjectTypeRegistry projectTypeRegistry = new ProjectTypeRegistry(new HashSet<>());
projectTypeRegistry.registerProjectType(new PT1());
//projectTypeRegistry.registerProjectType(new PT3());
//ProjectHandlerRegistry projectHandlerRegistry = new ProjectHandlerRegistry(new HashSet<>());
projectRegistry = new ProjectRegistry(workspaceHolder, vfsProvider, projectTypeRegistry, projectHandlerRegistry, eventService);
projectRegistry.initProjects();
pm = new ProjectManager(vfsProvider, projectTypeRegistry, projectRegistry, projectHandlerRegistry, null, fileWatcherNotificationHandler, fileTreeWatcher, workspaceHolder, fileWatcherManager);
pm.initWatcher();
projectHandlerRegistry.register(new ProjectInitHandler() {
@Override
public void onProjectInitialized(ProjectRegistry registry, FolderEntry projectFolder) throws ServerException, NotFoundException, ConflictException, ForbiddenException {
projectFolder.createFile("generated", "test".getBytes());
projectFolder.createFolder("project2");
projectRegistry.setProjectType("/project1/project2", BaseProjectType.ID, false);
//System.out.println(">>S>>> "+projectRegistry);
}
@Override
public String getProjectType() {
return "primary1";
}
});
}
use of org.eclipse.che.api.core.NotFoundException in project che by eclipse.
the class ProjectManagerWriteTest method testInvalidUpdateConfig.
@Test
public void testInvalidUpdateConfig() throws Exception {
ProjectConfig pc = new NewProjectConfigImpl(null, BaseProjectType.ID, null, "name", "descr", null, null, null);
try {
pm.updateProject(pc);
fail("ConflictException: Project path is not defined");
} catch (ConflictException e) {
}
pc = new NewProjectConfigImpl("/nothing", BaseProjectType.ID, null, "name", "descr", null, null, null);
try {
pm.updateProject(pc);
fail("NotFoundException: Project '/nothing' doesn't exist.");
} catch (NotFoundException e) {
}
}
use of org.eclipse.che.api.core.NotFoundException in project che by eclipse.
the class ProjectService method copy.
@POST
@Path("/copy/{path:.*}")
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Copy resource", notes = "Copy resource to a new location which is specified in a query parameter")
@ApiResponses({ @ApiResponse(code = 201, message = ""), @ApiResponse(code = 403, message = "User not authorized to call this operation"), @ApiResponse(code = 404, message = "Not found"), @ApiResponse(code = 409, message = "Resource already exists"), @ApiResponse(code = 500, message = "Internal Server Error") })
public Response copy(@ApiParam("Path to a resource") @PathParam("path") String path, @ApiParam(value = "Path to a new location", required = true) @QueryParam("to") String newParent, CopyOptions copyOptions) throws NotFoundException, ForbiddenException, ConflictException, ServerException {
final VirtualFileEntry entry = projectManager.asVirtualFileEntry(path);
// used to indicate over write of destination
boolean isOverWrite = false;
// used to hold new name set in request body
String newName = entry.getName();
if (copyOptions != null) {
if (copyOptions.getOverWrite() != null) {
isOverWrite = copyOptions.getOverWrite();
}
if (copyOptions.getName() != null) {
newName = copyOptions.getName();
}
}
final VirtualFileEntry copy = projectManager.copyTo(path, newParent, newName, isOverWrite);
final URI location = getServiceContext().getServiceUriBuilder().path(getClass(), copy.isFile() ? "getFile" : "getChildren").build(new String[] { copy.getPath().toString().substring(1) }, false);
if (copy.isFolder()) {
try {
final RegisteredProject project = projectManager.getProject(copy.getPath().toString());
final String name = project.getName();
final String projectType = project.getProjectType().getId();
logProjectCreatedEvent(name, projectType);
} catch (NotFoundException ignore) {
}
}
return Response.created(location).build();
}
Aggregations