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.model.control.user.server.transfer;
018
019import com.echothree.model.control.user.common.transfer.RecoveryQuestionTransfer;
020import com.echothree.model.control.user.server.control.UserControl;
021import com.echothree.model.data.user.server.entity.RecoveryQuestion;
022import com.echothree.model.data.user.server.entity.RecoveryQuestionDetail;
023import com.echothree.model.data.user.server.entity.UserVisit;
024
025public class RecoveryQuestionTransferCache
026        extends BaseUserTransferCache<RecoveryQuestion, RecoveryQuestionTransfer> {
027    
028    /** Creates a new instance of RecoveryQuestionTransferCache */
029    public RecoveryQuestionTransferCache(UserVisit userVisit, UserControl userControl) {
030        super(userVisit, userControl);
031
032        setIncludeEntityInstance(true);
033    }
034    
035    public RecoveryQuestionTransfer getRecoveryQuestionTransfer(RecoveryQuestion recoveryQuestion) {
036        RecoveryQuestionTransfer recoveryQuestionTransfer = get(recoveryQuestion);
037        
038        if(recoveryQuestionTransfer == null) {
039            RecoveryQuestionDetail recoveryQuestionDetail = recoveryQuestion.getLastDetail();
040            String recoveryQuestionName = recoveryQuestionDetail.getRecoveryQuestionName();
041            Boolean isDefault = recoveryQuestionDetail.getIsDefault();
042            Integer sortOrder = recoveryQuestionDetail.getSortOrder();
043            String description = userControl.getBestRecoveryQuestionDescription(recoveryQuestion, getLanguage());
044            
045            recoveryQuestionTransfer = new RecoveryQuestionTransfer(recoveryQuestionName, isDefault, sortOrder, description);
046            put(recoveryQuestion, recoveryQuestionTransfer);
047        }
048        
049        return recoveryQuestionTransfer;
050    }
051    
052}