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.period.server.logic; 018 019import com.echothree.model.control.core.server.control.EntityInstanceControl; 020import com.echothree.model.control.period.server.control.PeriodControl; 021import com.echothree.model.control.workflow.server.control.WorkflowControl; 022import com.echothree.model.data.party.common.pk.PartyPK; 023import com.echothree.model.data.period.server.entity.Period; 024import com.echothree.model.data.period.server.entity.PeriodKind; 025import com.echothree.model.data.period.server.entity.PeriodType; 026import javax.enterprise.context.ApplicationScoped; 027import javax.enterprise.inject.spi.CDI; 028import javax.inject.Inject; 029 030@ApplicationScoped 031public class PeriodLogic { 032 033 @Inject 034 EntityInstanceControl entityInstanceControl; 035 036 @Inject 037 PeriodControl periodControl; 038 039 @Inject 040 WorkflowControl workflowControl; 041 042 protected PeriodLogic() { 043 super(); 044 } 045 046 public static PeriodLogic getInstance() { 047 return CDI.current().select(PeriodLogic.class).get(); 048 } 049 050 public Period createPeriod(final PeriodKind periodKind, final String periodName, final Period parentPeriod, 051 final PeriodType periodType, final Long startTime, final Long endTime, final PartyPK createdBy) { 052 var period = periodControl.createPeriod(periodKind, periodName, parentPeriod, periodType, startTime, endTime, createdBy); 053 var periodTypeDetail = periodType.getLastDetail(); 054 var workflowEntrance = periodTypeDetail.getWorkflowEntrance(); 055 056 if(workflowEntrance == null) { 057 workflowEntrance = periodTypeDetail.getPeriodKind().getLastDetail().getWorkflowEntrance(); 058 } 059 060 if(workflowEntrance != null) { 061 var entityInstance = entityInstanceControl.getEntityInstanceByBasePK(period.getPrimaryKey()); 062 063 workflowControl.addEntityToWorkflow(workflowEntrance, entityInstance, null, null, createdBy); 064 } 065 066 return period; 067 } 068 069}