Skip to content

Commit

Permalink
refactored IppInspector to reduce "complexity" for sonar
Browse files Browse the repository at this point in the history
  • Loading branch information
gmuth committed Sep 20, 2024
1 parent bc77eb7 commit 6e2e05f
Showing 1 changed file with 26 additions and 22 deletions.
48 changes: 26 additions & 22 deletions src/main/kotlin/de/gmuth/ipp/client/IppInspector.kt
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,6 @@ class IppInspector {
logger.info { "Document formats: $documentFormatSupported" }
}

val pdfResource = when {
!attributes.containsKey("media-ready") -> {
logger.warning { "media-ready not supported" }
pdfA4
}

mediaReady.contains("iso-a4") || mediaReady.contains("iso_a4_210x297mm") -> pdfA4
mediaReady.contains("na_letter") || mediaReady.contains("na_letter_8.5x11in") -> "blank_USLetter.pdf"
else -> {
logger.warning { "No PDF available for media '$mediaReady', trying A4" }
pdfA4
}
}

if (savePrinterIcons && attributes.containsKey("printer-icons")) {
logger.info { "> Save Printer icons" }
savePrinterIcons()
Expand Down Expand Up @@ -113,16 +99,34 @@ class IppInspector {
}
logger.info { response.toString() }

logger.info { "> Print job $pdfResource" }
val documentStream = IppInspector::class.java.getResourceAsStream("/$pdfResource")!!
printJob(documentStream, jobName(pdfResource)).run {
logger.info { toString() }
logger.info { "> Get jobs" }
for (job in getJobs()) {
logger.info { "$job" }
logger.info { "> Print job" }
val job = printPdf()
logger.info { "$job" }

logger.info { "> Get jobs" }
getJobs().forEach { logger.info { "$it" } }

job.inspect(cancelJob)
}

private fun IppPrinter.printPdf(): IppJob {

val pdfResource = when {
!attributes.containsKey("media-ready") -> {
logger.warning { "media-ready not supported" }
pdfA4
}

mediaReady.contains("iso-a4") || mediaReady.contains("iso_a4_210x297mm") -> pdfA4
mediaReady.contains("na_letter") || mediaReady.contains("na_letter_8.5x11in") -> "blank_USLetter.pdf"
else -> {
logger.warning { "No PDF available for media '$mediaReady', trying A4" }
pdfA4
}
inspect(cancelJob)
}

val documentStream = javaClass.getResourceAsStream("/$pdfResource")!!
return printJob(documentStream, jobName(pdfResource))
}

private fun IppJob.inspect(cancelJob: Boolean) {
Expand Down

0 comments on commit 6e2e05f

Please sign in to comment.