(Context context)
| 701 | } |
| 702 | |
| 703 | void validate(Context context) throws JSONException, IllegalArgumentException { |
| 704 | try { |
| 705 | Expression expression = ExpressionHelper.getExpression(this, null, null, null, context); |
| 706 | if (expression != null) |
| 707 | ExpressionHelper.check(expression); |
| 708 | } catch (ParseException | MessagingException ex) { |
| 709 | Log.w("EXPR", ex); |
| 710 | String message = ex.getMessage(); |
| 711 | if (TextUtils.isEmpty(message)) |
| 712 | message = "Invalid expression"; |
| 713 | throw new IllegalArgumentException(message, ex); |
| 714 | } |
| 715 | |
| 716 | JSONObject jargs = new JSONObject(action); |
| 717 | int type = jargs.getInt("type"); |
| 718 | |
| 719 | DB db = DB.getInstance(context); |
| 720 | switch (type) { |
| 721 | case TYPE_NOOP: |
| 722 | return; |
| 723 | case TYPE_SEEN: |
| 724 | return; |
| 725 | case TYPE_UNSEEN: |
| 726 | return; |
| 727 | case TYPE_HIDE: |
| 728 | return; |
| 729 | case TYPE_IGNORE: |
| 730 | return; |
| 731 | case TYPE_SNOOZE: |
| 732 | return; |
| 733 | case TYPE_FLAG: |
| 734 | return; |
| 735 | case TYPE_IMPORTANCE: |
| 736 | return; |
| 737 | case TYPE_KEYWORD: |
| 738 | String keyword = jargs.optString("keyword"); |
| 739 | if (TextUtils.isEmpty(keyword)) |
| 740 | throw new IllegalArgumentException(context.getString(R.string.title_rule_keyword_missing)); |
| 741 | return; |
| 742 | case TYPE_MOVE: |
| 743 | case TYPE_COPY: |
| 744 | long target = jargs.optLong("target", -1); |
| 745 | if (target < 0) |
| 746 | throw new IllegalArgumentException(context.getString(R.string.title_rule_folder_missing)); |
| 747 | EntityFolder folder = db.folder().getFolder(target); |
| 748 | if (folder == null) |
| 749 | throw new IllegalArgumentException("Folder not found"); |
| 750 | return; |
| 751 | case TYPE_ANSWER: |
| 752 | long iid = jargs.optLong("identity", -1); |
| 753 | if (iid < 0) |
| 754 | throw new IllegalArgumentException(context.getString(R.string.title_rule_identity_missing)); |
| 755 | EntityIdentity identity = db.identity().getIdentity(iid); |
| 756 | if (identity == null) |
| 757 | throw new IllegalArgumentException("Identity not found"); |
| 758 | |
| 759 | long aid = jargs.optLong("answer", -1); |
| 760 | if (aid < 0) { |
no test coverage detected