use of javax.ws.rs.GET in project che by eclipse.
the class ProjectService method search.
@GET
@Path("/search/{path:.*}")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Search for resources", notes = "Search for resources applying a number of search filters as query parameters", response = ItemReference.class, responseContainer = "List")
@ApiResponses({ @ApiResponse(code = 200, message = "OK"), @ApiResponse(code = 403, message = "User not authorized to call this operation"), @ApiResponse(code = 404, message = "Not found"), @ApiResponse(code = 409, message = "Conflict error"), @ApiResponse(code = 500, message = "Internal Server Error") })
public List<ItemReference> search(@ApiParam(value = "Path to resource, i.e. where to search?", required = true) @PathParam("path") String path, @ApiParam(value = "Resource name") @QueryParam("name") String name, @ApiParam(value = "Search keywords") @QueryParam("text") String text, @ApiParam(value = "Maximum items to display. If this parameter is dropped, there are no limits") @QueryParam("maxItems") @DefaultValue("-1") int maxItems, @ApiParam(value = "Skip count") @QueryParam("skipCount") int skipCount) throws NotFoundException, ForbiddenException, ConflictException, ServerException {
final Searcher searcher;
try {
searcher = projectManager.getSearcher();
} catch (NotFoundException e) {
LOG.warn(e.getLocalizedMessage());
return Collections.emptyList();
}
if (skipCount < 0) {
throw new ConflictException(String.format("Invalid 'skipCount' parameter: %d.", skipCount));
}
final QueryExpression expr = new QueryExpression().setPath(path.startsWith("/") ? path : ('/' + path)).setName(name).setText(text).setMaxItems(maxItems).setSkipCount(skipCount);
final SearchResult result = searcher.search(expr);
final List<SearchResultEntry> searchResultEntries = result.getResults();
final List<ItemReference> items = new ArrayList<>(searchResultEntries.size());
final FolderEntry root = projectManager.getProjectsRoot();
for (SearchResultEntry searchResultEntry : searchResultEntries) {
final VirtualFileEntry child = root.getChild(searchResultEntry.getFilePath());
if (child != null && child.isFile()) {
items.add(injectFileLinks(asDto((FileEntry) child)));
}
}
return items;
}
use of javax.ws.rs.GET in project che by eclipse.
the class ProjectService method exportFile.
@GET
@Path("/export/file/{path:.*}")
@Produces(MediaType.APPLICATION_OCTET_STREAM)
public Response exportFile(@ApiParam(value = "Path to resource to be imported") @PathParam("path") String path) throws NotFoundException, ForbiddenException, ServerException {
final FileEntry file = projectManager.asFile(path);
if (file == null) {
throw new NotFoundException("File not found " + path);
}
final VirtualFile virtualFile = file.getVirtualFile();
return Response.ok(virtualFile.getContent(), TIKA.detect(virtualFile.getName())).lastModified(new Date(virtualFile.getLastModificationDate())).header(HttpHeaders.CONTENT_LENGTH, Long.toString(virtualFile.getLength())).header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + virtualFile.getName() + '"').build();
}
use of javax.ws.rs.GET in project hbase by apache.
the class RowResource method get.
@GET
@Produces({ MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF, MIMETYPE_PROTOBUF_IETF })
public Response get(@Context final UriInfo uriInfo) {
if (LOG.isTraceEnabled()) {
LOG.trace("GET " + uriInfo.getAbsolutePath());
}
servlet.getMetrics().incrementRequests(1);
MultivaluedMap<String, String> params = uriInfo.getQueryParameters();
try {
ResultGenerator generator = ResultGenerator.fromRowSpec(tableResource.getName(), rowspec, null, !params.containsKey(NOCACHE_PARAM_NAME));
if (!generator.hasNext()) {
servlet.getMetrics().incrementFailedGetRequests(1);
return Response.status(Response.Status.NOT_FOUND).type(MIMETYPE_TEXT).entity("Not found" + CRLF).build();
}
int count = 0;
CellSetModel model = new CellSetModel();
Cell value = generator.next();
byte[] rowKey = CellUtil.cloneRow(value);
RowModel rowModel = new RowModel(rowKey);
do {
if (!Bytes.equals(CellUtil.cloneRow(value), rowKey)) {
model.addRow(rowModel);
rowKey = CellUtil.cloneRow(value);
rowModel = new RowModel(rowKey);
}
rowModel.addCell(new CellModel(CellUtil.cloneFamily(value), CellUtil.cloneQualifier(value), value.getTimestamp(), CellUtil.cloneValue(value)));
if (++count > rowspec.getMaxValues()) {
break;
}
value = generator.next();
} while (value != null);
model.addRow(rowModel);
servlet.getMetrics().incrementSucessfulGetRequests(1);
return Response.ok(model).build();
} catch (Exception e) {
servlet.getMetrics().incrementFailedPutRequests(1);
return processException(e);
}
}
use of javax.ws.rs.GET in project hbase by apache.
the class ScannerInstanceResource method get.
@GET
@Produces({ MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF, MIMETYPE_PROTOBUF_IETF })
public Response get(@Context final UriInfo uriInfo, @QueryParam("n") int maxRows, @QueryParam("c") final int maxValues) {
if (LOG.isTraceEnabled()) {
LOG.trace("GET " + uriInfo.getAbsolutePath());
}
servlet.getMetrics().incrementRequests(1);
if (generator == null) {
servlet.getMetrics().incrementFailedGetRequests(1);
return Response.status(Response.Status.NOT_FOUND).type(MIMETYPE_TEXT).entity("Not found" + CRLF).build();
}
CellSetModel model = new CellSetModel();
RowModel rowModel = null;
byte[] rowKey = null;
int limit = batch;
if (maxValues > 0) {
limit = maxValues;
}
int count = limit;
do {
Cell value = null;
try {
value = generator.next();
} catch (IllegalStateException e) {
if (ScannerResource.delete(id)) {
servlet.getMetrics().incrementSucessfulDeleteRequests(1);
} else {
servlet.getMetrics().incrementFailedDeleteRequests(1);
}
servlet.getMetrics().incrementFailedGetRequests(1);
return Response.status(Response.Status.GONE).type(MIMETYPE_TEXT).entity("Gone" + CRLF).build();
} catch (IllegalArgumentException e) {
Throwable t = e.getCause();
if (t instanceof TableNotFoundException) {
return Response.status(Response.Status.NOT_FOUND).type(MIMETYPE_TEXT).entity("Not found" + CRLF).build();
}
throw e;
}
if (value == null) {
if (LOG.isTraceEnabled()) {
LOG.trace("generator exhausted");
}
// returned
if (count == limit) {
return Response.noContent().build();
}
break;
}
if (rowKey == null) {
rowKey = CellUtil.cloneRow(value);
rowModel = new RowModel(rowKey);
}
if (!Bytes.equals(CellUtil.cloneRow(value), rowKey)) {
// specified number of rows
if (maxRows > 0) {
if (--maxRows == 0) {
generator.putBack(value);
break;
}
}
model.addRow(rowModel);
rowKey = CellUtil.cloneRow(value);
rowModel = new RowModel(rowKey);
}
rowModel.addCell(new CellModel(CellUtil.cloneFamily(value), CellUtil.cloneQualifier(value), value.getTimestamp(), CellUtil.cloneValue(value)));
} while (--count > 0);
model.addRow(rowModel);
ResponseBuilder response = Response.ok(model);
response.cacheControl(cacheControl);
servlet.getMetrics().incrementSucessfulGetRequests(1);
return response.build();
}
use of javax.ws.rs.GET in project hbase by apache.
the class RegionsResource method get.
@GET
@Produces({ MIMETYPE_TEXT, MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF, MIMETYPE_PROTOBUF_IETF })
public Response get(@Context final UriInfo uriInfo) {
if (LOG.isTraceEnabled()) {
LOG.trace("GET " + uriInfo.getAbsolutePath());
}
servlet.getMetrics().incrementRequests(1);
try {
TableName tableName = TableName.valueOf(tableResource.getName());
TableInfoModel model = new TableInfoModel(tableName.getNameAsString());
Connection connection = ConnectionFactory.createConnection(servlet.getConfiguration());
@SuppressWarnings("deprecation") Map<HRegionInfo, ServerName> regions = MetaTableAccessor.allTableRegions(connection, tableName);
connection.close();
for (Map.Entry<HRegionInfo, ServerName> e : regions.entrySet()) {
HRegionInfo hri = e.getKey();
ServerName addr = e.getValue();
model.add(new TableRegionModel(tableName.getNameAsString(), hri.getRegionId(), hri.getStartKey(), hri.getEndKey(), addr.getHostAndPort()));
}
ResponseBuilder response = Response.ok(model);
response.cacheControl(cacheControl);
servlet.getMetrics().incrementSucessfulGetRequests(1);
return response.build();
} catch (TableNotFoundException e) {
servlet.getMetrics().incrementFailedGetRequests(1);
return Response.status(Response.Status.NOT_FOUND).type(MIMETYPE_TEXT).entity("Not found" + CRLF).build();
} catch (IOException e) {
servlet.getMetrics().incrementFailedGetRequests(1);
return Response.status(Response.Status.SERVICE_UNAVAILABLE).type(MIMETYPE_TEXT).entity("Unavailable" + CRLF).build();
}
}
Aggregations