<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body link="#355491" alink="#4262a1" vlink="#355491" style="background: #e2e2e2; margin: 0; padding: 20px;">

<div>
        <table cellpadding="0" bgcolor="#FFFFFF" border="0" cellspacing="0" style="border: 1px solid #dadada; margin-bottom: 30px; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                <tbody>
                        <tr>

                                <td>

                                        <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border: solid 2px #ccc; background: #dadada; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                                                <tbody>
                                                        <tr>
                                                                <td bgcolor="#000000" valign="middle" height="58px" style="border-bottom: 1px solid #ccc; padding: 20px; -moz-border-radius-topleft: 3px; -moz-border-radius-topright: 3px; -webkit-border-top-right-radius: 5px; -webkit-border-top-left-radius: 5px;">
                                                                        <h1 style="color: #333333; font: bold 22px Arial, Helvetica, sans-serif; margin: 0; display: block !important;">
                                                                        <!-- To have a header image/logo replace the name below with your img tag -->
                                                                        <!-- Email clients will render the images when the message is read so any image -->
                                                                        <!-- must be made available on a public server, so that all recipients can load the image. -->
                                                                        <a href="http://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">JBoss Community</a></h1>
                                                                </td>

                                                        </tr>
                                                        <tr>
                                                                <td bgcolor="#FFFFFF" style="font: normal 12px Arial, Helvetica, sans-serif; color:#333333; padding: 20px;  -moz-border-radius-bottomleft: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 5px; -webkit-border-bottom-left-radius: 5px;"><h3 style="margin: 10px 0 5px; font-size: 17px; font-weight: normal;">
    Tasks Assigned to Groups Not Found
</h3>
<span style="margin-bottom: 10px;">
    created by <a href="http://community.jboss.org/people/williajd">James Williams</a> in <i>jBPM</i> - <a href="http://community.jboss.org/message/614902#614902">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">

