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

prerna.reactor.security.SetInsightMetakeyOptionsReactor Maven / Gradle / Ivy

The newest version!
package prerna.reactor.security;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import prerna.auth.User;
import prerna.auth.utils.SecurityAdminUtils;
import prerna.auth.utils.SecurityInsightUtils;
import prerna.reactor.insights.AbstractInsightReactor;
import prerna.sablecc2.om.GenRowStruct;
import prerna.sablecc2.om.PixelDataType;
import prerna.sablecc2.om.nounmeta.NounMetadata;

public class SetInsightMetakeyOptionsReactor extends AbstractInsightReactor {
	
	private static final String METAOPTIONS = "metaoptions";
	
	public SetInsightMetakeyOptionsReactor() {
		this.keysToGet = new String[]{METAOPTIONS};
	}

	@Override
	public NounMetadata execute() {
		User user = this.insight.getUser();
		boolean res = false;
		SecurityAdminUtils adminUtils = SecurityAdminUtils.getInstance(user);
		if(adminUtils == null) {
			throw new IllegalArgumentException("User is not an admin.");
		} else {
			organizeKeys();
			List> metaoptions = getMetaOptions();
			if (metaoptions==null || metaoptions.isEmpty()) {
				throw new IllegalArgumentException("Must provide a set of metadata values to store.");
			}
			res = SecurityInsightUtils.updateMetakeyOptions(metaoptions);
		}
		NounMetadata noun = new NounMetadata(res, PixelDataType.BOOLEAN);
		if (res) {
			noun.addAdditionalReturn(NounMetadata.getSuccessNounMessage("Successfully updated the new metakey for metakey options"));
		} else {
			noun.addAdditionalReturn(NounMetadata.getErrorNounMessage("Did not update metakey options. Please check your inputs and try again."));
		}
		return noun;
	}
	
	private List> getMetaOptions() {
		GenRowStruct mapGrs = this.store.getNoun(METAOPTIONS);
		if(mapGrs != null && !mapGrs.isEmpty()) {
			List mapInputs = mapGrs.getNounsOfType(PixelDataType.MAP);
			if(mapInputs != null && !mapInputs.isEmpty()) {
				List> res = new ArrayList<>();
				for (int i=0; i) mapInputs.get(i).getValue());
				}
				return res;
			}
		}
		List mapInputs = this.curRow.getNounsOfType(PixelDataType.MAP);
		if(mapInputs != null && !mapInputs.isEmpty()) {
			List> res = new ArrayList<>();
			for (int i=0; i) mapInputs.get(i).getValue());
			}
			return res;
		}
		return null;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy