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.eventbus; 018 019import com.echothree.model.control.content.server.control.ContentControl; 020import com.echothree.model.control.core.common.EventTypes; 021import com.echothree.model.control.core.server.control.CoreControl; 022import com.echothree.model.control.core.server.eventbus.BaseEventSubscriber; 023import com.echothree.model.control.core.server.eventbus.Function5Arity; 024import com.echothree.model.control.core.server.eventbus.SentEvent; 025import com.echothree.model.control.core.server.eventbus.SentEventSubscriber; 026import com.echothree.model.data.content.common.ContentCatalogConstants; 027import com.echothree.model.data.core.server.entity.EntityInstance; 028import com.echothree.model.data.core.server.entity.Event; 029import com.echothree.util.server.persistence.PersistenceUtils; 030import com.echothree.util.server.persistence.Session; 031import com.google.common.eventbus.Subscribe; 032 033@SentEventSubscriber 034public class ContentCatalogModificationSubscriber 035 extends BaseEventSubscriber { 036 037 @Subscribe 038 public void receiveSentEvent(SentEvent se) { 039 decodeEventAndApply(se, touchContentCategoriesIfContentCatalog); 040 } 041 042 private static final Function5Arity<Event, EntityInstance, EventTypes, String, String> 043 touchContentCategoriesIfContentCatalog = (event, entityInstance, eventType, componentVendorName, entityTypeName) -> { 044 if(ContentCatalogConstants.COMPONENT_VENDOR_NAME.equals(componentVendorName) 045 && ContentCatalogConstants.ENTITY_TYPE_NAME.equals(entityTypeName) 046 && (eventType == EventTypes.MODIFY || eventType == EventTypes.TOUCH)) { 047 var coreControl = Session.getModelController(CoreControl.class); 048 var contentControl = Session.getModelController(ContentControl.class); 049 var contentCatalog = contentControl.getContentCatalogByEntityInstance(entityInstance); 050 var contentCategories = contentControl.getContentCategories(contentCatalog); 051 052 for(var contentCategory : contentCategories) { 053 coreControl.sendEvent(contentCategory.getPrimaryKey(), EventTypes.TOUCH, 054 contentCatalog.getPrimaryKey(), eventType, 055 PersistenceUtils.getInstance().getBasePKFromEntityInstance(event.getCreatedBy())); 056 } 057 } 058 }; 059 060}