Advertisement
Guest User

Untitled

a guest
Jul 26th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.50 KB | None | 0 0
  1. @JacksonXmlRootElement(localName = "kpi-accounts")
  2. @JsonRootName("kpi-accounts")
  3. @XlsxSheetProperty(name = "accounts")
  4. public class KPIAccountsTO extends KPIEntityTO {
  5.  
  6. private static final long serialVersionUID = 1L;
  7. private int active;
  8. private int onBoardingPending;
  9. private int notActive;
  10.  
  11. public KPIAccountsTO() {
  12. super();
  13. }
  14.  
  15. // setters omitted for brevity ...
  16.  
  17. @JacksonXmlProperty(localName = "active")
  18. @JsonProperty(value = "active", index = 0)
  19. @XlsxColumnProperty(name = "active", index = 0)
  20. public int getActive() {
  21. return active;
  22. }
  23.  
  24. @JacksonXmlProperty(localName = "on-boarding-pending")
  25. @JsonProperty(value = "on-boarding-pending", index = 1)
  26. @XlsxColumnProperty(name = "on-boarding-pending", index = 1, widthModifier = 2)
  27. public int getOnBoardingPending() {
  28. return onBoardingPending;
  29. }
  30.  
  31.  
  32. @JacksonXmlProperty(localName = "not-active")
  33. @JsonProperty(value = "not-active", index = 2)
  34. @XlsxColumnProperty(name = "not-active", index = 2)
  35. public int getNotActive() {
  36. return notActive;
  37. }
  38.  
  39. }
  40.  
  41. public static XSSFSheet createDefaultSheet(XSSFWorkbook book, Class<?> clazzHeader) {
  42. XlsxSheetProperty sheetAnnotation = clazzHeader.getAnnotationsByType(XlsxSheetProperty.class)[0];
  43. XSSFSheet sheet = book.createSheet(sheetAnnotation.name().toUpperCase());
  44. ...
  45. createRowHeder(sheet, clazzHeader);
  46. return sheet;
  47. }
  48.  
  49. private static XSSFRow createRowHeder(XSSFSheet sheet, Class<?> clazzHeader) {
  50. XSSFRow header = sheet.createRow(0);
  51. Method[] methods = Arrays.stream(clazzHeader.getMethods())
  52. .filter(method -> method.isAnnotationPresent(XlsxColumnProperty.class))
  53. // Sorted by index
  54. .sorted((m1, m2) -> Integer.compare(
  55. // m1
  56. m1.getAnnotation(XlsxColumnProperty.class).index(),
  57. // m2
  58. m2.getAnnotation(XlsxColumnProperty.class).index()))
  59. .toArray(size -> new Method[size]);
  60.  
  61. //TODO: Move the stream pipeline
  62. for (int idx = 0; idx < methods.length; idx++) {
  63. XlsxColumnProperty annotation = methods[idx].getAnnotation(XlsxColumnProperty.class);
  64. createDefaultCell(idx, header).setCellValue(annotation.name().toUpperCase());
  65. sheet.setColumnWidth(idx, sheet.getColumnWidth(idx) * annotation.widthModifier());
  66. }
  67. return header;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement