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.apache.commons.logging.Log; 033import org.apache.commons.logging.LogFactory; 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 private Log log; 053 054 /** Creates a new instance of BaseModelControl */ 055 protected BaseModelControl() { 056 } 057 058 @PostConstruct 059 public void init() { 060 } 061 062 protected Log getLog() { 063 if(log == null) { 064 log = LogFactory.getLog(this.getClass()); 065 } 066 067 return log; 068 } 069 070 // -------------------------------------------------------------------------------- 071 // Utilities 072 // -------------------------------------------------------------------------------- 073 074 protected EntityInstance getEntityInstanceByBasePK(final BasePK pk) { 075 return entityInstanceControl.getEntityInstanceByBasePK(pk); 076 } 077 078 protected EntityInstance getEntityInstanceByBaseEntity(final BaseEntity baseEntity) { 079 return getEntityInstanceByBasePK(baseEntity.getPrimaryKey()); 080 } 081 082 protected Event sendEvent(final BasePK basePK, final EventTypes eventType, final BasePK relatedBasePK, 083 final EventTypes relatedEventType, final BasePK createdByBasePK) { 084 return eventControl.sendEvent(basePK, eventType, relatedBasePK, relatedEventType, createdByBasePK); 085 } 086 087 protected Event sendEvent(final EntityInstance entityInstance, final EventTypes eventType, final BasePK relatedBasePK, 088 final EventTypes relatedEventType, final BasePK createdByBasePK) { 089 return eventControl.sendEvent(entityInstance, eventType, relatedBasePK, relatedEventType, createdByBasePK); 090 } 091 092 public Event sendEvent(final EntityInstance entityInstance, final EventTypes eventType, final EntityInstance relatedEntityInstance, 093 final EventTypes relatedEventType, final BasePK createdByBasePK) { 094 return eventControl.sendEvent(entityInstance, eventType, relatedEntityInstance, relatedEventType, createdByBasePK); 095 } 096 097}