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

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

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
Community showcase
Published in Apps & Integrations

🍻🍂Apptoberfest Update: Upcoming Virtual Events 🎉

Hello Community! I hope you've been enjoying the 🍂Apptoberfestivities🍂 (I know I have!) The event is heating up next week with a series of virtual events that we're calling the 🍻🍂Partner App ...

83 views 1 6
Read article

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