use of org.eclipse.che.api.core.ForbiddenException 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.ForbiddenException in project che by eclipse.
the class TarArchiverTest method failsExtractArchiveToFolderWhenItContainsLockedFile.
@Test
public void failsExtractArchiveToFolderWhenItContainsLockedFile() throws Exception {
byte[] archive = createTestTarArchive();
VirtualFile folder = vfsRoot.createFolder("folder");
VirtualFile arc = folder.createFolder("arc");
VirtualFile lockedFile = arc.createFolder("a").createFile("_a.txt", "xxx");
lockedFile.lock(0);
try {
new TarArchiver(folder).extract(new ByteArrayInputStream(archive), true, 0);
thrown.expect(ForbiddenException.class);
} catch (ForbiddenException expected) {
assertEquals("xxx", lockedFile.getContentAsString());
}
}
use of org.eclipse.che.api.core.ForbiddenException in project che by eclipse.
the class ZipArchiverTest method failsExtractArchiveToFolderWhenItContainsLockedFile.
@Test
public void failsExtractArchiveToFolderWhenItContainsLockedFile() throws Exception {
byte[] archive = createTestZipArchive();
VirtualFile folder = vfsRoot.createFolder("folder");
VirtualFile arc = folder.createFolder("arc");
VirtualFile lockedFile = arc.createFolder("a").createFile("_a.txt", "xxx");
lockedFile.lock(0);
try {
new ZipArchiver(folder).extract(new ByteArrayInputStream(archive), true, 0);
thrown.expect(ForbiddenException.class);
} catch (ForbiddenException expected) {
assertEquals("xxx", lockedFile.getContentAsString());
}
}
use of org.eclipse.che.api.core.ForbiddenException in project che by eclipse.
the class ProjectService method uploadZip.
private static Response uploadZip(VirtualFile parent, Iterator<FileItem> formData) throws ForbiddenException, ConflictException, ServerException {
try {
FileItem contentItem = null;
boolean overwrite = false;
boolean skipFirstLevel = false;
while (formData.hasNext()) {
FileItem item = formData.next();
if (!item.isFormField()) {
if (contentItem == null) {
contentItem = item;
} else {
throw new ServerException("More then one upload file is found but only one should be. ");
}
} else if ("overwrite".equals(item.getFieldName())) {
overwrite = Boolean.parseBoolean(item.getString().trim());
} else if ("skipFirstLevel".equals(item.getFieldName())) {
skipFirstLevel = Boolean.parseBoolean(item.getString().trim());
}
}
if (contentItem == null) {
throw new ServerException("Cannot find file for upload. ");
}
try {
importZip(parent, contentItem.getInputStream(), overwrite, skipFirstLevel);
} catch (IOException ioe) {
throw new ServerException(ioe.getMessage(), ioe);
}
return Response.ok("", MediaType.TEXT_HTML).build();
} catch (ForbiddenException | ConflictException | ServerException e) {
HtmlErrorFormatter.sendErrorAsHTML(e);
// never thrown
throw e;
}
}
use of org.eclipse.che.api.core.ForbiddenException in project che by eclipse.
the class LocalVirtualFileSystem method createFolder.
LocalVirtualFile createFolder(LocalVirtualFile parent, String name) throws ForbiddenException, ConflictException, ServerException {
checkName(name);
if (parent.isFolder()) {
final Path newPath = parent.getPath().newPath(name);
final File newIoFile = new File(ioRoot, toIoPath(newPath));
if (!newIoFile.mkdirs()) {
if (newIoFile.exists()) {
throw new ConflictException(String.format("Item '%s' already exists", newPath));
}
}
return new LocalVirtualFile(newIoFile, newPath, this);
} else {
throw new ForbiddenException("Unable create folder. Item specified as parent is not a folder");
}
}
Aggregations