Merge branch 'dilee-master'

revert-70aa11f8
harshanl 9 years ago
commit 26e3183abe

@ -26,7 +26,7 @@ public interface ApplicationMappingDAO {
int addApplicationMapping(int deviceId, int applicationId, int tenantId) throws DeviceManagementDAOException; int addApplicationMapping(int deviceId, int applicationId, int tenantId) throws DeviceManagementDAOException;
List<Integer> addApplicationMappings(int deviceId, List<Integer> applicationIds, int tenantId) void addApplicationMappings(int deviceId, List<Integer> applicationIds, int tenantId)
throws DeviceManagementDAOException; throws DeviceManagementDAOException;
void removeApplicationMapping(int deviceId, List<Integer> appIdList, int tenantId) void removeApplicationMapping(int deviceId, List<Integer> appIdList, int tenantId)

@ -46,7 +46,7 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
conn = this.getConnection(); conn = this.getConnection();
String sql = "INSERT INTO DM_DEVICE(DESCRIPTION, NAME, DEVICE_TYPE_ID, DEVICE_IDENTIFICATION, TENANT_ID) " + String sql = "INSERT INTO DM_DEVICE(DESCRIPTION, NAME, DEVICE_TYPE_ID, DEVICE_IDENTIFICATION, TENANT_ID) " +
"VALUES (?, ?, ?, ?, ?)"; "VALUES (?, ?, ?, ?, ?)";
stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS); stmt = conn.prepareStatement(sql, new String[] {"id"});
stmt.setString(1, device.getDescription()); stmt.setString(1, device.getDescription());
stmt.setString(2, device.getName()); stmt.setString(2, device.getName());
stmt.setInt(3, typeId); stmt.setInt(3, typeId);
@ -77,7 +77,7 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
conn = this.getConnection(); conn = this.getConnection();
String sql = "UPDATE DM_DEVICE SET DESCRIPTION = ?, NAME = ? WHERE DEVICE_IDENTIFICATION = ? AND " + String sql = "UPDATE DM_DEVICE SET DESCRIPTION = ?, NAME = ? WHERE DEVICE_IDENTIFICATION = ? AND " +
"DEVICE_TYPE_ID = ? AND TENANT_ID = ?"; "DEVICE_TYPE_ID = ? AND TENANT_ID = ?";
stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS); stmt = conn.prepareStatement(sql, new String[] {"id"});
stmt.setString(1, device.getDescription()); stmt.setString(1, device.getDescription());
stmt.setString(2, device.getName()); stmt.setString(2, device.getName());
stmt.setString(3, device.getDeviceIdentifier()); stmt.setString(3, device.getDeviceIdentifier());
@ -433,7 +433,7 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
conn = this.getConnection(); conn = this.getConnection();
String sql = "INSERT INTO DM_ENROLMENT(DEVICE_ID, OWNER, OWNERSHIP, STATUS,DATE_OF_ENROLMENT, " + String sql = "INSERT INTO DM_ENROLMENT(DEVICE_ID, OWNER, OWNERSHIP, STATUS,DATE_OF_ENROLMENT, " +
"DATE_OF_LAST_UPDATE, TENANT_ID) VALUES(?, ?, ?, ?, ?, ?, ?)"; "DATE_OF_LAST_UPDATE, TENANT_ID) VALUES(?, ?, ?, ?, ?, ?, ?)";
stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS); stmt = conn.prepareStatement(sql, new String[] {"id"});
stmt.setInt(1, device.getId()); stmt.setInt(1, device.getId());
stmt.setString(2, device.getEnrolmentInfo().getOwner()); stmt.setString(2, device.getEnrolmentInfo().getOwner());
stmt.setString(3, device.getEnrolmentInfo().getOwnership().toString()); stmt.setString(3, device.getEnrolmentInfo().getOwnership().toString());

