/** * */ package org.gcube.vremanagement.executor.configuration.jsonbased; import java.text.ParseException; import java.util.HashMap; import java.util.Map; import org.gcube.vremanagement.executor.SmartExecutorInitializator; import org.gcube.vremanagement.executor.api.types.LaunchParameter; import org.gcube.vremanagement.executor.api.types.Scheduling; import org.gcube.vremanagement.executor.exception.ScopeNotMatchException; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/ * */ public class JSONLaunchParameter extends LaunchParameter { private static Logger logger = LoggerFactory.getLogger(JSONLaunchParameter.class); public static final String PLUGIN_NAME = "pluginName"; public static final String PLUGIN_CAPABILITIES = "pluginCapabilites"; public static final String INPUTS = "inputs"; public static final String SCHEDULING = "scheduling"; public static final String USED_BY = "usedBy"; public static final String SCOPE = "SCOPE"; /** * Contains the GCOREEndpoint (aka Running Instance) ID */ protected String usedBy; protected String scope; @SuppressWarnings("unused") private JSONLaunchParameter(){} public JSONLaunchParameter(String pluginName, Map inputs) { super(pluginName, inputs); } public JSONLaunchParameter(String pluginName, Map pluginCapabilities, Map inputs) { super(pluginName, pluginCapabilities, inputs); this.scope = SmartExecutorInitializator.getScopeFromToken(); } public JSONLaunchParameter(String pluginName, Map inputs, Scheduling scheduling) throws ParseException { super(pluginName, inputs, scheduling); this.scope = SmartExecutorInitializator.getScopeFromToken(); } public JSONLaunchParameter(String pluginName, Map pluginCapabilities, Map inputs, Scheduling scheduling) throws ParseException { super(pluginName, pluginCapabilities, inputs, scheduling); this.scope = SmartExecutorInitializator.getScopeFromToken(); } public JSONLaunchParameter(LaunchParameter parameter) throws ParseException { super(parameter.getPluginName(), parameter.getPluginCapabilities(), parameter.getInputs(), parameter.getScheduling()); this.scheduling = new JSONScheduling(parameter.getScheduling()); this.scope = SmartExecutorInitializator.getScopeFromToken(); } public JSONLaunchParameter(JSONObject jsonObject) throws JSONException, ParseException, ScopeNotMatchException { super(); this.pluginName = jsonObject.getString(PLUGIN_NAME); this.pluginCapabilities = null; if(jsonObject.has(PLUGIN_CAPABILITIES)){ this.pluginCapabilities = new HashMap(); JSONObject capabilities = jsonObject.getJSONObject(PLUGIN_CAPABILITIES); JSONArray names = capabilities.names(); for(int j=0; j(); JSONObject inputsJsonObject = jsonObject.getJSONObject(INPUTS); JSONArray names = inputsJsonObject.names(); for(int j=0; j