This section describes the implementation of persisting/caching Case data in JIRA Issue Entity Properties to make them programmatically available to external applications.  This addresses the current limitation where these properties, as a result of their being stored in Add-on specific Active Objects in JIRA, are not accessible outside the Add-on.

The sections below cover the configuration (turning on support of Entity Properties for Case data, configuring listeners to update events, etc.), as well as examples of how the information may be retrieved from Issue Entity Properties by external applications.

Configuration

Configuration page for entity properties is in JIRA Administration → Addons → Entity properties configuration

There are two options available here:

1) Store Case fields in JIRA Issue Properties: if enabled, all the Case fields sent to JIRA Issue Salesforce Properties panel will be also copied into JIRA Issue entity properties.

2) Launch zAgile Events: the first time it is enabled it will create 3 Custom JIRA Events (Issue Linked to Case, Issue Unlinked, and Case Entity properties updated). Once the events are created it will list them in the configuration page and display the ID for each custom event:

A JIRA Issue listener can be created in a custom plugin to listen for those Events IDs, retrieve the data and perform some actions based on the event.

Custom events creation

Custom events will be created in JIRA the first time “Launch zAgile Events” option is set to “ON” and saved. If for some reason later these events are deleted manually, they can be recreated by setting the option to “ON” again and Saving.

Events

  • ZAGILE_SF_ENTITY_LINKED
  • ZAGILE_SF_ENTITY_UNLINKED
  • ZAGILE_SF_ENTITY_UPDATED

These events will be launched so listener can handle them. There is some additional information sent with the event:

  • sfentityname:  this is the CaseNumber of the case linked, unlinked or updated.
  • entityproperty: This is the entity property created,deleted or updated.

Example of how to retrieve these parameters on Issue listener:

@EventListener
   public void onIssueEvent(IssueEvent issueEvent) {
       Long eventTypeId = issueEvent.getEventTypeId();  
       if (eventTypeId.equals(... zAgile Event ID ...)) {
            Map<String,Object> params = issueEvent.getParams();
            String caseNumber = params.get("sfentityname").toString();
            String issueEntityPropertyKey = params.get("entityproperty").toString();
       }
   }
CODE

To retrieve more Case fields, it is possible to access the JSON content of the issueEntityPropertyKey, using the IssuePropertyService.

Entity properties

Each linked case to an issue will create an entity property for the issue. The name of the entity property will follow the rule:

SF_ENTITY_<CASE_ID>
CODE

To list all the entity properties for an issue (all the linked cases for an issue) using JIRA REST API use:

http://<JIRA_BASE_URL>/rest/api/2/issue/DJ-2791/properties

{
"keys": [
            {"self": "http://<JIRA_BASE_URL>/rest/api/2/issue/30309/properties/SF_ENTITY_50036000002hF77AAE",
            "key": "SF_ENTITY_50036000002hF77AAE"},
            {"self": "http://<JIRA_BASE_URL>/rest/api/2/issue/30309/properties/SF_ENTITY_50036000002hGEMAA2",
            "key": "SF_ENTITY_50036000002hGEMAA2"}
        ]
}
CODE

To access the content for a particular entity property (Case fields) use:

http://<JIRA_BASE_URL>/rest/api/2/issue/30309/properties/SF_ENTITY_50036000002hF77AAE

CODE
{
"key": "SF_ENTITY_50036000002hF77AAE",
"value": {"IsClosed": false,
          "Priority": "Low",
          "CaseNumber": "00001008",
          "Id": "50036000002hF77AAE",
          "attributes": {"type": "Case"}
         }
}
CODE

These entity properties can be accessed programmatically in a JIRA Plugin using the IssuePropertyService as described here https://developer.atlassian.com/jiradev/jira-platform/building-jira-add-ons/jira-entity-properties-overview

These entity properties will be created, deleted and updated whenever the issue is linked to a Case, unlinked or the Case is updated, specifically if any of the fields sent to JIRA Salesforce Properties panel are updated.