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.core.server.transfer;
018
019import javax.inject.Inject;
020import com.echothree.model.control.core.common.CoreProperties;
021import com.echothree.model.control.core.common.transfer.CacheEntryDependencyTransfer;
022import com.echothree.model.control.core.server.control.CacheEntryControl;
023import com.echothree.model.data.core.server.entity.CacheEntryDependency;
024import com.echothree.model.data.user.server.entity.UserVisit;
025import com.echothree.util.common.form.TransferProperties;
026import javax.enterprise.context.RequestScoped;
027
028@RequestScoped
029public class CacheEntryDependencyTransferCache
030        extends BaseCoreTransferCache<CacheEntryDependency, CacheEntryDependencyTransfer> {
031
032    @Inject
033    CacheEntryControl cacheEntryControl;
034
035    TransferProperties transferProperties;
036    boolean filterCacheEntry;
037    boolean filterEntityInstance;
038    
039    /** Creates a new instance of CacheEntryTransferCache */
040    protected CacheEntryDependencyTransferCache() {
041        super();
042        
043        transferProperties = session.getTransferProperties();
044        if(transferProperties != null) {
045            var properties = transferProperties.getProperties(CacheEntryDependencyTransfer.class);
046            
047            if(properties != null) {
048                filterCacheEntry = !properties.contains(CoreProperties.CACHE_ENTRY);
049                filterEntityInstance = !properties.contains(CoreProperties.ENTITY_INSTANCE);
050            }
051        }
052    }
053    
054    public CacheEntryDependencyTransfer getCacheEntryDependencyTransfer(UserVisit userVisit, CacheEntryDependency cacheEntryDependency) {
055        var cacheEntryDependencyTransfer = get(cacheEntryDependency);
056        
057        if(cacheEntryDependencyTransfer == null) {
058            var cacheEntry = filterCacheEntry ? null : cacheEntryControl.getCacheEntryTransfer(userVisit, cacheEntryDependency.getCacheEntry());
059            var entityInstance = filterEntityInstance ? null : entityInstanceControl.getEntityInstanceTransfer(userVisit, cacheEntryDependency.getEntityInstance(), false, false, false, false);
060
061            cacheEntryDependencyTransfer = new CacheEntryDependencyTransfer(cacheEntry, entityInstance);
062            put(userVisit, cacheEntryDependency, cacheEntryDependencyTransfer);
063        }
064        
065        return cacheEntryDependencyTransfer;
066    }
067    
068}