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

prerna.reactor.prompt.AddPromptReactor Maven / Gradle / Ivy

The newest version!
package prerna.reactor.prompt;

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

import prerna.auth.User;
import prerna.auth.utils.AbstractSecurityUtils;
import prerna.prompt.PromptUtils;
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.execptions.SemossPixelException;
import prerna.sablecc2.om.nounmeta.NounMetadata;

public class AddPromptReactor extends AbstractReactor {
	
	public AddPromptReactor() {
		this.keysToGet = new String[] {ReactorKeysEnum.MAP.getKey()};
	}

	@Override
	public NounMetadata execute() {
		User user = this.insight.getUser();
		String userId = this.insight.getUserId();
		if (user == null) {
			NounMetadata noun = new NounMetadata(
					"User must be signed into an account in order to create a prompt", PixelDataType.CONST_STRING,
					PixelOperationType.ERROR, PixelOperationType.LOGGIN_REQUIRED_ERROR);
			SemossPixelException err = new SemossPixelException(noun);
			err.setContinueThreadOfExecution(false);
			throw err;
		}

		if (AbstractSecurityUtils.anonymousUsersEnabled()) {
			if (this.insight.getUser().isAnonymous()) {
				throwAnonymousUserError();
			}
		}
		
		organizeKeys();
		Map promptDetails = getPromptDetails();
		PromptUtils.addPrompt(promptDetails, userId);
		NounMetadata nm = new NounMetadata(true, PixelDataType.BOOLEAN);
		return nm;
	}
	
	
	private Map getPromptDetails() {
		GenRowStruct grs = this.store.getNoun(ReactorKeysEnum.MAP.getKey());
		if(grs != null && !grs.isEmpty()) {
			List mapNouns = grs.getNounsOfType(PixelDataType.MAP);
			if(mapNouns != null && !mapNouns.isEmpty()) {
				return (Map) mapNouns.get(0).getValue();
			}
		}
		
		List mapNouns = this.curRow.getNounsOfType(PixelDataType.MAP);
		if(mapNouns != null && !mapNouns.isEmpty()) {
			return (Map) mapNouns.get(0).getValue();
		}
		
		throw new NullPointerException("Must define the prompt to store it correctly");
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy