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