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.training.server.transfer;
018
019import com.echothree.model.control.core.common.transfer.MimeTypeTransfer;
020import com.echothree.model.control.core.server.control.CoreControl;
021import com.echothree.model.control.party.common.transfer.LanguageTransfer;
022import com.echothree.model.control.training.common.transfer.TrainingClassTransfer;
023import com.echothree.model.control.training.common.transfer.TrainingClassTranslationTransfer;
024import com.echothree.model.control.training.server.control.TrainingControl;
025import com.echothree.model.data.core.server.entity.MimeType;
026import com.echothree.model.data.training.server.entity.TrainingClassTranslation;
027import com.echothree.model.data.user.server.entity.UserVisit;
028import com.echothree.util.server.persistence.Session;
029
030public class TrainingClassTranslationTransferCache
031        extends BaseTrainingDescriptionTransferCache<TrainingClassTranslation, TrainingClassTranslationTransfer> {
032    
033    CoreControl coreControl = Session.getModelController(CoreControl.class);
034    
035    /** Creates a new instance of TrainingClassTranslationTransferCache */
036    public TrainingClassTranslationTransferCache(UserVisit userVisit, TrainingControl trainingControl) {
037        super(userVisit, trainingControl);
038    }
039    
040    public TrainingClassTranslationTransfer getTrainingClassTranslationTransfer(TrainingClassTranslation trainingClassTranslation) {
041        TrainingClassTranslationTransfer trainingClassTranslationTransfer = get(trainingClassTranslation);
042        
043        if(trainingClassTranslationTransfer == null) {
044            TrainingClassTransfer trainingClassTransfer = trainingControl.getTrainingClassTransfer(userVisit, trainingClassTranslation.getTrainingClass());
045            LanguageTransfer languageTransfer = partyControl.getLanguageTransfer(userVisit, trainingClassTranslation.getLanguage());
046            String description = trainingClassTranslation.getDescription();
047            MimeType overviewMimeType = trainingClassTranslation.getOverviewMimeType();
048            MimeTypeTransfer overviewMimeTypeTransfer = overviewMimeType == null? null: coreControl.getMimeTypeTransfer(userVisit, overviewMimeType);
049            String overview = trainingClassTranslation.getOverview();
050            MimeType introductionMimeType = trainingClassTranslation.getIntroductionMimeType();
051            MimeTypeTransfer introductionMimeTypeTransfer = introductionMimeType == null? null: coreControl.getMimeTypeTransfer(userVisit, introductionMimeType);
052            String introduction = trainingClassTranslation.getIntroduction();
053            
054            trainingClassTranslationTransfer = new TrainingClassTranslationTransfer(trainingClassTransfer, languageTransfer, description,
055                    overviewMimeTypeTransfer, overview, introductionMimeTypeTransfer, introduction);
056            put(trainingClassTranslation, trainingClassTranslationTransfer);
057        }
058        
059        return trainingClassTranslationTransfer;
060    }
061    
062}