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.archive;
18  
19  import io.github.tonywasher.joceanus.oceanus.base.OceanusException;
20  import io.github.tonywasher.joceanus.oceanus.profile.OceanusProfile;
21  import io.github.tonywasher.joceanus.moneywise.data.basic.MoneyWiseDataSet;
22  import io.github.tonywasher.joceanus.moneywise.data.statics.MoneyWiseTaxBasis;
23  import io.github.tonywasher.joceanus.moneywise.data.statics.MoneyWiseTaxBasis.MoneyWiseTaxBasisList;
24  import io.github.tonywasher.joceanus.moneywise.exc.MoneyWiseIOException;
25  import io.github.tonywasher.joceanus.prometheus.service.sheet.PrometheusSheetCell;
26  import io.github.tonywasher.joceanus.prometheus.service.sheet.PrometheusSheetRow;
27  import io.github.tonywasher.joceanus.prometheus.service.sheet.PrometheusSheetView;
28  import io.github.tonywasher.joceanus.prometheus.service.sheet.PrometheusSheetWorkBook;
29  import io.github.tonywasher.joceanus.tethys.api.thread.TethysUIThreadCancelException;
30  import io.github.tonywasher.joceanus.tethys.api.thread.TethysUIThreadStatusReport;
31  
32  /**
33   * ArchiveLoader for TaxBasis.
34   *
35   * @author Tony Washer
36   */
37  public final class MoneyWiseArchiveTaxBasis {
38      /**
39       * NamedArea for Tax Bases.
40       */
41      private static final String AREA_TAXBASES = MoneyWiseTaxBasis.LIST_NAME;
42  
43      /**
44       * Report processor.
45       */
46      private final TethysUIThreadStatusReport theReport;
47  
48      /**
49       * Workbook.
50       */
51      private final PrometheusSheetWorkBook theWorkBook;
52  
53      /**
54       * DataSet.
55       */
56      private final MoneyWiseDataSet theData;
57  
58      /**
59       * Constructor.
60       *
61       * @param pReport   the report
62       * @param pWorkBook the workbook
63       * @param pData     the data set to load into
64       */
65      MoneyWiseArchiveTaxBasis(final TethysUIThreadStatusReport pReport,
66                               final PrometheusSheetWorkBook pWorkBook,
67                               final MoneyWiseDataSet pData) {
68          theReport = pReport;
69          theWorkBook = pWorkBook;
70          theData = pData;
71      }
72  
73      /**
74       * Load the TaxBases from an archive.
75       *
76       * @param pStage the stage
77       * @throws OceanusException on error
78       */
79      void loadArchive(final OceanusProfile pStage) throws OceanusException {
80          /* Access the list of tax bases */
81          pStage.startTask(AREA_TAXBASES);
82          final MoneyWiseTaxBasisList myList = theData.getTaxBases();
83  
84          /* Protect against exceptions */
85          try {
86              /* Find the range of cells */
87              final PrometheusSheetView myView = theWorkBook.getRangeView(AREA_TAXBASES);
88  
89              /* Declare the new stage */
90              theReport.setNewStage(AREA_TAXBASES);
91  
92              /* Count the number of TaxBases */
93              final int myTotal = myView.getRowCount();
94  
95              /* Declare the number of steps */
96              theReport.setNumSteps(myTotal);
97  
98              /* Loop through the rows of the single column range */
99              for (int i = 0; i < myTotal; i++) {
100                 /* Access the cell by reference */
101                 final PrometheusSheetRow myRow = myView.getRowByIndex(i);
102                 final PrometheusSheetCell myCell = myView.getRowCellByIndex(myRow, 0);
103 
104                 /* Add the value into the tables */
105                 myList.addBasicItem(myCell.getString());
106 
107                 /* Report the progress */
108                 theReport.setNextStep();
109             }
110 
111             /* PostProcess the list */
112             myList.postProcessOnLoad();
113 
114             /* Handle exceptions */
115         } catch (TethysUIThreadCancelException e) {
116             throw e;
117         } catch (OceanusException e) {
118             throw new MoneyWiseIOException("Failed to Load " + myList.getItemType().getListName(), e);
119         }
120     }
121 }