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.core.server.transfer; 018 019import com.echothree.model.control.core.common.CoreProperties; 020import com.echothree.model.control.core.common.transfer.CacheEntryDependencyTransfer; 021import com.echothree.model.control.core.common.transfer.CacheEntryTransfer; 022import com.echothree.model.control.core.common.transfer.EntityInstanceTransfer; 023import com.echothree.model.control.core.server.control.CoreControl; 024import com.echothree.model.data.core.server.entity.CacheEntryDependency; 025import com.echothree.model.data.user.server.entity.UserVisit; 026import com.echothree.util.common.form.TransferProperties; 027import com.echothree.util.server.persistence.Session; 028import java.util.Set; 029 030public class CacheEntryDependencyTransferCache 031 extends BaseCoreTransferCache<CacheEntryDependency, CacheEntryDependencyTransfer> { 032 033 CoreControl coreControl = Session.getModelController(CoreControl.class); 034 035 TransferProperties transferProperties; 036 boolean filterCacheEntry; 037 boolean filterEntityInstance; 038 039 /** Creates a new instance of CacheEntryTransferCache */ 040 public CacheEntryDependencyTransferCache(UserVisit userVisit) { 041 super(userVisit); 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(CacheEntryDependency cacheEntryDependency) { 055 CacheEntryDependencyTransfer cacheEntryDependencyTransfer = get(cacheEntryDependency); 056 057 if(cacheEntryDependencyTransfer == null) { 058 CacheEntryTransfer cacheEntry = filterCacheEntry ? null : coreControl.getCacheEntryTransfer(userVisit, cacheEntryDependency.getCacheEntry()); 059 EntityInstanceTransfer entityInstance = filterEntityInstance ? null : coreControl.getEntityInstanceTransfer(userVisit, cacheEntryDependency.getEntityInstance(), false, false, false, false, false, false); 060 061 cacheEntryDependencyTransfer = new CacheEntryDependencyTransfer(cacheEntry, entityInstance); 062 put(cacheEntryDependency, cacheEntryDependencyTransfer); 063 } 064 065 return cacheEntryDependencyTransfer; 066 } 067 068}