001// --------------------------------------------------------------------------------
002// Copyright 2002-2024 Echo Three, LLC
003//
004// Licensed under the Apache License, Version 2.0 (the "License");
005// you may not use this file except in compliance with the License.
006// You may obtain a copy of the License at
007//
008//     http://www.apache.org/licenses/LICENSE-2.0
009//
010// Unless required by applicable law or agreed to in writing, software
011// distributed under the License is distributed on an "AS IS" BASIS,
012// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013// See the License for the specific language governing permissions and
014// limitations under the License.
015// --------------------------------------------------------------------------------
016
017package com.echothree.view.client.web.struts;
018
019import com.echothree.control.user.accounting.common.AccountingUtil;
020import com.echothree.control.user.accounting.common.form.GetCurrencyChoicesForm;
021import com.echothree.control.user.accounting.common.result.GetCurrencyChoicesResult;
022import com.echothree.control.user.party.common.PartyUtil;
023import com.echothree.control.user.party.common.form.GetDateTimeFormatChoicesForm;
024import com.echothree.control.user.party.common.form.GetLanguageChoicesForm;
025import com.echothree.control.user.party.common.form.GetTimeZoneChoicesForm;
026import com.echothree.control.user.party.common.result.GetDateTimeFormatChoicesResult;
027import com.echothree.control.user.party.common.result.GetLanguageChoicesResult;
028import com.echothree.control.user.party.common.result.GetTimeZoneChoicesResult;
029import com.echothree.model.control.accounting.common.choice.CurrencyChoicesBean;
030import com.echothree.model.control.party.common.choice.DateTimeFormatChoicesBean;
031import com.echothree.model.control.party.common.choice.LanguageChoicesBean;
032import com.echothree.model.control.party.common.choice.TimeZoneChoicesBean;
033import com.echothree.util.common.command.CommandResult;
034import com.echothree.util.common.command.ExecutionResult;
035import java.util.List;
036import javax.naming.NamingException;
037import org.apache.struts.util.LabelValueBean;
038
039public class BasePartyActionForm
040        extends BaseActionForm {
041    
042    private CurrencyChoicesBean currencyChoices = null;
043    private DateTimeFormatChoicesBean dateTimeFormatChoices = null;
044    private LanguageChoicesBean languageChoices = null;
045    private TimeZoneChoicesBean timeZoneChoices = null;
046    
047    private String currencyChoice = null;
048    private String dateTimeFormatChoice = null;
049    private String languageChoice = null;
050    private String timeZoneChoice = null;
051    
052    /** Creates a new instance of BasePartyActionForm */
053    public BasePartyActionForm() {
054        super();
055    }
056    
057    private void setupCurrencyChoices() {
058        if(currencyChoices == null) {
059            try {
060                GetCurrencyChoicesForm commandForm = AccountingUtil.getHome().getGetCurrencyChoicesForm();
061                
062                commandForm.setDefaultCurrencyChoice(currencyChoice);
063                commandForm.setAllowNullChoice(Boolean.TRUE.toString());
064                
065                CommandResult commandResult = AccountingUtil.getHome().getCurrencyChoices(userVisitPK, commandForm);
066                ExecutionResult executionResult = commandResult.getExecutionResult();
067                GetCurrencyChoicesResult getCurrencyChoicesResult = (GetCurrencyChoicesResult)executionResult.getResult();
068                currencyChoices = getCurrencyChoicesResult.getCurrencyChoices();
069                
070                if(currencyChoice == null) {
071                    currencyChoice = currencyChoices.getDefaultValue();
072                }
073            } catch (NamingException ne) {
074                // failed, currencyChoices remains null, no default
075            }
076        }
077    }
078    
079    public List<LabelValueBean> getCurrencyChoices() {
080        List<LabelValueBean> choices = null;
081        
082        setupCurrencyChoices();
083        if(currencyChoices != null) {
084            choices = convertChoices(currencyChoices);
085        }
086        
087        return choices;
088    }
089    
090    public void setCurrencyChoice(String currencyChoice) {
091        this.currencyChoice = currencyChoice;
092    }
093    
094    public String getCurrencyChoice() {
095        setupCurrencyChoices();
096        
097        return currencyChoice;
098    }
099    
100    private void setupDateTimeFormatChoices() {
101        if(dateTimeFormatChoices == null) {
102            try {
103                GetDateTimeFormatChoicesForm commandForm = PartyUtil.getHome().getGetDateTimeFormatChoicesForm();
104                
105                commandForm.setDefaultDateTimeFormatChoice(dateTimeFormatChoice);
106                commandForm.setAllowNullChoice(Boolean.TRUE.toString());
107                
108                CommandResult commandResult = PartyUtil.getHome().getDateTimeFormatChoices(userVisitPK, commandForm);
109                ExecutionResult executionResult = commandResult.getExecutionResult();
110                GetDateTimeFormatChoicesResult getDateTimeFormatChoicesResult = (GetDateTimeFormatChoicesResult)executionResult.getResult();
111                dateTimeFormatChoices = getDateTimeFormatChoicesResult.getDateTimeFormatChoices();
112                
113                if(dateTimeFormatChoice == null) {
114                    dateTimeFormatChoice = dateTimeFormatChoices.getDefaultValue();
115                }
116            } catch (NamingException ne) {
117                // failed, dateTimeFormatChoices remains null, no default
118            }
119        }
120    }
121    
122    public List<LabelValueBean> getDateTimeFormatChoices() {
123        List<LabelValueBean> choices = null;
124        
125        setupDateTimeFormatChoices();
126        if(dateTimeFormatChoices != null) {
127            choices = convertChoices(dateTimeFormatChoices);
128        }
129        
130        return choices;
131    }
132    
133    public void setDateTimeFormatChoice(String dateTimeFormatChoice) {
134        this.dateTimeFormatChoice = dateTimeFormatChoice;
135    }
136    
137    public String getDateTimeFormatChoice() {
138        setupDateTimeFormatChoices();
139        
140        return dateTimeFormatChoice;
141    }
142    
143    private void setupLanguageChoices() {
144        if(languageChoices == null) {
145            try {
146                GetLanguageChoicesForm commandForm = PartyUtil.getHome().getGetLanguageChoicesForm();
147                
148                commandForm.setDefaultLanguageChoice(languageChoice);
149                commandForm.setAllowNullChoice(Boolean.TRUE.toString());
150                
151                CommandResult commandResult = PartyUtil.getHome().getLanguageChoices(userVisitPK, commandForm);
152                ExecutionResult executionResult = commandResult.getExecutionResult();
153                GetLanguageChoicesResult getLanguageChoicesResult = (GetLanguageChoicesResult)executionResult.getResult();
154                languageChoices = getLanguageChoicesResult.getLanguageChoices();
155                
156                if(languageChoice == null) {
157                    languageChoice = languageChoices.getDefaultValue();
158                }
159            } catch (NamingException ne) {
160                // failed, languageChoices remains null, no default
161            }
162        }
163    }
164    
165    public List<LabelValueBean> getLanguageChoices() {
166        List<LabelValueBean> choices = null;
167        
168        setupLanguageChoices();
169        if(languageChoices != null) {
170            choices = convertChoices(languageChoices);
171        }
172        
173        return choices;
174    }
175    
176    public void setLanguageChoice(String languageChoice) {
177        this.languageChoice = languageChoice;
178    }
179    
180    public String getLanguageChoice() {
181        setupLanguageChoices();
182        
183        return languageChoice;
184    }
185    
186    private void setupTimeZoneChoices() {
187        if(timeZoneChoices == null) {
188            try {
189                GetTimeZoneChoicesForm commandForm = PartyUtil.getHome().getGetTimeZoneChoicesForm();
190                
191                commandForm.setDefaultTimeZoneChoice(timeZoneChoice);
192                commandForm.setAllowNullChoice(Boolean.TRUE.toString());
193                
194                CommandResult commandResult = PartyUtil.getHome().getTimeZoneChoices(userVisitPK, commandForm);
195                ExecutionResult executionResult = commandResult.getExecutionResult();
196                GetTimeZoneChoicesResult getTimeZoneChoicesResult = (GetTimeZoneChoicesResult)executionResult.getResult();
197                timeZoneChoices = getTimeZoneChoicesResult.getTimeZoneChoices();
198                
199                if(timeZoneChoice == null) {
200                    timeZoneChoice = timeZoneChoices.getDefaultValue();
201                }
202            } catch (NamingException ne) {
203                // failed, timeZoneChoices remains null, no default
204            }
205        }
206    }
207    
208    public List<LabelValueBean> getTimeZoneChoices() {
209        List<LabelValueBean> choices = null;
210        
211        setupTimeZoneChoices();
212        if(timeZoneChoices != null) {
213            choices = convertChoices(timeZoneChoices);
214        }
215        
216        return choices;
217    }
218    
219    public void setTimeZoneChoice(String timeZoneChoice) {
220        this.timeZoneChoice = timeZoneChoice;
221    }
222    
223    public String getTimeZoneChoice() {
224        setupTimeZoneChoices();
225        
226        return timeZoneChoice;
227    }
228    
229}