Search in sources :

Example 1 with PathAuthorized

use of org.opengrok.web.api.v1.filter.PathAuthorized in project OpenGrok by OpenGrok.

the class HistoryController method get.

@GET
@CorsEnable
@PathAuthorized
@Produces(MediaType.APPLICATION_JSON)
public HistoryDTO get(@Context HttpServletRequest request, @Context HttpServletResponse response, @QueryParam("path") final String path, @QueryParam("withFiles") final boolean withFiles, @QueryParam("max") @DefaultValue(MAX_RESULTS + "") final int maxEntries, @QueryParam("start") @DefaultValue(0 + "") final int startIndex) throws HistoryException, IOException, NoPathParameterException {
    File file = toFile(path);
    History history = HistoryGuru.getInstance().getHistory(file, withFiles, true);
    if (history == null) {
        return null;
    }
    return getHistoryDTO(history.getHistoryEntries(maxEntries, startIndex), history.getTags(), startIndex, maxEntries, history.getHistoryEntries().size());
}
Also used : History(org.opengrok.indexer.history.History) FileUtil.toFile(org.opengrok.web.util.FileUtil.toFile) File(java.io.File) 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 2 with PathAuthorized

use of org.opengrok.web.api.v1.filter.PathAuthorized in project OpenGrok by OpenGrok.

the class AnnotationController method getContent.

@GET
@CorsEnable
@PathAuthorized
@Produces(MediaType.APPLICATION_JSON)
public List<AnnotationDTO> getContent(@Context HttpServletRequest request, @Context HttpServletResponse response, @QueryParam("path") final String path, @QueryParam("revision") final String revision) throws IOException, NoPathParameterException {
    File file = toFile(path);
    Annotation annotation = HistoryGuru.getInstance().annotate(file, revision == null || revision.isEmpty() ? null : revision);
    ArrayList<AnnotationDTO> annotationList = new ArrayList<>();
    for (int i = 1; i <= annotation.size(); i++) {
        annotationList.add(new AnnotationDTO(annotation.getRevision(i), annotation.getAuthor(i), annotation.getDesc(annotation.getRevision(i)), annotation.getFileVersion(annotation.getRevision(i)) + "/" + annotation.getRevisions().size()));
    }
    return annotationList;
}
Also used : ArrayList(java.util.ArrayList) FileUtil.toFile(org.opengrok.web.util.FileUtil.toFile) File(java.io.File) Annotation(org.opengrok.indexer.history.Annotation) 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 3 with PathAuthorized

use of org.opengrok.web.api.v1.filter.PathAuthorized 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 4 with PathAuthorized

use of org.opengrok.web.api.v1.filter.PathAuthorized 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)

Aggregations

GET (jakarta.ws.rs.GET)4 Produces (jakarta.ws.rs.Produces)4 File (java.io.File)4 CorsEnable (org.opengrok.web.api.v1.filter.CorsEnable)4 PathAuthorized (org.opengrok.web.api.v1.filter.PathAuthorized)4 FileUtil.toFile (org.opengrok.web.util.FileUtil.toFile)4 Path (jakarta.ws.rs.Path)2 Document (org.apache.lucene.document.Document)2 IndexDatabase.getDocument (org.opengrok.indexer.index.IndexDatabase.getDocument)2 ArrayList (java.util.ArrayList)1 AbstractAnalyzer (org.opengrok.indexer.analysis.AbstractAnalyzer)1 Annotation (org.opengrok.indexer.history.Annotation)1 History (org.opengrok.indexer.history.History)1