6
6
7
7
import java .util .*;
8
8
import java .util .regex .Matcher ;
9
- import java .util .regex .Pattern ;
10
- import java .util .stream .Collectors ;
11
9
12
10
/**
13
11
* This class represents the request to create a new subtask with the given attributes.
@@ -40,12 +38,6 @@ public static class Attributes {
40
38
41
39
}
42
40
43
- // custom fields can be referenced by id: customfield_12345:
44
- private static final Pattern CUSTOM_FIELD_ID_PATTERN = Pattern .compile ("customfield_\\ d{5}" );
45
-
46
- // custom fields can be reference by name: customfield(fieldname):
47
- private static final Pattern CUSTOM_FIELD_NAME_PATTERN = Pattern .compile ("customfield\\ ((?<name>(?:\\ \\ \\ \\ |\\ \\ \\ )|[^)])++)\\ )" );
48
-
49
41
private final String summary ;
50
42
private final String description ;
51
43
private final String assignee ;
@@ -226,8 +218,8 @@ private String ensureValidEstimate(ArrayListMultimap<String, String> attributes)
226
218
227
219
private void verifyOnlyKnownAttributes (ArrayListMultimap <String , String > attributes ) {
228
220
attributes .forEach ((key , value ) -> {
229
- if (!Attributes .ALL .contains (key ) && !CUSTOM_FIELD_ID_PATTERN .matcher (key ).matches ()
230
- && !CUSTOM_FIELD_NAME_PATTERN .matcher (key ).matches ())
221
+ if (!Attributes .ALL .contains (key ) && !CustomFields . CUSTOM_FIELD_ID_PATTERN .matcher (key ).matches ()
222
+ && !CustomFields . CUSTOM_FIELD_NAME_PATTERN .matcher (key ).matches ())
231
223
throw new SyntaxFormatException ("Unknown attribute " + key + " found." );
232
224
});
233
225
}
@@ -261,7 +253,7 @@ private String ensureValidDueDate(ArrayListMultimap<String, String> attributes)
261
253
private Map <String , List <String >> extractCustomFieldsById (ArrayListMultimap <String , String > attributes ) {
262
254
// get all custom field keys
263
255
List <String > customFieldKeys = attributes .keySet ().stream ()
264
- .filter (s -> CUSTOM_FIELD_ID_PATTERN .matcher (s ).matches ())
256
+ .filter (s -> CustomFields . CUSTOM_FIELD_ID_PATTERN .matcher (s ).matches ())
265
257
.toList ();
266
258
// collect all keys and values into a map
267
259
Map <String , List <String >> customFields = new HashMap <>();
@@ -272,25 +264,12 @@ private Map<String, List<String>> extractCustomFieldsById(ArrayListMultimap<Stri
272
264
private Map <String , List <String >> extractCustomFieldsByName (ArrayListMultimap <String , String > attributes ) {
273
265
// get all custom field keys
274
266
List <String > customFieldKeys = attributes .keySet ().stream ()
275
- .filter (s -> CUSTOM_FIELD_NAME_PATTERN .matcher (s ).matches ())
267
+ .filter (s -> CustomFields . CUSTOM_FIELD_NAME_PATTERN .matcher (s ).matches ())
276
268
.toList ();
277
269
// collect all keys and values into a map
278
270
Map <String , List <String >> customFields = new HashMap <>();
279
- customFieldKeys .forEach (key -> customFields .put (extractCustomFieldName (key ), new ArrayList <>(attributes .get (key ))));
271
+ customFieldKeys .forEach (key -> customFields .put (CustomFields . extractCustomFieldName (key ), new ArrayList <>(attributes .get (key ))));
280
272
return customFields ;
281
273
}
282
274
283
- private String extractCustomFieldName (String customFieldString ) {
284
- Matcher matcher = CUSTOM_FIELD_NAME_PATTERN .matcher (customFieldString );
285
- if (matcher .matches ()) {
286
- return matcher .group ("name" )
287
- .replaceAll ("\\ \\ \\ )" , ")" )
288
- .replaceAll ("\\ \\ \\ (" , "(" )
289
- .replaceAll ("\\ \\ :" , ":" )
290
- .trim ();
291
- } else {
292
- throw new SyntaxFormatException ("Illegal custom field name: " + customFieldString );
293
- }
294
- }
295
-
296
275
}
0 commit comments