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