Skip to content

Commit aaef90c

Browse files
author
Vladimir Kotal
committed
retag history entry DTOs
1 parent 17243de commit aaef90c

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

opengrok-web/src/main/java/org/opengrok/web/api/v1/controller/HistoryController.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919

2020
/*
21-
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
21+
* Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved.
2222
*/
2323
package org.opengrok.web.api.v1.controller;
2424

@@ -32,6 +32,7 @@
3232
import jakarta.ws.rs.QueryParam;
3333
import jakarta.ws.rs.core.Context;
3434
import jakarta.ws.rs.core.MediaType;
35+
import org.jetbrains.annotations.TestOnly;
3536
import org.opengrok.indexer.configuration.RuntimeEnvironment;
3637
import org.opengrok.indexer.history.History;
3738
import org.opengrok.indexer.history.HistoryEntry;
@@ -45,6 +46,7 @@
4546
import java.util.ArrayList;
4647
import java.util.Date;
4748
import java.util.List;
49+
import java.util.Map;
4850
import java.util.Objects;
4951
import java.util.SortedSet;
5052

@@ -79,11 +81,14 @@ static class HistoryEntryDTO implements JSONable {
7981
this.revision = entry.getRevision();
8082
this.date = entry.getDate();
8183
this.author = entry.getAuthor();
82-
// TODO this.tags = entry.getTags();
8384
this.message = entry.getMessage();
8485
this.files = entry.getFiles();
8586
}
8687

88+
public void setTags(String tags) {
89+
this.tags = tags;
90+
}
91+
8792
// for testing
8893
public String getAuthor() {
8994
return author;
@@ -135,7 +140,7 @@ static class HistoryDTO implements JSONable {
135140
@JsonProperty
136141
private int total;
137142

138-
// for testing
143+
@TestOnly
139144
HistoryDTO() {
140145
this.entries = new ArrayList<>();
141146
}
@@ -147,7 +152,7 @@ static class HistoryDTO implements JSONable {
147152
this.total = total;
148153
}
149154

150-
// for testing
155+
@TestOnly
151156
public List<HistoryEntryDTO> getEntries() {
152157
return entries;
153158
}
@@ -181,9 +186,11 @@ public int hashCode() {
181186
}
182187
}
183188

184-
static HistoryDTO getHistoryDTO(List<HistoryEntry> historyEntries, int start, int count, int total) {
189+
static HistoryDTO getHistoryDTO(List<HistoryEntry> historyEntries, Map<String, String> tags,
190+
int start, int count, int total) {
185191
List<HistoryEntryDTO> entries = new ArrayList<>();
186192
historyEntries.stream().map(HistoryEntryDTO::new).forEach(entries::add);
193+
entries.forEach(e -> e.setTags(tags.get(e.revision)));
187194
return new HistoryDTO(entries, start, count, total);
188195
}
189196

@@ -205,7 +212,7 @@ public HistoryDTO get(@Context HttpServletRequest request,
205212
return null;
206213
}
207214

208-
return getHistoryDTO(history.getHistoryEntries(maxEntries, startIndex),
215+
return getHistoryDTO(history.getHistoryEntries(maxEntries, startIndex), history.getTags(),
209216
startIndex, maxEntries, history.getHistoryEntries().size());
210217
}
211218
}

opengrok-web/src/test/java/org/opengrok/web/api/v1/controller/HistoryControllerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public void testHistoryGet() throws Exception {
133133
assertEquals("Kryštof Tulinger <krystof.tulinger@oracle.com>", history.getEntries().get(0).getAuthor());
134134

135135
History repoHistory = HistoryGuru.getInstance().getHistory(new File(repository.getSourceRoot(), path));
136-
assertEquals(history, getHistoryDTO(repoHistory.getHistoryEntries(size, start),
136+
assertEquals(history, getHistoryDTO(repoHistory.getHistoryEntries(size, start), repoHistory.getTags(),
137137
start, size, repoHistory.getHistoryEntries().size()));
138138
}
139139
}

0 commit comments

Comments
 (0)