View Javadoc
1   /*
2    * MoneyWise: Finance Application
3    * Copyright 2012-2026. Tony Washer
4    *
5    * Licensed under the Apache License, Version 2.0 (the "License"); you may not
6    * use this file except in compliance with the License.  You may obtain a copy
7    * of the License at
8    *
9    *   http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
14   * License for the specific language governing permissions and limitations under
15   * the License.
16   */
17  package io.github.tonywasher.joceanus.moneywise.data.validate;
18  
19  import io.github.tonywasher.joceanus.metis.field.MetisFieldRequired;
20  import io.github.tonywasher.joceanus.moneywise.data.basic.MoneyWisePayee;
21  import io.github.tonywasher.joceanus.moneywise.data.basic.MoneyWisePayeeInfo;
22  import io.github.tonywasher.joceanus.moneywise.data.basic.MoneyWisePayeeInfoSet;
23  import io.github.tonywasher.joceanus.moneywise.data.statics.MoneyWiseAccountInfoClass;
24  import io.github.tonywasher.joceanus.prometheus.data.PrometheusDataInfoClass;
25  import io.github.tonywasher.joceanus.prometheus.data.PrometheusDataItem;
26  import io.github.tonywasher.joceanus.prometheus.validate.PrometheusValidateInfoSet;
27  
28  /**
29   * Validate CashInfoSet.
30   */
31  public class MoneyWiseValidatePayeeInfoSet
32          extends PrometheusValidateInfoSet<MoneyWisePayeeInfo> {
33      @Override
34      public MoneyWisePayee getOwner() {
35          return (MoneyWisePayee) super.getOwner();
36      }
37  
38      @Override
39      public MetisFieldRequired isClassRequired(final PrometheusDataInfoClass pClass) {
40          /* Switch on class */
41          switch ((MoneyWiseAccountInfoClass) pClass) {
42              /* Allowed set */
43              case NOTES:
44              case SORTCODE:
45              case ACCOUNT:
46              case REFERENCE:
47              case WEBSITE:
48              case CUSTOMERNO:
49              case USERID:
50              case PASSWORD:
51                  return MetisFieldRequired.CANEXIST;
52  
53              /* Not allowed */
54              case MATURITY:
55              case OPENINGBALANCE:
56              case AUTOEXPENSE:
57              case AUTOPAYEE:
58              case SYMBOL:
59              case REGION:
60              case UNDERLYINGSTOCK:
61              case OPTIONPRICE:
62              default:
63                  return MetisFieldRequired.NOTALLOWED;
64          }
65      }
66  
67      @Override
68      public void validateClass(final MoneyWisePayeeInfo pInfo,
69                                final PrometheusDataInfoClass pClass) {
70          /* Switch on class */
71          switch ((MoneyWiseAccountInfoClass) pClass) {
72              case WEBSITE:
73              case CUSTOMERNO:
74              case USERID:
75              case PASSWORD:
76              case SORTCODE:
77              case ACCOUNT:
78              case NOTES:
79              case REFERENCE:
80                  validateInfoLength(pInfo);
81                  break;
82              default:
83                  break;
84          }
85      }
86  
87      /**
88       * Validate the info length.
89       *
90       * @param pInfo the info
91       */
92      private void validateInfoLength(final MoneyWisePayeeInfo pInfo) {
93          final char[] myArray = pInfo.getValue(char[].class);
94          final MoneyWiseAccountInfoClass myClass = pInfo.getInfoClass();
95          if (myArray.length > myClass.getMaximumLength()) {
96              getOwner().addError(PrometheusDataItem.ERROR_LENGTH, MoneyWisePayeeInfoSet.getFieldForClass(myClass));
97          }
98      }
99  }