From 4cd0afc504d7abf8f11f74b7ad9485b20f47cfff Mon Sep 17 00:00:00 2001 From: Manuel Rego Casasnovas Date: Wed, 30 Jan 2013 17:43:38 +0100 Subject: [PATCH] jira-integration: Simplify code in updateOrCreateDescriptionValuesAndAddToWorkReportLine As we know that the predefined WorkReportType will only have 1 DescriptionValue, we can take advantage of this to simplify the code. FEA: ItEr77S16JiraAndTimConnectorContributionIntegration --- .../importers/JiraTimesheetSynchronizer.java | 26 ++++++++----------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/libreplan-webapp/src/main/java/org/libreplan/importers/JiraTimesheetSynchronizer.java b/libreplan-webapp/src/main/java/org/libreplan/importers/JiraTimesheetSynchronizer.java index f836f336f..31506974a 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/importers/JiraTimesheetSynchronizer.java +++ b/libreplan-webapp/src/main/java/org/libreplan/importers/JiraTimesheetSynchronizer.java @@ -19,7 +19,6 @@ package org.libreplan.importers; -import java.util.HashSet; import java.util.List; import java.util.Set; @@ -243,21 +242,18 @@ public class JiraTimesheetSynchronizer implements IJiraTimesheetSynchronizer { */ private void updateOrCreateDescriptionValuesAndAddToWorkReportLine(WorkReportLine workReportLine, String comment) { - Set descriptionValues = new HashSet(); - for (DescriptionField descriptionField : workReportType.getLineFields()) { - DescriptionValue descriptionValue; - try { - descriptionValue = workReportLine - .getDescriptionValueByFieldName(descriptionField - .getFieldName()); - descriptionValue.setValue(comment.substring(0, - Math.min(comment.length(), 254))); - } catch (InstanceNotFoundException e) { - descriptionValue = DescriptionValue.create( - descriptionField.getFieldName(), comment); - } - descriptionValues.add(descriptionValue); + DescriptionField descriptionField = workReportType.getLineFields().iterator().next(); + comment = comment.substring(0, descriptionField.getLength() - 1); + + Set descriptionValues = workReportLine + .getDescriptionValues(); + if (descriptionValues.isEmpty()) { + descriptionValues.add(DescriptionValue.create( + descriptionField.getFieldName(), comment)); + } else { + descriptionValues.iterator().next().setValue(comment); } + workReportLine.setDescriptionValues(descriptionValues); }