How to trigger reindexing of a issue?

Omer February 14, 2012

Hi,

I have a datepicker custom field. We modify this customfield from outside of Jira via some scripting. But till index-optimization which occurs at midnights we can't see any change in our dashboard filters regarding this customfield. I think this is because we do not re-index issue during external modification. Is there a way to trigger a re-index process for a spesific issue (the one whose customfield is modified from outside)? Maybe listeners? It would be great to see some sample code which listens any changes about a customfield and perfoms a reindex for the involved issue.

Thank you

3 answers

1 accepted

3 votes
Answer accepted
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.
April 11, 2012

I think the better solution would be to stop manipulating the db directly, and change your external process to use jira's soap or rest APIs.

But the script runner has a built-in script to reindex issues either from a project or a query, you could use that or look at the code.

Alternatively write a service that compares the value provided by the jira API with the one in the database, and reindex accordingly. Of all the options I'd go for 1).

1 vote
Radek Kantor
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.
February 14, 2012

Hi, I think one sollution is implement own Reindexed Date CF Type and force reindex in create/update method.

public class ReindexDateCFType extends DateCFType {

	private static final Logger log = Logger.getLogger(ReindexDateCFType.class);
	private final IssueIndexManager issueIndexManager;

	public ReindexDateCFType(
			CustomFieldValuePersister customFieldValuePersister,
			DatePickerConverter dateConverter,
			GenericConfigManager genericConfigManager,
			DateTimeFieldChangeLogHelper dateTimeFieldChangeLogHelper,
			DateFieldFormat dateFieldFormat,
			DateTimeFormatterFactory dateTimeFormatterFactory, 
			IssueIndexManager issueIndexManager) {
		super(customFieldValuePersister, dateConverter, genericConfigManager,
				dateTimeFieldChangeLogHelper, dateFieldFormat, dateTimeFormatterFactory);
		this.issueIndexManager = issueIndexManager;
	}
	
	@Override
	public void createValue(CustomField field, Issue issue, Object value) {
		super.createValue(field, issue, value);
		reindexIssue(issue);
	}
	
	@Override
    public void updateValue(CustomField field, Issue issue, Object value) {
		super.updateValue(field, issue, value);
		reindexIssue(issue);
    }
	
	private void reindexIssue(Issue issue) {
		try {
			boolean origVal = ImportUtils.isIndexIssues();
			ImportUtils.setIndexIssues(true);
			issueIndexManager.reIndex(issue.getGenericValue());
			ImportUtils.setIndexIssues(origVal);
		} catch (IndexException ie) {
			log.error("Unable to reindex issue: " + issue.getString("key")
					+ ", [id=" + issue.getLong("id") + "].", ie);
		}
	}

}

Omer April 11, 2012

Thank you for the provided code. The problem is, do you think direct modification on DB will trigger this new custom field type's methods?

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.
April 11, 2012

It won't, not without polling the db, which you don't want to do.

1 vote
Wojciech Seliga
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.
February 14, 2012

Do you mean here direct manipulation of DB? Or modifying this customfield via JIRA API? If the former, then mere reindexing may be insufficient and listeners will be not called at all (they are not DB triggersm, listeners are triggered only when issues are changed "legally" using JIRA API stack), if the latter it should be needed at all.

Nevertheless: take a look at com.atlassian.jira.issue.index.IssueIndexManager - more precisely at its reIndex(Issue) method.

You can easily inject IssueIndexManager implementaiton to any spring/pico managed component or retrieve it statically via com.atlassian.jira.ManagerFactory#getIndexManager or via com.atlassian.jira.ComponentManager#getIndexManager.

Omer April 11, 2012

I mean direct manipulation. Unfortunately I'm not that much experinced on JAVA and JIRA API to apply your advices. Thank you anyway.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events