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