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.MoneyWiseDataSet;
20  import io.github.tonywasher.joceanus.moneywise.data.basic.MoneyWiseTransCategory;
21  import io.github.tonywasher.joceanus.moneywise.data.statics.MoneyWiseStaticDataType;
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 TransactionCategory.
31   *
32   * @author Tony Washer
33   */
34  public final class MoneyWiseSheetTransCategory
35          extends PrometheusSheetEncrypted<MoneyWiseTransCategory> {
36      /**
37       * NamedArea for TransactionCategories.
38       */
39      private static final String AREA_TRANSCATEGORIES = "TransCategoryInfo";
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       * Parent column.
53       */
54      private static final int COL_PARENT = COL_TYPE + 1;
55  
56      /**
57       * Description column.
58       */
59      private static final int COL_DESC = COL_PARENT + 1;
60  
61      /**
62       * Constructor for loading a spreadsheet.
63       *
64       * @param pReader the spreadsheet reader
65       */
66      MoneyWiseSheetTransCategory(final PrometheusSheetReader pReader) {
67          /* Call super constructor */
68          super(pReader, AREA_TRANSCATEGORIES);
69  
70          /* Access the Categories list */
71          final MoneyWiseDataSet myData = (MoneyWiseDataSet) pReader.getData();
72          setDataList(myData.getTransCategories());
73      }
74  
75      /**
76       * Constructor for creating a spreadsheet.
77       *
78       * @param pWriter the spreadsheet writer
79       */
80      MoneyWiseSheetTransCategory(final PrometheusSheetWriter pWriter) {
81          /* Call super constructor */
82          super(pWriter, AREA_TRANSCATEGORIES);
83  
84          /* Access the Categories list */
85          final MoneyWiseDataSet myData = (MoneyWiseDataSet) pWriter.getData();
86          setDataList(myData.getTransCategories());
87      }
88  
89      @Override
90      protected PrometheusDataValues loadSecureValues() throws OceanusException {
91          /* Build data values */
92          final PrometheusDataValues myValues = getRowValues(MoneyWiseTransCategory.OBJECT_NAME);
93          myValues.addValue(MoneyWiseStaticDataType.TRANSTYPE, loadInteger(COL_TYPE));
94          myValues.addValue(PrometheusDataResource.DATAGROUP_PARENT, loadInteger(COL_PARENT));
95          myValues.addValue(PrometheusDataResource.DATAITEM_FIELD_NAME, loadBytes(COL_NAME));
96          myValues.addValue(PrometheusDataResource.DATAITEM_FIELD_DESC, loadBytes(COL_DESC));
97  
98          /* Return the values */
99          return myValues;
100     }
101 
102     @Override
103     protected void insertSecureItem(final MoneyWiseTransCategory pItem) throws OceanusException {
104         /* Set the fields */
105         super.insertSecureItem(pItem);
106         writeInteger(COL_TYPE, pItem.getCategoryTypeId());
107         writeInteger(COL_PARENT, pItem.getParentCategoryId());
108         writeBytes(COL_NAME, pItem.getNameBytes());
109         writeBytes(COL_DESC, pItem.getDescBytes());
110     }
111 
112     @Override
113     protected int getLastColumn() {
114         /* Return the last column */
115         return COL_DESC;
116     }
117 }