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.moneywise.data.statics.MoneyWiseCurrency;
20  import io.github.tonywasher.joceanus.moneywise.data.statics.MoneyWiseCurrency.MoneyWiseCurrencyDataMap;
21  import io.github.tonywasher.joceanus.moneywise.data.statics.MoneyWiseCurrency.MoneyWiseCurrencyList;
22  import io.github.tonywasher.joceanus.moneywise.data.statics.MoneyWiseStaticResource;
23  import io.github.tonywasher.joceanus.prometheus.data.PrometheusData.PrometheusDataItemCtl;
24  import io.github.tonywasher.joceanus.prometheus.data.PrometheusDataItem;
25  import io.github.tonywasher.joceanus.prometheus.validate.PrometheusValidateStatic;
26  
27  /**
28   * Validator for Currency.
29   */
30  public class MoneyWiseValidateCurrency
31          extends PrometheusValidateStatic {
32  
33      @Override
34      public void validate(final PrometheusDataItemCtl pCurrency) {
35          final MoneyWiseCurrency myCurrency = (MoneyWiseCurrency) pCurrency;
36          final MoneyWiseCurrencyList myList = myCurrency.getList();
37          final MoneyWiseCurrencyDataMap myMap = myList.getDataMap();
38  
39          /* Check that reporting is non-null */
40          if (myCurrency.isReporting() == null) {
41              myCurrency.addError(PrometheusDataItem.ERROR_MISSING, MoneyWiseStaticResource.CURRENCY_REPORTING);
42  
43              /* else check various things for a reporting currency */
44          } else if (Boolean.TRUE.equals(myCurrency.isReporting())) {
45              /* Check that default is enabled */
46              if (!myCurrency.getEnabled()) {
47                  myCurrency.addError(PrometheusDataItem.ERROR_DISABLED, MoneyWiseStaticResource.CURRENCY_REPORTING);
48              }
49  
50              /* Check for multiple reports */
51              if (!myMap.validReportCount()) {
52                  myCurrency.addError("Multiple reporting currencies", MoneyWiseStaticResource.CURRENCY_REPORTING);
53              }
54          }
55  
56          /* Validate it */
57          super.validate(pCurrency);
58      }
59  }