@ -86,7 +86,7 @@ public class ApplicationDAOImpl implements ApplicationDAO {
conn = this.getConnection(); conn = this.getConnection();
stmt = conn.prepareStatement("INSERT INTO DM_APPLICATION (NAME, PLATFORM, CATEGORY, " + stmt = conn.prepareStatement("INSERT INTO DM_APPLICATION (NAME, PLATFORM, CATEGORY, " +
"VERSION, TYPE, LOCATION_URL, IMAGE_URL, TENANT_ID,APP_PROPERTIES,APP_IDENTIFIER) " + "VERSION, TYPE, LOCATION_URL, IMAGE_URL, TENANT_ID,APP_PROPERTIES,APP_IDENTIFIER) " +
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?,?)", PreparedStatement.RETURN_GENERATED_KEYS); "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?,?)", new String[] {"id"});
for (Application application : applications) { for (Application application : applications) {
@ -126,7 +126,7 @@ public class ApplicationDAOImpl implements ApplicationDAO {
conn = this.getConnection(); conn = this.getConnection();
conn.setAutoCommit(false); conn.setAutoCommit(false);
stmt = conn.prepareStatement("DELETE DM_APPLICATION WHERE APP_IDENTIFIER = ? AND TENANT_ID = ?", stmt = conn.prepareStatement("DELETE DM_APPLICATION WHERE APP_IDENTIFIER = ? AND TENANT_ID = ?",
Statement.RETURN_GENERATED_KEYS); new String[] {"id"});
for (Application app : apps) { for (Application app : apps) {
stmt.setString(1, app.getApplicationIdentifier()); stmt.setString(1, app.getApplicationIdentifier());

@ -49,7 +49,7 @@ public class ApplicationMappingDAOImpl implements ApplicationMappingDAO {
conn = this.getConnection(); conn = this.getConnection();
String sql = "INSERT INTO DM_DEVICE_APPLICATION_MAPPING (DEVICE_ID, APPLICATION_ID, " + String sql = "INSERT INTO DM_DEVICE_APPLICATION_MAPPING (DEVICE_ID, APPLICATION_ID, " +
"TENANT_ID) VALUES (?, ?, ?)"; "TENANT_ID) VALUES (?, ?, ?)";
stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS); stmt = conn.prepareStatement(sql, new String[] {"id"});
stmt.setInt(1, deviceId); stmt.setInt(1, deviceId);
stmt.setInt(2, applicationId); stmt.setInt(2, applicationId);
stmt.setInt(3, tenantId); stmt.setInt(3, tenantId);
@ -68,17 +68,17 @@ public class ApplicationMappingDAOImpl implements ApplicationMappingDAO {
} }
@Override @Override
public List<Integer> addApplicationMappings(int deviceId, List<Integer> applicationIds, public void addApplicationMappings(int deviceId, List<Integer> applicationIds,
int tenantId) throws DeviceManagementDAOException { int tenantId) throws DeviceManagementDAOException {
Connection conn; Connection conn;
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; ResultSet rs = null;
List<Integer> mappingIds = new ArrayList<>();
try { try {
conn = this.getConnection(); conn = this.getConnection();
String sql = "INSERT INTO DM_DEVICE_APPLICATION_MAPPING (DEVICE_ID, APPLICATION_ID, " + String sql = "INSERT INTO DM_DEVICE_APPLICATION_MAPPING (DEVICE_ID, APPLICATION_ID, " +
"TENANT_ID) VALUES (?, ?, ?)"; "TENANT_ID) VALUES (?, ?, ?)";
stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS); stmt = conn.prepareStatement(sql);
for (int applicationId : applicationIds) { for (int applicationId : applicationIds) {
stmt.setInt(1, deviceId); stmt.setInt(1, deviceId);
@ -88,11 +88,11 @@ public class ApplicationMappingDAOImpl implements ApplicationMappingDAO {
} }
stmt.executeBatch(); stmt.executeBatch();
rs = stmt.getGeneratedKeys(); // rs = stmt.getGeneratedKeys();
while (rs.next()) { // while (rs.next()) {
mappingIds.add(rs.getInt(1)); // mappingIds.add(rs.getInt(1));
} // }
return mappingIds; // return mappingIds;
} catch (SQLException e) { } catch (SQLException e) {
throw new DeviceManagementDAOException("Error occurred while adding device application mappings", e); throw new DeviceManagementDAOException("Error occurred while adding device application mappings", e);
} finally { } finally {
@ -109,7 +109,7 @@ public class ApplicationMappingDAOImpl implements ApplicationMappingDAO {
conn = this.getConnection(); conn = this.getConnection();
String sql = "DELETE DM_DEVICE_APPLICATION_MAPPING WHERE DEVICE_ID = ? AND " + String sql = "DELETE DM_DEVICE_APPLICATION_MAPPING WHERE DEVICE_ID = ? AND " +
"APPLICATION_ID = ? AND TENANT_ID = ?"; "APPLICATION_ID = ? AND TENANT_ID = ?";
stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS); stmt = conn.prepareStatement(sql);
for (Integer appId : appIdList) { for (Integer appId : appIdList) {
stmt.setInt(1, deviceId); stmt.setInt(1, deviceId);

@ -42,7 +42,7 @@ public class EnrollmentDAOImpl implements EnrollmentDAO {
conn = this.getConnection(); conn = this.getConnection();
String sql = "INSERT INTO DM_ENROLMENT(DEVICE_ID, OWNER, OWNERSHIP, STATUS, " + String sql = "INSERT INTO DM_ENROLMENT(DEVICE_ID, OWNER, OWNERSHIP, STATUS, " +
"DATE_OF_ENROLMENT, DATE_OF_LAST_UPDATE, TENANT_ID) VALUES(?, ?, ?, ?, ?, ?, ?)"; "DATE_OF_ENROLMENT, DATE_OF_LAST_UPDATE, TENANT_ID) VALUES(?, ?, ?, ?, ?, ?, ?)";
stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS); stmt = conn.prepareStatement(sql, new String[] {"id"});
stmt.setInt(1, deviceId); stmt.setInt(1, deviceId);
stmt.setString(2, enrolmentInfo.getOwner()); stmt.setString(2, enrolmentInfo.getOwner());
stmt.setString(3, enrolmentInfo.getOwnership().toString()); stmt.setString(3, enrolmentInfo.getOwnership().toString());
@ -76,7 +76,7 @@ public class EnrollmentDAOImpl implements EnrollmentDAO {
String sql = "UPDATE DM_ENROLMENT SET OWNERSHIP = ?, STATUS = ?, " + String sql = "UPDATE DM_ENROLMENT SET OWNERSHIP = ?, STATUS = ?, " +
"DATE_OF_ENROLMENT = ?, DATE_OF_LAST_UPDATE = ? WHERE DEVICE_ID = ? AND OWNER = ? AND TENANT_ID = ?" + "DATE_OF_ENROLMENT = ?, DATE_OF_LAST_UPDATE = ? WHERE DEVICE_ID = ? AND OWNER = ? AND TENANT_ID = ?" +
" AND ID = ?"; " AND ID = ?";
stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS); stmt = conn.prepareStatement(sql, new String[] {"id"});
stmt.setString(1, enrolmentInfo.getOwnership().toString()); stmt.setString(1, enrolmentInfo.getOwnership().toString());
stmt.setString(2, enrolmentInfo.getStatus().toString()); stmt.setString(2, enrolmentInfo.getStatus().toString());
stmt.setTimestamp(3, new Timestamp(enrolmentInfo.getDateOfEnrolment())); stmt.setTimestamp(3, new Timestamp(enrolmentInfo.getDateOfEnrolment()));
@ -109,7 +109,7 @@ public class EnrollmentDAOImpl implements EnrollmentDAO {
conn = this.getConnection(); conn = this.getConnection();
String sql = "UPDATE DM_ENROLMENT SET OWNERSHIP = ?, STATUS = ?, " + String sql = "UPDATE DM_ENROLMENT SET OWNERSHIP = ?, STATUS = ?, " +
"DATE_OF_ENROLMENT = ?, DATE_OF_LAST_UPDATE = ? WHERE ID = ?"; "DATE_OF_ENROLMENT = ?, DATE_OF_LAST_UPDATE = ? WHERE ID = ?";
stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS); stmt = conn.prepareStatement(sql, new String[] {"id"});
stmt.setString(1, enrolmentInfo.getOwnership().toString()); stmt.setString(1, enrolmentInfo.getOwnership().toString());
stmt.setString(2, enrolmentInfo.getStatus().toString()); stmt.setString(2, enrolmentInfo.getStatus().toString());
stmt.setTimestamp(3, new Timestamp(enrolmentInfo.getDateOfEnrolment())); stmt.setTimestamp(3, new Timestamp(enrolmentInfo.getDateOfEnrolment()));
@ -140,7 +140,7 @@ public class EnrollmentDAOImpl implements EnrollmentDAO {
try { try {
conn = this.getConnection(); conn = this.getConnection();
String sql = "DELETE DM_ENROLMENT WHERE DEVICE_ID = ? AND OWNER = ? AND TENANT_ID = ?"; String sql = "DELETE DM_ENROLMENT WHERE DEVICE_ID = ? AND OWNER = ? AND TENANT_ID = ?";
stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS); stmt = conn.prepareStatement(sql, new String[] {"id"});
stmt.setInt(1, deviceId); stmt.setInt(1, deviceId);
stmt.setString(2, currentOwner); stmt.setString(2, currentOwner);
stmt.setInt(3, tenantId); stmt.setInt(3, tenantId);

@ -45,7 +45,7 @@ public class OperationDAOImpl implements OperationDAO {
Connection connection = OperationManagementDAOFactory.getConnection(); Connection connection = OperationManagementDAOFactory.getConnection();
String sql = "INSERT INTO DM_OPERATION(TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE) " + String sql = "INSERT INTO DM_OPERATION(TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE) " +
"VALUES (?, ?, ?, ?)"; "VALUES (?, ?, ?, ?)";
stmt = connection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS); stmt = connection.prepareStatement(sql, new String[] {"id"});
stmt.setString(1, operation.getType().toString()); stmt.setString(1, operation.getType().toString());
stmt.setTimestamp(2, new Timestamp(new Date().getTime())); stmt.setTimestamp(2, new Timestamp(new Date().getTime()));
stmt.setTimestamp(3, null); stmt.setTimestamp(3, null);

@ -39,6 +39,8 @@ public class PolicyOperationDAOImpl extends OperationDAOImpl {
public int addOperation(Operation operation) throws OperationManagementDAOException { public int addOperation(Operation operation) throws OperationManagementDAOException {
int operationId; int operationId;
PreparedStatement stmt = null; PreparedStatement stmt = null;
ByteArrayOutputStream bao = null;
ObjectOutputStream oos = null;
try { try {
operationId = super.addOperation(operation); operationId = super.addOperation(operation);
operation.setCreatedTimeStamp(new Timestamp(new java.util.Date().getTime()).toString()); operation.setCreatedTimeStamp(new Timestamp(new java.util.Date().getTime()).toString());
@ -48,12 +50,33 @@ public class PolicyOperationDAOImpl extends OperationDAOImpl {
Connection conn = OperationManagementDAOFactory.getConnection(); Connection conn = OperationManagementDAOFactory.getConnection();
stmt = conn.prepareStatement("INSERT INTO DM_POLICY_OPERATION(OPERATION_ID, OPERATION_DETAILS) " + stmt = conn.prepareStatement("INSERT INTO DM_POLICY_OPERATION(OPERATION_ID, OPERATION_DETAILS) " +
"VALUES(?, ?)"); "VALUES(?, ?)");
bao = new ByteArrayOutputStream();
oos = new ObjectOutputStream(bao);
oos.writeObject(operation);
stmt.setInt(1, operationId); stmt.setInt(1, operationId);
stmt.setObject(2, policyOperation); stmt.setBytes(2, bao.toByteArray());
stmt.executeUpdate(); stmt.executeUpdate();
} catch (SQLException e) { } catch (SQLException e) {
throw new OperationManagementDAOException("Error occurred while adding policy operation", e); throw new OperationManagementDAOException("Error occurred while adding policy operation", e);
} catch (IOException e) {
throw new OperationManagementDAOException("Error occurred while serializing policy operation object", e);
} finally { } finally {
if (bao != null) {
try {
bao.close();
} catch (IOException e) {
log.warn("Error occurred while closing ByteArrayOutputStream", e);
}
}
if (oos != null) {
try {
oos.close();
} catch (IOException e) {
log.warn("Error occurred while closing ObjectOutputStream", e);
}
}
OperationManagementDAOUtil.cleanupResources(stmt); OperationManagementDAOUtil.cleanupResources(stmt);
} }
return operationId; return operationId;

@ -37,22 +37,46 @@ public class ProfileOperationDAOImpl extends OperationDAOImpl {
public int addOperation(Operation operation) throws OperationManagementDAOException { public int addOperation(Operation operation) throws OperationManagementDAOException {
PreparedStatement stmt = null; PreparedStatement stmt = null;
ByteArrayOutputStream bao = null;
ObjectOutputStream oos = null;
int operationId; int operationId;
try { try {
operationId = super.addOperation(operation); operationId = super.addOperation(operation);
operation.setCreatedTimeStamp(new Timestamp(new java.util.Date().getTime()).toString()); operation.setCreatedTimeStamp(new Timestamp(new java.util.Date().getTime()).toString());
operation.setId(operationId); operation.setId(operationId);
operation.setEnabled(true); operation.setEnabled(true);
ProfileOperation profileOp = (ProfileOperation) operation; //ProfileOperation profileOp = (ProfileOperation) operation;
Connection conn = OperationManagementDAOFactory.getConnection(); Connection conn = OperationManagementDAOFactory.getConnection();
stmt = conn.prepareStatement("INSERT INTO DM_PROFILE_OPERATION(OPERATION_ID, OPERATION_DETAILS) " + stmt = conn.prepareStatement("INSERT INTO DM_PROFILE_OPERATION(OPERATION_ID, OPERATION_DETAILS) " +
"VALUES(?, ?)"); "VALUES(?, ?)");
bao = new ByteArrayOutputStream();
oos = new ObjectOutputStream(bao);
oos.writeObject(operation);
stmt.setInt(1, operationId); stmt.setInt(1, operationId);
stmt.setObject(2, profileOp); stmt.setBytes(2, bao.toByteArray());
stmt.executeUpdate(); stmt.executeUpdate();
} catch (SQLException e) { } catch (SQLException e) {
throw new OperationManagementDAOException("Error occurred while adding profile operation", e); throw new OperationManagementDAOException("Error occurred while adding profile operation", e);
} catch (IOException e) {
throw new OperationManagementDAOException("Error occurred while serializing profile operation object", e);
} finally { } finally {
if (bao != null) {
try {
bao.close();
} catch (IOException e) {
log.warn("Error occurred while closing ByteArrayOutputStream", e);
}
}
if (oos != null) {
try {
oos.close();
} catch (IOException e) {
log.warn("Error occurred while closing ObjectOutputStream", e);
}
}
OperationManagementDAOUtil.cleanupResources(stmt); OperationManagementDAOUtil.cleanupResources(stmt);
} }
return operationId; return operationId;

@ -46,7 +46,7 @@ public interface MonitoringDAO {
void setDeviceAsCompliance(int deviceId, int enrolmentId, int policyId) throws MonitoringDAOException; void setDeviceAsCompliance(int deviceId, int enrolmentId, int policyId) throws MonitoringDAOException;
void addNoneComplianceFeatures(int policyComplianceStatusId, int deviceId, List<ComplianceFeature> void addNonComplianceFeatures(int policyComplianceStatusId, int deviceId, List<ComplianceFeature>
complianceFeatures) complianceFeatures)
throws MonitoringDAOException; throws MonitoringDAOException;

@ -67,7 +67,7 @@ public class FeatureDAOImpl implements FeatureDAO {
conn = this.getConnection(); conn = this.getConnection();
String query = "INSERT INTO DM_PROFILE_FEATURES (PROFILE_ID, FEATURE_CODE, DEVICE_TYPE_ID, CONTENT, " + String query = "INSERT INTO DM_PROFILE_FEATURES (PROFILE_ID, FEATURE_CODE, DEVICE_TYPE_ID, CONTENT, " +
"TENANT_ID) VALUES (?, ?, ?, ?, ?)"; "TENANT_ID) VALUES (?, ?, ?, ?, ?)";
stmt = conn.prepareStatement(query, PreparedStatement.RETURN_GENERATED_KEYS); stmt = conn.prepareStatement(query, new String[] {"id"});
for (ProfileFeature feature : features) { for (ProfileFeature feature : features) {
stmt.setInt(1, profileId); stmt.setInt(1, profileId);
@ -113,13 +113,9 @@ public class FeatureDAOImpl implements FeatureDAO {
String query = "UPDATE DM_PROFILE_FEATURES SET CONTENT = ? WHERE PROFILE_ID = ? AND FEATURE_CODE = ? AND" + String query = "UPDATE DM_PROFILE_FEATURES SET CONTENT = ? WHERE PROFILE_ID = ? AND FEATURE_CODE = ? AND" +
" TENANT_ID = ?"; " TENANT_ID = ?";
stmt = conn.prepareStatement(query, PreparedStatement.RETURN_GENERATED_KEYS); stmt = conn.prepareStatement(query);
for (ProfileFeature feature : features) { for (ProfileFeature feature : features) {
if (conn.getMetaData().getDriverName().contains("H2")) {
stmt.setBytes(1, PolicyManagerUtil.getBytes(feature.getContent()));
} else {
stmt.setBytes(1, PolicyManagerUtil.getBytes(feature.getContent())); stmt.setBytes(1, PolicyManagerUtil.getBytes(feature.getContent()));
}
stmt.setInt(2, profileId); stmt.setInt(2, profileId);
stmt.setString(3, feature.getFeatureCode()); stmt.setString(3, feature.getFeatureCode());
stmt.setInt(4, tenantId); stmt.setInt(4, tenantId);

@ -206,7 +206,7 @@ public class MonitoringDAOImpl implements MonitoringDAO {
} }
@Override @Override
public void addNoneComplianceFeatures(int policyComplianceStatusId, int deviceId, List<ComplianceFeature> public void addNonComplianceFeatures(int policyComplianceStatusId, int deviceId, List<ComplianceFeature>
complianceFeatures) throws MonitoringDAOException { complianceFeatures) throws MonitoringDAOException {
Connection conn; Connection conn;
PreparedStatement stmt = null; PreparedStatement stmt = null;
@ -215,7 +215,7 @@ public class MonitoringDAOImpl implements MonitoringDAO {
conn = this.getConnection(); conn = this.getConnection();
String query = "INSERT INTO DM_POLICY_COMPLIANCE_FEATURES (COMPLIANCE_STATUS_ID, FEATURE_CODE, STATUS, " + String query = "INSERT INTO DM_POLICY_COMPLIANCE_FEATURES (COMPLIANCE_STATUS_ID, FEATURE_CODE, STATUS, " +
"TENANT_ID) VALUES (?, ?, ?, ?) "; "TENANT_ID) VALUES (?, ?, ?, ?) ";
stmt = conn.prepareStatement(query, PreparedStatement.RETURN_GENERATED_KEYS); stmt = conn.prepareStatement(query);
for (ComplianceFeature feature : complianceFeatures) { for (ComplianceFeature feature : complianceFeatures) {
stmt.setInt(1, policyComplianceStatusId); stmt.setInt(1, policyComplianceStatusId);
stmt.setString(2, feature.getFeatureCode()); stmt.setString(2, feature.getFeatureCode());

@ -442,7 +442,7 @@ public class PolicyDAOImpl implements PolicyDAO {
try { try {
conn = this.getConnection(); conn = this.getConnection();
String query = "INSERT INTO DM_CRITERIA (TENANT_ID, NAME) VALUES (?, ?)"; String query = "INSERT INTO DM_CRITERIA (TENANT_ID, NAME) VALUES (?, ?)";
stmt = conn.prepareStatement(query, Statement.RETURN_GENERATED_KEYS); stmt = conn.prepareStatement(query, new String[] {"id"});
stmt.setInt(1, tenantId); stmt.setInt(1, tenantId);
stmt.setString(2, criteria.getName()); stmt.setString(2, criteria.getName());
stmt.executeUpdate(); stmt.executeUpdate();
@ -622,7 +622,7 @@ public class PolicyDAOImpl implements PolicyDAO {
try { try {
conn = this.getConnection(); conn = this.getConnection();
String query = "INSERT INTO DM_POLICY_CRITERIA (CRITERIA_ID, POLICY_ID) VALUES (?, ?)"; String query = "INSERT INTO DM_POLICY_CRITERIA (CRITERIA_ID, POLICY_ID) VALUES (?, ?)";
stmt = conn.prepareStatement(query, Statement.RETURN_GENERATED_KEYS); stmt = conn.prepareStatement(query, new String[] {"id"});
List<PolicyCriterion> criteria = policy.getPolicyCriterias(); List<PolicyCriterion> criteria = policy.getPolicyCriterias();
for (PolicyCriterion criterion : criteria) { for (PolicyCriterion criterion : criteria) {
@ -1348,7 +1348,7 @@ public class PolicyDAOImpl implements PolicyDAO {
conn = this.getConnection(); conn = this.getConnection();
String query = "INSERT INTO DM_POLICY (NAME, PROFILE_ID, TENANT_ID, PRIORITY, COMPLIANCE, OWNERSHIP_TYPE," + String query = "INSERT INTO DM_POLICY (NAME, PROFILE_ID, TENANT_ID, PRIORITY, COMPLIANCE, OWNERSHIP_TYPE," +
"UPDATED, ACTIVE, DESCRIPTION) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"; "UPDATED, ACTIVE, DESCRIPTION) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)";
stmt = conn.prepareStatement(query, PreparedStatement.RETURN_GENERATED_KEYS); stmt = conn.prepareStatement(query, new String[] {"id"});
stmt.setString(1, policy.getPolicyName()); stmt.setString(1, policy.getPolicyName());
stmt.setInt(2, policy.getProfile().getProfileId()); stmt.setInt(2, policy.getProfile().getProfileId());

@ -51,7 +51,7 @@ public class ProfileDAOImpl implements ProfileDAO {
conn = this.getConnection(); conn = this.getConnection();
String query = "INSERT INTO DM_PROFILE " + String query = "INSERT INTO DM_PROFILE " +
"(PROFILE_NAME,TENANT_ID, DEVICE_TYPE_ID, CREATED_TIME, UPDATED_TIME) VALUES (?, ?, ?, ?, ?)"; "(PROFILE_NAME,TENANT_ID, DEVICE_TYPE_ID, CREATED_TIME, UPDATED_TIME) VALUES (?, ?, ?, ?, ?)";
stmt = conn.prepareStatement(query, PreparedStatement.RETURN_GENERATED_KEYS); stmt = conn.prepareStatement(query, new String[] {"id"});
stmt.setString(1, profile.getProfileName()); stmt.setString(1, profile.getProfileName());
stmt.setInt(2, tenantId); stmt.setInt(2, tenantId);

@ -120,7 +120,7 @@ public class MonitoringManagerImpl implements MonitoringManager {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Compliance status primary key " + complianceData.getId()); log.debug("Compliance status primary key " + complianceData.getId());
} }
monitoringDAO.addNoneComplianceFeatures(complianceData.getId(), device.getId(), monitoringDAO.addNonComplianceFeatures(complianceData.getId(), device.getId(),
complianceFeatures); complianceFeatures);
PolicyManagementDAOFactory.commitTransaction(); PolicyManagementDAOFactory.commitTransaction();

@ -7,6 +7,7 @@ import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.certificate.mgt.core.exception.KeystoreException; import org.wso2.carbon.certificate.mgt.core.exception.KeystoreException;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants; import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
import org.wso2.carbon.device.mgt.core.scep.SCEPException; import org.wso2.carbon.device.mgt.core.scep.SCEPException;
import org.wso2.carbon.device.mgt.core.scep.SCEPManager; import org.wso2.carbon.device.mgt.core.scep.SCEPManager;
import org.wso2.carbon.device.mgt.core.scep.TenantedDeviceWrapper; import org.wso2.carbon.device.mgt.core.scep.TenantedDeviceWrapper;
@ -68,6 +69,14 @@ public class CertificateAuthenticator implements WebappAuthenticator {
TenantedDeviceWrapper tenantedDeviceWrapper = scepManager.getValidatedDevice(deviceIdentifier); TenantedDeviceWrapper tenantedDeviceWrapper = scepManager.getValidatedDevice(deviceIdentifier);
authenticationInfo.setTenantDomain(tenantedDeviceWrapper.getTenantDomain()); authenticationInfo.setTenantDomain(tenantedDeviceWrapper.getTenantDomain());
authenticationInfo.setTenantId(tenantedDeviceWrapper.getTenantId()); authenticationInfo.setTenantId(tenantedDeviceWrapper.getTenantId());
if(tenantedDeviceWrapper.getDevice() != null &&
tenantedDeviceWrapper.getDevice().getEnrolmentInfo() != null) {
EnrolmentInfo enrolmentInfo = tenantedDeviceWrapper.getDevice().getEnrolmentInfo();
authenticationInfo.setUsername(enrolmentInfo.getOwner());
}
authenticationInfo.setStatus(Status.CONTINUE); authenticationInfo.setStatus(Status.CONTINUE);
} }
} }

@ -35,7 +35,7 @@ CREATE TABLE DM_CONFIG_OPERATION (
CREATE TABLE DM_COMMAND_OPERATION ( CREATE TABLE DM_COMMAND_OPERATION (
OPERATION_ID INTEGER NOT NULL, OPERATION_ID INTEGER NOT NULL,
ENABLED BIT NOT NULL DEFAULT FALSE, ENABLED BIT NOT NULL DEFAULT 'FALSE',
PRIMARY KEY (OPERATION_ID), PRIMARY KEY (OPERATION_ID),
CONSTRAINT fk_dm_operation_command FOREIGN KEY (OPERATION_ID) REFERENCES CONSTRAINT fk_dm_operation_command FOREIGN KEY (OPERATION_ID) REFERENCES
DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
@ -337,20 +337,6 @@ CREATE TABLE DM_POLICY_COMPLIANCE_FEATURES (
ON UPDATE NO ACTION ON UPDATE NO ACTION
); );
CREATE TABLE DM_ENROLMENT (
ID INTEGER IDENTITY NOT NULL,
DEVICE_ID INTEGER NOT NULL,
OWNER VARCHAR(50) NOT NULL,
OWNERSHIP VARCHAR(45) DEFAULT NULL,
STATUS VARCHAR(50) NULL,
DATE_OF_ENROLMENT DATETIME2(0) DEFAULT NULL,
DATE_OF_LAST_UPDATE DATETIME2(0) DEFAULT NULL,
TENANT_ID INT NOT NULL,
PRIMARY KEY (ID),
CONSTRAINT fk_dm_device_enrolment FOREIGN KEY (DEVICE_ID) REFERENCES
DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
);
CREATE TABLE DM_APPLICATION ( CREATE TABLE DM_APPLICATION (
ID INTEGER IDENTITY NOT NULL, ID INTEGER IDENTITY NOT NULL,
NAME VARCHAR(150) NOT NULL, NAME VARCHAR(150) NOT NULL,

@ -26,7 +26,7 @@ CREATE TABLE DM_DEVICE (
DEVICE_IDENTIFICATION VARCHAR2(300) DEFAULT NULL, DEVICE_IDENTIFICATION VARCHAR2(300) DEFAULT NULL,
TENANT_ID NUMBER(10) DEFAULT 0, TENANT_ID NUMBER(10) DEFAULT 0,
CONSTRAINT PK_DM_DEVICE PRIMARY KEY (ID), CONSTRAINT PK_DM_DEVICE PRIMARY KEY (ID),
CONSTRAINT fk_DM_DEVICE_DM_DEVICE_TYPE2 FOREIGN KEY (DEVICE_TYPE_ID ) CONSTRAINT FK_DM_DEVICE_DM_DEVICE_TYPE2 FOREIGN KEY (DEVICE_TYPE_ID )
REFERENCES DM_DEVICE_TYPE (ID) REFERENCES DM_DEVICE_TYPE (ID)
) )
/ /
@ -71,7 +71,7 @@ CREATE TABLE DM_CONFIG_OPERATION (
OPERATION_ID NUMBER(10) NOT NULL, OPERATION_ID NUMBER(10) NOT NULL,
OPERATION_CONFIG BLOB DEFAULT NULL, OPERATION_CONFIG BLOB DEFAULT NULL,
CONSTRAINT PK_DM_CONFIG_OPERATION PRIMARY KEY (OPERATION_ID), CONSTRAINT PK_DM_CONFIG_OPERATION PRIMARY KEY (OPERATION_ID),
CONSTRAINT fk_dm_operation_config FOREIGN KEY (OPERATION_ID) REFERENCES CONSTRAINT FK_DM_OPERATION_CONFIG FOREIGN KEY (OPERATION_ID) REFERENCES
DM_OPERATION (ID) DM_OPERATION (ID)
) )
/ /
@ -79,7 +79,7 @@ CREATE TABLE DM_COMMAND_OPERATION (
OPERATION_ID NUMBER(10) NOT NULL, OPERATION_ID NUMBER(10) NOT NULL,
ENABLED NUMBER(10) DEFAULT 0 NOT NULL, ENABLED NUMBER(10) DEFAULT 0 NOT NULL,
CONSTRAINT PK_DM_COMMAND_OPERATION PRIMARY KEY (OPERATION_ID), CONSTRAINT PK_DM_COMMAND_OPERATION PRIMARY KEY (OPERATION_ID),
CONSTRAINT fk_dm_operation_command FOREIGN KEY (OPERATION_ID) REFERENCES CONSTRAINT FK_DM_OPERATION_COMMAND FOREIGN KEY (OPERATION_ID) REFERENCES
DM_OPERATION (ID) DM_OPERATION (ID)
) )
/ /
@ -88,7 +88,7 @@ CREATE TABLE DM_POLICY_OPERATION (
ENABLED NUMBER(10) DEFAULT 0 NOT NULL, ENABLED NUMBER(10) DEFAULT 0 NOT NULL,
OPERATION_DETAILS BLOB DEFAULT NULL, OPERATION_DETAILS BLOB DEFAULT NULL,
CONSTRAINT PK_DM_POLICY_OPERATION PRIMARY KEY (OPERATION_ID), CONSTRAINT PK_DM_POLICY_OPERATION PRIMARY KEY (OPERATION_ID),
CONSTRAINT fk_dm_operation_policy FOREIGN KEY (OPERATION_ID) REFERENCES CONSTRAINT FK_DM_OPERATION_POLICY FOREIGN KEY (OPERATION_ID) REFERENCES
DM_OPERATION (ID) DM_OPERATION (ID)
) )
/ /
@ -97,7 +97,7 @@ CREATE TABLE DM_PROFILE_OPERATION (
ENABLED NUMBER(10) DEFAULT 0 NOT NULL, ENABLED NUMBER(10) DEFAULT 0 NOT NULL,
OPERATION_DETAILS BLOB DEFAULT NULL, OPERATION_DETAILS BLOB DEFAULT NULL,
CONSTRAINT PK_DM_PROFILE_OPERATION PRIMARY KEY (OPERATION_ID), CONSTRAINT PK_DM_PROFILE_OPERATION PRIMARY KEY (OPERATION_ID),
CONSTRAINT fk_dm_operation_profile FOREIGN KEY (OPERATION_ID) REFERENCES CONSTRAINT FK_DM_OPERATION_PROFILE FOREIGN KEY (OPERATION_ID) REFERENCES
DM_OPERATION (ID) DM_OPERATION (ID)
) )
/ /
@ -111,7 +111,7 @@ CREATE TABLE DM_ENROLMENT (
DATE_OF_LAST_UPDATE TIMESTAMP(0) DEFAULT NULL, DATE_OF_LAST_UPDATE TIMESTAMP(0) DEFAULT NULL,
TENANT_ID NUMBER(10) NOT NULL, TENANT_ID NUMBER(10) NOT NULL,
CONSTRAINT PK_DM_ENROLMENT PRIMARY KEY (ID), CONSTRAINT PK_DM_ENROLMENT PRIMARY KEY (ID),
CONSTRAINT fk_dm_device_enrolment FOREIGN KEY (DEVICE_ID) REFERENCES CONSTRAINT FK_DM_DEVICE_ENROLMENT FOREIGN KEY (DEVICE_ID) REFERENCES
DM_DEVICE (ID) DM_DEVICE (ID)
) )
/ /
@ -129,29 +129,29 @@ WHEN (NEW.ID IS NULL)
END; END;
/ /
CREATE TABLE DM_ENROLMENT_op_map ( CREATE TABLE DM_ENROLMENT_OP_MAPPING (
ID NUMBER(10) NOT NULL, ID NUMBER(10) NOT NULL,
ENROLMENT_ID NUMBER(10) NOT NULL, ENROLMENT_ID NUMBER(10) NOT NULL,
OPERATION_ID NUMBER(10) NOT NULL, OPERATION_ID NUMBER(10) NOT NULL,
STATUS VARCHAR2(50) NULL, STATUS VARCHAR2(50) NULL,
PRIMARY KEY (ID), PRIMARY KEY (ID),
CONSTRAINT fk_dm_device_op_map_device FOREIGN KEY (ENROLMENT_ID) REFERENCES CONSTRAINT FK_DM_DEVICE_OP_MAP_DEVICE FOREIGN KEY (ENROLMENT_ID) REFERENCES
DM_ENROLMENT (ID), DM_ENROLMENT (ID),
CONSTRAINT fk_dm_device_op_map_operation FOREIGN KEY (OPERATION_ID) REFERENCES CONSTRAINT FK_DM_DEVICE_OP_MAP_OPERATION FOREIGN KEY (OPERATION_ID) REFERENCES
DM_OPERATION (ID) DM_OPERATION (ID)
) )
/ /
-- Generate ID using sequence and trigger -- Generate ID using sequence and trigger
CREATE SEQUENCE DM_ENROLMENT_op_map_seq START WITH 1 INCREMENT BY 1 NOCACHE CREATE SEQUENCE DM_ENROLMENT_OP_MAP_seq START WITH 1 INCREMENT BY 1 NOCACHE
/ /
CREATE OR REPLACE TRIGGER DM_ENROLMENT_op_map_seq_tr CREATE OR REPLACE TRIGGER DM_ENROLMENT_OP_MAP_seq_tr
BEFORE INSERT BEFORE INSERT
ON DM_ENROLMENT_op_map ON DM_ENROLMENT_OP_MAPPING
REFERENCING NEW AS NEW REFERENCING NEW AS NEW
FOR EACH ROW FOR EACH ROW
WHEN (NEW.ID IS NULL) WHEN (NEW.ID IS NULL)
BEGIN BEGIN
SELECT DM_ENROLMENT_op_map_seq.NEXTVAL INTO :NEW.ID FROM DUAL; SELECT DM_ENROLMENT_OP_MAP_seq.NEXTVAL INTO :NEW.ID FROM DUAL;
END; END;
/ /
@ -161,9 +161,9 @@ CREATE TABLE DM_DEVICE_OPERATION_RESPONSE (
OPERATION_ID NUMBER(10) NOT NULL, OPERATION_ID NUMBER(10) NOT NULL,
OPERATION_RESPONSE BLOB DEFAULT NULL, OPERATION_RESPONSE BLOB DEFAULT NULL,
CONSTRAINT PK_DM_DEVICE_OP_RESPONSE PRIMARY KEY (ID), CONSTRAINT PK_DM_DEVICE_OP_RESPONSE PRIMARY KEY (ID),
CONSTRAINT fk_dm_device_op_res_enrollment FOREIGN KEY (ENROLMENT_ID) REFERENCES CONSTRAINT FK_DM_DEVICE_OP_RES_DEVICE FOREIGN KEY (ENROLMENT_ID) REFERENCES
DM_ENROLMENT (ID), DM_ENROLMENT (ID),
CONSTRAINT fk_dm_device_op_res_operation FOREIGN KEY (OPERATION_ID) REFERENCES CONSTRAINT FK_DM_DEVICE_OP_RES_OPERATION FOREIGN KEY (OPERATION_ID) REFERENCES
DM_OPERATION (ID) DM_OPERATION (ID)
) )
/ /
@ -621,9 +621,9 @@ CREATE TABLE DM_NOTIFICATION (
STATUS VARCHAR2(10) NULL, STATUS VARCHAR2(10) NULL,
DESCRIPTION VARCHAR2(100) NULL, DESCRIPTION VARCHAR2(100) NULL,
CONSTRAINT PK_DM_NOTIFICATION PRIMARY KEY (NOTIFICATION_ID), CONSTRAINT PK_DM_NOTIFICATION PRIMARY KEY (NOTIFICATION_ID),
CONSTRAINT fk_dm_device_notification FOREIGN KEY (DEVICE_ID) REFERENCES CONSTRAINT FK_DM_DEVICE_NOTIFICATION FOREIGN KEY (DEVICE_ID) REFERENCES
DM_DEVICE (ID), DM_DEVICE (ID),
CONSTRAINT fk_dm_operation_notification FOREIGN KEY (OPERATION_ID) REFERENCES CONSTRAINT FK_DM_OPERATION_NOTIFICATION FOREIGN KEY (OPERATION_ID) REFERENCES
DM_OPERATION (ID) DM_OPERATION (ID)
) )
/ /

Loading…
Cancel
Save