diff --git a/src/main/java/cokr/xit/fims/cmmn/CmmnUtil.java b/src/main/java/cokr/xit/fims/cmmn/CmmnUtil.java index 4a9efafa..a82a3a80 100644 --- a/src/main/java/cokr/xit/fims/cmmn/CmmnUtil.java +++ b/src/main/java/cokr/xit/fims/cmmn/CmmnUtil.java @@ -4,6 +4,7 @@ import java.awt.Graphics2D; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; +import java.io.InputStream; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; @@ -105,7 +106,7 @@ public class CmmnUtil { * @param source 원본파일, target 결과파일, mosaicInfos 모자이크 정보 * @return */ - public static void createMaskedImage(File source, File target, List mosaicInfos) { + public static void createMaskedImage(InputStream source, File target, List mosaicInfos) { BufferedImage buffer_black_image = new BufferedImage(1, 1, BufferedImage.TYPE_3BYTE_BGR); String extension = FilenameUtils.getExtension(target.getName()); diff --git a/src/main/java/cokr/xit/fims/cmmn/pdf/print/PDFPrintUtil.java b/src/main/java/cokr/xit/fims/cmmn/pdf/print/PDFPrintUtil.java index 07cd463d..990f0443 100644 --- a/src/main/java/cokr/xit/fims/cmmn/pdf/print/PDFPrintUtil.java +++ b/src/main/java/cokr/xit/fims/cmmn/pdf/print/PDFPrintUtil.java @@ -2,6 +2,7 @@ package cokr.xit.fims.cmmn.pdf.print; import java.io.File; import java.io.IOException; +import java.io.InputStream; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; @@ -223,7 +224,7 @@ public class PDFPrintUtil extends PrintUtil { /** * pdf에 이미지를 삽입한다. */ - public void insertImage(PDDocument doc, PDPageContentStream contentStream, String imagePath, float[] XYmm, + public void insertImage(PDDocument doc, PDPageContentStream contentStream, InputStream imageStream, float[] XYmm, float[] SIZEmm) { float[] xyAbsolute = this.toPDFCoordinate(XYmm).absolute(); @@ -232,10 +233,10 @@ public class PDFPrintUtil extends PrintUtil { mmToPt(SIZEmm[0]),mmToPt(SIZEmm[1]) }; try { - if(!imagePath.equals("")) { - PDImageXObject image = PDImageXObject.createFromFile(imagePath, doc); - contentStream.drawImage(image, xyAbsolute[0], xyAbsolute[1]-size[1], size[0], size[1]); - } + + PDImageXObject image = PDImageXObject.createFromByteArray(doc, imageStream.readAllBytes(), "temp"); + contentStream.drawImage(image, xyAbsolute[0], xyAbsolute[1]-size[1], size[0], size[1]); + } catch (IOException e) { e.printStackTrace(); throw new RuntimeException("PDF 파일 출력 중 오류가 발생하였습니다."+e); diff --git a/src/main/java/cokr/xit/fims/sprt/service/bean/IntegrationSearchServiceBean.java b/src/main/java/cokr/xit/fims/sprt/service/bean/IntegrationSearchServiceBean.java index 095a6431..20bebce0 100644 --- a/src/main/java/cokr/xit/fims/sprt/service/bean/IntegrationSearchServiceBean.java +++ b/src/main/java/cokr/xit/fims/sprt/service/bean/IntegrationSearchServiceBean.java @@ -2,6 +2,7 @@ package cokr.xit.fims.sprt.service.bean; import java.io.BufferedWriter; import java.io.File; +import java.io.FileInputStream; import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; @@ -466,27 +467,50 @@ public class IntegrationSearchServiceBean extends AbstractServiceBean implements } else if(prototypeStng.getComponentType().equals("image")) { String imagePath = pdfFormat.getMappingValue(otptArtclNm,defaultValue,forPost,dataObject,printOption,pdfPrintUtil); + + if(ifEmpty(imagePath, ()->"").equals("")) { + continue; + } + + InputStream is = null; + if(imagePath.startsWith("files")) { + File imageFile = new File(imagePath); + is = new FileInputStream(imageFile); + } else { + is = new ClassPathResource(imagePath).getInputStream(); + } + String imageKey = ""; if(otptArtclNm.equals("rprsCrdnPhoto")) { imageKey = pdfFormat.getMappingValue(otptArtclNm+"Key",defaultValue,forPost,dataObject,printOption,pdfPrintUtil); } - pdfPrintUtil.insertImage(doc, contentStream, imagePath, pstn, size); + pdfPrintUtil.insertImage(doc, contentStream, is, pstn, size); if(otptArtclNm.equals("rprsCrdnPhoto") && !imageKey.equals("")) { - String blackImage = "samplefiles/black.png"; + + InputStream is0 = null; + if(imagePath.startsWith("files")) { + File imageFile0 = new File(imagePath); + is0 = new FileInputStream(imageFile0); + } else { + is0 = new ClassPathResource(imagePath).getInputStream(); + } List transformedMosaicInfos = mediaBean.getTransformedMosaic( - imageKey, imagePath, new PstnAndSize(pstn[0],pstn[1], size[0], size[1]) + imageKey, is0, new PstnAndSize(pstn[0],pstn[1], size[0], size[1]) ); for(int k=0; k < transformedMosaicInfos.size(); k++) { PstnAndSize mosaicInfo = transformedMosaicInfos.get(k); - pdfPrintUtil.insertImage(doc, contentStream, blackImage, + InputStream blackImageStream = new ClassPathResource("samplefiles/black.png").getInputStream(); + pdfPrintUtil.insertImage(doc, contentStream, blackImageStream, mosaicInfo.getPstn().to2Float(), mosaicInfo.getSize().to2Float()); } } + + } else if(prototypeStng.getComponentType().equals("images")) { List imagePaths = pdfFormat.getMappingValues(otptArtclNm,defaultValue,forPost,dataObject,printOption,pdfPrintUtil); @@ -513,22 +537,43 @@ public class IntegrationSearchServiceBean extends AbstractServiceBean implements for (int i=0; i< devideInfos.size(); i++){ PstnAndSize devideInfo = devideInfos.get(i); + String imagePath = imagePaths.get(i); + + if(ifEmpty(imagePath, ()-> "").equals("")) { + continue; + } - pdfPrintUtil.insertImage(doc, contentStream, - imagePaths.get(i), devideInfo.getPstn().to2Float(), devideInfo.getSize().to2Float()); + InputStream is = null; + if(imagePaths.get(i).startsWith("files")) { + File imageFile = new File(imagePath); + is = new FileInputStream(imageFile); + } else { + is = new ClassPathResource(imagePath).getInputStream(); + } + + pdfPrintUtil.insertImage(doc, contentStream, is, + devideInfo.getPstn().to2Float(), devideInfo.getSize().to2Float()); if(otptArtclNm.equals("crdnPhoto") && !imageKeys.isEmpty()) { - String blackImage = "samplefiles/black.png"; + + InputStream is0 = null; + String imagePath0 = imagePaths.get(i); + if(imagePath0.startsWith("files")) { + File imageFile0 = new File(imagePath0); + is0 = new FileInputStream(imageFile0); + } else { + is0 = new ClassPathResource(imagePath0).getInputStream(); + } List transformedMosaicInfos = mediaBean.getTransformedMosaic( - imageKeys.get(i), imagePaths.get(i), devideInfo + imageKeys.get(i), is0, devideInfo ); for(int k=0; k < transformedMosaicInfos.size(); k++) { PstnAndSize mosaicInfo = transformedMosaicInfos.get(k); - - pdfPrintUtil.insertImage(doc, contentStream, blackImage, + InputStream blackImageStream = new ClassPathResource("samplefiles/black.png").getInputStream(); + pdfPrintUtil.insertImage(doc, contentStream, blackImageStream, mosaicInfo.getPstn().to2Float(), mosaicInfo.getSize().to2Float()); } @@ -540,7 +585,7 @@ public class IntegrationSearchServiceBean extends AbstractServiceBean implements } - } + }//출력항목 loop 끝 if(!completeFoldLine) { if(!otptBscStng.string("FOLD_LINE_PSTN_SE_CD").equals("")) { @@ -549,7 +594,8 @@ public class IntegrationSearchServiceBean extends AbstractServiceBean implements } contentStream.close(); - } + + } //출력자료건수 loop 끝 doc.save(resultFilePath); @@ -619,11 +665,21 @@ public class IntegrationSearchServiceBean extends AbstractServiceBean implements for(int j=0; j < fileInfoList.size(); j++){ DataObject fileInfo = fileInfoList.get(j); List mosaicInfos = mediaBean.getMosaicList(fileInfo.string("FILE_ID")); + String orgnFilePath = fileInfo.string("FILE_PATH"); + if(ifEmpty(orgnFilePath, ()->"").equals("")) { + continue; + } - File orgnFile = new File(fileInfo.string("FILE_PATH")); + InputStream orgnFileInputStream = null; - if(!orgnFile.exists() || !orgnFile.canRead()) { - continue; + if(orgnFilePath.startsWith("files")) { + File orgnFile = new File(orgnFilePath); + if(!orgnFile.exists() || !orgnFile.canRead()) { + continue; + } + orgnFileInputStream = new FileInputStream(orgnFile); + } else { + orgnFileInputStream = new ClassPathResource(orgnFilePath).getInputStream(); } String modifiedFileName = "P"+fileInfo.string("INF_KEY")+CmmnUtil.indexToAlphabet(j, true)+"."+"JPG"; @@ -633,9 +689,9 @@ public class IntegrationSearchServiceBean extends AbstractServiceBean implements File modifiedFile = new File(modifiedFilePath); if(mosaicInfos != null) { - CmmnUtil.createMaskedImage(orgnFile, modifiedFile, mosaicInfos); + CmmnUtil.createMaskedImage(orgnFileInputStream, modifiedFile, mosaicInfos); } else { - Files.copy(orgnFile.toPath(), modifiedFile.toPath(), StandardCopyOption.REPLACE_EXISTING); + Files.copy(orgnFileInputStream, modifiedFile.toPath(), StandardCopyOption.REPLACE_EXISTING); } dataObject.set("CRDN_PHOTO"+(j+1), modifiedFilePath); } diff --git a/src/main/java/cokr/xit/fims/sprt/service/bean/MediaBean.java b/src/main/java/cokr/xit/fims/sprt/service/bean/MediaBean.java index fb2fc4ea..f5effd6a 100644 --- a/src/main/java/cokr/xit/fims/sprt/service/bean/MediaBean.java +++ b/src/main/java/cokr/xit/fims/sprt/service/bean/MediaBean.java @@ -1,7 +1,7 @@ package cokr.xit.fims.sprt.service.bean; import java.awt.image.BufferedImage; -import java.io.File; +import java.io.InputStream; import java.util.ArrayList; import java.util.List; @@ -77,17 +77,12 @@ public class MediaBean extends AbstractComponent { return mediaMapper.selectMosaicList(fileId); } - public List getTransformedMosaic(String imageKey, String imagePath, PstnAndSize pstnAndSize_in_print) { + public List getTransformedMosaic(String imageKey, InputStream inputStream, PstnAndSize pstnAndSize_in_print) { List result = new ArrayList<>(); try { - File imageFile = new File(imagePath); - if(!imageFile.exists() || !imageFile.canRead()) { - result.add(new PstnAndSize(0, 0, 0, 0)); - return result; - } - BufferedImage image = ImageIO.read(imageFile); + BufferedImage image = ImageIO.read(inputStream); float originalWidth = image.getWidth(null); float originalHeight = image.getHeight(null); float transX = pstnAndSize_in_print.getWidth() / originalWidth; diff --git a/samplefiles/black.png b/src/main/resources/samplefiles/black.png similarity index 100% rename from samplefiles/black.png rename to src/main/resources/samplefiles/black.png diff --git a/samplefiles/crdn1.png b/src/main/resources/samplefiles/crdn1.png similarity index 100% rename from samplefiles/crdn1.png rename to src/main/resources/samplefiles/crdn1.png diff --git a/samplefiles/crdn2.png b/src/main/resources/samplefiles/crdn2.png similarity index 100% rename from samplefiles/crdn2.png rename to src/main/resources/samplefiles/crdn2.png diff --git a/samplefiles/crdn3.png b/src/main/resources/samplefiles/crdn3.png similarity index 100% rename from samplefiles/crdn3.png rename to src/main/resources/samplefiles/crdn3.png diff --git a/samplefiles/crdn4.png b/src/main/resources/samplefiles/crdn4.png similarity index 100% rename from samplefiles/crdn4.png rename to src/main/resources/samplefiles/crdn4.png diff --git a/samplefiles/crdn5.png b/src/main/resources/samplefiles/crdn5.png similarity index 100% rename from samplefiles/crdn5.png rename to src/main/resources/samplefiles/crdn5.png diff --git a/samplefiles/crdn6.png b/src/main/resources/samplefiles/crdn6.png similarity index 100% rename from samplefiles/crdn6.png rename to src/main/resources/samplefiles/crdn6.png diff --git a/samplefiles/crdn7.png b/src/main/resources/samplefiles/crdn7.png similarity index 100% rename from samplefiles/crdn7.png rename to src/main/resources/samplefiles/crdn7.png diff --git a/samplefiles/sample.JPG b/src/main/resources/samplefiles/sample.JPG similarity index 100% rename from samplefiles/sample.JPG rename to src/main/resources/samplefiles/sample.JPG