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.om;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.Vector;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import prerna.auth.AuthProvider;
import prerna.auth.User;
import prerna.cache.CacheFactory;
import prerna.comments.InsightComment;
import prerna.comments.InsightCommentHelper;
import prerna.ds.h2.H2Frame;
import prerna.sablecc.PKQLRunner;
import prerna.sablecc2.PixelRunner;
import prerna.sablecc2.om.PixelDataType;
import prerna.sablecc2.om.PixelOperationType;
import prerna.sablecc2.om.VarStore;
import prerna.sablecc2.om.execptions.SemossPixelException;
import prerna.sablecc2.om.nounmeta.NounMetadata;
import prerna.sablecc2.om.task.TaskStore;
import prerna.sablecc2.reactor.frame.r.util.AbstractRJavaTranslator;
import prerna.sablecc2.reactor.frame.r.util.RJavaTranslatorFactory;
import prerna.sablecc2.reactor.imports.FileMeta;
import prerna.sablecc2.reactor.job.JobReactor;
import prerna.sablecc2.reactor.workflow.GetOptimizedRecipeReactor;
import prerna.ui.components.playsheets.datamakers.IDataMaker;
import prerna.util.ga.GATracker;
public class Insight {
private static final Logger LOGGER = LogManager.getLogger(Insight.class.getName());
// need to account for multiple frames to be saved on the insight
// we will use a special key
public static transient final String CUR_FRAME_KEY = "$CUR_FRAME_KEY";
// this is the id it is assigned within the InsightCache
// it varies from one instance of an insight to another instance of the same insight
protected String insightId;
// new user object
protected User user;
protected String insightName;
// if this is a saved insight
protected String rdbmsId;
protected String engineId;
protected String engineName;
// list to store the pixels that make this insight
private List pixelList;
// keep a map to store various properties
// new variable assignments in pixel are also stored here
private transient VarStore varStore = new VarStore();
// this is the store holding all current tasks (iterators) that are run on the
// data frames within this insight
private transient TaskStore taskStore;
// we will keep a central rJavaTranslator for the entire insight
// that can be referenced through all the reactors
// since reactors have access to insight
private transient AbstractRJavaTranslator rJavaTranslator;
/*
* TODO: find a better way of doing this
* keep a list of all the files that are used to create this insight
* this is important so we can save those files into full databases
* if the insight is saved
*/
private transient List filesUsedInInsight = new Vector();
private transient Map exportFiles = new Hashtable();
// insight comments
private transient LinkedList insightCommentList = null;
// this is the store holding information around the panels associated with this insight
private transient Map insightPanels = new LinkedHashMap();
private transient Map insightOrnament = new Hashtable();
// old - for pkql
@Deprecated
private transient Map> pkqlVarMap = new Hashtable>();
// need a way to shift between old and new insights...
// dont know how else to shift to this
protected boolean isOldInsight = false;
// GA Values
private String prevType = null;
private String thisPrevExpression = null;
////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////// START CONSTRUCTORS //////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////
/**
* Create an empty insight
*/
public Insight() {
loadDefaultSettings();
}
/**
* Open a saved insight
* @param engineId
* @param rdbmsId
*/
public Insight(String engineId, String engineName, String rdbmsId) {
this();
this.engineId = engineId;
this.engineName = engineName;
this.rdbmsId = rdbmsId;
}
private void loadDefaultSettings() {
this.pixelList = new Vector();
this.taskStore = new TaskStore();
this.insightId = UUID.randomUUID().toString();
// since we require the use of ids on the databases
// we will add the local alias to the global unique id
// Map aliasToId = MasterDatabaseUtility.getEngineAliasToId();
// for(String alias : aliasToId.keySet()) {
// this.varStore.put(alias, new NounMetadata(aliasToId.get(alias), PixelDataType.CONST_STRING));
// }
}
////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////// END CONSTRUCTORS ///////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////// START EXECUTION OF PIXEL //////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////
public synchronized PixelRunner runPixel(String pixelString) {
PixelRunner runner = getPixelRunner();
LOGGER.info("Running >>> " + pixelString);
runner.runPixel(pixelString, this);
return runner;
}
public synchronized PixelRunner runPixel(List pixelList) {
PixelRunner runner = getPixelRunner();
int size = pixelList.size();
if(size == 0) {
// set the insight in the runner as it is used
// to flush to FE
runner.setInsight(this);
} else {
for(int i = 0; i < size; i++) {
String pixelString = pixelList.get(i);
LOGGER.info("Running >>> " + pixelString);
try {
runner.runPixel(pixelString, this);
} catch(SemossPixelException e) {
if(!e.isContinueThreadOfExecution()) {
break;
}
}
}
}
return runner;
}
// run a new pixel routine
// public synchronized Map runPixel(String pixelString) {
// PixelRunner runner = getPixelRunner();
// LOGGER.info("Running >>> " + pixelString);
// runner.runPixel(pixelString, this);
// return collectPixelData(runner);
// }
//
// // run a new list of pixel routines
// public synchronized Map runPixel(List pixelList) {
// PixelRunner runner = getPixelRunner();
// int size = pixelList.size();
// for(int i = 0; i < size; i++) {
// String pixelString = pixelList.get(i);
// LOGGER.info("Running >>> " + pixelString);
// try {
// runner.runPixel(pixelString, this);
// } catch(SemossPixelException e) {
// if(!e.isContinueThreadOfExecution()) {
// break;
// }
// }
// }
// return collectPixelData(runner);
// }
// /**
// *
// * @param runner
// * @return
// */
// private Map collectPixelData(PixelRunner runner) {
// // get the return values
// List resultList = runner.getResults();
// // get the expression which created the return
// // this matches with the above by index
// List pixelStrings = runner.getPixelExpressions();
// List isMeta = runner.isMeta();
// Map encodedTextToOriginal = runner.getEncodedTextToOriginal();
// boolean invalidSyntax = runner.isInvalidSyntax();
// List