
prerna.reactor.security.GetInsightsReactor Maven / Gradle / Ivy
The newest version!
package prerna.reactor.security;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Vector;
import prerna.auth.utils.SecurityInsightUtils;
import prerna.auth.utils.SecurityProjectUtils;
import prerna.engine.api.IRawSelectWrapper;
import prerna.query.querystruct.selectors.QueryColumnOrderBySelector;
import prerna.reactor.AbstractReactor;
import prerna.sablecc2.om.GenRowStruct;
import prerna.sablecc2.om.PixelDataType;
import prerna.sablecc2.om.PixelOperationType;
import prerna.sablecc2.om.ReactorKeysEnum;
import prerna.sablecc2.om.nounmeta.NounMetadata;
import prerna.util.sql.AbstractSqlQueryUtil;
public class GetInsightsReactor extends AbstractReactor {
private static List META_KEYS_LIST = new Vector();
static {
META_KEYS_LIST.add("description");
META_KEYS_LIST.add("tag");
}
public GetInsightsReactor() {
this.keysToGet = new String[] { ReactorKeysEnum.PROJECT.getKey(), ReactorKeysEnum.FILTER_WORD.getKey(),
ReactorKeysEnum.LIMIT.getKey(), ReactorKeysEnum.OFFSET.getKey(),
ReactorKeysEnum.ONLY_FAVORITES.getKey(), ReactorKeysEnum.SORT.getKey(), ReactorKeysEnum.META_FILTERS.getKey(),
ReactorKeysEnum.NO_META.getKey() };
}
@Override
public NounMetadata execute() {
organizeKeys();
GenRowStruct projectFilterGrs = this.store.getNoun(this.keysToGet[0]);
List warningNouns = new Vector<>();
// get list of engineIds if user has access
List projectFilters = null;
if (projectFilterGrs != null && !projectFilterGrs.isEmpty()) {
projectFilters = new Vector();
for (int i = 0; i < projectFilterGrs.size(); i++) {
String pFilter = projectFilterGrs.get(i).toString();
pFilter = SecurityProjectUtils.testUserProjectIdForAlias(this.insight.getUser(), pFilter);
if (SecurityProjectUtils.userCanViewProject(this.insight.getUser(), pFilter)) {
projectFilters.add(pFilter);
} else {
// store warnings
warningNouns.add(NounMetadata.getWarningNounMessage(pFilter + " does not exist or user does not have access to project."));
}
}
}
String searchTerm = this.keyValue.get(this.keysToGet[1]);
String limit = this.keyValue.get(this.keysToGet[2]);
String offset = this.keyValue.get(this.keysToGet[3]);
Boolean favoritesOnly = Boolean.parseBoolean(this.keyValue.get(this.keysToGet[4]));
String sortCol = this.keyValue.get(this.keysToGet[5]);
if(sortCol == null) {
sortCol = "name";
}
Boolean noMeta = Boolean.parseBoolean(this.keyValue.get(ReactorKeysEnum.NO_META.getKey()));
// we only have 2 options for sorting
// based on name and last modified date
// these values are based on the projections in the query
QueryColumnOrderBySelector sortBy = null;
if(sortCol.equalsIgnoreCase("date")) {
sortBy = new QueryColumnOrderBySelector("last_modified_on", "desc");
} else {
sortBy = new QueryColumnOrderBySelector("low_name");
}
// get results and meta (if available, otherwise null)
Map insightMetadataFilter = getMetaMap();
// method handles if filters are null or not
List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy