1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package fr.paris.lutece.plugins.unittree.business.action;
35
36 import fr.paris.lutece.portal.service.plugin.Plugin;
37 import fr.paris.lutece.util.sql.DAOUtil;
38
39 import java.util.ArrayList;
40 import java.util.List;
41
42 import javax.inject.Inject;
43
44
45
46
47
48
49 public class ActionDAO implements IActionDAO
50 {
51 private static final String SQL_QUERY_SELECT_ACTIONS = "SELECT id_action, name_key, description_key, action_url, icon_url, action_permission, action_type "
52 + " FROM unittree_action WHERE action_type = ? ";
53 private static final String SQL_QUERY_SELECT_FILTER_BY_PERMISSION = "SELECT id_action, name_key, description_key, action_url, icon_url, action_permission, action_type "
54 + " FROM unittree_action WHERE action_type = ? AND action_permission != ? ";
55 @Inject
56 private ActionFactory _actionFactory;
57
58
59
60
61 @Override
62 public List<IAction> selectActions( String strActionType, Plugin plugin )
63 {
64 List<IAction> listActions = new ArrayList<>( );
65 try ( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_ACTIONS, plugin ) )
66 {
67 daoUtil.setString( 1, strActionType );
68 daoUtil.executeQuery( );
69
70 while ( daoUtil.next( ) )
71 {
72 IAction action = dataToObject( strActionType, daoUtil );
73 listActions.add( action );
74 }
75 }
76 return listActions;
77 }
78
79
80
81
82 @Override
83 public List<IAction> selectFilterByPermission( String strActionType, String strPermission, Plugin plugin )
84 {
85 List<IAction> listActions = new ArrayList<>( );
86 try ( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_FILTER_BY_PERMISSION, plugin ) )
87 {
88 int nIndex = 0;
89 daoUtil.setString( ++nIndex, strActionType );
90 daoUtil.setString( ++nIndex, strPermission );
91 daoUtil.executeQuery( );
92
93 while ( daoUtil.next( ) )
94 {
95 IAction action = dataToObject( strActionType, daoUtil );
96 listActions.add( action );
97 }
98 }
99 return listActions;
100 }
101
102 private IAction dataToObject( String strActionType, DAOUtil daoUtil )
103 {
104 int nIndex = 0;
105 IAction action = _actionFactory.newAction( strActionType );
106 action.setIdAction( daoUtil.getInt( ++nIndex ) );
107 action.setNameKey( daoUtil.getString( ++nIndex ) );
108 action.setDescriptionKey( daoUtil.getString( ++nIndex ) );
109 action.setUrl( daoUtil.getString( ++nIndex ) );
110 action.setIcon( daoUtil.getString( ++nIndex ) );
111 action.setPermission( daoUtil.getString( ++nIndex ) );
112 action.setActionType( daoUtil.getString( ++nIndex ) );
113
114 return action;
115 }
116 }