package com.smtaiserver.smtaiserver.javaai.jsonflow.node; import java.util.List; import com.smtaiserver.smtaiserver.core.SMTAIServerApp; import com.smtaiserver.smtaiserver.javaai.SMTJavaAIError; import com.smtaiserver.smtaiserver.javaai.jsonflow.core.SMTJsonFlowExecArg; import com.smtaiserver.smtaiserver.javaai.jsonflow.core.SMTJsonFlowManager; import com.smtaiserver.smtaiserver.javaai.jsonflow.core.SMTJsonFlowNodeOnlyOutput; import com.smtservlet.util.Json; import com.smtservlet.util.SMTStatic; public class SMTJsonFlowNodeTextResource extends SMTJsonFlowNodeOnlyOutput { private String _resKey; private String _resValue = ""; @Override public void initInstane(SMTJsonFlowManager manager, Json jsonNode) throws Exception { super.initInstane(manager, jsonNode); List jsonGroupParams = jsonNode.getJsonPath("data|group_params|", false).asJsonList(); for(Json jsonParams : jsonGroupParams) { String type = jsonParams.getJsonPath("params|0|type", false).asString(); if("input".equals(type)) { _resKey = jsonParams.getJsonPath("params|0|value", false).asString(); } else if("resource_value".equals(type)) { _resValue = jsonParams.getJsonPath("params|0|value", false).asString(); } } try { _resValue = SMTAIServerApp.getApp().esprimaJs2ASTStr(_resValue); } catch(Exception ex) { throw new Exception("esprima flow node js error for : " + this.getTitle() + "(" + this.getId() + ")", ex); } } @Override public void afterInstance() throws Exception { super.afterInstance(); if(SMTStatic.isNullOrEmpty(_resKey)) throw new Exception("text resource _resKey not define"); if(SMTStatic.isNullOrEmpty(_resValue)) throw new Exception("text resource _resKey not define"); } @Override public SMTJavaAIError executeFlowNode(SMTJsonFlowExecArg execArg) throws Exception { execArg._jsonArgs.set(_resKey, _resValue); return super.executeFlowNode(execArg); } }