Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class HealthController {
return result
}

private generatePdfData() {
private void generatePdfData() {
Path tmpDir = Files.createTempDirectory("generatePdfDataFolderTest")
def documentHtmlFile = Files.createTempFile("document", ".html") << "<html>document</html>"

Expand All @@ -44,8 +44,6 @@ class HealthController {
if (!new String(data).startsWith("%PDF-1.4\n")) {
throw new RuntimeException("Conversion form HTML to PDF failed, corrupt data.")
}
} catch (e) {
throw new RuntimeException("Conversion form HTML to PDF failed, corrupt data.", e)
} finally {
Files.delete(documentHtmlFile)
FileUtils.deleteDirectory(tmpDir.toFile())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,17 @@ class BitbucketService {
}

protected void downloadRepoWithFallBack(String project, String repo, String branch, Path zipArchive) {
try {
bitBucketClientConfig
.getClient()
.getRepoZipArchive(project, repo, branch)
.withCloseable { Response response ->
boolean found = false;
bitBucketClientConfig
.getClient()
.getRepoZipArchive(project, repo, branch)
.withCloseable { Response response ->
if (response.status() != 404) {
streamResult(response, zipArchive)
found = true;
}
} catch (Exception callException) {
}
if (!found) {
log.warn("Branch [${branch}] doesn't exist, using branch: [${MAIN_BRANCH}]")
bitBucketClientConfig
.getClient()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,11 @@ class JiraService {
}

try {
this.baseURL = new URIBuilder(baseURL).build()
this.targetURL = new URIBuilder(baseURL).build()
} catch (e) {
throw new IllegalArgumentException("Error: unable to connect to Jira. '${baseURL}' is not a valid URI.").initCause(e)
URI jiraURI = new URIBuilder(baseURL).build()
this.baseURL = jiraURI
this.targetURL = jiraURI
} catch (URISyntaxException e) {
throw new IllegalArgumentException("FATAL: Jira URL is invalid: jira.url='${baseURL}'", e)
}

this.username = username
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,8 @@ class NexusService {
checkParams(baseURL, username, password)
try {
this.baseURL = new URIBuilder(baseURL).build()
} catch (e) {
throw new IllegalArgumentException(
"Error: unable to connect to Nexus. '${baseURL}' is not a valid URI."
).initCause(e)
} catch (URISyntaxException e) {
throw new IllegalArgumentException("FATAL: Nexus URL is invalid: nexus.url=${baseURL}", e)
}

this.username = username
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class JUnitReportsService {

tests.each {
String targetFolder = it.value.targetFolder as String
Map testResult = getTestResults(it.key.capitalize(), targetFolder, component)
Map testResult = getTestResults(targetFolder)
it.value.testReportFiles = testResult.testReportFiles
it.value.testResults = testResult.testResults
}
Expand Down Expand Up @@ -104,7 +104,7 @@ class JUnitReportsService {
return testData
}

private Map getTestResults(String typeIn, String targetFolder, String component) {
private Map getTestResults(String targetFolder) {
if (targetFolder == null) {
// When targetFolder is null, we need to initialize testsuites !!
return [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,12 @@ class LevaDocController {
try {
prepareServiceDataParam(projectId, buildNumber, levaDocType, data)
return levaDocType.buildDocument.apply(leVADocumentService, data)
} catch (Throwable e) {
String msg = "Error building document: ${levaDocType} with data:${data}"
log.error(msg, e)
String msgWithDetails = msg;
if (! StringUtils.isEmpty(e.getMessage())) {
msgWithDetails = msg + ". " + e.getMessage();
} catch (e) {
if (log.isDebugEnabled()) {
String msg = "Error building document: ${levaDocType} with data:${data}"
log.debug(msg, e)
}
throw new RuntimeException(msgWithDetails, e)
throw e
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,8 @@ class DocGenService {
private Path convertToPdf(Map body) {
Path tmpDir
Path documentPdf
try {
tmpDir = Files.createTempDirectory("${body.metadata.type}-v${body.metadata.version}")
documentPdf = pdfGenerationService.generatePdfFile(body.metadata as Map, body.data as Map, tmpDir)
} catch (Throwable e) {
throw new RuntimeException("Conversion form HTML to PDF failed, corrupt data.", e)
}
tmpDir = Files.createTempDirectory("${body.metadata.type}-v${body.metadata.version}")
documentPdf = pdfGenerationService.generatePdfFile(body.metadata as Map, body.data as Map, tmpDir)

return documentPdf
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,14 @@ class DocGenController {
}

private Path convertToPdf(Map body, Path tmpDir) {
try {
Path documentPdf = pdfGeneration.generatePdfFile(body.metadata as Map, body.data as Map, tmpDir)
Path tempFile = Files.createTempFile(tmpDir, 'temp', '.b64')
tempFile.toFile().withOutputStream { os ->
Base64.getEncoder().wrap(os).withStream { encOs ->
Files.copy(documentPdf, encOs)
}
Path documentPdf = pdfGeneration.generatePdfFile(body.metadata as Map, body.data as Map, tmpDir)
Path tempFile = Files.createTempFile(tmpDir, 'temp', '.b64')
tempFile.toFile().withOutputStream { os ->
Base64.getEncoder().wrap(os).withStream { encOs ->
Files.copy(documentPdf, encOs)
}
return tempFile
} catch (Throwable e) {
throw new RuntimeException("Conversion form HTML to PDF failed, corrupt data.", e)
}
return tempFile
}

private static void logData(Map body) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExcep
@ControllerAdvice
class RestResponseEntityExceptionHandler extends ResponseEntityExceptionHandler {

@ExceptionHandler(value = [ IllegalArgumentException.class ])
protected ResponseEntity<Object> handleArgumentError(RuntimeException ex, WebRequest request) {
log.error("ExceptionHandler, handleArgumentError:${ex.message}", ex)
return handleExceptionInternal(ex, ex.message, new HttpHeaders(), HttpStatus.PRECONDITION_FAILED, request)
@ExceptionHandler(value = IllegalArgumentException.class)
protected ResponseEntity<Object> handleArgumentError(IllegalArgumentException ex, WebRequest request) {
log.error("Bad request: ", ex)
return handleExceptionInternal(ex, ex.message, new HttpHeaders(), HttpStatus.BAD_REQUEST, request)
}

@ExceptionHandler(value = [ RuntimeException.class ])
@ExceptionHandler(value = RuntimeException.class)
protected ResponseEntity<Object> runtimeError(RuntimeException ex, WebRequest request) {
log.error("ExceptionHandler, runtimeError:${ex.message}", ex)
return handleExceptionInternal(ex, ex.message, new HttpHeaders(), HttpStatus.CONFLICT, request)
log.error("Internal server error: ", ex)
return handleExceptionInternal(ex, ex.message, new HttpHeaders(), HttpStatus.INTERNAL_SERVER_ERROR, request)
}

}