It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Writing a Jira plugin: how to find issues changed after a given date? Edited

I'm writing a plugin for Jira.
I need to find issues that were changed after a given date.
Please tell me, how I can do that.

IssueManager can only find issues by id and list of ids.

1 answer

@Component
public class Utils{

    @ComponentImport
    private SearchProvider searchProvider;

    @ComponentImport
    private UserManager userManager;

    @ComponentImport
    private IssueManager issueManager;


    @Inject
    public Utils( IssueManager issueManager, UserManager userManager, SearchProvider searchProvider ){
        this.issueManager = issueManager;
        this.userManager = userManager;
        this.searchProvider = searchProvider;
        ...
    }

    ...

    public List<Issue> getIssuesByDateUpdateAfter( Date dTime ) throws SearchException{
        JqlQueryBuilder builder = JqlQueryBuilder.newBuilder();
        builder.where().addDateCondition( IssueFieldConstants.UPDATED, Operator.GREATER_THAN_EQUALS, dTime );
        return searchIssues( builder.buildQuery() );
    }

    public List<Issue> searchIssues( Query query ){
        ApplicationUser user = userManager.getUserByName( username );
        SearchQuery searchQuery = SearchQuery.create( query, user );
        IssueIdCollector collector = new IssueIdCollector();
        try{
            ThreadLocalSearcherCache.startSearcherContext();
            searchProvider.search( searchQuery, collector );
        }catch( Exception e ){
            e.getMessage();
        }finally{
            ThreadLocalSearcherCache.stopAndCloseSearcherContext();
        }
        return searchIssues(collector);
    }

    public List<Issue> searchIssues(IssueIdCollector collector){
        Set<String> strIds = collector.getIssueIds();
        List<Long> ids = new ArrayList<>();
        for( String strId : strIds ){
            ids.add( Long.parseLong( strId ) );
        }
        return issueManager.getIssueObjects( ids );
    }

    ...
}

Suggest an answer

Log in or Sign up to answer
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you