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