Fixing errors and adding caching sketch

revert-70aa11f8
geethkokila 9 years ago
parent 4e5a38998d
commit cceb3ac5db

@ -61,6 +61,7 @@
org.osgi.service.component,
org.apache.commons.logging,
javax.sql,
javax.cache,
javax.naming,
javax.xml.bind.*,
javax.xml.parsers.*,

@ -0,0 +1,59 @@
/*
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.policy.mgt.core.cache;
public class PolicyCacheException extends Exception {
private static final long serialVersionUID = -4234546127441192907L;
private String errorMessage;
public String getErrorMessage() {
return errorMessage;
}
public void setErrorMessage(String errorMessage) {
this.errorMessage = errorMessage;
}
public PolicyCacheException(String msg, Exception nestedEx) {
super(msg, nestedEx);
setErrorMessage(msg);
}
public PolicyCacheException(String message, Throwable cause) {
super(message, cause);
setErrorMessage(message);
}
public PolicyCacheException(String msg) {
super(msg);
setErrorMessage(msg);
}
public PolicyCacheException() {
super();
}
public PolicyCacheException(Throwable cause) {
super(cause);
}
}

@ -0,0 +1,49 @@
/*
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.policy.mgt.core.cache;
import org.wso2.carbon.device.mgt.core.policy.mgt.policy.Policy;
import java.util.List;
public interface PolicyCacheManager {
void addAllPolicies(List<Policy> policies);
void updateAllPolicies(List<Policy> policies);
List<Policy> getAllPolicies();
void removeAllPolicies();
void addPolicy(Policy policy);
void updatePolicy(Policy policy);
void removePolicy(int policyId);
Policy getPolicy(int policyId);
void addPolicyToDevice(int deviceId, int policyId);
List<Integer> getPolicyAppliedDeviceIds(int policyId);
int getPolicyIdOfDevice(int deviceId);
}

@ -0,0 +1,83 @@
/*
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.policy.mgt.core.cache.impl;
import org.wso2.carbon.device.mgt.core.policy.mgt.policy.Policy;
import org.wso2.carbon.policy.mgt.core.cache.PolicyCacheManager;
import java.util.List;
public class PolicyCacheManagerImpl implements PolicyCacheManager {
@Override
public void addAllPolicies(List<Policy> policies) {
}
@Override
public void updateAllPolicies(List<Policy> policies) {
}
@Override
public List<Policy> getAllPolicies() {
return null;
}
@Override
public void removeAllPolicies() {
}
@Override
public void addPolicy(Policy policy) {
}
@Override
public void updatePolicy(Policy policy) {
}
@Override
public void removePolicy(int policyId) {
}
@Override
public Policy getPolicy(int policyId) {
return null;
}
@Override
public void addPolicyToDevice(int deviceId, int policyId) {
}
@Override
public List<Integer> getPolicyAppliedDeviceIds(int policyId) {
return null;
}
@Override
public int getPolicyIdOfDevice(int deviceId) {
return 0;
}
}

@ -21,6 +21,7 @@ package org.wso2.carbon.policy.mgt.core.dao.impl;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.device.mgt.common.Feature;
import org.wso2.carbon.policy.mgt.common.Profile;
import org.wso2.carbon.policy.mgt.common.ProfileFeature;
@ -140,7 +141,8 @@ public class FeatureDAOImpl implements FeatureDAO {
stmt.executeUpdate();
} catch (SQLException e) {
String msg = "Error occurred while updating feature " + feature.getName() + " (Feature Name) to the database.";
String msg = "Error occurred while updating feature " + feature.getName() + " (Feature Name) to the
database.";
log.error(msg, e);
throw new FeatureManagerDAOException(msg, e);
} finally {
@ -156,32 +158,36 @@ public class FeatureDAOImpl implements FeatureDAO {
}
@Override
public ProfileFeature updateProfileFeature(ProfileFeature feature, int profileId) throws FeatureManagerDAOException {
public ProfileFeature updateProfileFeature(ProfileFeature feature, int profileId) throws
FeatureManagerDAOException {
return null;
}
@Override
public List<ProfileFeature> addProfileFeatures(List<ProfileFeature> features, int profileId) throws FeatureManagerDAOException {
public List<ProfileFeature> addProfileFeatures(List<ProfileFeature> features, int profileId) throws
FeatureManagerDAOException {
Connection conn;
PreparedStatement stmt = null;
ResultSet generatedKeys = null;
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
try {
conn = this.getConnection();
String query = "INSERT INTO DM_PROFILE_FEATURES (PROFILE_ID, FEATURE_CODE, DEVICE_TYPE_ID, CONTENT) " +
"VALUES (?, ?, ?, ?)";
String query = "INSERT INTO DM_PROFILE_FEATURES (PROFILE_ID, FEATURE_CODE, DEVICE_TYPE_ID, CONTENT, " +
"TENANT_ID) VALUES (?, ?, ?, ?, ?)";
stmt = conn.prepareStatement(query, PreparedStatement.RETURN_GENERATED_KEYS);
for (ProfileFeature feature : features) {
stmt.setInt(1, profileId);
stmt.setString(2, feature.getFeatureCode());
stmt.setInt(3, feature.getDeviceTypeId());
if (conn.getMetaData().getDriverName().contains("H2")) {
stmt.setBytes(4, PolicyManagerUtil.getBytes(feature.getContent()));
} else {
// if (conn.getMetaData().getDriverName().contains("H2")) {
// stmt.setBytes(4, PolicyManagerUtil.getBytes(feature.getContent()));
// } else {
stmt.setBytes(4, PolicyManagerUtil.getBytes(feature.getContent()));
}
//}
stmt.setInt(5, tenantId);
stmt.addBatch();
//Not adding the logic to check the size of the stmt and execute if the size records added is over 1000
}
@ -210,14 +216,17 @@ public class FeatureDAOImpl implements FeatureDAO {
}
@Override
public List<ProfileFeature> updateProfileFeatures(List<ProfileFeature> features, int profileId) throws FeatureManagerDAOException {
public List<ProfileFeature> updateProfileFeatures(List<ProfileFeature> features, int profileId) throws
FeatureManagerDAOException {
Connection conn;
PreparedStatement stmt = null;
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
try {
conn = this.getConnection();
String query = "UPDATE DM_PROFILE_FEATURES SET CONTENT = ? WHERE PROFILE_ID = ?, FEATURE_CODE = ?";
String query = "UPDATE DM_PROFILE_FEATURES SET CONTENT = ? WHERE PROFILE_ID = ? AND FEATURE_CODE = ? AND" +
" TENANT_ID = ?";
stmt = conn.prepareStatement(query, PreparedStatement.RETURN_GENERATED_KEYS);
for (ProfileFeature feature : features) {
@ -228,6 +237,7 @@ public class FeatureDAOImpl implements FeatureDAO {
}
stmt.setInt(2, profileId);
stmt.setString(3, feature.getFeatureCode());
stmt.setInt(4, tenantId);
stmt.addBatch();
//Not adding the logic to check the size of the stmt and execute if the size records added is over 1000
}
@ -252,12 +262,14 @@ public class FeatureDAOImpl implements FeatureDAO {
Connection conn;
PreparedStatement stmt = null;
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
try {
conn = this.getConnection();
String query = "DELETE FROM DM_PROFILE_FEATURES WHERE PROFILE_ID = ?";
String query = "DELETE FROM DM_PROFILE_FEATURES WHERE PROFILE_ID = ? AND TENANT_ID = ?";
stmt = conn.prepareStatement(query);
stmt.setInt(1, profile.getProfileId());
stmt.setInt(2, tenantId);
stmt.executeUpdate();
return true;
@ -272,14 +284,16 @@ public class FeatureDAOImpl implements FeatureDAO {
@Override
public boolean deleteFeaturesOfProfile(int profileId) throws FeatureManagerDAOException {
Connection conn;
PreparedStatement stmt = null;
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
try {
conn = this.getConnection();
String query = "DELETE FROM DM_PROFILE_FEATURES WHERE PROFILE_ID = ?";
String query = "DELETE FROM DM_PROFILE_FEATURES WHERE PROFILE_ID = ? AND TENANT_ID = ?";
stmt = conn.prepareStatement(query);
stmt.setInt(1, profileId);
stmt.setInt(2, tenantId);
stmt.executeUpdate();
return true;
@ -300,11 +314,14 @@ public class FeatureDAOImpl implements FeatureDAO {
PreparedStatement stmt = null;
ResultSet resultSet = null;
List<ProfileFeature> featureList = new ArrayList<ProfileFeature>();
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
try {
conn = this.getConnection();
String query = "SELECT ID, PROFILE_ID, FEATURE_CODE, DEVICE_TYPE_ID, CONTENT FROM DM_PROFILE_FEATURES";
String query = "SELECT ID, PROFILE_ID, FEATURE_CODE, DEVICE_TYPE_ID, CONTENT FROM DM_PROFILE_FEATURES " +
"WHERE TENANT_ID = ?";
stmt = conn.prepareStatement(query);
stmt.setInt(1, tenantId);
resultSet = stmt.executeQuery();
while (resultSet.next()) {
@ -406,13 +423,15 @@ public class FeatureDAOImpl implements FeatureDAO {
PreparedStatement stmt = null;
ResultSet resultSet = null;
List<ProfileFeature> featureList = new ArrayList<ProfileFeature>();
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
try {
conn = this.getConnection();
String query = "SELECT ID, FEATURE_CODE, DEVICE_TYPE_ID, CONTENT FROM DM_PROFILE_FEATURES " +
"WHERE PROFILE_ID = ?";
"WHERE PROFILE_ID = ? AND TENANT_ID = ?";
stmt = conn.prepareStatement(query);
stmt.setInt(1, profileId);
stmt.setInt(2, tenantId);
resultSet = stmt.executeQuery();
while (resultSet.next()) {
@ -473,12 +492,14 @@ public class FeatureDAOImpl implements FeatureDAO {
Connection conn;
PreparedStatement stmt = null;
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
try {
conn = this.getConnection();
String query = "DELETE FROM DM_FEATURES WHERE ID = ?";
String query = "DELETE FROM DM_FEATURES WHERE ID = ? AND TENANT_ID = ?";
stmt = conn.prepareStatement(query);
stmt.setInt(1, featureId);
stmt.setInt(2, tenantId);
stmt.executeUpdate();
return true;

@ -21,6 +21,7 @@ package org.wso2.carbon.policy.mgt.core.dao.impl;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.policy.mgt.common.monitor.ComplianceData;
import org.wso2.carbon.policy.mgt.common.monitor.ComplianceFeature;
import org.wso2.carbon.policy.mgt.core.dao.MonitoringDAO;
@ -39,20 +40,23 @@ public class MonitoringDAOImpl implements MonitoringDAO {
@Override
public int addComplianceDetails(int deviceId, int policyId) throws MonitoringDAOException {
Connection conn;
PreparedStatement stmt = null;
ResultSet generatedKeys = null;
Timestamp currentTimestamp = new Timestamp(Calendar.getInstance().getTime().getTime());
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
try {
conn = this.getConnection();
String query = "INSERT INTO DM_POLICY_COMPLIANCE_STATUS (DEVICE_ID, POLICY_ID, STATUS, ATTEMPTS, " +
"LAST_REQUESTED_TIME) VALUES (?, ?, ?,?, ?) ";
"LAST_REQUESTED_TIME, TENANT_ID) VALUES (?, ?, ?,?, ?, ?) ";
stmt = conn.prepareStatement(query, PreparedStatement.RETURN_GENERATED_KEYS);
stmt.setInt(1, deviceId);
stmt.setInt(2, policyId);
stmt.setInt(3, 1);
stmt.setInt(4, 1);
stmt.setTimestamp(5, currentTimestamp);
stmt.setInt(6, tenantId);
stmt.executeUpdate();
generatedKeys = stmt.getGeneratedKeys();
@ -74,10 +78,13 @@ public class MonitoringDAOImpl implements MonitoringDAO {
@Override
public void addComplianceDetails(Map<Integer, Integer> devicePolicyMap) throws MonitoringDAOException {
Connection conn;
PreparedStatement stmt = null;
ResultSet generatedKeys = null;
Timestamp currentTimestamp = new Timestamp(Calendar.getInstance().getTime().getTime());
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
if (log.isDebugEnabled()) {
log.debug("Adding the compliance details for devices and policies");
for (Map.Entry<Integer, Integer> map : devicePolicyMap.entrySet()) {
@ -88,7 +95,7 @@ public class MonitoringDAOImpl implements MonitoringDAO {
try {
conn = this.getConnection();
String query = "INSERT INTO DM_POLICY_COMPLIANCE_STATUS (DEVICE_ID, POLICY_ID, STATUS, ATTEMPTS, " +
"LAST_REQUESTED_TIME) VALUES (?, ?, ?,?, ?) ";
"LAST_REQUESTED_TIME, TENANT_ID) VALUES (?, ?, ?,?, ?, ?) ";
stmt = conn.prepareStatement(query);
for (Map.Entry<Integer, Integer> map : devicePolicyMap.entrySet()) {
stmt.setInt(1, map.getKey());
@ -96,6 +103,7 @@ public class MonitoringDAOImpl implements MonitoringDAO {
stmt.setInt(3, 1);
stmt.setInt(4, 1);
stmt.setTimestamp(5, currentTimestamp);
stmt.setInt(6, tenantId);
stmt.addBatch();
}
stmt.executeBatch();
@ -118,18 +126,20 @@ public class MonitoringDAOImpl implements MonitoringDAO {
PreparedStatement stmt = null;
ResultSet generatedKeys = null;
Timestamp currentTimestamp = new Timestamp(Calendar.getInstance().getTime().getTime());
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
try {
conn = this.getConnection();
String query = "UPDATE DM_POLICY_COMPLIANCE_STATUS SET STATUS = 0, LAST_FAILED_TIME = ?, POLICY_ID = ?," +
" ATTEMPTS=0 WHERE DEVICE_ID = ?";
" ATTEMPTS=0 WHERE DEVICE_ID = ? AND TENANT_ID = ?";
stmt = conn.prepareStatement(query);
stmt.setTimestamp(1, currentTimestamp);
stmt.setInt(2, policyId);
stmt.setInt(3, deviceId);
stmt.setInt(4, tenantId);
stmt.executeUpdate();
} catch (SQLException e) {
String msg = "Error occurred while updating the none compliance to the database.";
log.error(msg, e);
@ -147,15 +157,17 @@ public class MonitoringDAOImpl implements MonitoringDAO {
PreparedStatement stmt = null;
ResultSet generatedKeys = null;
Timestamp currentTimestamp = new Timestamp(Calendar.getInstance().getTime().getTime());
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
try {
conn = this.getConnection();
String query = "UPDATE DM_POLICY_COMPLIANCE_STATUS SET STATUS = ?, ATTEMPTS=0, LAST_SUCCESS_TIME = ?" +
" WHERE DEVICE_ID = ?";
" WHERE DEVICE_ID = ? AND TENANT_ID = ?";
stmt = conn.prepareStatement(query);
stmt.setInt(1, 1);
stmt.setTimestamp(2, currentTimestamp);
stmt.setInt(3, deviceId);
stmt.setInt(4, tenantId);
stmt.executeUpdate();
// generatedKeys = stmt.getGeneratedKeys();
@ -180,10 +192,12 @@ public class MonitoringDAOImpl implements MonitoringDAO {
Connection conn;
PreparedStatement stmt = null;
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
try {
conn = this.getConnection();
String query = "INSERT INTO DM_POLICY_COMPLIANCE_FEATURES (COMPLIANCE_STATUS_ID, FEATURE_CODE, STATUS) " +
"VALUES (?, ?, ?) ";
String query = "INSERT INTO DM_POLICY_COMPLIANCE_FEATURES (COMPLIANCE_STATUS_ID, FEATURE_CODE, STATUS, " +
"TENANT_ID) VALUES (?, ?, ?, ?) ";
stmt = conn.prepareStatement(query, PreparedStatement.RETURN_GENERATED_KEYS);
for (ComplianceFeature feature : complianceFeatures) {
@ -194,6 +208,7 @@ public class MonitoringDAOImpl implements MonitoringDAO {
} else {
stmt.setInt(3, 0);
}
stmt.setInt(4, tenantId);
stmt.addBatch();
}
stmt.executeBatch();
@ -214,11 +229,14 @@ public class MonitoringDAOImpl implements MonitoringDAO {
PreparedStatement stmt = null;
ResultSet resultSet = null;
ComplianceData complianceData = new ComplianceData();
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
try {
conn = this.getConnection();
String query = "SELECT * FROM DM_POLICY_COMPLIANCE_STATUS WHERE DEVICE_ID = ?";
String query = "SELECT * FROM DM_POLICY_COMPLIANCE_STATUS WHERE DEVICE_ID = ? AND TENANT_ID = ?";
stmt = conn.prepareStatement(query);
stmt.setInt(1, deviceId);
stmt.setInt(2, tenantId);
resultSet = stmt.executeQuery();
@ -246,16 +264,19 @@ public class MonitoringDAOImpl implements MonitoringDAO {
@Override
public List<ComplianceData> getCompliance(List<Integer> deviceIds) throws MonitoringDAOException {
Connection conn;
PreparedStatement stmt = null;
ResultSet resultSet = null;
List<ComplianceData> complianceDataList = new ArrayList<>();
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
try {
conn = this.getConnection();
String query = "SELECT * FROM DM_POLICY_COMPLIANCE_STATUS WHERE DEVICE_ID IN (?)";
String query = "SELECT * FROM DM_POLICY_COMPLIANCE_STATUS WHERE TENANT_ID = ? AND DEVICE_ID IN (?)";
stmt = conn.prepareStatement(query);
stmt.setString(1, PolicyManagerUtil.makeString(deviceIds));
stmt.setInt(1, tenantId);
stmt.setString(2, PolicyManagerUtil.makeString(deviceIds));
resultSet = stmt.executeQuery();
@ -294,11 +315,14 @@ public class MonitoringDAOImpl implements MonitoringDAO {
PreparedStatement stmt = null;
ResultSet resultSet = null;
List<ComplianceFeature> complianceFeatures = new ArrayList<ComplianceFeature>();
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
try {
conn = this.getConnection();
String query = "SELECT * FROM DM_POLICY_COMPLIANCE_FEATURES WHERE COMPLIANCE_STATUS_ID = ?";
String query = "SELECT * FROM DM_POLICY_COMPLIANCE_FEATURES WHERE COMPLIANCE_STATUS_ID = ? AND TENANT_ID = ?";
stmt = conn.prepareStatement(query);
stmt.setInt(1, policyComplianceStatusId);
stmt.setInt(2, tenantId);
resultSet = stmt.executeQuery();
@ -326,11 +350,14 @@ public class MonitoringDAOImpl implements MonitoringDAO {
Connection conn;
PreparedStatement stmt = null;
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
try {
conn = this.getConnection();
String query = "DELETE FROM DM_POLICY_COMPLIANCE_FEATURES WHERE COMPLIANCE_STATUS_ID = ?";
String query = "DELETE FROM DM_POLICY_COMPLIANCE_FEATURES WHERE COMPLIANCE_STATUS_ID = ? AND TENANT_ID = ?";
stmt = conn.prepareStatement(query);
stmt.setInt(1, policyComplianceStatusId);
stmt.setInt(2, tenantId);
stmt.executeUpdate();
} catch (SQLException e) {
@ -345,23 +372,27 @@ public class MonitoringDAOImpl implements MonitoringDAO {
@Override
public void updateAttempts(int deviceId, boolean reset) throws MonitoringDAOException {
Connection conn;
PreparedStatement stmt = null;
Timestamp currentTimestamp = new Timestamp(Calendar.getInstance().getTime().getTime());
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
try {
conn = this.getConnection();
String query = "";
if (reset) {
query = "UPDATE DM_POLICY_COMPLIANCE_STATUS SET ATTEMPTS = 0, LAST_REQUESTED_TIME = ? " +
"WHERE DEVICE_ID = ?";
"WHERE DEVICE_ID = ? AND TENANT_ID = ?";
} else {
query = "UPDATE DM_POLICY_COMPLIANCE_STATUS SET ATTEMPTS = ATTEMPTS + 1, LAST_REQUESTED_TIME = ? " +
"WHERE DEVICE_ID = ?";
"WHERE DEVICE_ID = ? AND TENANT_ID = ?";
}
stmt = conn.prepareStatement(query);
stmt.setTimestamp(1, currentTimestamp);
stmt.setInt(2, deviceId);
stmt.setInt(3, tenantId);
stmt.executeUpdate();
} catch (SQLException e) {
@ -376,24 +407,28 @@ public class MonitoringDAOImpl implements MonitoringDAO {
@Override
public void updateAttempts(List<Integer> deviceIds, boolean reset) throws MonitoringDAOException {
Connection conn;
PreparedStatement stmt = null;
Timestamp currentTimestamp = new Timestamp(Calendar.getInstance().getTime().getTime());
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
try {
conn = this.getConnection();
String query = "";
if (reset) {
query = "UPDATE DM_POLICY_COMPLIANCE_STATUS SET ATTEMPTS = 0, LAST_REQUESTED_TIME = ? " +
"WHERE DEVICE_ID = ?";
"WHERE DEVICE_ID = ? AND TENANT_ID = ?";
} else {
query = "UPDATE DM_POLICY_COMPLIANCE_STATUS SET ATTEMPTS = ATTEMPTS + 1, LAST_REQUESTED_TIME = ? " +
"WHERE DEVICE_ID = ?";
"WHERE DEVICE_ID = ? AND TENANT_ID = ?";
}
stmt = conn.prepareStatement(query);
for (int deviceId : deviceIds) {
stmt.setTimestamp(1, currentTimestamp);
stmt.setInt(2, deviceId);
stmt.setInt(3, tenantId);
stmt.addBatch();
}
stmt.executeBatch();

@ -54,6 +54,7 @@ public class PolicyDAOImpl implements PolicyDAO {
Connection conn;
PreparedStatement stmt = null;
try {
conn = this.getConnection();
String query = "INSERT INTO DM_DEVICE_TYPE_POLICY (DEVICE_TYPE_ID, POLICY_ID) VALUES (?, ?)";
@ -78,6 +79,7 @@ public class PolicyDAOImpl implements PolicyDAO {
Connection conn;
PreparedStatement stmt = null;
try {
conn = this.getConnection();
String query = "INSERT INTO DM_ROLE_POLICY (ROLE_NAME, POLICY_ID) VALUES (?, ?)";
@ -104,6 +106,7 @@ public class PolicyDAOImpl implements PolicyDAO {
Connection conn;
PreparedStatement stmt = null;
try {
conn = this.getConnection();
String query = "INSERT INTO DM_USER_POLICY (POLICY_ID, USERNAME) VALUES (?, ?)";
@ -130,6 +133,7 @@ public class PolicyDAOImpl implements PolicyDAO {
Connection conn;
PreparedStatement stmt = null;
try {
conn = this.getConnection();
String query = "INSERT INTO DM_DEVICE_POLICY (DEVICE_ID, POLICY_ID) VALUES (?, ?)";
@ -155,14 +159,17 @@ public class PolicyDAOImpl implements PolicyDAO {
Connection conn;
PreparedStatement stmt = null;
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
try {
conn = this.getConnection();
String query = "UPDATE DM_POLICY SET PRIORITY = ? WHERE ID = ?";
String query = "UPDATE DM_POLICY SET PRIORITY = ? WHERE ID = ? AND TENANT_ID = ?";
stmt = conn.prepareStatement(query);
for (Policy policy : policies) {
stmt.setInt(1, policy.getPriorityId());
stmt.setInt(2, policy.getId());
stmt.setInt(3, tenantId);
stmt.addBatch();
}
stmt.executeBatch();
@ -184,8 +191,8 @@ public class PolicyDAOImpl implements PolicyDAO {
Connection conn;
PreparedStatement stmt = null;
ResultSet generatedKeys;
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
try {
conn = this.getConnection();
String query = "INSERT INTO DM_CRITERIA (TENANT_ID, NAME) VALUES (?, ?)";
@ -216,13 +223,14 @@ public class PolicyDAOImpl implements PolicyDAO {
Connection conn;
PreparedStatement stmt = null;
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
try {
conn = this.getConnection();
String query = "UPDATE DM_CRITERIA SET TENANT_ID = ?, NAME = ? WHERE ID = ?";
String query = "UPDATE DM_CRITERIA SET NAME = ? WHERE ID = ? AND TENANT_ID = ?";
stmt = conn.prepareStatement(query);
stmt.setInt(1, tenantId);
stmt.setString(2, criteria.getName());
stmt.setInt(3, criteria.getId());
stmt.setString(1, criteria.getName());
stmt.setInt(2, criteria.getId());
stmt.setInt(3, tenantId);
stmt.executeUpdate();
} catch (SQLException e) {
@ -242,12 +250,14 @@ public class PolicyDAOImpl implements PolicyDAO {
PreparedStatement stmt = null;
ResultSet resultSet = null;
Criterion criterion = new Criterion();
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
try {
conn = this.getConnection();
String query = "SELECT * FROM DM_CRITERIA WHERE ID= ?";
String query = "SELECT * FROM DM_CRITERIA WHERE ID= ? AND TENANT_ID = ?";
stmt = conn.prepareStatement(query);
stmt.setInt(1, id);
stmt.setInt(2, tenantId);
resultSet = stmt.executeQuery();
while (resultSet.next()) {
@ -273,12 +283,14 @@ public class PolicyDAOImpl implements PolicyDAO {
PreparedStatement stmt = null;
ResultSet resultSet = null;
Criterion criterion = new Criterion();
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
try {
conn = this.getConnection();
String query = "SELECT * FROM DM_CRITERIA WHERE NAME= ?";
String query = "SELECT * FROM DM_CRITERIA WHERE NAME= ? AND TENANT_ID = ?";
stmt = conn.prepareStatement(query);
stmt.setString(1, name);
stmt.setInt(2, tenantId);
resultSet = stmt.executeQuery();
while (resultSet.next()) {
@ -303,13 +315,15 @@ public class PolicyDAOImpl implements PolicyDAO {
Connection conn;
PreparedStatement stmt = null;
ResultSet resultSet = null;
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
boolean exist = false;
try {
conn = this.getConnection();
String query = "SELECT * FROM DM_CRITERIA WHERE NAME = ?";
String query = "SELECT * FROM DM_CRITERIA WHERE NAME = ? AND TENANT_ID = ?";
stmt = conn.prepareStatement(query);
stmt.setString(1, name);
stmt.setInt(2, tenantId);
resultSet = stmt.executeQuery();
exist = resultSet.next();
@ -357,11 +371,13 @@ public class PolicyDAOImpl implements PolicyDAO {
PreparedStatement stmt = null;
ResultSet resultSet = null;
List<Criterion> criteria = new ArrayList<Criterion>();
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
try {
conn = this.getConnection();
String query = "SELECT * FROM DM_CRITERIA";
String query = "SELECT * FROM DM_CRITERIA WHERE TENANT_ID = ?";
stmt = conn.prepareStatement(query);
stmt.setInt(1, tenantId);
resultSet = stmt.executeQuery();
while (resultSet.next()) {
@ -523,17 +539,19 @@ public class PolicyDAOImpl implements PolicyDAO {
Connection conn;
PreparedStatement stmt = null;
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
try {
conn = this.getConnection();
String query = "UPDATE DM_POLICY SET NAME= ?, TENANT_ID = ?, PROFILE_ID = ?, PRIORITY = ?, COMPLIANCE = ?" +
" WHERE ID = ?";
String query = "UPDATE DM_POLICY SET NAME= ?, PROFILE_ID = ?, PRIORITY = ?, COMPLIANCE = ?" +
" WHERE ID = ? AND TENANT_ID = ?";
stmt = conn.prepareStatement(query);
stmt.setString(1, policy.getPolicyName());
stmt.setInt(2, policy.getTenantId());
stmt.setInt(3, policy.getProfile().getProfileId());
stmt.setInt(4, policy.getPriorityId());
stmt.setString(5, policy.getCompliance());
stmt.setInt(6, policy.getId());
stmt.setInt(2, policy.getProfile().getProfileId());
stmt.setInt(3, policy.getPriorityId());
stmt.setString(4, policy.getCompliance());
stmt.setInt(5, policy.getId());
stmt.setInt(6, tenantId);
stmt.executeUpdate();
} catch (SQLException e) {
@ -553,11 +571,14 @@ public class PolicyDAOImpl implements PolicyDAO {
PreparedStatement stmt = null;
ResultSet resultSet = null;
Policy policy = new Policy();
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
try {
conn = this.getConnection();
String query = "SELECT * FROM DM_POLICY WHERE ID= ?";
String query = "SELECT * FROM DM_POLICY WHERE ID= ? AND TENANT_ID = ? ";
stmt = conn.prepareStatement(query);
stmt.setInt(1, policyId);
stmt.setInt(2, tenantId);
resultSet = stmt.executeQuery();
while (resultSet.next()) {
@ -576,6 +597,7 @@ public class PolicyDAOImpl implements PolicyDAO {
throw new PolicyManagerDAOException(msg, e);
} finally {
PolicyManagementDAOUtil.cleanupResources(stmt, resultSet);
this.closeConnection();
}
}
@ -587,11 +609,14 @@ public class PolicyDAOImpl implements PolicyDAO {
PreparedStatement stmt = null;
ResultSet resultSet = null;
Policy policy = new Policy();
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
try {
conn = this.getConnection();
String query = "SELECT * FROM DM_POLICY WHERE PROFILE_ID= ?";
String query = "SELECT * FROM DM_POLICY WHERE PROFILE_ID= ? AND TENANT_ID = ?";
stmt = conn.prepareStatement(query);
stmt.setInt(1, profileId);
stmt.setInt(2, tenantId);
resultSet = stmt.executeQuery();
while (resultSet.next()) {
@ -621,10 +646,13 @@ public class PolicyDAOImpl implements PolicyDAO {
PreparedStatement stmt = null;
ResultSet resultSet = null;
List<Policy> policies = new ArrayList<Policy>();
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
try {
conn = this.getConnection();
String query = "SELECT * FROM DM_POLICY";
String query = "SELECT * FROM DM_POLICY WHERE TENANT_ID = ?";
stmt = conn.prepareStatement(query);
stmt.setInt(1, tenantId);
resultSet = stmt.executeQuery();
while (resultSet.next()) {
@ -633,7 +661,7 @@ public class PolicyDAOImpl implements PolicyDAO {
policy.setId(resultSet.getInt("ID"));
policy.setProfileId(resultSet.getInt("PROFILE_ID"));
policy.setPolicyName(resultSet.getString("NAME"));
policy.setTenantId(resultSet.getInt("TENANT_ID"));
policy.setTenantId(tenantId);
policy.setPriorityId(resultSet.getInt("PRIORITY"));
policy.setCompliance(resultSet.getString("COMPLIANCE"));
policy.setOwnershipType(resultSet.getString("OWNERSHIP_TYPE"));
@ -750,13 +778,13 @@ public class PolicyDAOImpl implements PolicyDAO {
@Override
public void addEffectivePolicyToDevice(int deviceId, Policy policy)
throws PolicyManagerDAOException {
public void addEffectivePolicyToDevice(int deviceId, Policy policy) throws PolicyManagerDAOException {
Connection conn;
PreparedStatement stmt = null;
Timestamp currentTimestamp = new Timestamp(Calendar.getInstance().getTime().getTime());
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
try {
conn = this.getConnection();
String query = "INSERT INTO DM_DEVICE_POLICY_APPLIED (DEVICE_ID, POLICY_ID, POLICY_CONTENT, " +
@ -791,13 +819,17 @@ public class PolicyDAOImpl implements PolicyDAO {
Connection conn;
PreparedStatement stmt = null;
Timestamp currentTimestamp = new Timestamp(Calendar.getInstance().getTime().getTime());
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
try {
conn = this.getConnection();
String query = "UPDATE DM_DEVICE_POLICY_APPLIED SET APPLIED_TIME = ?, APPLIED = ? WHERE DEVICE_ID = ? ";
String query = "UPDATE DM_DEVICE_POLICY_APPLIED SET APPLIED_TIME = ?, APPLIED = ? WHERE DEVICE_ID = ? AND" +
" TENANT_ID = ?";
stmt = conn.prepareStatement(query);
stmt.setTimestamp(1, currentTimestamp);
stmt.setBoolean(2, true);
stmt.setInt(3, deviceId);
stmt.setInt(4, tenantId);
stmt.executeUpdate();
@ -818,16 +850,19 @@ public class PolicyDAOImpl implements PolicyDAO {
Connection conn;
PreparedStatement stmt = null;
Timestamp currentTimestamp = new Timestamp(Calendar.getInstance().getTime().getTime());
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
try {
conn = this.getConnection();
String query = "UPDATE DM_DEVICE_POLICY_APPLIED SET POLICY_ID = ?, POLICY_CONTENT = ?, UPDATED_TIME = ?, " +
"APPLIED = ? WHERE DEVICE_ID = ?";
"APPLIED = ? WHERE DEVICE_ID = ? AND TENANT_ID = ?";
stmt = conn.prepareStatement(query);
stmt.setInt(1, policy.getId());
stmt.setBytes(2, PolicyManagerUtil.getBytes(policy));
stmt.setTimestamp(3, currentTimestamp);
stmt.setBoolean(4, false);
stmt.setInt(5, deviceId);
stmt.setInt(6, tenantId);
stmt.executeUpdate();
} catch (SQLException e) {
@ -846,16 +881,19 @@ public class PolicyDAOImpl implements PolicyDAO {
@Override
public boolean checkPolicyAvailable(int deviceId) throws PolicyManagerDAOException {
Connection conn;
PreparedStatement stmt = null;
ResultSet resultSet = null;
boolean exist = false;
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
try {
conn = this.getConnection();
String query = "SELECT * FROM DM_DEVICE_POLICY_APPLIED WHERE DEVICE_ID = ?";
String query = "SELECT * FROM DM_DEVICE_POLICY_APPLIED WHERE DEVICE_ID = ? AND TENANT_ID = ?";
stmt = conn.prepareStatement(query);
stmt.setInt(1, deviceId);
stmt.setInt(2, tenantId);
resultSet = stmt.executeQuery();
exist = resultSet.next();
@ -965,12 +1003,14 @@ public class PolicyDAOImpl implements PolicyDAO {
Connection conn;
PreparedStatement stmt = null;
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
try {
conn = this.getConnection();
String query = "DELETE FROM DM_POLICY WHERE ID = ?";
String query = "DELETE FROM DM_POLICY WHERE ID = ? AND TENANT_ID = ?";
stmt = conn.prepareStatement(query);
stmt.setInt(1, policy.getId());
stmt.setInt(2, tenantId);
stmt.executeUpdate();
if (log.isDebugEnabled()) {
@ -988,14 +1028,17 @@ public class PolicyDAOImpl implements PolicyDAO {
@Override
public boolean deletePolicy(int policyId) throws PolicyManagerDAOException {
Connection conn;
PreparedStatement stmt = null;
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
try {
conn = this.getConnection();
String query = "DELETE FROM DM_POLICY WHERE ID = ?";
String query = "DELETE FROM DM_POLICY WHERE ID = ? AND TENANT_ID = ?";
stmt = conn.prepareStatement(query);
stmt.setInt(1, policyId);
stmt.setInt(2, tenantId);
stmt.executeUpdate();
if (log.isDebugEnabled()) {
@ -1158,11 +1201,13 @@ public class PolicyDAOImpl implements PolicyDAO {
PreparedStatement stmt = null;
ResultSet resultSet = null;
int priority = 0;
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
try {
conn = this.getConnection();
String query = "SELECT MAX(PRIORITY) PRIORITY FROM DM_POLICY;";
String query = "SELECT MAX(PRIORITY) PRIORITY FROM DM_POLICY WHERE TENANT_ID = ?";
stmt = conn.prepareStatement(query);
stmt.setInt(1, tenantId);
resultSet = stmt.executeQuery();
while (resultSet.next()) {
@ -1188,11 +1233,14 @@ public class PolicyDAOImpl implements PolicyDAO {
Connection conn;
PreparedStatement stmt = null;
ResultSet resultSet = null;
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
int policyCount = 0;
try {
conn = this.getConnection();
String query = "SELECT COUNT(ID) AS POLICY_COUNT FROM DM_POLICY";
String query = "SELECT COUNT(ID) AS POLICY_COUNT FROM DM_POLICY WHERE TENANT_ID = ?";
stmt = conn.prepareStatement(query);
stmt.setInt(1, tenantId);
resultSet = stmt.executeQuery();
while (resultSet.next()) {
@ -1216,12 +1264,14 @@ public class PolicyDAOImpl implements PolicyDAO {
Connection conn;
PreparedStatement stmt = null;
ResultSet resultSet = null;
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
try {
conn = this.getConnection();
String query = "SELECT * FROM DM_DEVICE_POLICY_APPLIED WHERE DEVICE_ID = ?";
String query = "SELECT * FROM DM_DEVICE_POLICY_APPLIED WHERE DEVICE_ID = ? AND TENANT_ID = ?";
stmt = conn.prepareStatement(query);
stmt.setInt(1, deviceId);
stmt.setInt(2, tenantId);
resultSet = stmt.executeQuery();
while (resultSet.next()) {
@ -1246,21 +1296,16 @@ public class PolicyDAOImpl implements PolicyDAO {
Connection conn;
PreparedStatement stmt = null;
ResultSet resultSet = null;
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
Policy policy = null;
try {
conn = this.getConnection();
String query = "SELECT * FROM DM_DEVICE_POLICY_APPLIED WHERE DEVICE_ID = ?";
String query = "SELECT * FROM DM_DEVICE_POLICY_APPLIED WHERE DEVICE_ID = ? AND TENANT_ID = ?";
stmt = conn.prepareStatement(query);
stmt.setInt(1, deviceId);
stmt.setInt(2, tenantId);
resultSet = stmt.executeQuery();
// log.debug("Logging the statement................." + stmt.toString());
// log.debug("+++++++++++++++++++++++++++++");
// log.debug(conn.toString());
// log.debug("+++++++++++++++++++++++++++++");
while (resultSet.next()) {
ByteArrayInputStream bais = null;
@ -1320,6 +1365,7 @@ public class PolicyDAOImpl implements PolicyDAO {
@Override
public HashMap<Integer, Integer> getAppliedPolicyIds(List<Integer> deviceIds) throws PolicyManagerDAOException {
Connection conn;
PreparedStatement stmt = null;
ResultSet resultSet = null;

@ -225,6 +225,7 @@ public class ProfileDAOImpl implements ProfileDAO {
List<Profile> profileList = new ArrayList<Profile>();
try {
//TODO : Fix with TenantID.
conn = this.getConnection();
String query = "SELECT * FROM DM_PROFILE";
stmt = conn.prepareStatement(query);

@ -140,17 +140,24 @@ public class ComplianceDecisionPointImpl implements ComplianceDecisionPoint {
}
} else {
List<ComplianceFeature> noneComplianceFeatures = complianceData.getComplianceFeatures();
List<ProfileFeature> effectiveFeatures = policy.getProfile().getProfileFeaturesList();
for (ComplianceFeature feature : noneComplianceFeatures) {
for (ProfileFeature pf : effectiveFeatures) {
if (pf.getFeatureCode().equalsIgnoreCase(feature.getFeatureCode())) {
ProfileOperation profileOperation = new ProfileOperation();
profileOperation.setCode(feature.getFeatureCode());
profileOperation.setEnabled(true);
profileOperation.setStatus(Operation.Status.PENDING);
profileOperation.setType(Operation.Type.PROFILE);
profileOperation.setPayLoad(feature.getFeature().getContent());
profileOperation.setPayLoad(pf.getContent());
profileOperationList.add(profileOperation);
}
}
}
}
policyOperation.setProfileOperations(profileOperationList);
policyOperation.setPayLoad(policyOperation.getProfileOperations());
PolicyManagementDataHolder.getInstance().getDeviceManagementService().

@ -58,22 +58,22 @@ public class PolicyAdministratorPointImpl implements PolicyAdministratorPoint {
@Override
public Policy addPolicy(Policy policy) throws PolicyManagementException {
Policy resultantPolicy = policyManager.addPolicy(policy);
try {
delegator.delegate(resultantPolicy, resultantPolicy.getDevices());
} catch (PolicyDelegationException e) {
throw new PolicyManagementException("Error occurred while delegating policy operation to the devices", e);
}
// try {
// delegator.delegate(resultantPolicy, resultantPolicy.getDevices());
// } catch (PolicyDelegationException e) {
// throw new PolicyManagementException("Error occurred while delegating policy operation to the devices", e);
// }
return resultantPolicy;
}
@Override
public Policy updatePolicy(Policy policy) throws PolicyManagementException {
Policy resultantPolicy = policyManager.updatePolicy(policy);
try {
delegator.delegate(resultantPolicy, resultantPolicy.getDevices());
} catch (PolicyDelegationException e) {
throw new PolicyManagementException("Error occurred while delegating policy operation to the devices", e);
}
// try {
// delegator.delegate(resultantPolicy, resultantPolicy.getDevices());
// } catch (PolicyDelegationException e) {
// throw new PolicyManagementException("Error occurred while delegating policy operation to the devices", e);
// }
return resultantPolicy;
}

@ -89,7 +89,13 @@ public class PolicyFilterImpl implements PolicyFilter {
List<Policy> temp = new ArrayList<Policy>();
for (Policy policy : policies) {
List<String> users = policy.getUsers();
if (users.isEmpty()) {
temp.add(policy);
continue;
}
if (users.contains(PolicyManagementConstants.ANY)) {
temp.add(policy);
continue;

@ -304,6 +304,7 @@ public class MonitoringManagerImpl implements MonitoringManager {
if (!deviceIdsWithExistingOperation.isEmpty()) {
monitoringDAO.updateAttempts(new ArrayList<>(deviceIdsWithExistingOperation.keySet()), false);
//TODO: Add attempts. This has to be fixed in the get pending operation tables too. This will be
decisionPoint.setDevicesAsUnreachable(this.getDeviceIdentifiersFromDevices(
new ArrayList<>(deviceIdsWithExistingOperation.values())));
}

@ -291,8 +291,9 @@ public class PolicyManagerImpl implements PolicyManager {
public boolean deletePolicy(int policyId) throws PolicyManagementException {
try {
PolicyManagementDAOFactory.beginTransaction();
Policy policy = policyDAO.getPolicy(policyId);
PolicyManagementDAOFactory.beginTransaction();
policyDAO.deleteAllPolicyRelatedConfigs(policyId);
policyDAO.deletePolicy(policyId);

@ -37,4 +37,9 @@ public final class PolicyManagementConstants {
public static final String TASK_CLAZZ = "org.wso2.carbon.policy.mgt.core.task.MonitoringTask";
public static final String DM_CACHE_MANAGER = "DM_CACHE_MANAGER";
public static final String DM_CACHE = "DM_CACHE";
}

@ -31,6 +31,9 @@ import org.wso2.carbon.policy.mgt.core.config.datasource.DataSourceConfig;
import org.wso2.carbon.policy.mgt.core.config.datasource.JNDILookupDefinition;
import org.wso2.carbon.policy.mgt.core.dao.util.PolicyManagementDAOUtil;
import javax.cache.Cache;
import javax.cache.CacheManager;
import javax.cache.Caching;
import javax.sql.DataSource;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
@ -136,4 +139,10 @@ public class PolicyManagerUtil {
byte[] data = bos.toByteArray();
return data;
}
public static Cache getCacheManagerImpl(){
return Caching.getCacheManagerFactory()
.getCacheManager(PolicyManagementConstants.DM_CACHE_MANAGER).getCache(PolicyManagementConstants.DM_CACHE);
}
}

@ -31,6 +31,7 @@ import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderServiceImpl;
import org.wso2.carbon.policy.mgt.common.*;
import org.wso2.carbon.policy.mgt.core.impl.PolicyAdministratorPointImpl;
import org.wso2.carbon.policy.mgt.core.internal.PolicyManagementDataHolder;
import org.wso2.carbon.policy.mgt.core.mgt.FeatureManager;
import org.wso2.carbon.policy.mgt.core.mgt.PolicyManager;
import org.wso2.carbon.policy.mgt.core.mgt.ProfileManager;
@ -97,6 +98,8 @@ public class PolicyDAOTestCase extends BasePolicyManagementDAOTest {
DeviceManagementProviderService service = new DeviceManagementProviderServiceImpl();
PolicyManagementDataHolder.getInstance().setDeviceManagementService(service);
log.debug("Printing device taken by calling the service layer with device type.");
List<Device> devices3 = service.getAllDevices("android");

@ -37,7 +37,7 @@ public class PolicyCreator {
List<String> users = new ArrayList<String>();
users.add("Dilshan");
policy.setUsers(users);
policy.setCompliance("ENFORCE");
policy.setCompliance("NOTIFY");
policy.setOwnershipType("COPE");
return policy;
@ -52,7 +52,7 @@ public class PolicyCreator {
policy.setProfile(profile);
policy.setDevices(DeviceCreator.getDeviceList(DeviceTypeCreator.getDeviceType()));
policy.setCompliance("NOTIFY");
policy.setCompliance("ENFORCE");
List<String> roles = new ArrayList<String>();
roles.add("Role_01");

@ -201,6 +201,7 @@ CREATE TABLE IF NOT EXISTS DM_PROFILE_FEATURES (
PROFILE_ID INT(11) NOT NULL,
FEATURE_CODE VARCHAR(30) NOT NULL,
DEVICE_TYPE_ID INT NOT NULL,
TENANT_ID INT(11) NOT NULL ,
CONTENT BLOB NULL DEFAULT NULL,
PRIMARY KEY (ID),
CONSTRAINT FK_DM_PROFILE_DM_POLICY_FEATURES
@ -314,6 +315,7 @@ CREATE TABLE IF NOT EXISTS DM_POLICY_COMPLIANCE_STATUS (
ID INT NOT NULL AUTO_INCREMENT,
DEVICE_ID INT NOT NULL,
POLICY_ID INT NOT NULL,
TENANT_ID INT NOT NULL,
STATUS INT NULL,
LAST_SUCCESS_TIME TIMESTAMP NULL,
LAST_REQUESTED_TIME TIMESTAMP NULL,
@ -332,6 +334,7 @@ CREATE TABLE IF NOT EXISTS DM_POLICY_COMPLIANCE_STATUS (
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,
STATUS INT NULL,
PRIMARY KEY (ID),

@ -191,6 +191,7 @@ CREATE TABLE IF NOT EXISTS DM_PROFILE_FEATURES (
PROFILE_ID INT(11) NOT NULL,
FEATURE_CODE VARCHAR(30) NOT NULL,
DEVICE_TYPE_ID INT NOT NULL,
TENANT_ID INT(11) NOT NULL ,
CONTENT BLOB NULL DEFAULT NULL,
PRIMARY KEY (ID),
CONSTRAINT FK_DM_PROFILE_DM_POLICY_FEATURES
@ -300,6 +301,7 @@ CREATE TABLE IF NOT EXISTS DM_POLICY_COMPLIANCE_STATUS (
ID INT NOT NULL AUTO_INCREMENT,
DEVICE_ID INT NOT NULL,
POLICY_ID INT NOT NULL,
TENANT_ID INT NOT NULL,
STATUS INT NULL,
LAST_SUCCESS_TIME TIMESTAMP NULL,
LAST_REQUESTED_TIME TIMESTAMP NULL,
@ -318,6 +320,7 @@ CREATE TABLE IF NOT EXISTS DM_POLICY_COMPLIANCE_STATUS (
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,
STATUS INT NULL,
PRIMARY KEY (ID),

@ -414,10 +414,10 @@
<groupId>org.eclipse.equinox</groupId>
<artifactId>org.eclipse.equinox.http.helper</artifactId>
</exclusion>
<exclusion>
<!--<exclusion>
<groupId>org.wso2.carbon</groupId>
<artifactId>javax.cache.wso2</artifactId>
</exclusion>
</exclusion>-->
<exclusion>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.registry.core</artifactId>

Loading…
Cancel
Save