}
}
private void pullJiraActivity(Connection connection)
throws ConnectionNotFoundException, InvalidCredentialsException, IOException {
JiraClient client = (JiraClient)getClient(connection);
Map<String, InventoryItem> inventoryItemMap = getInventoryItemMap(connection);
Date lastActivityPoll = connection.getLastActivityPollDate();
Date lastActivity = lastActivityPoll;
try {
List<Entry> feedEntries = client.getActivity(inventoryItemMap.keySet());
if (feedEntries == null) {
return;
}
for (Entry entry : feedEntries) {
// To map project activity in Jira to a Nodeable ProjectHostingInventoryItem, we have
// to do some magic. Said magic is below.
Element activityObject = entry.getFirstChild(new QName("http://activitystrea.ms/spec/1.0/", "object",
"activity"));
String projectKey = client.getProjectKeyOfEntry(activityObject, inventoryItemMap.keySet());
if (projectKey == null) {
// If the projectKey is null here, this means we've gotten activity for a project we're monitoring
// but we were unable to map said activity to the project in question. This is a known issue and
// typically only seen in non-hosted Jira environments where people link their Jira project to other
// Atlassian products but do not use the same key for the Jira project and the project in the other
// Atlassian application. (SOBA-1193) Let's go ahead and log it so we do not forget but this is a
// known issue and should not become a ZenDesk ticket.
logger.error("Project key for Jira activity was unable to be found, possibly related to " +
"SOBA-1193: " + entry.toString().substring(0, 140));
// Move on to the next activity entry
continue;
}
InventoryItem inventoryItem = inventoryItemMap.get(projectKey);
// This can happen if the activity is from a project, or Jira Studio product, not associated with a
// project in our inventory system. (A good example of this is wiki changes. Each Jira Studio project
// gets its own wiki but you can create new wiki spaces that are not associated with a Jira Studio
// project and will end up without an inventory item in our system.)
if (inventoryItem == null) {
logger.error("Project with key of " + projectKey + " did not correspond with an inventory item, " +
"possibley related to SOBA-1193: " + entry.toString().substring(0, 140));
// Move on to the next activity entry
continue;
}
Date pubDate = entry.getPublished();
// Only create messages newer than the last activity poll date
if (pubDate.before(lastActivityPoll)) {
continue;
}
if (pubDate.after(lastActivity)) {
lastActivity = pubDate;
}
Map<String, Object> activityParts = client.getPartsForActivity(inventoryItem, entry);
// This can happen for unknown events which we log
if (activityParts == null) {
// We have ran into a Jira activity we do not know how to handle. Log the issue with as much
// detail as possible.