Search in sources :

Example 86 with ServerException

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

the class LuceneSearcher method doInit.

protected final synchronized void doInit() throws ServerException {
    try {
        luceneIndexWriter = new IndexWriter(makeDirectory(), new IndexWriterConfig(makeAnalyzer()));
        searcherManager = new SearcherManager(luceneIndexWriter, true, new SearcherFactory());
        closed = false;
    } catch (IOException e) {
        throw new ServerException(e);
    }
}
Also used : SearcherFactory(org.apache.lucene.search.SearcherFactory) ServerException(org.eclipse.che.api.core.ServerException) IndexWriter(org.apache.lucene.index.IndexWriter) SearcherManager(org.apache.lucene.search.SearcherManager) IOException(java.io.IOException) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig)

Example 87 with ServerException

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

the class LuceneSearcher method delete.

@Override
public final void delete(String path, boolean isFile) throws ServerException {
    try {
        if (isFile) {
            Term term = new Term(PATH_FIELD, path);
            getIndexWriter().deleteDocuments(term);
        } else {
            Term term = new Term(PATH_FIELD, path + '/');
            getIndexWriter().deleteDocuments(new PrefixQuery(term));
        }
    } catch (OutOfMemoryError oome) {
        close();
        throw oome;
    } catch (IOException e) {
        throw new ServerException(e.getMessage(), e);
    }
}
Also used : ServerException(org.eclipse.che.api.core.ServerException) PrefixQuery(org.apache.lucene.search.PrefixQuery) Term(org.apache.lucene.index.Term) IOException(java.io.IOException)

Example 88 with ServerException

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

the class LuceneSearcher method search.

@Override
public SearchResult search(QueryExpression query) throws ServerException {
    IndexSearcher luceneSearcher = null;
    try {
        final long startTime = System.currentTimeMillis();
        searcherManager.maybeRefresh();
        luceneSearcher = searcherManager.acquire();
        Query luceneQuery = createLuceneQuery(query);
        ScoreDoc after = null;
        final int numSkipDocs = Math.max(0, query.getSkipCount());
        if (numSkipDocs > 0) {
            after = skipScoreDocs(luceneSearcher, luceneQuery, numSkipDocs);
        }
        final int numDocs = query.getMaxItems() > 0 ? Math.min(query.getMaxItems(), RESULT_LIMIT) : RESULT_LIMIT;
        TopDocs topDocs = luceneSearcher.searchAfter(after, luceneQuery, numDocs);
        final int totalHitsNum = topDocs.totalHits;
        List<SearchResultEntry> results = newArrayList();
        for (int i = 0; i < topDocs.scoreDocs.length; i++) {
            ScoreDoc scoreDoc = topDocs.scoreDocs[i];
            String filePath = luceneSearcher.doc(scoreDoc.doc).getField(PATH_FIELD).stringValue();
            results.add(new SearchResultEntry(filePath));
        }
        final long elapsedTimeMillis = System.currentTimeMillis() - startTime;
        boolean hasMoreToRetrieve = numSkipDocs + topDocs.scoreDocs.length + 1 < totalHitsNum;
        QueryExpression nextPageQueryExpression = null;
        if (hasMoreToRetrieve) {
            nextPageQueryExpression = createNextPageQuery(query, numSkipDocs + topDocs.scoreDocs.length);
        }
        return SearchResult.aSearchResult().withResults(results).withTotalHits(totalHitsNum).withNextPageQueryExpression(nextPageQueryExpression).withElapsedTimeMillis(elapsedTimeMillis).build();
    } catch (IOException | ParseException e) {
        throw new ServerException(e.getMessage(), e);
    } finally {
        try {
            searcherManager.release(luceneSearcher);
        } catch (IOException e) {
            LOG.error(e.getMessage());
        }
    }
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) ServerException(org.eclipse.che.api.core.ServerException) Query(org.apache.lucene.search.Query) PrefixQuery(org.apache.lucene.search.PrefixQuery) BooleanQuery(org.apache.lucene.search.BooleanQuery) IOException(java.io.IOException) ScoreDoc(org.apache.lucene.search.ScoreDoc) TopDocs(org.apache.lucene.search.TopDocs) ParseException(org.apache.lucene.queryparser.classic.ParseException) QueryExpression(org.eclipse.che.api.vfs.search.QueryExpression) SearchResultEntry(org.eclipse.che.api.vfs.search.SearchResultEntry)

Example 89 with ServerException

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

the class LanguageServerRegistryImpl method extractProjectPath.

protected String extractProjectPath(String filePath) throws LanguageServerException {
    FolderEntry root;
    try {
        root = projectManagerProvider.get().getProjectsRoot();
    } catch (ServerException e) {
        throw new LanguageServerException("Project not found for " + filePath, e);
    }
    if (!filePath.startsWith(PROJECT_FOLDER_PATH)) {
        throw new LanguageServerException("Project not found for " + filePath);
    }
    VirtualFileEntry fileEntry;
    try {
        fileEntry = root.getChild(filePath.substring(PROJECT_FOLDER_PATH.length() + 1));
    } catch (ServerException e) {
        throw new LanguageServerException("Project not found for " + filePath, e);
    }
    if (fileEntry == null) {
        throw new LanguageServerException("Project not found for " + filePath);
    }
    return PROJECT_FOLDER_PATH + fileEntry.getProject();
}
Also used : LanguageServerException(org.eclipse.che.api.languageserver.exception.LanguageServerException) LanguageServerException(org.eclipse.che.api.languageserver.exception.LanguageServerException) ServerException(org.eclipse.che.api.core.ServerException) FolderEntry(org.eclipse.che.api.project.server.FolderEntry) VirtualFileEntry(org.eclipse.che.api.project.server.VirtualFileEntry)

Example 90 with ServerException

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

the class LocalVirtualFileSystem method createFile.

LocalVirtualFile createFile(LocalVirtualFile parent, String name, InputStream content) throws ForbiddenException, ConflictException, ServerException {
    checkName(name);
    if (Path.of(name).length() > 1) {
        throw new ServerException(String.format("Invalid name '%s'", name));
    }
    if (parent.isFolder()) {
        final Path newPath = parent.getPath().newPath(name);
        final File newIoFile = new File(ioRoot, toIoPath(newPath));
        try {
            if (!newIoFile.createNewFile()) {
                throw new ConflictException(String.format("Item '%s' already exists", newPath));
            }
        } catch (IOException e) {
            String errorMessage = String.format("Unable create new file '%s'", newPath);
            LOG.error(errorMessage + "\n" + e.getMessage(), e);
            throw new ServerException(errorMessage);
        }
        final LocalVirtualFile newVirtualFile = new LocalVirtualFile(newIoFile, newPath, this);
        if (content != null) {
            doUpdateContent(newVirtualFile, content);
        }
        addInSearcher(newVirtualFile);
        return newVirtualFile;
    } else {
        throw new ForbiddenException("Unable create new file. Item specified as parent is not a folder");
    }
}
Also used : Path(org.eclipse.che.api.vfs.Path) ForbiddenException(org.eclipse.che.api.core.ForbiddenException) ServerException(org.eclipse.che.api.core.ServerException) ConflictException(org.eclipse.che.api.core.ConflictException) IOException(java.io.IOException) VirtualFile(org.eclipse.che.api.vfs.VirtualFile) File(java.io.File)

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