History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: JRA-12118
Type: Bug Bug
Status: Resolved Resolved
Resolution: Duplicate
Priority: Minor Minor
Assignee: Unassigned
Reporter: Alastair F
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
JIRA

Set Component/Fix Version in post function does not set a component or version

Created: 08/Feb/07 06:29 PM   Updated: 29/Jan/08 10:37 AM
Component/s: JIRA Development Kit
Affects Version/s: 3.7.3
Fix Version/s: None

Time Tracking:
Not Specified

Issue Links:
Duplicate
 

Participants: Alastair F, Anton Mazkovoi [Atlassian] and Ken Roland
Since last comment: 24 weeks, 5 days ago
Resolution Date: 08/Feb/07 09:48 PM
Labels:


 Description  « Hide
SetComponentAndVersion.java
public class SetComponentAndVersion implements FunctionProvider
{
    /**
     * Automatically assign subtasks the same component/version as parent task.
     */
    public void execute (Map transientVars, Map args, PropertySet ps)
        throws WorkflowException
    {
        MutableIssue task = (MutableIssue)transientVars.get("issue");
        
        if (task.isSubTask())
        {
            ComponentManager componentManager = ComponentManager.getInstance();
            IssueManager issueManager = componentManager.getIssueManager();
            MutableIssue parent = issueManager.getIssueObject(task.getParentId());
            
            task.setComponents(parent.getComponents());
            task.setFixVersions(parent.getFixVersions());
            task.store();
        }
    }
}

Fairly simple and straight forward. I have access to the components and versions from the parent task, but they are not set successfully on the child task.



 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Anton Mazkovoi [Atlassian] - 08/Feb/07 09:48 PM
Alastair,

At the moment, setting fields on the parent issue does not affect its sub-tasks. Please vote for JRA-5225 for this feature.

In code, you will need to do the work yourself by looping over the children and setting the fields as needed.

If you have any coding questions, please post the questions to the JIRA Dev forum:
http://forums.atlassian.com/forum.jspa?forumID=100

I will resolve the issue for now, but if I misunderstood what you are after, please let us know.

Thanks,
Anton


Alastair F - 12/Feb/07 09:59 AM
Hi Anton.

I believe you misread my code then. The task itself is a subtask. I am retrieving its parent task then setting the subtask based on values from the parent.

Note the following fragment:

{code title=Code Fragment|borderStyle=solid}

if (task.isSubTask())

{ ComponentManager componentManager = ComponentManager.getInstance(); IssueManager issueManager = componentManager.getIssueManager(); MutableIssue parent = issueManager.getIssueObject(task.getParentId()); task.setComponents(parent.getComponents()); task.setFixVersions(parent.getFixVersions()); task.store(); }

It only completes this set of code if the task that initialized the post-function is a subtask. It then retrieves the parent task and sets the subtask based on the parent. Following your instructions, this should work correctly.


Alastair F - 12/Feb/07 10:04 AM
(ignore the last comment)

Hi Anton.

I believe you misread my code then. The task itself is a subtask. I am retrieving its parent task then setting the subtask based on values from the parent.

Note the following fragment:

Code Fragment
if (task.isSubTask())
{
    ComponentManager componentManager = ComponentManager.getInstance();
    IssueManager issueManager = componentManager.getIssueManager();
    MutableIssue parent = issueManager.getIssueObject(task.getParentId());
    
    task.setComponents(parent.getComponents());
    task.setFixVersions(parent.getFixVersions());
    task.store();
}

It only completes this set of code if the task that initialized the post-function is a subtask. It then retrieves the parent task and sets the subtask based on the parent. Following your instructions, this should work correctly.

Note: This is a post-create function. When a subtask is created, this plug-in code is run. It could have something to do with this. Here is the workflow XML:

<workflow>
  <meta name="jira.description">Open/Close/Re-Open transitions for subtasks.</meta>
  <initial-actions>
    <action id="1" name="Create">
      <results>
        <unconditional-result old-status="null" status="open" step="1">
          <post-functions>
            <function type="class">
              <arg name="class.name">com.atlassian.jira.workflow.function.issue.IssueCreateFunction</arg>
            </function>
            <function type="class">
              <arg name="class.name">ca.mda.jira.plugin.workflow.functions.SetComponentAndVersion</arg>
            </function>
            <function type="class">
              <arg name="class.name">com.atlassian.jira.workflow.function.issue.IssueReindexFunction</arg>
            </function>
            <function type="class">
              <arg name="eventTypeId">10005</arg>
              <arg name="class.name">com.atlassian.jira.workflow.function.event.FireIssueEventFunction</arg>
            </function>
          </post-functions>
        </unconditional-result>
      </results>
    </action>
  </initial-actions>
  ...
</workflow>

Alastair F - 12/Feb/07 05:51 PM
I have reproduced the problem with the exact scenario you listed. See the following code.
IssueUpdate.java
public class IssueUpdate implements FunctionProvider
{
    public void execute (Map transientVars, Map args, PropertySet ps)
        throws WorkflowException
    {
        MutableIssue issue = (MutableIssue)transientVars.get("issue");
        if (!issue.isSubTask())
        {
            Collection subtasks = issue.getSubTaskObjects();
            for (Iterator it = subtasks.iterator(); it.hasNext(); )
            {            
                // update then store to the DB
                MutableIssue subtask = (MutableIssue)it.next();
                
                // this call works
                subtask.setAssignee(issue.getAssignee());
                
                // these two calls do not seem to work
                subtask.setFixVersions(issue.getFixVersions());
                subtask.setComponents(issue.getComponents());
                
                // store the issue
                subtask.store();
            }
        }
    }
}

The result of this is that the assignee is set properly, but the fix version(s) and components are not.


Anton Mazkovoi [Atlassian] - 13/Feb/07 01:29 AM
Alastair,

Please accept my apologies for missing the point.

You are right, calling save() on the issue will not do the trick. You need to call:

Map actionParams = EasyMap.build("issue", issue.getGenericValue(), "issueObject", issue, "remoteUser", ManagerFactory.getWorkflowManager().getRemoteUser(transientVars), "dispatchEvent", Boolean.FALSE);
ActionResult aResult = CoreFactory.getActionDispatcher().execute(ActionNames.ISSUE_UPDATE, actionParams);

Note that the "dispatchEvent" parameter is set to false to ensure that the Issue Updated event is not fired.

Unfortunately, I did not get a chance to test that the above code works. If you run into trouble, please post a question to the JIRA Dev forum:
http://forums.atlassian.com/forum.jspa?forumID=100
There is a way to get things working.

Also, the following document might be helpful:
http://confluence.atlassian.com/display/JIRA/Creating+and+Editing+an+Issue


Alastair F - 04/Jun/07 02:29 PM
I believe that a re-index is require to force the fix version(s) and component(s) through properly. This is the fix for this problem and thus this issue may be resolved IMO (as the reporter).

Ken Roland - 29/Jan/08 10:37 AM
I had an almost identical plugin I created for a post function and had the same issues. My eventual fix was to remove the .store() line and place my post function at the very top of the tree BEFORE create issue. That worked perfectly and also solved the problem of the modifications being logged as changes in the Change History. (Which I did not want)