Skip to content

Commit d321742

Browse files
authored
Change ID from integer to string (#35)
1 parent 61e4a0a commit d321742

File tree

3 files changed

+37
-39
lines changed

3 files changed

+37
-39
lines changed

src/main/java/io/jenkins/plugins/pipelinegraphview/utils/PipelineGraphApi.java

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,12 @@ private List<PipelineStageInternal> getPipelineNodes() {
3535
}
3636

3737
return new PipelineStageInternal(
38-
Integer.parseInt(
39-
flowNodeWrapper
40-
.getId()), // TODO no need to parse it BO returns a string even though the
38+
flowNodeWrapper
39+
.getId(), // TODO no need to parse it BO returns a string even though the
4140
// datatype is number on the frontend
4241
flowNodeWrapper.getDisplayName(),
4342
flowNodeWrapper.getParents().stream()
44-
.map(wrapper -> Integer.parseInt(wrapper.getId()))
43+
.map(FlowNodeWrapper::getId)
4544
.collect(Collectors.toList()),
4645
state,
4746
50, // TODO how ???
@@ -57,32 +56,32 @@ public PipelineGraph createGraph() {
5756
List<PipelineStageInternal> stages = getPipelineNodes();
5857

5958
// id => stage
60-
Map<Integer, PipelineStageInternal> stageMap =
59+
Map<String, PipelineStageInternal> stageMap =
6160
stages.stream()
6261
.collect(
6362
Collectors.toMap(
6463
PipelineStageInternal::getId, stage -> stage, (u, v) -> u, LinkedHashMap::new));
6564

66-
Map<Integer, List<Integer>> stageToChildrenMap = new HashMap<>();
65+
Map<String, List<String>> stageToChildrenMap = new HashMap<>();
6766

68-
List<Integer> stagesThatAreNested = new ArrayList<>();
67+
List<String> stagesThatAreNested = new ArrayList<>();
6968

70-
Map<Integer, Integer> nextSiblingToOlderSibling = new HashMap<>();
69+
Map<String, String> nextSiblingToOlderSibling = new HashMap<>();
7170

72-
List<Integer> stagesThatAreChildrenOrNestedStages = new ArrayList<>();
71+
List<String> stagesThatAreChildrenOrNestedStages = new ArrayList<>();
7372
stages.forEach(
7473
stage -> {
7574
if (stage.getParents().isEmpty()) {
7675
stageToChildrenMap.put(stage.getId(), new ArrayList<>());
7776
} else if (stage.getType().equals("PARALLEL")) {
78-
Integer parentId = stage.getParents().get(0); // assume one parent for now
79-
List<Integer> childrenOfParent =
77+
String parentId = stage.getParents().get(0); // assume one parent for now
78+
List<String> childrenOfParent =
8079
stageToChildrenMap.getOrDefault(parentId, new ArrayList<>());
8180
childrenOfParent.add(stage.getId());
8281
stageToChildrenMap.put(parentId, childrenOfParent);
8382
stagesThatAreChildrenOrNestedStages.add(stage.getId());
8483
} else if (stageMap.get(stage.getParents().get(0)).getType().equals("PARALLEL")) {
85-
Integer parentId = stage.getParents().get(0);
84+
String parentId = stage.getParents().get(0);
8685
PipelineStageInternal parent = stageMap.get(parentId);
8786
parent.setSeqContainerName(parent.getName());
8887
parent.setName(stage.getName());
@@ -130,12 +129,11 @@ public PipelineGraph createGraph() {
130129
return new PipelineGraph(stageResults, execution != null && execution.isComplete());
131130
}
132131

133-
private Function<Integer, PipelineStage> mapper(
134-
Map<Integer, PipelineStageInternal> stageMap,
135-
Map<Integer, List<Integer>> stageToChildrenMap) {
132+
private Function<String, PipelineStage> mapper(
133+
Map<String, PipelineStageInternal> stageMap, Map<String, List<String>> stageToChildrenMap) {
136134

137135
return id -> {
138-
List<Integer> orDefault = stageToChildrenMap.getOrDefault(id, emptyList());
136+
List<String> orDefault = stageToChildrenMap.getOrDefault(id, emptyList());
139137
List<PipelineStage> children =
140138
orDefault.stream().map(mapper(stageMap, stageToChildrenMap)).collect(Collectors.toList());
141139
return stageMap.get(id).toPipelineStage(children);
@@ -148,16 +146,16 @@ private Function<Integer, PipelineStage> mapper(
148146
*/
149147
public PipelineGraph createTree() {
150148
List<PipelineStageInternal> stages = getPipelineNodes();
151-
List<Integer> topLevelStageIds = new ArrayList<>();
149+
List<String> topLevelStageIds = new ArrayList<>();
152150

153151
// id => stage
154-
Map<Integer, PipelineStageInternal> stageMap =
152+
Map<String, PipelineStageInternal> stageMap =
155153
stages.stream()
156154
.collect(
157155
Collectors.toMap(
158156
PipelineStageInternal::getId, stage -> stage, (u, v) -> u, LinkedHashMap::new));
159157

160-
Map<Integer, List<Integer>> stageToChildrenMap = new HashMap<>();
158+
Map<String, List<String>> stageToChildrenMap = new HashMap<>();
161159

162160
FlowExecution execution = run.getExecution();
163161
if (execution == null) {
@@ -168,25 +166,25 @@ public PipelineGraph createTree() {
168166
stages.forEach(
169167
stage -> {
170168
try {
171-
FlowNode stageNode = execution.getNode(Integer.toString(stage.getId()));
169+
FlowNode stageNode = execution.getNode(stage.getId());
172170
if (stageNode == null) {
173171
return;
174172
}
175-
List<Integer> ancestors = getAncestors(stage, stageMap);
176-
Integer treeParentId = null;
173+
List<String> ancestors = getAncestors(stage, stageMap);
174+
String treeParentId = null;
177175
// Compare the list of GraphVistor ancestors to the IDs of the enclosing node in the
178176
// execution.
179177
// If a node encloses another node, it means it's a tree parent, so the first ancestor
180178
// ID we find
181179
// which matches an enclosing node then it's the stages tree parent.
182-
for (Integer ancestorId : ancestors) {
183-
if (stageNode.getAllEnclosingIds().contains(Integer.toString(ancestorId))) {
180+
for (String ancestorId : ancestors) {
181+
if (stageNode.getAllEnclosingIds().contains(ancestorId)) {
184182
treeParentId = ancestorId;
185183
break;
186184
}
187185
}
188186
if (treeParentId != null) {
189-
List<Integer> childrenOfParent =
187+
List<String> childrenOfParent =
190188
stageToChildrenMap.getOrDefault(treeParentId, new ArrayList<>());
191189
childrenOfParent.add(stage.getId());
192190
stageToChildrenMap.put(treeParentId, childrenOfParent);
@@ -223,11 +221,11 @@ public PipelineGraph createTree() {
223221
return new PipelineGraph(stageResults, execution.isComplete());
224222
}
225223

226-
private List<Integer> getAncestors(
227-
PipelineStageInternal stage, Map<Integer, PipelineStageInternal> stageMap) {
228-
List<Integer> ancestors = new ArrayList<>();
224+
private List<String> getAncestors(
225+
PipelineStageInternal stage, Map<String, PipelineStageInternal> stageMap) {
226+
List<String> ancestors = new ArrayList<>();
229227
if (!stage.getParents().isEmpty()) {
230-
Integer parentId = stage.getParents().get(0); // Assume one parent.
228+
String parentId = stage.getParents().get(0); // Assume one parent.
231229
ancestors.add(parentId);
232230
if (stageMap.containsKey(parentId)) {
233231
PipelineStageInternal parent = stageMap.get(parentId);

src/main/java/io/jenkins/plugins/pipelinegraphview/utils/PipelineStage.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ public class PipelineStage {
1010
private int completePercent; // TODO int is fine?
1111
private String type; // TODO enum
1212
private String title;
13-
private int id; // TODO what's this for?
13+
private String id; // TODO what's this for?
1414
private String seqContainerName;
1515
private final PipelineStage nextSibling;
1616
private boolean sequential;
1717

1818
public PipelineStage(
19-
int id,
19+
String id,
2020
String name,
2121
List<PipelineStage> children,
2222
String state,
@@ -52,7 +52,7 @@ public String getSeqContainerName() {
5252
return seqContainerName;
5353
}
5454

55-
public int getId() {
55+
public String getId() {
5656
return id;
5757
}
5858

src/main/java/io/jenkins/plugins/pipelinegraphview/utils/PipelineStageInternal.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,20 @@
66
public class PipelineStageInternal {
77

88
private String name;
9-
private List<Integer> parents;
9+
private List<String> parents;
1010
private String state; // TODO enum
1111
private int completePercent; // TODO int is fine?
1212
private String type; // TODO enum
1313
private String title;
14-
private int id; // TODO what's this for?
14+
private String id;
1515
private String seqContainerName;
1616
private PipelineStageInternal nextSibling;
1717
private boolean sequential;
1818

1919
public PipelineStageInternal(
20-
int id,
20+
String id,
2121
String name,
22-
List<Integer> parents,
22+
List<String> parents,
2323
String state,
2424
int completePercent,
2525
String type,
@@ -37,7 +37,7 @@ public boolean isSequential() {
3737
return sequential;
3838
}
3939

40-
public void setId(int id) {
40+
public void setId(String id) {
4141
this.id = id;
4242
}
4343

@@ -77,15 +77,15 @@ public String getSeqContainerName() {
7777
return seqContainerName;
7878
}
7979

80-
public int getId() {
80+
public String getId() {
8181
return id;
8282
}
8383

8484
public String getName() {
8585
return name;
8686
}
8787

88-
public List<Integer> getParents() {
88+
public List<String> getParents() {
8989
return parents;
9090
}
9191

0 commit comments

Comments
 (0)