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.MoneyWisePortfolio;
23  import io.github.tonywasher.joceanus.moneywise.data.statics.MoneyWiseStaticDataType;
24  import io.github.tonywasher.joceanus.prometheus.data.PrometheusDataResource;
25  import io.github.tonywasher.joceanus.prometheus.data.PrometheusDataValues;
26  import io.github.tonywasher.joceanus.prometheus.sheets.PrometheusSheetEncrypted;
27  
28  /**
29   * SheetDataItem extension for Portfolio.
30   *
31   * @author Tony Washer
32   */
33  public final class MoneyWiseSheetPortfolio
34          extends PrometheusSheetEncrypted<MoneyWisePortfolio> {
35      /**
36       * NamedArea for Portfolios.
37       */
38      private static final String AREA_PORTFOLIOS = MoneyWisePortfolio.LIST_NAME;
39  
40      /**
41       * Name column.
42       */
43      private static final int COL_NAME = COL_KEYSETID + 1;
44  
45      /**
46       * Description column.
47       */
48      private static final int COL_DESC = COL_NAME + 1;
49  
50      /**
51       * Type column.
52       */
53      private static final int COL_TYPE = COL_DESC + 1;
54  
55      /**
56       * Parent column.
57       */
58      private static final int COL_PARENT = COL_TYPE + 1;
59  
60      /**
61       * Currency column.
62       */
63      private static final int COL_CURRENCY = COL_PARENT + 1;
64  
65      /**
66       * TaxFree column.
67       */
68      private static final int COL_TAXFREE = COL_CURRENCY + 1;
69  
70      /**
71       * Closed column.
72       */
73      private static final int COL_CLOSED = COL_TAXFREE + 1;
74  
75      /**
76       * Constructor for loading a spreadsheet.
77       *
78       * @param pReader the spreadsheet reader
79       */
80      MoneyWiseSheetPortfolio(final MoneyWiseReader pReader) {
81          /* Call super constructor */
82          super(pReader, AREA_PORTFOLIOS);
83  
84          /* Access the Portfolios list */
85          final MoneyWiseDataSet myData = (MoneyWiseDataSet) pReader.getData();
86          setDataList(myData.getPortfolios());
87      }
88  
89      /**
90       * Constructor for creating a spreadsheet.
91       *
92       * @param pWriter the spreadsheet writer
93       */
94      MoneyWiseSheetPortfolio(final MoneyWiseWriter pWriter) {
95          /* Call super constructor */
96          super(pWriter, AREA_PORTFOLIOS);
97  
98          /* Access the Portfolios list */
99          final MoneyWiseDataSet myData = (MoneyWiseDataSet) pWriter.getData();
100         setDataList(myData.getPortfolios());
101     }
102 
103     @Override
104     protected PrometheusDataValues loadSecureValues() throws OceanusException {
105         /* Build data values */
106         final PrometheusDataValues myValues = getRowValues(MoneyWisePortfolio.OBJECT_NAME);
107         myValues.addValue(MoneyWiseBasicResource.CATEGORY_NAME, loadInteger(COL_TYPE));
108         myValues.addValue(MoneyWiseBasicResource.ASSET_PARENT, loadInteger(COL_PARENT));
109         myValues.addValue(MoneyWiseStaticDataType.CURRENCY, loadInteger(COL_CURRENCY));
110         myValues.addValue(PrometheusDataResource.DATAITEM_FIELD_NAME, loadBytes(COL_NAME));
111         myValues.addValue(PrometheusDataResource.DATAITEM_FIELD_DESC, loadBytes(COL_DESC));
112         myValues.addValue(MoneyWiseBasicResource.ASSET_CLOSED, loadBoolean(COL_CLOSED));
113 
114         /* Return the values */
115         return myValues;
116     }
117 
118     @Override
119     protected void insertSecureItem(final MoneyWisePortfolio pItem) throws OceanusException {
120         /* Set the fields */
121         super.insertSecureItem(pItem);
122         writeInteger(COL_TYPE, pItem.getCategoryId());
123         writeInteger(COL_PARENT, pItem.getParentId());
124         writeInteger(COL_CURRENCY, pItem.getAssetCurrencyId());
125         writeBytes(COL_NAME, pItem.getNameBytes());
126         writeBytes(COL_DESC, pItem.getDescBytes());
127         writeBoolean(COL_TAXFREE, pItem.isTaxFree());
128         writeBoolean(COL_CLOSED, pItem.isClosed());
129     }
130 
131     @Override
132     protected int getLastColumn() {
133         /* Return the last column */
134         return COL_CLOSED;
135     }
136 }