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.util.server.control; 018 019import com.echothree.model.control.core.common.EventTypes; 020import com.echothree.model.control.core.server.control.EntityInstanceControl; 021import com.echothree.model.control.core.server.control.EventControl; 022import com.echothree.model.control.party.server.control.PartyControl; 023import com.echothree.model.control.workflow.server.control.WorkflowControl; 024import com.echothree.model.data.core.server.entity.EntityInstance; 025import com.echothree.model.data.core.server.entity.Event; 026import com.echothree.util.common.persistence.BasePK; 027import com.echothree.util.server.persistence.BaseEntity; 028import com.echothree.util.server.persistence.Session; 029import java.sql.Connection; 030import javax.annotation.PostConstruct; 031import javax.inject.Inject; 032import org.slf4j.Logger; 033import org.slf4j.LoggerFactory; 034 035public abstract class BaseModelControl { 036 037 @Inject 038 protected Session session; 039 040 @Inject 041 protected EntityInstanceControl entityInstanceControl; 042 043 @Inject 044 protected EventControl eventControl; 045 046 @Inject 047 protected PartyControl partyControl; 048 049 @Inject 050 protected WorkflowControl workflowControl; 051 052 protected final Logger log = LoggerFactory.getLogger(this.getClass()); 053 054 /** Creates a new instance of BaseModelControl */ 055 protected BaseModelControl() { 056 } 057 058 @PostConstruct 059 public void init() { 060 } 061 062 // -------------------------------------------------------------------------------- 063 // Utilities 064 // -------------------------------------------------------------------------------- 065 066 protected EntityInstance getEntityInstanceByBasePK(final BasePK pk) { 067 return entityInstanceControl.getEntityInstanceByBasePK(pk); 068 } 069 070 protected EntityInstance getEntityInstanceByBaseEntity(final BaseEntity baseEntity) { 071 return getEntityInstanceByBasePK(baseEntity.getPrimaryKey()); 072 } 073 074 protected Event sendEvent(final BasePK basePK, final EventTypes eventType, final BasePK relatedBasePK, 075 final EventTypes relatedEventType, final BasePK createdByBasePK) { 076 return eventControl.sendEvent(basePK, eventType, relatedBasePK, relatedEventType, createdByBasePK); 077 } 078 079 protected Event sendEvent(final EntityInstance entityInstance, final EventTypes eventType, final BasePK relatedBasePK, 080 final EventTypes relatedEventType, final BasePK createdByBasePK) { 081 return eventControl.sendEvent(entityInstance, eventType, relatedBasePK, relatedEventType, createdByBasePK); 082 } 083 084 public Event sendEvent(final EntityInstance entityInstance, final EventTypes eventType, final EntityInstance relatedEntityInstance, 085 final EventTypes relatedEventType, final BasePK createdByBasePK) { 086 return eventControl.sendEvent(entityInstance, eventType, relatedEntityInstance, relatedEventType, createdByBasePK); 087 } 088 089}