View Javadoc
1   package fr.paris.lutece.plugins.extend.modules.hit.business;
2   
3   import java.util.List;
4   import java.util.Optional;
5   
6   import fr.paris.lutece.plugins.extend.service.ExtendPlugin;
7   import fr.paris.lutece.portal.service.plugin.Plugin;
8   import fr.paris.lutece.portal.service.spring.SpringContextService;
9   
10  public class HitHome {
11  
12      private static IHitDAO _hitDAO = SpringContextService.getBean( "extend.hitDAO" );
13      private static Plugin _plugin = ExtendPlugin.getPlugin( );
14  
15      /**
16       * Private constructor
17       */
18      private HitHome ()
19      {
20      	
21      }    
22      /**
23       * Creates the a hit extender.
24       *
25       * @param hit
26       *            the hit
27       */
28      public static void create( Hit hit )
29      {
30          _hitDAO.insert( hit, _plugin );
31      }
32      /**
33       * Update a hit extender.
34       *
35       * @param hit
36       *            the hit
37       */
38      public static void update( Hit hit )
39      {
40          _hitDAO.store( hit, _plugin );
41      }
42      /**
43      * Removes a hit extender.
44      *
45      * @param nIdHit
46      *            the n id hit
47      */
48      public static void remove( int nIdExtender )
49      {
50          _hitDAO.delete( nIdExtender,_plugin );
51      }
52      /**
53       * Removes a hit extender by id resource and resource type.
54       * 
55       * @param strIdResource
56       *            The id of the resource to remove
57       * @param strResourceType
58       *            The type of the resource to remove
59       */
60      public static void removeByResource( String strIdResource, String strResourceType )
61      {
62          _hitDAO.deleteByResource( strIdResource, strResourceType, _plugin );
63      }
64      /**
65       * Find.
66       *
67       * @param nIdExtender
68       *            the n id extender
69       * @return the Optional<Hit>
70       */
71      public static Optional<Hit> findByPrimaryKey( int nIdHit )
72      {
73          return Optional.ofNullable(_hitDAO.load( nIdHit, _plugin ));
74      }
75      /**
76       * Find by id extender.
77       *
78       * @param strIdExtendableResource
79       *            the str id extendable resource
80       * @param strExtendableResourceType
81       *            the str extendable resource type
82       * @return the Optional<Hit>
83       */
84      public static Optional<Hit> findByParameters( String strIdExtendableResource, String strExtendableResourceType )
85      {
86          return Optional.ofNullable(_hitDAO.loadByParameters( strIdExtendableResource, strExtendableResourceType, _plugin ));
87      }
88      /**
89       * Get the ids of resources ordered by their number of hits
90       * 
91       * @param strExtendableResourceType
92       *            The type of resources to consider
93       * @param nItemsOffset
94       *            The offset of the items to get, or 0 to get items from the first one
95       * @param nMaxItemsNumber
96       *            The maximum number of items to return, or 0 to get every items
97       * @return The list of ids of resources ordered by the number hits
98       */
99      public static List<Integer> findIdMostHitedResources( String strExtendableResourceType, int nItemsOffset, int nMaxItemsNumber )
100     {
101         return _hitDAO.findIdMostHitedResources( strExtendableResourceType, nItemsOffset, nMaxItemsNumber, _plugin );
102     }
103     /**
104      * Find by list id extendable resource.
105      *
106      * @param listIdExtendableResource
107      *            the list of str id extendable resource
108      * @param strExtendableResourceType
109      *            the str extendable resource type
110      * @return the hit list
111      */
112 	public static List<Hit> findByResourceList(List<String> listIdExtendableResource, String strExtendableResourceType) 
113 	{
114 
115 		return _hitDAO.findByResourceList( listIdExtendableResource, strExtendableResourceType, _plugin );
116 	}
117 }