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