1 package org.openslx.imagemaster.db.mappers;
3 import java.sql.ResultSet;
4 import java.sql.SQLException;
5 import java.util.ArrayList;
8 import org.apache.logging.log4j.LogManager;
9 import org.apache.logging.log4j.Logger;
10 import org.
openslx.bwlp.thrift.iface.Organization;
24 +
" o.organizationid, o.name, o.authmethod, o.publickey"
25 +
" FROM organization o";
28 +
" WHERE organizationid = :organizationid";
32 String organizationId = rs.getString(
"organizationid" );
33 String ecpUrl = rs.getString(
"authmethod" );
34 if ( ecpUrl != null && !ecpUrl.startsWith(
"http" ) ) {
37 return new Organization( organizationId, rs.getString(
"name" ), ecpUrl,
getSuffixList( connection,
51 MysqlStatement stmt = connection.prepareStatement( organizationBaseSql +
" WHERE o.organizationid = :organizationid" );
52 stmt.
setString(
"organizationid", organizationId );
57 }
catch ( SQLException e ) {
58 LOGGER.error(
"Query failed in DbOrganization.fromOrganizationId()", e );
63 public static Organization
fromSuffix( String suffix )
throws SQLException
66 MysqlStatement stmt = connection.prepareStatement( organizationBaseSql
67 +
" INNER JOIN organization_suffix s USING (organizationid)"
68 +
" WHERE s.suffix = :suffix" );
74 }
catch ( SQLException e ) {
75 LOGGER.error(
"Query failed in DbOrganization.fromSuffix()", e );
82 stmt.setString(
"organizationid", organizationId );
83 ResultSet rs = stmt.executeQuery();
84 List<String> list =
new ArrayList<>();
86 list.add( rs.getString(
"suffix" ) );
98 public static List<Organization>
getAll() throws SQLException
101 MysqlStatement stmt = connection.prepareStatement( organizationBaseSql );
103 MysqlStatement stmtSuffix = connection.prepareStatement( suffixListFromOrgSql );
104 List<Organization> list =
new ArrayList<>();
105 while ( rsOrg.next() ) {
106 String organizationId = rsOrg.getString(
"organizationid" );
107 String ecpUrl = rsOrg.getString(
"authmethod" );
108 if ( ecpUrl != null && !ecpUrl.startsWith(
"http" ) ) {
111 List<String> suffixList =
suffixForOrg( stmtSuffix, organizationId );
112 list.add(
new Organization( organizationId, rsOrg.getString(
"name" ), ecpUrl, suffixList ) );
115 }
catch ( SQLException e ) {
116 LOGGER.error(
"Query failed in DbOrganization.getAll()", e );
128 List<String> list =
new ArrayList<>();
129 MysqlStatement stmt = connection.prepareStatement( suffixListFromOrgSql );
130 stmt.
setString(
"organizationid", organizationId );
131 ResultSet rs = stmt.executeQuery();
132 while ( rs.next() ) {
133 list.add( rs.getString(
"suffix" ) );
static List< Organization > getAll()
Return all known satellites/organizations as List of OrganizationData, which can be used directly by ...
static List< String > suffixForOrg(MysqlStatement stmt, String organizationId)
static MysqlConnection getConnection()
Get a connection to the database.
ResultSet executeQuery()
Executes the statement, which must be a query.
Represents an organization in the database.
void setString(String name, String value)
Sets a parameter.
static final Logger LOGGER
Class for creating PreparedStatements with named parameters.
static DbOrganization fromPrefix(String prefix)
static Organization fromSuffix(String suffix)
static Organization fromResultSet(MysqlConnection connection, ResultSet rs)
static List< String > getSuffixList(MysqlConnection connection, String organizationId)
static final String organizationBaseSql
static Organization fromOrganizationId(String organizationId)
Get organization by id.
static final String suffixListFromOrgSql