Improve MDM policy functionality

corrective-policy
tcdlpds@gmail.com 4 years ago
parent 94bdff30ed
commit d25779774b

@ -334,7 +334,7 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (ApplicationManagementException e) {
String msg = "Error occurred while creating a costom application";
String msg = "Error occurred while creating a custom application";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} catch (RequestValidatingException e) {
@ -716,7 +716,7 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
.changeLifecycleState(applicationUuid, lifecycleChanger);
return Response.status(Response.Status.CREATED).entity(applicationRelease).build();
} catch (BadRequestException e) {
String msg = "Request payload contains invalid data, hence veryfy the request payload.";
String msg = "Request payload contains invalid data, hence verify the request payload.";
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).build();
} catch (ForbiddenException e) {
@ -1005,10 +1005,10 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
}
if (attachmentList != null && !attachmentList.isEmpty()) {
Map<String, InputStream> scrrenshotData = new TreeMap<>();
Map<String, InputStream> screenshotData = new TreeMap<>();
for (Attachment sc : attachmentList) {
dataHandler = sc.getDataHandler();
String screenshotrFileName = dataHandler.getName();
String screenshotFileName = dataHandler.getName();
InputStream screenshotStream = dataHandler.getInputStream();
if (screenshotStream == null) {
String msg =
@ -1017,16 +1017,16 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
log.error(msg);
throw new BadRequestException(msg);
}
if (screenshotrFileName == null) {
if (screenshotFileName == null) {
String msg =
"Screenshot file name retrieving is failed for one screenshot. Hence can't proceed. "
+ "Please verify the screenshots.";
log.error(msg);
throw new BadRequestException(msg);
}
scrrenshotData.put(screenshotrFileName, screenshotStream);
screenshotData.put(screenshotFileName, screenshotStream);
}
applicationArtifact.setScreenshots(scrrenshotData);
applicationArtifact.setScreenshots(screenshotData);
}
return applicationArtifact;
} catch (IOException e) {

@ -136,6 +136,14 @@ public class PolicyManagementServiceImpl implements PolicyManagementService {
}
}
/**
* GEt {@link Policy} from {@link PolicyWrapper}
*
* @param policyWrapper {@link PolicyWrapper}
* @return {@link Policy}
* @throws DeviceManagementException if error occurred while creating {@link Policy} object from
* {@link PolicyWrapper}
*/
private Policy getPolicyFromWrapper(@Valid PolicyWrapper policyWrapper) throws DeviceManagementException {
Policy policy = new Policy();
policy.setPolicyName(policyWrapper.getPolicyName());
@ -151,7 +159,7 @@ public class PolicyManagementServiceImpl implements PolicyManagementService {
policy.setPolicyPayloadVersion(policyWrapper.getPayloadVersion());
policy.setCorrectiveActions(policyWrapper.getCorrectiveActions());
//TODO iterates the device identifiers to create the object. need to implement a proper DAO layer here.
List<Device> devices = new ArrayList<Device>();
List<Device> devices = new ArrayList<>();
List<DeviceIdentifier> deviceIdentifiers = policyWrapper.getDeviceIdentifiers();
if (deviceIdentifiers != null) {
for (DeviceIdentifier id : deviceIdentifiers) {

@ -19,7 +19,6 @@
package org.wso2.carbon.device.mgt.common.policy.mgt;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.NonComplianceData;
import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.PolicyComplianceException;

@ -150,7 +150,6 @@ import java.io.IOException;
import java.io.StringWriter;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collections;
import java.util.Date;

@ -25,7 +25,6 @@ import org.wso2.carbon.device.mgt.common.policy.mgt.Policy;
import org.wso2.carbon.device.mgt.common.policy.mgt.PolicyMonitoringManager;
import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.ComplianceFeature;
import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.NonComplianceData;
import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.PolicyComplianceException;
import java.util.ArrayList;
import java.util.List;
@ -35,10 +34,10 @@ import java.util.List;
*/
public class DefaultPolicyMonitoringManager implements PolicyMonitoringManager {
private static Log log = LogFactory.getLog(DefaultPolicyMonitoringManager.class);
private static final Log log = LogFactory.getLog(DefaultPolicyMonitoringManager.class);
@Override
public NonComplianceData checkPolicyCompliance(DeviceIdentifier deviceIdentifier, Policy policy, Object response)
throws PolicyComplianceException {
public NonComplianceData checkPolicyCompliance(DeviceIdentifier deviceIdentifier, Policy policy, Object response) {
if (log.isDebugEnabled()) {
log.debug("Checking policy compliance status of device '" + deviceIdentifier.getId() + "'");
}

@ -188,14 +188,6 @@ public class MonitoringDAOImpl implements MonitoringDAO {
stmt.setInt(4, tenantId);
stmt.setInt(5, enrolmentId);
stmt.executeUpdate();
// generatedKeys = stmt.getGeneratedKeys();
// if (generatedKeys.next()) {
// return generatedKeys.getInt(1);
// } else {
// return 0;
// }
} catch (SQLException e) {
throw new MonitoringDAOException("Error occurred while deleting the none compliance to the database.", e);
} finally {
@ -442,7 +434,7 @@ public class MonitoringDAOImpl implements MonitoringDAO {
Connection conn;
PreparedStatement stmt = null;
ResultSet resultSet = null;
List<ComplianceFeature> complianceFeatures = new ArrayList<ComplianceFeature>();
List<ComplianceFeature> complianceFeatures = new ArrayList<>();
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
try {
@ -488,8 +480,7 @@ public class MonitoringDAOImpl implements MonitoringDAO {
}
private Connection getConnection() throws MonitoringDAOException {
private Connection getConnection() {
return PolicyManagementDAOFactory.getConnection();
}
}

@ -75,41 +75,13 @@ public class PolicyDAOImpl implements PolicyDAO {
return persistPolicy(policy);
}
// @Override
// public Policy addPolicyToDeviceType(String deviceType, Policy policy) throws PolicyManagerDAOException {
// Connection conn;
// PreparedStatement stmt = null;
// try {
// conn = this.getConnection();
// String query = "INSERT INTO DM_DEVICE_TYPE_POLICY (DEVICE_TYPE_ID, POLICY_ID) VALUES (?, ?)";
// stmt = conn.prepareStatement(query);
// stmt.setInt(1, getDeviceTypeId(deviceType));
// stmt.setInt(2, policy.getId());
// stmt.executeQuery();
// } catch (SQLException e) {
// throw new PolicyManagerDAOException("Error occurred while adding the device type policy to database.", e);
// } finally {
// PolicyManagementDAOUtil.cleanupResources(stmt, null);
// }
// return policy;
//
// }
@Override
public Policy addPolicyToRole(List<String> rolesToAdd, Policy policy) throws PolicyManagerDAOException {
Connection conn;
PreparedStatement insertStmt = null;
// PreparedStatement deleteStmt = null;
// final List<String> currentRoles = this.getPolicy(policy.getId()).getRoles();
//
// SetReferenceTransformer<String> transformer = new SetReferenceTransformer<String>();
//
// transformer.transform(currentRoles, rolesToAdd);
// rolesToAdd = transformer.getObjectsToAdd();
// List<String> rolesToDelete = transformer.getObjectsToRemove();
try {
conn = this.getConnection();
if (rolesToAdd.size() > 0) {
if (!rolesToAdd.isEmpty()) {
String query = "INSERT INTO DM_ROLE_POLICY (ROLE_NAME, POLICY_ID) VALUES (?, ?)";
insertStmt = conn.prepareStatement(query);
for (String role : rolesToAdd) {
@ -119,16 +91,6 @@ public class PolicyDAOImpl implements PolicyDAO {
}
insertStmt.executeBatch();
}
// if (rolesToDelete.size() > 0){
// String deleteQuery = "DELETE FROM DM_ROLE_POLICY WHERE ROLE_NAME=? AND POLICY_ID=?";
// deleteStmt = conn.prepareStatement(deleteQuery);
// for (String role : rolesToDelete) {
// deleteStmt.setString(1, role);
// deleteStmt.setInt(2, policy.getId());
// deleteStmt.addBatch();
// }
// deleteStmt.executeBatch();
// }
} catch (SQLException e) {
throw new PolicyManagerDAOException("Error occurred while adding the role name with policy to database", e);
} finally {
@ -146,14 +108,14 @@ public class PolicyDAOImpl implements PolicyDAO {
final List<String> currentRoles = previousPolicy.getRoles();
SetReferenceTransformer<String> transformer = new SetReferenceTransformer<String>();
SetReferenceTransformer<String> transformer = new SetReferenceTransformer<>();
transformer.transform(currentRoles, rolesToAdd);
rolesToAdd = transformer.getObjectsToAdd();
List<String> rolesToDelete = transformer.getObjectsToRemove();
try {
conn = this.getConnection();
if (rolesToAdd.size() > 0) {
if (!rolesToAdd.isEmpty()) {
String query = "INSERT INTO DM_ROLE_POLICY (ROLE_NAME, POLICY_ID) VALUES (?, ?)";
insertStmt = conn.prepareStatement(query);
for (String role : rolesToAdd) {
@ -163,7 +125,7 @@ public class PolicyDAOImpl implements PolicyDAO {
}
insertStmt.executeBatch();
}
if (rolesToDelete.size() > 0) {
if (!rolesToDelete.isEmpty()) {
String deleteQuery = "DELETE FROM DM_ROLE_POLICY WHERE ROLE_NAME=? AND POLICY_ID=?";
deleteStmt = conn.prepareStatement(deleteQuery);
for (String role : rolesToDelete) {
@ -186,17 +148,9 @@ public class PolicyDAOImpl implements PolicyDAO {
public Policy addPolicyToUser(List<String> usersToAdd, Policy policy) throws PolicyManagerDAOException {
Connection conn;
PreparedStatement insertStmt = null;
// PreparedStatement deleteStmt = null;
// final List<String> currentUsers = this.getPolicy(policy.getId()).getUsers();
//
// SetReferenceTransformer<String> transformer = new SetReferenceTransformer<String>();
//
// transformer.transform(currentUsers, usersToAdd);
// usersToAdd = transformer.getObjectsToAdd();
// List<String> usersToDelete = transformer.getObjectsToRemove();
try {
conn = this.getConnection();
if (usersToAdd.size() > 0) {
if (!usersToAdd.isEmpty()) {
String query = "INSERT INTO DM_USER_POLICY (POLICY_ID, USERNAME) VALUES (?, ?)";
insertStmt = conn.prepareStatement(query);
for (String username : usersToAdd) {
@ -206,22 +160,10 @@ public class PolicyDAOImpl implements PolicyDAO {
}
insertStmt.executeBatch();
}
// if (usersToDelete.size() > 0){
// String deleteQuery = "DELETE FROM DM_USER_POLICY WHERE USERNAME=? AND POLICY_ID=?";
// deleteStmt = conn.prepareStatement(deleteQuery);
// for (String username : usersToDelete) {
// deleteStmt.setString(1, username);
// deleteStmt.setInt(2, policy.getId());
// deleteStmt.addBatch();
// }
// deleteStmt.executeBatch();
// }
} catch (SQLException e) {
throw new PolicyManagerDAOException("Error occurred while adding the user name with policy to database", e);
} finally {
PolicyManagementDAOUtil.cleanupResources(insertStmt, null);
// PolicyManagementDAOUtil.cleanupResources(deleteStmt, null);
}
return policy;
}
@ -234,14 +176,14 @@ public class PolicyDAOImpl implements PolicyDAO {
PreparedStatement deleteStmt = null;
final List<String> currentUsers = policy.getUsers();
SetReferenceTransformer<String> transformer = new SetReferenceTransformer<String>();
SetReferenceTransformer<String> transformer = new SetReferenceTransformer<>();
transformer.transform(currentUsers, usersToAdd);
usersToAdd = transformer.getObjectsToAdd();
List<String> usersToDelete = transformer.getObjectsToRemove();
try {
conn = this.getConnection();
if (usersToAdd.size() > 0) {
if (!usersToAdd.isEmpty()) {
String query = "INSERT INTO DM_USER_POLICY (POLICY_ID, USERNAME) VALUES (?, ?)";
insertStmt = conn.prepareStatement(query);
for (String username : usersToAdd) {
@ -251,7 +193,7 @@ public class PolicyDAOImpl implements PolicyDAO {
}
insertStmt.executeBatch();
}
if (usersToDelete.size() > 0) {
if (!usersToDelete.isEmpty()) {
String deleteQuery = "DELETE FROM DM_USER_POLICY WHERE USERNAME=? AND POLICY_ID=?";
deleteStmt = conn.prepareStatement(deleteQuery);
for (String username : usersToDelete) {
@ -328,7 +270,6 @@ public class PolicyDAOImpl implements PolicyDAO {
String query = "SELECT ACTION_TYPE, CORRECTIVE_POLICY_ID, FEATURE_ID, POLICY_ID, IS_REACTIVE " +
"FROM DM_POLICY_CORRECTIVE_ACTION ";
try (PreparedStatement stmt = conn.prepareStatement(query)) {
List<CorrectiveAction> correctiveActions = new ArrayList<>();
return extractCorrectivePolicies(stmt);
}
} catch (SQLException e) {
@ -826,7 +767,7 @@ public class PolicyDAOImpl implements PolicyDAO {
Connection conn;
PreparedStatement stmt = null;
ResultSet resultSet = null;
List<Criterion> criteria = new ArrayList<Criterion>();
List<Criterion> criteria = new ArrayList<>();
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
try {
conn = this.getConnection();
@ -912,8 +853,6 @@ public class PolicyDAOImpl implements PolicyDAO {
}
stmt.executeBatch();
}
// stmt.executeUpdate();
} catch (SQLException | IOException e) {
throw new PolicyManagerDAOException("Error occurred while inserting the criterion properties " +
"to database", e);
@ -928,7 +867,7 @@ public class PolicyDAOImpl implements PolicyDAO {
Connection conn;
PreparedStatement stmt = null;
ResultSet resultSet = null;
List<PolicyCriterion> criteria = new ArrayList<PolicyCriterion>();
List<PolicyCriterion> criteria = new ArrayList<>();
try {
conn = this.getConnection();
String query = "SELECT DPC.ID, DPC.CRITERIA_ID, DPCP.PROP_KEY, DPCP.PROP_VALUE, DPCP.CONTENT FROM " +
@ -1152,7 +1091,6 @@ public class PolicyDAOImpl implements PolicyDAO {
Connection conn;
PreparedStatement stmt = null;
ResultSet resultSet = null;
List<Policy> policies = new ArrayList<Policy>();
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
try {
@ -1180,7 +1118,7 @@ public class PolicyDAOImpl implements PolicyDAO {
Connection conn;
PreparedStatement stmt = null;
ResultSet resultSet = null;
List<Integer> deviceIdList = new ArrayList<Integer>();
List<Integer> deviceIdList = new ArrayList<>();
try {
conn = this.getConnection();
String query = "SELECT * FROM DM_DEVICE_POLICY WHERE POLICY_ID = ?";
@ -1204,7 +1142,7 @@ public class PolicyDAOImpl implements PolicyDAO {
Connection conn;
PreparedStatement stmt = null;
ResultSet resultSet = null;
List<String> roleNames = new ArrayList<String>();
List<String> roleNames = new ArrayList<>();
try {
conn = this.getConnection();
String query = "SELECT * FROM DM_ROLE_POLICY WHERE POLICY_ID = ?";
@ -1229,7 +1167,7 @@ public class PolicyDAOImpl implements PolicyDAO {
PreparedStatement stmt = null;
ResultSet resultSet = null;
List<String> users = new ArrayList<String>();
List<String> users = new ArrayList<>();
try {
conn = this.getConnection();
String query = "SELECT * FROM DM_USER_POLICY WHERE POLICY_ID = ?";
@ -1387,7 +1325,7 @@ public class PolicyDAOImpl implements PolicyDAO {
Connection conn;
PreparedStatement stmt = null;
ResultSet resultSet = null;
List<Integer> policyIds = new ArrayList<Integer>();
List<Integer> policyIds = new ArrayList<>();
try {
conn = this.getConnection();
String query = "SELECT * FROM DM_DEVICE_POLICY WHERE DEVICE_ID = ? ";
@ -1411,7 +1349,7 @@ public class PolicyDAOImpl implements PolicyDAO {
Connection conn;
PreparedStatement stmt = null;
ResultSet resultSet = null;
List<Integer> policyIds = new ArrayList<Integer>();
List<Integer> policyIds = new ArrayList<>();
try {
conn = this.getConnection();
String query = "SELECT * FROM DM_ROLE_POLICY WHERE ROLE_NAME = ? ";
@ -1435,7 +1373,7 @@ public class PolicyDAOImpl implements PolicyDAO {
Connection conn;
PreparedStatement stmt = null;
ResultSet resultSet = null;
List<Integer> policyIds = new ArrayList<Integer>();
List<Integer> policyIds = new ArrayList<>();
try {
conn = this.getConnection();
String query = "SELECT * FROM DM_USER_POLICY WHERE USERNAME = ? ";
@ -1563,16 +1501,6 @@ public class PolicyDAOImpl implements PolicyDAO {
try {
conn = this.getConnection();
// String userPolicy = "DELETE FROM DM_USER_POLICY WHERE POLICY_ID = ?";
// stmt = conn.prepareStatement(userPolicy);
// stmt.setInt(1, policyId);
// stmt.executeUpdate();
//
// String rolePolicy = "DELETE FROM DM_ROLE_POLICY WHERE POLICY_ID = ?";
// stmt = conn.prepareStatement(rolePolicy);
// stmt.setInt(1, policyId);
// stmt.executeUpdate();
String devicePolicy = "DELETE FROM DM_DEVICE_POLICY WHERE POLICY_ID = ?";
stmt = conn.prepareStatement(devicePolicy);
stmt.setInt(1, policyId);
@ -1601,7 +1529,7 @@ public class PolicyDAOImpl implements PolicyDAO {
}
}
private Connection getConnection() throws PolicyManagerDAOException {
private Connection getConnection() {
return PolicyManagementDAOFactory.getConnection();
}
@ -1821,15 +1749,6 @@ public class PolicyDAOImpl implements PolicyDAO {
} finally {
PolicyManagementDAOUtil.cleanupResources(stmt, resultSet);
}
//
// if (policy != null && log.isDebugEnabled()) {
// log.debug("Applied policy logging details started ------------------");
// log.debug("Applied policy name " + policy.getPolicyName() + "for the device id " + deviceId);
// log.debug(policy.getCompliance());
// log.debug(policy.getId());
// log.debug(policy.getPriorityId());
// log.debug("Applied policy logging details finished....");
// }
return policy;
}

@ -41,7 +41,8 @@ import java.util.Map;
public class DelegationTask implements Task {
private static final Log log = LogFactory.getLog(DelegationTask.class);
private PolicyConfiguration policyConfiguration = DeviceConfigurationManager.getInstance().getDeviceManagementConfig().getPolicyConfiguration();
private PolicyConfiguration policyConfiguration = DeviceConfigurationManager.getInstance()
.getDeviceManagementConfig().getPolicyConfiguration();
@Override
public void setProperties(Map<String, String> map) {
@ -73,21 +74,17 @@ public class DelegationTask implements Task {
List<Device> toBeNotified;
for (String deviceType : deviceTypes) {
try {
devices = new ArrayList<>();
toBeNotified = new ArrayList<>();
devices.addAll(service.getAllDevices(deviceType, false));
//HashMap<Integer, Integer> deviceIdPolicy = policyManager.getAppliedPolicyIdsDeviceIds();
devices = new ArrayList<>(service.getAllDevices(deviceType, false));
for (Device device : devices) {
// if (deviceIdPolicy.containsKey(device.getId())) {
if (device != null && device.getEnrolmentInfo() != null
&& device.getEnrolmentInfo().getStatus() != EnrolmentInfo.Status.REMOVED) {
toBeNotified.add(device);
}
// }
}
if (!toBeNotified.isEmpty()) {
PolicyEnforcementDelegator enforcementDelegator = new PolicyEnforcementDelegatorImpl
(toBeNotified, updatedPolicyDeviceList.getUpdatedPolicyIds());
PolicyEnforcementDelegator enforcementDelegator = new PolicyEnforcementDelegatorImpl(
toBeNotified, updatedPolicyDeviceList.getUpdatedPolicyIds());
enforcementDelegator.delegate();
}
} catch (DeviceManagementException e) {

@ -122,7 +122,6 @@ public class PolicyEnforcementDelegatorImpl implements PolicyEnforcementDelegato
return null;
}
return policy;
//return PolicyManagementDataHolder.getInstance().getPolicyEvaluationPoint().getEffectivePolicy(identifier);
} catch (PolicyEvaluationException | PolicyManagementException e) {
String msg = "Error occurred while retrieving the effective policy for devices.";
log.error(msg, e);
@ -135,7 +134,7 @@ public class PolicyEnforcementDelegatorImpl implements PolicyEnforcementDelegato
PolicyDelegationException {
try {
String type = null;
if (deviceIdentifiers.size() > 0) {
if (!deviceIdentifiers.isEmpty()) {
type = deviceIdentifiers.get(0).getType();
}
PolicyManagementDataHolder.getInstance().getDeviceManagementService().addOperation(type,
@ -161,7 +160,7 @@ public class PolicyEnforcementDelegatorImpl implements PolicyEnforcementDelegato
public void addPolicyRevokeOperation(List<DeviceIdentifier> deviceIdentifiers) throws PolicyDelegationException {
try {
String type = null;
if (deviceIdentifiers.size() > 0) {
if (!deviceIdentifiers.isEmpty()) {
type = deviceIdentifiers.get(0).getType();
}
PolicyManagementDataHolder.getInstance().getDeviceManagementService().addOperation(type,

@ -34,10 +34,8 @@ import org.wso2.carbon.policy.mgt.common.*;
import org.wso2.carbon.policy.mgt.core.cache.PolicyCacheManager;
import org.wso2.carbon.policy.mgt.core.cache.impl.PolicyCacheManagerImpl;
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;
import org.wso2.carbon.policy.mgt.core.mgt.impl.FeatureManagerImpl;
import org.wso2.carbon.policy.mgt.core.mgt.impl.PolicyManagerImpl;
import org.wso2.carbon.policy.mgt.core.mgt.impl.ProfileManagerImpl;
import org.wso2.carbon.policy.mgt.core.util.PolicyManagementConstants;
@ -53,28 +51,18 @@ public class PolicyAdministratorPointImpl implements PolicyAdministratorPoint {
private PolicyManager policyManager;
private ProfileManager profileManager;
private FeatureManager featureManager;
private PolicyCacheManager cacheManager;
private PolicyConfiguration policyConfiguration;
// private PolicyEnforcementDelegator delegator;
public PolicyAdministratorPointImpl() {
this.policyManager = new PolicyManagerImpl();
this.profileManager = new ProfileManagerImpl();
this.featureManager = new FeatureManagerImpl();
this.cacheManager = PolicyCacheManagerImpl.getInstance();
this.policyConfiguration = DeviceConfigurationManager.getInstance().getDeviceManagementConfig().getPolicyConfiguration();
// this.delegator = new PolicyEnforcementDelegatorImpl();
this.policyConfiguration = DeviceConfigurationManager.getInstance().getDeviceManagementConfig()
.getPolicyConfiguration();
}
@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);
// }
if (policyConfiguration.getCacheEnable()) {
PolicyCacheManagerImpl.getInstance().rePopulateCache();
}
@ -84,11 +72,6 @@ public class PolicyAdministratorPointImpl implements PolicyAdministratorPoint {
@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);
// }
if (policyConfiguration.getCacheEnable()) {
PolicyCacheManagerImpl.getInstance().rePopulateCache();
}
@ -190,7 +173,6 @@ public class PolicyAdministratorPointImpl implements PolicyAdministratorPoint {
}
}
}
} catch (TaskException e) {
String msg = "Error occurred while creating the policy delegation task for tenant " +
PrivilegedCarbonContext.
@ -198,42 +180,6 @@ public class PolicyAdministratorPointImpl implements PolicyAdministratorPoint {
log.error(msg, e);
throw new PolicyManagementException(msg, e);
}
// List<DeviceType> deviceTypes = policyManager.applyChangesMadeToPolicies();
//
// if(log.isDebugEnabled()) {
// log.debug("Number of device types which policies are changed .......... : " + deviceTypes.size() );
// }
//
// if (!deviceTypes.isEmpty()) {
//
//
// DeviceManagementProviderService service = PolicyManagementDataHolder.getInstance()
// .getDeviceManagementService();
// List<Device> devices = new ArrayList<>();
// for (DeviceType deviceType : deviceTypes) {
// try {
// devices.addAll(service.getAllDevices(deviceType.getName()));
// } catch (DeviceManagementException e) {
// throw new PolicyManagementException("Error occurred while taking the devices", e);
// }
// }
// HashMap<Integer, Integer> deviceIdPolicy = policyManager.getAppliedPolicyIdsDeviceIds();
// List<Device> toBeNotified = new ArrayList<>();
//
// for (Device device : devices) {
// if (deviceIdPolicy.containsKey(device.getId())) {
// toBeNotified.add(device);
// }
// }
// if (!toBeNotified.isEmpty()) {
//
// // ExecutorService executorService = getExecutor();
// // PolicyEnforcementDelegator enforcementDelegator = new PolicyEnforcementDelegatorImpl(toBeNotified);
//// Thread thread = new Thread(new PolicyEnforcementDelegatorImpl(toBeNotified));
//// thread.start();
// }
// }
}
@Override

@ -63,7 +63,7 @@ public class PolicyFilterImpl implements PolicyFilter {
}
}
List<Policy> temp = new ArrayList<Policy>();
List<Policy> temp = new ArrayList<>();
for (Policy policy : policies) {
if (policy.isActive()) {
temp.add(policy);

@ -18,8 +18,6 @@
package org.wso2.carbon.policy.mgt.core.mgt.bean;
import org.wso2.carbon.device.mgt.common.policy.mgt.Policy;
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
import java.util.List;

@ -32,7 +32,6 @@ import org.wso2.carbon.device.mgt.common.policy.mgt.Policy;
import org.wso2.carbon.device.mgt.common.policy.mgt.PolicyMonitoringManager;
import org.wso2.carbon.device.mgt.common.policy.mgt.ProfileFeature;
import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.ComplianceData;
import org.wso2.carbon.device.mgt.common.policy.mgt.ProfileFeature;
import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.ComplianceFeature;
import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.NonComplianceData;
import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.PolicyComplianceException;

@ -241,9 +241,9 @@ public class PolicyManagerImpl implements PolicyManager {
policy.getProfile().setUpdatedDate(currentTimestamp);
policy.setPriorityId(previousPolicy.getPriorityId());
policy.setPolicyPayloadVersion(previousPolicy.getPolicyPayloadVersion());
Policy updatedPolicy = policyDAO.updatePolicy(policy);
profileDAO.updateProfile(policy.getProfile());
policyDAO.updatePolicy(policy);
profileDAO.updateProfile(policy.getProfile());
featureDAO.updateProfileFeatures(existingFeaturesList, profileId);
if (!newFeaturesList.isEmpty()) {
featureDAO.addProfileFeatures(newFeaturesList, profileId);
@ -646,8 +646,8 @@ public class PolicyManagerImpl implements PolicyManager {
@Override
public void inactivatePolicy(int policyId) throws PolicyManagementException {
try {
Policy policy = this.getPolicy(policyId);
try {
PolicyManagementDAOFactory.beginTransaction();
policyDAO.inactivatePolicy(policyId);
policyDAO.recordUpdatedPolicy(policy);

@ -22,8 +22,6 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.common.policy.mgt.Profile;
import org.wso2.carbon.device.mgt.common.policy.mgt.ProfileFeature;
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
import org.wso2.carbon.device.mgt.core.dao.DeviceTypeDAO;
import org.wso2.carbon.policy.mgt.common.ProfileManagementException;
import org.wso2.carbon.policy.mgt.core.dao.FeatureDAO;
import org.wso2.carbon.policy.mgt.core.dao.FeatureManagerDAOException;
@ -41,17 +39,13 @@ import java.util.List;
public class ProfileManagerImpl implements ProfileManager {
private static Log log = LogFactory.getLog(ProfileManagerImpl.class);
private static final Log log = LogFactory.getLog(ProfileManagerImpl.class);
private ProfileDAO profileDAO;
private FeatureDAO featureDAO;
// private DeviceDAO deviceDAO;
private DeviceTypeDAO deviceTypeDAO;
public ProfileManagerImpl() {
profileDAO = PolicyManagementDAOFactory.getProfileDAO();
featureDAO = PolicyManagementDAOFactory.getFeatureDAO();
// deviceDAO = DeviceManagementDAOFactory.getDeviceDAO();
deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO();
}
@Override
@ -68,19 +62,21 @@ public class ProfileManagerImpl implements ProfileManager {
PolicyManagementDAOFactory.commitTransaction();
} catch (ProfileManagerDAOException e) {
PolicyManagementDAOFactory.rollbackTransaction();
throw new ProfileManagementException("Error occurred while adding the profile (" +
profile.getProfileName() + ")", e);
String msg = "Error occurred while adding the profile (" + profile.getProfileName() + ")";
log.error(msg, e);
throw new ProfileManagementException(msg, e);
} catch (FeatureManagerDAOException e) {
PolicyManagementDAOFactory.rollbackTransaction();
throw new ProfileManagementException("Error occurred while adding the profile features (" +
profile.getProfileName() + ")", e);
String msg = "Error occurred while adding the profile features (" + profile.getProfileName() + ")";
log.error(msg, e);
throw new ProfileManagementException(msg, e);
} catch (PolicyManagerDAOException e) {
throw new ProfileManagementException("Error occurred while adding the profile (" +
profile.getProfileName() + ") to the database", e);
String msg = "Error occurred while adding the profile (" + profile.getProfileName() + ") to the database";
log.error(msg, e);
throw new ProfileManagementException(msg, e);
} finally {
PolicyManagementDAOFactory.closeConnection();
}
return profile;
}
@ -115,7 +111,7 @@ public class ProfileManagerImpl implements ProfileManager {
@Override
public boolean deleteProfile(Profile profile) throws ProfileManagementException {
boolean bool = true;
boolean bool;
try {
PolicyManagementDAOFactory.beginTransaction();
featureDAO.deleteFeaturesOfProfile(profile);
@ -173,7 +169,7 @@ public class ProfileManagerImpl implements ProfileManager {
for (Profile profile : profileList) {
List<ProfileFeature> list = new ArrayList<ProfileFeature>();
List<ProfileFeature> list = new ArrayList<>();
for (ProfileFeature profileFeature : featureList) {
if (profile.getProfileId() == profileFeature.getProfileId()) {
list.add(profileFeature);
@ -204,7 +200,7 @@ public class ProfileManagerImpl implements ProfileManager {
featureList = featureDAO.getAllProfileFeatures();
for (Profile profile : profileList) {
List<ProfileFeature> profileFeatureList = new ArrayList<ProfileFeature>();
List<ProfileFeature> profileFeatureList = new ArrayList<>();
for (ProfileFeature profileFeature : featureList) {
if (profile.getProfileId() == profileFeature.getProfileId()) {
profileFeatureList.add(profileFeature);
@ -224,5 +220,4 @@ public class ProfileManagerImpl implements ProfileManager {
}
return profileList;
}
}

@ -38,7 +38,7 @@ import java.util.Map;
public class TaskScheduleServiceImpl implements TaskScheduleService {
private static Log log = LogFactory.getLog(TaskScheduleServiceImpl.class);
private static final Log log = LogFactory.getLog(TaskScheduleServiceImpl.class);
private PolicyConfiguration policyConfiguration;

Loading…
Cancel
Save