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