Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.apg.logic.dataimport.excel;
- import java.io.FileInputStream;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.text.SimpleDateFormat;
- import java.util.HashMap;
- import java.util.HashSet;
- import java.util.LinkedHashSet;
- import java.util.Locale;
- import java.util.Map;
- import java.util.Properties;
- import java.util.Set;
- import java.util.TreeMap;
- import org.apache.commons.lang.StringEscapeUtils;
- import org.apache.poi.hssf.usermodel.HSSFDateUtil;
- import org.apache.poi.ss.usermodel.Cell;
- import org.apache.poi.ss.usermodel.Row;
- import org.apache.poi.ss.usermodel.Sheet;
- import org.apache.poi.ss.usermodel.Workbook;
- import org.apache.poi.xssf.usermodel.XSSFWorkbook;
- import com.apg.entity.Session;
- import com.apg.util.DbMan;
- public class Reader {
- private static final String OTHER_TABLES = "other_tables";
- private static final String FBVA_TRADE_LOG = "fbva_trade_log";
- private static final String EQUIVEST_TRADE_LOG = "equivest_trade_log";
- private static final String OMP_TRADE_LOG = "omp_trade_log";
- private static final String SAM_MF_TRADE_LOG = "sam_mf_trade_log";
- private static final String MWP_TRADE_LOG = "mwp_trade_log";
- private static final String ETP_TRADE_LOG = "etp_trade_log";
- private static final String PWP_TRADE_LOG = "pwp_trade_log";
- private static final String MODEL_ALLOCATIONS_PREVIOUS = "model_allocations_previous";
- private static final String MODEL_ALLOCATIONS_CURRENT = "model_allocations_current";
- private static final String MODEL_OBJECTIVE = "model_objective";
- private static final String MODELS = "models";
- private static final String ASSETS = "assets";
- private static final String ASSET_CLASSES = "asset_classes";
- private static final String INDICES = "indices";
- private static final String MODEL_TYPE = "model_type";
- private static final String MANAGER_GUIDE_COVER = "manager_guide_cover";
- private static final String MODEL_TACTICAL_FOCUS = "model_tactical_focus";
- private static final String DISCLOSURE = "disclosure";
- private static final String DISCLOSURE_TYPE = "disclosure_type";
- private static final String MANAGER_RISK_CLASSIFICATION = "manager_risk_classification";
- private static final String PLATFORMS = "platforms";
- private static final String MANAGER_TYPE = "manager_type";
- private static final String POLICY = "policy";
- private static final String INSURANCE_COMPANY = "insurance_company";
- private static final String ASSET_TYPE = "asset_type";
- private static final String ASSET_TIER = "asset_tier";
- private static final Set<String> TABLE_LOAD_ORDER = new LinkedHashSet<String>() {
- private static final long serialVersionUID = 1L;
- {
- add(ASSET_TIER);
- add(ASSET_TYPE);
- add(INSURANCE_COMPANY);
- add(POLICY);
- add(MANAGER_TYPE);
- add(PLATFORMS);
- add(MANAGER_RISK_CLASSIFICATION);
- add(DISCLOSURE_TYPE);
- add(DISCLOSURE);
- add(MODEL_TACTICAL_FOCUS);
- add(MANAGER_GUIDE_COVER);
- add(MODEL_TYPE);
- add(INDICES);
- add(ASSET_CLASSES);
- add(ASSETS);
- add(MODELS);
- add(MODEL_OBJECTIVE);
- add(MODEL_ALLOCATIONS_CURRENT);
- add(MODEL_ALLOCATIONS_PREVIOUS);
- add(PWP_TRADE_LOG);
- add(ETP_TRADE_LOG);
- add(MWP_TRADE_LOG);
- add(SAM_MF_TRADE_LOG);
- add(OMP_TRADE_LOG);
- add(EQUIVEST_TRADE_LOG);
- add(FBVA_TRADE_LOG);
- add(OTHER_TABLES);
- }
- };
- public void processWorkbook(Workbook workbook) throws SQLException {
- int sheetCount = workbook.getNumberOfSheets();
- for (int i = 0; i < sheetCount; i++) {
- Sheet sheet = workbook.getSheetAt(i);
- String sheetName = sheet.getSheetName();
- if (ASSET_TIER.equalsIgnoreCase(sheetName)) {
- tables.put(ASSET_TIER, processAssetTier(sheet));
- } else if (ASSET_TYPE.equalsIgnoreCase(sheetName)) {
- tables.put(ASSET_TYPE, processAssetType(sheet));
- } else if (INSURANCE_COMPANY.equalsIgnoreCase(sheetName)) {
- tables.put(INSURANCE_COMPANY, processInsuranceCompany(sheet));
- } else if (MANAGER_TYPE.equalsIgnoreCase(sheetName)) {
- tables.put(MANAGER_TYPE, processManagerType(sheet));
- } else if (POLICY.equalsIgnoreCase(sheetName)) {
- tables.put(POLICY, processPolicy(sheet));
- } else if (PLATFORMS.equalsIgnoreCase(sheetName)) {
- tables.put(PLATFORMS, processPlatform(sheet));
- } else if (MANAGER_RISK_CLASSIFICATION.equalsIgnoreCase(sheetName)) {
- tables.put(MANAGER_RISK_CLASSIFICATION, processManagerRiskClassification(sheet));
- } else if (MODEL_TACTICAL_FOCUS.equalsIgnoreCase(sheetName)) {
- tables.put(MODEL_TACTICAL_FOCUS, processModelTacticalFocus(sheet));
- } else if (DISCLOSURE.equalsIgnoreCase(sheetName)) {
- tables.put(DISCLOSURE_TYPE, processDisclosureType(sheet));
- tables.put(DISCLOSURE, processDisclosure(sheet));
- } else if (MANAGER_GUIDE_COVER.equalsIgnoreCase(sheetName)) {
- tables.put(MANAGER_GUIDE_COVER, processManagerGuideCover(sheet));
- } else if (MODEL_TYPE.equalsIgnoreCase(sheetName)) {
- tables.put(MODEL_TYPE, processModelType(sheet));
- } else if (INDICES.equalsIgnoreCase(sheetName)) {
- tables.put(INDICES, processIndices(sheet));
- } else if (ASSET_CLASSES.equalsIgnoreCase(sheetName)) {
- tables.put(ASSET_CLASSES, processAssetClasses(sheet));
- } else if (ASSETS.equalsIgnoreCase(sheetName)) {
- tables.put(ASSETS, processAssets(sheet));
- } else if (MODELS.equalsIgnoreCase(sheetName)) {
- tables.put(MODELS, processModels(sheet));
- } else if (MODEL_OBJECTIVE.equalsIgnoreCase(sheetName)) {
- tables.put(MODEL_OBJECTIVE, processModelObjective(sheet));
- } else if (MODEL_ALLOCATIONS_CURRENT.equalsIgnoreCase(sheetName)) {
- tables.put(MODEL_ALLOCATIONS_CURRENT, processModelAllocationsCurrent(sheet));
- } else if (MODEL_ALLOCATIONS_PREVIOUS.equalsIgnoreCase(sheetName)) {
- tables.put(MODEL_ALLOCATIONS_PREVIOUS, processModelAllocationsPrevious(sheet));
- }
- }
- tables.put(OTHER_TABLES, deleteAssetIdTemp());
- }
- public void processTradeLogsWorkbook(Workbook workbook) throws SQLException {
- int sheetCount = workbook.getNumberOfSheets();
- for (int i = 0; i < sheetCount; i++) {
- Sheet sheet = workbook.getSheetAt(i);
- String sheetName = sheet.getSheetName();
- if (PWP_TRADE_LOG.equalsIgnoreCase(sheetName)) {
- tables.put(PWP_TRADE_LOG, processPWPTradeLog(sheet));
- } else if (ETP_TRADE_LOG.equalsIgnoreCase(sheetName)) {
- tables.put(ETP_TRADE_LOG, processETPTradeLog(sheet));
- } else if (MWP_TRADE_LOG.equalsIgnoreCase(sheetName)) {
- tables.put(MWP_TRADE_LOG, processMWPTradeLog(sheet));
- } else if (SAM_MF_TRADE_LOG.equalsIgnoreCase(sheetName)) {
- tables.put(SAM_MF_TRADE_LOG, processSAMTradeLog(sheet));
- } else if (OMP_TRADE_LOG.equalsIgnoreCase(sheetName)) {
- tables.put(OMP_TRADE_LOG, processOMPTradeLog(sheet));
- } else if (EQUIVEST_TRADE_LOG.equalsIgnoreCase(sheetName)) {
- tables.put(EQUIVEST_TRADE_LOG, processEquivestTradeLog(sheet));
- } else if (FBVA_TRADE_LOG.equalsIgnoreCase(sheetName)) {
- tables.put(FBVA_TRADE_LOG, processFBVATradeLog(sheet));
- }
- }
- }
- private StringBuffer processFBVATradeLog(Sheet sheet) throws SQLException {
- StringBuffer result = new StringBuffer();
- result
- .append("DROP TABLE IF EXISTS `trade_log_id_temp`; \n CREATE TABLE `trade_log_id_temp` (`trade_log_id` INT(10)) ENGINE=InnoDB DEFAULT CHARSET=utf8; \n insert into trade_log_id_temp (trade_log_id) select distinct tl.trade_log_id from trade_log as tl join strategy as s on s.strategy_id=tl.strategy_id join model_objective as mo on tl.model_objective_id=mo.model_objective_id join model as m on m.model_id=tl.model_id join trade_log_assets as tla on tla.trade_log_id=tl.trade_log_id join asset as a1 on a1.asset_id=tla.asset_id_previous join asset as a2 on a2.asset_id=tla.asset_id_current join data_group as dg1 on dg1.data_group_id=m.data_group_id join data_group as dg2 on dg2.data_group_id=s.platform_id join model_direction as md on md.model_direction_id=m.model_direction_id join model_product as mp on mp.model_product_id=m.model_product_id join insurance_policy as ip on ip.policy_id=m.policy_id join insurance_company as ic on ip.insurance_company_id=ic.insurance_company_id where (dg1.abbreviation='SAM'and dg2.abbreviation='SAM' OR dg1.abbreviation='SWM'and dg2.abbreviation='SWM') and mp.model_product_code='VA' order by dg1.abbreviation,ic.insurance_company_name, ip.insurance_policy_name,md.model_direction_name; \n delete from trade_log where trade_log_id in (select * from trade_log_id_temp); \n");
- String lastUpdatedDate;
- String lastTradeDate;
- String modelObjectiveCode;
- String modelObjectiveId;
- Row dateRow = sheet.getRow(0);
- String asOfDate = dateRow!=null?prepareCellData(dateRow.getCell(3)):null;
- int objectivesCount = Integer
- .parseInt(getIdByName("select count(`model_objective_id`) as `id` from `model_objective`"));
- int offset = 0;
- for (int i = 0; i < objectivesCount; i++) {
- int startRow = 0;
- Row row = sheet.getRow(startRow);
- while (startRow <= sheet.getLastRowNum()) {
- if (!isRowNullable(row)
- && ((lastTradeDate = prepareCellData(row.getCell(0))) != null || (prepareCellData(row.getCell(1 + offset))) != null
- && prepareCellData(row.getCell(2 + offset)) == null
- && !prepareCellData(row.getCell(1 + offset)).equalsIgnoreCase("'As of Date'"))) {
- lastUpdatedDate = prepareCellData(sheet.getRow(startRow - 1).getCell(0));
- modelObjectiveCode = prepareCellData(sheet.getRow(startRow - 1).getCell(1 + offset));
- modelObjectiveId = getIdByName("select `model_objective_id` as `id` from `model_objective` where `model_objective_code` = "
- + modelObjectiveCode);
- startRow++;
- row = sheet.getRow(startRow);
- String firstCol = null;
- if (isRowNullable(row) || (firstCol = prepareCellData(row.getCell(0))) == null) {
- row = sheet.getRow(startRow++);
- continue;
- }
- if (firstCol != null && firstCol.startsWith("'") && firstCol.endsWith("'")) {
- firstCol = firstCol.substring(1, firstCol.length() - 1);
- }
- String dataGroupName = firstCol.split(":")[0].trim();
- String insurancePolicyName = firstCol.split(":")[2].trim();
- String modelDirectionName = firstCol.split(":")[3].trim();
- String dataGroupId = getIdByName("select `data_group_id` as `id` from `data_group` where `abbreviation` = '"
- + dataGroupName + "'");
- String insurancePolicyId = getIdByName("select `policy_id` as `id` from `insurance_policy` "
- + " where `insurance_policy_name` = '" + insurancePolicyName + "'");
- String modelDirectionId = "'"
- + getIdByName("select `model_direction_id` as `id` from `model_direction` where `model_direction_name` = '"
- + modelDirectionName + "'") + "'";
- String strategyId = getIdByName("select `strategy_id` as `id` from `model` "
- + "join model_product as mp on mp.`model_product_id`=`model`.model_product_id where `model_objective_id`="
- + modelObjectiveId + " AND `data_group_id`=" + dataGroupId + " AND `model`.`model_direction_id`="
- + modelDirectionId + " AND mp.model_product_code='VA' " + " AND `policy_id`=" + insurancePolicyId);
- if (strategyId == null) {
- row = sheet.getRow(startRow++);
- continue;
- }
- String modelId = getIdByName("select `model_id` as `id` from `model` "
- + "join model_product as mp on mp.`model_product_id`=`model`.model_product_id where `model_objective_id`="
- + modelObjectiveId + " AND `data_group_id`=" + dataGroupId + " AND `model`.`model_direction_id`="
- + modelDirectionId + " AND mp.model_product_code='VA' " + " AND `policy_id`=" + insurancePolicyId);
- String tradeLogId = "(select `trade_log_id` as `id` from `trade_log` where `model_id`=" + modelId
- + " AND `model_objective_id`=" + modelObjectiveId + " AND `strategy_id`=" + strategyId + " LIMIT 1)";
- if (modelId != null) {
- result.append("INSERT INTO `trade_log` (`model_id`, `model_objective_id`, `strategy_id`, "
- + " `as_of_date`, `last_updated`, `last_trade_date`) VALUES (" + modelId + ", " + modelObjectiveId
- + ", " + strategyId + "," + asOfDate + ", " + lastUpdatedDate + ", " + lastTradeDate + ") "
- + "ON DUPLICATE KEY UPDATE `as_of_date`=" + asOfDate + ", `last_updated`=" + lastUpdatedDate
- + ", `last_trade_date`=" + lastTradeDate + "; \n");
- for (; startRow <= sheet.getLastRowNum(); startRow++) {
- row = sheet.getRow(startRow);
- if (!isRowNullable(row)) {
- result.append(processTradeLogGroup(tradeLogId, prepareCellData(row.getCell(1 + offset)),
- prepareCellData(row.getCell(2 + offset)), prepareCellData(row.getCell(3 + offset)),
- prepareCellData(row.getCell(4 + offset))));
- } else {
- break;
- }
- }
- }
- }
- row = sheet.getRow(startRow++);
- }
- offset += 5;
- }
- return result;
- }
- private StringBuffer processEquivestTradeLog(Sheet sheet) throws SQLException {
- StringBuffer result = new StringBuffer();
- result
- .append("DROP TABLE IF EXISTS `trade_log_id_temp`; \n CREATE TABLE `trade_log_id_temp` (`trade_log_id` INT(10)) ENGINE=InnoDB DEFAULT CHARSET=utf8; \n insert into trade_log_id_temp (trade_log_id) select distinct tl.trade_log_id from trade_log as tl join strategy as s on s.strategy_id=tl.strategy_id join model_objective as mo on tl.model_objective_id=mo.model_objective_id join model as m on m.model_id=tl.model_id join trade_log_assets as tla on tla.trade_log_id=tl.trade_log_id join asset as a1 on a1.asset_id=tla.asset_id_previous join asset as a2 on a2.asset_id=tla.asset_id_current join data_group as dg1 on dg1.data_group_id=m.data_group_id join data_group as dg2 on dg2.data_group_id=s.platform_id join model_direction as md on md.model_direction_id=m.model_direction_id join model_product as mp on mp.model_product_id=m.model_product_id join annuity_type as ant on ant.annuity_type_id=m.annuity_type_id where dg1.abbreviation='SAM'and dg2.abbreviation='SAM' and mp.model_product_code='VA' order by dg1.abbreviation,ant.annuity_type_name,mp.model_product_name; \n delete from trade_log where trade_log_id in (select * from trade_log_id_temp); \n");
- String lastUpdatedDate;
- String lastTradeDate;
- String modelObjectiveCode;
- String modelObjectiveId;
- String dataGroupId = getIdByName("select `data_group_id` as `id` from `data_group` where `abbreviation` = 'SAM'");
- Row dateRow = sheet.getRow(0);
- String asOfDate = dateRow!=null?prepareCellData(dateRow.getCell(3)):null;
- int objectivesCount = Integer
- .parseInt(getIdByName("select count(`model_objective_id`) as `id` from `model_objective`"));
- int offset = 0;
- for (int i = 0; i < objectivesCount; i++) {
- int startRow = 0;
- Row row = sheet.getRow(startRow);
- while (startRow <= sheet.getLastRowNum()) {
- if (!isRowNullable(row)
- && ((lastTradeDate = prepareCellData(row.getCell(0))) != null || (prepareCellData(row.getCell(1 + offset))) != null
- && prepareCellData(row.getCell(2 + offset)) == null
- && !prepareCellData(row.getCell(1 + offset)).equalsIgnoreCase("'As of Date'"))) {
- lastUpdatedDate = prepareCellData(sheet.getRow(startRow - 1).getCell(0));
- modelObjectiveCode = prepareCellData(sheet.getRow(startRow - 1).getCell(1 + offset));
- modelObjectiveId = getIdByName("select `model_objective_id` as `id` from `model_objective` where `model_objective_code` = "
- + modelObjectiveCode);
- startRow++;
- row = sheet.getRow(startRow);
- String firstCol = null;
- if (isRowNullable(row) || (firstCol = prepareCellData(row.getCell(0))) == null) {
- row = sheet.getRow(startRow++);
- continue;
- }
- if (firstCol != null && firstCol.startsWith("'") && firstCol.endsWith("'")) {
- firstCol = firstCol.substring(1, firstCol.length() - 1);
- }
- String annuityTypeName = firstCol.split(":")[1].trim();
- String modelProducName = firstCol.split(":")[2].trim();
- String annuityTypeId = getIdByName("select `annuity_type_id` as `id` from `annuity_type` "
- + " where `annuity_type_name` = '" + annuityTypeName + "'");
- String modelProductId = "'"
- + getIdByName("select `model_product_id` as `id` from `model_product` where `model_product_name` = '"
- + modelProducName + "'") + "'";
- String strategyId = getIdByName("select `strategy_id` as `id` from `model` "
- + "join model_product as mp on mp.`model_product_id`=`model`.model_product_id where `model_objective_id`="
- + modelObjectiveId + " AND `data_group_id`=" + dataGroupId + " AND `model`.`model_product_id`="
- + modelProductId + " AND mp.model_product_code='VA' AND annuity_type_id=" + annuityTypeId);
- if (strategyId == null) {
- row = sheet.getRow(startRow++);
- continue;
- }
- String modelId = getIdByName("select `model_id` as `id` from `model` "
- + "join model_product as mp on mp.`model_product_id`=`model`.model_product_id where `model_objective_id`="
- + modelObjectiveId + " AND `data_group_id`=" + dataGroupId + " AND `model`.`model_product_id`="
- + modelProductId + " AND mp.model_product_code='VA' AND annuity_type_id=" + annuityTypeId);
- String tradeLogId = "(select `trade_log_id` as `id` from `trade_log` where `model_id`=" + modelId
- + " AND `model_objective_id`=" + modelObjectiveId + " AND `strategy_id`=" + strategyId + " LIMIT 1)";
- if (modelId != null) {
- result.append("INSERT INTO `trade_log` (`model_id`, `model_objective_id`, `strategy_id`, "
- + " `as_of_date`, `last_updated`, `last_trade_date`) VALUES (" + modelId + ", " + modelObjectiveId
- + ", " + strategyId + "," + asOfDate + ", " + lastUpdatedDate + ", " + lastTradeDate + ") "
- + "ON DUPLICATE KEY UPDATE `as_of_date`=" + asOfDate + ", `last_updated`=" + lastUpdatedDate
- + ", `last_trade_date`=" + lastTradeDate + "; \n");
- for (; startRow <= sheet.getLastRowNum(); startRow++) {
- row = sheet.getRow(startRow);
- if (!isRowNullable(row)) {
- result.append(processTradeLogGroup(tradeLogId, prepareCellData(row.getCell(1 + offset)),
- prepareCellData(row.getCell(2 + offset)), prepareCellData(row.getCell(3 + offset)),
- prepareCellData(row.getCell(4 + offset))));
- } else {
- break;
- }
- }
- }
- }
- row = sheet.getRow(startRow++);
- }
- offset += 5;
- }
- return result;
- }
- private StringBuffer processOMPTradeLog(Sheet sheet) throws SQLException {
- StringBuffer result = new StringBuffer();
- result
- .append("DROP TABLE IF EXISTS `trade_log_id_temp`; \n CREATE TABLE `trade_log_id_temp` (`trade_log_id` INT(10)) ENGINE=InnoDB DEFAULT CHARSET=utf8; \n insert into trade_log_id_temp (trade_log_id) select distinct tl.trade_log_id from trade_log as tl join strategy as s on s.strategy_id=tl.strategy_id join model_objective as mo on tl.model_objective_id=mo.model_objective_id join model as m on m.model_id=tl.model_id join trade_log_assets as tla on tla.trade_log_id=tl.trade_log_id join asset as a1 on a1.asset_id=tla.asset_id_previous join asset as a2 on a2.asset_id=tla.asset_id_current join data_group as dg1 on dg1.data_group_id=m.data_group_id join data_group as dg2 on dg2.data_group_id=s.platform_id join model_direction as md on md.model_direction_id=m.model_direction_id join model_product as mp on mp.model_product_id=m.model_product_id where dg1.abbreviation='OMP'and dg2.abbreviation='OMP' and mp.model_product_code='MF' order by s.name,md.model_direction_name; \n delete from trade_log where trade_log_id in (select * from trade_log_id_temp); \n");
- String lastUpdatedDate;
- String lastTradeDate;
- String modelObjectiveCode;
- String modelObjectiveId;
- String dataGroupId = getIdByName("select `data_group_id` as `id` from `data_group` where `abbreviation` = 'OMP'");
- Row dateRow = sheet.getRow(0);
- String asOfDate = dateRow!=null?prepareCellData(dateRow.getCell(3)):null;
- int objectivesCount = Integer
- .parseInt(getIdByName("select count(`model_objective_id`) as `id` from `model_objective`"));
- int offset = 0;
- for (int i = 0; i < objectivesCount; i++) {
- int startRow = 0;
- Row row = sheet.getRow(startRow);
- while (startRow <= sheet.getLastRowNum()) {
- if (!isRowNullable(row) && (lastTradeDate = prepareCellData(row.getCell(0))) != null) {
- lastUpdatedDate = prepareCellData(sheet.getRow(startRow - 1).getCell(0));
- modelObjectiveCode = prepareCellData(sheet.getRow(startRow - 1).getCell(1 + offset));
- modelObjectiveId = getIdByName("select `model_objective_id` as `id` from `model_objective` where `model_objective_code` = "
- + modelObjectiveCode);
- startRow++;
- row = sheet.getRow(startRow);
- String firstCol = null;
- if (isRowNullable(row) || (firstCol = prepareCellData(row.getCell(0))) == null) {
- row = sheet.getRow(startRow++);
- continue;
- }
- if (firstCol != null && firstCol.startsWith("'") && firstCol.endsWith("'")) {
- firstCol = firstCol.substring(1, firstCol.length() - 1);
- }
- String strategyName = firstCol.split(":")[0].trim();
- String modelDirectionName = firstCol.split(":")[1].trim();
- String strategyId = getIdByName("select `strategy_id` as `id` from `strategy` "
- + "join data_group as dg1 on dg1.data_group_id=`strategy`.platform_id where `strategy`.`name` = '"
- + strategyName + "' AND dg1.abbreviation='OMP'");
- if (strategyId == null) {
- Set<String> tableProblems = problems.get(sheet.getSheetName().toLowerCase());
- if (tableProblems == null) {
- tableProblems = new HashSet<String>();
- problems.put(sheet.getSheetName().toLowerCase(), tableProblems);
- }
- tableProblems.add("Can't find strategy:" + strategyName + " in DB");
- row = sheet.getRow(startRow++);
- continue;
- }
- String modelDirectionId = "'"
- + getIdByName("select `model_direction_id` as `id` from `model_direction` where `model_direction_name` = '"
- + modelDirectionName + "'") + "'";
- String modelId = getIdByName("select `model_id` as `id` from `model` "
- + "join model_product as mp on mp.`model_product_id`=`model`.model_product_id where `strategy_id` = "
- + strategyId + " AND `model_objective_id`=" + modelObjectiveId + " AND `data_group_id`=" + dataGroupId
- + " AND `model_direction_id`=" + modelDirectionId + " AND mp.model_product_code='MF'");
- String tradeLogId = "(select `trade_log_id` as `id` from `trade_log` where `model_id`=" + modelId
- + " AND `model_objective_id`=" + modelObjectiveId + " AND `strategy_id`=" + strategyId + " LIMIT 1)";
- if (modelId != null) {
- result.append("INSERT INTO `trade_log` (`model_id`, `model_objective_id`, `strategy_id`, "
- + " `as_of_date`, `last_updated`, `last_trade_date`) VALUES (" + modelId + ", " + modelObjectiveId
- + ", " + strategyId + "," + asOfDate + ", " + lastUpdatedDate + ", " + lastTradeDate + ") "
- + "ON DUPLICATE KEY UPDATE `as_of_date`=" + asOfDate + ", `last_updated`=" + lastUpdatedDate
- + ", `last_trade_date`=" + lastTradeDate + "; \n");
- for (; startRow <= sheet.getLastRowNum(); startRow++) {
- row = sheet.getRow(startRow);
- if (!isRowNullable(row)) {
- result.append(processTradeLogGroup(tradeLogId, prepareCellData(row.getCell(1 + offset)),
- prepareCellData(row.getCell(2 + offset)), prepareCellData(row.getCell(3 + offset)),
- prepareCellData(row.getCell(4 + offset))));
- } else {
- break;
- }
- }
- }
- }
- row = sheet.getRow(startRow++);
- }
- offset += 5;
- }
- return result;
- }
- private StringBuffer processSAMTradeLog(Sheet sheet) throws SQLException {
- StringBuffer result = new StringBuffer();
- result
- .append("DROP TABLE IF EXISTS `trade_log_id_temp`; \n CREATE TABLE `trade_log_id_temp` (`trade_log_id` INT(10)) ENGINE=InnoDB DEFAULT CHARSET=utf8; \n insert into trade_log_id_temp (trade_log_id) select distinct tl.trade_log_id from trade_log as tl join strategy as s on s.strategy_id=tl.strategy_id join model_objective as mo on tl.model_objective_id=mo.model_objective_id join model as m on m.model_id=tl.model_id join trade_log_assets as tla on tla.trade_log_id=tl.trade_log_id join asset as a1 on a1.asset_id=tla.asset_id_previous join asset as a2 on a2.asset_id=tla.asset_id_current join data_group as dg1 on dg1.data_group_id=m.data_group_id join data_group as dg2 on dg2.data_group_id=s.platform_id join model_direction as md on md.model_direction_id=m.model_direction_id join model_product as mp on mp.model_product_id=m.model_product_id where dg1.abbreviation='SAM'and dg2.abbreviation='SAM' and mp.model_product_code='MF' order by s.name,md.model_direction_name; \n delete from trade_log where trade_log_id in (select * from trade_log_id_temp); \n");
- String lastUpdatedDate;
- String lastTradeDate;
- String modelObjectiveCode;
- String modelObjectiveId;
- String dataGroupId = getIdByName("select `data_group_id` as `id` from `data_group` where `abbreviation` = 'SAM'");
- Row dateRow = sheet.getRow(0);
- String asOfDate = dateRow!=null?prepareCellData(dateRow.getCell(3)):null;
- int objectivesCount = Integer
- .parseInt(getIdByName("select count(`model_objective_id`) as `id` from `model_objective`"));
- int offset = 0;
- for (int i = 0; i < objectivesCount; i++) {
- int startRow = 0;
- Row row = sheet.getRow(startRow);
- while (startRow <= sheet.getLastRowNum()) {
- if (!isRowNullable(row) && (lastTradeDate = prepareCellData(row.getCell(0))) != null) {
- lastUpdatedDate = prepareCellData(sheet.getRow(startRow - 1).getCell(0));
- modelObjectiveCode = prepareCellData(sheet.getRow(startRow - 1).getCell(1 + offset));
- modelObjectiveId = getIdByName("select `model_objective_id` as `id` from `model_objective` where `model_objective_code` = "
- + modelObjectiveCode);
- startRow++;
- row = sheet.getRow(startRow);
- if (isRowNullable(row)) {
- row = sheet.getRow(startRow++);
- continue;
- }
- String firstCol = getFirstCol(sheet, startRow, row);
- String strategyName = firstCol.split(":")[0].trim();
- String modelDirectionName = firstCol.split(":")[1].trim();
- String strategyId = getIdByName("select `strategy_id` as `id` from `strategy` "
- + "join data_group as dg1 on dg1.data_group_id=`strategy`.platform_id where `strategy`.`name` = '"
- + strategyName + "' AND dg1.abbreviation='SAM'");
- if (strategyId == null) {
- Set<String> tableProblems = problems.get(sheet.getSheetName().toLowerCase());
- if (tableProblems == null) {
- tableProblems = new HashSet<String>();
- problems.put(sheet.getSheetName().toLowerCase(), tableProblems);
- }
- tableProblems.add("Can't find strategy:" + strategyName + " in DB");
- row = sheet.getRow(startRow++);
- continue;
- }
- String modelDirectionId = "'"
- + getIdByName("select `model_direction_id` as `id` from `model_direction` where `model_direction_name` = '"
- + modelDirectionName + "'") + "'";
- String modelId = getIdByName("select `model_id` as `id` from `model` "
- + "join model_product as mp on mp.`model_product_id`=`model`.model_product_id where `strategy_id` = "
- + strategyId + " AND `model_objective_id`=" + modelObjectiveId + " AND `data_group_id`=" + dataGroupId
- + " AND `model_direction_id`=" + modelDirectionId + " AND mp.model_product_code='MF'");
- String tradeLogId = "(select `trade_log_id` as `id` from `trade_log` where `model_id`=" + modelId
- + " AND `model_objective_id`=" + modelObjectiveId + " AND `strategy_id`=" + strategyId + " LIMIT 1)";
- if (modelId != null) {
- result.append("INSERT INTO `trade_log` (`model_id`, `model_objective_id`, `strategy_id`, "
- + " `as_of_date`, `last_updated`, `last_trade_date`) VALUES (" + modelId + ", " + modelObjectiveId
- + ", " + strategyId + "," + asOfDate + ", " + lastUpdatedDate + ", " + lastTradeDate + ") "
- + "ON DUPLICATE KEY UPDATE `as_of_date`=" + asOfDate + ", `last_updated`=" + lastUpdatedDate
- + ", `last_trade_date`=" + lastTradeDate + "; \n");
- for (; startRow <= sheet.getLastRowNum(); startRow++) {
- row = sheet.getRow(startRow);
- if (!isRowNullable(row)) {
- result.append(processTradeLogGroup(tradeLogId, prepareCellData(row.getCell(1 + offset)),
- prepareCellData(row.getCell(2 + offset)), prepareCellData(row.getCell(3 + offset)),
- prepareCellData(row.getCell(4 + offset))));
- } else {
- break;
- }
- }
- }
- }
- row = sheet.getRow(startRow++);
- }
- offset += 5;
- }
- return result;
- }
- private String getFirstCol(Sheet sheet, int startRow, Row row) {
- String firstCol = prepareCellData(row.getCell(0));
- int goback = 2;
- while (firstCol == null && (startRow - goback) >= 0) {
- firstCol = prepareCellData(sheet.getRow(startRow - goback).getCell(0));
- goback++;
- }
- if (firstCol != null && firstCol.startsWith("'") && firstCol.endsWith("'")) {
- firstCol = firstCol.substring(1, firstCol.length() - 1);
- }
- return firstCol;
- }
- private StringBuffer processMWPTradeLog(Sheet sheet) throws SQLException {
- StringBuffer result = new StringBuffer();
- result
- .append("DROP TABLE IF EXISTS `trade_log_id_temp`; \n CREATE TABLE `trade_log_id_temp` (`trade_log_id` INT(10)) ENGINE=InnoDB DEFAULT CHARSET=utf8; \n insert into trade_log_id_temp (trade_log_id) select distinct tl.trade_log_id from trade_log as tl join strategy as s on s.strategy_id=tl.strategy_id join model_objective as mo on tl.model_objective_id=mo.model_objective_id join model as m on m.model_id=tl.model_id join trade_log_assets as tla on tla.trade_log_id=tl.trade_log_id join asset as a1 on a1.asset_id=tla.asset_id_previous join asset as a2 on a2.asset_id=tla.asset_id_current join data_group as dg1 on dg1.data_group_id=m.data_group_id join data_group as dg2 on dg2.data_group_id=s.platform_id join model_direction as md on md.model_direction_id=m.model_direction_id join model_product as mp on mp.model_product_id=m.model_product_id where dg1.abbreviation='MWP'and dg2.abbreviation='MWP' and mp.model_product_code='MF' order by s.name,md.model_direction_name; \n delete from trade_log where trade_log_id in (select * from trade_log_id_temp); \n");
- String lastUpdatedDate;
- String lastTradeDate;
- String modelObjectiveCode;
- String modelObjectiveId;
- String dataGroupId = getIdByName("select `data_group_id` as `id` from `data_group` where `abbreviation` = 'MWP'");
- Row dateRow = sheet.getRow(0);
- String asOfDate = dateRow!=null?prepareCellData(dateRow.getCell(3)):null;
- int objectivesCount = Integer
- .parseInt(getIdByName("select count(`model_objective_id`) as `id` from `model_objective`"));
- int offset = 0;
- for (int i = 0; i < objectivesCount; i++) {
- int startRow = 0;
- Row row = sheet.getRow(startRow);
- while (startRow <= sheet.getLastRowNum()) {
- if (!isRowNullable(row)
- && ((lastTradeDate = prepareCellData(row.getCell(0))) != null || (prepareCellData(row.getCell(1 + offset))) != null
- && prepareCellData(row.getCell(2 + offset)) == null
- && !prepareCellData(row.getCell(1 + offset)).equalsIgnoreCase("'As of Date'"))) {
- lastUpdatedDate = prepareCellData(sheet.getRow(startRow - 1).getCell(0));
- modelObjectiveCode = prepareCellData(sheet.getRow(startRow - 1).getCell(1 + offset));
- modelObjectiveId = getIdByName("select `model_objective_id` as `id` from `model_objective` where `model_objective_code` = "
- + modelObjectiveCode);
- startRow++;
- row = sheet.getRow(startRow);
- if (isRowNullable(row)) {
- row = sheet.getRow(startRow++);
- continue;
- }
- String firstCol = getFirstCol(sheet, startRow, row);
- String strategyName = firstCol.split(":")[0].trim();
- String modelDirectionName = firstCol.split(":")[1].trim();
- String strategyId = getIdByName("select `strategy_id` as `id` from `strategy` "
- + "join data_group as dg1 on dg1.data_group_id=`strategy`.platform_id "
- + "join model_product as mp using(model_product_id) where `strategy`.`name` = '" + strategyName
- + "' AND dg1.abbreviation='MWP' AND mp.model_product_code='MF'");
- if (strategyId == null) {
- Set<String> tableProblems = problems.get(sheet.getSheetName().toLowerCase());
- if (tableProblems == null) {
- tableProblems = new HashSet<String>();
- problems.put(sheet.getSheetName().toLowerCase(), tableProblems);
- }
- tableProblems.add("Can't find strategy:" + strategyName + " in DB");
- row = sheet.getRow(startRow++);
- continue;
- }
- String modelDirectionId = "'"
- + getIdByName("select `model_direction_id` as `id` from `model_direction` where `model_direction_name` = '"
- + modelDirectionName + "'") + "'";
- String modelId = getIdByName("select `model_id` as `id` from `model` "
- + "join model_product as mp on mp.`model_product_id`=`model`.model_product_id where `strategy_id` = "
- + strategyId + " AND `model_objective_id`=" + modelObjectiveId + " AND `data_group_id`=" + dataGroupId
- + " AND `model_direction_id`=" + modelDirectionId + " AND mp.model_product_code='MF'");
- String tradeLogId = "(select `trade_log_id` as `id` from `trade_log` where `model_id`=" + modelId
- + " AND `model_objective_id`=" + modelObjectiveId + " AND `strategy_id`=" + strategyId + " LIMIT 1)";
- if (modelId != null) {
- result.append("INSERT INTO `trade_log` (`model_id`, `model_objective_id`, `strategy_id`, "
- + " `as_of_date`, `last_updated`, `last_trade_date`) VALUES (" + modelId + ", " + modelObjectiveId
- + ", " + strategyId + "," + asOfDate + ", " + lastUpdatedDate + ", " + lastTradeDate + ") "
- + "ON DUPLICATE KEY UPDATE `as_of_date`=" + asOfDate + ", `last_updated`=" + lastUpdatedDate
- + ", `last_trade_date`=" + lastTradeDate + "; \n");
- for (; startRow <= sheet.getLastRowNum(); startRow++) {
- row = sheet.getRow(startRow);
- if (!isRowNullable(row)) {
- result.append(processTradeLogGroup(tradeLogId, prepareCellData(row.getCell(1 + offset)),
- prepareCellData(row.getCell(2 + offset)), prepareCellData(row.getCell(3 + offset)),
- prepareCellData(row.getCell(4 + offset))));
- } else {
- break;
- }
- }
- }
- }
- row = sheet.getRow(startRow++);
- }
- offset += 5;
- }
- return result;
- }
- private StringBuffer processETPTradeLog(Sheet sheet) throws SQLException {
- StringBuffer result = new StringBuffer();
- result
- .append("DROP TABLE IF EXISTS `trade_log_id_temp`; \n CREATE TABLE `trade_log_id_temp` (`trade_log_id` INT(10)) ENGINE=InnoDB DEFAULT CHARSET=utf8; \n insert into trade_log_id_temp (trade_log_id) select distinct tl.trade_log_id from trade_log as tl join strategy as s on s.strategy_id=tl.strategy_id join model_objective as mo on tl.model_objective_id=mo.model_objective_id join model as m on m.model_id=tl.model_id join trade_log_assets as tla on tla.trade_log_id=tl.trade_log_id join asset as a1 on a1.asset_id=tla.asset_id_previous join asset as a2 on a2.asset_id=tla.asset_id_current join data_group as dg1 on dg1.data_group_id=m.data_group_id join data_group as dg2 on dg2.data_group_id=s.platform_id join model_direction as md on md.model_direction_id=m.model_direction_id join model_product as mp on mp.model_product_id=m.model_product_id where dg1.abbreviation='MWP'and dg2.abbreviation='MWP' and mp.model_product_code='ETP' order by s.name,md.model_direction_name; \n delete from trade_log where trade_log_id in (select * from trade_log_id_temp); \n");
- String lastUpdatedDate;
- String lastTradeDate;
- String modelObjectiveCode;
- String modelObjectiveId;
- String dataGroupId = getIdByName("select `data_group_id` as `id` from `data_group` where `abbreviation` = 'MWP'");
- Row dateRow = sheet.getRow(0);
- String asOfDate = dateRow!=null?prepareCellData(dateRow.getCell(3)):null;
- int objectivesCount = Integer
- .parseInt(getIdByName("select count(`model_objective_id`) as `id` from `model_objective`"));
- int offset = 0;
- for (int i = 0; i < objectivesCount; i++) {
- int startRow = 0;
- Row row = sheet.getRow(startRow);
- while (startRow <= sheet.getLastRowNum()) {
- if (!isRowNullable(row)
- && ((lastTradeDate = prepareCellData(row.getCell(0))) != null || (prepareCellData(row.getCell(1 + offset))) != null
- && prepareCellData(row.getCell(2 + offset)) == null
- && !prepareCellData(row.getCell(1 + offset)).equalsIgnoreCase("'As of Date'"))) {
- lastUpdatedDate = prepareCellData(sheet.getRow(startRow - 1).getCell(0));
- modelObjectiveCode = prepareCellData(sheet.getRow(startRow - 1).getCell(1 + offset));
- modelObjectiveId = getIdByName("select `model_objective_id` as `id` from `model_objective` where `model_objective_code` = "
- + modelObjectiveCode);
- startRow++;
- row = sheet.getRow(startRow);
- if (isRowNullable(row)) {
- row = sheet.getRow(startRow++);
- continue;
- }
- String firstCol = getFirstCol(sheet, startRow, row);
- String strategyName = firstCol.split(":")[0].trim();
- String modelDirectionName = firstCol.split(":")[1].trim();
- String strategyId = getIdByName("select `strategy_id` as `id` from `strategy` "
- + "join data_group as dg1 on dg1.data_group_id=`strategy`.platform_id where `strategy`.`name` = '"
- + strategyName + "' AND dg1.abbreviation='MWP'");
- if (strategyId == null) {
- Set<String> tableProblems = problems.get(sheet.getSheetName().toLowerCase());
- if (tableProblems == null) {
- tableProblems = new HashSet<String>();
- problems.put(sheet.getSheetName().toLowerCase(), tableProblems);
- }
- tableProblems.add("Can't find strategy:" + strategyName + " in DB");
- row = sheet.getRow(startRow++);
- continue;
- }
- String modelDirectionId = getIdByName("select `model_direction_id` as `id` from `model_direction` where `model_direction_name` = '"
- + modelDirectionName + "'");
- String modelId = getIdByName("select `model_id` as `id` from `model` "
- + "join model_product as mp on mp.`model_product_id`=`model`.model_product_id where `strategy_id` = "
- + strategyId + " AND `model_objective_id`=" + modelObjectiveId + " AND `data_group_id`=" + dataGroupId
- + " AND `model_direction_id`=" + modelDirectionId + " AND mp.model_product_code='ETP'");
- String tradeLogId = "(select `trade_log_id` as `id` from `trade_log` where `model_id`=" + modelId
- + " AND `model_objective_id`=" + modelObjectiveId + " AND `strategy_id`=" + strategyId + " LIMIT 1)";
- if (modelId != null) {
- result.append("INSERT INTO `trade_log` (`model_id`, `model_objective_id`, `strategy_id`, "
- + " `as_of_date`, `last_updated`, `last_trade_date`) VALUES (" + modelId + ", " + modelObjectiveId
- + ", " + strategyId + "," + asOfDate + ", " + lastUpdatedDate + ", " + lastTradeDate
- + ") ON DUPLICATE KEY UPDATE `as_of_date`=" + asOfDate + ", `last_updated`=" + lastUpdatedDate
- + ", `last_trade_date`=" + lastTradeDate + "; \n");
- for (; startRow <= sheet.getLastRowNum(); startRow++) {
- row = sheet.getRow(startRow);
- if (!isRowNullable(row)) {
- result.append(processTradeLogGroup(tradeLogId, prepareCellData(row.getCell(1 + offset)),
- prepareCellData(row.getCell(2 + offset)), prepareCellData(row.getCell(3 + offset)),
- prepareCellData(row.getCell(4 + offset))));
- } else {
- break;
- }
- }
- }
- }
- row = sheet.getRow(startRow++);
- }
- offset += 5;
- }
- return result;
- }
- private StringBuffer processPWPTradeLog(Sheet sheet) throws SQLException {
- StringBuffer result = new StringBuffer();
- result
- .append("DROP TABLE IF EXISTS `trade_log_id_temp`; \n CREATE TABLE `trade_log_id_temp` (`trade_log_id` INT(10)) ENGINE=InnoDB DEFAULT CHARSET=utf8; \n insert into trade_log_id_temp (trade_log_id) select distinct tl.trade_log_id from trade_log as tl join strategy as s on s.strategy_id=tl.strategy_id join model_objective as mo on tl.model_objective_id=mo.model_objective_id join model as m on m.model_id=tl.model_id join trade_log_assets as tla on tla.trade_log_id=tl.trade_log_id join asset as a1 on a1.asset_id=tla.asset_id_previous join asset as a2 on a2.asset_id=tla.asset_id_current join tactical_focus as tf on tf.tactical_focus_id=tl.tactical_focus_id join data_group as dg1 on dg1.data_group_id=m.data_group_id join data_group as dg2 on dg2.data_group_id=s.platform_id where dg1.abbreviation='PWP'and dg2.abbreviation='PWP' order by s.name, tf.tactical_focus_name; \n delete from trade_log where trade_log_id in (select * from trade_log_id_temp); \n");
- String lastUpdatedDate;
- String lastTradeDate;
- String modelObjectiveCode;
- String modelObjectiveId;
- String dataGroupId = getIdByName("select `data_group_id` as `id` from `data_group` where `abbreviation` = 'PWP'");
- Row dateRow = sheet.getRow(0);
- String asOfDate = dateRow!=null?prepareCellData(dateRow.getCell(3)):null;
- int objectivesCount = Integer
- .parseInt(getIdByName("select count(`model_objective_id`) as `id` from `model_objective`"));
- int offset = 0;
- for (int i = 0; i < objectivesCount; i++) {
- int startRow = 0;
- Row row = sheet.getRow(startRow);
- while (startRow <= sheet.getLastRowNum()) {
- if (!isRowNullable(row)
- && ((lastTradeDate = prepareCellData(row.getCell(0))) != null || (prepareCellData(row.getCell(1 + offset))) != null
- && prepareCellData(row.getCell(2 + offset)) == null
- && !prepareCellData(row.getCell(1 + offset)).equalsIgnoreCase("'As of Date'"))) {
- lastUpdatedDate = prepareCellData(sheet.getRow(startRow - 1).getCell(0));
- modelObjectiveCode = prepareCellData(sheet.getRow(startRow - 1).getCell(1 + offset));
- modelObjectiveId = getIdByName("select `model_objective_id` as `id` from `model_objective` where `model_objective_code` = "
- + modelObjectiveCode);
- startRow++;
- row = sheet.getRow(startRow);
- if (isRowNullable(row)) {
- row = sheet.getRow(startRow++);
- continue;
- }
- String firstCol = getFirstCol(sheet, startRow, row);
- String strategyName = firstCol.split(":")[0].trim();
- String tacticalFocusName = firstCol.split(":")[1].trim();
- String strategyId = getIdByName("select `strategy_id` as `id` from `strategy` "
- + "join data_group as dg1 on dg1.data_group_id=`strategy`.platform_id where `strategy`.`name` = '"
- + strategyName + "' AND dg1.abbreviation='PWP'");
- if (strategyId == null) {
- Set<String> tableProblems = problems.get(sheet.getSheetName().toLowerCase());
- if (tableProblems == null) {
- tableProblems = new HashSet<String>();
- problems.put(sheet.getSheetName().toLowerCase(), tableProblems);
- }
- tableProblems.add("Can't find strategy:" + strategyName + " in DB");
- row = sheet.getRow(startRow++);
- continue;
- }
- String tacticalFocusId = "'"
- + getIdByName("select `tactical_focus_id` as `id` from `tactical_focus` where `tactical_focus_name` = '"
- + tacticalFocusName + "'") + "'";
- String modelId = getIdByName("select `model_id` as `id` from `model` where `strategy_id` = " + strategyId
- + " AND `model_objective_id`=" + modelObjectiveId + " AND `data_group_id`=" + dataGroupId);
- String tradeLogId = "(select `trade_log_id` as `id` from `trade_log` where `model_id`=" + modelId
- + " AND `model_objective_id`=" + modelObjectiveId + " AND `strategy_id`=" + strategyId
- + " AND `tactical_focus_id`=" + tacticalFocusId + " LIMIT 1)";
- if (modelId != null) {
- result.append("INSERT INTO `trade_log` (`model_id`, `model_objective_id`, `strategy_id`, "
- + "`tactical_focus_id`, `as_of_date`, `last_updated`, `last_trade_date`) VALUES (" + modelId + ", "
- + modelObjectiveId + ", " + strategyId + "," + tacticalFocusId + ", " + asOfDate + ", "
- + lastUpdatedDate + ", " + lastTradeDate + ") ON DUPLICATE KEY UPDATE `as_of_date`=" + asOfDate
- + ", `last_updated`=" + lastUpdatedDate + ", `last_trade_date`=" + lastTradeDate + "; \n");
- for (; startRow <= sheet.getLastRowNum(); startRow++) {
- row = sheet.getRow(startRow);
- if (!isRowNullable(row)) {
- result.append(processTradeLogGroup(tradeLogId, prepareCellData(row.getCell(1 + offset)),
- prepareCellData(row.getCell(2 + offset)), prepareCellData(row.getCell(3 + offset)),
- prepareCellData(row.getCell(4 + offset))));
- } else {
- break;
- }
- }
- }
- }
- row = sheet.getRow(startRow++);
- }
- offset += 5;
- }
- return result;
- }
- private String processTradeLogGroup(String tradeLogId, String tickerOld, String tickerNew, String oldValue,
- String newValue) throws SQLException {
- String tickerOldId = getIdByName("select asset_id as `id` from asset where `ticker` = " + tickerOld);
- String tickerNewId = getIdByName("select asset_id as `id` from asset where `ticker` = " + tickerNew);
- return "INSERT INTO `trade_log_assets` (`trade_log_id`, `asset_id_previous`, `asset_id_current`, "
- + " `weight_previous`, `weight_current`) VALUES (" + tradeLogId + ", " + tickerOldId + ", " + tickerNewId
- + ", " + oldValue + ", " + newValue + "); \n";
- }
- private StringBuffer processModelAllocationsPrevious(Sheet sheet) throws SQLException {
- StringBuffer result = new StringBuffer();
- int startRow;
- if ("class_name".equalsIgnoreCase(sheet.getRow(1).getCell(0).getStringCellValue())) {
- startRow = 2;
- } else if ("class_name".equalsIgnoreCase(sheet.getRow(2).getCell(0).getStringCellValue())) {
- startRow = 3;
- } else {
- startRow = 4;
- }
- Map<String, String> models = new HashMap<String, String>();
- Map<String, String> dates = new HashMap<String, String>();
- for (int i = startRow; i <= sheet.getLastRowNum(); i++) {
- Row row = sheet.getRow(i);
- if (!isRowNullable(row)) {
- String assetId = "(select asset_id as `id` from asset where `ticker` = " + prepareCellDataQuote(row.getCell(1))
- + ")";
- for (int col = 2; col <= row.getLastCellNum(); col++) {
- String modelId;
- String dateAsOf;
- String modelName = prepareCellData(sheet.getRow(startRow - 1).getCell(col));
- if (models.containsKey(modelName)) {
- modelId = models.get(modelName);
- dateAsOf = dates.get(modelName);
- } else {
- modelId = getIdByName("select `model_id` as `id` from `model` where `code` = " + modelName);
- models.put(modelName, modelId);
- dateAsOf = prepareCellData(sheet.getRow(startRow - 2).getCell(col));
- dates.put(modelName, dateAsOf);
- }
- result.append(processModelAllocationPrevious(assetId, prepareCellData(row.getCell(col)), modelId, dateAsOf));
- }
- }
- }
- return result;
- }
- private String processModelAllocationPrevious(String assetId, String value, String modelId, String dateAsOf)
- throws SQLException {
- if (modelId != null) {
- String modelAssetId = getIdByName("select`model_asset_id` as `id` from `model_asset_previous` where `asset_id` = "
- + assetId + " AND `model_id`=" + modelId);
- if (value != null) {
- if (modelAssetId == null) {
- return "INSERT INTO `model_asset_previous` (`model_id`, `asset_id`, `weight`, `as_of_date`) VALUES ("
- + modelId + ", " + assetId + ", " + value + ", " + dateAsOf + "); \n";
- } else {
- return "UPDATE `model_asset_previous` SET `weight`=" + value + ", `as_of_date`=" + dateAsOf
- + " WHERE `model_asset_id`=" + modelAssetId + "; \n";
- }
- } else {
- return "DELETE FROM `model_asset_previous` WHERE `model_asset_id`=" + modelAssetId + "; \n";
- }
- }
- return "";
- }
- private StringBuffer processModelAllocationsCurrent(Sheet sheet) throws SQLException {
- StringBuffer result = new StringBuffer();
- int startRow;
- if ("class_name".equalsIgnoreCase(sheet.getRow(1).getCell(0).getStringCellValue())) {
- startRow = 2;
- } else if ("class_name".equalsIgnoreCase(sheet.getRow(2).getCell(0).getStringCellValue())) {
- startRow = 3;
- } else {
- startRow = 4;
- }
- Map<String, String> models = new HashMap<String, String>();
- Map<String, String> dates = new HashMap<String, String>();
- for (int i = startRow; i <= sheet.getLastRowNum(); i++) {
- Row row = sheet.getRow(i);
- if (!isRowNullable(row)) {
- String assetId = "(select asset_id as `id` from asset where `ticker` = " + prepareCellDataQuote(row.getCell(1))
- + ")";
- for (int col = 2; col <= row.getLastCellNum(); col++) {
- String modelId;
- String dateAsOf;
- String modelName = prepareCellData(sheet.getRow(startRow - 1).getCell(col));
- if (models.containsKey(modelName)) {
- modelId = models.get(modelName);
- dateAsOf = dates.get(modelName);
- } else {
- modelId = getIdByName("select`model_id` as `id` from `model` where `code` = " + modelName);
- models.put(modelName, modelId);
- dateAsOf = prepareCellData(sheet.getRow(startRow - 2).getCell(col));
- dates.put(modelName, dateAsOf);
- }
- result.append(processModelAllocationCurrent(assetId, prepareCellData(row.getCell(col)), modelId, dateAsOf));
- }
- }
- }
- return result;
- }
- private String processModelAllocationCurrent(String assetId, String value, String modelId, String dateAsOf)
- throws SQLException {
- if (modelId != null) {
- String modelAssetId = getIdByName("select`model_asset_id` as `id` from `model_asset` where `asset_id` = "
- + assetId + " AND `model_id`=" + modelId);
- if (value != null) {
- if (modelAssetId == null) {
- return "INSERT INTO `model_asset` (`model_id`, `asset_id`, `weight`, `as_of_date`) VALUES (" + modelId + ", "
- + assetId + ", " + value + ", " + dateAsOf + "); \n";
- } else {
- return "UPDATE `model_asset` SET `weight`=" + value + ", `as_of_date`=" + dateAsOf
- + " WHERE `model_asset_id`=" + modelAssetId + "; \n";
- }
- } else {
- return "DELETE FROM `model_asset` WHERE `model_asset_id`=" + modelAssetId + "; \n";
- }
- }
- return "";
- }
- private StringBuffer processModelObjective(Sheet sheet) throws SQLException {
- Set<String> codes = getCodes("SELECT `model_objective_code` as `key` FROM `model_objective`;");
- StringBuffer result = new StringBuffer();
- for (int i = 1; i <= sheet.getLastRowNum(); i++) {
- Row row = sheet.getRow(i);
- if (!isRowNullable(row)) {
- if (row.getCell(0) != null && codes.contains(row.getCell(0).getStringCellValue())) {
- result.append("UPDATE `model_objective` SET `model_objective_name` = " + prepareCellData(row.getCell(1))
- + ", `order` = " + prepareCellData(row.getCell(2)) + ", `description` = "
- + prepareCellData(row.getCell(3)) + " WHERE `model_objective_code` = " + prepareCellData(row.getCell(0))
- + "; \n");
- } else {
- result.append("INSERT INTO `model_objective` (`model_objective_code`, `model_objective_name`,`order`, "
- + "`description`) VALUES (" + prepareCellData(row.getCell(0)) + "," + prepareCellData(row.getCell(1))
- + "," + prepareCellData(row.getCell(2)) + "," + prepareCellData(row.getCell(3)) + "); \n");
- }
- }
- String modelObjectiveId = getIdByName("select `model_objective_id` as `id` from `model_objective` where `model_objective_code` = "
- + prepareCellData(row.getCell(0)));
- result.append(processModelObkectivePerc(modelObjectiveId, prepareCellData(row.getCell(4)), "STOCKS"));
- result.append(processModelObkectivePerc(modelObjectiveId, prepareCellData(row.getCell(5)), "BONDS"));
- result.append(processModelObkectivePerc(modelObjectiveId, prepareCellData(row.getCell(6)), "CASH"));
- }
- return result;
- }
- private String processModelObkectivePerc(String modelObjectiveId, String percentage, String type) throws SQLException {
- String ticker;
- if ("STOCKS".equalsIgnoreCase(type)) {
- ticker = "'IDX_40'";
- } else if ("BONDS".equalsIgnoreCase(type)) {
- ticker = "'IDX_18'";
- } else {// CASH
- ticker = "'IDX_31'";
- }
- String assetId = getIdByName("select asset_id as `id` from asset where `ticker` = " + ticker);
- String objectiveBenchmarkId = getIdByName("select `objective_benchmark_id` as `id` from `objective_benchmark` where `asset_id` = "
- + assetId + " AND `model_objective_id`=" + modelObjectiveId);
- if (objectiveBenchmarkId == null) {
- return "INSERT INTO `objective_benchmark` (`model_objective_id`,`asset_id`,`weighting`) VALUES " + "("
- + modelObjectiveId + ", " + assetId + ", " + percentage + "); \n";
- } else {
- return "UPDATE `objective_benchmark` SET `weighting`=" + percentage + " where `asset_id` = " + assetId
- + " AND `model_objective_id`=" + modelObjectiveId + "; \n";
- }
- }
- private StringBuffer processModels(Sheet sheet) throws SQLException {
- Set<String> codes = getCodes("SELECT `code` as `key` FROM `model`;");
- StringBuffer result = new StringBuffer();
- for (int i = 1; i <= sheet.getLastRowNum(); i++) {
- Row row = sheet.getRow(i);
- if (!isRowNullable(row)) {
- String modelDirectionId = getIdByName("select `model_direction_id` as `id` from `model_direction` where `model_direction_name` = "
- + prepareCellData(row.getCell(2)));
- String annuityTypeId = getIdByName("select `annuity_type_id` as `id` from `annuity_type` where `annuity_type_name` = "
- + prepareCellData(row.getCell(3)));
- String modelProductId = getIdByName("select `model_product_id` as `id` from `model_product` where `model_product_code` = "
- + prepareCellData(row.getCell(4)));
- String policyId = getIdByName("select `policy_id` as `id` from `insurance_policy` where `insurance_policy_name` = "
- + prepareCellData(row.getCell(5)));
- String modelObjectiveId = getIdByName("select `model_objective_id` as `id` from `model_objective` where `model_objective_name` = "
- + prepareCellData(row.getCell(7)));
- String platformId = getIdByName("select `data_group_id` as `id` from `data_group` where `abbreviation` = "
- + prepareCellData(row.getCell(8)));
- String strategyId = getIdByName("select `strategy_id` as `id` from `strategy` where `name` = "
- + prepareCellData(row.getCell(6)) + " AND `model_product_id`=" + modelProductId + " AND `platform_id`="
- + platformId);
- String key = prepareCellData(row.getCell(0));
- if (key != null && key.startsWith("'") && key.endsWith("'")) {
- key = key.substring(1, key.length() - 1);
- }
- if (key != null && codes.contains(key)) {
- result.append("UPDATE `model` SET " + "`name` = " + prepareCellData(row.getCell(1)) + ", `"
- + "model_direction_id`=" + modelDirectionId + ", `annuity_type_id` = " + annuityTypeId
- + ",`model_product_id`=" + modelProductId + ",`policy_id`=" + policyId + ",`strategy_id`=" + strategyId
- + ",`model_objective_id`=" + modelObjectiveId + ", `data_group_id`=" + platformId + ", `hidden` ="
- + ("'YES'".equalsIgnoreCase(prepareCellData(row.getCell(9))) ? "0" : "1")
- + ", `owner_id`=1, `creator_id`=1, `tracking_number`=" + prepareCellData(row.getCell(10))
- + ", `res_number`=" + prepareCellData(row.getCell(11)) + ", `overview`="
- + prepareCellData(row.getCell(12)) + " WHERE `code` = " + prepareCellData(row.getCell(0)) + "; \n");
- } else {
- result.append("INSERT INTO `model` "
- + "(`code`,`name`,`model_direction_id`, `annuity_type_id`, `model_product_id`, "
- + "`policy_id`, `strategy_id`, `model_objective_id`, `hidden`, `data_group_id`, `creator_id`, "
- + "`tracking_number`, `res_number`, `overview`, `owner_id`) VALUES ("
- + prepareCellData(row.getCell(0))
- + ","
- + prepareCellData(row.getCell(1))
- + ","
- + modelDirectionId
- + ", "
- + annuityTypeId
- + ", "
- + modelProductId
- + ", "
- + policyId
- + ", "
- + strategyId
- + ", "
- + modelObjectiveId
- + ", "
- + ("'YES'".equalsIgnoreCase(prepareCellData(row.getCell(9))) ? "0" : "1")
- + ", "
- + platformId
- + ", 1, "
- + prepareCellData(row.getCell(10))
- + ", "
- + prepareCellData(row.getCell(11))
- + ", "
- + prepareCellData(row.getCell(12)) + ", 1); \n");
- }
- }
- }
- return result;
- }
- private StringBuffer processAssets(Sheet sheet) throws SQLException {
- // Set<String> codes = getCodes("SELECT `ticker` as `key` FROM `asset`;");
- StringBuffer result = new StringBuffer();
- for (int i = 1; i <= sheet.getLastRowNum(); i++) {
- Row row = sheet.getRow(i);
- if (!isRowNullable(row)) {
- String key = prepareCellData(row.getCell(0));
- if (key != null && key.startsWith("'") && key.endsWith("'")) {
- key = key.substring(1, key.length() - 1);
- }
- result.append("INSERT INTO `asset` " + "(`ticker`,`name`,`extern_key`, `class`, `hidden`, "
- + "`data_group_id`, `extern_src`, `owner`) VALUES (" + prepareCellData(row.getCell(0)) + ","
- + prepareCellData(row.getCell(1)) + "," + prepareCellData(row.getCell(0)) + ","
- + prepareCellData(row.getCell(2)) + ", "
- + ("'YES'".equalsIgnoreCase(prepareCellData(row.getCell(5))) ? "0" : "1") + ", 1,'LPL', 1)"
- + " ON DUPLICATE KEY UPDATE `name` = " + prepareCellData(row.getCell(1)) + ", `" + "class`="
- + prepareCellData(row.getCell(2)) + ", `extern_key` = " + prepareCellData(row.getCell(0)) + ", `hidden` ="
- + ("'YES'".equalsIgnoreCase(prepareCellData(row.getCell(5))) ? "0" : "1")
- + ", `owner`=1,`data_group_id`=1, `extern_src`='LPL', `owner`=1; \n");
- String assetId = "(select `asset_id` as `id` from `asset` where `ticker` = "
- + prepareCellDataQuote(row.getCell(0)) + ")";
- result.append(processAssetDisclosures(assetId, prepareCellData(row.getCell(22))));
- result.append(processAssetPolicies(assetId, prepareCellData(row.getCell(7))));
- result.append(processAssetClass(assetId, prepareCellData(row.getCell(3)), prepareCellData(row.getCell(4))));
- result.append(processAssetRiskClassification(assetId, prepareCellData(row.getCell(5))));
- result.append(processAssetOption(assetId, prepareCellData(row.getCell(8))));
- result.append(processAssetStatistics(assetId, prepareCellData(row.getCell(9)),
- prepareCellData(row.getCell(10)), prepareCellData(row.getCell(11)), prepareCellData(row.getCell(12)),
- prepareCellData(row.getCell(13)), prepareCellData(row.getCell(14)), prepareCellData(row.getCell(15)),
- prepareCellData(row.getCell(16)), prepareCellData(row.getCell(17)), prepareCellData(row.getCell(18)),
- prepareCellData(row.getCell(19)), prepareCellData(row.getCell(20)), prepareCellData(row.getCell(21))));
- result.append(processAssetPlatformAvailability(assetId, prepareCellData(row.getCell(23)), "PWP"));
- result.append(processAssetPlatformAvailability(assetId, prepareCellData(row.getCell(24)), "SAM"));
- result.append(processAssetPlatformAvailability(assetId, prepareCellData(row.getCell(25)), "MWP"));
- result.append(processAssetPlatformAvailability(assetId, prepareCellData(row.getCell(26)), "OMP"));
- result.append(processAssetPlatformAvailability(assetId, prepareCellData(row.getCell(27)), "MS"));
- result.append(processAssetPlatformAvailability(assetId, prepareCellData(row.getCell(28)), "SWM"));
- }
- }
- return result;
- }
- private StringBuffer processAssetPlatformAvailability(String assetId, String yesNo, String platform)
- throws SQLException {
- String dataGroupOptionId = getIdByName("select data_group_id as `id` from `data_group` where `abbreviation`='"
- + platform + "';");
- StringBuffer buffer = new StringBuffer();
- if (dataGroupOptionId != null && assetId != null) {
- buffer.append("DELETE FROM `asset_platform_availability` WHERE `asset_id`=" + assetId
- + " AND `data_group_option_id`=" + dataGroupOptionId + "; \n");
- if (yesNo != null) {
- if ("'Y'".equalsIgnoreCase(yesNo)) {
- buffer.append("INSERT INTO `asset_platform_availability` (`asset_id`, `data_group_option_id`) " + "VALUES ("
- + assetId + ", " + dataGroupOptionId + "); \n");
- }
- }
- }
- return buffer;
- }
- private String processAssetOption(String assetId, String assetOption) throws SQLException {
- if (assetId != null && assetOption != null) {
- String oldAssetId = getIdByName("select asset_id as `id` from `asset_option` where `asset_id`=" + assetId);
- if (oldAssetId == null) {
- return "INSERT INTO `asset_option` (`asset_id`, `min_value_non_sac`) VALUES (" + assetId + ", " + assetOption
- + "); \n";
- } else {
- return "UPDATE `asset_option` SET `min_value_non_sac`=" + assetOption + " WHERE `asset_id`=" + assetId + "; \n";
- }
- }
- return "";
- }
- private StringBuffer processAssetClass(String assetId, String classNameDetailed, String className)
- throws SQLException {
- StringBuffer buffer = new StringBuffer("DELETE FROM `asset_classification` WHERE `security_id`=" + assetId + "; \n");
- if ((classNameDetailed != null || className != null) && assetId != null) {
- String asseClasstId = getIdByName("select asset_id as `id` from `asset` where `name`=" + className);
- String classNameDetailedId = getIdByName("select asset_id as `id` from `asset` where `name`=" + classNameDetailed);
- if (asseClasstId != null || classNameDetailedId != null) {
- buffer
- .append("INSERT INTO `asset_classification` (`security_id`, `asset_class_id`, `asset_class_detailed_id`, `owner`) VALUES ("
- + assetId
- + ", "
- + (asseClasstId != null ? asseClasstId : classNameDetailedId)
- + ", "
- + (classNameDetailedId != null ? classNameDetailedId : asseClasstId) + ", 1); \n");
- }
- }
- return buffer;
- }
- private StringBuffer processAssetRiskClassification(String assetId, String riskClassificationName)
- throws SQLException {
- StringBuffer buffer = new StringBuffer("DELETE FROM `asset_risk_classification` WHERE `asset_id`=" + assetId
- + "; \n");
- if (riskClassificationName != null && assetId != null) {
- String riskId = getIdByName("select `risk_classification_id` as `id` from `risk_classification` where `classification_name`="
- + riskClassificationName);
- if (riskId != null) {
- buffer.append("INSERT INTO `asset_risk_classification` (`asset_id`, `risk_classification_id`) VALUES ("
- + assetId + ", " + riskId + "); \n");
- }
- }
- return buffer;
- }
- private StringBuffer processAssetClasses(Sheet sheet) throws SQLException {
- StringBuffer result = new StringBuffer();
- String parentId = "(SELECT `asset_id_temp`.`asset_id` FROM `asset_id_temp` LIMIT 1, 1)";
- for (int i = 1; i <= sheet.getLastRowNum(); i++) {
- Row row = sheet.getRow(i);
- if (!isRowNullable(row)) {
- String proxyId = getIdByName("select asset_id as `id` from asset where ticker="
- + prepareCellDataQuote(row.getCell(3)) + ";");
- String assetTypeId = getIdByName("select asset_type_id as `id` from asset_type where name="
- + prepareCellData(row.getCell(4)) + ";");
- String assetTierId = getIdByName("select asset_tier_id as `id` from asset_tier where name="
- + prepareCellData(row.getCell(5)) + ";");
- if (row.getCell(0) != null) {
- result.append("INSERT INTO `asset` "
- + "(`ticker`,`name`,`extern_key`, `order_no`, `hidden`, `owner`, `proxy_id`, "
- + "`asset_type_id`, `asset_tier_id`, `data_group_id`, `extern_src`, `class`, "
- + "`parent`, `color_1`, `color_2`) VALUES ("
- + prepareCellData(row.getCell(0))
- + ","
- + prepareCellData(row.getCell(1))
- + ","
- + prepareCellData(row.getCell(0))
- + ","
- + prepareCellData(row.getCell(2))
- + ", "
- + ("'YES'".equalsIgnoreCase(prepareCellData(row.getCell(6))) ? "0" : "1")
- + ", 1, "
- + proxyId
- + ", "
- + assetTypeId
- + ", "
- + assetTierId
- + ", 1,'LPL','AC', "
- + parentId
- + ", "
- + prepareCellData(row.getCell(7)) + "," + prepareCellData(row.getCell(8)) + ") ON DUPLICATE KEY UPDATE `name` = " + prepareCellData(row.getCell(1)) + ", `order_no`="
- + prepareCellData(row.getCell(2)) + ", `proxy_id`=" + proxyId + ", `asset_type_id`=" + assetTypeId
- + ", `asset_tier_id`=" + assetTierId + ", `extern_key` = " + prepareCellData(row.getCell(0))
- + ", `hidden` =" + ("'YES'".equalsIgnoreCase(prepareCellData(row.getCell(6))) ? "0" : "1")
- + ", `owner`=1,`data_group_id`=1, `extern_src`='LPL', `class`='AC', `parent`=" + parentId
- + ", `color_1`=" + prepareCellData(row.getCell(7)) + ", `color_2`=" + prepareCellData(row.getCell(8))
- + "; \n");
- } else {
- }
- String assetId = "(select asset_id as `id` from asset where `ticker` = " + prepareCellDataQuote(row.getCell(0))
- + ")";
- result.append(processAssetDisclosures(assetId, prepareCellData(row.getCell(9))));
- }
- }
- return result;
- }
- private StringBuffer processAssetDisclosures(String assetId, String disclosures) throws SQLException {
- StringBuffer buffer = new StringBuffer("DELETE FROM `asset_disclosure` WHERE `asset_id`=" + assetId + "; \n");
- if (disclosures != null && assetId != null) {
- disclosures = disclosures.substring(1, disclosures.length() - 1).replaceAll("\\|", ",");
- for (String disclosureId : disclosures.split(",")) {
- if (!"".equals(disclosureId)
- && getIdByName("select `disclosure_code` as `id` from `disclosure` where `disclosure_code`='"
- + disclosureId + "'") != null) {
- buffer.append("INSERT INTO `asset_disclosure` (`asset_id`, `disclosure_code`) VALUES (" + assetId + ", '"
- + disclosureId + "'); \n");
- }
- }
- }
- return buffer;
- }
- private StringBuffer processAssetPolicies(String assetId, String policies) throws SQLException {
- StringBuffer buffer = new StringBuffer("DELETE FROM `asset_policy` WHERE `asset_id`=" + assetId + "; \n");
- if (policies != null && assetId != null) {
- policies = policies.substring(1, policies.length() - 1).replaceAll("\\|", ",");
- for (String policyName : policies.split(",")) {
- if (!"".equals(policyName)) {
- String policyId = getIdByName("select `policy_id` as `id` from `insurance_policy` where `insurance_policy_code`='"
- + policyName + "';");
- if (policyId != null) {
- buffer.append("INSERT INTO `asset_policy` (`asset_id`, `policy_id`) VALUES (" + assetId + ", " + policyId
- + "); \n");
- }
- }
- }
- }
- return buffer;
- }
- private StringBuffer processIndices(Sheet sheet) throws SQLException {
- Set<String> codes = getCodes("SELECT `ticker` as `key` FROM `asset`;");
- StringBuffer result = new StringBuffer();
- result.append(createAssetIdTemp());
- String parentId = "(SELECT `asset_id_temp`.`asset_id` FROM `asset_id_temp` LIMIT 0, 1)";
- for (int i = 1; i <= sheet.getLastRowNum(); i++) {
- Row row = sheet.getRow(i);
- if (!isRowNullable(row)) {
- if (row.getCell(0) != null && codes.contains(row.getCell(0).getStringCellValue())) {
- result.append("UPDATE `asset` SET `name` = " + prepareCellData(row.getCell(1)) + ", `extern_key` = "
- + prepareCellData(row.getCell(0))
- + ", `hidden` =1, `owner`=1,`data_group_id`=1, `extern_src`='LPL', `class`='AC', `parent`=" + parentId
- + " WHERE `ticker` = " + prepareCellDataQuote(row.getCell(0)) + "; \n");
- } else {
- result.append("INSERT INTO `asset` " + "(`ticker`,`name`,`extern_key`, "
- + "`hidden`, `owner`, `data_group_id`, `extern_src`, `class`,`parent`) VALUES ("
- + prepareCellData(row.getCell(0)) + "," + prepareCellData(row.getCell(1)) + ","
- + prepareCellData(row.getCell(0)) + ", 1, 1, 1,'LPL','AC'," + parentId + "); \n");
- }
- String assetId = "(select asset_id as `id` from asset where `ticker` = " + prepareCellDataQuote(row.getCell(0))
- + ")";
- if ("'INDEX_DEFINITION'".equalsIgnoreCase(prepareCellData(sheet.getRow(0).getCell(9)))) {
- result.append(processAssetDefinition(assetId, prepareCellData(row.getCell(9))));
- } else {
- result.append(processAssetDefinition(assetId, prepareCellData(row.getCell(15))));
- }
- result.append(processAssetStatistics(assetId, prepareCellData(row.getCell(2)), prepareCellData(row.getCell(3)),
- prepareCellData(row.getCell(4)), prepareCellData(row.getCell(5)), prepareCellData(row.getCell(6)),
- prepareCellData(row.getCell(7)), prepareCellData(row.getCell(8)), prepareCellData(row.getCell(9)),
- prepareCellData(row.getCell(10)), prepareCellData(row.getCell(11)), prepareCellData(row.getCell(12)),
- prepareCellData(row.getCell(13)), prepareCellData(row.getCell(14))));
- }
- }
- return result;
- }
- private StringBuffer createAssetIdTemp() throws SQLException {
- StringBuffer result = new StringBuffer();
- String parentId = getIdByName("select asset_id as `id` from asset where name='INDEX_ROOT';");
- if (parentId == null) {
- result.append("INSERT INTO `asset` (`parent`, `owner`, `class`, `asset_type_id`, "
- + "`asset_tier_id`, `taxable`, `industry_id`, `asset_category_id`, `order_no`, "
- + "`hidden`, `name`, `proxy_id`, `currency_id`, `ticker`, `cusip`, `isin`, `sedol`, "
- + "`start_date`, `end_date`, `yield`, `extern_src`, `extern_key`, `axis`, `data_group_id`, "
- + "`nav`, `nav_as_of_date`, `asset_class_group_id`, `sei_discount_eligible`, `color_1`, `color_2`) "
- + "VALUES (null, 1, 'FOLDER',null,null,1,null,null,0,1,'INDEX_ROOT',null,1,'INDEXROOT',null, "
- + "null,null,null,null,null,'LPL','LPL_INDEX_ROOT',null,1,null,null,null,0,null,null); \n");
- }
- parentId = getIdByName("select asset_id as `id` from asset where name='ASSET_CLASS_ROOT';");
- if (parentId == null) {
- result.append("INSERT INTO `asset` (`parent`, `owner`, `class`, `asset_type_id`, `asset_tier_id`, "
- + "`taxable`, `industry_id`, `asset_category_id`, `order_no`, `hidden`, `name`, `proxy_id`, "
- + "`currency_id`, `ticker`, `cusip`, `isin`, `sedol`, `start_date`, `end_date`, `yield`, "
- + "`extern_src`, `extern_key`, `axis`, `data_group_id`, `nav`, `nav_as_of_date`, "
- + "`asset_class_group_id`, `sei_discount_eligible`, `color_1`, `color_2`) "
- + "VALUES (null, 1, 'FOLDER',null,null,1,null,null,0,1,'ASSET_CLASS_ROOT',null,1,'ASSETCROOT', "
- + "null,null,null,null,null,null,'LPL','LPL_ASSET_CLASS_ROOT',null,1,null,null,null,0,null,null); \n");
- }
- result.append("DROP TABLE IF EXISTS `asset_id_temp`; \n" + "CREATE TABLE `asset_id_temp` (`asset_id` INT(10)) "
- + "ENGINE=InnoDB DEFAULT CHARSET=utf8; \n" + "INSERT INTO `asset_id_temp` VALUES ("
- + "(SELECT `asset`.`asset_id` FROM `asset` WHERE `asset`.`extern_key` = 'LPL_INDEX_ROOT')), "
- + "((SELECT `asset`.`asset_id` FROM `asset` WHERE `asset`.`extern_key` = 'LPL_ASSET_CLASS_ROOT')); \n");
- return result;
- }
- private StringBuffer deleteAssetIdTemp() {
- StringBuffer result = new StringBuffer();
- result.append("DROP TABLE IF EXISTS `asset_id_temp`; \n");
- return result;
- }
- private String prepareCellDataQuote(Cell cell) {
- String prepareCellData = prepareCellData(cell);
- return prepareCellData != null ? prepareCellData.startsWith("'") ? prepareCellData : "'" + prepareCellData + "'"
- : null;
- }
- private Object processAssetStatistics(String assetId, String oneYearReturn, String threYearReturn,
- String fiveYearReturn, String tenYearReturn, String sinceInceptionReturn, String standardDeviation, String alpha,
- String beta, String r2, String sharpe, String upCapture, String downCapture, String dataAsOf) throws SQLException {
- if ((oneYearReturn != null || threYearReturn != null || fiveYearReturn != null || tenYearReturn != null
- || sinceInceptionReturn != null || standardDeviation != null || alpha != null || beta != null || r2 != null
- || sharpe != null || upCapture != null || downCapture != null || dataAsOf != null)
- && assetId != null) {
- String assetStatisticsId = getIdByName("select asset_id as `id` from asset_statistics WHERE `asset_id`="
- + assetId + ";");
- if (assetStatisticsId == null) {
- return "INSERT INTO `asset_statistics` (`asset_id`, `1_year_return`, `3_year_return`, `5_year_return`, "
- + "`10_year_return`, `since_inception_return`, `standard_deviation`, `alpha`, `beta`, `r2`, "
- + "`sharpe`, " + "`up_capture`, `down_capture`, `data_as_of`) VALUES ("
- + assetId
- + ", "
- + oneYearReturn
- + ", "
- + threYearReturn
- + ", "
- + fiveYearReturn
- + ", "
- + tenYearReturn
- + ", "
- + sinceInceptionReturn
- + ", "
- + standardDeviation
- + ", "
- + alpha
- + ", "
- + beta
- + ", "
- + r2
- + ", "
- + sharpe + ", " + upCapture + ", " + downCapture + ", " + dataAsOf + "); \n";
- } else {
- return "UPDATE `asset_statistics` SET `1_year_return`=" + oneYearReturn + ", `3_year_return`=" + threYearReturn
- + ", `5_year_return`=" + fiveYearReturn + ", " + "`10_year_return`=" + tenYearReturn
- + ", `since_inception_return`=" + sinceInceptionReturn + ", `standard_deviation`=" + standardDeviation
- + ",`alpha`=" + alpha + ", `beta`=" + beta + ", `r2`=" + r2 + ", `sharpe`=" + sharpe + ", `up_capture`="
- + upCapture + ", `down_capture`=" + downCapture + ", `data_as_of`=" + dataAsOf + " WHERE `asset_id`="
- + assetId + "; \n";
- }
- }
- return "DELETE FROM `asset_statistics` WHERE `asset_id`=" + assetId + "; \n";
- }
- private String processAssetDefinition(String assetId, String definition) throws SQLException {
- if (definition == null) {
- return "DELETE FROM `asset_definition` WHERE `asset_id`=" + assetId + "; \n";
- } else {
- String assetDefinitionId = getIdByName("select asset_id as `id` from asset_definition WHERE `asset_id`="
- + assetId + ";");
- if (assetDefinitionId == null) {
- return "INSERT INTO `asset_definition` (`asset_id`, `definition`) VALUES (" + assetId + ", " + definition
- + "); \n";
- } else {
- return "UPDATE `asset_definition` SET `definition`=" + definition + " WHERE `asset_id`=" + assetId + "; \n";
- }
- }
- }
- private StringBuffer processModelType(Sheet sheet) throws SQLException {
- Set<String> codes = getCodes("SELECT `code` as `key` FROM `strategy`;");
- StringBuffer result = new StringBuffer();
- for (int i = 1; i <= sheet.getLastRowNum(); i++) {
- Row row = sheet.getRow(i);
- if (!isRowNullable(row)) {
- String platformName = row.getCell(5) == null ? null : row.getCell(5).getStringCellValue();
- String platformId = getIdByName("SELECT `data_group_id` as `id` FROM `data_group` WHERE `abbreviation`='"
- + StringEscapeUtils.escapeSql(platformName) + "';");
- String modelName = row.getCell(6) == null ? null : row.getCell(6).getStringCellValue();
- String modelId = getIdByName("SELECT `model_product_id` as `id` FROM `model_product` WHERE `model_product_name`='"
- + StringEscapeUtils.escapeSql(modelName) + "';");
- if (row.getCell(0) != null && codes.contains(row.getCell(0).getStringCellValue())) {
- result.append("UPDATE `strategy` SET `name` = " + prepareCellData(row.getCell(1))
- + ", `strategy_disclosure` = " + prepareCellData(row.getCell(2)) + ", `strategy_highlights` = "
- + prepareCellData(row.getCell(3)) + ", `strategy_trade_log_focus` = " + prepareCellData(row.getCell(4))
- + ", `model_product_id` = " + modelId + ", `platform_id` = " + platformId + " WHERE `code` = "
- + prepareCellData(row.getCell(0)) + "; \n");
- } else {
- result.append("INSERT INTO `strategy` " + "(`code`,`name`,`strategy_disclosure`, "
- + "`strategy_highlights`, `strategy_trade_log_focus`, `model_product_id`, `platform_id`) VALUES ("
- + prepareCellData(row.getCell(0)) + "," + prepareCellData(row.getCell(1)) + ","
- + prepareCellData(row.getCell(2)) + "," + prepareCellData(row.getCell(3)) + ","
- + prepareCellData(row.getCell(4)) + "," + modelId + "," + platformId + "); \n");
- }
- }
- }
- return result;
- }
- private StringBuffer processManagerGuideCover(Sheet sheet) throws SQLException {
- Set<String> codes = getCodes("SELECT data_group.abbreviation as `key` " + "FROM manager_guide_cover_text "
- + "join data_group on manager_guide_cover_text.data_group_id=data_group.data_group_id; ");
- StringBuffer result = new StringBuffer();
- for (int i = 1; i <= sheet.getLastRowNum(); i++) {
- Row row = sheet.getRow(i);
- if (!isRowNullable(row)) {
- String name = row.getCell(0) == null ? null : row.getCell(0).getStringCellValue();
- String id = getIdByName("SELECT `data_group_id` as `id` FROM `data_group` WHERE `abbreviation`='"
- + StringEscapeUtils.escapeSql(name) + "';");
- if (row.getCell(0) != null && codes.contains(row.getCell(0).getStringCellValue())) {
- result.append("UPDATE `manager_guide_cover_text` SET `description` = " + prepareCellData(row.getCell(1))
- + ", `data_group_id` = " + id + ", `companion_bullet1` = " + prepareCellData(row.getCell(2))
- + ", `companion_bullet2` = " + prepareCellData(row.getCell(3)) + ", `companion_bullet3` = "
- + prepareCellData(row.getCell(4)) + ", `companion_bullet4` = " + prepareCellData(row.getCell(5))
- + " WHERE `data_group_id` = " + id + "; \n");
- } else {
- result.append("INSERT INTO `manager_guide_cover_text` "
- + "(`description`,`companion_bullet1`,`data_group_id`, "
- + "`companion_bullet2`, `companion_bullet3`, `companion_bullet4`) VALUES ("
- + prepareCellData(row.getCell(1)) + "," + prepareCellData(row.getCell(2)) + "," + id + ","
- + prepareCellData(row.getCell(3)) + "," + prepareCellData(row.getCell(4)) + ","
- + prepareCellData(row.getCell(5)) + "); \n");
- }
- }
- }
- return result;
- }
- private StringBuffer processDisclosureType(Sheet sheet) throws SQLException {
- Set<String> codes = getCodes("SELECT distinct `disclosure_type_name` as `key` FROM `disclosure_type`;");
- StringBuffer result = new StringBuffer();
- for (int i = 1; i <= sheet.getLastRowNum(); i++) {
- Row row = sheet.getRow(i);
- if (!isRowNullable(row)) {
- if (prepareCellData(row.getCell(3)) != null && !codes.contains(row.getCell(3).getStringCellValue())) {
- result.append("INSERT INTO `disclosure_type` " + "(`disclosure_type_name`) VALUES ("
- + prepareCellData(row.getCell(3)) + "); \n");
- }
- }
- }
- return result;
- }
- private StringBuffer processDisclosure(Sheet sheet) throws SQLException {
- StringBuffer result = new StringBuffer();
- for (int i = 1; i <= sheet.getLastRowNum(); i++) {
- Row row = sheet.getRow(i);
- if (!isRowNullable(row)) {
- String name = row.getCell(2) == null ? null : (row.getCell(3) == null ? null : row.getCell(3)
- .getStringCellValue());
- String id = getIdByName("SELECT `disclosure_type_id` as `id` FROM `disclosure_type` WHERE `disclosure_type_name`='"
- + StringEscapeUtils.escapeSql(name) + "';");
- result.append("INSERT INTO `disclosure` " + "(`disclosure_code`,`disclosure`,`disclosure_name`, "
- + "`disclosure_type_id`, `disclosure_order`) VALUES (" + prepareCellData(row.getCell(0)) + ","
- + prepareCellData(row.getCell(1)) + "," + prepareCellData(row.getCell(2)) + "," + id + ","
- + prepareCellData(row.getCell(4)) + ") ON DUPLICATE KEY UPDATE `disclosure` = "
- + prepareCellData(row.getCell(1)) + ", `disclosure_type_id` = " + id + ", `disclosure_name` = "
- + prepareCellData(row.getCell(2)) + ", `disclosure_order` = " + prepareCellData(row.getCell(4)) + "; \n");
- }
- }
- return result;
- }
- private StringBuffer processModelTacticalFocus(Sheet sheet) throws SQLException {
- Set<String> codes = getCodes("SELECT `tactical_focus_id` as `key` FROM `tactical_focus`;");
- StringBuffer result = new StringBuffer();
- for (int i = 1; i <= sheet.getLastRowNum(); i++) {
- Row row = sheet.getRow(i);
- if (!isRowNullable(row)) {
- String strategyName = row.getCell(2) == null ? null : row.getCell(2).getStringCellValue();
- String strategyId = getIdByName("SELECT `strategy_id` as `id` FROM `strategy` WHERE `name`='"
- + StringEscapeUtils.escapeSql(strategyName) + "';");
- if (row.getCell(0) != null && codes.contains(row.getCell(0).getStringCellValue())) {
- result.append("UPDATE `tactical_focus` SET `tactical_focus_name` = " + prepareCellData(row.getCell(1))
- + ", `strategy_id` = " + strategyId + ", `focus_order` = " + prepareCellData(row.getCell(3))
- + ", `definition` = " + prepareCellData(row.getCell(4)) + " WHERE `tactical_focus_id` = "
- + prepareCellData(row.getCell(0)) + "; \n");
- } else {
- result.append("INSERT INTO `tactical_focus` " + "(`tactical_focus_id`,`tactical_focus_name`,`strategy_id`, "
- + "`focus_order`, `definition`) VALUES (" + prepareCellData(row.getCell(0)) + ","
- + prepareCellData(row.getCell(1)) + "," + strategyId + "," + prepareCellData(row.getCell(3)) + ","
- + prepareCellData(row.getCell(4)) + "); \n");
- }
- }
- }
- return result;
- }
- private StringBuffer processManagerRiskClassification(Sheet sheet) throws SQLException {
- Set<String> codes = getCodes("SELECT `risk_classification_id` as `key` FROM `risk_classification`;");
- StringBuffer result = new StringBuffer();
- for (int i = 1; i <= sheet.getLastRowNum(); i++) {
- Row row = sheet.getRow(i);
- if (!isRowNullable(row)) {
- if (codes.contains(prepareCellData(row.getCell(0)))) {
- result.append("UPDATE `risk_classification` SET `classification_name` = " + prepareCellData(row.getCell(1))
- + ", `classification_code` = " + prepareCellData(row.getCell(2)) + ", `order` = "
- + prepareCellData(row.getCell(3)) + ", `risk_classification_description` = "
- + prepareCellData(row.getCell(4)) + " WHERE `risk_classification_id` = "
- + prepareCellData(row.getCell(0)) + "; \n");
- } else {
- result.append("INSERT INTO `risk_classification` "
- + "(`risk_classification_id`,`classification_name`,`classification_code`, `order`, "
- + "`risk_classification_description`) VALUES (" + prepareCellData(row.getCell(0)) + ","
- + prepareCellData(row.getCell(1)) + "," + prepareCellData(row.getCell(2)) + ","
- + prepareCellData(row.getCell(3)) + "," + prepareCellData(row.getCell(4)) + "); \n");
- }
- }
- }
- return result;
- }
- private StringBuffer processPlatform(Sheet sheet) throws SQLException {
- Set<String> codes = getCodes("SELECT `code` as `key` FROM `data_group`;");
- StringBuffer result = new StringBuffer();
- for (int i = 1; i <= sheet.getLastRowNum(); i++) {
- Row row = sheet.getRow(i);
- if (!isRowNullable(row)) {
- if (codes.contains(row.getCell(0).getStringCellValue())) {
- result.append("UPDATE `data_group` SET `name` = " + prepareCellData(row.getCell(1)) + ", `abbreviation` = "
- + prepareCellData(row.getCell(2)) + ", `data_group_id` = " + prepareCellData(row.getCell(3))
- + ", `description` = " + prepareCellData(row.getCell(4)) + " WHERE `code` = "
- + prepareCellData(row.getCell(0)) + "; \n");
- } else {
- result.append("INSERT INTO `data_group` "
- + "(`code`,`name`,`abbreviation`, `data_group_id`, `description`) VALUES ("
- + prepareCellData(row.getCell(0)) + "," + prepareCellData(row.getCell(1)) + ","
- + prepareCellData(row.getCell(2)) + "," + prepareCellData(row.getCell(3)) + ","
- + prepareCellData(row.getCell(4)) + "); \n");
- }
- }
- }
- return result;
- }
- private StringBuffer processPolicy(Sheet sheet) throws SQLException {
- Set<String> codes = getCodes("SELECT `insurance_policy_code` as `key` FROM `insurance_policy`;");
- StringBuffer result = new StringBuffer();
- for (int i = 1; i <= sheet.getLastRowNum(); i++) {
- Row row = sheet.getRow(i);
- if (!isRowNullable(row)) {
- String insuranceCompanyName = row.getCell(2) == null ? null : row.getCell(2).getStringCellValue();
- String insuranceCompanyId = getIdByName("SELECT `insurance_company_id` as `id` FROM `insurance_company` WHERE insurance_company_name='"
- + StringEscapeUtils.escapeSql(insuranceCompanyName) + "';");
- if (row.getCell(0) != null && codes.contains(row.getCell(0).getStringCellValue())) {
- result.append("UPDATE `insurance_policy` SET `insurance_policy_name` = " + prepareCellData(row.getCell(1))
- + ", `insurance_company_id` = " + insuranceCompanyId
- + ", `disclosure_annual_contract_fee_surrender_schedule` = " + prepareCellData(row.getCell(3))
- + " WHERE `insurance_policy_code` = " + prepareCellData(row.getCell(0)) + "; \n");
- } else {
- result
- .append("INSERT INTO `insurance_policy` "
- + "(`insurance_policy_code`,`insurance_policy_name`,`insurance_company_id`, `disclosure_annual_contract_fee_surrender_schedule`) VALUES ("
- + prepareCellData(row.getCell(0)) + "," + prepareCellData(row.getCell(1)) + "," + insuranceCompanyId
- + "," + prepareCellData(row.getCell(3)) + "); \n");
- }
- }
- }
- return result;
- }
- private StringBuffer processManagerType(Sheet sheet) throws SQLException {
- Set<String> codes = getCodes("SELECT `security_type_id` as `key` FROM `asset_security_type`;");
- StringBuffer result = new StringBuffer();
- for (int i = 1; i <= sheet.getLastRowNum(); i++) {
- Row row = sheet.getRow(i);
- if (!isRowNullable(row)) {
- if (codes.contains(prepareCellData(row.getCell(0)))) {
- result.append("UPDATE `asset_security_type` SET `security_type_name` = " + prepareCellData(row.getCell(1))
- + ", `class` = " + prepareCellData(row.getCell(2)) + ", `order` = " + prepareCellData(row.getCell(3))
- + ", `color` = " + prepareCellData(row.getCell(4)) + " WHERE `security_type_id` = "
- + prepareCellData(row.getCell(0)) + "; \n");
- } else {
- result.append("INSERT INTO `asset_security_type` "
- + "(`security_type_id`,`security_type_name`,`class`, `order`, `color`) VALUES ("
- + prepareCellData(row.getCell(0)) + "," + prepareCellData(row.getCell(1)) + ","
- + prepareCellData(row.getCell(2)) + "," + prepareCellData(row.getCell(3)) + ","
- + prepareCellData(row.getCell(4)) + "); \n");
- }
- }
- }
- return result;
- }
- private StringBuffer processInsuranceCompany(Sheet sheet) throws SQLException {
- Set<String> codes = getCodes("SELECT `insurance_company_code` as `key` FROM `insurance_company`;");
- StringBuffer result = new StringBuffer();
- for (int i = 1; i <= sheet.getLastRowNum(); i++) {
- Row row = sheet.getRow(i);
- if (!isRowNullable(row)) {
- if (codes.contains(row.getCell(0).getStringCellValue())) {
- result.append("UPDATE `insurance_company` SET `insurance_company_name` = " + prepareCellData(row.getCell(1))
- + ", `insurance_company_website` = " + prepareCellData(row.getCell(2))
- + " WHERE `insurance_company_code` = " + prepareCellData(row.getCell(0)) + "; \n");
- } else {
- result.append("INSERT INTO `insurance_company` "
- + "(`insurance_company_code`,`insurance_company_name`,`insurance_company_website`) VALUES ("
- + prepareCellData(row.getCell(0)) + "," + prepareCellData(row.getCell(1)) + ","
- + prepareCellData(row.getCell(2)) + "); \n");
- }
- }
- }
- return result;
- }
- private StringBuffer processAssetTier(Sheet sheet) throws SQLException {
- Set<String> codes = getCodes("SELECT `code` as `key` FROM `asset_tier`;");
- StringBuffer result = new StringBuffer();
- for (int i = 1; i <= sheet.getLastRowNum(); i++) {
- Row row = sheet.getRow(i);
- if (!isRowNullable(row)) {
- if (codes.contains(row.getCell(0).getStringCellValue())) {
- result.append("UPDATE `asset_tier` SET `name` = " + prepareCellData(row.getCell(1)) + ", `order` = "
- + prepareCellData(row.getCell(2)) + ", `color` = " + prepareCellData(row.getCell(3)) + " WHERE `code` = "
- + prepareCellData(row.getCell(0)) + "; \n");
- } else {
- result.append("INSERT INTO `asset_tier` (`code`,`name`,`order`,`color`) VALUES ("
- + prepareCellData(row.getCell(0)) + "," + prepareCellData(row.getCell(1)) + ","
- + prepareCellData(row.getCell(2)) + "," + prepareCellData(row.getCell(3)) + "); \n");
- }
- }
- }
- return result;
- }
- private StringBuffer processAssetType(Sheet sheet) throws SQLException {
- Set<String> codes = getCodes("SELECT `code` as `key` FROM `asset_type`;");
- StringBuffer result = new StringBuffer();
- for (int i = 1; i <= sheet.getLastRowNum(); i++) {
- Row row = sheet.getRow(i);
- if (!isRowNullable(row)) {
- if (codes.contains(row.getCell(0).getStringCellValue())) {
- result.append("UPDATE `asset_type` SET `name` = " + prepareCellData(row.getCell(1)) + ", `display_order` = "
- + prepareCellData(row.getCell(2)) + " WHERE `code` = " + prepareCellData(row.getCell(0)) + "; \n");
- } else {
- result.append("INSERT INTO `asset_type` (`code`,`name`,`display_order`) VALUES ("
- + prepareCellData(row.getCell(0)) + "," + prepareCellData(row.getCell(1)) + ","
- + prepareCellData(row.getCell(2)) + "); \n");
- }
- }
- }
- return result;
- }
- private Set<String> getCodes(String sql) throws SQLException {
- Set<String> res = new HashSet<String>();
- ResultSet result = connection.createStatement().executeQuery(sql);
- while (result.next()) {
- res.add(result.getString("key"));
- }
- return res;
- }
- private String getIdByName(String sql) throws SQLException {
- ResultSet result = connection.createStatement().executeQuery(sql);
- while (result.next()) {
- return result.getString("id");
- }
- return null;
- }
- public static void main(String[] args) throws Exception {
- Workbook workbook = new XSSFWorkbook(
- new FileInputStream(
- "/home/stovbun/workspaces/LPL Reports/LPL Reports/java/com/apg/logic/dataimport/excel/LPL_Provided_Upload file_2-4-11.xlsx"));
- Reader reader = new Reader(true);
- reader.processWorkbook(workbook);
- reader.processTradeLogsWorkbook(workbook);
- // reader.makeDbChanges();
- reader.printParsedData();
- }
- private Map<String, StringBuffer> tables;
- private Map<String, Integer> updateCount;
- private Session session;
- private DbMan dbMan;
- private Map<String, Set<String>> problems;
- private Connection connection;
- public Reader() throws SQLException {
- super();
- tables = new TreeMap<String, StringBuffer>();
- updateCount = new TreeMap<String, Integer>();
- session = Session.getSession();
- dbMan = session.getDbMan();
- problems = new TreeMap<String, Set<String>>();
- connection = dbMan.getDefaultConnection();
- }
- public Reader(boolean b) throws SQLException {
- super();
- tables = new TreeMap<String, StringBuffer>();
- updateCount = new TreeMap<String, Integer>();
- problems = new TreeMap<String, Set<String>>();
- Properties properties = new Properties();
- properties.put("user", "lpl");
- // properties.put("password", "nfAu1yq3");
- properties.put("password", "aaa");
- properties.put("jdbcCompliantTruncation", "false");
- properties.put("zeroDateTimeBehavior", "convertToNull");
- connection = DriverManager.getConnection("jdbc:mysql://192.168.0.111:3306/lpl", properties);
- }
- private boolean isRowNullable(Row row) {
- if (row != null) {
- for (Cell cell : row) {
- if (prepareCellData(cell) != null) {
- return false;
- }
- }
- }
- return true;
- }
- private String prepareCellData(Cell cell) {
- try {
- if (cell == null) {
- return null;
- }
- switch (cell.getCellType()) {
- case Cell.CELL_TYPE_BLANK:
- return null;
- case Cell.CELL_TYPE_BOOLEAN:
- return String.valueOf(cell.getBooleanCellValue());
- case Cell.CELL_TYPE_ERROR:
- break;
- case Cell.CELL_TYPE_FORMULA:
- break;
- case Cell.CELL_TYPE_NUMERIC:
- if (HSSFDateUtil.isCellDateFormatted(cell) || HSSFDateUtil.isCellInternalDateFormatted(cell)) {
- return "'" + new SimpleDateFormat("yyyy-MM-dd hh:mm:ss", Locale.US).format(cell.getDateCellValue()) + "'";
- }
- double cellValue = cell.getNumericCellValue();
- double floor = Math.floor(cellValue);
- if (floor == cellValue || cellValue - floor < Math.pow(10, -5)) {
- return String.valueOf((int) cellValue);
- }
- return String.valueOf(cellValue);
- case Cell.CELL_TYPE_STRING:
- String stringCellValue = cell.getStringCellValue().trim();
- if (stringCellValue == null || stringCellValue.equals("null") || stringCellValue.equals("")) {
- return null;
- }
- return "'" + StringEscapeUtils.escapeSql(stringCellValue) + "'";
- }
- } catch (Exception e) {
- try {
- return String.valueOf(((int) cell.getNumericCellValue()));
- } catch (Exception e1) {
- String tableName = cell.getSheet().getSheetName();
- Set<String> tableProblems = problems.get(tableName);
- if (tableProblems == null) {
- tableProblems = new HashSet<String>();
- problems.put(tableName, tableProblems);
- }
- tableProblems.add("Can't parse data in Row:" + cell.getRowIndex() + " Column:" + cell.getColumnIndex()
- + " Cell value:" + cell);
- }
- }
- return null;
- }
- public void printParsedData() {
- for (String tableName : TABLE_LOAD_ORDER) {
- System.out
- .println("-- -----------------------------------------------------------------------------------------------------------");
- System.out.println(tables.get(tableName));
- }
- }
- public void makeDbChanges() {
- for (String tableName : TABLE_LOAD_ORDER) {
- try {
- StringBuffer string = tables.get(tableName);
- if (string != null && !"".equals(string.toString())) {
- updateCount.put(tableName, dbMan.executeNonQueryTransactional(string.toString()));
- }
- } catch (SQLException e) {
- Set<String> tableProblems = problems.get(tableName);
- if (tableProblems == null) {
- tableProblems = new HashSet<String>();
- problems.put(tableName, tableProblems);
- }
- tableProblems.add(e.getMessage());
- problems.put(tableName, tableProblems);
- }
- }
- }
- public Map<String, Integer> getUpdateCount() {
- return updateCount;
- }
- public Map<String, Set<String>> getProblems() {
- return problems;
- }
- /**
- * @return the tables
- */
- public Map<String, StringBuffer> getTables() {
- return tables;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement