Versions Compared

Key

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

...

Let's assume that, after Reading Structure Content, you have StructureComponents instance and an instance of ForestSpec for a forest. We can read a number of attributes for a number of rows by going to StructureAttributeService.

Figure out which Attributes do you need

The service accepts multiple attribute specs in one request. If you need several attributes calculated – it's better to do that in one request.

Code Block
List<AttributeSpec<?>> attributeSet = new ArrayList<>();
attributeSet.add(CoreAttributeSpecs.KEY);
attributeSet.add(CoreAttributeSpecs.SUMMARY);
attributeSet.add(CoreAttributeSpecs.TOTAL_REMAINING_ESTIMATE);

CoreAttributeSpecs class and its parent class, SharedAttributeSpecs, contain some of the most popular attributes.

It's likely that you'll need to build you own attribute specification. For example, to address a numeric JIRA custom field and calculate total of that field based on sub-issues, you'll need the following.

Code Block
AttributeSpec<Number> customField =
  AttributeSpecBuilder.create("customfield", ValueFormat.NUMBER).params().set("fieldId", 10000).build();

AttributeSpec<Number> customFieldTotal =
  AttributeSpecBuilder.create(CoreAttributeSpecs.Id.SUM, ValueFormat.NUMBER).params().setAttribute(customField).build();

attributeSet.add(customFieldTotal);

Figure out which Rows do you need to calculate the Attributes for

For example, this could be all rows in that structure.

Code Block
LongList rows = myStructureComponents.getForestService().getForestSource(forestSpec).getLatest().getForest().getRows();
Tip

If you need to create a LongList manually, use LongArray implementation.

Call StructureAttributeService

This service calculates a matrix of values for each row and attribute you specify.

Code Block
RowValues values = myStructureComponents.getAttributeService().getAttributeValues(forestSpec, rows, attributeSet);
Info

There is a variation of getAttributeValues() method that accepts a Forest, rather than ForestSpec. It is recommended to use the variant that accepts ForestSpec whenever possible, because that variant uses caching.

Read out the result

The returned object contains values for all pairs of requested row and requested attribute.

Code Block
for (LongIterator ii : rows) {
  String key = values.get(ii.value(), CoreAttributeSpecs.KEY);
  Number total = values.get(ii.value(), customFieldTotal);
  ...
}