Skip to content

Commit

Permalink
fixes Confluence page hierarchy retrieval
Browse files Browse the repository at this point in the history
  • Loading branch information
tjuerge committed Jul 30, 2024
1 parent 79f565b commit bf164c6
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 12 deletions.
6 changes: 3 additions & 3 deletions config/mock/initializerJson.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
"httpResponse": {
"statusCode": 200,
"body": "{\"page\":{\"results\":[{\"id\":\"1\",\"title\":\"Page 1\",\"children\":{\"page\":{\"results\":[{\"id\":\"11\",\"title\":\"Page 1.1\",\"_links\":{\"tinyui\":\"/x/Pcz-B11\"}},{\"id\":\"12\",\"title\":\"Page 1.2\",\"_links\":{\"tinyui\":\"/x/Pcz-B12\"}}]}},\"_links\":{\"tinyui\":\"/x/Pcz-B1\"}},{\"id\":\"2\",\"title\":\"Page 2\",\"children\":{\"page\":{\"results\":[]}},\"_links\":{\"tinyui\":\"/x/Pcz-B2\"}}]}}",
"body": "{\"results\":[{\"id\":\"1\",\"title\":\"Page 1\",\"children\":{\"page\":{\"results\":[{\"id\":\"11\",\"title\":\"Page 1.1\",\"_links\":{\"tinyui\":\"/x/Pcz-B11\"}},{\"id\":\"12\",\"title\":\"Page 1.2\",\"_links\":{\"tinyui\":\"/x/Pcz-B12\"}}]}},\"_links\":{\"tinyui\":\"/x/Pcz-B1\"}},{\"id\":\"2\",\"title\":\"Page 2\",\"children\":{\"page\":{\"results\":[]}},\"_links\":{\"tinyui\":\"/x/Pcz-B2\"}}]}",
"headers": {
"Content-Type": ["application/json"]
}
Expand All @@ -27,7 +27,7 @@
},
"httpResponse": {
"statusCode": 200,
"body": "{\"page\":{\"results\":[{\"id\":\"111\",\"title\":\"Page 1.1.1\",\"children\":{\"page\":{\"results\":[]}},\"_links\":{\"tinyui\":\"/x/Pcz-B111\"}},{\"id\":\"112\",\"title\":\"Page 1.1.2\",\"children\":{\"page\":{\"results\":[]}},\"_links\":{\"tinyui\":\"/x/Pcz-B112\"}}]}}",
"body": "{\"results\":[{\"id\":\"111\",\"title\":\"Page 1.1.1\",\"children\":{\"page\":{\"results\":[]}},\"_links\":{\"tinyui\":\"/x/Pcz-B111\"}},{\"id\":\"112\",\"title\":\"Page 1.1.2\",\"children\":{\"page\":{\"results\":[]}},\"_links\":{\"tinyui\":\"/x/Pcz-B112\"}}]}",
"headers": {
"Content-Type": ["application/json"]
}
Expand All @@ -44,7 +44,7 @@
},
"httpResponse": {
"statusCode": 200,
"body": "{ \"page\": { \"results\": [] } }",
"body": "{\"results\":[]}",
"headers": {
"Content-Type": ["application/json"]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ private List<ConfluencePage> getChildPages(String pageId) {
.param("limit", "100");
try (SimpleHttp.Response response = simpleHttp.asResponse()) {
if (response.getStatus() == 200) {
List<ConfluencePage> children = ConfluencePage.getChildren(response.asJson());
List<ConfluencePage> children = ConfluencePage.of(response.asJson());
LOG.debugf("Retrieved %s child pages from parent page %s", children.size(), pageId);
// Recursively retrieve grand-grand child pages from grand child pages
for (ConfluencePage child : children) {
Expand Down Expand Up @@ -70,9 +70,9 @@ public List<ConfluencePageProperty> getPageProperties() {
try (SimpleHttp.Response response = simpleHttp.asResponse()) {
if (response.getStatus() == 200) {
JsonNode node = response.asJson();
if (node.has("totalPages") && node.has("detailLines")) {
if (node.has("totalPages")) {
totalPages = node.get("totalPages").asInt();
pageProperties.addAll(ConfluencePageProperty.getPageProperties(node));
pageProperties.addAll(ConfluencePageProperty.of(node));
}
} else {
throw new IOException(response.asJson().toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ protected void unnestLinks(JsonNode node) {

@JsonProperty("children")
protected void unnestChildren(JsonNode node) {
children = getChildren(node);
if (node.has("page") && node.get("page").has("results")) {
children = MAPPER.convertValue(node.get("page").get("results"), new TypeReference<>() {});
} else {
children = Collections.emptyList();
}
}

public String getId() {
Expand All @@ -56,9 +60,9 @@ protected void setChildren(List<ConfluencePage> children) {
this.children = children;
}

/* package */ static List<ConfluencePage> getChildren(JsonNode node) {
if (node.has("page") && node.get("page").has("results")) {
return MAPPER.convertValue(node.get("page").get("results"), new TypeReference<>() {});
public static List<ConfluencePage> of(JsonNode node) {
if (node.has("results")) {
return MAPPER.convertValue(node.get("results"), new TypeReference<>() {});
}
return Collections.emptyList();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public String getId() {
return id;
}

/* package */ void setValues(int columnIndex) {
protected void setValues(int columnIndex) {
values = new ArrayList<>();
for (String detail : details) {
Elements elements = Jsoup.parse(detail).selectXpath("//tr/td[position()=" + columnIndex + "]");
Expand All @@ -38,7 +38,7 @@ public List<String> getValues() {
return values;
}

/* package */ static List<ConfluencePageProperty> getPageProperties(JsonNode node) {
public static List<ConfluencePageProperty> of(JsonNode node) {
if (node.has("detailLines")) {
return MAPPER.convertValue(node.get("detailLines"), new TypeReference<>() {});
}
Expand Down

0 comments on commit bf164c6

Please sign in to comment.