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.content.server.transfer; 018 019import javax.inject.Inject; 020import com.echothree.model.control.content.common.ContentOptions; 021import com.echothree.model.control.content.common.ContentProperties; 022import com.echothree.model.control.content.common.transfer.ContentCatalogTransfer; 023import com.echothree.model.control.content.common.transfer.ContentCategoryTransfer; 024import com.echothree.model.control.content.server.control.ContentControl; 025import com.echothree.model.control.offer.server.control.OfferUseControl; 026import com.echothree.model.data.content.server.entity.ContentCatalog; 027import com.echothree.model.data.user.server.entity.UserVisit; 028import com.echothree.util.common.form.TransferProperties; 029import com.echothree.util.common.transfer.ListWrapper; 030import javax.enterprise.context.RequestScoped; 031 032@RequestScoped 033public class ContentCatalogTransferCache 034 extends BaseContentTransferCache<ContentCatalog, ContentCatalogTransfer> { 035 036 @Inject 037 ContentControl contentControl; 038 039 @Inject 040 OfferUseControl offerUseControl; 041 042 boolean includeContentCatalogItems; 043 boolean includeContentCatalogCategories; 044 045 TransferProperties transferProperties; 046 boolean filterContentCollection; 047 boolean filterContentCatalogName; 048 boolean filterDefaultOfferUse; 049 boolean filterIsDefault; 050 boolean filterSortOrder; 051 boolean filterDescription; 052 boolean filterEntityInstance; 053 054 /** Creates a new instance of ContentCatalogTransferCache */ 055 protected ContentCatalogTransferCache() { 056 super(); 057 058 var options = session.getOptions(); 059 if(options != null) { 060 includeContentCatalogItems = options.contains(ContentOptions.ContentCatalogIncludeContentCatalogItems); 061 includeContentCatalogCategories = options.contains(ContentOptions.ContentCatalogIncludeContentCatalogCategories); 062 setIncludeUuid(options.contains(ContentOptions.ContentCatalogIncludeUuid)); 063 setIncludeEntityAttributeGroups(options.contains(ContentOptions.ContentCatalogIncludeEntityAttributeGroups)); 064 setIncludeTagScopes(options.contains(ContentOptions.ContentCatalogIncludeTagScopes)); 065 } 066 067 068 transferProperties = session.getTransferProperties(); 069 if(transferProperties != null) { 070 var properties = transferProperties.getProperties(ContentCategoryTransfer.class); 071 072 if(properties != null) { 073 filterContentCollection = !properties.contains(ContentProperties.CONTENT_COLLECTION); 074 filterContentCatalogName = !properties.contains(ContentProperties.CONTENT_CATALOG_NAME); 075 filterDefaultOfferUse = !properties.contains(ContentProperties.DEFAULT_OFFER_USE); 076 filterIsDefault = !properties.contains(ContentProperties.IS_DEFAULT); 077 filterSortOrder = !properties.contains(ContentProperties.SORT_ORDER); 078 filterDescription = !properties.contains(ContentProperties.DESCRIPTION); 079 filterEntityInstance = !properties.contains(ContentProperties.ENTITY_INSTANCE); 080 } 081 } 082 083 setIncludeEntityInstance(!filterEntityInstance); 084 } 085 086 public ContentCatalogTransfer getContentCatalogTransfer(UserVisit userVisit, ContentCatalog contentCatalog) { 087 var contentCatalogTransfer = get(contentCatalog); 088 089 if(contentCatalogTransfer == null) { 090 var contentCatalogDetail = contentCatalog.getLastDetail(); 091 var contentCollectionTransfer = filterContentCollection ? null : contentControl.getContentCollectionTransfer(userVisit, contentCatalogDetail.getContentCollection()); 092 var contentCatalogName = filterContentCatalogName ? null : contentCatalogDetail.getContentCatalogName(); 093 var defaultOfferUse = filterDefaultOfferUse ? null : contentCatalogDetail.getDefaultOfferUse(); 094 var defaultOfferUseTransfer = defaultOfferUse == null ? null : offerUseControl.getOfferUseTransfer(userVisit, defaultOfferUse); 095 var isDefault = filterIsDefault ? null : contentCatalogDetail.getIsDefault(); 096 var sortOrder = filterSortOrder ? null : contentCatalogDetail.getSortOrder(); 097 var description = filterDescription ? null : contentControl.getBestContentCatalogDescription(contentCatalog, getLanguage(userVisit)); 098 099 contentCatalogTransfer = new ContentCatalogTransfer(contentCollectionTransfer, contentCatalogName, defaultOfferUseTransfer, isDefault, sortOrder, 100 description); 101 put(userVisit, contentCatalog, contentCatalogTransfer); 102 103 if(includeContentCatalogItems) { 104 contentCatalogTransfer.setContentCatalogItems(new ListWrapper<>(contentControl.getContentCatalogItemTransfers(userVisit, contentCatalog))); 105 } 106 107 if(includeContentCatalogCategories) { 108 contentCatalogTransfer.setContentCategories(new ListWrapper<>(contentControl.getContentCategoryTransfers(userVisit, contentCatalog))); 109 } 110 } 111 112 return contentCatalogTransfer; 113 } 114 115}