View Javadoc
1   /*
2    * Copyright (c) 2002-2020, 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.business.providers.mock;
35  
36  import fr.paris.lutece.plugins.broadcastproxy.business.Feed;
37  import fr.paris.lutece.plugins.broadcastproxy.business.IBroadcastProvider;
38  import fr.paris.lutece.plugins.broadcastproxy.business.Subscription;
39  
40  import java.util.HashMap;
41  import java.util.Map;
42  
43  import java.util.ArrayList;
44  import java.util.List;
45  
46  public class MockProvider implements IBroadcastProvider
47  {
48  
49      private static final String DEFAULT_USER_SUBSCRIPTIONS_JSON = "{\"subscriptions\":[{\"name\":\"EXAMPLE_ONE\",\"active\":\"0\"},{\"name\":\"EXAMPLE_TWO\",\"active\":\"1\",\"data\":[\"data1\",\"date2\"]}]}";
50      private static final Map<String, String> DEFAULT_USER_SUBSCRIPTIONS_MAP = createDefaultMap( );
51  
52      /**
53       * initialize default map
54       * 
55       * @return the map
56       */
57      private static Map<String, String> createDefaultMap( )
58      {
59          Map<String, String> myMap = new HashMap<>( );
60          myMap.put( "1", "sub1" );
61          myMap.put( "2", "sub2" );
62          return myMap;
63      }
64  
65      @Override
66      public String getName( )
67      {
68          return "Mock";
69      }
70  
71      @Override
72      public String getUserSubscriptionsAsJson( String userId )
73      {
74          return DEFAULT_USER_SUBSCRIPTIONS_JSON;
75      }
76  
77      public boolean updateSubscribtions( List<Subscription> subscriptionsList )
78      {
79          return true;
80      }
81  
82      @Override
83      public boolean subscribe( String userId, String subscriptionId, String typeSubscription )
84      {
85          return true;
86      }
87  
88      @Override
89      public boolean unsubscribe( String userId, String subscriptionId, String typeSubscription )
90      {
91          return true;
92      }
93  
94      @Override
95      public Map<String, Map<String, List<Subscription>>> getUserSubscriptionsAsList( String userId ) throws Exception
96      {
97          Map<String, Map<String, List<Subscription>>> map = new HashMap<String, Map<String, List<Subscription>>>( );
98  
99          /*
100          * Subscription sub1 = new Subscription( ); sub1.setId( "EXAMPLE_ONE" ); sub1.setUserId( userId ); sub1.setActive( false ); sub1.setType(
101          * typeSubscription ); Map<String, String> mapDatas = new HashMap<>( ); mapDatas.put( "T1", "theme1" ); mapDatas.put( "T2", "theme2" ); sub1.setData(
102          * mapDatas );
103          * 
104          * Subscription sub2 = new Subscription( ); sub2.setId( "EXAMPLE_TWO" ); sub2.setUserId( userId ); sub2.setActive( true ); sub2.setType(
105          * typeSubscription ); List<String> data = new ArrayList<>( );
106          * 
107          * List<Subscription> list = new ArrayList<>( ); list.add( sub1 ); list.add( sub2 );
108          * 
109          * //map.put(null, list);
110          */
111         return map;
112 
113     }
114 
115     @Override
116     public boolean update( Subscription subscription ) throws Exception
117     {
118         return true;
119     }
120 
121     public List<Feed> getFeeds( )
122     {
123         List<Feed> list = new ArrayList<>( );
124 
125         Feedplugins/broadcastproxy/business/Feed.html#Feed">Feed testFeed = new Feed( );
126         testFeed.setActive( true );
127         testFeed.setName( "EXAMPLE_ONE" );
128         testFeed.setId( "ONE" );
129         testFeed.setDescription( "Test" );
130         testFeed.setType( "TEST" );
131         Map<String, String> mapDatas = new HashMap<>( );
132         mapDatas.put( "T1", "theme1" );
133         mapDatas.put( "T2", "theme2" );
134         testFeed.setData( mapDatas );
135 
136         list.add( testFeed );
137 
138         Feedlugins/broadcastproxy/business/Feed.html#Feed">Feed testFeed2 = new Feed( );
139         testFeed2.setActive( false );
140         testFeed2.setName( "EXAMPLE_TWO" );
141         testFeed2.setId( "TWO" );
142         testFeed2.setDescription( "Test" );
143         testFeed2.setType( "TEST" );
144 
145         list.add( testFeed2 );
146 
147         return list;
148     }
149 
150     @Override
151     public boolean updateSubscribtions( String userId, String jsonSubscriptions ) throws Exception
152     {
153         // TODO Auto-generated method stub
154         return false;
155     }
156 
157     @Override
158     public boolean updateSubscribtions( String userId, List<Subscription> subscriptionsList ) throws Exception
159     {
160         // TODO Auto-generated method stub
161         return false;
162     }
163 
164     @Override
165     public List<String> getSubscriptionViewOrder( )
166     {
167         // TODO Auto-generated method stub
168         return null;
169     }
170 
171 }