Skip to content

Commit 6d0af57

Browse files
committed
Fixing puml2Confluence-core
1 parent 633bf35 commit 6d0af57

File tree

3 files changed

+28
-16
lines changed

3 files changed

+28
-16
lines changed

puml2confluence-core/src/main/java/com/kicksolutions/confluence/ConfluenceUtils.java

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import java.net.URI;
77
import java.util.Arrays;
88
import java.util.Map;
9+
import java.util.logging.Level;
10+
import java.util.logging.Logger;
911

1012
import javax.xml.bind.DatatypeConverter;
1113

@@ -30,7 +32,10 @@
3032
*
3133
*/
3234
public class ConfluenceUtils {
33-
35+
36+
private static final Logger LOGGER = Logger.getLogger(ConfluenceUtils.class.getName());
37+
38+
3439
private static final String EXPAND = "expand";
3540
private static final String ID = "id";
3641
private static final String SPACE_KEY = "spaceKey";
@@ -53,11 +58,15 @@ public boolean isPageExists(ConfluenceVo confluenceVo) {
5358
.queryParam(SPACE_KEY, confluenceVo.getSpaceKey()).queryParam(TITLE, confluenceVo.getTitle())
5459
.queryParam(EXPAND, "body.storage,version,ancestors").build().toUri();
5560

61+
LOGGER.log(java.util.logging.Level.FINEST, "Method GET: "+targetUrl);
62+
5663
final ResponseEntity<String> responseEntity = new RestTemplate().exchange(targetUrl, HttpMethod.GET,
5764
requestEntity, String.class);
58-
65+
5966
final String jsonBody = responseEntity.getBody();
6067

68+
LOGGER.log(java.util.logging.Level.FINEST, "Response: "+jsonBody);
69+
6170
try {
6271
final String id = JsonPath.read(jsonBody, "$.results[0].id");
6372
final Integer version = JsonPath.read(jsonBody, "$.results[0].version.number");
@@ -97,6 +106,11 @@ public String createPage(ConfluenceVo confluenceVo) {
97106
confluenceVo.getContent(), confluenceVo.getSpaceKey()).toJSONString();
98107

99108
final HttpEntity<String> requestEntity = new HttpEntity<>(jsonPostBody, httpHeaders);
109+
110+
LOGGER.log(java.util.logging.Level.FINEST, "Method GET: "+targetUrl);
111+
LOGGER.log(Level.FINEST, "jsonPostBody" +jsonPostBody);
112+
LOGGER.log(Level.FINEST, "httpHeaders " + httpHeaders.toString());
113+
100114
final HttpEntity<String> responseEntity = new RestTemplate().exchange(targetUrl, HttpMethod.POST, requestEntity,
101115
String.class);
102116

@@ -198,11 +212,6 @@ private String getAuthenticationString(String userName, String password) {
198212
new StringBuilder().append(userName).append(":").append(password).toString().getBytes());
199213
}
200214

201-
/**
202-
*
203-
* @param confluenceAuthentication
204-
* @return
205-
*/
206215
private HttpHeaders buildHttpHeaders(final String confluenceAuthentication) {
207216
final HttpHeaders headers = new HttpHeaders();
208217
headers.set("Authorization", String.format("Basic %s", confluenceAuthentication));

puml2confluence-core/src/main/java/com/kicksolutions/confluence/Puml2Confluence.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class Puml2Confluence {
1717
.append(Puml2Confluence.class.getName()).append(" <options> \n")
1818
.append(" -i <Path of Puml> ").append(" -a <Parent Page Id> ").append(" -u <User Name> ")
1919
.append(" -p <Password> ").append(" -l <Conflunce URL> ").append(" -s <Confluenec Space key>")
20-
.append(" -t <Title of Page>").toString();
20+
.append(" -t <Title of Page>").append(" -f <Prefix for Confluence Page>").toString();
2121

2222
public Puml2Confluence() {
2323
super();
@@ -45,12 +45,13 @@ private void init(String args[]) {
4545
String confluenceURL = cliArgs.getArgumentValue("-l", "");
4646
String confluenceSpaceKey = cliArgs.getArgumentValue("-s", "");
4747
String title = cliArgs.getArgumentValue("-t", "");
48-
48+
String prefixForConfluencePage = cliArgs.getArgumentValue("-f", "");
49+
4950
if (StringUtils.isNotEmpty(specFile) && StringUtils.isNotEmpty(parentPageID) && StringUtils.isNotEmpty(userName)
5051
&& StringUtils.isNotEmpty(password) && StringUtils.isNotEmpty(confluenceURL)
5152
&& StringUtils.isNotEmpty(confluenceSpaceKey)) {
5253
processSwagger2Confluence(specFile, parentPageID, userName, password, confluenceURL, confluenceSpaceKey,
53-
title);
54+
title,prefixForConfluencePage);
5455
} else {
5556
LOGGER.severe(USAGE);
5657
}
@@ -65,14 +66,15 @@ private void init(String args[]) {
6566
* @param confluenceURL
6667
* @param spaceKey
6768
* @param title
69+
* @param prefixForConfluencePage
6870
*/
6971
private void processSwagger2Confluence(String specFile, String parentPageID, String userName, String password,
70-
String confluenceURL, String spaceKey, String title) {
72+
String confluenceURL, String spaceKey, String title,String prefixForConfluencePage) {
7173

7274
try{
7375
PumlConfluenceUploader confluenceUploader = new PumlConfluenceUploader();
7476
confluenceUploader.processPuml2Confluence(specFile, parentPageID, userName, password, confluenceURL, spaceKey,
75-
title);
77+
title,prefixForConfluencePage);
7678
}catch (Exception e){
7779
throw new RuntimeException(e);
7880
}

puml2confluence-core/src/main/java/com/kicksolutions/confluence/PumlConfluenceUploader.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public PumlConfluenceUploader() {
3333
* @throws IOException
3434
*/
3535
public String processPuml2Confluence(String specFile, String parentPageID, String userName, String password,
36-
String confluenceURL, String spaceKey, String title) throws IOException {
36+
String confluenceURL, String spaceKey, String title,String prefixForConfluencePage) throws IOException {
3737

3838
File pumlFile = new File(specFile);
3939

@@ -43,11 +43,12 @@ public String processPuml2Confluence(String specFile, String parentPageID, Strin
4343

4444
if (StringUtils.isNotEmpty(pumlContents) && pumlContents.contains("@startuml")) {
4545
String swaggerPageContent = plantUMLMacroContent(pumlContents);
46-
47-
LOGGER.log(Level.INFO, "About to generate Page -->" + title);
46+
String pageTitle = StringUtils.isEmpty(prefixForConfluencePage) ? title : new StringBuilder().append(prefixForConfluencePage).append(" - ").append(title).toString();
47+
48+
LOGGER.log(Level.INFO, "About to generate Page -->" + pageTitle);
4849

4950
ConfluenceVo parentPageVo = createSwaggerPage(new ConfluenceVo(userName, password, confluenceURL, "",
50-
parentPageID, "", title, "0", swaggerPageContent, spaceKey, false));
51+
parentPageID, "", pageTitle, "0", swaggerPageContent, spaceKey, false));
5152

5253
LOGGER.log(Level.INFO, "Done.... by generating Pages " + parentPageVo.getPageID());
5354

0 commit comments

Comments
 (0)