Issue
I'm developing an application with YAWL 4. I need to add a codelet to an automatized task. I wrote a java class and added it following various tutorials, but nothing worked. The YAWL engine log gives an error, but it just says "error loading codelet x" without any details. I checked YAWL default codelets looking for errors but nothing come up (I just haven't implemented all methods, could be this?). Here is my code:
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;
}
}
I noticed yawl uses .class files for codelets, but my codelet is a .java file, so I tryed to port it but I was unsuccessful. Does somebody have experience about Yawl 4 codelets? Or, can someone tell me how to use a .class file instead of .java?
Solution
I found out by myself. Libraries (except the java default) used by the class must be put in the same folder as the .class file. This was enough for the workflow editor to notice my codelet.
Answered By - Luciano Sacco
Answer Checked By - Timothy Miller (JavaFixing Admin)