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);
}
}
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;
}
Aggregations