com.alogic.xscript.plugins.SetAsJson Maven / Gradle / Ivy
package com.alogic.xscript.plugins;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import com.alogic.xscript.AbstractLogiclet;
import com.alogic.xscript.ExecuteWatcher;
import com.alogic.xscript.Logiclet;
import com.alogic.xscript.LogicletContext;
import com.anysoft.util.Properties;
import com.anysoft.util.PropertiesConstants;
import com.jayway.jsonpath.spi.JsonProvider;
import com.jayway.jsonpath.spi.JsonProviderFactory;
public class SetAsJson extends AbstractLogiclet{
protected String id;
protected JsonProvider provider = JsonProviderFactory.createProvider();
public SetAsJson(String tag, Logiclet p) {
super(tag, p);
}
@Override
public void configure(Properties p){
super.configure(p);
id = PropertiesConstants.getString(p,"id","",true);
}
@Override
protected void onExecute(Map root,
Map current, LogicletContext ctx,
ExecuteWatcher watcher) {
if (StringUtils.isNotEmpty(id)){
String content = provider.toJson(current);
if (StringUtils.isNotEmpty(content)){
ctx.SetValue(id, content);
}
}
}
}