jelly/groovy script to copy component/versions from task to subtasks

Alex Perez
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 28, 2013

Hi all,

We are running a category of projects with tasks and subtasks. In this category there is a requirement to have all the component/affected/fixversion in subtasks equal to it's parent task.

Users with appropiate permissions can change these fields via the "Edit" operation in Tasks, but in subtasks the screen associated to the Edit op doesn't show any of these 3 fields. Then, a listener is catching all edit events from the project category, to copy those 3 fields to its subtasks. So the only way to update these 3 fields is editing this in the parent task and letting the listener do it's work.

But unfortunatelly the listener has some bug that leads to subtasks showing old version info in the Search screen (causing the filters showing incorrect results), but showing the correct info in the issue screen.

Our guess is that it's somewhat related to the order of storing the tasks/subtasks in the listener (?). Only a locking reindex fix this (background indexing doesn't!).

Is there some jelly/groovy example scripts to copy these 3 fileds from parent to subs without locking the whole instance? Is this doable only with Jelly? We need some interim solution while fixing the listener ...

Thanks in advance.

7 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Answer accepted
Alex Perez
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 6, 2013

Our mistake:

There was a different version deployed in production and stagging environment. The issue was fixed in a old version but never deployed to live ...

Plonk!

1 vote
RambanamP
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 6, 2013

instead of using edit operation you can create global WFA action something like "update versions" and add those three fields to that screen then using postfunction you can copy over to subtask

1 vote
Boris Georgiev _Appfire_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 30, 2013

What about using "Jira Misc Workflow Extensions" Set Field Value from Parent post function ?

Alex Perez
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 30, 2013

Hi Boris,

I already installed that plugin, but the problem is that this "copy" is implemented as a postfunction, so I can only "link" this to a transition (Edit is an operation, not transition). Hence our need to implement this as a listener, or as a script while fixing the original listener ...

thx

0 votes
Alex Perez
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 6, 2013

Potential sources to the problem (IMO):

-calls to ImportUtils.setIndexIssues, but Ive seen them in all the examples I found.

-IssueManager.updateIssue doesn't update the indexes? Need for the MutableIssue.store()?

-using old listener interface

public class SyncEdicion extends AbstractIssueEventListener implements IssueEventListener {
.....
.....

	public void workflowEvent(IssueEvent event) {
		Issue i = event.getIssue();

		// event from a "controlled" projet?
		if (i.getProjectObject().getProjectCategoryObject().getId().equals(this.prjCategory)) {

			boolean wasIndexing = ImportUtils.isIndexIssues();
			ImportUtils.setIndexIssues(true);
			try {
				this.handleFields(event);
			} catch (IndexException e) {
				e.printStackTrace();
			} catch (EntityNotFoundException e) {
				e.printStackTrace();
			} catch (Exception e) {
				e.printStackTrace();
			}
			ImportUtils.setIndexIssues(wasIndexing);
		}
	}
0 votes
Alex Perez
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 6, 2013
private void copyAffectedVersion(Issue src, MutableIssue dest) {
	log.debug("copyAffectedVersion");
	Collection<Version> affectedVersions = new ArrayList<Version>();
	Version myVersion;
	Iterator ite = null;
	GenericValue gv = null;
	ite = src.getAffectedVersions().iterator();
	while (ite.hasNext()) {
		myVersion = (Version) ite.next();
		gv = myVersion.getGenericValue();
		affectedVersions.add(myVersion);
	}
	dest.setAffectedVersions(affectedVersions);
}

0 votes
Alex Perez
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 6, 2013
private void handleFields(IssueEvent event) throws IndexException, EntityNotFoundException, Exception {
	
	Iterator ite = null;
	MutableIssue mi, smi;
	boolean updated;

	mi = (MutableIssue) event.getIssue();

	if (!event.getIssue().isSubTask()) {
		// propagar T -> ST
		ite = mi.getSubTaskObjects().iterator();
		while (ite.hasNext()) {
			updated = false;
			smi = (MutableIssue) ite.next();
			// this copy the affected version from task to subtask. There are other to compare and copy fixVersion and components, but removed from the sample code
			if (!mi.getAffectedVersions().equals(smi.getAffectedVersions())) {
				log.debug("copiando version afectada");
				this.copyAffectedVersion(mi, smi);
				updated = true;
			}

			if (updated) {
				log.debug("storing");
				ComponentAccessor.getIssueManager().updateIssue(event.getUser(), smi,
						EventDispatchOption.DO_NOT_DISPATCH, false);
				// smi.store();  ?
			}

		}

	} else { 
		smi = (MutableIssue) event.getIssue();
		mi = (MutableIssue) smi.getParentObject();
		
		updated = false;
		// event raised from a subtask, ensure that parent task have same affected versions or copy from it.
		if (!mi.getAffectedVersions().equals(smi.getAffectedVersions())) {
			log.debug("copiando versiones afectadas");
			this.copyAffectedVersion(mi, smi);
			updated = true;
		}

		if (updated) {
			log.debug("storing");

			ComponentAccessor.getIssueManager().updateIssue(event.getUser(), smi,
					EventDispatchOption.DO_NOT_DISPATCH, false);
			// smi.store();  ?
		}

	}

}

0 votes
JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 2, 2013

Can you post your listener code?

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events