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