001/*
002 *  Copyright 2024 Anyware Services
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 */
016package org.ametys.plugins.pagesubscription;
017
018import javax.jcr.Node;
019import javax.jcr.RepositoryException;
020
021import org.apache.avalon.framework.service.ServiceException;
022import org.apache.avalon.framework.service.ServiceManager;
023
024import org.ametys.plugins.pagesubscription.type.SubscriptionType;
025import org.ametys.plugins.pagesubscription.type.SubscriptionTypeExtensionPoint;
026import org.ametys.plugins.repository.AmetysRepositoryException;
027import org.ametys.plugins.repository.RepositoryConstants;
028import org.ametys.plugins.repository.jcr.SimpleAmetysObjectFactory;
029import org.ametys.web.data.type.ModelItemTypeExtensionPoint;
030
031/**
032 * AmetysObject factory associated with {@link Subscription}
033 */
034public class SubscriptionFactory extends SimpleAmetysObjectFactory
035{
036    /** Avalon Role for subscription data types */
037    public static final String MODEL_ITEM_TYPE_EXTENSION_ROLE = ModelItemTypeExtensionPoint.class.getName() + ".Subscription";
038    
039    /** Subscription node type name. */
040    public static final String NODE_TYPE = RepositoryConstants.NAMESPACE_PREFIX + ":subscription";
041    
042    /** Data name for the subscription type id */
043    public static final String SUBSCRIPTION_TYPE_ID = "typeId";
044    
045    /** Data name for the subscriber */
046    public static final String SUBSCRIBER = "subscriber";
047
048    /** Data name for the subscribers group */
049    public static final String SUBSCRIBERS_GROUP = "group";
050
051    /** Data name for the date of the subscription */
052    public static final String DATE = "date";
053
054    /** Data name for the frequency of the subscription */
055    public static final String FREQUENCY = "frequency";
056
057    /** Data name for the broadcast channel of the subscription */
058    public static final String BROADCAST_CHANNEL = "broadcastChannel";
059    
060    /** Data name to determine if the subscription is forced or not */
061    public static final String IS_FORCED = "isForced";
062    
063    /** Data name for the day of the subscription if it's forced */
064    public static final String FORCED_DAY = "forcedDay";
065    
066    /** Data name for the hour of the subscription if it's forced */
067    public static final String FORCED_HOUR = "forcedHour";
068    
069    private SubscriptionTypeExtensionPoint _subscriptionTypeEP;
070
071    @Override
072    public void service(ServiceManager serviceManager) throws ServiceException
073    {
074        super.service(serviceManager);
075        _subscriptionTypeEP = (SubscriptionTypeExtensionPoint) serviceManager.lookup(SubscriptionTypeExtensionPoint.ROLE);
076    }
077    
078    @Override
079    public Subscription getAmetysObject(Node node, String parentPath) throws AmetysRepositoryException, RepositoryException
080    {
081        return new Subscription(node, parentPath, this);
082    }
083    
084    @Override
085    protected String getModelItemTypeExtensionPointId()
086    {
087        return MODEL_ITEM_TYPE_EXTENSION_ROLE;
088    }
089
090    /**
091     * Retrieve an {@link SubscriptionType}
092     * @param subscriptionTypeId the type id
093     * @return the subscription type
094     */
095    public SubscriptionType getSubscriptionType(String subscriptionTypeId)
096    {
097        return _subscriptionTypeEP.getExtension(subscriptionTypeId);
098    }
099}