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 relationships and relationship
* properties for type triple specified on the DB Modification tab, Export Data
* section Can export a maximum of 9 different relationships, stored in
* different tabs, at one time
*/
public class RelationshipLoadingSheetWriter {
private static final String NONE_SELECTED = "None";
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(RelationshipLoadingSheetWriter.class);
public void writeRelationshipLoadingSheets(IDatabaseEngine engine, ArrayList relationships) {
Hashtable> hash = queryData(engine, relationships);
Hashtable> preparedHash = prepareLoadingSheetExport(hash);
// create the blank excel files
String workingDir = DIHelper.getInstance().getProperty(Constants.BASE_FOLDER);
String folder = DIR_SEPARATOR + "export" + DIR_SEPARATOR + "Relationships" + DIR_SEPARATOR;
if (writeFileName == null)
writeFileName = "Relationships_LoadingSheet_" + DateFormat
.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT).format(new Date()).replace(":", "")
+ ".xlsx";
String fileLoc = workingDir + folder + writeFileName;
// write the loader sheet to excel
XSSFWorkbook wb = new XSSFWorkbook();
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++) {
String valFirstColumn = data.get(row)[0];
if (valFirstColumn != null && !valFirstColumn.equals("") && !valFirstColumn.startsWith("-")
&& !valFirstColumn.endsWith("-") && !valFirstColumn.endsWith("None")) {
XSSFRow row1 = sheet.createRow(count);
count++;
for (int col = 0; col < data.get(row).length; col++) {
XSSFCell cell = row1.createCell(col);
String val = data.get(row)[col];
if (val != null)
cell.setCellValue(data.get(row)[col].replace("\"", ""));
}
}
}
// Add a sheet for each relationship and 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 relationships successfully: " + fileLoc);
}
private Hashtable> queryData(IDatabaseEngine engine, ArrayList relationships) {
Hashtable> hash = new Hashtable>();
// Iterate through each relationship, grab data, store in hashtable
for (String[] spo : relationships) {
String subjectNodeType = spo[0];
String relationship = spo[1];
String objectNodeType = spo[2];
// is this needed? think this check should be done prior to this
if (!(subjectNodeType.equals(this.NONE_SELECTED) || objectNodeType.equals(this.NONE_SELECTED)
|| relationship.equals(this.NONE_SELECTED))) {
ArrayList