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.insights;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Vector;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
import org.quartz.CronExpression;
import com.google.common.io.Files;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import prerna.auth.utils.SecurityInsightUtils;
import prerna.auth.utils.SecurityProjectUtils;
import prerna.engine.api.IEngine;
import prerna.io.connector.couch.CouchException;
import prerna.io.connector.couch.CouchUtil;
import prerna.om.Pixel;
import prerna.om.PixelList;
import prerna.reactor.AbstractReactor;
import prerna.sablecc2.PixelUtility;
import prerna.sablecc2.om.GenRowStruct;
import prerna.sablecc2.om.PixelDataType;
import prerna.sablecc2.om.ReactorKeysEnum;
import prerna.sablecc2.om.nounmeta.NounMetadata;
import prerna.util.AssetUtility;
import prerna.util.EngineUtility;
import prerna.util.Utility;
import prerna.util.insight.InsightUtility;
import prerna.util.Constants;
public abstract class AbstractInsightReactor extends AbstractReactor {
private static final Logger classLogger = LogManager.getLogger(AbstractInsightReactor.class);
// used for saving a base insight
protected static final String IMAGE_THEME_FILE = "insight_theme.json";
protected static final String IMAGE_NAME = "image.png";
protected static final String CACHEABLE = "cache";
protected static final String CACHE_MINUTES = "cacheMinutes";
protected static final String CACHE_CRON = "cacheCron";
protected static final String CACHE_ENCRYPT = "cacheEncrypt";
protected static final String ENCODED_KEY = "encoded";
protected static final String PIPELINE_FILE = "pipeline.json";
protected static final String USE_EXISTING_OPEN = "useExistingIfOpen";
// used for jdbc
protected static final String SCHEMA_NAME = "schemaName";
public static String USER_SPACE_KEY = "USER";
public static final String SPACE = ReactorKeysEnum.SPACE.getKey();
protected String getProject() {
String projectId = null;
// look at all the ways the insight panel could be passed
// look at store if it was passed in
GenRowStruct genericEngineGrs = this.store.getNoun(ReactorKeysEnum.PROJECT.getKey());
if(genericEngineGrs != null && !genericEngineGrs.isEmpty()) {
projectId = (String) genericEngineGrs.get(0);
}
if(projectId == null) {
// see if it is in the curRow
// if it was passed directly in as a variable
List stringNouns = this.curRow.getNounsOfType(PixelDataType.CONST_STRING);
if(stringNouns != null && !stringNouns.isEmpty()) {
return (String) stringNouns.get(0).getValue();
}
}
// LEGACY
// LEGACY
// LEGACY
// LEGACY
if(projectId == null) {
genericEngineGrs = this.store.getNoun("app");
if(genericEngineGrs != null && !genericEngineGrs.isEmpty()) {
projectId = (String) genericEngineGrs.get(0);
}
}
if(projectId == null) {
// well, you are out of luck
throw new IllegalArgumentException("Need to define the project where the insight currently exists");
}
projectId = SecurityProjectUtils.testUserProjectIdForAlias(this.insight.getUser(), projectId);
return projectId;
}
/**
* This can either be passed specifically using the insightName key
* Or it is the second input in a list of values
* Save(engineName, insightName)
* @return
*/
protected String getInsightName() {
// look at all the ways the insight panel could be passed
// look at store if it was passed in
GenRowStruct genericEngineGrs = this.store.getNoun(ReactorKeysEnum.INSIGHT_NAME.getKey());
if(genericEngineGrs != null && !genericEngineGrs.isEmpty()) {
return (String) genericEngineGrs.get(0);
}
// see if it is in the curRow
// if it was passed directly in as a variable
// this will be the second input! (i.e. index 1)
List stringNouns = this.curRow.getNounsOfType(PixelDataType.CONST_STRING);
if(stringNouns != null && !stringNouns.isEmpty()) {
return (String) stringNouns.get(1).getValue();
}
// well, you are out of luck
return null;
}
protected String getRdbmsId() {
// see if it was passed directly in with the lower case key ornaments
GenRowStruct genericIdGrs = this.store.getNoun(ReactorKeysEnum.ID.getKey());
if(genericIdGrs != null && !genericIdGrs.isEmpty()) {
return genericIdGrs.get(0).toString();
}
// well, you are out of luck
throw new IllegalArgumentException("Need to define the app where the insight currently exists");
}
protected boolean getGlobal() {
// see if it was passed directly in with the lower case key ornaments
GenRowStruct genericIdGrs = this.store.getNoun(ReactorKeysEnum.GLOBAL.getKey());
if(genericIdGrs != null && !genericIdGrs.isEmpty()) {
return (boolean) genericIdGrs.get(0);
}
// well, you are out of luck
return false;
}
protected Boolean getUserDefinedCacheable() {
// see if it was passed directly in with the lower case key ornaments
GenRowStruct genericIdGrs = this.store.getNoun(CACHEABLE);
if(genericIdGrs != null && !genericIdGrs.isEmpty()) {
return (boolean) genericIdGrs.get(0);
}
// well, you are out of luck
return null;
}
protected Integer getUserDefinedCacheMinutes() {
// see if it was passed directly in with the lower case key ornaments
GenRowStruct genericIdGrs = this.store.getNoun(CACHE_MINUTES);
if(genericIdGrs != null && !genericIdGrs.isEmpty()) {
return (int) genericIdGrs.get(0);
}
// well, you are out of luck
return null;
}
protected String getUserDefinedCacheCron() {
// see if it was passed directly in with the lower case key ornaments
GenRowStruct genericIdGrs = this.store.getNoun(CACHE_CRON);
if(genericIdGrs != null && !genericIdGrs.isEmpty()) {
String cronExpression = (String) genericIdGrs.get(0);
if(cronExpression != null) {
cronExpression = cronExpression.trim();
if(cronExpression.isEmpty()) {
return "";
}
if (!CronExpression.isValidExpression(cronExpression)) {
throw new IllegalArgumentException("Cron expression '" + cronExpression + "' is not of a valid format");
}
return cronExpression;
}
}
// well, you are out of luck
return null;
}
protected Boolean getUserDefinedCacheEncrypt() {
// see if it was passed directly in with the lower case key ornaments
GenRowStruct genericIdGrs = this.store.getNoun(CACHE_ENCRYPT);
if(genericIdGrs != null && !genericIdGrs.isEmpty()) {
return (boolean) genericIdGrs.get(0);
}
// well, you are out of luck
return null;
}
protected String getUrl() {
// see if it was passed directly in with the lower case key ornaments
GenRowStruct genericIdGrs = this.store.getNoun(ReactorKeysEnum.URL.getKey());
if(genericIdGrs != null && !genericIdGrs.isEmpty()) {
return genericIdGrs.get(0).toString();
}
// well, you are out of luck
return null;
}
protected List getRecipe() {
// it must be passed directly into its own grs
GenRowStruct genericRecipeGrs = this.store.getNoun(ReactorKeysEnum.RECIPE.getKey());
if(genericRecipeGrs != null && !genericRecipeGrs.isEmpty()) {
int size = genericRecipeGrs.size();
List recipe = new Vector<>(size);
for(int i = 0; i < size; i++) {
recipe.add(genericRecipeGrs.get(i).toString());
}
return recipe;
}
// well, you are out of luck
return null;
}
protected String getLayout() {
// it must be passed directly into its own grs
GenRowStruct genericLayoutGrs = this.store.getNoun(ReactorKeysEnum.LAYOUT_KEY.getKey());
if(genericLayoutGrs != null && !genericLayoutGrs.isEmpty()) {
return genericLayoutGrs.get(0).toString();
}
// TODO: there can be more than 1 layout given clone...
return "grid";
}
/**
*
* @return location of an image file
*/
protected String getImage() {
GenRowStruct genericBaseURLGrs = this.store.getNoun(ReactorKeysEnum.IMAGE.getKey());
if (genericBaseURLGrs != null && !genericBaseURLGrs.isEmpty()) {
String image = genericBaseURLGrs.get(0).toString();
return image;
}
// well, you are out of luck
return null;
}
/**
* Get params needed for execution
* @return
*/
@Deprecated
protected Object getExecutionParams() {
GenRowStruct paramGrs = this.store.getNoun(ReactorKeysEnum.PARAM_KEY.getKey());
if(paramGrs == null || paramGrs.isEmpty()) {
return null;
}
if(paramGrs.size() == 1) {
return paramGrs.get(0);
} else {
List