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.ContentOptions; 020import com.echothree.model.control.content.common.ContentProperties; 021import com.echothree.model.control.content.common.transfer.ContentCollectionTransfer; 022import com.echothree.model.control.content.common.transfer.ContentSectionTransfer; 023import com.echothree.model.control.content.server.control.ContentControl; 024import com.echothree.model.data.content.server.entity.ContentSection; 025import com.echothree.model.data.content.server.entity.ContentSectionDetail; 026import com.echothree.model.data.user.server.entity.UserVisit; 027import com.echothree.util.common.form.TransferProperties; 028import com.echothree.util.server.transfer.ListWrapperBuilder; 029import java.util.Set; 030 031public class ContentSectionTransferCache 032 extends BaseContentTransferCache<ContentSection, ContentSectionTransfer> { 033 034 boolean includeContentPages; 035 036 TransferProperties transferProperties; 037 boolean filterContentCollection; 038 boolean filterContentSectionName; 039 boolean filterParentContentSection; 040 boolean filterIsDefault; 041 boolean filterSortOrder; 042 boolean filterDescription; 043 boolean filterEntityInstance; 044 045 /** Creates a new instance of ContentSectionTransferCache */ 046 public ContentSectionTransferCache(UserVisit userVisit, ContentControl contentControl) { 047 super(userVisit, contentControl); 048 049 var options = session.getOptions(); 050 if(options != null) { 051 includeContentPages = options.contains(ContentOptions.ContentSectionIncludeContentPages); 052 setIncludeKey(options.contains(ContentOptions.ContentSectionIncludeKey)); 053 setIncludeGuid(options.contains(ContentOptions.ContentSectionIncludeGuid)); 054 setIncludeEntityAttributeGroups(options.contains(ContentOptions.ContentSectionIncludeEntityAttributeGroups)); 055 setIncludeTagScopes(options.contains(ContentOptions.ContentSectionIncludeTagScopes)); 056 } 057 058 transferProperties = session.getTransferProperties(); 059 if(transferProperties != null) { 060 var properties = transferProperties.getProperties(ContentSectionTransfer.class); 061 062 if(properties != null) { 063 filterContentCollection = !properties.contains(ContentProperties.CONTENT_COLLECTION); 064 filterContentSectionName = !properties.contains(ContentProperties.CONTENT_SECTION_NAME); 065 filterParentContentSection = !properties.contains(ContentProperties.PARENT_CONTENT_SECTION); 066 filterIsDefault = !properties.contains(ContentProperties.IS_DEFAULT); 067 filterSortOrder = !properties.contains(ContentProperties.SORT_ORDER); 068 filterDescription = !properties.contains(ContentProperties.DESCRIPTION); 069 filterEntityInstance = !properties.contains(ContentProperties.ENTITY_INSTANCE); 070 } 071 } 072 073 setIncludeEntityInstance(!filterEntityInstance); 074 } 075 076 public ContentSectionTransfer getContentSectionTransfer(ContentSection contentSection) { 077 ContentSectionTransfer contentSectionTransfer = get(contentSection); 078 079 if(contentSectionTransfer == null) { 080 ContentSectionDetail contentSectionDetail = contentSection.getLastDetail(); 081 ContentCollectionTransfer contentCollectionTransfer = filterContentCollection ? null : contentControl.getContentCollectionTransfer(userVisit, contentSectionDetail.getContentCollection()); 082 String contentSectionName = filterContentSectionName ? null : contentSectionDetail.getContentSectionName(); 083 ContentSection parentContentSection = filterParentContentSection ? null : contentSectionDetail.getParentContentSection(); 084 ContentSectionTransfer parentContentSectionTransfer = parentContentSection == null ? null : contentControl.getContentSectionTransfer(userVisit, parentContentSection); 085 Boolean isDefault = filterIsDefault ? null : contentSectionDetail.getIsDefault(); 086 Integer sortOrder = filterSortOrder ? null : contentSectionDetail.getSortOrder(); 087 String description = filterDescription ? null : contentControl.getBestContentSectionDescription(contentSection, getLanguage()); 088 089 contentSectionTransfer = new ContentSectionTransfer(contentCollectionTransfer, contentSectionName, parentContentSectionTransfer, isDefault, 090 sortOrder, description); 091 put(contentSection, contentSectionTransfer); 092 093 if(includeContentPages) { 094 contentSectionTransfer.setContentPages(ListWrapperBuilder.getInstance().filter(transferProperties, contentControl.getContentPageTransfers(userVisit, contentSectionDetail.getContentSection()))); 095 } 096 } 097 098 return contentSectionTransfer; 099 } 100 101}