Skip to content

Commit

Permalink
Fixing puml2Confluence-core
Browse files Browse the repository at this point in the history
  • Loading branch information
astroDEX2020 committed Jan 7, 2018
1 parent 633bf35 commit 6d0af57
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import java.net.URI;
import java.util.Arrays;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.xml.bind.DatatypeConverter;

Expand All @@ -30,7 +32,10 @@
*
*/
public class ConfluenceUtils {


private static final Logger LOGGER = Logger.getLogger(ConfluenceUtils.class.getName());


private static final String EXPAND = "expand";
private static final String ID = "id";
private static final String SPACE_KEY = "spaceKey";
Expand All @@ -53,11 +58,15 @@ public boolean isPageExists(ConfluenceVo confluenceVo) {
.queryParam(SPACE_KEY, confluenceVo.getSpaceKey()).queryParam(TITLE, confluenceVo.getTitle())
.queryParam(EXPAND, "body.storage,version,ancestors").build().toUri();

LOGGER.log(java.util.logging.Level.FINEST, "Method GET: "+targetUrl);

final ResponseEntity<String> responseEntity = new RestTemplate().exchange(targetUrl, HttpMethod.GET,
requestEntity, String.class);

final String jsonBody = responseEntity.getBody();

LOGGER.log(java.util.logging.Level.FINEST, "Response: "+jsonBody);

try {
final String id = JsonPath.read(jsonBody, "$.results[0].id");
final Integer version = JsonPath.read(jsonBody, "$.results[0].version.number");
Expand Down Expand Up @@ -97,6 +106,11 @@ public String createPage(ConfluenceVo confluenceVo) {
confluenceVo.getContent(), confluenceVo.getSpaceKey()).toJSONString();

final HttpEntity<String> requestEntity = new HttpEntity<>(jsonPostBody, httpHeaders);

LOGGER.log(java.util.logging.Level.FINEST, "Method GET: "+targetUrl);
LOGGER.log(Level.FINEST, "jsonPostBody" +jsonPostBody);
LOGGER.log(Level.FINEST, "httpHeaders " + httpHeaders.toString());

final HttpEntity<String> responseEntity = new RestTemplate().exchange(targetUrl, HttpMethod.POST, requestEntity,
String.class);

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

/**
*
* @param confluenceAuthentication
* @return
*/
private HttpHeaders buildHttpHeaders(final String confluenceAuthentication) {
final HttpHeaders headers = new HttpHeaders();
headers.set("Authorization", String.format("Basic %s", confluenceAuthentication));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class Puml2Confluence {
.append(Puml2Confluence.class.getName()).append(" <options> \n")
.append(" -i <Path of Puml> ").append(" -a <Parent Page Id> ").append(" -u <User Name> ")
.append(" -p <Password> ").append(" -l <Conflunce URL> ").append(" -s <Confluenec Space key>")
.append(" -t <Title of Page>").toString();
.append(" -t <Title of Page>").append(" -f <Prefix for Confluence Page>").toString();

public Puml2Confluence() {
super();
Expand Down Expand Up @@ -45,12 +45,13 @@ private void init(String args[]) {
String confluenceURL = cliArgs.getArgumentValue("-l", "");
String confluenceSpaceKey = cliArgs.getArgumentValue("-s", "");
String title = cliArgs.getArgumentValue("-t", "");

String prefixForConfluencePage = cliArgs.getArgumentValue("-f", "");

if (StringUtils.isNotEmpty(specFile) && StringUtils.isNotEmpty(parentPageID) && StringUtils.isNotEmpty(userName)
&& StringUtils.isNotEmpty(password) && StringUtils.isNotEmpty(confluenceURL)
&& StringUtils.isNotEmpty(confluenceSpaceKey)) {
processSwagger2Confluence(specFile, parentPageID, userName, password, confluenceURL, confluenceSpaceKey,
title);
title,prefixForConfluencePage);
} else {
LOGGER.severe(USAGE);
}
Expand All @@ -65,14 +66,15 @@ private void init(String args[]) {
* @param confluenceURL
* @param spaceKey
* @param title
* @param prefixForConfluencePage
*/
private void processSwagger2Confluence(String specFile, String parentPageID, String userName, String password,
String confluenceURL, String spaceKey, String title) {
String confluenceURL, String spaceKey, String title,String prefixForConfluencePage) {

try{
PumlConfluenceUploader confluenceUploader = new PumlConfluenceUploader();
confluenceUploader.processPuml2Confluence(specFile, parentPageID, userName, password, confluenceURL, spaceKey,
title);
title,prefixForConfluencePage);
}catch (Exception e){
throw new RuntimeException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public PumlConfluenceUploader() {
* @throws IOException
*/
public String processPuml2Confluence(String specFile, String parentPageID, String userName, String password,
String confluenceURL, String spaceKey, String title) throws IOException {
String confluenceURL, String spaceKey, String title,String prefixForConfluencePage) throws IOException {

File pumlFile = new File(specFile);

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

if (StringUtils.isNotEmpty(pumlContents) && pumlContents.contains("@startuml")) {
String swaggerPageContent = plantUMLMacroContent(pumlContents);

LOGGER.log(Level.INFO, "About to generate Page -->" + title);
String pageTitle = StringUtils.isEmpty(prefixForConfluencePage) ? title : new StringBuilder().append(prefixForConfluencePage).append(" - ").append(title).toString();

LOGGER.log(Level.INFO, "About to generate Page -->" + pageTitle);

ConfluenceVo parentPageVo = createSwaggerPage(new ConfluenceVo(userName, password, confluenceURL, "",
parentPageID, "", title, "0", swaggerPageContent, spaceKey, false));
parentPageID, "", pageTitle, "0", swaggerPageContent, spaceKey, false));

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

Expand Down

0 comments on commit 6d0af57

Please sign in to comment.