View Javadoc
1   package fr.paris.lutece.plugins.grustoragedb.business;
2   
3   import fr.paris.lutece.plugins.grubusiness.business.notification.INotificationDAO;
4   import fr.paris.lutece.plugins.grubusiness.business.notification.Notification;
5   import fr.paris.lutece.plugins.grubusiness.business.notification.NotificationFilter;
6   import fr.paris.lutece.portal.service.file.IFileStoreServiceProvider;
7   import fr.paris.lutece.portal.service.plugin.Plugin;
8   import fr.paris.lutece.portal.service.plugin.PluginService;
9   import fr.paris.lutece.portal.service.spring.SpringContextService;
10  import fr.paris.lutece.util.ReferenceList;
11  
12  import java.util.List;
13  import java.util.Optional;
14  
15  /**
16   * This class provides instances management methods (create, find, ...) for Notification objects
17   */
18  public final class NotificationHome
19  {
20      // Static variable pointed at the DAO instance
21      private static INotificationDAO _dao = SpringContextService.getBean( "grustoragedb.NotificationDAO" );
22      private static Plugin _plugin = PluginService.getPlugin( "grustoragedb" );
23  
24      /**
25       * Private constructor - this class need not be instantiated
26       */
27      private NotificationHome(  )
28      {
29      }
30  
31      /**
32       * Find the demand's notifications
33       * 
34       * @param strDemandId
35       * @param strDemandTypeId
36       * @return the notification list
37       */
38      public static List<Notification> findByDemand( String strDemandId, String strDemandTypeId )
39      {
40  	return _dao.loadByDemand(strDemandId, strDemandTypeId);
41      }
42      
43      
44      /**
45       * Find the notification by demand id's and date
46       * 
47       * @param strDemandId
48       * @param strDemandTypeId
49       * @param lDate
50       * @return the notification list
51       */
52      public static List<Notification> findByNotification( String strDemandId, String strDemandTypeId, long lDate )
53      {
54  	return _dao.loadByDemandAndDate(strDemandId, strDemandTypeId, lDate);
55      }
56  
57      /**
58       * Finds a notification  with the specified id 
59       * 
60       * @param strId
61       * @return the notification
62       */
63      public static Optional<Notification> getById( int id )
64      {
65          return _dao.loadById( id );
66      }
67  
68      /**
69       * search notifications by filter
70       * 
71       * @param filter
72       * @return the notification list
73       */
74      public static List<Notification> findByFilter( NotificationFilter filter )
75      {
76          return _dao.loadByFilter( filter );
77      }
78  
79      /**
80       * search notifications Ids by filter
81       * 
82       * @param filter
83       * @return the notification list
84       */
85      public static List<Integer> findIdsByFilter( NotificationFilter filter )
86      {
87          return _dao.loadIdsByFilter( filter );
88      }
89  
90      /**
91       * Find the notifications according to the filter
92       * 
93       * @param notificationFilter
94       * @return the notification list
95       */
96      public static List<Notification> getByFilter(NotificationFilter notificationFilter )
97      {
98          return _dao.loadByFilter( notificationFilter );
99      }
100 
101     /**
102      * Find the notifications by demand id, type id, customer id
103      * 
104      * @param strDemandId
105      * @param strDemandTypeId
106      * @param strCustomerId
107      * @return the notification list
108      */
109     public static List<Notification> getByDemandIdTypeIdCustomerId( String strDemandId, String strDemandTypeId, String strCustomerId )
110     {
111         return _dao.loadByDemandIdTypeIdCustomerId( strDemandId, strDemandTypeId, strCustomerId );
112     }
113     
114     /**
115      * Find the notifications according to the filter
116      * 
117      * @param notificationFilter
118      * @return the notification list
119      */
120     public static List<Notification> getByIds(List<Integer> listIds )
121     {
122         return _dao.loadByIds( listIds );
123     }
124 
125     /**
126      * Get distinct demand type ids list
127      * 
128      * @return the  list
129      */
130     public static ReferenceList getDemandTypeIds( )
131     {
132         List<String> strList = _dao.loadDistinctDemandTypeIds( );
133         
134         ReferenceList refList = new ReferenceList( );
135         for (String strId : strList )
136         {
137             refList.addItem(strId, strId);
138         }
139         
140         return refList;
141     }
142     
143     /**
144      * Create an instance of the Notification class
145      * 
146      * @param Notification
147      *            The instance of the Notification which contains the informations to store
148      * @return The instance of Notification which has been created with its primary key.
149      */
150     public static Notification create( Notification notification )
151     {
152         _dao.insert( notification );
153 
154         return notification;
155     }
156 
157     /**
158      * Remove the Notification whose identifier is specified in parameter
159      * 
160      * @param nKey
161      *            The Notification Id
162      */
163     public static void remove( int nKey )
164     {
165         _dao.delete( nKey );
166     }
167     
168     /**
169      * Get last notification by demand id and demand type id
170      * @param strDemandId
171      * @param strDemandTypeId
172      * @return last notification 
173      */
174     public static Notification getLastNotifByDemandIdAndDemandTypeId( String strDemandId, String strDemandTypeId )
175     {
176         return _dao.loadLastNotifByDemandIdAndDemandTypeId( strDemandId, strDemandTypeId );
177     }
178 }