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