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.archive;
18  
19  import io.github.tonywasher.joceanus.oceanus.base.OceanusException;
20  import io.github.tonywasher.joceanus.oceanus.date.OceanusDate;
21  import io.github.tonywasher.joceanus.oceanus.profile.OceanusProfile;
22  import io.github.tonywasher.joceanus.moneywise.data.basic.MoneyWiseBasicDataType;
23  import io.github.tonywasher.joceanus.moneywise.data.basic.MoneyWiseBasicResource;
24  import io.github.tonywasher.joceanus.moneywise.data.basic.MoneyWiseCash;
25  import io.github.tonywasher.joceanus.moneywise.data.basic.MoneyWiseCash.MoneyWiseCashList;
26  import io.github.tonywasher.joceanus.moneywise.data.basic.MoneyWiseCashInfo.MoneyWiseCashInfoList;
27  import io.github.tonywasher.joceanus.moneywise.data.basic.MoneyWiseCategoryBase;
28  import io.github.tonywasher.joceanus.moneywise.data.basic.MoneyWiseDataSet;
29  import io.github.tonywasher.joceanus.moneywise.data.basic.MoneyWiseDeposit;
30  import io.github.tonywasher.joceanus.moneywise.data.basic.MoneyWiseDeposit.MoneyWiseDepositList;
31  import io.github.tonywasher.joceanus.moneywise.data.basic.MoneyWiseDepositInfo.MoneyWiseDepositInfoList;
32  import io.github.tonywasher.joceanus.moneywise.data.basic.MoneyWiseLoan;
33  import io.github.tonywasher.joceanus.moneywise.data.basic.MoneyWiseLoan.MoneyWiseLoanList;
34  import io.github.tonywasher.joceanus.moneywise.data.basic.MoneyWiseLoanInfo.MoneyWiseLoanInfoList;
35  import io.github.tonywasher.joceanus.moneywise.data.basic.MoneyWisePayee;
36  import io.github.tonywasher.joceanus.moneywise.data.basic.MoneyWisePayee.MoneyWisePayeeList;
37  import io.github.tonywasher.joceanus.moneywise.data.basic.MoneyWisePayeeInfo.MoneyWisePayeeInfoList;
38  import io.github.tonywasher.joceanus.moneywise.data.basic.MoneyWisePortfolio;
39  import io.github.tonywasher.joceanus.moneywise.data.basic.MoneyWisePortfolio.MoneyWisePortfolioList;
40  import io.github.tonywasher.joceanus.moneywise.data.basic.MoneyWisePortfolioInfo.MoneyWisePortfolioInfoList;
41  import io.github.tonywasher.joceanus.moneywise.data.basic.MoneyWiseSecurity;
42  import io.github.tonywasher.joceanus.moneywise.data.basic.MoneyWiseSecurity.MoneyWiseSecurityList;
43  import io.github.tonywasher.joceanus.moneywise.data.basic.MoneyWiseSecurityInfo.MoneyWiseSecurityInfoList;
44  import io.github.tonywasher.joceanus.moneywise.data.statics.MoneyWiseAccountInfoClass;
45  import io.github.tonywasher.joceanus.moneywise.data.statics.MoneyWiseCurrency;
46  import io.github.tonywasher.joceanus.moneywise.data.statics.MoneyWisePayeeClass;
47  import io.github.tonywasher.joceanus.moneywise.data.statics.MoneyWiseStaticDataType;
48  import io.github.tonywasher.joceanus.moneywise.exc.MoneyWiseIOException;
49  import io.github.tonywasher.joceanus.moneywise.exc.MoneyWiseLogicException;
50  import io.github.tonywasher.joceanus.prometheus.data.PrometheusDataResource;
51  import io.github.tonywasher.joceanus.prometheus.data.PrometheusDataValues;
52  import io.github.tonywasher.joceanus.prometheus.service.sheet.PrometheusSheetCell;
53  import io.github.tonywasher.joceanus.prometheus.service.sheet.PrometheusSheetRow;
54  import io.github.tonywasher.joceanus.prometheus.service.sheet.PrometheusSheetView;
55  import io.github.tonywasher.joceanus.prometheus.service.sheet.PrometheusSheetWorkBook;
56  import io.github.tonywasher.joceanus.tethys.api.thread.TethysUIThreadCancelException;
57  import io.github.tonywasher.joceanus.tethys.api.thread.TethysUIThreadStatusReport;
58  
59  /**
60   * ArchiveLoader extension for Accounts.
61   *
62   * @author Tony Washer
63   */
64  public final class MoneyWiseArchiveAccount {
65      /**
66       * Sheet Area name.
67       */
68      private static final String SHEET_AREA = "AccountInfo";
69  
70      /**
71       * Report processor.
72       */
73      private final TethysUIThreadStatusReport theReport;
74  
75      /**
76       * Workbook.
77       */
78      private final PrometheusSheetWorkBook theWorkBook;
79  
80      /**
81       * DataSet.
82       */
83      private final MoneyWiseDataSet theData;
84  
85      /**
86       * Cache.
87       */
88      private final MoneyWiseArchiveCache theCache;
89  
90      /**
91       * Constructor.
92       *
93       * @param pReport   the report
94       * @param pWorkBook the workbook
95       * @param pData     the data set to load into
96       * @param pCache    the cache
97       */
98      MoneyWiseArchiveAccount(final TethysUIThreadStatusReport pReport,
99                              final PrometheusSheetWorkBook pWorkBook,
100                             final MoneyWiseDataSet pData,
101                             final MoneyWiseArchiveCache pCache) {
102         theReport = pReport;
103         theWorkBook = pWorkBook;
104         theData = pData;
105         theCache = pCache;
106     }
107 
108     /**
109      * Load the AccountCategories from an archive.
110      *
111      * @param pStage the stage
112      * @throws OceanusException on error
113      */
114     void loadArchive(final OceanusProfile pStage) throws OceanusException {
115         /* Protect against exceptions */
116         try {
117             /* Find the range of cells */
118             pStage.startTask("Accounts");
119             final PrometheusSheetView myView = theWorkBook.getRangeView(SHEET_AREA);
120 
121             /* Declare the new stage */
122             theReport.setNewStage(SHEET_AREA);
123 
124             /* Count the number of accounts */
125             final int myTotal = myView.getRowCount();
126 
127             /* Declare the number of steps (*2) */
128             theReport.setNumSteps(myTotal << 1);
129 
130             /* Loop through the rows of the table */
131             for (int i = 0; i < myTotal; i++) {
132                 /* Access the row by reference */
133                 final PrometheusSheetRow myRow = myView.getRowByIndex(i);
134 
135                 /* Process payee account */
136                 processPayee(myView, myRow);
137 
138                 /* Report the progress */
139                 theReport.setNextStep();
140             }
141 
142             /* Resolve Payee lists */
143             resolvePayeeLists();
144 
145             /* Loop through the rows of the table */
146             for (int i = 0; i < myTotal; i++) {
147                 /* Access the row by reference */
148                 final PrometheusSheetRow myRow = myView.getRowByIndex(i);
149 
150                 /* Process account */
151                 processAccount(myView, myRow);
152 
153                 /* Report the progress */
154                 theReport.setNextStep();
155             }
156 
157             /* Resolve Account lists */
158             resolveAccountLists();
159 
160             /* Handle exceptions */
161         } catch (TethysUIThreadCancelException e) {
162             throw e;
163         } catch (OceanusException e) {
164             throw new MoneyWiseIOException("Failed to Load " + SHEET_AREA, e);
165         }
166     }
167 
168     /**
169      * Process account row.
170      *
171      * @param pView the spreadsheet view
172      * @param pRow  the spreadsheet row
173      * @throws OceanusException on error
174      */
175     private void processPayee(final PrometheusSheetView pView,
176                               final PrometheusSheetRow pRow) throws OceanusException {
177         /* Skip name and type column */
178         int iAdjust = -1;
179         ++iAdjust;
180         ++iAdjust;
181 
182         /* Access account class */
183         final String myClass = pView.getRowCellByIndex(pRow, ++iAdjust).getString();
184 
185         /* If this is a Payee */
186         if (myClass.equals(MoneyWiseBasicDataType.PAYEE.toString())) {
187             /* Process as a payee */
188             processStdPayee(pView, pRow);
189 
190             /* If this is a cash */
191         } else if (myClass.equals(MoneyWiseBasicDataType.CASH.toString())) {
192             /* Process as a cash payee */
193             processCashPayee(pView, pRow);
194         }
195     }
196 
197     /**
198      * Process account row.
199      *
200      * @param pView the spreadsheet view
201      * @param pRow  the spreadsheet row
202      * @throws OceanusException on error
203      */
204     private void processAccount(final PrometheusSheetView pView,
205                                 final PrometheusSheetRow pRow) throws OceanusException {
206         /* Skip name and type column */
207         int iAdjust = -1;
208         ++iAdjust;
209         ++iAdjust;
210 
211         /* Access account class */
212         final String myClass = pView.getRowCellByIndex(pRow, ++iAdjust).getString();
213 
214         /* If this is a deposit */
215         if (myClass.equals(MoneyWiseBasicDataType.DEPOSIT.toString())) {
216             /* Process as a deposit */
217             processDeposit(pView, pRow);
218 
219             /* If this is a cash */
220         } else if (myClass.equals(MoneyWiseBasicDataType.CASH.toString())) {
221             /* Process as a cash */
222             processCash(pView, pRow);
223 
224             /* If this is a loan */
225         } else if (myClass.equals(MoneyWiseBasicDataType.LOAN.toString())) {
226             /* Process as a loan */
227             processLoan(pView, pRow);
228 
229             /* If this is a security */
230         } else if (myClass.equals(MoneyWiseBasicDataType.SECURITY.toString())) {
231             /* Process as a security */
232             processSecurity(pView, pRow);
233 
234             /* If this is a portfolio */
235         } else if (myClass.equals(MoneyWiseBasicDataType.PORTFOLIO.toString())) {
236             /* Process as a portfolio */
237             processPortfolio(pView, pRow);
238 
239             /* else reject if not payee */
240         } else if (!myClass.equals(MoneyWiseBasicDataType.PAYEE.toString())) {
241             throw new MoneyWiseLogicException("Unexpected Account Class " + myClass);
242         }
243     }
244 
245     /**
246      * Resolve payee account lists.
247      *
248      * @throws OceanusException on error
249      */
250     private void resolvePayeeLists() throws OceanusException {
251         /* PostProcess the Payees */
252         final MoneyWisePayeeList myPayeeList = theData.getPayees();
253         final MoneyWisePayeeInfoList myPayeeInfoList = theData.getPayeeInfo();
254         myPayeeList.postProcessOnLoad();
255         myPayeeInfoList.postProcessOnLoad();
256     }
257 
258     /**
259      * Resolve non-payee account lists.
260      *
261      * @throws OceanusException on error
262      */
263     private void resolveAccountLists() throws OceanusException {
264         /* PostProcess the securities */
265         final MoneyWiseSecurityList mySecurityList = theData.getSecurities();
266         final MoneyWiseSecurityInfoList mySecInfoList = theData.getSecurityInfo();
267         mySecurityList.postProcessOnLoad();
268         mySecInfoList.postProcessOnLoad();
269 
270         /* PostProcess the deposits */
271         final MoneyWiseDepositList myDepositList = theData.getDeposits();
272         final MoneyWiseDepositInfoList myDepInfoList = theData.getDepositInfo();
273         myDepositList.postProcessOnLoad();
274         myDepInfoList.postProcessOnLoad();
275 
276         /* PostProcess the cash */
277         final MoneyWiseCashList myCashList = theData.getCash();
278         final MoneyWiseCashInfoList myCashInfoList = theData.getCashInfo();
279         myCashList.postProcessOnLoad();
280         myCashInfoList.postProcessOnLoad();
281 
282         /* PostProcess the loans */
283         final MoneyWiseLoanList myLoanList = theData.getLoans();
284         final MoneyWiseLoanInfoList myLoanInfoList = theData.getLoanInfo();
285         myLoanList.postProcessOnLoad();
286         myLoanInfoList.postProcessOnLoad();
287 
288         /* PostProcess the portfolios */
289         final MoneyWisePortfolioList myPortfolioList = theData.getPortfolios();
290         final MoneyWisePortfolioInfoList myPortInfoList = theData.getPortfolioInfo();
291         myPortfolioList.postProcessOnLoad();
292         myPortInfoList.postProcessOnLoad();
293 
294         /* Resolve Security Holdings */
295         theCache.resolveSecurityHoldings(theData);
296     }
297 
298     /**
299      * Process payee row from archive.
300      *
301      * @param pView the spreadsheet view
302      * @param pRow  the spreadsheet row
303      * @throws OceanusException on error
304      */
305     private void processStdPayee(final PrometheusSheetView pView,
306                                  final PrometheusSheetRow pRow) throws OceanusException {
307         /* Access name and type */
308         int iAdjust = -1;
309         final String myName = pView.getRowCellByIndex(pRow, ++iAdjust).getString();
310         final String myType = pView.getRowCellByIndex(pRow, ++iAdjust).getString();
311 
312         /* Skip class */
313         ++iAdjust;
314 
315         /* Handle closed which may be missing */
316         final PrometheusSheetCell myCell = pView.getRowCellByIndex(pRow, ++iAdjust);
317         Boolean isClosed = Boolean.FALSE;
318         if (myCell != null) {
319             isClosed = myCell.getBoolean();
320         }
321 
322         /* Build data values */
323         final PrometheusDataValues myValues = new PrometheusDataValues(MoneyWisePayee.OBJECT_NAME);
324         myValues.addValue(PrometheusDataResource.DATAITEM_FIELD_NAME, myName);
325         myValues.addValue(MoneyWiseBasicResource.CATEGORY_NAME, myType);
326         myValues.addValue(MoneyWiseBasicResource.ASSET_CLOSED, isClosed);
327 
328         /* Add the value into the list */
329         final MoneyWisePayeeList myList = theData.getPayees();
330         final MoneyWisePayee myPayee = myList.addValuesItem(myValues);
331 
332         /* Declare the payee */
333         theCache.declareAsset(myPayee);
334     }
335 
336     /**
337      * Process cashPayee row from archive.
338      *
339      * @param pView the spreadsheet view
340      * @param pRow  the spreadsheet row
341      * @throws OceanusException on error
342      */
343     private void processCashPayee(final PrometheusSheetView pView,
344                                   final PrometheusSheetRow pRow) throws OceanusException {
345         /* Access name */
346         int iAdjust = -1;
347         final String myName = pView.getRowCellByIndex(pRow, ++iAdjust).getString();
348 
349         /* Skip type, class */
350         ++iAdjust;
351         ++iAdjust;
352 
353         /* Handle closed which may be missing */
354         PrometheusSheetCell myCell = pView.getRowCellByIndex(pRow, ++iAdjust);
355         Boolean isClosed = Boolean.FALSE;
356         if (myCell != null) {
357             isClosed = myCell.getBoolean();
358         }
359 
360         /*
361          * Skip parent, alias, portfolio, maturity, openingBalance, symbol, region and currency
362          * columns
363          */
364         ++iAdjust;
365         ++iAdjust;
366         ++iAdjust;
367         ++iAdjust;
368         ++iAdjust;
369         ++iAdjust;
370         ++iAdjust;
371         ++iAdjust;
372 
373         /* Handle autoExpense which may be missing */
374         myCell = pView.getRowCellByIndex(pRow, ++iAdjust);
375         if (myCell != null) {
376             final String myAutoPayee = myName + "Expense";
377 
378             /* Build values */
379             final PrometheusDataValues myValues = new PrometheusDataValues(MoneyWisePayee.OBJECT_NAME);
380             myValues.addValue(PrometheusDataResource.DATAITEM_FIELD_NAME, myAutoPayee);
381             myValues.addValue(MoneyWiseBasicResource.CATEGORY_NAME, MoneyWisePayeeClass.PAYEE.toString());
382             myValues.addValue(MoneyWiseBasicResource.ASSET_CLOSED, isClosed);
383 
384             /* Add the value into the list */
385             final MoneyWisePayeeList myPayeeList = theData.getPayees();
386             myPayeeList.addValuesItem(myValues);
387         }
388     }
389 
390     /**
391      * Process cash row from archive.
392      *
393      * @param pView the spreadsheet view
394      * @param pRow  the spreadsheet row
395      * @throws OceanusException on error
396      */
397     private void processCash(final PrometheusSheetView pView,
398                              final PrometheusSheetRow pRow) throws OceanusException {
399         /* Access name and type */
400         int iAdjust = -1;
401         final String myName = pView.getRowCellByIndex(pRow, ++iAdjust).getString();
402         final String myType = pView.getRowCellByIndex(pRow, ++iAdjust).getString();
403 
404         /* Skip class */
405         ++iAdjust;
406 
407         /* Handle closed which may be missing */
408         PrometheusSheetCell myCell = pView.getRowCellByIndex(pRow, ++iAdjust);
409         Boolean isClosed = Boolean.FALSE;
410         if (myCell != null) {
411             isClosed = myCell.getBoolean();
412         }
413 
414         /* Skip parent, alias, portfolio, and maturity columns */
415         ++iAdjust;
416         ++iAdjust;
417         ++iAdjust;
418         ++iAdjust;
419 
420         /* Handle opening balance which may be missing */
421         myCell = pView.getRowCellByIndex(pRow, ++iAdjust);
422         String myBalance = null;
423         if (myCell != null) {
424             myBalance = myCell.getString();
425         }
426 
427         /* Skip symbol and region columns */
428         ++iAdjust;
429         ++iAdjust;
430 
431         /* Handle currency which may be missing */
432         myCell = pView.getRowCellByIndex(pRow, ++iAdjust);
433         MoneyWiseCurrency myCurrency = theData.getReportingCurrency();
434         if (myCell != null) {
435             final String myCurrName = myCell.getString();
436             myCurrency = theData.getAccountCurrencies().findItemByName(myCurrName);
437         }
438 
439         /* Handle autoExpense which may be missing */
440         myCell = pView.getRowCellByIndex(pRow, ++iAdjust);
441         String myAutoExpense = null;
442         String myAutoPayee = null;
443         if (myCell != null) {
444             myAutoExpense = myCell.getString();
445             myAutoPayee = myName + "Expense";
446         }
447 
448         /* Build data values */
449         final PrometheusDataValues myValues = new PrometheusDataValues(MoneyWiseCash.OBJECT_NAME);
450         myValues.addValue(PrometheusDataResource.DATAITEM_FIELD_NAME, myName);
451         myValues.addValue(MoneyWiseBasicResource.CATEGORY_NAME, myType);
452         myValues.addValue(MoneyWiseStaticDataType.CURRENCY, myCurrency);
453         myValues.addValue(MoneyWiseBasicResource.ASSET_CLOSED, isClosed);
454 
455         /* Add the value into the list */
456         final MoneyWiseCashList myList = theData.getCash();
457         final MoneyWiseCash myCash = myList.addValuesItem(myValues);
458 
459         /* Add information relating to the cash */
460         final MoneyWiseCashInfoList myInfoList = theData.getCashInfo();
461         myInfoList.addInfoItem(null, myCash, MoneyWiseAccountInfoClass.AUTOEXPENSE, myAutoExpense);
462         myInfoList.addInfoItem(null, myCash, MoneyWiseAccountInfoClass.AUTOPAYEE, myAutoPayee);
463         myInfoList.addInfoItem(null, myCash, MoneyWiseAccountInfoClass.OPENINGBALANCE, myBalance);
464 
465         /* Declare the cash */
466         theCache.declareAsset(myCash);
467     }
468 
469     /**
470      * Process deposit row from archive.
471      *
472      * @param pView the spreadsheet view
473      * @param pRow  the spreadsheet row
474      * @throws OceanusException on error
475      */
476     private void processDeposit(final PrometheusSheetView pView,
477                                 final PrometheusSheetRow pRow) throws OceanusException {
478         /* Access name and type */
479         int iAdjust = -1;
480         final String myName = pView.getRowCellByIndex(pRow, ++iAdjust).getString();
481         final String myType = pView.getRowCellByIndex(pRow, ++iAdjust).getString();
482 
483         /* Skip class */
484         ++iAdjust;
485 
486         /* Handle closed which may be missing */
487         PrometheusSheetCell myCell = pView.getRowCellByIndex(pRow, ++iAdjust);
488         Boolean isClosed = Boolean.FALSE;
489         if (myCell != null) {
490             isClosed = myCell.getBoolean();
491         }
492 
493         /* Access Parent account */
494         final String myParent = pView.getRowCellByIndex(pRow, ++iAdjust).getString();
495 
496         /* Skip alias and portfolio columns */
497         ++iAdjust;
498         ++iAdjust;
499 
500         /* Handle maturity which may be missing */
501         myCell = pView.getRowCellByIndex(pRow, ++iAdjust);
502         OceanusDate myMaturity = null;
503         if (myCell != null) {
504             myMaturity = myCell.getDate();
505         }
506 
507         /* Handle opening balance which may be missing */
508         myCell = pView.getRowCellByIndex(pRow, ++iAdjust);
509         String myBalance = null;
510         if (myCell != null) {
511             myBalance = myCell.getString();
512         }
513 
514         /* Skip symbol and region columns */
515         ++iAdjust;
516         ++iAdjust;
517 
518         /* Handle currency which may be missing */
519         myCell = pView.getRowCellByIndex(pRow, ++iAdjust);
520         MoneyWiseCurrency myCurrency = theData.getReportingCurrency();
521         if (myCell != null) {
522             final String myCurrName = myCell.getString();
523             myCurrency = theData.getAccountCurrencies().findItemByName(myCurrName);
524         }
525 
526         /* Build data values */
527         final PrometheusDataValues myValues = new PrometheusDataValues(MoneyWiseDeposit.OBJECT_NAME);
528         myValues.addValue(PrometheusDataResource.DATAITEM_FIELD_NAME, myName);
529         myValues.addValue(MoneyWiseBasicResource.CATEGORY_NAME, myType);
530         myValues.addValue(MoneyWiseStaticDataType.CURRENCY, myCurrency);
531         myValues.addValue(MoneyWiseBasicResource.ASSET_PARENT, myParent);
532         myValues.addValue(MoneyWiseBasicResource.ASSET_CLOSED, isClosed);
533 
534         /* Add the value into the list */
535         final MoneyWiseDepositList myList = theData.getDeposits();
536         final MoneyWiseDeposit myDeposit = myList.addValuesItem(myValues);
537 
538         /* Add information relating to the deposit */
539         final MoneyWiseDepositInfoList myInfoList = theData.getDepositInfo();
540         myInfoList.addInfoItem(null, myDeposit, MoneyWiseAccountInfoClass.MATURITY, myMaturity);
541         myInfoList.addInfoItem(null, myDeposit, MoneyWiseAccountInfoClass.OPENINGBALANCE, myBalance);
542 
543         /* Declare the deposit */
544         theCache.declareAsset(myDeposit);
545     }
546 
547     /**
548      * Process loan row from archive.
549      *
550      * @param pView the spreadsheet view
551      * @param pRow  the spreadsheet row
552      * @throws OceanusException on error
553      */
554     private void processLoan(final PrometheusSheetView pView,
555                              final PrometheusSheetRow pRow) throws OceanusException {
556         /* Access name and type */
557         int iAdjust = -1;
558         final String myName = pView.getRowCellByIndex(pRow, ++iAdjust).getString();
559         final String myType = pView.getRowCellByIndex(pRow, ++iAdjust).getString();
560 
561         /* Skip class */
562         ++iAdjust;
563 
564         /* Handle closed which may be missing */
565         PrometheusSheetCell myCell = pView.getRowCellByIndex(pRow, ++iAdjust);
566         Boolean isClosed = Boolean.FALSE;
567         if (myCell != null) {
568             isClosed = myCell.getBoolean();
569         }
570 
571         /* Access Parent account */
572         final String myParent = pView.getRowCellByIndex(pRow, ++iAdjust).getString();
573 
574         /* Skip alias, portfolio, maturity, openingBalance, symbol and region columns */
575         ++iAdjust;
576         ++iAdjust;
577         ++iAdjust;
578         ++iAdjust;
579         ++iAdjust;
580         ++iAdjust;
581 
582         /* Handle currency which may be missing */
583         myCell = pView.getRowCellByIndex(pRow, ++iAdjust);
584         MoneyWiseCurrency myCurrency = theData.getReportingCurrency();
585         if (myCell != null) {
586             final String myCurrName = myCell.getString();
587             myCurrency = theData.getAccountCurrencies().findItemByName(myCurrName);
588         }
589 
590         /* Build data values */
591         final PrometheusDataValues myValues = new PrometheusDataValues(MoneyWiseLoan.OBJECT_NAME);
592         myValues.addValue(PrometheusDataResource.DATAITEM_FIELD_NAME, myName);
593         myValues.addValue(MoneyWiseBasicResource.CATEGORY_NAME, myType);
594         myValues.addValue(MoneyWiseStaticDataType.CURRENCY, myCurrency);
595         myValues.addValue(MoneyWiseBasicResource.ASSET_PARENT, myParent);
596         myValues.addValue(MoneyWiseBasicResource.ASSET_CLOSED, isClosed);
597 
598         /* Add the value into the list */
599         final MoneyWiseLoanList myList = theData.getLoans();
600         final MoneyWiseLoan myLoan = myList.addValuesItem(myValues);
601 
602         /* Declare the loan */
603         theCache.declareAsset(myLoan);
604     }
605 
606     /**
607      * Process portfolio row from archive.
608      *
609      * @param pView the spreadsheet view
610      * @param pRow  the spreadsheet row
611      * @throws OceanusException on error
612      */
613     private void processPortfolio(final PrometheusSheetView pView,
614                                   final PrometheusSheetRow pRow) throws OceanusException {
615         /* Access name */
616         int iAdjust = -1;
617         final String myName = pView.getRowCellByIndex(pRow, ++iAdjust).getString();
618 
619         /* Access portfolio type */
620         final String myType = pView.getRowCellByIndex(pRow, ++iAdjust).getString();
621 
622         /* Look for separator in category */
623         final int iIndex = myType.indexOf(MoneyWiseCategoryBase.STR_SEP);
624         if (iIndex == -1) {
625             throw new MoneyWiseLogicException("Unexpected Portfolio Class " + myType);
626         }
627 
628         /* Access subCategory as portfolio type */
629         final String myPortType = myType.substring(iIndex + 1);
630 
631         /* Skip class */
632         ++iAdjust;
633 
634         /* Handle closed which may be missing */
635         PrometheusSheetCell myCell = pView.getRowCellByIndex(pRow, ++iAdjust);
636         Boolean isClosed = Boolean.FALSE;
637         if (myCell != null) {
638             isClosed = myCell.getBoolean();
639         }
640 
641         /* Access Parent account */
642         final String myParent = pView.getRowCellByIndex(pRow, ++iAdjust).getString();
643 
644         /* Skip alias, portfolio, maturity, openingBalance, symbol and region columns */
645         ++iAdjust;
646         ++iAdjust;
647         ++iAdjust;
648         ++iAdjust;
649         ++iAdjust;
650         ++iAdjust;
651 
652         /* Handle currency which may be missing */
653         myCell = pView.getRowCellByIndex(pRow, ++iAdjust);
654         MoneyWiseCurrency myCurrency = theData.getReportingCurrency();
655         if (myCell != null) {
656             final String myCurrName = myCell.getString();
657             myCurrency = theData.getAccountCurrencies().findItemByName(myCurrName);
658         }
659 
660         /* Build data values */
661         final PrometheusDataValues myValues = new PrometheusDataValues(MoneyWisePortfolio.OBJECT_NAME);
662         myValues.addValue(PrometheusDataResource.DATAITEM_FIELD_NAME, myName);
663         myValues.addValue(MoneyWiseBasicResource.CATEGORY_NAME, myPortType);
664         myValues.addValue(MoneyWiseBasicResource.ASSET_PARENT, myParent);
665         myValues.addValue(MoneyWiseStaticDataType.CURRENCY, myCurrency);
666         myValues.addValue(MoneyWiseBasicResource.ASSET_CLOSED, isClosed);
667 
668         /* Add the value into the list */
669         final MoneyWisePortfolioList myList = theData.getPortfolios();
670         final MoneyWisePortfolio myPortfolio = myList.addValuesItem(myValues);
671 
672         /* Declare the portfolio */
673         theCache.declareAsset(myPortfolio);
674     }
675 
676     /**
677      * Process security row from archive.
678      *
679      * @param pView the spreadsheet view
680      * @param pRow  the spreadsheet row
681      * @throws OceanusException on error
682      */
683     private void processSecurity(final PrometheusSheetView pView,
684                                  final PrometheusSheetRow pRow) throws OceanusException {
685         /* Access name and type */
686         int iAdjust = -1;
687         final String myName = pView.getRowCellByIndex(pRow, ++iAdjust).getString();
688         final String myType = pView.getRowCellByIndex(pRow, ++iAdjust).getString();
689 
690         /* Look for separator in category */
691         final int iIndex = myType.indexOf(MoneyWiseCategoryBase.STR_SEP);
692         if (iIndex == -1) {
693             throw new MoneyWiseLogicException("Unexpected Security Class " + myType);
694         }
695 
696         /* Access subCategory as security type */
697         final String mySecType = myType.substring(iIndex + 1);
698 
699         /* Skip class */
700         ++iAdjust;
701 
702         /* Handle closed which may be missing */
703         PrometheusSheetCell myCell = pView.getRowCellByIndex(pRow, ++iAdjust);
704         Boolean isClosed = Boolean.FALSE;
705         if (myCell != null) {
706             isClosed = myCell.getBoolean();
707         }
708 
709         /* Access the list */
710         final MoneyWiseSecurityList myList = theData.getSecurities();
711 
712         /* Access Parent account */
713         final String myParent = pView.getRowCellByIndex(pRow, ++iAdjust).getString();
714 
715         /* Access the alias account */
716         myCell = pView.getRowCellByIndex(pRow, ++iAdjust);
717         String myAlias = null;
718         if (myCell != null) {
719             myAlias = myCell.getString();
720         }
721 
722         /* Access Portfolio */
723         final String myPortfolio = pView.getRowCellByIndex(pRow, ++iAdjust).getString();
724 
725         /* If we have an alias */
726         if (myAlias != null) {
727             /* Declare the security alias */
728             theCache.declareAliasHolding(myName, myAlias, myPortfolio);
729 
730             /* return */
731             return;
732         }
733 
734         /* Skip maturity and opening columns */
735         ++iAdjust;
736         ++iAdjust;
737 
738         /* Access Symbol which may be missing */
739         myCell = pView.getRowCellByIndex(pRow, ++iAdjust);
740         String mySymbol = null;
741         if (myCell != null) {
742             mySymbol = myCell.getString();
743         }
744 
745         /* Handle region which may be missing */
746         myCell = pView.getRowCellByIndex(pRow, ++iAdjust);
747         String myRegion = null;
748         if (myCell != null) {
749             myRegion = myCell.getString();
750         }
751 
752         /* Handle currency which may be missing */
753         myCell = pView.getRowCellByIndex(pRow, ++iAdjust);
754         MoneyWiseCurrency myCurrency = theData.getReportingCurrency();
755         if (myCell != null) {
756             final String myCurrName = myCell.getString();
757             myCurrency = theData.getAccountCurrencies().findItemByName(myCurrName);
758         }
759 
760         /* Build data values */
761         final PrometheusDataValues myValues = new PrometheusDataValues(MoneyWiseSecurity.OBJECT_NAME);
762         myValues.addValue(PrometheusDataResource.DATAITEM_FIELD_NAME, myName);
763         myValues.addValue(MoneyWiseBasicResource.CATEGORY_NAME, mySecType);
764         myValues.addValue(MoneyWiseStaticDataType.CURRENCY, myCurrency);
765         myValues.addValue(MoneyWiseBasicResource.ASSET_PARENT, myParent);
766         myValues.addValue(MoneyWiseBasicResource.ASSET_CLOSED, isClosed);
767 
768         /* Add the value into the list */
769         final MoneyWiseSecurity mySecurity = myList.addValuesItem(myValues);
770 
771         /* Add information relating to the security */
772         final MoneyWiseSecurityInfoList myInfoList = theData.getSecurityInfo();
773         myInfoList.addInfoItem(null, mySecurity, MoneyWiseAccountInfoClass.SYMBOL, mySymbol);
774         myInfoList.addInfoItem(null, mySecurity, MoneyWiseAccountInfoClass.REGION, myRegion);
775 
776         /* Declare the security holding */
777         theCache.declareSecurityHolding(mySecurity, myPortfolio);
778     }
779 }