View Javadoc
1   /*
2    * Copyright (c) 2002-2023, City of Paris
3    * All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions
7    * are met:
8    *
9    *  1. Redistributions of source code must retain the above copyright notice
10   *     and the following disclaimer.
11   *
12   *  2. Redistributions in binary form must reproduce the above copyright notice
13   *     and the following disclaimer in the documentation and/or other materials
14   *     provided with the distribution.
15   *
16   *  3. Neither the name of 'Mairie de Paris' nor 'Lutece' nor the names of its
17   *     contributors may be used to endorse or promote products derived from
18   *     this software without specific prior written permission.
19   *
20   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23   * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
24   * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27   * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30   * POSSIBILITY OF SUCH DAMAGE.
31   *
32   * License 1.0
33   */
34  package fr.paris.lutece.plugins.broadcastproxy.service;
35  
36  import java.util.List;
37  import java.util.Map;
38  
39  import org.json.simple.JSONObject;
40  
41  import fr.paris.lutece.plugins.broadcastproxy.business.Feed;
42  import fr.paris.lutece.plugins.broadcastproxy.business.IBroadcastProvider;
43  import fr.paris.lutece.plugins.broadcastproxy.business.Subscription;
44  import fr.paris.lutece.portal.service.init.LuteceInitException;
45  import fr.paris.lutece.portal.service.spring.SpringContextService;
46  import fr.paris.lutece.portal.service.util.AppLogService;
47  
48  public class BroadcastService
49  {
50  
51      private static final String BEAN_BROADCAST_PROVIDER = "broadcastproxy.provider";
52  
53      private static IBroadcastProvider _broadcastProvider;
54      private static BroadcastService _instance;
55  
56      /**
57       * Private constructor
58       */
59      private BroadcastService( )
60      {
61      }
62  
63      /**
64       * get provider name
65       * 
66       * @return the name of the provider
67       */
68      public String getName( )
69      {
70          return _broadcastProvider.getName( );
71      }
72  
73      /**
74       * Get the unique instance of the Security Service
75       *
76       * @return The instance
77       */
78      public static synchronized BroadcastService getInstance( )
79      {
80          if ( _instance == null )
81          {
82              _instance = new BroadcastService( );
83              _instance.init( );
84          }
85  
86          return _instance;
87      }
88  
89      /**
90       * Initialize service
91       *
92       * @throws LuteceInitException
93       *             If error while initialization
94       */
95      private synchronized void init( )
96      {
97          if ( _broadcastProvider == null )
98          {
99              _broadcastProvider = (IBroadcastProvider) SpringContextService.getBean( BEAN_BROADCAST_PROVIDER );
100             AppLogService.info( "BroadcastProvider loaded : " + _broadcastProvider.getName( ) );
101         }
102     }
103 
104     /**
105      * update user subscriptions to the specified subscription list
106      * 
107      * @param subscriptionsList
108      * @return true if success
109      * @throws Exception
110      */
111     public boolean updateSubscribtions( String userId, List<Subscription> subscriptionsList ) throws Exception
112     {
113         return _broadcastProvider.updateSubscribtions( userId, subscriptionsList );
114     }
115 
116     /**
117      * update user subscriptions to the specified subscription list
118      * 
119      * @param subscriptionsList
120      * @param strAccountId
121      * @return true if success
122      * @throws Exception
123      */
124     public boolean updateSubscribtions( String userId, String jsonSubscriptions, String strAccountId ) throws Exception
125     {
126         return _broadcastProvider.updateSubscribtions( userId, jsonSubscriptions, strAccountId );
127     }
128     
129     /**
130      * update user subscriptions to the specified subscription list
131      * 
132      * @param subscriptionsList
133      * @param strAccountId
134      * @return true if success
135      * @throws Exception
136      */
137     public boolean updateArrondissementSubscribtions( String userId, String jsonSubscriptions, String strAccountId ) throws Exception
138     {
139         return _broadcastProvider.updateArrondissementSubscribtions( userId, jsonSubscriptions, strAccountId );
140     }
141 
142     /**
143      * updates a Subscription bean
144      * 
145      * @param sub
146      * @param strAccountId
147      * @return the map
148      * @throws java.lang.Exception
149      */
150     public boolean update( Subscription sub, String strAccountId ) throws Exception
151     {
152         return _broadcastProvider.update( sub, strAccountId );
153     }
154 
155     /**
156      * get the list of available feeds
157      * 
158      * @return the list
159      */
160     public List<Feed> getFeeds( )
161     {
162         return _broadcastProvider.getFeeds( );
163     }
164 
165     /**
166      * get all subscription by group
167      * @param typeSubscription
168      * @param strAccountId
169      * @return
170      */
171     public String getAllSubscriptionByGroup( String typeSubscription, String strAccountId )
172     {
173         return _broadcastProvider.getAllSubscriptionByGroup( typeSubscription, strAccountId );
174     }
175     
176     /**
177      * 
178      * @param userId
179      * @param strAccountId
180      * @return
181      * @throws Exception 
182      */
183     public List<JSONObject> getUserSubscriptionIds( String strUserId, String strAccountId )
184     {
185         return _broadcastProvider.getUserSubscriptionIds( strUserId, strAccountId );
186     }
187 }