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.scale.server.transfer; 018 019import com.echothree.model.control.core.common.transfer.ServerServiceTransfer; 020import com.echothree.model.control.core.server.control.CoreControl; 021import com.echothree.model.control.scale.common.transfer.ScaleTransfer; 022import com.echothree.model.control.scale.common.transfer.ScaleTypeTransfer; 023import com.echothree.model.control.scale.server.control.ScaleControl; 024import com.echothree.model.data.scale.server.entity.Scale; 025import com.echothree.model.data.scale.server.entity.ScaleDetail; 026import com.echothree.model.data.user.server.entity.UserVisit; 027import com.echothree.util.server.persistence.Session; 028 029public class ScaleTransferCache 030 extends BaseScaleTransferCache<Scale, ScaleTransfer> { 031 032 CoreControl coreControl = Session.getModelController(CoreControl.class); 033 034 /** Creates a new instance of ScaleTransferCache */ 035 public ScaleTransferCache(UserVisit userVisit, ScaleControl scaleControl) { 036 super(userVisit, scaleControl); 037 038 setIncludeEntityInstance(true); 039 } 040 041 public ScaleTransfer getScaleTransfer(Scale scale) { 042 ScaleTransfer scaleTransfer = get(scale); 043 044 if(scaleTransfer == null) { 045 ScaleDetail scaleDetail = scale.getLastDetail(); 046 String scaleName = scaleDetail.getScaleName(); 047 ScaleTypeTransfer scaleType = scaleControl.getScaleTypeTransfer(userVisit, scaleDetail.getScaleType()); 048 ServerServiceTransfer serverService = coreControl.getServerServiceTransfer(userVisit, scaleDetail.getServerService()); 049 Boolean isDefault = scaleDetail.getIsDefault(); 050 Integer sortOrder = scaleDetail.getSortOrder(); 051 String description = scaleControl.getBestScaleDescription(scale, getLanguage()); 052 053 scaleTransfer = new ScaleTransfer(scaleName, scaleType, serverService, isDefault, sortOrder, description); 054 put(scale, scaleTransfer); 055 } 056 057 return scaleTransfer; 058 } 059 060}