001// --------------------------------------------------------------------------------
002// Copyright 2002-2025 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;
026import javax.enterprise.context.ApplicationScoped;
027import javax.enterprise.inject.spi.CDI;
028
029@ApplicationScoped
030public class SubscriptionLogic {
031
032    protected SubscriptionLogic() {
033        super();
034    }
035
036    public static SubscriptionLogic getInstance() {
037        return CDI.current().select(SubscriptionLogic.class).get();
038    }
039    
040    public Subscription createSubscription(final ExecutionErrorAccumulator eea, final Session session, final SubscriptionType subscriptionType, final Party party,
041            final Long endTime, final BasePK createdBy) {
042        var subscriptionControl = Session.getModelController(SubscriptionControl.class);
043        var subscription = subscriptionControl.createSubscription(subscriptionType, party, session.START_TIME_LONG, endTime, createdBy);
044
045        SubscriptionChainLogic.getInstance().createSubscriptionInitialChainInstance(eea, subscription, createdBy);
046        
047        return subscription;
048    }
049    
050}