Skip to content

Commit c7eafbf

Browse files
authored
Merge pull request #17 from com-pas/fix-historyitem
Changed the HItem records being added.
2 parents 0f1bfb5 + 1f75f60 commit c7eafbf

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

service/src/main/java/org/lfenergy/compas/scl/auto/alignment/model/GenericHeader.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,15 @@ public String getVersion() {
2525
}
2626

2727
public void addHistoryItem(String who, String fullmessage) {
28-
var formatter = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ssXXX");
28+
var formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX");
2929
var history = getOrCreateHistory();
3030

31+
var now = new Date();
3132
var document = getElement().getOwnerDocument();
3233
Element hItem = document.createElementNS(SCL_NS_URI, "Hitem");
3334
hItem.setAttribute("version", getVersion());
34-
hItem.setAttribute("revision", "saa");
35-
hItem.setAttribute("when", formatter.format(new Date()));
35+
hItem.setAttribute("revision", String.valueOf(now.getTime()));
36+
hItem.setAttribute("when", formatter.format(now));
3637
hItem.setAttribute("who", who);
3738
hItem.setAttribute("what", fullmessage);
3839
history.appendChild(hItem);

service/src/main/java/org/lfenergy/compas/scl/auto/alignment/service/SclAutoAlignmentService.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,11 @@ public String updateSCL(String sclData, List<String> substationNames, String who
5050
// Use that JSON to enrich the passed SCL XML with X/Y Coordinates.
5151
var enricher = new SclAutoAlignmentEnricher(scl, jsonGraphInfo);
5252
enricher.enrich();
53-
});
5453

55-
// Add an extra History Element to show there was a change.
56-
scl.getOrCreateHeader().addHistoryItem(who, "Add or replaced the X/Y Coordinates in the SCL File.");
54+
// Add an extra History Element to show there was a change.
55+
scl.getOrCreateHeader().addHistoryItem(who, "Add or replaced the X/Y Coordinates for Substation '" +
56+
substationName + "' in the SCL File.");
57+
});
5758

5859
return converter.convertToString(scl.getElement());
5960
}

service/src/test/java/org/lfenergy/compas/scl/auto/alignment/model/GenericHeaderTest.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
import static org.lfenergy.compas.scl.auto.alignment.model.GenericSCLTest.BASIC_SCD_FILENAME;
2020

2121
class GenericHeaderTest {
22+
private static final String USERNAME = "Test User";
23+
private static final String MESSAGE = "Some message";
24+
2225
private GenericHeader header;
2326

2427
@BeforeEach
@@ -45,15 +48,16 @@ void getVersion_WhenCalled_ThenTypeReturned() {
4548

4649
@Test
4750
void addHistoryItem_WhenCalled_ThenAllElementsAreCreated() {
48-
header.addHistoryItem("Test User", "Some message");
51+
header.addHistoryItem(USERNAME, MESSAGE);
4952

5053
var history = ElementUtil.getElementsStream(header.getElement(), "History").findFirst().orElse(null);
5154
assertNotNull(history);
5255
var historyItems = ElementUtil.getElementsStream(header.getElement(), "Hitem").collect(Collectors.toList());
5356
var historyItem = historyItems.get(historyItems.size() - 1);
5457
assertNotNull(historyItem);
55-
assertEquals("Test User", historyItem.getAttribute("who"));
56-
assertEquals("Some message", historyItem.getAttribute("what"));
58+
assertNotNull(historyItem.getAttribute("revision"));
59+
assertEquals(USERNAME, historyItem.getAttribute("who"));
60+
assertEquals(MESSAGE, historyItem.getAttribute("what"));
5761
}
5862

5963
@Test
@@ -64,7 +68,7 @@ void addHistoryItem_WhenCalledNotContainingHistory_ThenAllElementsAreCreated() {
6468
var scl = new GenericSCL(sclElement);
6569
header = scl.getOrCreateHeader();
6670

67-
header.addHistoryItem("Test User", "Some message");
71+
header.addHistoryItem(USERNAME, MESSAGE);
6872

6973
var history = ElementUtil.getElementsStream(header.getElement(), "History").findFirst().orElse(null);
7074
assertNotNull(history);

0 commit comments

Comments
 (0)