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.ContentCategoryTransfer; 023import com.echothree.model.control.content.server.control.ContentControl; 024import com.echothree.model.control.offer.server.control.OfferUseControl; 025import com.echothree.model.control.selector.server.control.SelectorControl; 026import com.echothree.model.data.content.server.entity.ContentCategory; 027import com.echothree.model.data.user.server.entity.UserVisit; 028import com.echothree.util.common.form.TransferProperties; 029import com.echothree.util.server.transfer.ListWrapperBuilder; 030import javax.enterprise.context.RequestScoped; 031 032@RequestScoped 033public class ContentCategoryTransferCache 034 extends BaseContentTransferCache<ContentCategory, ContentCategoryTransfer> { 035 036 @Inject 037 ContentControl contentControl; 038 039 @Inject 040 OfferUseControl offerUseControl; 041 042 @Inject 043 SelectorControl selectorControl; 044 045 boolean includeContentCategoryItems; 046 047 TransferProperties transferProperties; 048 boolean filterContentCatalog; 049 boolean filterContentCategoryName; 050 boolean filterParentContentCategory; 051 boolean filterDefaultOfferUse; 052 boolean filterContentCategoryItemSelector; 053 boolean filterIsDefault; 054 boolean filterSortOrder; 055 boolean filterDescription; 056 boolean filterEntityInstance; 057 058 /** Creates a new instance of ContentCategoryTransferCache */ 059 protected ContentCategoryTransferCache() { 060 super(); 061 062 var options = session.getOptions(); 063 if(options != null) { 064 includeContentCategoryItems = options.contains(ContentOptions.ContentCategoryIncludeContentCategoryItems); 065 setIncludeUuid(options.contains(ContentOptions.ContentCategoryIncludeUuid)); 066 setIncludeEntityAttributeGroups(options.contains(ContentOptions.ContentCategoryIncludeEntityAttributeGroups)); 067 setIncludeTagScopes(options.contains(ContentOptions.ContentCategoryIncludeTagScopes)); 068 } 069 070 transferProperties = session.getTransferProperties(); 071 if(transferProperties != null) { 072 var properties = transferProperties.getProperties(ContentCategoryTransfer.class); 073 074 if(properties != null) { 075 filterContentCatalog = !properties.contains(ContentProperties.CONTENT_CATALOG); 076 filterContentCategoryName = !properties.contains(ContentProperties.CONTENT_CATEGORY_NAME); 077 filterParentContentCategory = !properties.contains(ContentProperties.PARENT_CONTENT_CATEGORY); 078 filterDefaultOfferUse = !properties.contains(ContentProperties.DEFAULT_OFFER_USE); 079 filterContentCategoryItemSelector = !properties.contains(ContentProperties.CONTENT_CATEGORY_ITEM_SELECTOR); 080 filterIsDefault = !properties.contains(ContentProperties.IS_DEFAULT); 081 filterSortOrder = !properties.contains(ContentProperties.SORT_ORDER); 082 filterDescription = !properties.contains(ContentProperties.DESCRIPTION); 083 filterEntityInstance = !properties.contains(ContentProperties.ENTITY_INSTANCE); 084 } 085 } 086 087 setIncludeEntityInstance(!filterEntityInstance); 088 } 089 090 public ContentCategoryTransfer getContentCategoryTransfer(UserVisit userVisit, ContentCategory contentCategory) { 091 var contentCategoryTransfer = get(contentCategory); 092 093 if(contentCategoryTransfer == null) { 094 var contentCategoryDetail = contentCategory.getLastDetail(); 095 var contentCatalogTransfer = filterContentCatalog ? null : contentControl.getContentCatalogTransfer(userVisit, contentCategoryDetail.getContentCatalog()); 096 var contentCategoryName = filterContentCategoryName ? null : contentCategoryDetail.getContentCategoryName(); 097 var parentContentCategory = filterParentContentCategory ? null : contentCategoryDetail.getParentContentCategory(); 098 var parentContentCategoryTransfer = parentContentCategory == null ? null : contentControl.getContentCategoryTransfer(userVisit, parentContentCategory); 099 var defaultOfferUse = filterDefaultOfferUse ? null : contentCategoryDetail.getDefaultOfferUse(); 100 var defaultOfferUseTransfer = defaultOfferUse == null ? null : offerUseControl.getOfferUseTransfer(userVisit, defaultOfferUse); 101 var contentCategoryItemSelector = filterContentCategoryItemSelector ? null : contentCategoryDetail.getContentCategoryItemSelector(); 102 var contentCategoryItemSelectorTransfer = contentCategoryItemSelector == null ? null : selectorControl.getSelectorTransfer(userVisit, contentCategoryItemSelector); 103 var isDefault = filterIsDefault ? null : contentCategoryDetail.getIsDefault(); 104 var sortOrder = filterSortOrder ? null : contentCategoryDetail.getSortOrder(); 105 var description = filterDescription ? null : contentControl.getBestContentCategoryDescription(contentCategory, getLanguage(userVisit)); 106 107 contentCategoryTransfer = new ContentCategoryTransfer(contentCatalogTransfer, contentCategoryName, parentContentCategoryTransfer, 108 defaultOfferUseTransfer, contentCategoryItemSelectorTransfer, isDefault, sortOrder, description); 109 put(userVisit, contentCategory, contentCategoryTransfer); 110 111 if(includeContentCategoryItems) { 112 contentCategoryTransfer.setContentCategoryItems(ListWrapperBuilder.getInstance().filter(transferProperties, contentControl.getContentCategoryItemTransfersByContentCategory(userVisit, contentCategoryDetail.getContentCategory()))); 113 } 114 } 115 116 return contentCategoryTransfer; 117 } 118 119}