81308909babb3c05fcf4a07c0282ee85f6e2ed00
[portal/sdk.git] /
1 /*-
2  * ================================================================================
3  * eCOMP Portal SDK
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ================================================================================
19  */
20  package org.openecomp.portalsdk.analytics.controller;
21
22 import java.util.*;
23
24 import org.openecomp.portalsdk.analytics.model.base.*;
25 import org.openecomp.portalsdk.analytics.model.definition.*;
26 import org.openecomp.portalsdk.analytics.system.*;
27 import org.openecomp.portalsdk.analytics.util.*;
28
29 public class WizardSequence extends Vector {
30         // private String currentStep = AppConstants.WS_DEFINITION;
31         private int currentStepIdx = 0;
32
33         private String currentSubStep = "";
34
35         private int nextElemIdx = 0;
36
37         public void resetNext() {
38                 resetNext(0);
39         } // resetNext
40
41         public void resetNext(int toPos) {
42                 nextElemIdx = toPos;
43         } // resetNext
44
45         public boolean hasNext() {
46                 return (nextElemIdx < size());
47         } // hasNext
48
49         public String getNext() {
50                 return hasNext() ? getStep(nextElemIdx++) : null;
51         } // getNext
52
53         // *****************************************************
54
55         public WizardSequence() {
56                 add(AppConstants.WS_DEFINITION);
57         } // WizardSequence
58
59         private String getStep(int index) {
60                 return (String) get(index);
61         } // getStep
62
63         private int getStepIndex(String step) {
64                 for (int i = 0; i < size(); i++)
65                         if (getStep(i).equals(step))
66                                 return i;
67
68                 throw new IndexOutOfBoundsException();
69         } // getStepIndex
70
71         /*
72          * private String getInitialStep() { return getStep(0); } // getInitialStep
73          * 
74          * private String getFinalStep() { return getStep(getStepCount()-1); } //
75          * getFinalStep
76          */
77         private boolean isInitialStep(int index) {
78                 return (index == 0);
79         } // isInitialStep
80
81         /*
82          * private boolean isInitialStep(String step) { return
83          * isInitialStep(getStepIndex(step)); } // isInitialStep
84          */
85         private boolean isFinalStep(int index) {
86                 if (index == 0)
87                         return false;
88
89                 return (index == (getStepCount() - 1));
90         } // isFinalStep
91
92         /*
93          * private boolean isFinalStep(String step) { return
94          * isFinalStep(getStepIndex(step)); } // isFinalStep
95          */
96
97         private int getNextStepIndex(int index) {
98                 return (index == (getStepCount() - 1)) ? index : (index + 1);
99         } // getNextStep
100
101         /*
102          * private String getNextStep(String step) { return
103          * getStep(getNextStepIndex(getStepIndex(step))); } // getNextStep
104          * 
105          * private String getNextStep(String step, String subStep) {
106          * if(subStep.length()>0) return step;
107          * 
108          * return getNextStep(step); } // getNextStep
109          */
110         private int getPrevStepIndex(int index) {
111                 return (index == 0) ? index : (index - 1);
112         } // getPrevStepIndex
113
114         /*
115          * private String getPrevStep(String step) { return
116          * getStep(getPrevStepIndex(getStepIndex(step))); } // getPrevStep
117          * 
118          * private String getPrevStep(String step, String subStep) {
119          * if(subStep.length()>0) return step;
120          * 
121          * return getPrevStep(step); } // getPrevStep
122          */
123         // *****************************************************
124         public int getStepCount() {
125                 return size();
126         } // getStepCount
127
128         public int getCurrentStepIndex() {
129                 return currentStepIdx + 1;
130         } // getCurrentStepIndex
131
132         public String getCurrentStep() {
133                 return getStep(currentStepIdx);
134         } // getCurrentStep
135
136         public String getCurrentSubStep() {
137                 return currentSubStep;
138         } // getCurrentSubStep
139
140         public boolean isInitialStep() {
141                 return isInitialStep(currentStepIdx);
142         } // isInitialStep
143
144         public boolean isFinalStep() {
145                 return isFinalStep(currentStepIdx);
146         } // isFinalStep
147
148         public void performAction(String action, ReportDefinition rdef) {
149                 if (action.equals(AppConstants.WA_BACK))
150                         if (currentSubStep.length() > 0)
151                                 currentSubStep = "";
152                         else
153                                 currentStepIdx = getPrevStepIndex(currentStepIdx);
154                 else if (action.equals(AppConstants.WA_NEXT)) {
155                         if (currentSubStep.length() > 0)
156                                 currentSubStep = "";
157                         else {
158                                 currentStepIdx = getNextStepIndex(currentStepIdx);
159                                 if (rdef != null)
160                                         if (!rdef.getReportDefType().equals(AppConstants.RD_SQL_BASED))
161                                                 if (getCurrentStep().equals(AppConstants.WS_TABLES)
162                                                                 && (rdef.getDataSourceList().getDataSource().size() == 0))
163                                                         currentSubStep = AppConstants.WSS_ADD;
164                                                 else if (getCurrentStep().equals(AppConstants.WS_COLUMNS)
165                                                                 && (rdef.getAllColumns().size() == 0))
166                                                         currentSubStep = (rdef.getReportType().equals(
167                                                                         AppConstants.RT_CROSSTAB) ? AppConstants.WSS_ADD
168                                                                         : AppConstants.WSS_ADD_MULTI);
169                         }
170                 } else if (action.equals(AppConstants.WA_EDIT) || action.equals(AppConstants.WA_ADD)
171                                 || action.equals(AppConstants.WA_ADD_MULTI)
172                                 || action.equals(AppConstants.WA_ORDER_ALL)|| action.equals(AppConstants.WSS_ADD_BLANK) || action.equals(AppConstants.WA_MODIFY)) {
173                         currentSubStep = action;
174                 }
175                 else if (currentSubStep.equals(AppConstants.WSS_ADD)
176                                 || currentSubStep.equals(AppConstants.WSS_EDIT))
177                         currentSubStep = AppConstants.WSS_EDIT;
178                 else
179                         currentSubStep = "";
180         } // performAction
181
182         public void performGoToStep(String step) {
183                 int stepIdx = getStepIndex(step);
184
185                 if (stepIdx >= 0 && stepIdx < getStepCount()) {
186                         currentStepIdx = stepIdx;
187                         currentSubStep = "";
188                 }
189         } // performGoToStep
190
191 } // WizardSequence