001// --------------------------------------------------------------------------------
002// Copyright 2002-2026 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.party.common.PartyUtil;
021import com.echothree.model.control.accounting.common.choice.CurrencyChoicesBean;
022import com.echothree.model.control.party.common.choice.DateTimeFormatChoicesBean;
023import com.echothree.model.control.party.common.choice.LanguageChoicesBean;
024import com.echothree.model.control.party.common.choice.TimeZoneChoicesBean;
025import java.util.List;
026import javax.naming.NamingException;
027import org.apache.struts.util.LabelValueBean;
028
029public class BasePartyActionForm
030        extends BaseActionForm {
031    
032    private CurrencyChoicesBean currencyChoices = null;
033    private DateTimeFormatChoicesBean dateTimeFormatChoices = null;
034    private LanguageChoicesBean languageChoices = null;
035    private TimeZoneChoicesBean timeZoneChoices = null;
036    
037    private String currencyChoice = null;
038    private String dateTimeFormatChoice = null;
039    private String languageChoice = null;
040    private String timeZoneChoice = null;
041    
042    /** Creates a new instance of BasePartyActionForm */
043    public BasePartyActionForm() {
044        super();
045    }
046    
047    private void setupCurrencyChoices() {
048        if(currencyChoices == null) {
049            try {
050                var commandForm = AccountingUtil.getHome().getGetCurrencyChoicesForm();
051                
052                commandForm.setDefaultCurrencyChoice(currencyChoice);
053                commandForm.setAllowNullChoice(String.valueOf(true));
054
055                var commandResult = AccountingUtil.getHome().getCurrencyChoices(userVisitPK, commandForm);
056                var executionResult = commandResult.getExecutionResult();
057                var getCurrencyChoicesResult = executionResult.getResult();
058                currencyChoices = getCurrencyChoicesResult.getCurrencyChoices();
059                
060                if(currencyChoice == null) {
061                    currencyChoice = currencyChoices.getDefaultValue();
062                }
063            } catch (NamingException ne) {
064                // failed, currencyChoices remains null, no default
065            }
066        }
067    }
068    
069    public List<LabelValueBean> getCurrencyChoices() {
070        List<LabelValueBean> choices = null;
071        
072        setupCurrencyChoices();
073        if(currencyChoices != null) {
074            choices = convertChoices(currencyChoices);
075        }
076        
077        return choices;
078    }
079    
080    public void setCurrencyChoice(String currencyChoice) {
081        this.currencyChoice = currencyChoice;
082    }
083    
084    public String getCurrencyChoice() {
085        setupCurrencyChoices();
086        
087        return currencyChoice;
088    }
089    
090    private void setupDateTimeFormatChoices() {
091        if(dateTimeFormatChoices == null) {
092            try {
093                var commandForm = PartyUtil.getHome().getGetDateTimeFormatChoicesForm();
094                
095                commandForm.setDefaultDateTimeFormatChoice(dateTimeFormatChoice);
096                commandForm.setAllowNullChoice(String.valueOf(true));
097
098                var commandResult = PartyUtil.getHome().getDateTimeFormatChoices(userVisitPK, commandForm);
099                var executionResult = commandResult.getExecutionResult();
100                var getDateTimeFormatChoicesResult = executionResult.getResult();
101                dateTimeFormatChoices = getDateTimeFormatChoicesResult.getDateTimeFormatChoices();
102                
103                if(dateTimeFormatChoice == null) {
104                    dateTimeFormatChoice = dateTimeFormatChoices.getDefaultValue();
105                }
106            } catch (NamingException ne) {
107                // failed, dateTimeFormatChoices remains null, no default
108            }
109        }
110    }
111    
112    public List<LabelValueBean> getDateTimeFormatChoices() {
113        List<LabelValueBean> choices = null;
114        
115        setupDateTimeFormatChoices();
116        if(dateTimeFormatChoices != null) {
117            choices = convertChoices(dateTimeFormatChoices);
118        }
119        
120        return choices;
121    }
122    
123    public void setDateTimeFormatChoice(String dateTimeFormatChoice) {
124        this.dateTimeFormatChoice = dateTimeFormatChoice;
125    }
126    
127    public String getDateTimeFormatChoice() {
128        setupDateTimeFormatChoices();
129        
130        return dateTimeFormatChoice;
131    }
132    
133    private void setupLanguageChoices() {
134        if(languageChoices == null) {
135            try {
136                var commandForm = PartyUtil.getHome().getGetLanguageChoicesForm();
137                
138                commandForm.setDefaultLanguageChoice(languageChoice);
139                commandForm.setAllowNullChoice(String.valueOf(true));
140
141                var commandResult = PartyUtil.getHome().getLanguageChoices(userVisitPK, commandForm);
142                var executionResult = commandResult.getExecutionResult();
143                var getLanguageChoicesResult = executionResult.getResult();
144                languageChoices = getLanguageChoicesResult.getLanguageChoices();
145                
146                if(languageChoice == null) {
147                    languageChoice = languageChoices.getDefaultValue();
148                }
149            } catch (NamingException ne) {
150                // failed, languageChoices remains null, no default
151            }
152        }
153    }
154    
155    public List<LabelValueBean> getLanguageChoices() {
156        List<LabelValueBean> choices = null;
157        
158        setupLanguageChoices();
159        if(languageChoices != null) {
160            choices = convertChoices(languageChoices);
161        }
162        
163        return choices;
164    }
165    
166    public void setLanguageChoice(String languageChoice) {
167        this.languageChoice = languageChoice;
168    }
169    
170    public String getLanguageChoice() {
171        setupLanguageChoices();
172        
173        return languageChoice;
174    }
175    
176    private void setupTimeZoneChoices() {
177        if(timeZoneChoices == null) {
178            try {
179                var commandForm = PartyUtil.getHome().getGetTimeZoneChoicesForm();
180                
181                commandForm.setDefaultTimeZoneChoice(timeZoneChoice);
182                commandForm.setAllowNullChoice(String.valueOf(true));
183
184                var commandResult = PartyUtil.getHome().getTimeZoneChoices(userVisitPK, commandForm);
185                var executionResult = commandResult.getExecutionResult();
186                var getTimeZoneChoicesResult = executionResult.getResult();
187                timeZoneChoices = getTimeZoneChoicesResult.getTimeZoneChoices();
188                
189                if(timeZoneChoice == null) {
190                    timeZoneChoice = timeZoneChoices.getDefaultValue();
191                }
192            } catch (NamingException ne) {
193                // failed, timeZoneChoices remains null, no default
194            }
195        }
196    }
197    
198    public List<LabelValueBean> getTimeZoneChoices() {
199        List<LabelValueBean> choices = null;
200        
201        setupTimeZoneChoices();
202        if(timeZoneChoices != null) {
203            choices = convertChoices(timeZoneChoices);
204        }
205        
206        return choices;
207    }
208    
209    public void setTimeZoneChoice(String timeZoneChoice) {
210        this.timeZoneChoice = timeZoneChoice;
211    }
212    
213    public String getTimeZoneChoice() {
214        setupTimeZoneChoices();
215        
216        return timeZoneChoice;
217    }
218    
219}