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.dolist;
35  
36  import java.io.IOException;
37  import java.text.Collator;
38  import java.util.ArrayList;
39  import java.util.Collections;
40  import java.util.HashMap;
41  import java.util.List;
42  import java.util.Locale;
43  import java.util.Map;
44  import java.util.TreeMap;
45  
46  import org.apache.commons.lang.StringUtils;
47  
48  import com.fasterxml.jackson.databind.JsonNode;
49  import com.fasterxml.jackson.databind.ObjectMapper;
50  
51  import fr.paris.lutece.plugins.broadcastproxy.business.Feed;
52  import fr.paris.lutece.plugins.broadcastproxy.business.IBroadcastProvider;
53  import fr.paris.lutece.plugins.broadcastproxy.business.Subscription;
54  import fr.paris.lutece.plugins.broadcastproxy.service.Constants;
55  import fr.paris.lutece.portal.service.util.AppLogService;
56  import fr.paris.lutece.portal.service.util.AppPropertiesService;
57  
58  public class DolistProvider implements IBroadcastProvider
59  {
60      // Constants
61      private static final String PROVIDER_NAME = "Dolist";
62  
63      private static final String JSON_NODE_ITEMLIST = AppPropertiesService.getProperty( "dolist.jsonNode.ItemList" );
64      private static final String JSON_NODE_ITEM_INTERESTLIST = AppPropertiesService.getProperty( "dolist.jsonNode.item.InterestList" );
65      private static final String JSON_NODE_ITEM_INTEREST = AppPropertiesService.getProperty( "dolist.jsonNode.item.Interest" );
66      private static final String JSON_NODE_ITEM_GROUP = AppPropertiesService.getProperty( "dolist.jsonNode.item.Group" );
67      private static final String JSON_NODE_ITEM_STATUS = AppPropertiesService.getProperty( "dolist.jsonNode.item.Status" );
68      private static final String JSON_NODE_SUB_ID = AppPropertiesService.getProperty( "dolist.jsonNode.sub.SubscriptionID" );
69      private static final String JSON_NODE_INTEREST_NAME = AppPropertiesService.getProperty( "dolist.jsonNode.interest.Name" );
70      private static final String JSON_NODE_INTEREST_IS_ACTIVE = AppPropertiesService.getProperty( "dolist.jsonNode.interest.isActive" );
71      private static final String JSON_NODE_GROUP_NAME = AppPropertiesService.getProperty( "dolist.jsonNode.group.Name" );
72      private static final String JSON_NODE_SUB_NAME = AppPropertiesService.getProperty( "dolist.jsonNode.sub.Name" );
73      private static final String JSON_NODE_SUB_SUBSCRIBED = AppPropertiesService.getProperty( "dolist.jsonNode.sub.Subscribed" );
74      private static final String JSON_NODE_SUB_UNSUBSCRIBED = AppPropertiesService.getProperty( "dolist.jsonNode.sub.Unsubscribed" );
75  
76      private static final String CONSTANTE_OPERATION_MODE_ADD = AppPropertiesService.getProperty( "dolist.CONSTANTE_OPERATION_MODE_ADD" );
77      private static final String CONSTANTE_OPERATION_MODE_DELETE = AppPropertiesService.getProperty( "dolist.CONSTANTE_OPERATION_MODE_DELETE" );
78  
79      // instance variables
80      private DolistAPI _dolistAPI;
81  
82      private TreeMap<Integer, String> _groupViewRang = new TreeMap<>( );
83      private Map<String, String> _groupsMapIdName = new HashMap<>( );
84      private Map<String, String> _interestsMapIdName = new HashMap<>( );
85      private Map<String, String> _subscriptionsMapIdName = new HashMap<>( );
86  
87      /**
88       * Constructor
89       */
90      public DolistProvider( )
91      {
92          _dolistAPI = new DolistAPI( );
93          initMapIdName( );
94      }
95  
96      @Override
97      public String getName( )
98      {
99          return PROVIDER_NAME;
100     }
101 
102     @Override
103     public boolean subscribe( String userId, String subscriptionId, String typeSubscription ) throws Exception
104     {
105         // TODO Auto-generated method stub
106         return false;
107     }
108 
109     @Override
110     public boolean unsubscribe( String userId, String subscriptionId, String typeSubscription ) throws Exception
111     {
112         // TODO Auto-generated method stub
113         return false;
114     }
115 
116     @Override
117     public Map<String, Map<String, List<Subscription>>> getUserSubscriptionsAsList( String userId ) throws Exception
118     {
119 
120         String userDolistSubscriptionsList = _dolistAPI.getUserSubscriptions( userId, DolistConstants.TYPE_SUBSCRIPTION );
121 
122         Map<String, Map<String, List<Subscription>>> userSubscriptions = getUserSubscriptionsByGroup( userDolistSubscriptionsList, userId );
123 
124         return userSubscriptions;
125     }
126 
127     @Override
128     public String getUserSubscriptionsAsJson( String userId ) throws Exception
129     {
130         Map<String, Map<String, List<Subscription>>> userSubscriptions = getUserSubscriptionsAsList( userId );
131 
132         String jsonUserSubscriptions = buildUserSubscriptionsJson( userSubscriptions );
133 
134         return jsonUserSubscriptions;
135     }
136 
137     @Override
138     public boolean updateSubscribtions( String userId, List<Subscription> subscriptionsList ) throws Exception
139     {
140         return false;
141     }
142 
143     @Override
144     public boolean updateSubscribtions( String userId, String jsonSubscriptions ) throws Exception
145     {
146         Map<String, String> subscriptionStatus = new HashMap<>( );
147         List<Integer> interestsToAdd = new ArrayList<>( );
148         List<Integer> interestsToDelete = new ArrayList<>( );
149 
150         try
151         {
152             Map<String, Boolean> subscriptionsToUpdate = getUserSubscribtionsToUpdate( jsonSubscriptions );
153 
154             for ( Map.Entry<String, Boolean> sub : subscriptionsToUpdate.entrySet( ) )
155             {
156                 if ( sub.getValue( ) )
157                 {
158                     subscriptionStatus.put( getSubscriptionDolistId( sub.getKey( ), _subscriptionsMapIdName ), JSON_NODE_SUB_SUBSCRIBED );
159                     interestsToAdd.add( Integer.parseInt( getSubscriptionDolistId( sub.getKey( ), _interestsMapIdName ) ) );
160                 }
161                 else
162                 {
163                     subscriptionStatus.put( getSubscriptionDolistId( sub.getKey( ), _subscriptionsMapIdName ), JSON_NODE_SUB_UNSUBSCRIBED );
164                     interestsToDelete.add( Integer.parseInt( getSubscriptionDolistId( sub.getKey( ), _interestsMapIdName ) ) );
165                 }
166             }
167 
168             // update dolist subscriptions
169             _dolistAPI.updateSubscribtions( userId, subscriptionStatus );
170 
171             // Update Dolist Interests
172             if ( !interestsToAdd.isEmpty( ) )
173             {
174                 _dolistAPI.updateInterests( userId, interestsToAdd, CONSTANTE_OPERATION_MODE_ADD );
175             }
176 
177             if ( !interestsToDelete.isEmpty( ) )
178             {
179                 _dolistAPI.updateInterests( userId, interestsToDelete, CONSTANTE_OPERATION_MODE_DELETE );
180             }
181 
182         }
183         catch( Exception e )
184         {
185             AppLogService.error( "An error occured while updating subscriptions : " + e.getMessage( ) );
186             return false;
187         }
188 
189         return true;
190     }
191 
192     @Override
193     public boolean update( Subscription sub ) throws Exception
194     {
195         Map<String, String> subscriptionStatus = new HashMap<String, String>( );
196 
197         if ( sub.isActive( ) )
198         {
199             subscriptionStatus.put( getSubscriptionDolistId( sub.getName( ), _interestsMapIdName ), JSON_NODE_SUB_SUBSCRIBED );
200         }
201         else
202         {
203             subscriptionStatus.put( getSubscriptionDolistId( sub.getName( ), _interestsMapIdName ), JSON_NODE_SUB_UNSUBSCRIBED );
204         }
205 
206         _dolistAPI.updateSubscribtions( sub.getUserId( ), subscriptionStatus );
207 
208         return true;
209     }
210 
211     @Override
212     public List<Feed> getFeeds( )
213     {
214         return null;
215     }
216 
217     @Override
218     public List<String> getSubscriptionViewOrder( )
219     {
220         List<String> subscriptionViewOrder = new ArrayList<String>( );
221 
222         for ( Map.Entry<Integer, String> group : _groupViewRang.entrySet( ) )
223         {
224             subscriptionViewOrder.add( group.getValue( ) );
225         }
226 
227         return subscriptionViewOrder;
228     }
229 
230     public Map<String, Map<String, List<Subscription>>> getUserSubscriptionsByGroup( String jsonUserDolistSubscriptions, String userId ) throws Exception
231     {
232         Map<String, Map<String, List<Subscription>>> userSubscriptions = new HashMap<String, Map<String, List<Subscription>>>( );
233         List<String> userSubscriptionNamesList = new ArrayList<String>( );
234         Map<String, List<String>> allDolistSubscriptionsNamesByGroup = new HashMap<String, List<String>>( );
235         Map<String, List<Subscription>> userNewsletters = new HashMap<String, List<Subscription>>( );
236         Map<String, List<Subscription>> userAlerts = new HashMap<String, List<Subscription>>( );
237 
238         try
239         {
240             // Build list of user subscriptions and interests names
241             userSubscriptionNamesList.addAll( getUserSubscriptionsNamesAsList( jsonUserDolistSubscriptions, DolistConstants.TYPE_SUBSCRIPTION ) );
242 
243             // Add all dolist subscriptions and interests names by group
244             allDolistSubscriptionsNamesByGroup.putAll( getAllSubscriptionsNamesByGroup( DolistConstants.TYPE_INTEREST ) );
245 
246             for ( Map.Entry<String, List<String>> subscriptionsNamesByGroup : allDolistSubscriptionsNamesByGroup.entrySet( ) )
247             {
248                 if ( subscriptionsNamesByGroup.getKey( ) != null )
249                 {
250                     List<Subscription> subscriptionsList = new ArrayList<>( );
251 
252                     for ( String name : subscriptionsNamesByGroup.getValue( ) )
253                     {
254                         Subscriptiongins/broadcastproxy/business/Subscription.html#Subscription">Subscription sub = new Subscription( );
255 
256                         sub.setUserId( userId );
257                         sub.setName( name );
258                         sub.setId( name.trim( ).replace( " ", "_" ) );
259 
260                         if ( userSubscriptionNamesList.contains( name ) )
261                             sub.setActive( true );
262                         else
263                             sub.setActive( false );
264 
265                         subscriptionsList.add( sub );
266                     }
267 
268                     String groupName = subscriptionsNamesByGroup.getKey( );
269 
270                     if ( groupName.equals( "Alertes" ) )
271                     {
272                         // subscriptionType = Constants.TYPE_ALERT;
273                         if ( userAlerts.containsKey( groupName ) )
274                         {
275                             subscriptionsList.addAll( userAlerts.get( groupName ) );
276                         }
277 
278                         userAlerts.put( groupName, subscriptionsList );
279                     }
280                     else
281                     {
282                         // subscriptionType = Constants.TYPE_NEWSLETTER;
283                         if ( userNewsletters.containsKey( groupName ) )
284                         {
285                             subscriptionsList.addAll( userNewsletters.get( groupName ) );
286                         }
287 
288                         userNewsletters.put( groupName, subscriptionsList );
289                     }
290                 }
291             }
292 
293             userSubscriptions.put( Constants.TYPE_NEWSLETTER, userNewsletters );
294             userSubscriptions.put( Constants.TYPE_ALERT, userAlerts );
295         }
296         catch( Exception e )
297         {
298             String strError = "Error occured while getting the user list subscriptions.";
299             AppLogService.error( strError + e.getMessage( ), e );
300         }
301 
302         return userSubscriptions;
303     }
304 
305     public Map<String, List<String>> getAllSubscriptionsNamesByGroup( String typeSubscription ) throws Exception
306     {
307         String subscriptionsInJson = _dolistAPI.getAllSubscriptions( typeSubscription );
308         return buildDolistAllSubscriptionsNamesListByGroup( subscriptionsInJson, typeSubscription );
309     }
310 
311     public Map<String, List<String>> buildDolistAllSubscriptionsNamesListByGroup( String jsonAllSubscriptions, String typeSubscription ) throws Exception
312     {
313         ObjectMapper mapper = new ObjectMapper( );
314         Map<String, List<String>> SubscriptionsName = new HashMap<String, List<String>>( );
315         String groupName = StringUtils.EMPTY;
316 
317         JsonNode nodes = mapper.readTree( jsonAllSubscriptions );
318         if ( nodes.get( JSON_NODE_ITEMLIST ).isNull( ) )
319             return null;
320         try
321         {
322             JsonNode itemListNode = nodes.get( JSON_NODE_ITEMLIST );
323 
324             for ( JsonNode itemNode : itemListNode )
325             {
326                 JsonNode groupData = itemNode.get( JSON_NODE_ITEM_GROUP );
327 
328                 groupName = groupData.get( JSON_NODE_GROUP_NAME ).asText( );
329 
330                 if ( groupName.substring( 0, 1 ).equals( "[" ) && groupName.substring( groupName.length( ) - 1, groupName.length( ) ).equals( "]" )
331                         && groupName.length( ) > 2 )
332                 {
333                     String [ ] splitDlGrName = groupName.split( "\\]" );
334 
335                     groupName = splitDlGrName [0].substring( 1, splitDlGrName [0].length( ) );
336 
337                     List<String> SubscriptionsNamesList = new ArrayList<String>( );
338                     for ( JsonNode node : itemNode.get( JSON_NODE_ITEM_INTERESTLIST ) )
339                     {
340                         if ( !node.has( JSON_NODE_INTEREST_IS_ACTIVE ) )
341                         {
342                             SubscriptionsNamesList.add( node.get( JSON_NODE_INTEREST_NAME ).asText( ) );
343                         }
344                     }
345 
346                     Collections.sort( SubscriptionsNamesList, Collator.getInstance(Locale.FRENCH) );
347 
348                     SubscriptionsName.put( groupName, SubscriptionsNamesList );
349                 }
350             }
351         }
352         catch( Exception e )
353         {
354             String strError = "Error occured while getting the list of interests ids and names.";
355             AppLogService.error( strError + e.getMessage( ), e );
356         }
357 
358         return SubscriptionsName;
359     }
360 
361     private List<String> getUserSubscriptionsNamesAsList( String jsonResponse, String typeSubscription )
362     {
363         ObjectMapper mapper = new ObjectMapper( );
364         List<String> userSubscriptionNamesList = new ArrayList<String>( );
365         List<String> activeSubscriptionsId = new ArrayList<String>( );
366 
367         try
368         {
369             // Get list of only active subscriptions
370             for ( Map.Entry<String, String> subEntry : _subscriptionsMapIdName.entrySet( ) )
371             {
372                 activeSubscriptionsId.add( subEntry.getKey( ) );
373             }
374 
375             JsonNode nodes = mapper.readTree( jsonResponse );
376             if ( nodes.get( JSON_NODE_ITEMLIST ).isNull( ) )
377                 return null;
378 
379             JsonNode itemListNode = nodes.get( JSON_NODE_ITEMLIST );
380             if ( itemListNode != null )
381             {
382                 if ( typeSubscription.equals( DolistConstants.TYPE_SUBSCRIPTION ) )
383                 {
384                     for ( JsonNode itemNode : itemListNode )
385                     {
386                         if ( activeSubscriptionsId.contains( itemNode.get( JSON_NODE_SUB_ID ).asText( ) )
387                                 && itemNode.get( JSON_NODE_ITEM_STATUS ).asText( ).equals( JSON_NODE_SUB_SUBSCRIBED ) )
388                             userSubscriptionNamesList.add( _subscriptionsMapIdName.get( itemNode.get( JSON_NODE_SUB_ID ).asText( ) ) );
389                     }
390                 }
391                 else
392                     if ( typeSubscription.equals( DolistConstants.TYPE_INTEREST ) )
393                     {
394                         for ( JsonNode node : itemListNode )
395                         {
396                             userSubscriptionNamesList.add( node.get( JSON_NODE_ITEM_INTEREST ).get( JSON_NODE_INTEREST_NAME ).asText( ) );
397                         }
398                     }
399             }
400         }
401         catch( Exception e )
402         {
403             String strError = "Error occured while getting the list of interests ids and names.";
404             AppLogService.error( strError + e.getMessage( ), e );
405         }
406 
407         return userSubscriptionNamesList;
408     }
409 
410     /**
411      * Build JSON response from subscription beans list
412      * 
413      * @param the
414      *            list
415      * @return a JSON String
416      */
417     private String buildUserSubscriptionsJson( Map<String, Map<String, List<Subscription>>> userSubscriptions ) throws IOException
418     {
419         ObjectMapper mapper = new ObjectMapper( );
420         String jsonSubscriptions = StringUtils.EMPTY;
421         List<String> jsonSubByGrList = new ArrayList<String>( );
422 
423         for ( Map.Entry<String, Map<String, List<Subscription>>> subscriptionsByGroup : userSubscriptions.entrySet( ) )
424         {
425             if ( subscriptionsByGroup.getKey( ) != null )
426             {
427                 for ( Map.Entry<String, List<Subscription>> subscriptionsList : subscriptionsByGroup.getValue( ).entrySet( ) )
428                 {
429                     String jsonSubList = mapper.writeValueAsString( subscriptionsList.getValue( ) );
430 
431                     String jsonSubGr = "{\"groupName\":" + subscriptionsByGroup.getKey( ) + ",\"subscriptionsList\":" + jsonSubList + "}";
432 
433                     jsonSubByGrList.add( jsonSubGr );
434                 }
435             }
436         }
437 
438         jsonSubscriptions = "{\"userSubscriptions\":" + mapper.writeValueAsString( jsonSubByGrList ) + "}";
439 
440         return jsonSubscriptions;
441     }
442 
443     public Map<String, Boolean> getUserSubscribtionsToUpdate( String jsonSubscriptions ) throws Exception
444     {
445         ObjectMapper mapper = new ObjectMapper( );
446         Map<String, Boolean> subscriptionsToUpdate = new HashMap<>( );
447 
448         try
449         {
450             JsonNode jsonNodes = mapper.readTree( jsonSubscriptions );
451 
452             JsonNode jsonUserSubscriptionList = jsonNodes.get( "userSubscriptions" );
453 
454             for ( JsonNode subscriptionsByTypeNode : jsonUserSubscriptionList )
455             {
456                 JsonNode subscriptionsByGrList = subscriptionsByTypeNode.get( "subscriptionsByGroup" );
457 
458                 for ( JsonNode subscriptionsByGr : subscriptionsByGrList )
459                 {
460                     JsonNode subscriptionsList = subscriptionsByGr.get( "subscriptionsList" );
461 
462                     for ( JsonNode jsonSubscription : subscriptionsList )
463                     {
464                         // Build Map (Name / Status) of subscriptions to update
465                         subscriptionsToUpdate.put( jsonSubscription.get( "id" ).asText( ).replace( "_", " " ),
466                                 Boolean.valueOf( jsonSubscription.get( "active" ).asText( ) ) );
467                     }
468                 }
469             }
470         }
471         catch( Exception e )
472         {
473             AppLogService.error( "An error occured while updating subscriptions : " + e.getMessage( ) );
474             return null;
475         }
476 
477         return subscriptionsToUpdate;
478     }
479 
480     /**
481      * init
482      */
483     private void initMapIdName( )
484     {
485         ObjectMapper mapper = new ObjectMapper( );
486 
487         String subscriptionsInJson = _dolistAPI.getAllSubscriptions( DolistConstants.TYPE_SUBSCRIPTION );
488         String interestsInJson = _dolistAPI.getAllSubscriptions( DolistConstants.TYPE_INTEREST );
489 
490         try
491         {
492             // Get subscriptions data (id and name)
493             JsonNode nodes = mapper.readTree( subscriptionsInJson );
494 
495             JsonNode itemListNode = nodes.get( JSON_NODE_ITEMLIST );
496 
497             for ( JsonNode node : itemListNode )
498             {
499                 if ( node.get( "IsEnabled" ).asBoolean( ) )
500                 {
501                     _subscriptionsMapIdName.put( node.get( "ID" ).asText( ), node.get( JSON_NODE_SUB_NAME ).asText( ) );
502                 }
503             }
504 
505             // Get interests data (id and name)
506             nodes = null;
507             itemListNode = null;
508 
509             nodes = mapper.readTree( interestsInJson );
510 
511             itemListNode = nodes.get( JSON_NODE_ITEMLIST );
512 
513             for ( JsonNode node : itemListNode )
514             {
515                 JsonNode groupData = node.get( JSON_NODE_ITEM_GROUP );
516 
517                 String dolistGroupName = groupData.get( JSON_NODE_GROUP_NAME ).asText( );
518                 if ( dolistGroupName.substring( 0, 1 ).equals( "[" )
519                         && dolistGroupName.substring( dolistGroupName.length( ) - 1, dolistGroupName.length( ) ).equals( "]" ) )
520                 {
521                     String [ ] splitDlGrName = dolistGroupName.split( "\\]" );
522 
523                     if ( splitDlGrName.length > 0 )
524                     {
525                         String groupName = splitDlGrName [0].substring( 1, splitDlGrName [0].length( ) );
526 
527                         if ( splitDlGrName.length == 2 && splitDlGrName [1].length( ) > 0 && !groupName.equals( "Alertes" ) )
528                         {
529                             _groupViewRang.put( Integer.valueOf( splitDlGrName [1].substring( 1, splitDlGrName [1].length( ) ) ), groupName );
530                         }
531 
532                         _groupsMapIdName.put( groupData.get( "ID" ).asText( ), groupName );
533 
534                         JsonNode intersts = node.get( JSON_NODE_ITEM_INTERESTLIST );
535                         for ( JsonNode interest : intersts )
536                         {
537                             if ( !interest.has( JSON_NODE_INTEREST_IS_ACTIVE ) )
538                             {
539                                 _interestsMapIdName.put( interest.get( "ID" ).asText( ), interest.get( JSON_NODE_INTEREST_NAME ).asText( ) );
540                             }
541                         }
542                     }
543                 }
544             }
545         }
546         catch( Exception e )
547         {
548             String strError = "Error occured while getting the list of interests ids and names.";
549             AppLogService.error( strError + e.getMessage( ), e );
550         }
551     }
552 
553     /**
554      * get map from sub datas
555      * 
556      * @param sub
557      * @return the map
558      */
559     public Map<String, String> subToMap( Subscription sub, Map<String, String> mapIdName )
560     {
561         Map<String, String> mapSubData = new HashMap<>( );
562         String subscriptionDolistId = StringUtils.EMPTY;
563 
564         for ( Map.Entry<String, String> subMapIdName : _subscriptionsMapIdName.entrySet( ) )
565         {
566             if ( subMapIdName.getValue( ).equals( sub.getName( ) ) )
567             {
568                 subscriptionDolistId = subMapIdName.getKey( );
569                 continue;
570             }
571         }
572 
573         if ( sub.isActive( ) )
574             mapSubData.put( subscriptionDolistId, JSON_NODE_SUB_SUBSCRIBED );
575         else
576             mapSubData.put( subscriptionDolistId, JSON_NODE_SUB_UNSUBSCRIBED );
577 
578         return mapSubData;
579     }
580 
581     /**
582      * get subscription dolist ID
583      * 
584      * @param sub
585      * @return the map
586      */
587     public String getSubscriptionDolistId( String subscriptionName, Map<String, String> mapIdName )
588     {
589         String subscriptionDolistId = null;
590 
591         for ( Map.Entry<String, String> subMapIdName : mapIdName.entrySet( ) )
592         {
593             if ( subMapIdName.getValue( ).equals( subscriptionName ) )
594             {
595                 subscriptionDolistId = subMapIdName.getKey( );
596             }
597         }
598 
599         return subscriptionDolistId;
600     }
601 
602 }