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