001// -------------------------------------------------------------------------------- 002// Copyright 2002-2026 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.server.control.ClubControl; 021import com.echothree.model.control.item.server.control.ItemControl; 022import com.echothree.model.control.uom.common.UomConstants; 023import com.echothree.model.control.uom.server.control.UomControl; 024import com.echothree.model.data.club.server.entity.ClubItem; 025import com.echothree.model.data.uom.server.entity.UnitOfMeasureKind; 026import com.echothree.model.data.user.server.entity.UserVisit; 027import javax.annotation.PostConstruct; 028import javax.enterprise.context.RequestScoped; 029import javax.inject.Inject; 030 031@RequestScoped 032public class ClubItemTransferCache 033 extends BaseClubTransferCache<ClubItem, ClubItemTransfer> { 034 035 @Inject 036 ClubControl clubControl; 037 038 @Inject 039 ItemControl itemControl; 040 041 @Inject 042 UomControl uomControl; 043 044 UnitOfMeasureKind timeUnitOfMeasureKind; 045 046 /** Creates a new instance of ClubItemTransferCache */ 047 protected ClubItemTransferCache() { 048 super(); 049 } 050 051 @PostConstruct 052 public void setup() { 053 timeUnitOfMeasureKind = uomControl.getUnitOfMeasureKindByUnitOfMeasureKindUseTypeUsingNames(UomConstants.UnitOfMeasureKindUseType_TIME); 054 } 055 056 public ClubItemTransfer getClubItemTransfer(UserVisit userVisit, ClubItem clubItem) { 057 var clubItemTransfer = get(clubItem); 058 059 if(clubItemTransfer == null) { 060 var club = clubControl.getClubTransfer(userVisit, clubItem.getClub()); 061 var clubItemType = clubControl.getClubItemTypeTransfer(userVisit, clubItem.getClubItemType()); 062 var item = itemControl.getItemTransfer(userVisit, clubItem.getItem()); 063 var unformattedSubscriptionTime = clubItem.getSubscriptionTime(); 064 var subscriptionTime = formatUnitOfMeasure(userVisit, timeUnitOfMeasureKind, unformattedSubscriptionTime); 065 066 clubItemTransfer = new ClubItemTransfer(club, clubItemType, item, unformattedSubscriptionTime, subscriptionTime); 067 put(userVisit, clubItem, clubItemTransfer); 068 } 069 return clubItemTransfer; 070 } 071 072}