Parses query string parameters into a blank tree rule object. Used for updating individual rules @param query The HTTP query to work with @return A rule object filled in with changes @throws BadRequestException if some of the data was invalid
(HttpQuery query)
| 617 | * @throws BadRequestException if some of the data was invalid |
| 618 | */ |
| 619 | private TreeRule parseRule(HttpQuery query) { |
| 620 | final TreeRule rule = new TreeRule(parseTreeId(query, true)); |
| 621 | |
| 622 | if (query.hasQueryStringParam("type")) { |
| 623 | try { |
| 624 | rule.setType(TreeRule.stringToType(query.getQueryStringParam("type"))); |
| 625 | } catch (IllegalArgumentException e) { |
| 626 | throw new BadRequestException("Unable to parse the 'type' parameter", e); |
| 627 | } |
| 628 | } |
| 629 | if (query.hasQueryStringParam("field")) { |
| 630 | rule.setField(query.getQueryStringParam("field")); |
| 631 | } |
| 632 | if (query.hasQueryStringParam("custom_field")) { |
| 633 | rule.setCustomField(query.getQueryStringParam("custom_field")); |
| 634 | } |
| 635 | if (query.hasQueryStringParam("regex")) { |
| 636 | try { |
| 637 | rule.setRegex(query.getQueryStringParam("regex")); |
| 638 | } catch (PatternSyntaxException e) { |
| 639 | throw new BadRequestException( |
| 640 | "Unable to parse the 'regex' parameter", e); |
| 641 | } |
| 642 | } |
| 643 | if (query.hasQueryStringParam("separator")) { |
| 644 | rule.setSeparator(query.getQueryStringParam("separator")); |
| 645 | } |
| 646 | if (query.hasQueryStringParam("description")) { |
| 647 | rule.setDescription(query.getQueryStringParam("description")); |
| 648 | } |
| 649 | if (query.hasQueryStringParam("notes")) { |
| 650 | rule.setNotes(query.getQueryStringParam("notes")); |
| 651 | } |
| 652 | if (query.hasQueryStringParam("regex_group_idx")) { |
| 653 | try { |
| 654 | rule.setRegexGroupIdx(Integer.parseInt( |
| 655 | query.getQueryStringParam("regex_group_idx"))); |
| 656 | } catch (NumberFormatException e) { |
| 657 | throw new BadRequestException( |
| 658 | "Unable to parse the 'regex_group_idx' parameter", e); |
| 659 | } |
| 660 | } |
| 661 | if (query.hasQueryStringParam("display_format")) { |
| 662 | rule.setDisplayFormat(query.getQueryStringParam("display_format")); |
| 663 | } |
| 664 | //if (query.hasQueryStringParam("level")) { |
| 665 | try { |
| 666 | rule.setLevel(Integer.parseInt( |
| 667 | query.getRequiredQueryStringParam("level"))); |
| 668 | } catch (NumberFormatException e) { |
| 669 | throw new BadRequestException( |
| 670 | "Unable to parse the 'level' parameter", e); |
| 671 | } |
| 672 | //} |
| 673 | //if (query.hasQueryStringParam("order")) { |
| 674 | try { |
| 675 | rule.setOrder(Integer.parseInt( |
| 676 | query.getRequiredQueryStringParam("order"))); |
no test coverage detected