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.elasticdata.modules.identity.business;
35
36 import java.util.ArrayList;
37 import java.util.Collection;
38 import java.util.HashMap;
39 import java.util.List;
40 import java.util.Map;
41 import org.apache.commons.collections.CollectionUtils;
42 import fr.paris.lutece.portal.service.plugin.Plugin;
43 import fr.paris.lutece.util.sql.DAOUtil;
44
45
46
47
48 public final class IdentityDataObjectDAO implements IIdentityDataObjectDAO
49 {
50
51 private static final String SQL_QUERY_SELECT_ID_IDENTITY_TO_EXPORT = "SELECT id_identity FROM identitystore_identity";
52 private static final String SQL_QUERY_SELECT_IDENTITY_TO_EXPORT = "SELECT id_identity, customer_id, connection_id, date_create, date_delete FROM identitystore_identity";
53 private static final String SQL_QUERY_SELECT_ATTRIBUTE = "SELECT id_attribute, key_name FROM identitystore_ref_attribute";
54 private static final String SQL_QUERY_SELECT_IDENTITY_ATTRIBUTE = "SELECT a.id_identity, a.id_attribute, attribute_value, lastupdate_date,certifier_code,certificate_date,level, expiration_date "
55 + " FROM identitystore_identity_attribute a , identitystore_identity_attribute_certificate c, identitystore_ref_certification_level l, identitystore_ref_certification_processus p, identitystore_ref_certification_attribute_level lp "
56 + " WHERE a.id_certification = c.id_attribute_certificate and c.certifier_code = p.code and p.id_ref_attribute_certification_processus = lp.id_ref_attribute_certification_processus and lp.id_attribute = a.id_attribute and lp.id_ref_certification_level = l.id_ref_certification_level ";
57 private static final String SQL_QUERY_SELECT_FILTER = " and id_identity in ( ";
58 private static final String SQL_QUERY_SELECT_IDENTITY_FILTER = " WHERE id_identity in (?";
59 private static final String SQL_CLOSE_PARENTHESIS = " ) ";
60 private static final String SQL_ADITIONAL_PARAMETER = ",?";
61
62
63
64
65 @Override
66 public List<IdentityAttributeDataObject> selectAttributes( Collection<IdentityDataObject> lIdIdentity, Plugin plugin )
67 {
68 List<IdentityAttributeDataObject> ListIdentityAttributes = new ArrayList<>( );
69 StringBuffer strQuery = new StringBuffer( SQL_QUERY_SELECT_IDENTITY_ATTRIBUTE );
70 strQuery.append( SQL_QUERY_SELECT_FILTER );
71 if ( !CollectionUtils.isEmpty( lIdIdentity ) )
72 for ( IdentityDataObject id : lIdIdentity )
73 {
74 strQuery.append( "?," );
75 }
76 strQuery.deleteCharAt( strQuery.length( ) - 1 );
77 strQuery.append( ")" );
78 DAOUtil daoUtil = new DAOUtil( strQuery.toString( ), plugin );
79 int ncpt = 1;
80 for ( IdentityDataObject id : lIdIdentity )
81 {
82 daoUtil.setInt( ncpt++, Integer.valueOf( id.getId( ) ) );
83 }
84 daoUtil.executeQuery( );
85 int nIndex;
86 while ( daoUtil.next( ) )
87 {
88 IdentityAttributeDataObjecttity/business/IdentityAttributeDataObject.html#IdentityAttributeDataObject">IdentityAttributeDataObject identityAttribute = new IdentityAttributeDataObject( );
89 nIndex = 1;
90 identityAttribute.setIdIdentity( daoUtil.getInt( nIndex++ ) );
91 identityAttribute.setIdAttribute( daoUtil.getInt( nIndex++ ) );
92 identityAttribute.setValue( daoUtil.getString( nIndex++ ) );
93 identityAttribute.setLastUpdateDate( daoUtil.getTimestamp( nIndex++ ) );
94 identityAttribute.setCertifierCode( daoUtil.getString( nIndex++ ) );
95 identityAttribute.setCertificateDate( daoUtil.getTimestamp( nIndex++ ) );
96 identityAttribute.setCertificateLevel( daoUtil.getString( nIndex++ ) );
97 identityAttribute.setCertificateExpirationDate( daoUtil.getTimestamp( nIndex++ ) );
98 ListIdentityAttributes.add( identityAttribute );
99 }
100 daoUtil.free( );
101 return ListIdentityAttributes;
102 }
103
104
105
106
107 @Override
108 public List<IdentityDataObject> selectAllIdentity( List<Integer> listIdIdentity, Plugin plugin )
109 {
110 List<IdentityDataObject> listIdentity = new ArrayList<>( );
111 int nlistIdIdentitySize = listIdIdentity.size( );
112 if ( nlistIdIdentitySize > 0 )
113 {
114 StringBuilder sbSQL = new StringBuilder( SQL_QUERY_SELECT_IDENTITY_TO_EXPORT + " " + SQL_QUERY_SELECT_IDENTITY_FILTER );
115 for ( int i = 1; i < nlistIdIdentitySize; i++ )
116 {
117 sbSQL.append( SQL_ADITIONAL_PARAMETER );
118 }
119 sbSQL.append( SQL_CLOSE_PARENTHESIS );
120 try ( DAOUtil daoUtil = new DAOUtil( sbSQL.toString( ), plugin ) )
121 {
122 for ( int i = 0; i < nlistIdIdentitySize; i++ )
123 {
124 daoUtil.setInt( i + 1, listIdIdentity.get( i ) );
125 }
126 daoUtil.executeQuery( );
127 while ( daoUtil.next( ) )
128 {
129 listIdentity
130 .add( new IdentityDataObject( daoUtil.getInt( 1 ), daoUtil.getString( 2 ), daoUtil.getString( 3 ), daoUtil.getTimestamp( 4 ), daoUtil.getTimestamp( 5 ) ) );
131 }
132 }
133 }
134 return listIdentity;
135 }
136
137
138
139
140 @Override
141 public List<Integer> selectAllIdIdentity( Plugin plugin )
142 {
143 List<Integer> listIdentity = new ArrayList<>( );
144 try ( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_ID_IDENTITY_TO_EXPORT, plugin ) )
145 {
146 daoUtil.executeQuery( );
147 while ( daoUtil.next( ) )
148 {
149 listIdentity.add( daoUtil.getInt( 1 ) );
150 }
151 }
152 return listIdentity;
153 }
154
155
156
157
158 @Override
159 public Map<Integer, String> selectAllAttributes( Plugin plugin )
160 {
161 Map<Integer, String> mapAttribute = new HashMap<>( );
162 try ( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_ATTRIBUTE, plugin ) )
163 {
164 daoUtil.executeQuery( );
165 while ( daoUtil.next( ) )
166 {
167 mapAttribute.put( daoUtil.getInt( 1 ), daoUtil.getString( 2 ) );
168 }
169 }
170 return mapAttribute;
171 }
172 }