List of usage examples for org.apache.poi.ss.usermodel IndexedColors LIGHT_BLUE
IndexedColors LIGHT_BLUE
To view the source code for org.apache.poi.ss.usermodel IndexedColors LIGHT_BLUE.
Click Source Link
From source file:br.com.algoritmo.compilacao.CompilaXlsx.java
License:Apache License
/** * Create a library of cell styles// w ww .j a v a 2 s . c om */ private static Map<String, CellStyle> createStyles(Workbook wb) { Map<String, CellStyle> styles = new HashMap<String, CellStyle>(); CellStyle style; Font titleFont = wb.createFont(); titleFont.setFontHeightInPoints((short) 12); titleFont.setBoldweight(Font.BOLDWEIGHT_BOLD); style = wb.createCellStyle(); style.setAlignment(CellStyle.ALIGN_CENTER); style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); style.setFont(titleFont); styles.put("title", style); Font monthFont = wb.createFont(); monthFont.setFontHeightInPoints((short) 10); monthFont.setColor(IndexedColors.WHITE.getIndex()); monthFont.setBoldweight(Font.BOLDWEIGHT_BOLD); style = wb.createCellStyle(); style.setAlignment(CellStyle.ALIGN_LEFT); style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); style.setFillForegroundColor(IndexedColors.LIGHT_BLUE.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); style.setFont(monthFont); style.setWrapText(true); styles.put("header", style); Font monthFont1 = wb.createFont(); monthFont1.setFontHeightInPoints((short) 10); monthFont1.setColor(IndexedColors.WHITE.getIndex()); monthFont1.setBoldweight(Font.BOLDWEIGHT_BOLD); style = wb.createCellStyle(); style.setAlignment(CellStyle.ALIGN_LEFT); style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); style.setFont(monthFont1); style.setWrapText(true); styles.put("header1", style); style = wb.createCellStyle(); style.setAlignment(CellStyle.ALIGN_LEFT); style.setWrapText(true); style.setBorderRight(CellStyle.BORDER_THIN); style.setRightBorderColor(IndexedColors.BLACK.getIndex()); style.setBorderLeft(CellStyle.BORDER_THIN); style.setLeftBorderColor(IndexedColors.BLACK.getIndex()); style.setBorderTop(CellStyle.BORDER_THIN); style.setTopBorderColor(IndexedColors.BLACK.getIndex()); style.setBorderBottom(CellStyle.BORDER_THIN); style.setBottomBorderColor(IndexedColors.BLACK.getIndex()); styles.put("cell", style); style = wb.createCellStyle(); style.setAlignment(CellStyle.ALIGN_CENTER); style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); style.setDataFormat(wb.createDataFormat().getFormat("0.00")); styles.put("formula", style); style = wb.createCellStyle(); style.setAlignment(CellStyle.ALIGN_LEFT); style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); style.setFillForegroundColor(IndexedColors.GREY_40_PERCENT.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); style.setDataFormat(wb.createDataFormat().getFormat("0.00")); styles.put("formula_2", style); return styles; }
From source file:com.wantdo.stat.excel.poi_src.ConditionalFormats.java
License:Apache License
/** * Use Excel conditional formatting to highlight items that are in a list on the worksheet. *//*from ww w. j a v a 2 s.c o m*/ static void inList(Sheet sheet) { sheet.createRow(0).createCell(0).setCellValue("Codes"); sheet.createRow(1).createCell(0).setCellValue("AA"); sheet.createRow(2).createCell(0).setCellValue("BB"); sheet.createRow(3).createCell(0).setCellValue("GG"); sheet.createRow(4).createCell(0).setCellValue("AA"); sheet.createRow(5).createCell(0).setCellValue("FF"); sheet.createRow(6).createCell(0).setCellValue("XX"); sheet.createRow(7).createCell(0).setCellValue("CC"); sheet.getRow(0).createCell(2).setCellValue("Valid"); sheet.getRow(1).createCell(2).setCellValue("AA"); sheet.getRow(2).createCell(2).setCellValue("BB"); sheet.getRow(3).createCell(2).setCellValue("CC"); SheetConditionalFormatting sheetCF = sheet.getSheetConditionalFormatting(); // Condition 1: Formula Is =A2=A1 (White Font) ConditionalFormattingRule rule1 = sheetCF.createConditionalFormattingRule("COUNTIF($C$2:$C$4,A2)"); PatternFormatting fill1 = rule1.createPatternFormatting(); fill1.setFillBackgroundColor(IndexedColors.LIGHT_BLUE.index); fill1.setFillPattern(PatternFormatting.SOLID_FOREGROUND); CellRangeAddress[] regions = { CellRangeAddress.valueOf("A2:A8") }; sheetCF.addConditionalFormatting(regions, rule1); sheet.getRow(2).createCell(3).setCellValue( "<== Use Excel conditional formatting to highlight items that are in a list on the worksheet"); }
From source file:edu.casetools.rcase.extensions.excel.control.Exporter.java
License:Open Source License
private void createHeaderStyle() { headerCellStyle = workbook.createCellStyle(); headerCellStyle.setFillForegroundColor(IndexedColors.LIGHT_BLUE.getIndex()); headerCellStyle.setFillPattern((short) 1); headerCellStyle.setWrapText(false);// www . ja va 2 s . c o m Font headerFont = workbook.createFont(); headerFont.setColor(IndexedColors.WHITE.getIndex()); headerFont.setBoldweight((short) 700); headerCellStyle.setFont(headerFont); headerCellStyle.setBorderBottom((short) 1); headerCellStyle.setBottomBorderColor(IndexedColors.WHITE.getIndex()); headerCellStyle.setBorderLeft((short) 1); headerCellStyle.setLeftBorderColor(IndexedColors.WHITE.getIndex()); headerCellStyle.setBorderRight((short) 1); headerCellStyle.setRightBorderColor(IndexedColors.WHITE.getIndex()); headerCellStyle.setBorderTop((short) 1); headerCellStyle.setTopBorderColor(IndexedColors.WHITE.getIndex()); }
From source file:nc.noumea.mairie.appock.util.StockSpreadsheetExporter.java
License:Open Source License
private static int generateHeader(XSSFSheet worksheet, XSSFWorkbook workbook, int rowNum) { // Now add/*from w w w . j a va 2 s . c o m*/ XSSFRow row = worksheet.createRow(rowNum); XSSFCell cell; XSSFCellStyle headerStyle = workbook.createCellStyle(); headerStyle.setFillForegroundColor(IndexedColors.LIGHT_BLUE.index); headerStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); headerStyle.setBorderBottom(BorderStyle.MEDIUM); headerStyle.setBorderLeft(BorderStyle.MEDIUM); headerStyle.setBorderRight(BorderStyle.MEDIUM); headerStyle.setBorderTop(BorderStyle.MEDIUM); headerStyle.setAlignment(HorizontalAlignment.CENTER); headerStyle.setVerticalAlignment(VerticalAlignment.CENTER); XSSFFont txtFont = workbook.createFont(); txtFont.setFontName("calibri"); txtFont.setFontHeightInPoints((short) 9); txtFont.setBold(true); headerStyle.setFont(txtFont); cell = row.createCell(0); cell.setCellValue("Photo"); cell.setCellStyle(headerStyle); worksheet.setColumnWidth(0, ConvertImageUnits.pixel2WidthUnits(COLUMN_WIDTH_PX));//4387 cell = row.createCell(1); cell.setCellValue("Rfrence"); cell.setCellStyle(headerStyle); cell = row.createCell(2); cell.setCellValue("Libell"); cell.setCellStyle(headerStyle); cell = row.createCell(3); cell.setCellValue("Stock\n Appock"); cell.setCellStyle(headerStyle); cell.getCellStyle().setWrapText(true); cell = row.createCell(4); cell.setCellValue("Stock\n rel"); cell.setCellStyle(headerStyle); cell.getCellStyle().setWrapText(true); row.setHeight((short) 600); return rowNum + 1; }
From source file:org.aio.handy.poi.ConditionalFormats.java
License:Apache License
/** * Use Excel conditional formatting to highlight items that are in a list on * the worksheet.//from ww w. jav a 2 s . com */ static void inList(Sheet sheet) { sheet.createRow(0).createCell(0).setCellValue("Codes"); sheet.createRow(1).createCell(0).setCellValue("AA"); sheet.createRow(2).createCell(0).setCellValue("BB"); sheet.createRow(3).createCell(0).setCellValue("GG"); sheet.createRow(4).createCell(0).setCellValue("AA"); sheet.createRow(5).createCell(0).setCellValue("FF"); sheet.createRow(6).createCell(0).setCellValue("XX"); sheet.createRow(7).createCell(0).setCellValue("CC"); sheet.getRow(0).createCell(2).setCellValue("Valid"); sheet.getRow(1).createCell(2).setCellValue("AA"); sheet.getRow(2).createCell(2).setCellValue("BB"); sheet.getRow(3).createCell(2).setCellValue("CC"); SheetConditionalFormatting sheetCF = sheet.getSheetConditionalFormatting(); // Condition 1: Formula Is =A2=A1 (White Font) ConditionalFormattingRule rule1 = sheetCF.createConditionalFormattingRule("COUNTIF($C$2:$C$4,A2)"); PatternFormatting fill1 = rule1.createPatternFormatting(); fill1.setFillBackgroundColor(IndexedColors.LIGHT_BLUE.index); fill1.setFillPattern(PatternFormatting.SOLID_FOREGROUND); CellRangeAddress[] regions = { CellRangeAddress.valueOf("A2:A8") }; sheetCF.addConditionalFormatting(regions, rule1); sheet.getRow(2).createCell(3).setCellValue( "<== Use Excel conditional formatting to highlight items that are in a list on the worksheet"); }
From source file:org.alanwilliamson.openbd.plugin.spreadsheet.SpreadSheetFormatOptions.java
License:Open Source License
public static void initialize() { lookup_colors = new HashMap<String, Short>(); lookup_alignment = new HashMap<String, Short>(); lookup_border = new HashMap<String, Short>(); lookup_fillpatten = new HashMap<String, Short>(); lookup_underline = new HashMap<String, Byte>(); lookup_color = new HashMap<String, Color>(); lookup_underline.put("double", Font.U_DOUBLE); lookup_underline.put("double_accounting", Font.U_DOUBLE_ACCOUNTING); lookup_underline.put("single", Font.U_SINGLE); lookup_underline.put("single_accounting", Font.U_SINGLE_ACCOUNTING); lookup_underline.put("none", Font.U_NONE); lookup_colors.put("black", IndexedColors.BLACK.getIndex()); lookup_colors.put("brown", IndexedColors.BROWN.getIndex()); lookup_colors.put("olive_green", IndexedColors.OLIVE_GREEN.getIndex()); lookup_colors.put("dark_green", IndexedColors.DARK_GREEN.getIndex()); lookup_colors.put("dark_teal", IndexedColors.DARK_TEAL.getIndex()); lookup_colors.put("dark_blue", IndexedColors.DARK_BLUE.getIndex()); lookup_colors.put("indigo", IndexedColors.INDIGO.getIndex()); lookup_colors.put("grey_80_percent", IndexedColors.GREY_80_PERCENT.getIndex()); lookup_colors.put("grey_50_percent", IndexedColors.GREY_50_PERCENT.getIndex()); lookup_colors.put("grey_40_percent", IndexedColors.GREY_40_PERCENT.getIndex()); lookup_colors.put("grey_25_percent", IndexedColors.GREY_25_PERCENT.getIndex()); lookup_colors.put("orange", IndexedColors.ORANGE.getIndex()); lookup_colors.put("dark_yellow", IndexedColors.DARK_YELLOW.getIndex()); lookup_colors.put("green", IndexedColors.GREEN.getIndex()); lookup_colors.put("teal", IndexedColors.TEAL.getIndex()); lookup_colors.put("blue", IndexedColors.BLUE.getIndex()); lookup_colors.put("blue_grey", IndexedColors.BLUE_GREY.getIndex()); lookup_colors.put("red", IndexedColors.RED.getIndex()); lookup_colors.put("light_orange", IndexedColors.LIGHT_ORANGE.getIndex()); lookup_colors.put("lime", IndexedColors.LIME.getIndex()); lookup_colors.put("sea_green", IndexedColors.SEA_GREEN.getIndex()); lookup_colors.put("aqua", IndexedColors.AQUA.getIndex()); lookup_colors.put("light_blue", IndexedColors.LIGHT_BLUE.getIndex()); lookup_colors.put("violet", IndexedColors.VIOLET.getIndex()); lookup_colors.put("pink", IndexedColors.PINK.getIndex()); lookup_colors.put("gold", IndexedColors.GOLD.getIndex()); lookup_colors.put("yellow", IndexedColors.YELLOW.getIndex()); lookup_colors.put("bright_green", IndexedColors.BRIGHT_GREEN.getIndex()); lookup_colors.put("turquoise", IndexedColors.TURQUOISE.getIndex()); lookup_colors.put("dark_red", IndexedColors.DARK_RED.getIndex()); lookup_colors.put("sky_blue", IndexedColors.SKY_BLUE.getIndex()); lookup_colors.put("plum", IndexedColors.PLUM.getIndex()); lookup_colors.put("rose", IndexedColors.ROSE.getIndex()); lookup_colors.put("light_yellow", IndexedColors.LIGHT_YELLOW.getIndex()); lookup_colors.put("light_green", IndexedColors.LIGHT_GREEN.getIndex()); lookup_colors.put("light_turquoise", IndexedColors.LIGHT_TURQUOISE.getIndex()); lookup_colors.put("pale_blue", IndexedColors.PALE_BLUE.getIndex()); lookup_colors.put("lavender", IndexedColors.LAVENDER.getIndex()); lookup_colors.put("white", IndexedColors.WHITE.getIndex()); lookup_colors.put("cornflower_blue", IndexedColors.CORNFLOWER_BLUE.getIndex()); lookup_colors.put("lemon_chiffon", IndexedColors.LEMON_CHIFFON.getIndex()); lookup_colors.put("maroon", IndexedColors.MAROON.getIndex()); lookup_colors.put("orchid", IndexedColors.ORCHID.getIndex()); lookup_colors.put("coral", IndexedColors.CORAL.getIndex()); lookup_colors.put("royal_blue", IndexedColors.ROYAL_BLUE.getIndex()); lookup_colors.put("light_cornflower_blue", IndexedColors.LIGHT_CORNFLOWER_BLUE.getIndex()); lookup_alignment.put("left", CellStyle.ALIGN_LEFT); lookup_alignment.put("right", CellStyle.ALIGN_RIGHT); lookup_alignment.put("center", CellStyle.ALIGN_CENTER); lookup_alignment.put("justify", CellStyle.ALIGN_JUSTIFY); lookup_alignment.put("general", CellStyle.ALIGN_GENERAL); lookup_alignment.put("fill", CellStyle.ALIGN_FILL); lookup_alignment.put("center_selection", CellStyle.ALIGN_CENTER_SELECTION); lookup_alignment.put("vertical_top", CellStyle.VERTICAL_TOP); lookup_alignment.put("vertical_bottom", CellStyle.VERTICAL_BOTTOM); lookup_alignment.put("vertical_center", CellStyle.VERTICAL_CENTER); lookup_alignment.put("vertical_justify", CellStyle.VERTICAL_JUSTIFY); lookup_border.put("none", CellStyle.BORDER_NONE); lookup_border.put("thin", CellStyle.BORDER_THIN); lookup_border.put("medium", CellStyle.BORDER_MEDIUM); lookup_border.put("dashed", CellStyle.BORDER_DASHED); lookup_border.put("hair", CellStyle.BORDER_HAIR); lookup_border.put("thick", CellStyle.BORDER_THICK); lookup_border.put("double", CellStyle.BORDER_DOUBLE); lookup_border.put("dotted", CellStyle.BORDER_DOTTED); lookup_border.put("medium_dashed", CellStyle.BORDER_MEDIUM_DASHED); lookup_border.put("dash_dot", CellStyle.BORDER_DASH_DOT); lookup_border.put("medium_dash_dot", CellStyle.BORDER_MEDIUM_DASH_DOT); lookup_border.put("dash_dot_dot", CellStyle.BORDER_DASH_DOT_DOT); lookup_border.put("medium_dash_dot_dot", CellStyle.BORDER_MEDIUM_DASH_DOT_DOT); lookup_border.put("slanted_dash_dot", CellStyle.BORDER_SLANTED_DASH_DOT); lookup_fillpatten.put("big_spots", CellStyle.BIG_SPOTS); lookup_fillpatten.put("squares", CellStyle.SQUARES); lookup_fillpatten.put("nofill", CellStyle.NO_FILL); lookup_fillpatten.put("solid_foreground", CellStyle.SOLID_FOREGROUND); lookup_fillpatten.put("fine_dots", CellStyle.FINE_DOTS); lookup_fillpatten.put("alt_bars", CellStyle.ALT_BARS); lookup_fillpatten.put("sparse_dots", CellStyle.SPARSE_DOTS); lookup_fillpatten.put("thick_horz_bands", CellStyle.THICK_HORZ_BANDS); lookup_fillpatten.put("thick_vert_bands", CellStyle.THICK_VERT_BANDS); lookup_fillpatten.put("thick_backward_diag", CellStyle.THICK_BACKWARD_DIAG); lookup_fillpatten.put("thick_forward_diag", CellStyle.THICK_FORWARD_DIAG); lookup_fillpatten.put("thin_horz_bands", CellStyle.THIN_HORZ_BANDS); lookup_fillpatten.put("thin_vert_bands", CellStyle.THIN_VERT_BANDS); lookup_fillpatten.put("thin_backward_diag", CellStyle.THIN_BACKWARD_DIAG); lookup_fillpatten.put("thin_forward_diag", CellStyle.THIN_FORWARD_DIAG); lookup_fillpatten.put("diamonds", CellStyle.DIAMONDS); lookup_fillpatten.put("less_dots", CellStyle.LESS_DOTS); lookup_fillpatten.put("least_dots", CellStyle.LEAST_DOTS); lookup_color.put("black", Color.BLACK); lookup_color.put("blue", Color.BLUE); lookup_color.put("cyan", Color.CYAN); lookup_color.put("dark_gray", Color.DARK_GRAY); lookup_color.put("darkGray", Color.DARK_GRAY); lookup_color.put("gray", Color.GRAY); lookup_color.put("green", Color.GREEN); lookup_color.put("light_gray", Color.LIGHT_GRAY); lookup_color.put("lightGray", Color.LIGHT_GRAY); lookup_color.put("magenta", Color.MAGENTA); lookup_color.put("orange", Color.ORANGE); lookup_color.put("pink", Color.PINK); lookup_color.put("red", Color.RED); lookup_color.put("white", Color.WHITE); lookup_color.put("yellow", Color.YELLOW); }
From source file:org.jcvi.ometa.utils.JsonProducer.java
License:Open Source License
public void jsonHelper(String projectNames, String attributes, String screenAttributes, String sorting, String fileName, String filePath, String domain) { String PROJECT_STATUS = "Project Status"; try {// w ww . j a v a 2s.c o m JSONObject json = new JSONObject(); File directory = new File(filePath); if (!directory.exists() || !directory.isDirectory()) { if ((new File(directory.getParent())).canWrite()) directory.mkdir(); else throw new Exception(); } //Json file Creation File tempFile = new File(filePath + File.separator + fileName + "_temp.json"); FileWriter fileWriter = new FileWriter(tempFile); BufferedWriter bufferedWriter = new BufferedWriter(fileWriter); //Normal status data retrieval LookupValue tempLookupValue; List<String> projectNameList = new ArrayList<String>(); if (projectNames.contains(",")) projectNameList.addAll(Arrays.asList(projectNames.split(","))); else projectNameList.add(projectNames); List<String> availableAttributes = new ArrayList<String>(); availableAttributes.add("Sample Name"); List<Project> projects = pseEjb.getProjects(projectNameList); List<Long> projectIds = new ArrayList<Long>(); Map<String, Long> projectNameVsId = new HashMap<String, Long>(); for (Project project : projects) { projectIds.add(project.getProjectId()); projectNameVsId.put(project.getProjectName(), project.getProjectId()); } List<ProjectMetaAttribute> allProjectMetaAttributes = pseEjb.getProjectMetaAttributes(projectIds); for (ProjectMetaAttribute pma : allProjectMetaAttributes) { if (!availableAttributes.contains(pma.getLookupValue().getName())) availableAttributes.add(pma.getLookupValue().getName()); } List<SampleMetaAttribute> allSampleMetaAttributes = pseEjb.getSampleMetaAttributes(projectIds); for (SampleMetaAttribute sma : allSampleMetaAttributes) { if (!availableAttributes.contains(sma.getLookupValue().getName())) availableAttributes.add(sma.getLookupValue().getName()); } List<EventMetaAttribute> allEventMetaAttributes = pseEjb.getEventMetaAttributes(projectIds); for (EventMetaAttribute ema : allEventMetaAttributes) { if (!availableAttributes.contains(ema.getLookupValue().getName())) availableAttributes.add(ema.getLookupValue().getName()); } List<String> parameterizedAttributes = null; if (attributes == null || attributes.equals("") || "ALL".equals(attributes)) { parameterizedAttributes = availableAttributes; } else { parameterizedAttributes = new ArrayList<String>(); ArrayList<String> tokenizedAttribute = new ArrayList<String>(Arrays.asList(attributes.split(","))); for (String tempAttribute : tokenizedAttribute) { if (availableAttributes.contains(tempAttribute)) parameterizedAttributes.add(tempAttribute); } } parameterizedAttributes.removeAll(Arrays.asList(forbiddenAttributes)); /*------------ XLS Part ------------*/ //Excel file Creation Workbook workBook = new HSSFWorkbook(); Sheet workSheet = workBook.createSheet(); int cellIndex = 0, rowIndex = 0; Row singleRow = workSheet.createRow(rowIndex++); Cell headerCell = null; //Header row cell style CellStyle style = workBook.createCellStyle(); style.setFillBackgroundColor(IndexedColors.CORNFLOWER_BLUE.getIndex()); style.setFillForegroundColor(IndexedColors.LIGHT_BLUE.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); Font font = workBook.createFont(); font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); font.setColor(IndexedColors.WHITE.getIndex()); style.setFont(font); /*------------ XLS Part END ------------*/ List<String> attributeList = new ArrayList<String>(); for (String tempAttribute : parameterizedAttributes) { attributeList.add(tempAttribute); headerCell = singleRow.createCell(cellIndex++); headerCell.setCellValue(tempAttribute); headerCell.setCellStyle(style); } if (screenAttributes == null || screenAttributes.equals("") || screenAttributes.equals("ALL")) { json.put("attributes", attributeList); } else { json.put("attributes", Arrays.asList(screenAttributes.split(","))); } json.put("sorting", (sorting == null || sorting.isEmpty() || sorting.equals("-") ? null : sorting)); json.put("projectNames", projectNames); List<ProjectAttribute> allProjectAttributes = pseEjb.getProjectAttributes(projectIds); Map<Long, List<ProjectAttribute>> projIdVsAttributes = new HashMap<Long, List<ProjectAttribute>>(); for (ProjectAttribute pa : allProjectAttributes) { List<ProjectAttribute> paList = projIdVsAttributes.get(pa.getProjectId()); if (paList == null) { paList = new ArrayList<ProjectAttribute>(); projIdVsAttributes.put(pa.getProjectId(), paList); } paList.add(pa); } List<Sample> allSamplesAllProjects = pseEjb.getSamplesForProjects(projectIds); Map<Long, List<Sample>> projectIdVsSampleList = new HashMap<Long, List<Sample>>(); for (Sample sample : allSamplesAllProjects) { List<Sample> thisProjectsSamples = projectIdVsSampleList.get(sample.getProjectId()); if (thisProjectsSamples == null) { thisProjectsSamples = new ArrayList<Sample>(); projectIdVsSampleList.put(sample.getProjectId(), thisProjectsSamples); } thisProjectsSamples.add(sample); } /************* Main LOOP starts *****************/ List<JSONObject> sampleList = new ArrayList<JSONObject>(); List<String> statusList = new ArrayList<String>(); List<JSONObject> sumList = new ArrayList<JSONObject>(); for (Project project : projects) { JSONObject currSum = new JSONObject(); if (project.getIsPublic() == 0) continue; Long tempProjectId = project.getProjectId(); List<ProjectAttribute> paList = projIdVsAttributes.get(tempProjectId); Map<String, Object> projectAttrMap = new HashMap<String, Object>(); if (paList != null) { for (ProjectAttribute pa : paList) { ProjectMetaAttribute projectMeta = pa.getMetaAttribute(); tempLookupValue = projectMeta.getLookupValue(); projectAttrMap.put(tempLookupValue.getName(), ModelValidator.getModelValue(tempLookupValue, pa)); if (projectMeta.getLabel() != null) { //add another key-value pair for a labeled attribute projectAttrMap.put(projectMeta.getLabel(), ModelValidator.getModelValue(tempLookupValue, pa)); } } } if (!projectAttrMap.containsKey(Constants.ATTR_PROJECT_NAME)) projectAttrMap.put(Constants.ATTR_PROJECT_NAME, project.getProjectName()); currSum.put("p_n", project.getProjectName()); currSum.put("p_s", projectAttrMap.get(PROJECT_STATUS)); currSum.put("p_g", projectAttrMap.get("Project Group")); List<Long> sampleIdList = getSampleIdList(getSamplesFromList(projectIdVsSampleList, tempProjectId)); Map<Long, List<SampleAttribute>> sampleIdVsAttributeList = getSampleVsAttributeList(sampleIdList); Map<Long, List<Event>> sampleIdVsEventList = getSampleIdVsEventList(sampleIdList); List<Sample> samplesForProject = getSamplesFromList(projectIdVsSampleList, tempProjectId); currSum.put("tot", samplesForProject.size()); for (Sample sample : samplesForProject) { Map<String, Object> sampleAttrMap = new HashMap<String, Object>(); sampleAttrMap.putAll(projectAttrMap); sampleAttrMap.put(Constants.ATTR_SAMPLE_NAME, sample.getSampleName()); sampleAttrMap.put("sampleId", sample.getSampleId()); List<SampleAttribute> sampleAttributes = sampleIdVsAttributeList.get(sample.getSampleId()); if (sampleAttributes != null && sampleAttributes.size() > 0) { for (SampleAttribute sa : sampleAttributes) { if (sa.getMetaAttribute() == null) continue; SampleMetaAttribute sampleMeta = sa.getMetaAttribute(); tempLookupValue = sampleMeta.getLookupValue(); Object sav = ModelValidator.getModelValue(tempLookupValue, sa); sampleAttrMap.put(tempLookupValue.getName(), sav); if (sampleMeta.getLabel() != null) { //add another key-value pair for a labeled attribute sampleAttrMap.put(sampleMeta.getLabel(), sav); } if (SAMPLE_STATUS.equals(tempLookupValue.getName())) { String currStatus = (String) sav; if (!statusList.contains(currStatus)) //add new status value statusList.add(currStatus); currSum.put(currStatus, currSum.has(currStatus) ? currSum.getInt(currStatus) + 1 : 1); //count } } } List<Event> sampleEvents = sampleIdVsEventList.get(sample.getSampleId()); if (sampleEvents != null && sampleEvents.size() > 0) { Map<Long, List<EventAttribute>> eventIdVsAttributes = getEventIdVsAttributeList( sampleEvents, tempProjectId); //skip sample status value in event attributes String[] skipArrForEventAttribute = { "Sample Status" }; for (Event evt : sampleEvents) { List<EventAttribute> eventAttributes = eventIdVsAttributes.get(evt.getEventId()); if (eventAttributes == null) continue; sampleAttrMap.putAll(CommonTool.getAttributeValueMap(eventAttributes, false, skipArrForEventAttribute)); } } if (!sampleAttrMap.containsKey("Organism")) { //manually add Organism attribute if not exist for GCID projects sampleAttrMap.put("Organism", ""); } JSONObject sampleJsonObj = new JSONObject(); for (String key : sampleAttrMap.keySet()) { //this is custom decorating process for json data file only //in status.shtml page, link on an organism should land to the project page rather than sample detail page if (key.equals("Organism")) { String organismVal = (String) sampleAttrMap.get(key); if (organismVal == null) { //get different attribute value for GCID projects organismVal = (String) sampleAttrMap.get("Species Source Common Name(CS4)"); } sampleJsonObj.put("OrganismUrl", (PROD_SERVER_ADDRESS + Constants.SAMPLE_DETAIL_URL + "iss=true" + "&projectName=" + project.getProjectName() + "&projectId=" + project.getProjectId() + "&sampleName=" + sampleAttrMap.get("Sample Name") + "&sampleId=" + sampleAttrMap.get("sampleId")).replaceAll("\\\"", "\\\\\"")); if (domain != null && !"none".equals(domain)) { String projectGroup = (String) sampleAttrMap.get("Project Group"); organismVal = convertIntoATag(String.format(Constants.PROJECT_SPECIFIC_PAGE, domain, //hostName != null && hostName.contains("spike") ? fileName + "-dev" : fileName, (projectGroup == null ? "" : projectGroup.toLowerCase()), project.getProjectName().replaceAll(" ", "_")), organismVal); } sampleJsonObj.put(key, organismVal); } else { sampleJsonObj.put(key, CommonTool.decorateAttribute(sampleAttrMap, key, project)); } } sampleList.add(sampleJsonObj); cellIndex = 0; singleRow = workSheet.createRow(rowIndex++); for (String tempAttribute : parameterizedAttributes) { singleRow.createCell(cellIndex++) .setCellValue(sampleAttrMap.get(tempAttribute) != null ? "" + sampleAttrMap.get(tempAttribute) : ""); } } sumList.add(currSum); } JSONObject sumMap = new JSONObject(); sumMap.put("s_l", statusList); sumMap.put("data", sumList); json.put("sums", sumMap); json.put("samples", sampleList); //bufferedWriter.write("]"); bufferedWriter.write(json.toString()); bufferedWriter.close(); if (tempFile.exists() && tempFile.length() > 0) { File dataFile = new File(filePath + File.separator + fileName + ".json"); tempFile.renameTo(dataFile); FileOutputStream fileOut = new FileOutputStream(filePath + File.separator + fileName + ".xls"); workBook.write(fileOut); fileOut.close(); } else throw new Exception("Failure in retrieving data for " + fileName + ". File does not exist or file size is zero."); logger.info("[JsonProducer-MBean] JsonProducer process succeeded for " + projectNames); } catch (Exception ex) { logger.info("[JsonProducer-MBean] JsonProducer failed for " + projectNames); ex.printStackTrace(); /*if( hostName.contains( "dmzweb" ) ) { //Send error notification for DMZs only new EmailSender().send( "json", "[PST]Failure in generating Json Data file on : " + hostName, ex.toString() ); }*/ } }
From source file:utilities.XlsxGenerator.java
private CellStyle createRCFStyle() { CellStyle style = createStandardStyle(); style.setFillForegroundColor(IndexedColors.LIGHT_BLUE.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); return style; }