use of org.kie.api.task.model.OrganizationalEntity in project jbpm by kiegroup.
the class EmailDeadlinesBaseTest method testDelayedEmailNotificationOnDeadlineTaskFailed.
@Test(timeout = 10000)
public void testDelayedEmailNotificationOnDeadlineTaskFailed() throws Exception {
CountDownTaskEventListener countDownListener = new CountDownTaskEventListener(1, false, true);
addCountDownListner(countDownListener);
Map<String, Object> vars = new HashMap<String, Object>();
vars.put("now", new Date());
Reader reader = new InputStreamReader(getClass().getResourceAsStream(MvelFilePath.DeadlineWithNotification));
InternalTask task = (InternalTask) TaskFactory.evalTask(reader, vars);
((InternalTaskData) task.getTaskData()).setSkipable(true);
InternalPeopleAssignments assignments = (InternalPeopleAssignments) TaskModelProvider.getFactory().newPeopleAssignments();
List<OrganizationalEntity> ba = new ArrayList<OrganizationalEntity>();
User user = TaskModelProvider.getFactory().newUser();
((InternalOrganizationalEntity) user).setId("Administrator");
ba.add(user);
assignments.setBusinessAdministrators(ba);
List<OrganizationalEntity> po = new ArrayList<OrganizationalEntity>();
User user2 = TaskModelProvider.getFactory().newUser();
((InternalOrganizationalEntity) user2).setId("Administrator");
po.add(user2);
assignments.setPotentialOwners(po);
task.setPeopleAssignments(assignments);
taskService.addTask(task, new HashMap<String, Object>());
long taskId = task.getId();
InternalContent content = (InternalContent) TaskModelProvider.getFactory().newContent();
Map<String, String> params = fillMarshalSubjectAndBodyParams();
ContentData marshalledObject = ContentMarshallerHelper.marshal(task, params, null);
content.setContent(marshalledObject.getContent());
taskService.addContent(taskId, content);
long contentId = content.getId();
content = (InternalContent) taskService.getContentById(contentId);
Object unmarshallObject = ContentMarshallerHelper.unmarshall(content.getContent(), null);
checkContentSubjectAndBody(unmarshallObject);
taskService.start(taskId, "Administrator");
taskService.fail(taskId, "Administrator", null);
// emails should not be set yet
assertEquals(0, getWiser().getMessages().size());
countDownListener.waitTillCompleted();
// no email should ne sent as task was completed before deadline was triggered
assertEquals(0, getWiser().getMessages().size());
task = (InternalTask) taskService.getTaskById(taskId);
assertEquals(Status.Failed, task.getTaskData().getStatus());
assertEquals(0, task.getDeadlines().getStartDeadlines().size());
assertEquals(0, task.getDeadlines().getEndDeadlines().size());
}
use of org.kie.api.task.model.OrganizationalEntity in project jbpm by kiegroup.
the class AssignmentService method assignTask.
public void assignTask(Task task) {
List<OrganizationalEntity> potentialOwners = task.getPeopleAssignments().getPotentialOwners();
potentialOwners.clear();
Group group = TaskModelProvider.getFactory().newGroup();
((InternalOrganizationalEntity) group).setId("Crusaders");
potentialOwners.add(group);
}
use of org.kie.api.task.model.OrganizationalEntity in project jbpm by kiegroup.
the class MVELLifeCycleManager method taskOperation.
public void taskOperation(final Operation operation, final long taskId, final String userId, final String targetEntityId, final Map<String, Object> data, List<String> groupIds, OrganizationalEntity... entities) throws TaskException {
try {
final List<OperationCommand> commands = operations.get(operation);
Task task = persistenceContext.findTask(taskId);
if (task == null) {
String errorMessage = "Task '" + taskId + "' not found";
throw new PermissionDeniedException(errorMessage);
}
String deploymentId = (String) context.get(EnvironmentName.DEPLOYMENT_ID);
if (deploymentId != null && !deploymentId.equals(task.getTaskData().getDeploymentId())) {
throw new IllegalStateException("Task instance " + task.getId() + " is owned by another deployment expected " + task.getTaskData().getDeploymentId() + " found " + deploymentId);
}
// automatically load task variables on each operation if the event manager is activated
if (EventManagerProvider.getInstance().isActive()) {
taskContentService.loadTaskVariables(task);
}
User user = persistenceContext.findUser(userId);
OrganizationalEntity targetEntity = null;
if (targetEntityId != null && !targetEntityId.equals("")) {
targetEntity = persistenceContext.findOrgEntity(targetEntityId);
}
getExecutionErrorHandler().processing(task);
switch(operation) {
case Activate:
{
taskEventSupport.fireBeforeTaskActivated(task, context);
break;
}
case Claim:
{
taskEventSupport.fireBeforeTaskClaimed(task, context);
break;
}
case Complete:
{
taskEventSupport.fireBeforeTaskCompleted(task, context);
break;
}
case Delegate:
{
taskEventSupport.fireBeforeTaskDelegated(task, context);
break;
}
case Exit:
{
taskEventSupport.fireBeforeTaskExited(task, context);
break;
}
case Fail:
{
if (data != null) {
FaultData faultData = ContentMarshallerHelper.marshalFault(task, data, null);
Content content = TaskModelProvider.getFactory().newContent();
((InternalContent) content).setContent(faultData.getContent());
persistenceContext.persistContent(content);
persistenceContext.setFaultToTask(content, faultData, task);
}
taskEventSupport.fireBeforeTaskFailed(task, context);
break;
}
case Forward:
{
taskEventSupport.fireBeforeTaskForwarded(task, context);
break;
}
case Nominate:
{
taskEventSupport.fireBeforeTaskNominated(task, context);
break;
}
case Release:
{
taskEventSupport.fireBeforeTaskReleased(task, context);
break;
}
case Resume:
{
taskEventSupport.fireBeforeTaskResumed(task, context);
break;
}
case Skip:
{
taskEventSupport.fireBeforeTaskSkipped(task, context);
break;
}
case Start:
{
taskEventSupport.fireBeforeTaskStarted(task, context);
break;
}
case Stop:
{
taskEventSupport.fireBeforeTaskStopped(task, context);
break;
}
case Suspend:
{
taskEventSupport.fireBeforeTaskSuspended(task, context);
break;
}
}
evalCommand(operation, commands, task, user, targetEntity, groupIds, entities);
persistenceContext.updateTask(task);
switch(operation) {
case Activate:
{
taskEventSupport.fireAfterTaskActivated(task, context);
break;
}
case Claim:
{
taskEventSupport.fireAfterTaskClaimed(task, context);
break;
}
case Complete:
{
if (data != null) {
taskContentService.addOutputContent(taskId, data);
}
taskEventSupport.fireAfterTaskCompleted(task, context);
break;
}
case Delegate:
{
// This is a really bad hack to execut the correct behavior
((InternalTaskData) task.getTaskData()).setStatus(Status.Reserved);
taskEventSupport.fireAfterTaskDelegated(task, context);
break;
}
case Exit:
{
taskEventSupport.fireAfterTaskExited(task, context);
break;
}
case Fail:
{
taskEventSupport.fireAfterTaskFailed(task, context);
break;
}
case Forward:
{
invokeAssignmentService(task, context, userId);
taskEventSupport.fireAfterTaskForwarded(task, context);
break;
}
case Nominate:
{
invokeAssignmentService(task, context, userId);
taskEventSupport.fireAfterTaskNominated(task, context);
break;
}
case Release:
{
invokeAssignmentService(task, context, userId);
taskEventSupport.fireAfterTaskReleased(task, context);
break;
}
case Resume:
{
taskEventSupport.fireAfterTaskResumed(task, context);
break;
}
case Start:
{
taskEventSupport.fireAfterTaskStarted(task, context);
break;
}
case Skip:
{
taskEventSupport.fireAfterTaskSkipped(task, context);
break;
}
case Stop:
{
taskEventSupport.fireAfterTaskStopped(task, context);
break;
}
case Suspend:
{
taskEventSupport.fireAfterTaskSuspended(task, context);
break;
}
}
getExecutionErrorHandler().processed(task);
} catch (RuntimeException re) {
throw re;
}
}
use of org.kie.api.task.model.OrganizationalEntity in project jbpm by kiegroup.
the class JaxbTask method copyOrganizationalEntityList.
private List<OrganizationalEntity> copyOrganizationalEntityList(List<OrganizationalEntity> jaxbOrgEntList) {
if (jaxbOrgEntList == null) {
return null;
}
List<OrganizationalEntity> orgEntList = new ArrayList<OrganizationalEntity>(jaxbOrgEntList.size());
for (OrganizationalEntity jaxbOrgEnt : jaxbOrgEntList) {
if (jaxbOrgEnt instanceof User) {
User user = createUser(jaxbOrgEnt.getId());
orgEntList.add(user);
} else if (jaxbOrgEnt instanceof Group) {
Group group = createGroup(jaxbOrgEnt.getId());
orgEntList.add(group);
}
}
return orgEntList;
}
use of org.kie.api.task.model.OrganizationalEntity in project jbpm by kiegroup.
the class DBUserInfoImpl method getMembersForGroup.
@Override
public Iterator<OrganizationalEntity> getMembersForGroup(Group group) {
List<OrganizationalEntity> roles = new ArrayList<OrganizationalEntity>();
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
conn = ds.getConnection();
ps = conn.prepareStatement(this.config.getProperty(MEMBERS_QUERY));
try {
ps.setString(1, group.getId());
} catch (ArrayIndexOutOfBoundsException ignore) {
}
rs = ps.executeQuery();
while (rs.next()) {
roles.add(TaskModelProvider.getFactory().newUser(rs.getString(1)));
}
} catch (Exception e) {
logger.error("Error when fetching members of a group from db, groups id: ", group.getId(), e);
} finally {
if (rs != null) {
try {
rs.close();
} catch (SQLException e) {
}
}
if (ps != null) {
try {
ps.close();
} catch (SQLException e) {
}
}
if (conn != null) {
try {
conn.close();
} catch (Exception ex) {
}
}
}
return roles.iterator();
}
Aggregations