<div class="jive-rendered-content"><p>Hi,</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>I'm using JBPM 5.1 Final and have spent a couple of hours learning how tasks are returned from the TaskService. I believe I have found a bug in the way tasks are returned when they are not assigned to a particular user.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>I have 2 simple processes that I'm using to test my code. I'm making sure I can create a process and then return the first tasks from them. </p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>The first one SimpleHumanTaskProcess has a single task with the owner id set to "testUser". When I create the process I can use the TaskClient.getTasksOwned method to return the created tasks as expected. When I look in the database the tasks are there and have owner and creator set to "testUser".</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>The second process is called SimpleGroupTaskProcess and has a single Human Task that has groupId = "testGroup". The process is created properly and I am able to examine the database and noticed that the task owner and creator are not set. The potential owner DOES include the "testGroup" so I would expect it to be found. Howevewr it is not retrieved when using the TaskClient.getTasksAssignedAsPotentialOwner passing in the user "testUser" and group "testGroup".</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>After some digging I think I have found the problem. The key is that the creator and owner is not set on the task. I found the underlying named query called "TasksAssignedAsPotentialOwnerWithGroups" in the orm.xml file. The query was not taking into account the null creator and owner so was only returning the tasks belonging to the "testUser" but not the group assignment.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><table border="1" cellpadding="3" cellspacing="0" class="jiveBorder" style="width: 100%; border: 1px solid #000000;"><tbody><tr><th align="center" style="border:1px solid black;border: 1px solid #000000;background-color: #6690bc;" valign="middle"><span style="color: #ffffff;"><strong>Old<br/></strong></span></th><th align="center" style="border:1px solid black;border: 1px solid #000000;background-color: #6690bc;" valign="middle"><span style="color: #ffffff;"><strong>New<br/></strong></span></th></tr><tr><td style="border:1px solid black;border: 1px solid #000000;"><p>select</p><p>&#160;&#160;&#160;&#160; new org.jbpm.task.query.TaskSummary(</p><p>&#160;&#160;&#160;&#160; t.id,</p><p>&#160;&#160;&#160;&#160; t.taskData.processInstanceId,</p><p>&#160;&#160;&#160;&#160; name.text,</p><p>&#160;&#160;&#160;&#160; subject.text,</p><p>&#160;&#160;&#160;&#160; description.text,</p><p>&#160;&#160;&#160;&#160; t.taskData.status,</p><p>&#160;&#160;&#160;&#160; t.priority,</p><p>&#160;&#160;&#160;&#160; t.taskData.skipable,</p><p>&#160;&#160;&#160;&#160; t.taskData.actualOwner,</p><p>&#160;&#160;&#160;&#160; t.taskData.createdBy,</p><p>&#160;&#160;&#160;&#160; t.taskData.createdOn,</p><p>&#160;&#160;&#160;&#160; t.taskData.activationTime,</p><p>&#160;&#160;&#160;&#160; t.taskData.expirationTime)</p><p>from</p><p>&#160;&#160;&#160; Task t </p><p>&#160;&#160;&#160; left join t.taskData.createdBy </p><p>&#160;&#160;&#160; left join t.taskData.actualOwner</p><p>&#160;&#160;&#160; left join t.subjects as subject</p><p>&#160;&#160;&#160; left join t.descriptions as description</p><p>&#160;&#160;&#160; left join t.names as name,</p><p>&#160;&#160;&#160; OrganizationalEntity potentialOwners</p><p>where</p><p>&#160;&#160;&#160; ( potentialOwners.id = :userId or potentialOwners.id in (:groupIds) ) and</p><p>&#160;&#160;&#160; potentialOwners in elements ( t.peopleAssignments.potentialOwners )&#160; and</p><p>&#160;&#160;&#160; (</p><p>&#160;&#160;&#160; name.language = :language</p><p>&#160;&#160;&#160; or t.names.size = 0</p><p>&#160;&#160;&#160; ) and</p><p>&#160;&#160;&#160; (</p><p>&#160;&#160;&#160; subject.language = :language</p><p>&#160;&#160;&#160; or t.subjects.size = 0</p><p>&#160;&#160;&#160; ) and</p><p>&#160;&#160;&#160; (</p><p>&#160;&#160;&#160; description.language = :language</p><p>&#160;&#160;&#160; or t.descriptions.size = 0</p><p>&#160;&#160;&#160; ) and</p><p>&#160;&#160;&#160; t.taskData.status in ('Created', 'Ready', 'Reserved', 'InProgress', 'Suspended') and</p><p>&#160;&#160;&#160; t.taskData.expirationTime is nul</p></td><td style="border:1px solid black;border: 1px solid #000000;"><p>select</p><p>&#160;&#160;&#160;&#160; new org.jbpm.task.query.TaskSummary(</p><p>&#160;&#160;&#160;&#160; t.id,</p><p>&#160;&#160;&#160;&#160; t.taskData.processInstanceId,</p><p>&#160;&#160;&#160;&#160; name.text,</p><p>&#160;&#160;&#160;&#160; subject.text,</p><p>&#160;&#160;&#160;&#160; description.text,</p><p>&#160;&#160;&#160;&#160; t.taskData.status,</p><p>&#160;&#160;&#160;&#160; t.priority,</p><p>&#160;&#160;&#160;&#160; t.taskData.skipable,</p><p>&#160;&#160;&#160;&#160; owner,</p><p>&#160;&#160;&#160;&#160; creator,</p><p>&#160;&#160;&#160;&#160; t.taskData.createdOn,</p><p>&#160;&#160;&#160;&#160; t.taskData.activationTime,</p><p>&#160;&#160;&#160;&#160; t.taskData.expirationTime)</p><p>from</p><p>&#160;&#160;&#160; Task t </p><p>&#160;&#160;&#160; left join t.taskData.createdBy as creator</p><p>&#160;&#160;&#160; left join t.taskData.actualOwner as owner</p><p>&#160;&#160;&#160; left join t.subjects as subject</p><p>&#160;&#160;&#160; left join t.descriptions as description</p><p>&#160;&#160;&#160; left join t.names as name,</p><p>&#160;&#160;&#160; OrganizationalEntity potentialOwners</p><p>where</p><p>&#160;&#160;&#160; ( potentialOwners.id = :userId or potentialOwners.id in (:groupIds) ) and</p><p>&#160;&#160;&#160; potentialOwners in elements ( t.peopleAssignments.potentialOwners )&#160; and</p><p>&#160;&#160;&#160; (</p><p>&#160;&#160;&#160; name.language = :language</p><p>&#160;&#160;&#160; or t.names.size = 0</p><p>&#160;&#160;&#160; ) and</p><p>&#160;&#160;&#160; (</p><p>&#160;&#160;&#160; subject.language = :language</p><p>&#160;&#160;&#160; or t.subjects.size = 0</p><p>&#160;&#160;&#160; ) and</p><p>&#160;&#160;&#160; (</p><p>&#160;&#160;&#160; description.language = :language</p><p>&#160;&#160;&#160; or t.descriptions.size = 0</p><p>&#160;&#160;&#160; ) and</p><p>&#160;&#160;&#160; t.taskData.status in ('Created', 'Ready', 'Reserved', 'InProgress', 'Suspended') and</p><p>&#160;&#160;&#160; t.taskData.expirationTime is null</p></td></tr></tbody></table><p>This appears to work. </p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>I do have a couple of questions though. Should tasks be created in the database without having at least a creator id? Is this expected behaviour for tasks assigned to groups?</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>I have attached my processes, just in case there is something I've done wrong that someone can help me with.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Thanks</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>James</p></div>

<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
    <p style="margin: 0;">Reply to this message by <a href="http://community.jboss.org/message/614902#614902">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in jBPM at <a href="http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034">Community</a></p>
</div></td>
                        </tr>
                    </tbody>
                </table>


                </td>
            </tr>
        </tbody>
    </table>

</div>

</body>
</html>