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.transfer.ContentCollectionTransfer;
021import com.echothree.model.control.content.common.transfer.ContentWebAddressTransfer;
022import com.echothree.model.control.content.server.control.ContentControl;
023import com.echothree.model.data.content.server.entity.ContentWebAddress;
024import com.echothree.model.data.content.server.entity.ContentWebAddressDetail;
025import com.echothree.model.data.user.server.entity.UserVisit;
026import java.util.Set;
027
028public class ContentWebAddressTransferCache
029        extends BaseContentTransferCache<ContentWebAddress, ContentWebAddressTransfer> {
030    
031    /** Creates a new instance of ContentWebAddressTransferCache */
032    public ContentWebAddressTransferCache(UserVisit userVisit, ContentControl contentControl) {
033        super(userVisit, contentControl);
034        
035        var options = session.getOptions();
036        if(options != null) {
037            setIncludeKey(options.contains(ContentOptions.ContentWebAddressIncludeKey));
038            setIncludeGuid(options.contains(ContentOptions.ContentWebAddressIncludeGuid));
039            setIncludeEntityAttributeGroups(options.contains(ContentOptions.ContentWebAddressIncludeEntityAttributeGroups));
040            setIncludeTagScopes(options.contains(ContentOptions.ContentWebAddressIncludeTagScopes));
041        }
042        
043        setIncludeEntityInstance(true);
044    }
045    
046    public ContentWebAddressTransfer getContentWebAddressTransfer(ContentWebAddress contentWebAddress) {
047        ContentWebAddressTransfer contentWebAddressTransfer = get(contentWebAddress);
048        
049        if(contentWebAddressTransfer == null) {
050            ContentWebAddressDetail contentWebAddressDetail = contentWebAddress.getLastDetail();
051            String contentWebAddressName = contentWebAddressDetail.getContentWebAddressName();
052            ContentCollectionTransfer contentCollectionTransfer = contentControl.getContentCollectionTransfer(userVisit, contentWebAddressDetail.getContentCollection());
053            String description = contentControl.getBestContentWebAddressDescription(contentWebAddress, getLanguage());
054            
055            contentWebAddressTransfer = new ContentWebAddressTransfer(contentWebAddressName, contentCollectionTransfer, description);
056            put(contentWebAddress, contentWebAddressTransfer);
057        }
058        
059        return contentWebAddressTransfer;
060    }
061    
062}