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,456,300
Community Members
 
Community Events
176
Community Groups

ScriptRunner:com.decadis.jira.xchart.api.model.Period, check the plugin is installed / enabled / lic

Edited

Hi Dear All:

I met a difficult when i run my script in the ScriptRunner , This Problem makes me puzzled in the past two days, if there somebady can solve this problem, please make me know, Thanks.

error:

Script console script failed: java.lang.Exception: Can't find plugin module or OSGi service for class: com.decadis.jira.xchart.api.model.Period, check the plugin is installed / enabled / licensed.

JIRA Version:8.2.1                       ScriptRunner Version: 5.5.9.1-jira8

 

You can find the API in https://apps.decadis.net/display/XCHARTS/Latest+xCharts+API+Javadoc

 

code:

import java.lang.reflect.Field;

import java.math.BigDecimal;
import java.util.Date;

import org.apache.lucene.document.Document;

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.DocumentIssueImpl;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.IssueFieldConstants;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.fields.FieldManager;
import com.atlassian.jira.jql.builder.JqlClauseBuilder;
import com.atlassian.jira.jql.builder.JqlQueryBuilder;
import com.atlassian.jira.jql.parser.JqlQueryParser;
import com.atlassian.query.Query;
import com.atlassian.query.operator.Operator;
import com.atlassian.jira.jql.parser.JqlParseException
import com.atlassian.jira.user.ApplicationUser

import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.decadis.jira.xchart.api.util.ChartBuilder
//import com.decadis.jira.xchart.api.ChartParam;
import com.decadis.jira.xchart.api.model.Period;
import com.decadis.jira.xchart.api.util.DateUtils;

@WithPlugin("com.decadis.jira.xchart.xchart-core")

@PluginModule
Period period

@PluginModule
ChartBuilder chartBuilder

@PluginModule
DateUtils dateUtils

def DateFieldParam="created";
def TimePeriod="DAY";
def ValuePicker="issueCount";
def GroupBy="resolution";
def From="-14d";
def JQL="project = OCC AND resolution = Unresolved";
def ChartType="bar";

def fieldManager = ComponentAccessor.getFieldManager();
def i18n = ComponentAccessor.getJiraAuthenticationContext().getI18nHelper();

String dateField = DateFieldParam;
if ( dateField.isEmpty() )
{
dateField = IssueFieldConstants.CREATED;
}

com.atlassian.jira.issue.fields.Field dateFieldObject = fieldManager.getField(dateField);
boolean isCustomField = fieldManager.isCustomField(dateFieldObject);
Period selectedPeriod = period.fromString(TimePeriod);


JqlQueryParser jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser.class);
Query query = null;

JqlClauseBuilder jqlClauseBuilder = JqlQueryBuilder.newClauseBuilder(jqlQueryParser.parseQuery(JQL));

Date start = chartBuilder.getDateFromParam(From);


String searchKey = dateFieldObject.getId();
if ( isCustomField ) {
searchKey = "cf[" + ((CustomField) dateFieldObject).getIdAsLong() + "]";
}

jqlClauseBuilder.defaultAnd();
if ( start != null ) {
jqlClauseBuilder.addDateCondition(searchKey, Operator.GREATER_THAN_EQUALS, start);
}


query = jqlClauseBuilder.buildQuery();

 

def countGroup = chartBuilder.newDataCollector();
def valueExtractor = chartBuilder.getValueExtractor(ValuePicker);

if ( valueExtractor == null )
{
throw new IllegalArgumentException("Valuepicker for " + ValuePicker + " is not supported.");
}

def groupValueExtractor = chartBuilder.getGrouper(GroupBy);
Field documentField;
try
{
documentField = DocumentIssueImpl.class.getDeclaredField("document");
documentField.setAccessible(true);

for ( Issue issue : chartBuilder.getFilterUtils().performSearchOverrideSecurity(query) )
{
Document document = (Document) documentField.get(issue);
String[] groups = groupValueExtractor.getGroups((Document) documentField.get(issue));

for ( String group : groups )
{
Date dateFromField = new Date();
if ( isCustomField ) {
dateFromField = (Date) issue.getCustomFieldValue((CustomField) dateFieldObject);
}
else
{
switch ( dateFieldObject.getId() ) {
case IssueFieldConstants.CREATED:
dateFromField = issue.getCreated();
break;
case IssueFieldConstants.UPDATED:
dateFromField = issue.getUpdated();
break;
case IssueFieldConstants.RESOLUTION_DATE:
dateFromField = issue.getResolutionDate();
break;
case IssueFieldConstants.DUE_DATE:
dateFromField = issue.getDueDate();
break;
default:
dateFromField = new Date();
break;
}
}
countGroup.addValue(valueExtractor.get(issue, document), group, dateUtils.getPeriodGroup(dateFromField, selectedPeriod));
}
}
} catch (Exception e) {
System.out.println("Could not extract groups" + e);
}

countGroup.fillMissingValues();
log.warn(countGroup);

def chartData = chartBuilder.newChartData(i18n.getText("common.concepts.issues"));

for ( String grpKey : countGroup.keySet() )
{
chartData.addGroupName(grpKey, groupValueExtractor.getResolvedValue(grpKey, null));
}

chartData.setxFormat(dateUtils.SimpleDateFormatD3);
chartData.setPeriod(selectedPeriod);


chartData.setType(ChartType);


chartBuilder.getChartUtil().transformResult(countGroup, chartData, true);
return chartData;

 

 

 

 

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events