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.subscription.server.logic; 018 019import com.echothree.model.control.subscription.server.control.SubscriptionControl; 020import com.echothree.model.data.party.server.entity.Party; 021import com.echothree.model.data.subscription.server.entity.Subscription; 022import com.echothree.model.data.subscription.server.entity.SubscriptionType; 023import com.echothree.util.common.persistence.BasePK; 024import com.echothree.util.server.message.ExecutionErrorAccumulator; 025import com.echothree.util.server.persistence.Session; 026 027public class SubscriptionLogic { 028 029 private SubscriptionLogic() { 030 super(); 031 } 032 033 private static class SubscriptionLogicHolder { 034 static SubscriptionLogic instance = new SubscriptionLogic(); 035 } 036 037 public static SubscriptionLogic getInstance() { 038 return SubscriptionLogicHolder.instance; 039 } 040 041 public Subscription createSubscription(final ExecutionErrorAccumulator eea, final Session session, final SubscriptionType subscriptionType, final Party party, 042 final Long endTime, final BasePK createdBy) { 043 var subscriptionControl = Session.getModelController(SubscriptionControl.class); 044 Subscription subscription = subscriptionControl.createSubscription(subscriptionType, party, session.START_TIME_LONG, endTime, createdBy); 045 046 SubscriptionChainLogic.getInstance().createSubscriptionInitialChainInstance(eea, subscription, createdBy); 047 048 return subscription; 049 } 050 051}