blob: b9fa09a31dd080a4a16ac2e4b164f0733376070d (
plain) (
blame)
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
package org.openslx.imagemaster.db.mappers;
import java.nio.ByteBuffer;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.openslx.bwlp.thrift.iface.Satellite;
import org.openslx.bwlp.thrift.iface.UserInfo;
import org.openslx.imagemaster.db.Database;
import org.openslx.imagemaster.db.MysqlConnection;
import org.openslx.imagemaster.db.MysqlStatement;
import org.openslx.imagemaster.db.models.LocalSatellite;
import org.openslx.util.Json;
public class DbSatellite
{
private static final Logger LOGGER = LogManager.getLogger( DbSatellite.class );
public static LocalSatellite get( int satelliteId )
{
return null;
}
public static List<Satellite> getSatellites( UserInfo ui ) throws SQLException
{
if ( ui == null )
return null;
return getSatellites( ui.organizationId );
}
public static List<Satellite> getSatellites( String organizationId ) throws SQLException
{
if ( organizationId == null )
return null;
try ( MysqlConnection connection = Database.getConnection() ) {
MysqlStatement stmt = connection.prepareStatement( "SELECT satellitename, addresses, certsha256"
+ " FROM satellite WHERE organizationid = :organizationid" );
stmt.setString( "organizationid", organizationId );
ResultSet rs = stmt.executeQuery();
List<Satellite> list = new ArrayList<>();
while ( rs.next() ) {
List<String> al = Arrays.asList( Json.deserialize( rs.getString( "addresses" ), String[].class ) );
byte[] certBytes = rs.getBytes( "certsha256" );
ByteBuffer cert = null;
if ( certBytes != null ) {
cert = ByteBuffer.wrap( certBytes );
}
list.add( new Satellite( al, rs.getString( "satellitename" ), cert ) );
}
return list;
} catch ( SQLException e ) {
LOGGER.error( "Query failed in DbSatellite.getSatellites()", e );
throw e;
}
}
public static LocalSatellite get( String organizationId, String displayName )
{
// TODO Auto-generated method stub
return null;
}
}
|