All Downloads are FREE. Search and download functionalities are using the official Maven repository.

prerna.reactor.workflow.ModifyInsightDatasourceReactor Maven / Gradle / Ivy

The newest version!
package prerna.reactor.workflow;

import java.util.List;
import java.util.Map;
import java.util.Vector;

import prerna.om.Insight;
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.insight.InsightUtility;

public class ModifyInsightDatasourceReactor extends AbstractReactor {

	public ModifyInsightDatasourceReactor() {
		this.keysToGet = new String[]{ReactorKeysEnum.OPTIONS.getKey()};
	}
	
	@Override
	public NounMetadata execute() {
		List> replacementOptions = getOptions();

		List recipe = this.insight.getPixelList().getPixelRecipe();
		StringBuilder b = new StringBuilder();
		for(String s : recipe) {
			b.append(s);
		}
		String fullRecipe = b.toString();
		
		// make a copy of the insight
		// so we do not mess up the state of execution
		Insight cInsight = new Insight();
		cInsight.setInsightId(this.insight.getInsightId());
		InsightUtility.transferDefaultVars(this.insight, cInsight);
		List newRecipe = PixelUtility.modifyInsightDatasource(cInsight, fullRecipe, replacementOptions);
		
		return new NounMetadata(newRecipe, PixelDataType.CUSTOM_DATA_STRUCTURE);
	}
	
	/**
	 * Get the replacement information
	 * @return
	 */
	public List> getOptions() {
		List> ret = new Vector>();
		
		GenRowStruct options = this.store.getNoun(this.keysToGet[0]);
		if(options != null && !options.isEmpty()) {
			int size = options.size();
			for(int i = 0; i < size; i++) {
				ret.add( (Map) options.get(i));
			}
			return ret;
		}
		
		int size = this.curRow.size();
		for(int i = 0; i < size; i++) {
			ret.add( (Map) this.curRow.get(i));
		}
		return ret;
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy