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.
package prerna.reactor;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Vector;
import org.apache.commons.text.StringSubstitutor;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.codehaus.plexus.util.StringUtils;
import prerna.algorithm.api.ITableDataFrame;
import prerna.auth.utils.SecurityEngineUtils;
import prerna.auth.utils.SecurityQueryUtils;
import prerna.engine.api.IHeadersDataRow;
import prerna.om.Insight;
import prerna.om.ThreadStore;
import prerna.reactor.job.JobReactor;
import prerna.sablecc2.comm.InMemoryConsole;
import prerna.sablecc2.om.GenRowStruct;
import prerna.sablecc2.om.NounStore;
import prerna.sablecc2.om.PixelDataType;
import prerna.sablecc2.om.PixelOperationType;
import prerna.sablecc2.om.ReactorKeysEnum;
import prerna.sablecc2.om.execptions.SemossPixelException;
import prerna.sablecc2.om.nounmeta.NounMetadata;
public abstract class AbstractReactor implements IReactor {
private static final Logger classLogger = LogManager.getLogger(AbstractReactor.class);
// get the directory separator
public static final String DIR_SEPARATOR = "/";//java.nio.file.FileSystems.getDefault().getSeparator();
protected static final String ALL_NOUN_STORE = "all";
protected Insight insight = null;
protected PixelPlanner planner = null;
// keep track of parent reactor and all children reactors
protected IReactor parentReactor = null;
protected Vector childReactor = new Vector();
// keep track of the original signature passed in
// and the signature when we do basic replacements in the pixel
protected String signature = null;
protected String originalSignature = null;
protected String operationName = null;
protected String curNoun = null;
protected NounStore store = null;
protected IReactor.TYPE type = IReactor.TYPE.FLATMAP;
protected IReactor.STATUS status = null;
protected GenRowStruct curRow = null;
protected String reactorName = "";
protected String [] asName = null;
protected Vector outputFields = null;
protected Vector outputTypes = null;
@Deprecated
protected Hashtable propStore = new Hashtable();
protected Lambda runner = null;
protected String[] defaultOutputAlias;
boolean evaluate = false;
protected String jobId;
// all the different keys to get
public String[] keysToGet = new String[]{"no keys defined"};
// which of these are optional : 1 means required, 0 means optional
public int[] keyRequired = null;
// single or multi if 1 multi if 0 single
public int[] keyMulti = null;
// defaults if one exists
// this I am not so sure.. but let us try
public Object[] keyDefaults = new Object[]{};
public Map keyValue = new Hashtable();
public AbstractReactor() {
}
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
/*
* Methods for merging up the noun store across reactors
*/
@Override
public void mergeUp() {
// merge this reactor into the parent reactor
if(parentReactor != null) {
NounMetadata data = new NounMetadata(this, PixelDataType.LAMBDA);
this.parentReactor.getCurRow().add(data);
}
}
@Override
public List getInputs() {
List inputs = new Vector();
// grab all the nouns in the noun store
Set nounKeys = this.getNounStore().nounRow.keySet();
for(String nounKey : nounKeys) {
// grab the genrowstruct for the noun
// and add its vector to the inputs list
GenRowStruct struct = this.getNounStore().getNoun(nounKey);
inputs.addAll(struct.vector);
}
// we also need to account for some special cases
// when we have a filter reactor
// it doesn't get added as an op
// so we need to go through the child of this reactor
// and if it has a filter
// add its nouns to the inputs for this reactor
for(IReactor child : childReactor) {
List childInputs = child.getInputs();
if(childInputs != null) {
inputs.addAll(childInputs);
}
}
return inputs;
}
@Override
public List getOutputs() {
//Default operation for the abstract is to return the asName aliases as the outputs
if(this.asName != null) {
List outputs = new Vector<>();
for(String alias : this.asName) {
NounMetadata aliasNoun = new NounMetadata(alias, PixelDataType.ALIAS);
outputs.add(aliasNoun);
}
return outputs;
}
return null;
}
@Override
public void updatePlan() {
// at this point, the inner child is still just part of a
// larger parent
// we only need to update the plan when the full pixel
// is loaded
if(this.parentReactor != null) {
return;
}
// this is me testing on 8/14
// not going to push this yet... will come back later to
// figuring out the right logic for this
// // since we use reactors to capture state at various points
// // like a reactor to generate a Map properly, etc.
// // there are not really ones we need to put in the plan
// // since they are in reality just constants
// if(this.signature == null) {
// return;
// }
// get the inputs and outputs
// and add this to the plan using the signature
// of the reactor
List inputs = this.getInputs();
List outputs = this.getOutputs();
if(inputs != null && !inputs.isEmpty()) {
// this is me testing on 8/14
// not going to push this yet... will come back later to
// figuring out the right logic for this
// this.planner.addInputs(this.signature, inputs);
List strInputs = new ArrayList();
for(int inputIndex = 0; inputIndex < inputs.size(); inputIndex++) {
NounMetadata noun = inputs.get(inputIndex);
PixelDataType type = noun.getNounType();
if(type == PixelDataType.COLUMN) {
strInputs.add(noun.getValue() + "");
}
}
this.planner.addInputs(this.signature, strInputs, TYPE.FLATMAP);
}
if(outputs != null && !outputs.isEmpty()) {
// this is me testing on 8/14
// not going to push this yet... will come back later to
// figuring out the right logic for this
// this.planner.addOutputs(this.signature, outputs);
List strOutputs = new Vector();
for(int outputIndex = 0; outputIndex < outputs.size(); outputIndex++) {
NounMetadata noun = outputs.get(outputIndex);
PixelDataType type = noun.getNounType();
if(type == PixelDataType.COLUMN) {
strOutputs.add(noun.getValue() + "");
}
}
this.planner.addOutputs(this.signature, strOutputs, TYPE.FLATMAP);
}
}
public Map> getStoreMap() {
Map> inputMap = new HashMap<>();
for(int keyIndex = 0; keyIndex < keysToGet.length; keyIndex++) {
String key = keysToGet[keyIndex];
if(this.store.getNoun(key) != null) {
GenRowStruct grs = this.store.getNoun(key);
if(!grs.isEmpty()) {
List