adding database changes

revert-70aa11f8
inosh-perera 9 years ago
parent fbc7c0807c
commit 41ba2f4f0a

@ -18,6 +18,7 @@
package org.wso2.carbon.certificate.mgt.core.dao;
import org.wso2.carbon.certificate.mgt.core.dto.CertificateResponse;
import org.wso2.carbon.device.mgt.common.PaginationRequest;
import org.wso2.carbon.device.mgt.common.PaginationResult;
@ -58,6 +59,13 @@ public interface CertificateDAO {
*/
PaginationResult getAllCertificates(PaginationRequest request) throws CertificateManagementDAOException;
/**
* Get all the certificates.
* @return List of certificates
* @throws CertificateManagementDAOException
*/
public List<CertificateResponse> getAllCertificates() throws CertificateManagementDAOException;
/**
* Delete a certificate identified by a serial number()
* @param serialNumber serial number

@ -157,6 +157,39 @@ public class GenericCertificateDAOImpl implements CertificateDAO {
return paginationResult;
}
@Override
public List<CertificateResponse> getAllCertificates() throws CertificateManagementDAOException {
PreparedStatement stmt = null;
ResultSet resultSet = null;
CertificateResponse certificateResponse;
List<CertificateResponse> certificates = new ArrayList<>();
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
try {
Connection conn = this.getConnection();
String sql = "SELECT CERTIFICATE, SERIAL_NUMBER, TENANT_ID FROM DM_DEVICE_CERTIFICATE WHERE TENANT_ID = ? " +
"ORDER BY ID DESC";
stmt = conn.prepareStatement(sql);
stmt.setInt(1, tenantId);
resultSet = stmt.executeQuery();
while (resultSet.next()) {
certificateResponse = new CertificateResponse();
byte [] certificateBytes = resultSet.getBytes("CERTIFICATE");
certificateResponse.setSerialNumber(resultSet.getString("SERIAL_NUMBER"));
certificateResponse.setTenantId(resultSet.getInt("TENANT_ID"));
CertificateGenerator.extractCertificateDetails(certificateBytes, certificateResponse);
certificates.add(certificateResponse);
}
} catch (SQLException e) {
String errorMsg = "SQL error occurred while retrieving the certificates.";
log.error(errorMsg, e);
throw new CertificateManagementDAOException(errorMsg, e);
} finally {
OperationManagementDAOUtil.cleanupResources(stmt, resultSet);
}
return certificates;
}
@Override
public boolean removeCertificate(String serialNumber) throws CertificateManagementDAOException {
Connection conn;

@ -74,4 +74,6 @@ public interface CertificateManagementService {
public PaginationResult getAllCertificates(PaginationRequest request) throws CertificateManagementDAOException;
boolean removeCertificate(String serialNumber) throws CertificateManagementDAOException;
public List<CertificateResponse> getCertificates() throws CertificateManagementDAOException;
}

@ -177,4 +177,19 @@ public class CertificateManagementServiceImpl implements CertificateManagementSe
}
}
@Override
public List<CertificateResponse> getCertificates() throws CertificateManagementDAOException {
try {
CertificateManagementDAOFactory.openConnection();
CertificateDAO certificateDAO = CertificateManagementDAOFactory.getCertificateDAO();
return certificateDAO.getAllCertificates();
} catch (SQLException e) {
String errorMsg = "Error when opening connection";
log.error(errorMsg, e);
throw new CertificateManagementDAOException(errorMsg, e);
} finally {
CertificateManagementDAOFactory.closeConnection();
}
}
}

@ -217,7 +217,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE_POLICY (
CREATE TABLE IF NOT EXISTS DM_PROFILE_FEATURES (
ID INT(11) NOT NULL AUTO_INCREMENT,
PROFILE_ID INT(11) NOT NULL,
FEATURE_CODE VARCHAR(30) NOT NULL,
FEATURE_CODE VARCHAR(100) NOT NULL,
DEVICE_TYPE_ID INT NOT NULL,
TENANT_ID INT(11) NOT NULL ,
CONTENT BLOB NULL DEFAULT NULL,
@ -349,7 +349,7 @@ CREATE TABLE IF NOT EXISTS DM_POLICY_COMPLIANCE_FEATURES (
ID INT NOT NULL AUTO_INCREMENT,
COMPLIANCE_STATUS_ID INT NOT NULL,
TENANT_ID INT NOT NULL,
FEATURE_CODE VARCHAR(15) NOT NULL,
FEATURE_CODE VARCHAR(100) NOT NULL,
STATUS INT NULL,
PRIMARY KEY (ID),
CONSTRAINT FK_COMPLIANCE_FEATURES_STATUS

@ -8,6 +8,7 @@ CREATE TABLE DM_DEVICE_CERTIFICATE (
ID INTEGER IDENTITY NOT NULL,
SERIAL_NUMBER VARCHAR(500) DEFAULT NULL,
CERTIFICATE VARBINARY(max) DEFAULT NULL,
TENANT_ID INTEGER DEFAULT 0,
PRIMARY KEY (ID)
);
@ -196,7 +197,7 @@ CREATE TABLE DM_DEVICE_TYPE_POLICY (
CREATE TABLE DM_PROFILE_FEATURES (
ID INT NOT NULL IDENTITY,
PROFILE_ID INT NOT NULL,
FEATURE_CODE VARCHAR(30) NOT NULL,
FEATURE_CODE VARCHAR(100) NOT NULL,
DEVICE_TYPE_ID INT NOT NULL,
TENANT_ID INT NOT NULL ,
CONTENT VARBINARY(max) NULL DEFAULT NULL,
@ -328,7 +329,7 @@ CREATE TABLE DM_POLICY_COMPLIANCE_FEATURES (
ID INT NOT NULL IDENTITY,
COMPLIANCE_STATUS_ID INT NOT NULL,
TENANT_ID INT NOT NULL,
FEATURE_CODE VARCHAR(15) NOT NULL,
FEATURE_CODE VARCHAR(100) NOT NULL,
STATUS INT NULL,
PRIMARY KEY (ID),
CONSTRAINT FK_COMPLIANCE_FEATURES_STATUS

@ -8,6 +8,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_CERTIFICATE (
ID INTEGER auto_increment NOT NULL,
SERIAL_NUMBER VARCHAR(500) DEFAULT NULL,
CERTIFICATE BLOB DEFAULT NULL,
TENANT_ID INTEGER DEFAULT 0,
PRIMARY KEY (ID)
)ENGINE = InnoDB;
@ -191,7 +192,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE_POLICY (
CREATE TABLE IF NOT EXISTS DM_PROFILE_FEATURES (
ID INT(11) NOT NULL AUTO_INCREMENT,
PROFILE_ID INT(11) NOT NULL,
FEATURE_CODE VARCHAR(30) NOT NULL,
FEATURE_CODE VARCHAR(100) NOT NULL,
DEVICE_TYPE_ID INT NOT NULL,
TENANT_ID INT(11) NOT NULL ,
CONTENT BLOB NULL DEFAULT NULL,
@ -319,7 +320,7 @@ CREATE TABLE IF NOT EXISTS DM_POLICY_COMPLIANCE_FEATURES (
ID INT NOT NULL AUTO_INCREMENT,
COMPLIANCE_STATUS_ID INT NOT NULL,
TENANT_ID INT NOT NULL,
FEATURE_CODE VARCHAR(15) NOT NULL,
FEATURE_CODE VARCHAR(100) NOT NULL,
STATUS INT NULL,
PRIMARY KEY (ID),
CONSTRAINT FK_COMPLIANCE_FEATURES_STATUS

@ -22,6 +22,7 @@ CREATE TABLE DM_DEVICE_CERTIFICATE (
ID NUMBER(10) NOT NULL,
SERIAL_NUMBER VARCHAR2(500) DEFAULT NULL,
CERTIFICATE BLOB DEFAULT NULL,
TENANT_ID NUMBER(10) DEFAULT 0,
PRIMARY KEY (ID)
)
/
@ -308,7 +309,7 @@ CREATE TABLE DM_DEVICE_TYPE_POLICY (
CREATE TABLE DM_PROFILE_FEATURES (
ID NUMBER(10) NOT NULL,
PROFILE_ID NUMBER(10) NOT NULL,
FEATURE_CODE VARCHAR2(30) NOT NULL,
FEATURE_CODE VARCHAR2(100) NOT NULL,
DEVICE_TYPE_ID NUMBER(10) NOT NULL,
TENANT_ID NUMBER(10) NOT NULL ,
CONTENT BLOB DEFAULT NULL NULL,
@ -543,7 +544,7 @@ CREATE TABLE DM_POLICY_COMPLIANCE_FEATURES (
ID NUMBER(10) NOT NULL,
COMPLIANCE_STATUS_ID NUMBER(10) NOT NULL,
TENANT_ID NUMBER(10) NOT NULL,
FEATURE_CODE VARCHAR2(15) NOT NULL,
FEATURE_CODE VARCHAR2(100) NOT NULL,
STATUS NUMBER(10) NULL,
CONSTRAINT PK_COMPLIANCE_FEATURES_STATUS PRIMARY KEY (ID),
CONSTRAINT FK_COMPLIANCE_FEATURES_STATUS

@ -7,6 +7,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_CERTIFICATE (
ID BIGSERIAL NOT NULL PRIMARY KEY,
SERIAL_NUMBER VARCHAR(500) DEFAULT NULL,
CERTIFICATE BYTEA DEFAULT NULL
TENANT_ID INTEGER DEFAULT 0,
);
CREATE TABLE IF NOT EXISTS DM_DEVICE (
@ -169,7 +170,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE_POLICY (
CREATE TABLE IF NOT EXISTS DM_PROFILE_FEATURES (
ID BIGSERIAL NOT NULL PRIMARY KEY,
PROFILE_ID INTEGER NOT NULL,
FEATURE_CODE VARCHAR(30) NOT NULL,
FEATURE_CODE VARCHAR(100) NOT NULL,
DEVICE_TYPE_ID INT NOT NULL,
TENANT_ID INTEGER NOT NULL ,
CONTENT BYTEA NULL DEFAULT NULL,
@ -280,7 +281,7 @@ CREATE TABLE IF NOT EXISTS DM_POLICY_COMPLIANCE_FEATURES (
ID BIGSERIAL NOT NULL PRIMARY KEY,
COMPLIANCE_STATUS_ID INTEGER NOT NULL,
TENANT_ID INTEGER NOT NULL,
FEATURE_CODE VARCHAR(15) NOT NULL,
FEATURE_CODE VARCHAR(100) NOT NULL,
STATUS INTEGER NULL,
CONSTRAINT FK_COMPLIANCE_FEATURES_STATUS
FOREIGN KEY (COMPLIANCE_STATUS_ID)

Loading…
Cancel
Save