Search in sources :

Example 1 with Annotation

use of org.opengrok.indexer.history.Annotation in project OpenGrok by OpenGrok.

the class PageConfigTest method testGetAnnotation.

@Test
public void testGetAnnotation() {
    final String[] revisions = { "aa35c258", "bb74b7e8" };
    for (int i = 0; i < revisions.length; i++) {
        final int index = i;
        HttpServletRequest req = new DummyHttpServletRequest() {

            @Override
            public String getContextPath() {
                return "/source";
            }

            @Override
            public String getServletPath() {
                return "/history";
            }

            @Override
            public String getPathInfo() {
                return "/git/main.c";
            }

            @Override
            public String getParameter(String name) {
                switch(name) {
                    case "r":
                        return revisions[index];
                    case "a":
                        return "true";
                }
                return null;
            }
        };
        PageConfig cfg = PageConfig.get(req);
        Annotation annotation = cfg.getAnnotation();
        assertNotNull(annotation);
        assertEquals("main.c", annotation.getFilename());
        assertEquals(revisions.length - i, annotation.getFileVersionsCount());
        for (int j = 1; j <= annotation.size(); j++) {
            String tmp = annotation.getRevision(j);
            assertTrue(Arrays.asList(revisions).contains(tmp));
        }
        assertEquals(revisions.length - i, annotation.getFileVersion(revisions[i]), "The version should be reflected through the revision");
        PageConfig.cleanup(req);
    }
}
Also used : HttpServletRequest(jakarta.servlet.http.HttpServletRequest) DummyHttpServletRequest(org.opengrok.indexer.web.DummyHttpServletRequest) DummyHttpServletRequest(org.opengrok.indexer.web.DummyHttpServletRequest) Annotation(org.opengrok.indexer.history.Annotation) Test(org.junit.jupiter.api.Test)

Example 2 with Annotation

use of org.opengrok.indexer.history.Annotation 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)

Aggregations

Annotation (org.opengrok.indexer.history.Annotation)2 HttpServletRequest (jakarta.servlet.http.HttpServletRequest)1 GET (jakarta.ws.rs.GET)1 Produces (jakarta.ws.rs.Produces)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 Test (org.junit.jupiter.api.Test)1 DummyHttpServletRequest (org.opengrok.indexer.web.DummyHttpServletRequest)1 CorsEnable (org.opengrok.web.api.v1.filter.CorsEnable)1 PathAuthorized (org.opengrok.web.api.v1.filter.PathAuthorized)1 FileUtil.toFile (org.opengrok.web.util.FileUtil.toFile)1