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