Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.


Page properties
hiddentrue





UI Text Box
sizemedium
typeinfo

On this page, we explain the new block search functionality and compare it with the old simple search.

The goal is for scriptwriters to understand what they need to change in their scripts, in order to benefit from the improved performance.


UI Text Box
typenote

We recommend adapting the existing scripts because they will be visibly faster for a large number of issues!

First, we will show an example of a simple search script, which then we will transform into a script processed in blocks, with comments and explanations.

For this, we will transform the chart from this example: Simple Timeseries Chart


UI Expand
titleSimple Search


Code Block
languagejs
themeMidnight
linenumberstrue
import java.math.BigDecimal;
import java.text.DateFormat;
import java.util.Calendar;
  
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.jql.parser.JqlParseException;
import com.atlassian.jira.jql.parser.JqlQueryParser;
import com.atlassian.query.Query;
import com.decadis.jira.xchart.api.model.Period;
import com.decadis.jira.xchart.api.util.DateUtils;
import com.decadis.jira.xchart.api.model.ChartData;
  
  
def metaCountGroup = chartBuilder.newDataCollector();
DateFormat dateFormat = DateUtils.SimpleDateFormat;
  
JqlQueryParser jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser.class);
Query query = null;
  
try
{
  query = jqlQueryParser.parseQuery(JQL); //JQL is a parameter of type Jql Autocomplete Picker
} catch (JqlParseException e)
{
  throw new IllegalArgumentException("Bad JQL: " + query);
}
  
Period selectedPeriod = Period.MONTH;
 
/** start of code block that will be changed in the new version */
for ( Issue issue : chartBuilder.getFilterUtils().performSearchOverrideSecurity(query) )
{
  Calendar cwCreated = dateUtils.getStartOfPeriod(issue.getCreated(), selectedPeriod);
  String cw = dateFormat.format(cwCreated.getTime());
  metaCountGroup.addValue(BigDecimal.ONE, issue.getIssueType().getName(), cw);
}
/** end */
ChartData chartData = chartBuilder.newChartData("Issues");
chartData.setxFormat("%Y.%m.%d");
chartData.setType("line");
  
chartBuilder.getChartUtil().transformResult(metaCountGroup, chartData, false);
  
return chartData;



UI Expand
titleBlock Search


Code Block
languagejs
themeMidnight
linenumberstrue
import java.math.BigDecimal;
import java.text.DateFormat;
import java.util.Calendar;
 
import org.apache.lucene.document.Document;
 
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.jql.parser.JqlParseException;
import com.atlassian.jira.jql.parser.JqlQueryParser;
import com.atlassian.query.Query;
 
import com.decadis.jira.xchart.api.model.Period;
import com.decadis.jira.xchart.api.util.DateUtils;
import com.decadis.jira.xchart.api.model.ChartData;
import com.decadis.jira.xchart.api.ForeachDocumentIssue;
  
def metaCountGroup = chartBuilder.newDataCollector();
DateFormat dateFormat = DateUtils.SimpleDateFormat;
  
JqlQueryParser jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser.class);
Query query = null;
  
try
{
  query = jqlQueryParser.parseQuery(JQL); //JQL is a parameter of type Jql Autocomplete Picker
} catch (JqlParseException e)
{
  throw new IllegalArgumentException("Bad JQL: " + query);
}
 
Period selectedPeriod = Period.MONTH;
/**
* START NEW METHOD
* the searchClosure is the actual functionality that we want executed in each block search
* this can be as complex as you want - see BusinessChart example, there we use the new functionality, and the processing in blocks is more complex
*/
ForeachDocumentIssue searchClosure = {Issue issue, Document doc ->
    Calendar cwCreated = dateUtils.getStartOfPeriod(issue.getCreated(), selectedPeriod);
    String cw = dateFormat.format(cwCreated.getTime());
    metaCountGroup.addValue(BigDecimal.ONE, issue.getIssueType().getName(), cw);
}
 
chartBuilder.getFilterUtils().blockSearch(searchClosure, query, user); 
/** END */
 
ChartData chartData = chartBuilder.newChartData("Issues");
chartData.setxFormat("%Y.%m.%d");
chartData.setType("line");
 
chartBuilder.getChartUtil().transformResult(metaCountGroup, chartData, false);
 
return chartData;




Related examples

Page properties report
cqllabel = "chart_script_example" and space = currentSpace()


Excerpt Include
DECADIS:Contact support
DECADIS:Contact support
nopaneltrue