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.ContentProperties;
021import com.echothree.model.control.content.common.transfer.ContentCategoryItemTransfer;
022import com.echothree.model.control.content.server.control.ContentControl;
023import com.echothree.model.data.content.server.entity.ContentCategoryItem;
024import com.echothree.model.data.user.server.entity.UserVisit;
025import com.echothree.util.common.form.TransferProperties;
026import javax.enterprise.context.RequestScoped;
027
028@RequestScoped
029public class ContentCategoryItemTransferCache
030        extends BaseContentTransferCache<ContentCategoryItem, ContentCategoryItemTransfer> {
031
032    @Inject
033    ContentControl contentControl;
034
035    TransferProperties transferProperties;
036    boolean filterContentCategory;
037    boolean filterContentCatalogItem;
038    boolean filterIsDefault;
039    boolean filterSortOrder;
040
041    /** Creates a new instance of ContentCategoryItemTransferCache */
042    protected ContentCategoryItemTransferCache() {
043        super();
044        
045        transferProperties = session.getTransferProperties();
046        if(transferProperties != null) {
047            var properties = transferProperties.getProperties(ContentCategoryItemTransfer.class);
048            
049            if(properties != null) {
050                filterContentCategory = !properties.contains(ContentProperties.CONTENT_CATEGORY);
051                filterContentCatalogItem = !properties.contains(ContentProperties.CONTENT_CATALOG_ITEM);
052                filterIsDefault = !properties.contains(ContentProperties.IS_DEFAULT);
053                filterSortOrder = !properties.contains(ContentProperties.SORT_ORDER);
054            }
055        }
056    }
057    
058    public ContentCategoryItemTransfer getContentCategoryItemTransfer(UserVisit userVisit, ContentCategoryItem contentCategoryItem) {
059        var contentCategoryItemTransfer = get(contentCategoryItem);
060        
061        if(contentCategoryItemTransfer == null) {
062            var contentCategory = filterContentCategory ? null : contentControl.getContentCategoryTransfer(userVisit, contentCategoryItem.getContentCategory());
063            var contentCatalogItem = filterContentCatalogItem ? null : contentControl.getContentCatalogItemTransfer(userVisit, contentCategoryItem.getContentCatalogItem());
064            var isDefault = filterIsDefault ? null : contentCategoryItem.getIsDefault();
065            var sortOrder = filterSortOrder ? null : contentCategoryItem.getSortOrder();
066            
067            contentCategoryItemTransfer = new ContentCategoryItemTransfer(contentCategory, contentCatalogItem, isDefault, sortOrder);
068            put(userVisit, contentCategoryItem, contentCategoryItemTransfer);
069        }
070        
071        return contentCategoryItemTransfer;
072    }
073
074}