Search in sources :

Example 31 with ConflictException

use of org.eclipse.che.api.core.ConflictException in project che by eclipse.

the class ProjectManagerWriteTest method testInvalidConfigProjectCreateFailed.

@Test
public void testInvalidConfigProjectCreateFailed() throws Exception {
    // SPECS:
    // If project path is not defined
    // Project creation failed with ConflictException
    ProjectConfig pc = new NewProjectConfigImpl(null, "pt2", null, "name", "descr", null, null, null);
    try {
        pm.createProject(pc, null);
        fail("ConflictException: Path for new project should be defined ");
    } catch (ConflictException e) {
    }
}
Also used : NewProjectConfig(org.eclipse.che.api.core.model.project.NewProjectConfig) ProjectConfig(org.eclipse.che.api.core.model.project.ProjectConfig) ConflictException(org.eclipse.che.api.core.ConflictException) Test(org.junit.Test)

Example 32 with ConflictException

use of org.eclipse.che.api.core.ConflictException in project che by eclipse.

the class LocalVirtualFileSystem method rename.

LocalVirtualFile rename(LocalVirtualFile virtualFile, String newName, String lockToken) throws ForbiddenException, ConflictException, ServerException {
    checkName(newName);
    if (virtualFile.isRoot()) {
        throw new ForbiddenException("Unable rename root folder");
    }
    if (virtualFile.isFile()) {
        if (fileIsLockedAndLockTokenIsInvalid(virtualFile, lockToken)) {
            throw new ForbiddenException(String.format("Unable rename file '%s'. File is locked", virtualFile.getPath()));
        }
    } else {
        final List<VirtualFile> lockedFiles = new LockedFileFinder(virtualFile).findLockedFiles();
        if (!lockedFiles.isEmpty()) {
            throw new ForbiddenException(String.format("Unable rename folder '%s'. Child items '%s' are locked", virtualFile.getPath(), lockedFiles));
        }
    }
    if (newName.equals(virtualFile.getName())) {
        return virtualFile;
    } else {
        final Path newPath = virtualFile.getPath().getParent().newPath(newName);
        final LocalVirtualFile newVirtualFile = new LocalVirtualFile(new File(ioRoot, toIoPath(newPath)), newPath, this);
        if (newVirtualFile.exists()) {
            throw new ConflictException(String.format("Item '%s' already exists", newVirtualFile.getName()));
        }
        doCopy(virtualFile, newVirtualFile);
        addInSearcher(newVirtualFile);
        final Path path = virtualFile.getPath();
        final boolean isFile = virtualFile.isFile();
        doDelete(virtualFile, lockToken);
        deleteInSearcher(path, isFile);
        return newVirtualFile;
    }
}
Also used : VirtualFile(org.eclipse.che.api.vfs.VirtualFile) Path(org.eclipse.che.api.vfs.Path) ForbiddenException(org.eclipse.che.api.core.ForbiddenException) LockedFileFinder(org.eclipse.che.api.vfs.LockedFileFinder) ConflictException(org.eclipse.che.api.core.ConflictException) VirtualFile(org.eclipse.che.api.vfs.VirtualFile) File(java.io.File)

Example 33 with ConflictException

use of org.eclipse.che.api.core.ConflictException 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;
    }
}
Also used : ForbiddenException(org.eclipse.che.api.core.ForbiddenException) ServerException(org.eclipse.che.api.core.ServerException) ConflictException(org.eclipse.che.api.core.ConflictException) UnauthorizedException(org.eclipse.che.api.core.UnauthorizedException) NotFoundException(org.eclipse.che.api.core.NotFoundException) BadRequestException(org.eclipse.che.api.core.BadRequestException) UriBuilder(javax.ws.rs.core.UriBuilder) Link(org.eclipse.che.api.core.rest.shared.dto.Link)

Example 34 with ConflictException

use of org.eclipse.che.api.core.ConflictException 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";
        }
    });
}
Also used : ProjectTypeRegistry(org.eclipse.che.api.project.server.type.ProjectTypeRegistry) ProjectInitHandler(org.eclipse.che.api.project.server.handlers.ProjectInitHandler) ForbiddenException(org.eclipse.che.api.core.ForbiddenException) ServerException(org.eclipse.che.api.core.ServerException) ConflictException(org.eclipse.che.api.core.ConflictException) ArrayList(java.util.ArrayList) NotFoundException(org.eclipse.che.api.core.NotFoundException) ProjectConfig(org.eclipse.che.api.core.model.project.ProjectConfig) File(java.io.File) Before(org.junit.Before)

Example 35 with ConflictException

use of org.eclipse.che.api.core.ConflictException in project che by eclipse.

the class TarArchiverTest method failsExtractArchiveToFolderWhenItContainsItemWithSameNameAndOverwritingIsDisabled.

@Test
public void failsExtractArchiveToFolderWhenItContainsItemWithSameNameAndOverwritingIsDisabled() throws Exception {
    byte[] archive = createTestTarArchive();
    VirtualFile folder = vfsRoot.createFolder("folder");
    VirtualFile arc = folder.createFolder("arc");
    VirtualFile lockedFile = arc.createFolder("a").createFile("_a.txt", "xxx");
    try {
        new TarArchiver(folder).extract(new ByteArrayInputStream(archive), false, 0);
        thrown.expect(ConflictException.class);
    } catch (ConflictException expected) {
        assertEquals("xxx", lockedFile.getContentAsString());
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ConflictException(org.eclipse.che.api.core.ConflictException) Test(org.junit.Test)

Aggregations

ConflictException (org.eclipse.che.api.core.ConflictException)81 VirtualFile (org.eclipse.che.api.vfs.VirtualFile)28 ForbiddenException (org.eclipse.che.api.core.ForbiddenException)25 ServerException (org.eclipse.che.api.core.ServerException)24 Test (org.junit.Test)24 NotFoundException (org.eclipse.che.api.core.NotFoundException)17 Path (org.eclipse.che.api.vfs.Path)12 IOException (java.io.IOException)10 NewProjectConfig (org.eclipse.che.api.core.model.project.NewProjectConfig)8 Unlocker (org.eclipse.che.commons.lang.concurrent.Unlocker)8 ArrayList (java.util.ArrayList)7 BadRequestException (org.eclipse.che.api.core.BadRequestException)7 MachineException (org.eclipse.che.api.machine.server.exception.MachineException)7 File (java.io.File)6 ProjectConfig (org.eclipse.che.api.core.model.project.ProjectConfig)6 CommandImpl (org.eclipse.che.api.machine.server.model.impl.CommandImpl)6 List (java.util.List)5 Map (java.util.Map)5 WorkspaceImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl)5 String.format (java.lang.String.format)4