View Javadoc
1   /*
2    * Prometheus: Application Framework
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.prometheus.sheets;
18  
19  import io.github.tonywasher.joceanus.oceanus.base.OceanusException;
20  import io.github.tonywasher.joceanus.prometheus.data.PrometheusControlKey;
21  import io.github.tonywasher.joceanus.prometheus.data.PrometheusDataResource;
22  import io.github.tonywasher.joceanus.prometheus.data.PrometheusDataSet;
23  import io.github.tonywasher.joceanus.prometheus.data.PrometheusDataValues;
24  
25  /**
26   * SheetDataItem extension for ControlKey.
27   *
28   * @author Tony Washer
29   */
30  public class PrometheusSheetControlKey
31          extends PrometheusSheetDataItem<PrometheusControlKey> {
32      /**
33       * SheetName for Keys.
34       */
35      private static final String SHEET_NAME = PrometheusControlKey.class.getSimpleName();
36  
37      /**
38       * KeyData column.
39       */
40      private static final int COL_CREATION = COL_ID + 1;
41  
42      /**
43       * KeyData column.
44       */
45      private static final int COL_KEYDATA = COL_CREATION + 1;
46  
47      /**
48       * Constructor for loading a spreadsheet.
49       *
50       * @param pReader the spreadsheet reader
51       */
52      protected PrometheusSheetControlKey(final PrometheusSheetReader pReader) {
53          /* Call super constructor */
54          super(pReader, SHEET_NAME);
55  
56          /* Access the Lists */
57          final PrometheusDataSet myData = pReader.getData();
58          setDataList(myData.getControlKeys());
59      }
60  
61      /**
62       * Constructor for creating a spreadsheet.
63       *
64       * @param pWriter the Spreadsheet writer
65       */
66      protected PrometheusSheetControlKey(final PrometheusSheetWriter pWriter) {
67          /* Call super constructor */
68          super(pWriter, SHEET_NAME);
69  
70          /* Access the Control list */
71          final PrometheusDataSet myData = pWriter.getData();
72          setDataList(myData.getControlKeys());
73      }
74  
75      @Override
76      protected PrometheusDataValues loadSecureValues() throws OceanusException {
77          /* Build data values */
78          final PrometheusDataValues myValues = getRowValues(PrometheusControlKey.OBJECT_NAME);
79          myValues.addValue(PrometheusDataResource.CONTROLKEY_CREATION, loadDate(COL_CREATION));
80          myValues.addValue(PrometheusDataResource.CONTROLKEY_LOCKBYTES, loadBytes(COL_KEYDATA));
81  
82          /* Return the values */
83          return myValues;
84      }
85  
86      @Override
87      protected void insertSecureItem(final PrometheusControlKey pItem) throws OceanusException {
88          /* Set the fields */
89          super.insertSecureItem(pItem);
90          writeDate(COL_CREATION, pItem.getCreationDate());
91          writeBytes(COL_KEYDATA, pItem.getLockBytes());
92      }
93  
94      @Override
95      protected int getLastColumn() {
96          /* Return the last column */
97          return COL_KEYDATA;
98      }
99  }