@@ -81,7 +81,8 @@ public static Ticket toTicket(IssueBean jiraIssue, String jiraUrl) {
8181 return ticket ;
8282 }
8383
84- public static IssueUpdateDetails toIssueInput (JiraRestClient client , Project jiraProject , IssueTypeDetails issueType , PostTicketRQ ticketRQ ,
84+ public static IssueUpdateDetails toIssueInput (JiraRestClient client , Project jiraProject , IssueTypeDetails issueType ,
85+ PostTicketRQ ticketRQ ,
8586 JIRATicketDescriptionService descriptionService ) {
8687 String userDefinedDescription = "" ;
8788 IssueUpdateDetails issueUpdateDetails = new IssueUpdateDetails ();
@@ -164,14 +165,11 @@ public static IssueUpdateDetails toIssueInput(JiraRestClient client, Project jir
164165
165166 var cimFieldInfo = cimIssueType .getFirst ().getFields ().get (one .getId ());
166167 // Arrays and fields with 'allowedValues' handler
167- if (cimFieldInfo .getAllowedValues () != null ) {
168+ if (CollectionUtils . isNotEmpty ( cimFieldInfo .getAllowedValues ()) ) {
168169 try {
169170 List <Object > arrayOfValues = new ArrayList <>();
170- for (Object o : new ArrayList <>(cimFieldInfo .getAllowedValues ())) {
171- JsonNode jn = new ObjectMapper ().valueToTree (o );
172- if (isCustomField (jn ) && one .getValue ().contains (jn .get ("value" ).asText ())) {
173- arrayOfValues .add (Map .entry ("id" , jn .get ("id" ).asText ()));
174- }
171+ for (Object allowedValue : new ArrayList <>(cimFieldInfo .getAllowedValues ())) {
172+ mapAllowedValue (one , cimFieldInfo , allowedValue , arrayOfValues );
175173 }
176174 if (one .getFieldType ().equalsIgnoreCase (IssueFieldType .ARRAY .getName ())) {
177175 issueUpdateDetails .putFieldsItem (one .getId (), arrayOfValues );
@@ -184,7 +182,9 @@ public static IssueUpdateDetails toIssueInput(JiraRestClient client, Project jir
184182 }
185183 } else {
186184 if (one .getFieldType ().equalsIgnoreCase (IssueFieldType .ARRAY .getName ())) {
187- issueUpdateDetails .putFieldsItem (one .getId (), one .getValue ());
185+ List <Object > arrayOfValues = new ArrayList <>();
186+ one .getValue ().forEach (value -> arrayOfValues .add (Map .entry ("value" , value )));
187+ issueUpdateDetails .putFieldsItem (one .getId (), arrayOfValues );
188188 } else if (one .getFieldType ().equalsIgnoreCase (IssueFieldType .NUMBER .getName ())) {
189189 issueUpdateDetails .putFieldsItem (one .getId (), Long .valueOf (one .getValue ().get (0 )));
190190 } else if (one .getFieldType ().equalsIgnoreCase (IssueFieldType .USER .getName ())) {
@@ -219,13 +219,37 @@ public static IssueUpdateDetails toIssueInput(JiraRestClient client, Project jir
219219 return issueUpdateDetails ;
220220 }
221221
222+ private static void checkAllowedValues (List <Object > allowedValues , List <String > value ) {
223+ System .out .println ("Checking allowed values" );
224+ }
225+
226+ private static void mapAllowedValue (PostFormField postFormField , FieldMetadata fieldMetadata , Object allowedValue ,
227+ List <Object > result ) {
228+ JsonNode jn = new ObjectMapper ().valueToTree (allowedValue );
229+ if (isCustomField (jn ) && postFormField .getValue ().contains (jn .get ("value" ).asText ())) {
230+ result .add (Map .entry ("id" , jn .get ("id" ).asText ()));
231+ } else if (isMultiselectField (postFormField , fieldMetadata )
232+ && postFormField .getValue ().contains (jn .get ("name" ).asText ())) {
233+ result .add (Map .entry ("name" , jn .get ("name" ).asText ()));
234+ }
235+
236+ }
237+
222238 private static boolean isLabelField (PostFormField one , FieldMetadata cimFieldInfo ) {
223239 return (cimFieldInfo .getSchema () != null && cimFieldInfo .getSchema ().getCustom () != null
224240 && (cimFieldInfo .getSchema ().getCustom ().equals ("com.atlassian.jira.plugin.system.customfieldtypes:labels" )))
225241 || one .getId ().equalsIgnoreCase (IssueField .LABELS_FIELD .getValue ());
226242 }
227243
228- private static void processArrayValue (IssueUpdateDetails issueUpdateDetails , FieldMetadata cimFieldInfo , PostFormField one ,
244+ private static boolean isMultiselectField (PostFormField one , FieldMetadata cimFieldInfo ) {
245+ return (cimFieldInfo .getSchema () != null
246+ && cimFieldInfo .getSchema ().getCustom () != null
247+ && (cimFieldInfo .getSchema ().getCustom ()
248+ .equals ("com.atlassian.jira.plugin.system.customfieldtypes:multiversion" )));
249+ }
250+
251+ private static void processArrayValue (IssueUpdateDetails issueUpdateDetails , FieldMetadata cimFieldInfo ,
252+ PostFormField one ,
229253 List <Object > arrayOfValues ) {
230254 if (cimFieldInfo .getSchema () != null
231255 && cimFieldInfo .getSchema ().getCustom () != null
0 commit comments