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.content.server.transfer; 018 019import com.echothree.model.control.content.common.ContentOptions; 020import com.echothree.model.control.content.common.transfer.ContentCollectionTransfer; 021import com.echothree.model.control.content.server.control.ContentControl; 022import com.echothree.model.control.offer.common.transfer.OfferUseTransfer; 023import com.echothree.model.control.offer.server.control.OfferUseControl; 024import com.echothree.model.data.content.server.entity.ContentCollection; 025import com.echothree.model.data.content.server.entity.ContentCollectionDetail; 026import com.echothree.model.data.user.server.entity.UserVisit; 027import com.echothree.util.common.transfer.ListWrapper; 028import com.echothree.util.server.persistence.Session; 029import java.util.Set; 030 031public class ContentCollectionTransferCache 032 extends BaseContentTransferCache<ContentCollection, ContentCollectionTransfer> { 033 034 OfferUseControl offerUseControl = Session.getModelController(OfferUseControl.class); 035 boolean includeContentCatalogs; 036 boolean includeContentForums; 037 boolean includeContentSections; 038 039 /** Creates a new instance of ContentCollectionTransferCache */ 040 public ContentCollectionTransferCache(UserVisit userVisit, ContentControl contentControl) { 041 super(userVisit, contentControl); 042 043 var options = session.getOptions(); 044 if(options != null) { 045 includeContentCatalogs = options.contains(ContentOptions.ContentCollectionIncludeContentCatalogs); 046 includeContentForums = options.contains(ContentOptions.ContentCollectionIncludeContentForums); 047 includeContentSections = options.contains(ContentOptions.ContentCollectionIncludeContentSections); 048 setIncludeKey(options.contains(ContentOptions.ContentCollectionIncludeKey)); 049 setIncludeGuid(options.contains(ContentOptions.ContentCollectionIncludeGuid)); 050 setIncludeEntityAttributeGroups(options.contains(ContentOptions.ContentCollectionIncludeEntityAttributeGroups)); 051 setIncludeTagScopes(options.contains(ContentOptions.ContentCollectionIncludeTagScopes)); 052 } 053 054 setIncludeEntityInstance(true); 055 } 056 057 public ContentCollectionTransfer getContentCollectionTransfer(ContentCollection contentCollection) { 058 ContentCollectionTransfer contentCollectionTransfer = get(contentCollection); 059 060 if(contentCollectionTransfer == null) { 061 ContentCollectionDetail contentCollectionDetail = contentCollection.getLastDetail(); 062 String contentCollectionName = contentCollectionDetail.getContentCollectionName(); 063 OfferUseTransfer defaultOfferUse = offerUseControl.getOfferUseTransfer(userVisit, contentCollectionDetail.getDefaultOfferUse()); 064 String description = contentControl.getBestContentCollectionDescription(contentCollection, getLanguage()); 065 066 contentCollectionTransfer = new ContentCollectionTransfer(contentCollectionName, defaultOfferUse, description); 067 put(contentCollection, contentCollectionTransfer); 068 069 if(includeContentCatalogs) { 070 contentCollectionTransfer.setContentCatalogs(new ListWrapper<>(contentControl.getContentCatalogTransfers(userVisit, contentCollection))); 071 } 072 073 if(includeContentForums) { 074 contentCollectionTransfer.setContentForums(new ListWrapper<>(contentControl.getContentForumTransfers(userVisit, contentCollection))); 075 } 076 077 if(includeContentSections) { 078 contentCollectionTransfer.setContentSections(new ListWrapper<>(contentControl.getContentSectionTransfers(userVisit, contentCollection))); 079 } 080 } 081 082 return contentCollectionTransfer; 083 } 084 085}