use of org.eclipse.che.api.core.NotFoundException in project che by eclipse.
the class Workspace method createResource.
public void createResource(IResource resource, int updateFlags) throws CoreException {
try {
IPath path = resource.getFullPath();
switch(resource.getType()) {
case IResource.FILE:
String newName = path.lastSegment();
VirtualFileEntry child = getProjectsRoot().getChild(path.removeLastSegments(1).toOSString());
if (child == null) {
throw new NotFoundException("Can't find parent folder: " + path.removeLastSegments(1).toOSString());
}
FolderEntry entry = (FolderEntry) child;
entry.createFile(newName, new byte[0]);
break;
case IResource.FOLDER:
getProjectsRoot().createFolder(path.toOSString());
break;
case IResource.PROJECT:
ProjectConfigImpl projectConfig = new ProjectConfigImpl();
projectConfig.setPath(resource.getName());
projectConfig.setName(resource.getName());
projectConfig.setType(BaseProjectType.ID);
projectManager.get().createProject(projectConfig, new HashMap<>());
break;
default:
throw new UnsupportedOperationException();
}
} catch (ForbiddenException | ConflictException | ServerException | NotFoundException e) {
throw new CoreException(new Status(0, ResourcesPlugin.getPluginId(), e.getMessage(), e));
}
}
use of org.eclipse.che.api.core.NotFoundException in project che by eclipse.
the class ProjectManagerWriteTest method testImportProjectWithoutImporterFailed.
@Test
public void testImportProjectWithoutImporterFailed() throws Exception {
SourceStorage sourceConfig = DtoFactory.newDto(SourceStorageDto.class).withType("nothing");
try {
pm.importProject("/testImportProject", sourceConfig, false, () -> new ProjectImportOutputWSLineConsumer("testImportProject", "ws", 300));
fail("NotFoundException: Unable import sources project from 'null'. Sources type 'nothing' is not supported.");
} catch (NotFoundException e) {
}
}
use of org.eclipse.che.api.core.NotFoundException in project che by eclipse.
the class LocalWorkspaceFolderPathProvider method getPath.
@Override
public String getPath(@Assisted("workspace") String workspaceId) throws IOException {
if (!isWindows && hostProjectsFolder != null) {
return hostProjectsFolder;
}
try {
WorkspaceManager workspaceManager = this.workspaceManager.get();
Workspace workspace = workspaceManager.getWorkspace(workspaceId);
String wsName = workspace.getConfig().getName();
return doGetPathByName(wsName);
} catch (NotFoundException | ServerException e) {
throw new IOException(e.getLocalizedMessage());
}
}
use of org.eclipse.che.api.core.NotFoundException in project che by eclipse.
the class DockerProcess method checkAlive.
@Override
public void checkAlive() throws MachineException, NotFoundException {
// Read pid from file and run 'kill -0 [pid]' command.
final String isAliveCmd = format("[ -r %1$s ] && kill -0 $(cat %1$s) || echo 'Unable read PID file'", pidFilePath);
final ListLineConsumer output = new ListLineConsumer();
final String[] command = { "/bin/sh", "-c", isAliveCmd };
Exec exec;
try {
exec = docker.createExec(CreateExecParams.create(container, command).withDetach(false));
} catch (IOException e) {
throw new MachineException(format("Error occurs while initializing command %s in docker container %s: %s", Arrays.toString(command), container, e.getMessage()), e);
}
try {
docker.startExec(StartExecParams.create(exec.getId()), new LogMessagePrinter(output));
} catch (IOException e) {
throw new MachineException(format("Error occurs while executing command %s in docker container %s: %s", Arrays.toString(exec.getCommand()), container, e.getMessage()), e);
}
// 'kill -0 [pid]' is silent if process is running or print "No such process" message otherwise
if (!output.getText().isEmpty()) {
throw new NotFoundException(format("Process with pid %s not found", getPid()));
}
}
use of org.eclipse.che.api.core.NotFoundException in project che by eclipse.
the class OAuthAuthenticationService method token.
/**
* Gets OAuth token for user.
*
* @param oauthProvider
* OAuth provider name
* @return OAuthToken
* @throws ServerException
*/
@GET
@Path("token")
@Produces(MediaType.APPLICATION_JSON)
public OAuthToken token(@Required @QueryParam("oauth_provider") String oauthProvider) throws ServerException, BadRequestException, NotFoundException, ForbiddenException {
OAuthAuthenticator provider = getAuthenticator(oauthProvider);
final Subject subject = EnvironmentContext.getCurrent().getSubject();
try {
OAuthToken token = provider.getToken(subject.getUserId());
if (token == null) {
token = provider.getToken(subject.getUserName());
}
if (token != null) {
return token;
}
throw new NotFoundException("OAuth token for user " + subject.getUserId() + " was not found");
} catch (IOException e) {
throw new ServerException(e.getLocalizedMessage(), e);
}
}
Aggregations