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 ModelItemTypeExtensionPoint _modelItemTypeEP; 070 private SubscriptionTypeExtensionPoint _subscriptionTypeEP; 071 072 @Override 073 public void service(ServiceManager serviceManager) throws ServiceException 074 { 075 super.service(serviceManager); 076 _modelItemTypeEP = (ModelItemTypeExtensionPoint) serviceManager.lookup(MODEL_ITEM_TYPE_EXTENSION_ROLE); 077 _subscriptionTypeEP = (SubscriptionTypeExtensionPoint) serviceManager.lookup(SubscriptionTypeExtensionPoint.ROLE); 078 } 079 080 @Override 081 public Subscription getAmetysObject(Node node, String parentPath) throws AmetysRepositoryException, RepositoryException 082 { 083 return new Subscription(node, parentPath, this); 084 } 085 086 /** 087 * Retrieves the extension point with available modelItem types for {@link Subscription} 088 * @return the extension point with available modelItem types for {@link Subscription} 089 */ 090 public ModelItemTypeExtensionPoint getElementTypesExtensionPoint() 091 { 092 return _modelItemTypeEP; 093 } 094 095 /** 096 * Retrieve an {@link SubscriptionType} 097 * @param subscriptionTypeId the type id 098 * @return the subscription type 099 */ 100 public SubscriptionType getSubscriptionType(String subscriptionTypeId) 101 { 102 return _subscriptionTypeEP.getExtension(subscriptionTypeId); 103 } 104}