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.om;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.google.gson.Gson;
import prerna.algorithm.api.ITableDataFrame;
import prerna.query.querystruct.SelectQueryStruct;
import prerna.query.querystruct.filters.GenRowFilters;
import prerna.query.querystruct.selectors.IQuerySort;
import prerna.reactor.export.IFormatter;
import prerna.sablecc2.om.task.options.TaskOptions;
import prerna.util.gson.GsonUtility;
public class InsightPanel {
private static Gson GSON = GsonUtility.getDefaultGson();
// unique id for the panel
private String panelId;
// the sheet this panel sits in
private String sheetId;
// label for the panel
private String panelLabel;
// current UI view for the panel
private String view;
// active view options
private String viewOptions;
// rendered view options
// for things like KPI
private String renderedViewOptions;
private List dynamicVars;
// panel configuration - opacity, etc.
private Map config;
// view options on the current view
private transient Map> viewOptionsMap;
// state held for UI options on the panel
private transient Map ornaments;
// state held for events on the panel
private transient Map events;
// set of filters that are only applied to this panel
private transient GenRowFilters grf;
// set the sorts on the panel
private transient List orderBys;
// list of comments added to the panel
// key is the id pointing to the info on the comment
// the info on the comment also contains the id
private transient Map> comments;
// store the color by value rules for the panel
private transient List colorByValue;
// last qs
private transient SelectQueryStruct lastQs = null;
// last task options
private transient TaskOptions lastTaskOptions = null;
// last formatter
private transient IFormatter lastFormatter = null;
// mapping from layer to task
private transient Map layerTaskOption = null;
private transient Map layerQueryStruct = null;
private transient Map layerFormatter = null;
// the default # to collect from tasks on this panel
private int numCollect = 2000;
// set temporary filter model state frame
private transient ITableDataFrame tempFitlerModelFrame;
// set temporary filter model state
private transient GenRowFilters tempFilterModelGrf;
public InsightPanel(String panelId, String sheetId) {
this.panelId = panelId;
this.sheetId = sheetId;
this.viewOptionsMap = new HashMap>();
this.config = new HashMap();
this.ornaments = new HashMap();
this.events = new HashMap();
this.comments = new HashMap>();
this.colorByValue = new ArrayList();
this.grf = new GenRowFilters();
this.orderBys = new ArrayList();
this.tempFilterModelGrf = new GenRowFilters();
}
/**
* Merge new panel configuration options into the existing panel config map
* This will merge child maps together if possible
* @param config
*/
public void addConfig(Map newPanelConfig) {
recursivelyMergeMaps(this.config, newPanelConfig);
}
/**
* Get the panel config
* @return
*/
public Map getConfig() {
return this.config;
}
/**
* Get the color by value rules
* @return
*/
public List getColorByValue() {
return this.colorByValue;
}
/**
* Add a new cbv rule
* @param cbv
*/
public void addColorByValue(ColorByValueRule cbv) {
// if the name is the same
// we will override
// we defined the equals to do this
if(this.colorByValue.contains(cbv)) {
this.colorByValue.remove(cbv);
}
this.colorByValue.add(cbv);
}
/**
* Get a specific color by value rule
* @param ruleId
* @return
*/
public ColorByValueRule getColorByValue(String ruleId) {
for(ColorByValueRule cbv : this.colorByValue) {
if(cbv.getId().equals(ruleId)) {
return cbv;
}
}
return null;
}
/**
* Delete a specific color by value rule
* @param ruleId
* @return
*/
public boolean removeColorByValue(String ruleId) {
for(int i = 0; i < this.colorByValue.size(); i++) {
ColorByValueRule cbv = this.colorByValue.get(i);
if(cbv.getId().equals(ruleId)) {
this.colorByValue.remove(i);
return true;
}
}
return false;
}
/**
* Get the ornaments on the panel
* @return
*/
public Map getOrnaments() {
return this.ornaments;
}
/**
* Merge new ornaments into the existing ornament map
* This will merge child maps together if possible
* @param ornaments
*/
public void addOrnaments(Map newOrnaments) {
recursivelyMergeMaps(this.ornaments, newOrnaments);
}
/**
* Remove all ornaments downstream from a given traversal path
* @param traversal
* @return
*/
public boolean removeOrnament(String traversal) {
return removePathFromMap(this.ornaments, traversal);
}
/**
* Remove all ornaments
*/
public void resetOrnaments() {
this.ornaments.clear();
}
/**
* Get the events on the panel
* @return
*/
public Map getEvents() {
return this.events;
}
/**
* Merge new event info into the existing event map
* This will merge child maps together if possible
* @param ornaments
*/
public void addEvents(Map newEventInfo) {
recursivelyMergeMaps(this.events, newEventInfo);
}
/**
* Remove all event info downstream from a given traversal path
* @param traversal
* @return
*/
public boolean removeEvent(String traversal) {
return removePathFromMap(this.events, traversal);
}
/**
* Remove all event info
*/
public void resetEvents() {
this.events.clear();
}
/**
* traversalPath is a period delimited key traversal to go through the ornaments object
* @param traversalPath
* @return
*/
public Object getMapInput(Map map, String traversalPath) {
String[] traversal = traversalPath.split("\\.");
// check first key
if(!map.containsKey(traversal[0])) {
return null;
}
Object innerObj = map.get(traversal[0]);
// go to the necessary depth required
int depth = traversal.length;
for(int i = 1; i < depth; i++) {
if(innerObj instanceof Map) {
Map innerMap = (Map) innerObj;
if(innerMap.containsKey(traversal[i])) {
innerObj = innerMap.get(traversal[i]);
} else {
// well, can't find this...
// just return empty
return null;
}
}
else {
// well, can't find this...
// just return empty
return null;
}
}
return innerObj;
}
/**
* Return the map of additional formatting stored on the panel for export functionality
* @param formatDatavalues
* @return
*/
public Map> getPanelFormatValues() {
Map> res = new HashMap>();
Object formatDataValues = getMapInput(this.ornaments, "tools.shared.formatDataValues.formats");
if (formatDataValues != null && formatDataValues instanceof List) {
List