Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*******************************************************************************
* Copyright 2015 Defense Health Agency (DHA)
*
* If your use of this software does not include any GPLv2 components:
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ----------------------------------------------------------------------------
* If your use of this software includes any GPLv2 components:
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*******************************************************************************/
package prerna.poi.main;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Set;
import java.util.Vector;
import java.util.regex.Pattern;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import prerna.engine.api.IDatabaseEngine;
import prerna.engine.api.ISelectStatement;
import prerna.engine.api.ISelectWrapper;
import prerna.rdf.engine.wrappers.WrapperManager;
import prerna.util.Constants;
import prerna.util.DIHelper;
import prerna.util.Utility;
/**
* Create an excel file listing all the instance nodes and their properties for
* a type node specified on the DB Modification tab, Export Data section Can
* export a maximum of 9 different node types, stored in different tabs, at one
* time
*/
public class NodeLoadingSheetWriter {
private Boolean showSuccessMessage = true;
private String writeFileName;
public static final String DIR_SEPARATOR = java.nio.file.FileSystems.getDefault().getSeparator();
private static final Logger classLogger = LogManager.getLogger(NodeLoadingSheetWriter.class);
/**
* Functions as the main method for the class Reorganizes the information from
* ExportNodeLoadSheetsListener into a format that is similar to a load sheet
* and saves it in a workbook The data is reorganized in a Hashtable> where the keys become the sheet name and the instance data
* in the format Vector
*
* @param fileLoc String containing the path location to save the workbook
* @param hash Hashtable containing the information gotten from
* ExportNodeLoadSheetsListener, which gets the data from
* querying the engine
* @param engine
* @param nodeTypes
*/
public void writeNodeLoadingSheets(IDatabaseEngine engine, ArrayList nodeTypes) {
Hashtable> hash = queryData(engine, nodeTypes);
Hashtable> preparedHash = prepareLoadingSheetExport(hash);
// Create the blank excel file
String workingDir = DIHelper.getInstance().getProperty(Constants.BASE_FOLDER);
String folder = DIR_SEPARATOR + "export" + DIR_SEPARATOR + "Nodes" + DIR_SEPARATOR;
if (writeFileName == null)
writeFileName = "Nodes_LoadingSheet_" + DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT)
.format(new Date()).replace(":", "") + ".xlsx";
String fileLoc = workingDir + folder + writeFileName;
XSSFWorkbook wb = new XSSFWorkbook();
// Write the loader sheet to excel
XSSFSheet sheet = wb.createSheet("Loader");
Vector data = new Vector();
data.add(new String[] { "Sheet Name", "Type" });
for (String key : hash.keySet()) {
data.add(new String[] { key, "Usual" });
}
int count = 0;
for (int row = 0; row < data.size(); row++) {
XSSFRow row1 = sheet.createRow(count);
count++;
for (int col = 0; col < data.get(row).length; col++) {
XSSFCell cell = row1.createCell(col);
if (data.get(row)[col] != null) {
cell.setCellValue(data.get(row)[col].replace("\"", ""));
}
}
}
// Add a sheet for each concept that lists all of its properties
Set keySet = preparedHash.keySet();
for (String key : keySet) {
Vector sheetVector = preparedHash.get(key);
writeSheet(key, sheetVector, wb);
}
// Write the excel
Utility.writeWorkbook(wb, fileLoc);
if (showSuccessMessage)
Utility.showMessage("Exported node properties successfully: " + fileLoc);
}
private Hashtable> queryData(IDatabaseEngine engine, ArrayList nodeTypes) {
Hashtable> hash = new Hashtable>();
for (String nodeType : nodeTypes) {
ArrayList