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.atlas.reports;
18  
19  import io.github.tonywasher.joceanus.metis.report.MetisReportBase;
20  import io.github.tonywasher.joceanus.metis.report.MetisReportManager;
21  import io.github.tonywasher.joceanus.moneywise.atlas.data.analysis.buckets.MoneyWiseXAnalysis;
22  import io.github.tonywasher.joceanus.moneywise.atlas.data.analysis.buckets.MoneyWiseXAnalysisBucketResource;
23  import io.github.tonywasher.joceanus.moneywise.atlas.data.analysis.buckets.MoneyWiseXAnalysisSecurityBucket;
24  import io.github.tonywasher.joceanus.moneywise.atlas.data.analysis.values.MoneyWiseXAnalysisValuesResource;
25  import io.github.tonywasher.joceanus.moneywise.atlas.views.MoneyWiseXAnalysisFilter;
26  import org.w3c.dom.Document;
27  
28  import java.util.EnumMap;
29  import java.util.Map;
30  
31  /**
32   * Report Classes.
33   *
34   * @author Tony Washer
35   */
36  public class MoneyWiseXReportBuilder {
37      /**
38       * The Total text.
39       */
40      protected static final String TEXT_TOTAL = MoneyWiseXAnalysisBucketResource.ANALYSIS_TOTALS.getValue();
41  
42      /**
43       * The Profit text.
44       */
45      protected static final String TEXT_PROFIT = MoneyWiseXAnalysisValuesResource.SECURITYATTR_PROFIT.getValue();
46  
47      /**
48       * The Income text.
49       */
50      protected static final String TEXT_INCOME = MoneyWiseXAnalysisValuesResource.PAYEEATTR_INCOME.getValue();
51  
52      /**
53       * The Expense text.
54       */
55      protected static final String TEXT_EXPENSE = MoneyWiseXAnalysisValuesResource.PAYEEATTR_EXPENSE.getValue();
56  
57      /**
58       * The Report Manager.
59       */
60      private final MetisReportManager<MoneyWiseXAnalysisFilter<?, ?>> theManager;
61  
62      /**
63       * Map of allocated reports.
64       */
65      private final Map<MoneyWiseXReportType, MetisReportBase<MoneyWiseXAnalysis, MoneyWiseXAnalysisFilter<?, ?>>> theReportMap;
66  
67      /**
68       * Constructor.
69       *
70       * @param pManager the report manager
71       */
72      public MoneyWiseXReportBuilder(final MetisReportManager<MoneyWiseXAnalysisFilter<?, ?>> pManager) {
73          /* Record the details */
74          theManager = pManager;
75  
76          /* Allocate map */
77          theReportMap = new EnumMap<>(MoneyWiseXReportType.class);
78      }
79  
80      /**
81       * Build a report of the appropriate type.
82       *
83       * @param pAnalysis the analysis
84       * @param pType     the report type
85       * @param pSecurity the security
86       * @return the Web document
87       */
88      public Document createReport(final MoneyWiseXAnalysis pAnalysis,
89                                   final MoneyWiseXReportType pType,
90                                   final MoneyWiseXAnalysisSecurityBucket pSecurity) {
91          /* Access existing report */
92          MetisReportBase<MoneyWiseXAnalysis, MoneyWiseXAnalysisFilter<?, ?>> myReport = theReportMap.get(pType);
93  
94          /* If we have not previously allocated this report */
95          if (myReport == null) {
96              /* Switch on the report type */
97              switch (pType) {
98                  case NETWORTH:
99                      myReport = new MoneyWiseXReportNetWorth(theManager);
100                     break;
101                 case BALANCESHEET:
102                     myReport = new MoneyWiseXReportBalanceSheet(theManager);
103                     break;
104                 case CASHFLOW:
105                     myReport = new MoneyWiseXReportCashFlow(theManager);
106                     break;
107                 case INCOMEEXPENSE:
108                     myReport = new MoneyWiseXReportIncomeExpense(theManager);
109                     break;
110                 case PORTFOLIO:
111                     myReport = new MoneyWiseXReportPortfolioView(theManager);
112                     break;
113                 case MARKETGROWTH:
114                     myReport = new MoneyWiseXReportMarketGrowth(theManager);
115                     break;
116                 case TAXBASIS:
117                     myReport = new MoneyWiseXReportTaxationBasis(theManager);
118                     break;
119                 case TAXCALC:
120                     myReport = new MoneyWiseXReportTaxCalculation(theManager);
121                     break;
122                 case ASSETGAINS:
123                     myReport = new MoneyWiseXReportAssetGains(theManager);
124                     break;
125                 case CAPITALGAINS:
126                     myReport = new MoneyWiseXReportCapitalGains(theManager);
127                     break;
128                 default:
129                     return null;
130             }
131 
132             /* Store allocated report */
133             theReportMap.put(pType, myReport);
134         }
135 
136         /* If the report requires the security */
137         if (myReport instanceof MoneyWiseXReportCapitalGains myCapGains) {
138             myCapGains.setSecurity(pSecurity);
139         }
140 
141         /* Set up the report */
142         theManager.setReport(myReport);
143 
144         /* Create the report */
145         return myReport.createReport(pAnalysis);
146     }
147 }