jira-integration: Prevent error if found OrderElement is not a line

There was a cast without checking if the OrderElement was or not a line, so it
could cause exceptions in some cases.

On the other hand the OrderLine gotten or created in
JiraOrderElementSynchronizer.syncOrderLine is used in the next methods too.

FEA: ItEr77S16JiraAndTimConnectorContributionIntegration
This commit is contained in:
Manuel Rego Casasnovas 2013-01-29 19:27:15 +01:00
parent da13e85326
commit f912cb6dc5

View file

@ -98,14 +98,17 @@ public class JiraOrderElementSynchronizer implements IJiraOrderElementSynchroniz
+ issue.getKey();
String name = issue.getFields().getSummary();
syncOrderLine(order, code, name);
OrderLine orderLine = syncOrderLine(order, code, name);
if (orderLine == null) {
jiraSyncInfo.addSyncFailedReason("Order-element for '"
+ issue.getKey() + "' issue not found");
continue;
}
syncHoursGroup(orderLine, code, getEstimatedHours(issue.getFields()
.getTimetracking()));
syncHoursGroup(
(OrderLine) order.getOrderElement(code), code,
getEstimatedHours(issue.getFields().getTimetracking()));
syncProgressMeasurement(order.getOrderElement(code), issue);
syncProgressMeasurement(orderLine, issue);
}
}
@ -126,15 +129,21 @@ public class JiraOrderElementSynchronizer implements IJiraOrderElementSynchroniz
* @param name
* name for the orderLine to be added or updated
*/
private void syncOrderLine(Order order, String code,
private OrderLine syncOrderLine(Order order, String code,
String name) {
OrderLine orderLine = (OrderLine) order.getOrderElement(code);
OrderElement orderElement = order.getOrderElement(code);
if (orderElement != null && !orderElement.isLeaf()) {
return null;
}
OrderLine orderLine = (OrderLine) orderElement;
if (orderLine == null) {
orderLine = OrderLine.create();
orderLine.setCode(code);
order.add(orderLine);
}
orderLine.setName(name);
return orderLine;
}
/**
@ -167,13 +176,13 @@ public class JiraOrderElementSynchronizer implements IJiraOrderElementSynchroniz
/**
* Synchronize progress assignment and measurement
*
* @param orderElement
* an exist orderElement
* @param orderLine
* an exist orderLine
* @param issue
* jira's issue to synchronize with progress assignment and
* measurement
*/
private void syncProgressMeasurement(OrderElement orderElement, Issue issue) {
private void syncProgressMeasurement(OrderLine orderLine, Issue issue) {
WorkLog workLog = issue.getFields().getWorklog();
@ -182,11 +191,6 @@ public class JiraOrderElementSynchronizer implements IJiraOrderElementSynchroniz
+ issue.getKey() + "' issue");
return;
}
if (orderElement == null) {
jiraSyncInfo.addSyncFailedReason("Order-element for '"
+ issue.getKey() + "' issue not found");
return;
}
List<WorkLogItem> workLogItems = workLog.getWorklogs();
if (workLogItems.isEmpty()) {
@ -221,7 +225,7 @@ public class JiraOrderElementSynchronizer implements IJiraOrderElementSynchroniz
LocalDate latestWorkLogDate = LocalDate
.fromDateFields(getTheLatestWorkLoggedDate(workLogItems));
updateOrCreateProgressAssignmentAndMeasurement(orderElement,
updateOrCreateProgressAssignmentAndMeasurement(orderLine,
percentage, latestWorkLogDate);
}