Search in sources :

Example 6 with ServerException

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

the class ProjectServiceTest method registerImporter.

private void registerImporter(String importType, InputStream zip) throws Exception {
    final ValueHolder<FolderEntry> folderHolder = new ValueHolder<>();
    importerRegistry.register(new ProjectImporter() {

        @Override
        public String getId() {
            return importType;
        }

        @Override
        public boolean isInternal() {
            return false;
        }

        @Override
        public String getDescription() {
            return "Chuck importer";
        }

        @Override
        public void importSources(FolderEntry baseFolder, SourceStorage storage) throws ConflictException, ServerException, ForbiddenException {
            importSources(baseFolder, storage, LineConsumerFactory.NULL);
        }

        @Override
        public void importSources(FolderEntry baseFolder, SourceStorage storage, LineConsumerFactory importOutputConsumerFactory) throws ConflictException, ServerException, ForbiddenException {
            // Don't really use location in this test.
            baseFolder.getVirtualFile().unzip(zip, true, 0);
            folderHolder.set(baseFolder);
        }

        @Override
        public ImporterCategory getCategory() {
            return ImporterCategory.ARCHIVE;
        }
    });
}
Also used : SourceStorage(org.eclipse.che.api.core.model.project.SourceStorage) ForbiddenException(org.eclipse.che.api.core.ForbiddenException) ServerException(org.eclipse.che.api.core.ServerException) ConflictException(org.eclipse.che.api.core.ConflictException) LineConsumerFactory(org.eclipse.che.api.core.util.LineConsumerFactory) ValueHolder(org.eclipse.che.api.core.util.ValueHolder) ProjectImporter(org.eclipse.che.api.project.server.importer.ProjectImporter)

Example 7 with ServerException

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

the class LocalVirtualFileSystem method getFileLock.

private FileLock getFileLock(LocalVirtualFile virtualFile) throws ServerException {
    final PathLockFactory.PathLock lockFilePathLock = pathLockFactory.getLock(virtualFile.getPath(), true).acquire(WAIT_FOR_FILE_LOCK_TIMEOUT);
    try {
        final FileLock lock;
        try {
            lock = lockTokensCache.get(virtualFile.getPath());
        } catch (ExecutionException e) {
            String errorMessage = String.format("Unable get lock of file '%s'", virtualFile.getPath());
            LOG.error(errorMessage + "\n" + e.getCause().getMessage(), e.getCause());
            throw new ServerException(errorMessage);
        }
        if (NO_LOCK == lock) {
            return lock;
        }
        if (lock.getExpired() < System.currentTimeMillis()) {
            final File fileLockIoFile = getFileLockIoFile(virtualFile.getPath());
            if (!fileLockIoFile.delete()) {
                if (fileLockIoFile.exists()) {
                    FileCleaner.addFile(fileLockIoFile);
                    LOG.warn("Unable delete lock file %s", fileLockIoFile);
                }
            }
            lockTokensCache.put(virtualFile.getPath(), NO_LOCK);
            return NO_LOCK;
        }
        return lock;
    } finally {
        lockFilePathLock.release();
    }
}
Also used : PathLockFactory(org.eclipse.che.api.vfs.PathLockFactory) ServerException(org.eclipse.che.api.core.ServerException) ExecutionException(java.util.concurrent.ExecutionException) VirtualFile(org.eclipse.che.api.vfs.VirtualFile) File(java.io.File)

Example 8 with ServerException

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

the class LocalVirtualFileSystem method untar.

void untar(LocalVirtualFile parent, InputStream tarArchive, boolean overwrite, int stripNumber) throws ForbiddenException, ConflictException, ServerException {
    if (archiverFactory == null)
        throw new ServerException("VFS: Could not create tar archiver. Archiver Factory is not properly configured (is null)");
    if (parent.isFolder()) {
        extract(archiverFactory.createArchiver(parent, "tar"), tarArchive, overwrite, stripNumber);
        addInSearcher(parent);
    } else {
        throw new ForbiddenException(String.format("Unable import tar archive. Item '%s' is not a folder", parent.getPath()));
    }
}
Also used : ForbiddenException(org.eclipse.che.api.core.ForbiddenException) ServerException(org.eclipse.che.api.core.ServerException)

Example 9 with ServerException

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

the class MemoryVirtualFile method compress.

private InputStream compress(Archiver archiver) throws ForbiddenException, ServerException {
    try {
        ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
        archiver.compress(byteOut);
        return new ByteArrayInputStream(byteOut.toByteArray());
    } catch (IOException e) {
        throw new ServerException(e.getMessage(), e);
    }
}
Also used : ServerException(org.eclipse.che.api.core.ServerException) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 10 with ServerException

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

the class MemoryVirtualFile method copyTo.

@Override
public VirtualFile copyTo(VirtualFile parent, String newName, boolean overwrite) throws ForbiddenException, ConflictException, ServerException {
    checkExistence();
    ((MemoryVirtualFile) parent).checkExistence();
    if (isRoot()) {
        throw new ServerException("Unable copy root folder");
    }
    if (newName == null || newName.trim().isEmpty()) {
        newName = this.getName();
    }
    if (parent.isFolder()) {
        VirtualFile copy = doCopy((MemoryVirtualFile) parent, newName, overwrite);
        addInSearcher(copy);
        return copy;
    } else {
        throw new ForbiddenException(String.format("Unable create copy of '%s'. Item '%s' specified as parent is not a folder.", getPath(), parent.getPath()));
    }
}
Also used : VirtualFile(org.eclipse.che.api.vfs.VirtualFile) ForbiddenException(org.eclipse.che.api.core.ForbiddenException) ServerException(org.eclipse.che.api.core.ServerException)

Aggregations

ServerException (org.eclipse.che.api.core.ServerException)143 IOException (java.io.IOException)51 ForbiddenException (org.eclipse.che.api.core.ForbiddenException)37 NotFoundException (org.eclipse.che.api.core.NotFoundException)37 ConflictException (org.eclipse.che.api.core.ConflictException)32 File (java.io.File)22 Test (org.testng.annotations.Test)20 ArrayList (java.util.ArrayList)19 VirtualFile (org.eclipse.che.api.vfs.VirtualFile)19 List (java.util.List)15 WorkspaceImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl)15 Map (java.util.Map)13 Transactional (com.google.inject.persist.Transactional)12 BadRequestException (org.eclipse.che.api.core.BadRequestException)12 InputStream (java.io.InputStream)11 Unlocker (org.eclipse.che.commons.lang.concurrent.Unlocker)10 String.format (java.lang.String.format)9 Path (javax.ws.rs.Path)9 Produces (javax.ws.rs.Produces)9 HashMap (java.util.HashMap)8