Search in sources :

Example 11 with GET

use of jakarta.ws.rs.GET in project OpenGrok by OpenGrok.

the class FileController method getGenre.

@GET
@CorsEnable
@PathAuthorized
@Path("/genre")
@Produces(MediaType.TEXT_PLAIN)
public String getGenre(@Context HttpServletRequest request, @Context HttpServletResponse response, @QueryParam("path") final String path) throws IOException, ParseException, NoPathParameterException {
    File file = toFile(path);
    Document doc;
    if ((doc = getDocument(file)) == null) {
        response.sendError(HttpServletResponse.SC_NOT_FOUND, "Cannot get document for file");
        return null;
    }
    AbstractAnalyzer.Genre genre = AbstractAnalyzer.Genre.get(doc.get(QueryBuilder.T));
    if (genre == null) {
        response.sendError(HttpServletResponse.SC_NOT_FOUND, "Cannot get genre from the document");
        return null;
    }
    return genre.toString();
}
Also used : AbstractAnalyzer(org.opengrok.indexer.analysis.AbstractAnalyzer) Document(org.apache.lucene.document.Document) IndexDatabase.getDocument(org.opengrok.indexer.index.IndexDatabase.getDocument) FileUtil.toFile(org.opengrok.web.util.FileUtil.toFile) File(java.io.File) Path(jakarta.ws.rs.Path) CorsEnable(org.opengrok.web.api.v1.filter.CorsEnable) Produces(jakarta.ws.rs.Produces) GET(jakarta.ws.rs.GET) PathAuthorized(org.opengrok.web.api.v1.filter.PathAuthorized)

Example 12 with GET

use of jakarta.ws.rs.GET in project OpenGrok by OpenGrok.

the class FileController method getContentPlain.

@GET
@CorsEnable
@PathAuthorized
@Path("/content")
@Produces(MediaType.TEXT_PLAIN)
public StreamingOutput getContentPlain(@Context HttpServletRequest request, @Context HttpServletResponse response, @QueryParam("path") final String path) throws IOException, ParseException, NoPathParameterException {
    File file = toFile(path);
    Document doc;
    if ((doc = getDocument(file)) == null) {
        response.sendError(HttpServletResponse.SC_NOT_FOUND, "Cannot get document for file");
        return null;
    }
    String fileType = doc.get(QueryBuilder.T);
    if (!AbstractAnalyzer.Genre.PLAIN.typeName().equals(fileType)) {
        response.sendError(HttpServletResponse.SC_NOT_ACCEPTABLE, "Not a text file");
        return null;
    }
    return transfer(file);
}
Also used : Document(org.apache.lucene.document.Document) IndexDatabase.getDocument(org.opengrok.indexer.index.IndexDatabase.getDocument) FileUtil.toFile(org.opengrok.web.util.FileUtil.toFile) File(java.io.File) Path(jakarta.ws.rs.Path) CorsEnable(org.opengrok.web.api.v1.filter.CorsEnable) Produces(jakarta.ws.rs.Produces) GET(jakarta.ws.rs.GET) PathAuthorized(org.opengrok.web.api.v1.filter.PathAuthorized)

Example 13 with GET

use of jakarta.ws.rs.GET in project OpenGrok by OpenGrok.

the class SystemController method getIndexTime.

@GET
@Path("/indextime")
@Produces(MediaType.APPLICATION_JSON)
public String getIndexTime() throws JsonProcessingException {
    Date date = new IndexTimestamp().getDateForLastIndexRun();
    ObjectMapper mapper = new ObjectMapper();
    // StdDateFormat is ISO8601 since jackson 2.9
    mapper.setDateFormat(new StdDateFormat().withColonInTimeZone(true));
    return mapper.writeValueAsString(date);
}
Also used : IndexTimestamp(org.opengrok.indexer.configuration.IndexTimestamp) StdDateFormat(com.fasterxml.jackson.databind.util.StdDateFormat) Date(java.util.Date) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Path(jakarta.ws.rs.Path) Produces(jakarta.ws.rs.Produces) GET(jakarta.ws.rs.GET)

Aggregations

GET (jakarta.ws.rs.GET)13 Produces (jakarta.ws.rs.Produces)13 Path (jakarta.ws.rs.Path)9 CorsEnable (org.opengrok.web.api.v1.filter.CorsEnable)6 File (java.io.File)5 WebApplicationException (jakarta.ws.rs.WebApplicationException)4 Project (org.opengrok.indexer.configuration.Project)4 PathAuthorized (org.opengrok.web.api.v1.filter.PathAuthorized)4 FileUtil.toFile (org.opengrok.web.util.FileUtil.toFile)4 ArrayList (java.util.ArrayList)3 RepositoryInfo (org.opengrok.indexer.history.RepositoryInfo)3 Instant (java.time.Instant)2 List (java.util.List)2 Document (org.apache.lucene.document.Document)2 IndexDatabase.getDocument (org.opengrok.indexer.index.IndexDatabase.getDocument)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 StdDateFormat (com.fasterxml.jackson.databind.util.StdDateFormat)1 Inject (jakarta.inject.Inject)1 HttpServletRequest (jakarta.servlet.http.HttpServletRequest)1 Consumes (jakarta.ws.rs.Consumes)1