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.sheets;
18  
19  import io.github.tonywasher.joceanus.moneywise.data.basic.MoneyWiseBasicResource;
20  import io.github.tonywasher.joceanus.moneywise.data.basic.MoneyWiseDataSet;
21  import io.github.tonywasher.joceanus.moneywise.data.basic.MoneyWisePayee;
22  import io.github.tonywasher.joceanus.oceanus.base.OceanusException;
23  import io.github.tonywasher.joceanus.prometheus.data.PrometheusDataResource;
24  import io.github.tonywasher.joceanus.prometheus.data.PrometheusDataValues;
25  import io.github.tonywasher.joceanus.prometheus.sheets.PrometheusSheetEncrypted;
26  import io.github.tonywasher.joceanus.prometheus.sheets.PrometheusSheetReader;
27  import io.github.tonywasher.joceanus.prometheus.sheets.PrometheusSheetWriter;
28  
29  /**
30   * SheetDataItem extension for Payee.
31   *
32   * @author Tony Washer
33   */
34  public final class MoneyWiseSheetPayee
35          extends PrometheusSheetEncrypted<MoneyWisePayee> {
36      /**
37       * NamedArea for Payees.
38       */
39      private static final String AREA_PAYEES = MoneyWisePayee.LIST_NAME;
40  
41      /**
42       * Name column.
43       */
44      private static final int COL_NAME = COL_KEYSETID + 1;
45  
46      /**
47       * Type column.
48       */
49      private static final int COL_TYPE = COL_NAME + 1;
50  
51      /**
52       * Description column.
53       */
54      private static final int COL_DESC = COL_TYPE + 1;
55  
56      /**
57       * Closed column.
58       */
59      private static final int COL_CLOSED = COL_DESC + 1;
60  
61      /**
62       * Constructor for loading a spreadsheet.
63       *
64       * @param pReader the spreadsheet reader
65       */
66      MoneyWiseSheetPayee(final PrometheusSheetReader pReader) {
67          /* Call super constructor */
68          super(pReader, AREA_PAYEES);
69  
70          /* Access the Payees list */
71          final MoneyWiseDataSet myData = (MoneyWiseDataSet) pReader.getData();
72          setDataList(myData.getPayees());
73      }
74  
75      /**
76       * Constructor for creating a spreadsheet.
77       *
78       * @param pWriter the spreadsheet writer
79       */
80      MoneyWiseSheetPayee(final PrometheusSheetWriter pWriter) {
81          /* Call super constructor */
82          super(pWriter, AREA_PAYEES);
83  
84          /* Access the Payees list */
85          final MoneyWiseDataSet myData = (MoneyWiseDataSet) pWriter.getData();
86          setDataList(myData.getPayees());
87      }
88  
89      @Override
90      protected PrometheusDataValues loadSecureValues() throws OceanusException {
91          /* Build data values */
92          final PrometheusDataValues myValues = getRowValues(MoneyWisePayee.OBJECT_NAME);
93          myValues.addValue(MoneyWiseBasicResource.CATEGORY_NAME, loadInteger(COL_TYPE));
94          myValues.addValue(PrometheusDataResource.DATAITEM_FIELD_NAME, loadBytes(COL_NAME));
95          myValues.addValue(PrometheusDataResource.DATAITEM_FIELD_DESC, loadBytes(COL_DESC));
96          myValues.addValue(MoneyWiseBasicResource.ASSET_CLOSED, loadBoolean(COL_CLOSED));
97  
98          /* Return the values */
99          return myValues;
100     }
101 
102     @Override
103     protected void insertSecureItem(final MoneyWisePayee pItem) throws OceanusException {
104         /* Set the fields */
105         super.insertSecureItem(pItem);
106         writeInteger(COL_TYPE, pItem.getCategoryId());
107         writeBytes(COL_NAME, pItem.getNameBytes());
108         writeBytes(COL_DESC, pItem.getDescBytes());
109         writeBoolean(COL_CLOSED, pItem.isClosed());
110     }
111 
112     @Override
113     protected int getLastColumn() {
114         /* Return the last column */
115         return COL_CLOSED;
116     }
117 }