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

com.logicbus.kvalue.xscript.list.KVLRPush Maven / Gradle / Ivy

package com.logicbus.kvalue.xscript.list;

import java.util.Map;

import org.apache.commons.lang3.StringUtils;

import com.alogic.xscript.ExecuteWatcher;
import com.alogic.xscript.Logiclet;
import com.alogic.xscript.LogicletContext;
import com.logicbus.kvalue.xscript.KVRowOperation;
import com.anysoft.util.Properties;
import com.anysoft.util.PropertiesConstants;
import com.logicbus.kvalue.core.KeyValueRow;
import com.logicbus.kvalue.core.ListRow;

public class KVLRPush extends KVRowOperation {
	protected String item = "";
	protected String delimeter = "";
	
	public KVLRPush(String tag, Logiclet p) {
		super(tag, p);
	}

	@Override
	public void configure(Properties p){
		super.configure(p);
		item = PropertiesConstants.getRaw(p,"item",item);
		delimeter = PropertiesConstants.getString(p,"delimeter",delimeter,true);		
	}
	
	@Override
	protected void onExecute(KeyValueRow row, Map root, Map current,
			LogicletContext ctx, ExecuteWatcher watcher) {
		String items = ctx.transform(item);

		if (row instanceof ListRow) {
			ListRow r = (ListRow) row;
			if (StringUtils.isNotEmpty(delimeter)){
				ctx.SetValue(id, String.valueOf(r.rightPush(items.split(delimeter))));
			}else{
				ctx.SetValue(id, String.valueOf(r.rightPush(items)));
			}
		}
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy