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.ContentOptions;
021import com.echothree.model.control.content.common.transfer.ContentCollectionTransfer;
022import com.echothree.model.control.content.server.control.ContentControl;
023import com.echothree.model.control.offer.server.control.OfferUseControl;
024import com.echothree.model.data.content.server.entity.ContentCollection;
025import com.echothree.model.data.user.server.entity.UserVisit;
026import com.echothree.util.common.transfer.ListWrapper;
027import javax.enterprise.context.RequestScoped;
028
029@RequestScoped
030public class ContentCollectionTransferCache
031        extends BaseContentTransferCache<ContentCollection, ContentCollectionTransfer> {
032
033    @Inject
034    ContentControl contentControl;
035
036    @Inject
037    OfferUseControl offerUseControl;
038
039    boolean includeContentCatalogs;
040    boolean includeContentForums;
041    boolean includeContentSections;
042
043    /** Creates a new instance of ContentCollectionTransferCache */
044    protected ContentCollectionTransferCache() {
045        super();
046
047        var options = session.getOptions();
048        if(options != null) {
049            includeContentCatalogs = options.contains(ContentOptions.ContentCollectionIncludeContentCatalogs);
050            includeContentForums = options.contains(ContentOptions.ContentCollectionIncludeContentForums);
051            includeContentSections = options.contains(ContentOptions.ContentCollectionIncludeContentSections);
052            setIncludeUuid(options.contains(ContentOptions.ContentCollectionIncludeUuid));
053            setIncludeEntityAttributeGroups(options.contains(ContentOptions.ContentCollectionIncludeEntityAttributeGroups));
054            setIncludeTagScopes(options.contains(ContentOptions.ContentCollectionIncludeTagScopes));
055        }
056        
057        setIncludeEntityInstance(true);
058    }
059
060    public ContentCollectionTransfer getContentCollectionTransfer(UserVisit userVisit, ContentCollection contentCollection) {
061        var contentCollectionTransfer = get(contentCollection);
062        
063        if(contentCollectionTransfer == null) {
064            var contentCollectionDetail = contentCollection.getLastDetail();
065            var contentCollectionName = contentCollectionDetail.getContentCollectionName();
066            var defaultOfferUse = offerUseControl.getOfferUseTransfer(userVisit, contentCollectionDetail.getDefaultOfferUse());
067            var description = contentControl.getBestContentCollectionDescription(contentCollection, getLanguage(userVisit));
068            
069            contentCollectionTransfer = new ContentCollectionTransfer(contentCollectionName, defaultOfferUse, description);
070            put(userVisit, contentCollection, contentCollectionTransfer);
071            
072            if(includeContentCatalogs) {
073                contentCollectionTransfer.setContentCatalogs(new ListWrapper<>(contentControl.getContentCatalogTransfers(userVisit, contentCollection)));
074            }
075
076            if(includeContentForums) {
077                contentCollectionTransfer.setContentForums(new ListWrapper<>(contentControl.getContentForumTransfers(userVisit, contentCollection)));
078            }
079
080            if(includeContentSections) {
081                contentCollectionTransfer.setContentSections(new ListWrapper<>(contentControl.getContentSectionTransfers(userVisit, contentCollection)));
082            }
083        }
084        
085        return contentCollectionTransfer;
086    }
087    
088}