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