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.club.common.transfer.ClubItemTransfer;
020import com.echothree.model.control.club.common.transfer.ClubItemTypeTransfer;
021import com.echothree.model.control.club.common.transfer.ClubTransfer;
022import com.echothree.model.control.club.server.control.ClubControl;
023import com.echothree.model.control.item.common.transfer.ItemTransfer;
024import com.echothree.model.control.item.server.control.ItemControl;
025import com.echothree.model.control.uom.common.UomConstants;
026import com.echothree.model.control.uom.server.control.UomControl;
027import com.echothree.model.data.club.server.entity.ClubItem;
028import com.echothree.model.data.uom.server.entity.UnitOfMeasureKind;
029import com.echothree.model.data.user.server.entity.UserVisit;
030import com.echothree.util.server.persistence.Session;
031
032public class ClubItemTransferCache
033        extends BaseClubTransferCache<ClubItem, ClubItemTransfer> {
034
035    ItemControl itemControl = Session.getModelController(ItemControl.class);
036    UomControl uomControl = Session.getModelController(UomControl.class);
037    UnitOfMeasureKind timeUnitOfMeasureKind = uomControl.getUnitOfMeasureKindByUnitOfMeasureKindUseTypeUsingNames(UomConstants.UnitOfMeasureKindUseType_TIME);
038    
039    /** Creates a new instance of ClubItemTransferCache */
040    public ClubItemTransferCache(UserVisit userVisit, ClubControl clubControl) {
041        super(userVisit, clubControl);
042    }
043    
044    public ClubItemTransfer getClubItemTransfer(ClubItem clubItem) {
045        ClubItemTransfer clubItemTransfer = get(clubItem);
046        
047        if(clubItemTransfer == null) {
048            ClubTransfer club = clubControl.getClubTransfer(userVisit, clubItem.getClub());
049            ClubItemTypeTransfer clubItemType = clubControl.getClubItemTypeTransfer(userVisit, clubItem.getClubItemType());
050            ItemTransfer item = itemControl.getItemTransfer(userVisit, clubItem.getItem());
051            Long unformattedSubscriptionTime = clubItem.getSubscriptionTime();
052            String subscriptionTime = formatUnitOfMeasure(timeUnitOfMeasureKind, unformattedSubscriptionTime);
053            
054            clubItemTransfer = new ClubItemTransfer(club, clubItemType, item, unformattedSubscriptionTime, subscriptionTime);
055            put(clubItem, clubItemTransfer);
056        }
057        return clubItemTransfer;
058    }
059    
060}