001// -------------------------------------------------------------------------------- 002// Copyright 2002-2025 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.club.server.transfer; 018 019import com.echothree.model.control.accounting.server.control.AccountingControl; 020import com.echothree.model.control.club.common.transfer.ClubTransfer; 021import com.echothree.model.control.club.server.control.ClubControl; 022import com.echothree.model.control.filter.server.control.FilterControl; 023import com.echothree.model.control.subscription.server.control.SubscriptionControl; 024import com.echothree.model.data.club.server.entity.Club; 025import com.echothree.model.data.user.server.entity.UserVisit; 026import com.echothree.util.server.persistence.Session; 027import javax.enterprise.context.RequestScoped; 028 029@RequestScoped 030public class ClubTransferCache 031 extends BaseClubTransferCache<Club, ClubTransfer> { 032 033 AccountingControl accountingControl = Session.getModelController(AccountingControl.class); 034 ClubControl clubControl = Session.getModelController(ClubControl.class); 035 FilterControl filterControl = Session.getModelController(FilterControl.class); 036 SubscriptionControl subscriptionControl = Session.getModelController(SubscriptionControl.class); 037 038 /** Creates a new instance of ClubTransferCache */ 039 protected ClubTransferCache() { 040 super(); 041 042 setIncludeEntityInstance(true); 043 } 044 045 public ClubTransfer getClubTransfer(UserVisit userVisit, Club club) { 046 var clubTransfer = get(club); 047 048 if(clubTransfer == null) { 049 var clubDetail = club.getLastDetail(); 050 var clubName = clubDetail.getClubName(); 051 var subscriptionTypeTransfer = subscriptionControl.getSubscriptionTypeTransfer(userVisit, clubDetail.getSubscriptionType()); 052 var clubPriceFilter = clubDetail.getClubPriceFilter(); 053 var clubPriceFilterTransfer = clubPriceFilter == null? null: filterControl.getFilterTransfer(userVisit, clubPriceFilter); 054 var currency = clubDetail.getCurrency(); 055 var currencyTransfer = currency == null? null: accountingControl.getCurrencyTransfer(userVisit, currency); 056 var isDefault = clubDetail.getIsDefault(); 057 var sortOrder = clubDetail.getSortOrder(); 058 var description = clubControl.getBestClubDescription(club, getLanguage(userVisit)); 059 060 clubTransfer = new ClubTransfer(clubName, subscriptionTypeTransfer, clubPriceFilterTransfer, currencyTransfer, isDefault, sortOrder, description); 061 put(userVisit, club, clubTransfer); 062 } 063 064 return clubTransfer; 065 } 066 067}