11package ru .mail .jira .plugins .groovy .impl .jql .indexers ;
22
33import com .atlassian .jira .issue .Issue ;
4- import com .atlassian .jira .issue .changehistory .ChangeHistory ;
5- import com .atlassian .jira .issue .changehistory .ChangeHistoryManager ;
64import com .atlassian .jira .issue .index .indexers .impl .UserFieldIndexer ;
5+ import com .atlassian .jira .ofbiz .OfBizDelegator ;
6+ import com .atlassian .jira .ofbiz .OfBizListIterator ;
77import com .atlassian .jira .web .FieldVisibilityManager ;
88import com .atlassian .plugin .spring .scanner .annotation .component .Scanned ;
99import com .atlassian .plugin .spring .scanner .annotation .imports .ComponentImport ;
10+ import com .google .common .collect .ImmutableList ;
1011import org .apache .lucene .document .Document ;
12+ import org .ofbiz .core .entity .*;
1113
12- import java .util .List ;
1314
1415@ Scanned
1516public class LastUpdatedByIndexer extends UserFieldIndexer {
1617 public static final String LAST_UPDATED_BY_FIELD = "mrg_lastupd" ;
1718
18- private final ChangeHistoryManager changeHistoryManager ;
19+ private final OfBizDelegator ofBizDelegator ;
1920
2021 public LastUpdatedByIndexer (
21- @ ComponentImport ChangeHistoryManager changeHistoryManager ,
22- @ ComponentImport FieldVisibilityManager fieldVisibilityManager
22+ @ ComponentImport FieldVisibilityManager fieldVisibilityManager ,
23+ @ ComponentImport OfBizDelegator ofBizDelegator
2324 ) {
2425 super (fieldVisibilityManager );
25- this .changeHistoryManager = changeHistoryManager ;
26+ this .ofBizDelegator = ofBizDelegator ;
2627 }
2728
2829 @ Override
@@ -42,14 +43,24 @@ public boolean isFieldVisibleAndInScope(Issue issue) {
4243
4344 @ Override
4445 public void addIndex (Document document , Issue issue ) {
45- List <ChangeHistory > changeHistories = changeHistoryManager .getChangeHistories (issue );
46+ OfBizListIterator changeGroups = this .ofBizDelegator .findListIteratorByCondition (
47+ "ChangeGroup" ,
48+ new EntityExpr ("issue" , EntityOperator .EQUALS , issue .getId ()),
49+ null ,
50+ null ,
51+ ImmutableList .of ("created DESC" , "id DESC" ),
52+ new EntityFindOptions ().maxResults (1 )
53+ );
4654
47- if (changeHistories .size () > 0 ) {
48- ChangeHistory lastHistory = changeHistories .get (changeHistories .size () - 1 );
55+ GenericValue changeGroup = changeGroups .next ();
56+ if (changeGroup != null ) {
57+ String author = changeGroup .getString ("author" );
4958
50- if (lastHistory . getAuthorKey () != null ) {
51- this .indexUserKey (document , this .getDocumentFieldId (), lastHistory . getAuthorKey () , issue );// 22
59+ if (author != null ) {
60+ this .indexUserKey (document , this .getDocumentFieldId (), author , issue );
5261 }
5362 }
63+
64+ changeGroups .close ();
5465 }
5566}
0 commit comments