Search in sources :

Example 11 with Produces

use of jakarta.ws.rs.Produces 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 12 with Produces

use of jakarta.ws.rs.Produces 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 13 with Produces

use of jakarta.ws.rs.Produces 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 14 with Produces

use of jakarta.ws.rs.Produces 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 15 with Produces

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

the class ProjectsController method getRepositoriesType.

@GET
@Path("/{project}/repositories/type")
@Produces(MediaType.APPLICATION_JSON)
public Set<String> getRepositoriesType(@PathParam("project") String projectName) {
    // Avoid classification as a taint bug.
    projectName = Laundromat.launderInput(projectName);
    Project project = env.getProjects().get(projectName);
    if (project != null) {
        List<RepositoryInfo> infos = env.getProjectRepositoriesMap().get(project);
        if (infos != null) {
            return infos.stream().map(RepositoryInfo::getType).collect(Collectors.toSet());
        }
    }
    return Collections.emptySet();
}
Also used : Project(org.opengrok.indexer.configuration.Project) RepositoryInfo(org.opengrok.indexer.history.RepositoryInfo) Path(jakarta.ws.rs.Path) Produces(jakarta.ws.rs.Produces) GET(jakarta.ws.rs.GET)

Aggregations

Produces (jakarta.ws.rs.Produces)22 Path (jakarta.ws.rs.Path)18 GET (jakarta.ws.rs.GET)12 SimpleResult (ru.sbtqa.tag.api.dto.SimpleResult)11 POST (jakarta.ws.rs.POST)7 CorsEnable (org.opengrok.web.api.v1.filter.CorsEnable)6 Consumes (jakarta.ws.rs.Consumes)4 File (java.io.File)4 PathAuthorized (org.opengrok.web.api.v1.filter.PathAuthorized)4 FileUtil.toFile (org.opengrok.web.util.FileUtil.toFile)4 WebApplicationException (jakarta.ws.rs.WebApplicationException)3 Project (org.opengrok.indexer.configuration.Project)3 BasicDBObject (com.mongodb.BasicDBObject)2 Instant (java.time.Instant)2 ArrayList (java.util.ArrayList)2 Document (org.apache.lucene.document.Document)2 RepositoryInfo (org.opengrok.indexer.history.RepositoryInfo)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