Fix sql query columns

Add createIdentityServer method to all DAOs
feature/traccar-sync
Mohamed Rashd 3 years ago
parent 3dd0690552
commit 3f60a0cdda

@ -26,7 +26,7 @@ import java.util.List;
public interface SPApplicationDAO { public interface SPApplicationDAO {
int createIdentityServer(IdentityServerDTO identityServer, int tenantId) throws ApplicationManagementDAOException; int createIdentityServer(IdentityServerDTO identityServerDTO, int tenantId) throws ApplicationManagementDAOException;
/** /**
* *

@ -41,7 +41,7 @@ public class GenericSPApplicationDAOImpl extends AbstractDAOImpl implements SPAp
private static final Log log = LogFactory.getLog(GenericApplicationDAOImpl.class); private static final Log log = LogFactory.getLog(GenericApplicationDAOImpl.class);
@Override @Override
public List<IdentityServerDTO> getIdentityServers(int tenantId) throws ApplicationManagementDAOException { public List<IdentityServerDTO> getIdentityServers(int tenantId) throws ApplicationManagementDAOException {
String sql = "SELECT ID, NAME, DESCRIPTION, URL, SP_APPS_URI, SP_APPS_API, TENANT_ID, USERNAME, PASSWORD " String sql = "SELECT ID, PROVIDER_NAME, NAME, DESCRIPTION, URL, API_URL, USERNAME, PASSWORD, TENANT_ID "
+ "FROM AP_IDENTITY_SERVER " + "FROM AP_IDENTITY_SERVER "
+ "WHERE TENANT_ID = ?"; + "WHERE TENANT_ID = ?";
try { try {
@ -68,7 +68,7 @@ public class GenericSPApplicationDAOImpl extends AbstractDAOImpl implements SPAp
@Override @Override
public IdentityServerDTO getIdentityServerById(int id, int tenantId) throws ApplicationManagementDAOException { public IdentityServerDTO getIdentityServerById(int id, int tenantId) throws ApplicationManagementDAOException {
String sql = "SELECT ID, NAME, DESCRIPTION, URL, SP_APPS_URI, SP_APPS_API, TENANT_ID, USERNAME, PASSWORD " String sql = "SELECT ID, PROVIDER_NAME, NAME, DESCRIPTION, URL, API_URL, USERNAME, PASSWORD, TENANT_ID "
+ "FROM AP_IDENTITY_SERVER " + "FROM AP_IDENTITY_SERVER "
+ "WHERE TENANT_ID = ? AND " + "WHERE TENANT_ID = ? AND "
+ "ID = ?"; + "ID = ?";

@ -41,7 +41,7 @@ public class OracleSPApplicationDAOImpl extends AbstractDAOImpl implements SPAp
@Override @Override
public List<IdentityServerDTO> getIdentityServers(int tenantId) throws ApplicationManagementDAOException { public List<IdentityServerDTO> getIdentityServers(int tenantId) throws ApplicationManagementDAOException {
String sql = "SELECT ID, NAME, DESCRIPTION, URL, SP_APPS_URI, SP_APPS_API, TENANT_ID, USERNAME, PASSWORD " String sql = "SELECT ID, PROVIDER_NAME, NAME, DESCRIPTION, URL, API_URL, USERNAME, PASSWORD, TENANT_ID "
+ "FROM AP_IDENTITY_SERVER " + "FROM AP_IDENTITY_SERVER "
+ "WHERE TENANT_ID = ?"; + "WHERE TENANT_ID = ?";
try { try {
@ -68,7 +68,7 @@ public class OracleSPApplicationDAOImpl extends AbstractDAOImpl implements SPAp
@Override @Override
public IdentityServerDTO getIdentityServerById(int id, int tenantId) throws ApplicationManagementDAOException { public IdentityServerDTO getIdentityServerById(int id, int tenantId) throws ApplicationManagementDAOException {
String sql = "SELECT ID, NAME, DESCRIPTION, URL, SP_APPS_URI, SP_APPS_API, TENANT_ID, USERNAME, PASSWORD " String sql = "SELECT ID, PROVIDER_NAME, NAME, DESCRIPTION, URL, API_URL, USERNAME, PASSWORD, TENANT_ID "
+ "FROM AP_IDENTITY_SERVER " + "FROM AP_IDENTITY_SERVER "
+ "WHERE TENANT_ID = ? AND " + "WHERE TENANT_ID = ? AND "
+ "ID = ?"; + "ID = ?";
@ -99,6 +99,46 @@ public class OracleSPApplicationDAOImpl extends AbstractDAOImpl implements SPAp
} }
} }
@Override
public int createIdentityServer(IdentityServerDTO identityServerDTO, int tenantId) throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to create an identity server");
}
String sql = "INSERT INTO AP_IDENTITY_SERVER "
+ "(PROVIDER_NAME, "
+ "NAME, "
+ "DESCRIPTION, URL, API_URL, USERNAME, PASSWORD, TENANT_ID) "
+ "VALUES (?, ?, ?, ?)";
try {
Connection conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) {
stmt.setString(1, identityServerDTO.getProviderName());
stmt.setString(2, identityServerDTO.getName());
stmt.setString(3, identityServerDTO.getDescription());
stmt.setString(4, identityServerDTO.getUrl());
stmt.setString(5, identityServerDTO.getApiUrl());
stmt.setString(6, identityServerDTO.getUserName());
stmt.setString(7, identityServerDTO.getPassword());
stmt.setInt(8, tenantId);
stmt.executeUpdate();
try (ResultSet rs = stmt.getGeneratedKeys()) {
if (rs.next()) {
return rs.getInt(1);
}
return -1;
}
}
} catch (DBConnectionException e) {
String msg = "Error occurred while creating identity server ";
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
} catch (SQLException e) {
String msg = "Error occurred while executing SQL to create an identity server ";
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
}
}
@Override @Override
public List<ApplicationDTO> getSPApplications(int identityServerId, String spUID, int tenantId) throws ApplicationManagementDAOException { public List<ApplicationDTO> getSPApplications(int identityServerId, String spUID, int tenantId) throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {

@ -41,7 +41,7 @@ public class PostgreSQLSPApplicationDAOImpl extends AbstractDAOImpl implements S
@Override @Override
public List<IdentityServerDTO> getIdentityServers(int tenantId) throws ApplicationManagementDAOException { public List<IdentityServerDTO> getIdentityServers(int tenantId) throws ApplicationManagementDAOException {
String sql = "SELECT ID, NAME, DESCRIPTION, URL, SP_APPS_URI, SP_APPS_API, TENANT_ID, USERNAME, PASSWORD " String sql = "SELECT ID, PROVIDER_NAME, NAME, DESCRIPTION, URL, API_URL, USERNAME, PASSWORD, TENANT_ID "
+ "FROM AP_IDENTITY_SERVER " + "FROM AP_IDENTITY_SERVER "
+ "WHERE TENANT_ID = ?"; + "WHERE TENANT_ID = ?";
try { try {
@ -68,7 +68,7 @@ public class PostgreSQLSPApplicationDAOImpl extends AbstractDAOImpl implements S
@Override @Override
public IdentityServerDTO getIdentityServerById(int id, int tenantId) throws ApplicationManagementDAOException { public IdentityServerDTO getIdentityServerById(int id, int tenantId) throws ApplicationManagementDAOException {
String sql = "SELECT ID, NAME, DESCRIPTION, URL, SP_APPS_URI, SP_APPS_API, TENANT_ID, USERNAME, PASSWORD " String sql = "SELECT ID, PROVIDER_NAME, NAME, DESCRIPTION, URL, API_URL, USERNAME, PASSWORD, TENANT_ID "
+ "FROM AP_IDENTITY_SERVER " + "FROM AP_IDENTITY_SERVER "
+ "WHERE TENANT_ID = ? AND " + "WHERE TENANT_ID = ? AND "
+ "ID = ?"; + "ID = ?";
@ -99,6 +99,46 @@ public class PostgreSQLSPApplicationDAOImpl extends AbstractDAOImpl implements S
} }
} }
@Override
public int createIdentityServer(IdentityServerDTO identityServerDTO, int tenantId) throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to create an identity server");
}
String sql = "INSERT INTO AP_IDENTITY_SERVER "
+ "(PROVIDER_NAME, "
+ "NAME, "
+ "DESCRIPTION, URL, API_URL, USERNAME, PASSWORD, TENANT_ID) "
+ "VALUES (?, ?, ?, ?)";
try {
Connection conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) {
stmt.setString(1, identityServerDTO.getProviderName());
stmt.setString(2, identityServerDTO.getName());
stmt.setString(3, identityServerDTO.getDescription());
stmt.setString(4, identityServerDTO.getUrl());
stmt.setString(5, identityServerDTO.getApiUrl());
stmt.setString(6, identityServerDTO.getUserName());
stmt.setString(7, identityServerDTO.getPassword());
stmt.setInt(8, tenantId);
stmt.executeUpdate();
try (ResultSet rs = stmt.getGeneratedKeys()) {
if (rs.next()) {
return rs.getInt(1);
}
return -1;
}
}
} catch (DBConnectionException e) {
String msg = "Error occurred while creating identity server ";
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
} catch (SQLException e) {
String msg = "Error occurred while executing SQL to create an identity server ";
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
}
}
@Override @Override
public List<ApplicationDTO> getSPApplications(int identityServerId, String spUID, int tenantId) throws ApplicationManagementDAOException { public List<ApplicationDTO> getSPApplications(int identityServerId, String spUID, int tenantId) throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {

@ -41,7 +41,7 @@ public class SQLServerSPApplicationDAOImpl extends AbstractDAOImpl implements S
@Override @Override
public List<IdentityServerDTO> getIdentityServers(int tenantId) throws ApplicationManagementDAOException { public List<IdentityServerDTO> getIdentityServers(int tenantId) throws ApplicationManagementDAOException {
String sql = "SELECT ID, NAME, DESCRIPTION, URL, SP_APPS_URI, SP_APPS_API, TENANT_ID, USERNAME, PASSWORD " String sql = "SELECT ID, PROVIDER_NAME, NAME, DESCRIPTION, URL, API_URL, USERNAME, PASSWORD, TENANT_ID "
+ "FROM AP_IDENTITY_SERVER " + "FROM AP_IDENTITY_SERVER "
+ "WHERE TENANT_ID = ?"; + "WHERE TENANT_ID = ?";
try { try {
@ -68,7 +68,7 @@ public class SQLServerSPApplicationDAOImpl extends AbstractDAOImpl implements S
@Override @Override
public IdentityServerDTO getIdentityServerById(int id, int tenantId) throws ApplicationManagementDAOException { public IdentityServerDTO getIdentityServerById(int id, int tenantId) throws ApplicationManagementDAOException {
String sql = "SELECT ID, NAME, DESCRIPTION, URL, SP_APPS_URI, SP_APPS_API, TENANT_ID, USERNAME, PASSWORD " String sql = "SELECT ID, PROVIDER_NAME, NAME, DESCRIPTION, URL, API_URL, USERNAME, PASSWORD, TENANT_ID "
+ "FROM AP_IDENTITY_SERVER " + "FROM AP_IDENTITY_SERVER "
+ "WHERE TENANT_ID = ? AND " + "WHERE TENANT_ID = ? AND "
+ "ID = ?"; + "ID = ?";
@ -99,6 +99,46 @@ public class SQLServerSPApplicationDAOImpl extends AbstractDAOImpl implements S
} }
} }
@Override
public int createIdentityServer(IdentityServerDTO identityServerDTO, int tenantId) throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to create an identity server");
}
String sql = "INSERT INTO AP_IDENTITY_SERVER "
+ "(PROVIDER_NAME, "
+ "NAME, "
+ "DESCRIPTION, URL, API_URL, USERNAME, PASSWORD, TENANT_ID) "
+ "VALUES (?, ?, ?, ?)";
try {
Connection conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) {
stmt.setString(1, identityServerDTO.getProviderName());
stmt.setString(2, identityServerDTO.getName());
stmt.setString(3, identityServerDTO.getDescription());
stmt.setString(4, identityServerDTO.getUrl());
stmt.setString(5, identityServerDTO.getApiUrl());
stmt.setString(6, identityServerDTO.getUserName());
stmt.setString(7, identityServerDTO.getPassword());
stmt.setInt(8, tenantId);
stmt.executeUpdate();
try (ResultSet rs = stmt.getGeneratedKeys()) {
if (rs.next()) {
return rs.getInt(1);
}
return -1;
}
}
} catch (DBConnectionException e) {
String msg = "Error occurred while creating identity server ";
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
} catch (SQLException e) {
String msg = "Error occurred while executing SQL to create an identity server ";
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
}
}
@Override @Override
public List<ApplicationDTO> getSPApplications(int identityServerId, String spUID, int tenantId) throws ApplicationManagementDAOException { public List<ApplicationDTO> getSPApplications(int identityServerId, String spUID, int tenantId) throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {

Loading…
Cancel
Save