Sample Functions Using API
Function - AddCustomerRecord.java
import com.collager.trillo.pojo.Result;
import com.collager.trillo.pojo.ScriptParameter;
import com.collager.trillo.util.DSApi;
import com.collager.trillo.util.Loggable;
import com.collager.trillo.util.TrilloFunction;
import java.util.HashMap;
import java.util.Map;
public class AddCustomerRecord implements Loggable, TrilloFunction {
public Object handle(ScriptParameter scriptParameter) {
// do the implementation inside _handle()
try {
return _handle(scriptParameter);
} catch (Exception e) {
log().error("Failed", e);
return Result.getFailedResult(e.getMessage());
}
}
@SuppressWarnings("unchecked")
private Object _handle(ScriptParameter scriptParameter) {
String className = "shared.common.customer";
Map<String, Object> entity = new HashMap<>();
entity.put("name", "Sam");
entity.put("email", "sam@gmail.com");
entity.put("address", "45, park view, NY");
entity.put("phoneNumber", "+16463704660");
Object res = DSApi.save(className, entity);
return res;
}
}
Function - UpdateCustomerAddress.java
import com.collager.trillo.pojo.Result;
import com.collager.trillo.pojo.ScriptParameter;
import com.collager.trillo.util.DSApi;
import com.collager.trillo.util.Loggable;
import com.collager.trillo.util.TrilloFunction;
public class UpdateCustomerAddress implements Loggable, TrilloFunction {
public Object handle(ScriptParameter scriptParameter) {
// do the implementation inside _handle()
try {
return _handle(scriptParameter);
} catch (Exception e) {
log().error("Failed", e);
return Result.getFailedResult(e.getMessage());
}
}
@SuppressWarnings("unchecked")
private Object _handle(ScriptParameter scriptParameter) {
String className = "shared.common.customer";
String id = "1";
String attrName = "address";
String value = "7, woodland street, NY";
Object res = DSApi.update(className, id, attrName, value);
return res;
}
}
Last updated