@Override
public String invoke(BpmStep step, Map params) throws Exception {
ProcessInstance processInstance = step.getProcessInstance();
try {
ProcessToolContext ctx = ProcessToolContext.Util.getThreadProcessToolContext();
UserSubstitution userSubstitution = new UserSubstitution();
userSubstitution.setUser(processInstance.getCreator());
userSubstitution.setDateFrom(Formats.parseShortDate(processInstance.getSimpleAttributeValue("dateFrom")));
userSubstitution.setDateTo(Formats.parseShortDate(processInstance.getSimpleAttributeValue("dateTo")));
String substituteUserLogin = processInstance.getSimpleAttributeValue("userSubstitute");
UserData substituteUser = ctx.getUserDataDAO().loadUserByLogin(substituteUserLogin);
if (substituteUser == null) {
substituteUser = LiferayBridge.getLiferayUser(substituteUserLogin,
processInstance.getCreator().getCompanyId());
ctx.getUserDataDAO().saveOrUpdate(substituteUser);
if (substituteUser == null) {
logger.warning("Unable to determine application user by login: " + substituteUserLogin);
return STATUS_ERROR;
}
}
userSubstitution.setUserSubstitute(substituteUser);
ctx.getUserSubstitutionDAO().saveOrUpdate(userSubstitution);
logger.warning("Added substitution for user " + userSubstitution.getUser().getLogin());
return STATUS_OK;
}
catch (Exception e) {
logger.log(Level.SEVERE, e.getMessage(), e);