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