|
35 | 35 | import uk.co.spudsoft.query.defn.Argument;
|
36 | 36 | import uk.co.spudsoft.query.defn.DataType;
|
37 | 37 | import uk.co.spudsoft.query.defn.ArgumentValue;
|
| 38 | +import static uk.co.spudsoft.query.defn.DataType.Null; |
38 | 39 | import uk.co.spudsoft.query.defn.Format;
|
39 | 40 | import uk.co.spudsoft.query.exec.FilterFactory;
|
40 | 41 | import uk.co.spudsoft.query.exec.conditions.ConditionInstance;
|
@@ -169,25 +170,22 @@ void buildArguments(JsonGenerator generator, PipelineFile pipeline) throws IOExc
|
169 | 170 |
|
170 | 171 | private void buildArgument(Argument arg, JsonGenerator generator) throws IOException, IllegalStateException {
|
171 | 172 | switch (arg.getType()) {
|
172 |
| - case Date: |
173 |
| - case Time: |
174 |
| - case DateTime: |
175 |
| - buildDateTime(generator, arg); |
176 |
| - break; |
177 |
| - case Double: |
178 |
| - case Integer: |
179 |
| - case Long: |
180 |
| - buildNumber(generator, arg); |
181 |
| - break; |
182 |
| - case String: |
| 173 | + case Date, Time, DateTime -> buildDateTime(generator, arg); |
| 174 | + case Double, Integer, Long, Float -> buildNumber(generator, arg); |
| 175 | + case String -> { |
183 | 176 | if (!isNullOrEmpty(arg.getPossibleValues()) || !Strings.isNullOrEmpty(arg.getPossibleValuesUrl())) {
|
184 | 177 | buildSelect(generator, arg);
|
185 | 178 | } else {
|
186 | 179 | buildTextField(generator, arg);
|
187 | 180 | }
|
188 |
| - break; |
189 |
| - default: |
190 |
| - throw new IllegalStateException("New types added to DataType and not implemented here"); |
| 181 | + } |
| 182 | + case Boolean -> buildCheckBox(generator, arg); |
| 183 | + case Null -> { |
| 184 | + logger.warn("Argument {} is of null type", arg.getName()); |
| 185 | + } |
| 186 | + default -> { |
| 187 | + logger.warn("Argument {} is of unknown type ({})", arg.getName(), arg.getType()); |
| 188 | + } |
191 | 189 | }
|
192 | 190 | }
|
193 | 191 |
|
@@ -355,6 +353,36 @@ static LocalDateTime parseToLocalDateTime(String value) {
|
355 | 353 | }
|
356 | 354 | }
|
357 | 355 |
|
| 356 | + void buildCheckBox(JsonGenerator generator, Argument arg) throws IOException { |
| 357 | + try (CheckBox checkbox = new CheckBox(generator)) { |
| 358 | + checkbox |
| 359 | + .withLabel(arg.getTitle()) |
| 360 | + .withPlaceholder(arg.getPrompt()) |
| 361 | + .withDescription(arg.getDescription()) |
| 362 | + .withKey(arg.getName()) |
| 363 | + .withMultiple(arg.isMultiValued()) |
| 364 | + ; |
| 365 | + if (!Strings.isNullOrEmpty(arg.getDefaultValueExpression())) { |
| 366 | + JexlEvaluator evaluator = new JexlEvaluator(arg.getDefaultValueExpression()); |
| 367 | + Object result = evaluator.evaluateAsObject(requestContext, null); |
| 368 | + if (result != null) { |
| 369 | + try { |
| 370 | + Boolean defaultBoolean = (Boolean) DataType.Boolean.cast(result); |
| 371 | + if (defaultBoolean != null) { |
| 372 | + checkbox.withDefaultValue(defaultBoolean.toString()); |
| 373 | + } |
| 374 | + } catch (Throwable ex) { |
| 375 | + checkbox.withDefaultValue(result.toString()); |
| 376 | + } |
| 377 | + } |
| 378 | + } |
| 379 | + |
| 380 | + try (Validation v = checkbox.addValidate()) { |
| 381 | + v.withRequired(!arg.isOptional()); |
| 382 | + } |
| 383 | + } |
| 384 | + } |
| 385 | + |
358 | 386 | void buildDateTime(JsonGenerator generator, Argument arg) throws IOException {
|
359 | 387 | try (DateTime dateTime = new DateTime(generator)) {
|
360 | 388 | dateTime
|
|
0 commit comments