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.control.user.party.client.helper;
018
019import com.echothree.control.user.party.common.PartyUtil;
020import com.echothree.control.user.party.common.form.GetPersonalTitleChoicesForm;
021import com.echothree.control.user.party.common.form.PartyFormFactory;
022import com.echothree.control.user.party.common.result.GetPersonalTitleChoicesResult;
023import com.echothree.model.control.party.common.choice.PersonalTitleChoicesBean;
024import com.echothree.model.data.user.common.pk.UserVisitPK;
025import com.echothree.util.common.command.CommandResult;
026import com.echothree.util.common.command.ExecutionResult;
027import javax.naming.NamingException;
028
029public class PersonalTitlesHelper {
030    
031    private PersonalTitlesHelper() {
032        super();
033    }
034    
035    private static class PersonalTitlesHelperHolder {
036        static PersonalTitlesHelper instance = new PersonalTitlesHelper();
037    }
038    
039    public static PersonalTitlesHelper getInstance() {
040        return PersonalTitlesHelperHolder.instance;
041    }
042    
043    public PersonalTitleChoicesBean getPersonalTitleChoices(final UserVisitPK userVisitPK, final Boolean allowNullChoice)
044            throws NamingException {
045        PersonalTitleChoicesBean personalTitleChoices = null;
046        GetPersonalTitleChoicesForm commandForm = PartyFormFactory.getGetPersonalTitleChoicesForm();
047
048        commandForm.setAllowNullChoice(allowNullChoice.toString());
049
050        CommandResult commandResult = PartyUtil.getHome().getPersonalTitleChoices(userVisitPK, commandForm);
051        if(!commandResult.hasErrors()) {
052            ExecutionResult executionResult = commandResult.getExecutionResult();
053            GetPersonalTitleChoicesResult result = (GetPersonalTitleChoicesResult)executionResult.getResult();
054
055            personalTitleChoices = result.getPersonalTitleChoices();
056        }
057
058        return personalTitleChoices;
059    }
060
061}