创建小码并将其添加到 YAWL
Creating and adding codelets to YAWL
我正在使用 YAWL 4 开发应用程序。我需要将小码添加到自动化任务中。我写了一个 java class 并按照各种教程添加了它,但没有任何效果。 YAWL 引擎日志给出了一个错误,但它只是说 "error loading codelet x" 没有任何细节。我检查了 YAWL 默认小码以查找错误但没有出现(我只是没有实现所有方法,可能是这个?)。这是我的代码:
public class PrepareDataTaskCodelet extends AbstractCodelet {
private Connection connection;
private Statement statement;
private PreparedStatement preparedStatement;
private ResultSet resultSet;
private String user;
private String password;
private String getAllAppuser;
private String getAllDocument;
private String getAllRequest;
private String getAllRole;
private String tempQuery;
private Element inData;
private List<YParameter> inParams;
private List<YParameter> outParams;
private boolean cancelled;
public PrepareDataTaskCodelet() {
// TODO Auto-generated constructor stub
super();
connection = null;
statement = null;
preparedStatement = null;
resultSet = null;
user = null;
password = null;
tempQuery = null;
}
private ResultSet getSingleAppuser(String field, String data) throws SQLException{
tempQuery = getAllAppuser + "WHERE " + field + " = " + data;
connection.prepareStatement(tempQuery);
resultSet = preparedStatement.executeQuery();
return resultSet;
}
// controlla se è presente appuser con username e password. ritorna false se non viene trovato alcun appuser, true altrimenti
public boolean checkAppuser(String username, String password) throws SQLException{
tempQuery = getAllAppuser + "WHERE username = " + username + "AND password = " + password;
connection.prepareStatement(tempQuery);
resultSet = preparedStatement.executeQuery();
return (resultSet.first());
}
public void initConnection() throws Exception { // starts connection
try {
Class.forName("com.mysql.jdbc.Driver");
connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/yawlConnection","root","root"); //default connection values
} finally {}
}
public PrepareDataTaskCodelet(String desc) {
super(desc);
// TODO Auto-generated constructor stub
}
@Override // TODO assegnare paramentri in ingresso (user e pw)
public Element execute(Element inData, List<YParameter> inParams, List<YParameter> outParams)
throws CodeletExecutionException {
// TODO Auto-generated method stub
setInputs(inData, inParams, outParams);
String username = "";
String password = "";
boolean isValidUser = false;
username = (String) getParameterValue("username");
password = (String) getParameterValue("password");
try {
initConnection();
isValidUser = checkAppuser(username, password);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
setParameterValue("isValidUser", String.valueOf(isValidUser));
return getOutputData();
}
protected void setInputs(Element inData, List<YParameter> inParams, List<YParameter> outParams)
{
this.inData = inData;
this.inParams = inParams;
this.outParams = outParams;
}
public void cancel()
{
this.cancelled = true;
}
public List<YParameter> getRequiredParams() { // corretto
List<YParameter> params = new ArrayList<YParameter>();
YParameter param1 = new YParameter(null, YParameter._INPUT_PARAM_TYPE);
param1.setDataTypeAndName("String", "username", XSD_NAMESPACE);
param1.setDocumentation("appuser username");
params.add(param1);
YParameter param2 = new YParameter(null, YParameter._INPUT_PARAM_TYPE);
param2.setDataTypeAndName("String", "password", XSD_NAMESPACE);
param2.setDocumentation("appuser password");
params.add(param2);
YParameter param3 = new YParameter(null, YParameter._OUTPUT_PARAM_TYPE);
param3.setDataTypeAndName("boolean", "isValidUser", XSD_NAMESPACE);
param3.setDocumentation("check if current user has valid login data");
params.add(param3);
return params;
}
}
我注意到 yawl 使用 .class 文件作为小码,但我的小码是 .java 文件,所以我尝试移植它但没有成功。有人对 Yawl 4 codelet 有经验吗?或者,有人可以告诉我如何使用 .class 文件而不是 .java 吗?
我自己发现的。 class 使用的库(默认的 java 除外)必须与 .class 文件放在同一文件夹中。这足以让工作流编辑器注意到我的代码。
我正在使用 YAWL 4 开发应用程序。我需要将小码添加到自动化任务中。我写了一个 java class 并按照各种教程添加了它,但没有任何效果。 YAWL 引擎日志给出了一个错误,但它只是说 "error loading codelet x" 没有任何细节。我检查了 YAWL 默认小码以查找错误但没有出现(我只是没有实现所有方法,可能是这个?)。这是我的代码:
public class PrepareDataTaskCodelet extends AbstractCodelet {
private Connection connection;
private Statement statement;
private PreparedStatement preparedStatement;
private ResultSet resultSet;
private String user;
private String password;
private String getAllAppuser;
private String getAllDocument;
private String getAllRequest;
private String getAllRole;
private String tempQuery;
private Element inData;
private List<YParameter> inParams;
private List<YParameter> outParams;
private boolean cancelled;
public PrepareDataTaskCodelet() {
// TODO Auto-generated constructor stub
super();
connection = null;
statement = null;
preparedStatement = null;
resultSet = null;
user = null;
password = null;
tempQuery = null;
}
private ResultSet getSingleAppuser(String field, String data) throws SQLException{
tempQuery = getAllAppuser + "WHERE " + field + " = " + data;
connection.prepareStatement(tempQuery);
resultSet = preparedStatement.executeQuery();
return resultSet;
}
// controlla se è presente appuser con username e password. ritorna false se non viene trovato alcun appuser, true altrimenti
public boolean checkAppuser(String username, String password) throws SQLException{
tempQuery = getAllAppuser + "WHERE username = " + username + "AND password = " + password;
connection.prepareStatement(tempQuery);
resultSet = preparedStatement.executeQuery();
return (resultSet.first());
}
public void initConnection() throws Exception { // starts connection
try {
Class.forName("com.mysql.jdbc.Driver");
connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/yawlConnection","root","root"); //default connection values
} finally {}
}
public PrepareDataTaskCodelet(String desc) {
super(desc);
// TODO Auto-generated constructor stub
}
@Override // TODO assegnare paramentri in ingresso (user e pw)
public Element execute(Element inData, List<YParameter> inParams, List<YParameter> outParams)
throws CodeletExecutionException {
// TODO Auto-generated method stub
setInputs(inData, inParams, outParams);
String username = "";
String password = "";
boolean isValidUser = false;
username = (String) getParameterValue("username");
password = (String) getParameterValue("password");
try {
initConnection();
isValidUser = checkAppuser(username, password);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
setParameterValue("isValidUser", String.valueOf(isValidUser));
return getOutputData();
}
protected void setInputs(Element inData, List<YParameter> inParams, List<YParameter> outParams)
{
this.inData = inData;
this.inParams = inParams;
this.outParams = outParams;
}
public void cancel()
{
this.cancelled = true;
}
public List<YParameter> getRequiredParams() { // corretto
List<YParameter> params = new ArrayList<YParameter>();
YParameter param1 = new YParameter(null, YParameter._INPUT_PARAM_TYPE);
param1.setDataTypeAndName("String", "username", XSD_NAMESPACE);
param1.setDocumentation("appuser username");
params.add(param1);
YParameter param2 = new YParameter(null, YParameter._INPUT_PARAM_TYPE);
param2.setDataTypeAndName("String", "password", XSD_NAMESPACE);
param2.setDocumentation("appuser password");
params.add(param2);
YParameter param3 = new YParameter(null, YParameter._OUTPUT_PARAM_TYPE);
param3.setDataTypeAndName("boolean", "isValidUser", XSD_NAMESPACE);
param3.setDocumentation("check if current user has valid login data");
params.add(param3);
return params;
}
}
我注意到 yawl 使用 .class 文件作为小码,但我的小码是 .java 文件,所以我尝试移植它但没有成功。有人对 Yawl 4 codelet 有经验吗?或者,有人可以告诉我如何使用 .class 文件而不是 .java 吗?
我自己发现的。 class 使用的库(默认的 java 除外)必须与 .class 文件放在同一文件夹中。这足以让工作流编辑器注意到我的代码。