Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,553,303
Community Members
 
Community Events
184
Community Groups

ScriptRunner fails to implement Liskov principle?

Because issuePicker custom field is not parseable (does not support IN or IN (subquery) ) by search I'm trying to implement own JQL search plugin to run something like this:

 

project = MYPROJECT and issuetype = Epic and issueFunction in issuePickerSearch("Project Link", "filter=12345")

 

Which should return all Epics whose "Project Link" is on the list of the issues returned by filter

 

The code itself works fine, but the problem is at the very end after getQuery method of my issuePickerSearch plugin returns the results to Jira:

 

public Query getQuery(QueryCreationContext queryCreationContext, FunctionOperand operand, TerminalClause terminalClause) {

BooleanQuery.Builder boolQueryBuilder = new BooleanQuery.Builder();

String searchField = operand.getArgs().get(0);
CustomField customField = customFieldManager.getCustomFieldObjectByName(searchField);

SearchService.ParseResult searchByFilter = searchService
.parseQuery(user, operand.getArgs().get(1));

if (searchByFilter.isValid()) {
SearchResults resultIssuesInFilter;

try {
List<Issue> allIssuesWithCustomField = getAllIssuesWithCustomField(customField);
resultIssuesInFilter = searchService
.search(user, searchByFilter.getQuery(), PagerFilter.getUnlimitedFilter());

List<String> matchingParentKeys = resultIssuesInFilter.getIssues().stream()
.map(Issue::getKey)
.collect(Collectors.toList());


List<Issue> foundIssues = allIssuesWithCustomField.stream()
.filter(i -> hasParentInFilter(i, matchingParentKeys, customField))
.collect(Collectors.toList());


BooleanQuery.setMaxClauseCount(foundIssues.size());

foundIssues.forEach(issue -> boolQueryBuilder
.add(new TermQuery(new Term("issue_id", issue.getId().toString())),
Occur.SHOULD));


} catch (SearchException | NullPointerException e) {
log.error("Major search error: {}", e);
return null;
}

}

return boolQueryBuilder.build();
}

 

The code above throws     

org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object  with class 'org.apache.lucene.search.BooleanQuery' to class 'org.apache.lucene.search.Query'

 

How come? BooleanQuery extends Query and according to Liskov's principle should be perfectly compatible

 

Jira 7.2.9

Scriptrunner  5.5.9

 

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events