PageRenderTime 41ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

/excelgen/src/main/java/by/q64/promo/excelgen/service/marketing/MarketingReportFirstSlideGeneratorImpl.java

https://bitbucket.org/quadrate/promo
Java | 80 lines | 59 code | 17 blank | 4 comment | 0 complexity | e8d97edebf3bc6b01a7ffe249d99390a MD5 | raw file
  1. package by.q64.promo.excelgen.service.marketing;
  2. import by.q64.promo.excelgen.service.marketing.source.MarketingReportData;
  3. import by.q64.promo.excelgen.service.marketing.source.MarketingReportDataOneCity;
  4. import by.q64.promo.excelgen.service.marketing.source.MarketingSourceByCity;
  5. import by.q64.promo.excelgen.service.marketing.source.settings.MarketingReportSettings;
  6. import by.q64.promo.excelgen.service.utils.OtherUtils;
  7. import org.apache.log4j.Logger;
  8. import org.apache.poi.util.IOUtils;
  9. import org.apache.poi.xslf.usermodel.*;
  10. import org.springframework.beans.factory.annotation.Autowired;
  11. import org.springframework.stereotype.Service;
  12. import java.awt.*;
  13. import java.io.IOException;
  14. import java.util.function.Function;
  15. /**
  16. * Created by Pavel.Sirotkin on 25.12.2014.
  17. */
  18. @Service("marketingReportFirstSlideGenerator")
  19. public class MarketingReportFirstSlideGeneratorImpl implements MarketingReportPartGenerator {
  20. private static final String imageName = "/firstSlideImage.png";
  21. @Autowired
  22. private OtherUtils otherUtils;
  23. private static final Logger LOGGER = Logger.getLogger(MarketingReportFirstSlideGeneratorImpl.class);
  24. @Override
  25. public XMLSlideShow generate(XMLSlideShow ppt, MarketingReportSettings reportSettings,
  26. MarketingReportDataOneCity marketingReportDataOneCity, Function<String, byte[]> pictureGetter) {
  27. String title = marketingReportDataOneCity.getMarketingReportData().getReportTitle();
  28. MarketingSourceByCity cityData = marketingReportDataOneCity.getMarketingSourceByCity();
  29. MarketingReportData mData = marketingReportDataOneCity.getMarketingReportData();
  30. // fill the placeholders
  31. XSLFSlide slide1 = ppt.createSlide();
  32. XSLFTextBox txt1 = slide1.createTextBox();
  33. txt1.setAnchor(new java.awt.Rectangle(250, 250, 450, 200));
  34. XSLFTextParagraph p1 = txt1.addNewTextParagraph();
  35. XSLFTextRun r1 = p1.addNewTextRun();
  36. r1.setText(title);
  37. r1.setFontFamily("Verdana");
  38. r1.setFontColor(new Color(255, 0, 102));
  39. r1.setFontSize(32);
  40. r1.setBold(true);
  41. XSLFTextBox txt2 = slide1.createTextBox();
  42. txt2.setAnchor(new java.awt.Rectangle(420, 480, 200, 40));
  43. XSLFTextParagraph p2 = txt2.addNewTextParagraph();
  44. XSLFTextRun r2 = p2.addNewTextRun();
  45. r2.setText(marketingReportDataOneCity.getMarketingSourceByCity().getCityName()
  46. + "\n" + otherUtils.getMonthName(mData.getMonth()) + " " + mData.getYear());
  47. r2.setFontFamily("Verdana");
  48. r2.setFontColor(Color.black);
  49. r2.setFontSize(16);
  50. try {
  51. drawImage(ppt, slide1);
  52. } catch (IOException e) {
  53. LOGGER.error("", e);
  54. }
  55. return ppt;
  56. }
  57. private void drawImage(XMLSlideShow ppt, XSLFSlide slide) throws IOException {
  58. byte[] bytes = IOUtils.toByteArray(this.getClass().getResourceAsStream(imageName));
  59. int idx = ppt.addPicture(bytes, XSLFPictureData.PICTURE_TYPE_PNG);
  60. XSLFPictureShape pic = slide.createPicture(idx);
  61. pic.setAnchor(new Rectangle(30, 80, 210, 340));
  62. }
  63. }