diff --git a/.github/workflows/deploy_feature.yaml b/.github/workflows/deploy_feature.yaml index bb7228dc..674a872c 100644 --- a/.github/workflows/deploy_feature.yaml +++ b/.github/workflows/deploy_feature.yaml @@ -5,8 +5,6 @@ on: - '**' - '!main' - '!dependabot/**' -env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} jobs: build_and_deploy: diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml index 16d1762f..12f902fa 100644 --- a/.github/workflows/pr.yaml +++ b/.github/workflows/pr.yaml @@ -3,9 +3,6 @@ on: pull_request: types: [ ready_for_review, opened, synchronize ] -env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - jobs: build_and_deploy: name: "Build and deploy to main" diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 74ba805b..b42e753e 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -3,13 +3,10 @@ on: push: branches: - 'main' -env: - GITHUB_USERNAME: x-access-token - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} jobs: build_and_deploy: - name: "Build and deploy to feature" + name: "Build and deploy to prod" permissions: contents: "write" id-token: "write" diff --git a/.github/workflows/rollback_prod.yaml b/.github/workflows/rollback_prod.yaml index f2211a3c..731fc128 100644 --- a/.github/workflows/rollback_prod.yaml +++ b/.github/workflows/rollback_prod.yaml @@ -6,10 +6,6 @@ on: description: 'Deploy tag. Default the previous tag will be deployed' required: false -env: - GITHUB_USERNAME: x-access-token - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - jobs: build-deploy: name: "Rollback and deploy previous version to prod" @@ -19,4 +15,5 @@ jobs: uses: navikt/bidrag-workflow/.github/workflows/rollback_prod.yaml@main secrets: inherit with: - cluster: fss \ No newline at end of file + cluster: fss + deploy_tag: ${{inputs.deploy_tag}} \ No newline at end of file diff --git a/src/main/java/no/nav/bidrag/dokument/aop/AspectExceptionLogger.kt b/src/main/java/no/nav/bidrag/dokument/aop/AspectExceptionLogger.kt deleted file mode 100644 index 8b696e09..00000000 --- a/src/main/java/no/nav/bidrag/dokument/aop/AspectExceptionLogger.kt +++ /dev/null @@ -1,20 +0,0 @@ -package no.nav.bidrag.dokument.aop - -import mu.KotlinLogging -import no.nav.bidrag.dokument.sikkerLogg -import org.aspectj.lang.JoinPoint -import org.aspectj.lang.annotation.AfterThrowing -import org.aspectj.lang.annotation.Aspect -import org.springframework.stereotype.Component - -private val log = KotlinLogging.logger {} - -@Aspect -@Component -class AspectExceptionLogger { - @AfterThrowing(pointcut = "within (no.nav.bidrag.dokument.controller..*)", throwing = "exception") - fun logException(joinPoint: JoinPoint, exception: Exception?) { - log.warn(exception) { "Det skjedde en feil i controller metoden ${joinPoint.signature.toShortString()}. Se sikkerlogg for detaljer" } - sikkerLogg.warn(exception) { "Det skjedde en feil i controller metoden ${joinPoint.signature.toShortString()} | Argumenter => ${joinPoint.args.joinToString(", ")}" } - } -} diff --git a/src/main/java/no/nav/bidrag/dokument/service/PDFDokumentProcessor.kt b/src/main/java/no/nav/bidrag/dokument/service/PDFDokumentProcessor.kt index f970fb19..f12b1949 100644 --- a/src/main/java/no/nav/bidrag/dokument/service/PDFDokumentProcessor.kt +++ b/src/main/java/no/nav/bidrag/dokument/service/PDFDokumentProcessor.kt @@ -14,7 +14,6 @@ import org.apache.pdfbox.pdmodel.PDPageContentStream import org.apache.pdfbox.pdmodel.PDPageContentStream.AppendMode import org.apache.pdfbox.pdmodel.common.PDRectangle import org.apache.pdfbox.util.Matrix -import org.slf4j.LoggerFactory import java.io.ByteArrayOutputStream import java.io.File import java.io.FileInputStream @@ -48,21 +47,34 @@ class PDFDokumentProcessor { optimaliserForDobbelsidigPrinting() } this.document?.isAllSecurityToBeRemoved = true - this.document?.save(documentByteStream) - this.document?.close() + lagreDokument(documentByteStream) return documentByteStream.toByteArray() } } catch (e: Exception) { - LOGGER.error("Det skjedde en feil ved prossesering av PDF dokument", e) + log.error(e) { "Det skjedde en feil ved prossesering av PDF dokument" } + return dokumentFil + } catch (e: StackOverflowError) { + log.error(e) { "Det skjedde en feil ved prossesering av PDF dokument" } return dokumentFil } finally { IOUtils.closeQuietly(documentByteStream) } } + private fun lagreDokument(documentByteStream: ByteArrayOutputStream) { + try { + this.document?.save(documentByteStream) + } catch (error: StackOverflowError) { + log.error(error) { "Det skjedde en feil ved lagring av dokument med kompresjon. Forsøker å merge dokumenter uten kompresjon" } + this.document?.save(documentByteStream, CompressParameters.NO_COMPRESSION) + } finally { + this.document?.close() + } + } + fun optimaliserForDobbelsidigPrinting() { if (documentHasOddNumberOfPages() && documentProperties!!.hasMoreThanOneDocument() && !documentProperties!!.isLastDocument()) { - LOGGER.debug("Dokumentet har oddetall antall sider. Legger til en blank side på slutten av dokumentet.") + log.debug("Dokumentet har oddetall antall sider. Legger til en blank side på slutten av dokumentet.") document?.addPage(PDPage(PDRectangle.A4)) } } @@ -91,7 +103,7 @@ class PDFDokumentProcessor { @Throws(IOException::class) private fun konverterAlleSiderTilA4() { - LOGGER.debug( + log.debug( "Konverterer {} sider til A4 størrelse. Filstørrelse {}", document!!.numberOfPages, bytesIntoHumanReadable( @@ -149,9 +161,6 @@ class PDFDokumentProcessor { } companion object { - private val LOGGER = LoggerFactory.getLogger( - PDFDokumentProcessor::class.java, - ) @Throws(IOException::class) fun fileToByte(file: File): ByteArray { @@ -215,8 +224,14 @@ class PDFDokumentMerger { private fun executeMerge(mergedDocument: PDFMergerUtility) { try { mergedDocument.mergeDocuments(MemoryUsageSetting.setupTempFileOnly().streamCache) + } catch (e: StackOverflowError) { + log.error(e) { "Det skjedde en feil ved merging av dokumenter. Forsøker å merge dokumenter uten kompresjon" } + mergedDocument.mergeDocuments( + MemoryUsageSetting.setupTempFileOnly().streamCache, + CompressParameters.NO_COMPRESSION + ) } catch (e: Exception) { - log.error(e) { "Det skjedde en feil ved merging av dokumenter. Forsøker å merge dokumenter uten komprimering" } + log.error(e) { "Det skjedde en feil ved merging av dokumenter. Forsøker å merge dokumenter uten kompresjon" } mergedDocument.mergeDocuments( MemoryUsageSetting.setupTempFileOnly().streamCache, CompressParameters.NO_COMPRESSION