package foundation.action;
|
|
import foundation.dao.OperatorCode;
|
import foundation.dao.bizlogic.IActionProvider;
|
import foundation.data.entity.Entity;
|
import foundation.json.IJSONWriter;
|
import foundation.server.ObjectCreator;
|
import foundation.util.Util;
|
|
public class ActionMeta {
|
|
private String id;
|
private String name;
|
private String title;
|
private String methodName;
|
private String providerName;
|
private double transactionScore;
|
private Events fireEvents;
|
private Class<ActionProvider> providerClass;
|
private OperatorCode operatorCode;
|
private String param;
|
|
|
public ActionMeta() {
|
|
}
|
|
public void load(Entity entity) throws Exception {
|
id = entity.getString("id");
|
name = entity.getString("name");
|
title = entity.getString("title");
|
methodName = entity.getString("method_name");
|
providerName = entity.getString("provider_name");
|
transactionScore = entity.getDouble("score", 0);
|
|
fireEvents = Events.getInstance(entity.getString("fire_event_code"));
|
|
parseMethodName(methodName);
|
operatorCode = OperatorCode.parse(methodName);
|
}
|
|
private void parseMethodName(String value) {
|
if (Util.isEmpty(value)) {
|
methodName = value;
|
}
|
|
methodName = methodName.trim().replace("(", "(").replace(")", ")");
|
int pos = value.indexOf("(");
|
|
if (pos <= 0) {
|
methodName = value;
|
return;
|
}
|
|
methodName = value.substring(0, pos);
|
param = value.substring(pos + 1, value.length() - 1);
|
param = param.trim();
|
}
|
|
public String getId() {
|
return id;
|
}
|
|
public String getName() {
|
return name;
|
}
|
|
public String getTitle() {
|
return title;
|
}
|
|
public String getMethodName() {
|
return methodName;
|
}
|
|
public String getProviderName() {
|
return providerName;
|
}
|
|
public double getTransactionScore() {
|
return transactionScore;
|
}
|
|
public IActionProvider createProvider() throws Exception {
|
if (Util.isEmpty(providerName)) {
|
return null;
|
}
|
|
IActionProvider provider = ObjectCreator.create(providerName);
|
return provider;
|
}
|
|
public Class<ActionProvider> getProviderClass() {
|
return providerClass;
|
}
|
|
public Events getFireEvents() {
|
return fireEvents;
|
}
|
|
public String getParam() {
|
return param;
|
}
|
|
public OperatorCode getOperatorCode() {
|
return operatorCode;
|
}
|
|
@Override
|
public String toString() {
|
return providerName + "." + methodName;
|
}
|
|
public void writeJSONBody(IJSONWriter writer) {
|
writer.write("id", id);
|
writer.write("name", name);
|
writer.write("title", title);
|
writer.write("method_name", methodName);
|
writer.write("provider_name", providerName);
|
writer.write("transactionScore", transactionScore);
|
}
|
|
}
|