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.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 = Logger.getLogger( DbSatellite.class ); public static LocalSatellite get( int satelliteId ) { return null; } public static List getSatellites( UserInfo ui ) throws SQLException { if ( ui == null ) return null; return getSatellites( ui.organizationId ); } public static List 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 list = new ArrayList<>(); while ( rs.next() ) { List al = Arrays.asList( Json.deserialize( rs.getString( "addresses" ), String[].class ) ); list.add( new Satellite( al, rs.getString( "satellitename" ), ByteBuffer.wrap( rs.getBytes( "certsha256" ) ) ) ); } 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; } }