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.PrometheusControlKeySet;
21  import io.github.tonywasher.joceanus.prometheus.data.PrometheusDataKeySet;
22  import io.github.tonywasher.joceanus.prometheus.data.PrometheusDataResource;
23  import io.github.tonywasher.joceanus.prometheus.data.PrometheusDataSet;
24  import io.github.tonywasher.joceanus.prometheus.data.PrometheusDataSet.PrometheusCryptographyDataType;
25  import io.github.tonywasher.joceanus.prometheus.data.PrometheusDataValues;
26  
27  /**
28   * SheetDataItem extension for ControlKeySet.
29   *
30   * @author Tony Washer
31   */
32  public class PrometheusSheetControlKeySet
33          extends PrometheusSheetDataItem<PrometheusControlKeySet> {
34      /**
35       * SheetName for KeySets.
36       */
37      private static final String SHEET_NAME = PrometheusControlKeySet.class.getSimpleName();
38  
39      /**
40       * ControlId column.
41       */
42      private static final int COL_CONTROL = COL_ID + 1;
43  
44      /**
45       * KeySetDef column.
46       */
47      private static final int COL_KEYSETDEF = COL_CONTROL + 1;
48  
49      /**
50       * Constructor for loading a spreadsheet.
51       *
52       * @param pReader the spreadsheet reader
53       */
54      protected PrometheusSheetControlKeySet(final PrometheusSheetReader pReader) {
55          /* Call super constructor */
56          super(pReader, SHEET_NAME);
57  
58          /* Access the Lists */
59          final PrometheusDataSet myData = pReader.getData();
60          setDataList(myData.getControlKeySets());
61      }
62  
63      /**
64       * Constructor for creating a spreadsheet.
65       *
66       * @param pWriter the Spreadsheet writer
67       */
68      protected PrometheusSheetControlKeySet(final PrometheusSheetWriter pWriter) {
69          /* Call super constructor */
70          super(pWriter, SHEET_NAME);
71  
72          /* Access the Control list */
73          final PrometheusDataSet myData = pWriter.getData();
74          setDataList(myData.getControlKeySets());
75      }
76  
77      @Override
78      protected PrometheusDataValues loadSecureValues() throws OceanusException {
79          /* Build data values */
80          final PrometheusDataValues myValues = getRowValues(PrometheusDataKeySet.OBJECT_NAME);
81          myValues.addValue(PrometheusCryptographyDataType.CONTROLKEY, loadInteger(COL_CONTROL));
82          myValues.addValue(PrometheusDataResource.KEYSET_KEYSETDEF, loadBytes(COL_KEYSETDEF));
83  
84          /* Return the values */
85          return myValues;
86      }
87  
88      @Override
89      protected void insertSecureItem(final PrometheusControlKeySet pItem) throws OceanusException {
90          /* Set the fields */
91          super.insertSecureItem(pItem);
92          writeInteger(COL_CONTROL, pItem.getControlKeyId());
93          writeBytes(COL_KEYSETDEF, pItem.getSecuredKeySetDef());
94      }
95  
96      @Override
97      protected int getLastColumn() {
98          /* Return the last column */
99          return COL_KEYSETDEF;
100     }
101 }