Commits

Nick Pellow committed 87207dc

CONNECT-165: improved custom field handling. Now many more custom fields are supported, including Labels.

  • Participants
  • Parent commits 073202a
  • Branches 1.1

Comments (0)

Files changed (3)

 
 
     <properties>
-        <jira.version>5.0.1</jira.version>
+        <jira.version>5.0.2</jira.version>
         <jira.data.version>5.0</jira.data.version>
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
         <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

src/main/java/com/atlassian/jconnect/jira/IssueHelper.java

     {
         
         final IssueType issueType = resolveIssueType(issueEntity);
+//        IssueInputParameters issue = new IssueInputParametersImpl(); // TODO: issue input params: Y U NO SUPPORT LABELS ?
         final MutableIssue issue = issueFactory.getIssue();
 
         final HashMap<String, Version> allVersions = new HashMap<String, Version>();
             log.warn(missingUUIDMessage);
         }
         // store the issue
-        issueManager.createIssue(user, issue);
+        issueManager.createIssueObject(user, issue);
 
         log.debug(String.format("User %s created issue %s: %s", user.getName(), issue.getKey(), issue.getSummary()));
 

src/main/java/com/atlassian/jconnect/rest/resources/IssueResource.java

 import com.atlassian.jira.issue.CustomFieldManager;
 import com.atlassian.jira.issue.Issue;
 import com.atlassian.jira.issue.MutableIssue;
+import com.atlassian.jira.issue.customfields.view.CustomFieldParams;
+import com.atlassian.jira.issue.customfields.view.CustomFieldParamsImpl;
 import com.atlassian.jira.issue.fields.CustomField;
 import com.atlassian.jira.project.Project;
 import com.atlassian.jira.util.ErrorCollection;
         return Response.status(Response.Status.FORBIDDEN).entity("Missing uuid.");
     }
 
-    private void extractCustomFields(UploadData customfields, List<CustomField> fields, List<Object> values) throws JSONException, IOException {
+    private void extractCustomFields(UploadData customfields, List<CustomField> fields, List<Object> values) throws JSONException, IOException
+    {
 
         final JSONObject json = new JSONObject(IOUtils.toString(customfields.getInputStream(), "UTF-8"));
 
         final List<CustomField> allCustomFields = customFieldManager.getCustomFieldObjects();
         for (CustomField field : allCustomFields) {
             final String fieldNameLower = field.getName().toLowerCase();
-            if (json.has(fieldNameLower) || json.has(field.getName())) {
+            if (json.has(fieldNameLower) || json.has(field.getName()))
+            {
                 final String fieldValue = json.has(fieldNameLower) ? json.getString(fieldNameLower) : json.getString(field.getName());
-                if (fieldValue != null) {
+                addFieldAndValue(fields, values, field, fieldValue);
+            }
+        }
+    }
+
+    private void addFieldAndValue(List<CustomField> fields, List<Object> values, CustomField field, String fieldValue) {
+        if (fieldValue != null)
+        {
+            try {
+                final CustomFieldParams params = new CustomFieldParamsImpl(field, fieldValue);
+                final Object valueFromCustomFieldParams = field.getCustomFieldType().getValueFromCustomFieldParams(params);
+                if (valueFromCustomFieldParams != null)
+                {
+                    values.add(valueFromCustomFieldParams);
                     fields.add(field);
-                    values.add(field.getCustomFieldType().getSingularObjectFromString(fieldValue));
                 }
+                else
+                {
+                    log.debug("Value for custom field: " + field.getName() + " is null. This field will not be set.");
+                }
+            } catch (Exception e) {
+                log.info("Could not validate custom field value for field: " + field.getName() + " with value: " + fieldValue + ". Error: " + e.getMessage());
+                log.debug(e.getMessage(), e);
             }
+
         }
     }