policy manager refactored to support tenancy

revert-70aa11f8
ayyoob 8 years ago
parent 9995f4293e
commit db2ddc7bed

@ -41,6 +41,7 @@ import javax.xml.bind.annotation.XmlRootElement;
* <element name="PushNotificationProvider" type="{}PushNotificationProvider"/>
* <element name="License" type="{}License"/>
* <element name="DataSource" type="{}DataSource"/>
* <element name="PolicyMonitoring" type="{}PolicyMonitoring"/>
* <element name="DeviceAuthorizationConfig" type="{}DeviceAuthorizationConfig"/>
* </sequence>
* <attribute name="name" type="{http://www.w3.org/2001/XMLSchema}string" />
@ -71,6 +72,8 @@ public class DeviceTypeConfiguration {
protected DeviceAuthorizationConfig deviceAuthorizationConfig;
@XmlAttribute(name = "name")
protected String name;
@XmlElement(name = "PolicyMonitoring", required = true)
protected PolicyMonitoring policyMonitoring;
/**
* Gets the value of the taskConfiguration property.
@ -116,6 +119,26 @@ public class DeviceTypeConfiguration {
this.deviceDetails = value;
}
/**
* Gets the value of the policyMonitoring property.
*
* @return possible object is
* {@link DeviceDetails }
*/
public PolicyMonitoring getPolicyMonitoring() {
return policyMonitoring;
}
/**
* Sets the value of the policyMonitoring property.
*
* @param value allowed object is
* {@link DeviceDetails }
*/
public void setDeviceDetails(PolicyMonitoring value) {
this.policyMonitoring = value;
}
/**
* Gets the value of the features property.
*

@ -0,0 +1,104 @@
/*
* Copyright (c) 2016, 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.device.mgt.extensions.device.type.deployer.config;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlType;
import javax.xml.bind.annotation.XmlValue;
/**
* <p>Java class for PolicyMonitoring complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* &lt;complexType name="PolicyMonitoring">
* &lt;simpleContent>
* &lt;extension base="&lt;http://www.w3.org/2001/XMLSchema>string">
* &lt;attribute name="enabled" type="{http://www.w3.org/2001/XMLSchema}boolean" />
* &lt;/extension>
* &lt;/simpleContent>
* &lt;/complexType>
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "PolicyMonitoring", propOrder = {
"value"
})
public class PolicyMonitoring {
@XmlValue
protected String value;
@XmlAttribute(name = "enabled")
protected boolean enabled;
/**
* Gets the value of the value property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getValue() {
return value;
}
/**
* Sets the value of the value property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setValue(String value) {
this.value = value;
}
/**
* Gets the value of the enabled property.
*
* @return
* possible object is
* {@link String }
*
*/
public boolean isEnabled() {
return enabled;
}
/**
* Sets the value of the enabled property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setEnabled(boolean value) {
this.enabled = value;
}
}

@ -21,6 +21,8 @@ package org.wso2.carbon.device.mgt.extensions.device.type.deployer.internal;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.osgi.service.component.ComponentContext;
import org.wso2.carbon.application.deployer.handler.AppDeploymentHandler;
import org.wso2.carbon.device.mgt.extensions.device.type.deployer.DeviceTypeCAppDeployer;
import org.wso2.carbon.registry.core.service.RegistryService;
import org.wso2.carbon.utils.ConfigurationContextService;
@ -45,6 +47,7 @@ public class DeviceTypeManagementServiceComponent {
if (log.isDebugEnabled()) {
log.debug("Activating DeviceType Deployer Service Component");
}
ctx.getBundleContext().registerService(AppDeploymentHandler.class.getName(), new DeviceTypeCAppDeployer(), null);
DeviceTypeManagementDataHolder.getInstance().setBundleContext(ctx.getBundleContext());
}

@ -28,12 +28,14 @@ import org.wso2.carbon.device.mgt.common.ProvisioningConfig;
import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager;
import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationEntry;
import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration;
import org.wso2.carbon.device.mgt.common.policy.mgt.PolicyMonitoringManager;
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig;
import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
import org.wso2.carbon.device.mgt.extensions.device.type.deployer.config.DeviceTypeConfiguration;
import org.wso2.carbon.device.mgt.extensions.device.type.deployer.config.Property;
import org.wso2.carbon.device.mgt.extensions.device.type.deployer.config.PushNotificationProvider;
import org.wso2.carbon.device.mgt.extensions.device.type.deployer.config.TaskConfiguration;
import org.wso2.carbon.device.mgt.extensions.device.type.deployer.template.policy.mgt.DefaultPolicyMonitoringManager;
import java.util.ArrayList;
import java.util.HashMap;
@ -54,6 +56,7 @@ public class DeviceTypeManagerService implements DeviceManagementService {
private String type;
private OperationMonitoringTaskConfig operationMonitoringConfigs;
private List<MonitoringOperation> monitoringOperations;
private PolicyMonitoringManager policyMonitoringManager;
public DeviceTypeManagerService(DeviceTypeConfigIdentifier deviceTypeConfigIdentifier,
DeviceTypeConfiguration deviceTypeConfiguration) {
@ -63,6 +66,10 @@ public class DeviceTypeManagerService implements DeviceManagementService {
this.populatePushNotificationConfig(deviceTypeConfiguration.getPushNotificationProvider());
this.operationMonitoringConfigs = new OperationMonitoringTaskConfig();
this.setOperationMonitoringConfig(deviceTypeConfiguration);
if (deviceTypeConfiguration.getPolicyMonitoring() != null && deviceTypeConfiguration.getPolicyMonitoring()
.isEnabled()) {
this.policyMonitoringManager = new DefaultPolicyMonitoringManager();
}
}
@Override
@ -145,6 +152,11 @@ public class DeviceTypeManagerService implements DeviceManagementService {
return pushNotificationConfig;
}
@Override
public PolicyMonitoringManager getPolicyMonitoringManager() {
return null;
}
private void setProvisioningConfig(String tenantDomain, DeviceTypeConfiguration deviceTypeConfiguration) {
if (deviceTypeConfiguration.getProvisioningConfig() != null) {
boolean sharedWithAllTenants = deviceTypeConfiguration.getProvisioningConfig().isSharedWithAllTenants();

@ -0,0 +1,72 @@
/*
* Copyright (c) 2016, 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.device.mgt.extensions.device.type.deployer.template.policy.mgt;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.Feature;
import org.wso2.carbon.device.mgt.common.FeatureManager;
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 org.wso2.carbon.device.mgt.extensions.device.type.deployer.config.Operation;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* This implementation policy monitoring manager.
*/
public class DefaultPolicyMonitoringManager implements PolicyMonitoringManager {
private static Log log = LogFactory.getLog(DefaultPolicyMonitoringManager.class);
@Override
public NonComplianceData checkPolicyCompliance(DeviceIdentifier deviceIdentifier, Policy policy, Object response)
throws PolicyComplianceException {
if (log.isDebugEnabled()) {
log.debug("Checking policy compliance status of device '" + deviceIdentifier.getId() + "'");
}
NonComplianceData nonComplianceData = new NonComplianceData();
if (response == null || policy == null) {
return nonComplianceData;
}
List<ComplianceFeature> complianceFeatures = (List<ComplianceFeature>) response;
List<ComplianceFeature> nonComplianceFeatures = new ArrayList<>();
for (ComplianceFeature complianceFeature : complianceFeatures) {
if (!complianceFeature.isCompliant()) {
nonComplianceFeatures.add(complianceFeature);
nonComplianceData.setStatus(false);
break;
}
}
nonComplianceData.setComplianceFeatures(nonComplianceFeatures);
return nonComplianceData;
}
}

@ -81,12 +81,33 @@
</ConfigProperties>
</PushNotificationProvider>
<PolicyMonitoring enabled="true"/>
<License>
<Language>en_US</Language>
<Version>1.0.0</Version>
<Text>This is license text</Text>
</License>
<TaskConfiguration>
<Enable>true</Enable>
<Frequency>600000</Frequency>
<Operations>
<Operation>
<Name>DEVICE_INFO</Name>
<RecurrentTimes>1</RecurrentTimes>
</Operation>
<Operation>
<Name>APPLICATION_LIST</Name>
<RecurrentTimes>5</RecurrentTimes>
</Operation>
<Operation>
<Name>DEVICE_LOCATION</Name>
<RecurrentTimes>1</RecurrentTimes>
</Operation>
</Operations>
</TaskConfiguration>
<DataSource>
<jndiConfig>
<name>jdbc/SampleDM_DB</name>
@ -101,22 +122,5 @@
</Table>
</tableConfig>
</DataSource>
<TaskConfiguration>
<Enable>true</Enable>
<Frequency>600000</Frequency>
<Operations>
<Operation>
<Name>DEVICE_INFO</Name>
<RecurrentTimes>1</RecurrentTimes>
</Operation>
<Operation>
<Name>APPLICATION_LIST</Name>
<RecurrentTimes>5</RecurrentTimes>
</Operation>
<Operation>
<Name>DEVICE_LOCATION</Name>
<RecurrentTimes>1</RecurrentTimes>
</Operation>
</Operations>
</TaskConfiguration>
</DeviceTypeConfiguration>

@ -19,20 +19,20 @@
package org.wso2.carbon.device.mgt.jaxrs.beans;
import io.swagger.annotations.ApiModel;
import org.wso2.carbon.policy.mgt.common.monitor.ComplianceData;
import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.NonComplianceData;
@ApiModel(value = "DeviceCompliance", description = "Device's policy compliance status")
public class DeviceCompliance {
private String deviceID;
private ComplianceData complianceData;
private NonComplianceData complianceData;
private Long code;
public ComplianceData getComplianceData() {
public NonComplianceData getComplianceData() {
return complianceData;
}
public void setComplianceData(ComplianceData complianceData) {
public void setComplianceData(NonComplianceData complianceData) {
this.complianceData = complianceData;
}

@ -21,7 +21,7 @@ package org.wso2.carbon.device.mgt.jaxrs.beans;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.wso2.carbon.policy.mgt.common.Policy;
import org.wso2.carbon.device.mgt.common.policy.mgt.Policy;
import java.util.List;

@ -21,7 +21,7 @@ package org.wso2.carbon.device.mgt.jaxrs.beans;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.policy.mgt.common.DeviceGroupWrapper;
import org.wso2.carbon.device.mgt.common.policy.mgt.DeviceGroupWrapper;
import javax.validation.constraints.Size;
import java.util.List;

@ -38,8 +38,8 @@ import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
import org.wso2.carbon.device.mgt.common.search.SearchContext;
import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceList;
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
import org.wso2.carbon.policy.mgt.common.Policy;
import org.wso2.carbon.policy.mgt.common.monitor.ComplianceData;
import org.wso2.carbon.device.mgt.common.policy.mgt.Policy;
import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.NonComplianceData;
import javax.validation.constraints.Size;
import javax.ws.rs.*;
@ -850,7 +850,7 @@ public interface DeviceManagementService {
@ApiResponse(
code = 200,
message = "OK",
response = ComplianceData.class),
response = NonComplianceData.class),
@ApiResponse(
code = 400,
message = "Bad Request. \n Invalid request or validation error.",

@ -35,7 +35,7 @@ import org.wso2.carbon.apimgt.annotations.api.Permission;
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
import org.wso2.carbon.device.mgt.jaxrs.beans.PolicyWrapper;
import org.wso2.carbon.device.mgt.jaxrs.beans.PriorityUpdatedPolicyWrapper;
import org.wso2.carbon.policy.mgt.common.Policy;
import org.wso2.carbon.device.mgt.common.policy.mgt.Policy;
import javax.validation.Valid;
import javax.ws.rs.*;

@ -40,10 +40,10 @@ import org.wso2.carbon.device.mgt.jaxrs.beans.OperationList;
import org.wso2.carbon.device.mgt.jaxrs.service.api.DeviceManagementService;
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.RequestValidationUtil;
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils;
import org.wso2.carbon.policy.mgt.common.Policy;
import org.wso2.carbon.device.mgt.common.policy.mgt.Policy;
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
import org.wso2.carbon.policy.mgt.common.monitor.ComplianceData;
import org.wso2.carbon.policy.mgt.common.monitor.PolicyComplianceException;
import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.NonComplianceData;
import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.PolicyComplianceException;
import org.wso2.carbon.policy.mgt.core.PolicyManagerService;
import org.wso2.carbon.utils.multitenancy.MultitenantUtils;
@ -442,7 +442,7 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
RequestValidationUtil.validateDeviceIdentifier(type, id);
PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService();
Policy policy;
ComplianceData complianceData = null;
NonComplianceData complianceData = null;
DeviceCompliance deviceCompliance = new DeviceCompliance();
try {

@ -36,7 +36,7 @@ import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.FilteringUtil;
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.RequestValidationUtil;
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils;
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtUtil;
import org.wso2.carbon.policy.mgt.common.Policy;
import org.wso2.carbon.device.mgt.common.policy.mgt.Policy;
import org.wso2.carbon.policy.mgt.common.PolicyAdministratorPoint;
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
import org.wso2.carbon.policy.mgt.core.PolicyManagerService;
@ -168,7 +168,7 @@ public class PolicyManagementServiceImpl implements PolicyManagementService {
@Override
public Response getPolicy(@PathParam("id") int id, @HeaderParam("If-Modified-Since") String ifModifiedSince) {
PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService();
final org.wso2.carbon.policy.mgt.common.Policy policy;
final Policy policy;
try {
PolicyAdministratorPoint policyAdministratorPoint = policyManagementService.getPAP();
policy = policyAdministratorPoint.getPolicy(id);
@ -378,7 +378,7 @@ public class PolicyManagementServiceImpl implements PolicyManagementService {
@Override
public Response getEffectivePolicy(@PathParam("deviceId") String deviceId, @PathParam("deviceType") String deviceType) {
PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService();
final org.wso2.carbon.policy.mgt.common.Policy policy;
final Policy policy;
try {
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
deviceIdentifier.setId(deviceId);

@ -23,7 +23,7 @@ import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorListItem;
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
import org.wso2.carbon.device.mgt.jaxrs.beans.ProfileFeature;
import org.wso2.carbon.device.mgt.jaxrs.exception.BadRequestException;
import org.wso2.carbon.policy.mgt.common.Profile;
import org.wso2.carbon.device.mgt.common.policy.mgt.Profile;
import javax.validation.ConstraintViolation;
import java.util.ArrayList;
@ -38,9 +38,8 @@ public class DeviceMgtUtil {
profile.setCreatedDate(mdmProfile.getCreatedDate());
profile.setDeviceType(mdmProfile.getDeviceType());
List<org.wso2.carbon.policy.mgt.common.ProfileFeature> profileFeatures =
new ArrayList<org.wso2.carbon.policy.
mgt.common.ProfileFeature>(mdmProfile.getProfileFeaturesList().size());
List<org.wso2.carbon.device.mgt.common.policy.mgt.ProfileFeature> profileFeatures =
new ArrayList<org.wso2.carbon.device.mgt.common.policy.mgt.ProfileFeature>(mdmProfile.getProfileFeaturesList().size());
for (ProfileFeature mdmProfileFeature : mdmProfile.getProfileFeaturesList()) {
profileFeatures.add(convertProfileFeature(mdmProfileFeature));
}
@ -51,11 +50,11 @@ public class DeviceMgtUtil {
return profile;
}
public static org.wso2.carbon.policy.mgt.common.ProfileFeature convertProfileFeature(ProfileFeature
public static org.wso2.carbon.device.mgt.common.policy.mgt.ProfileFeature convertProfileFeature(ProfileFeature
mdmProfileFeature) {
org.wso2.carbon.policy.mgt.common.ProfileFeature profileFeature =
new org.wso2.carbon.policy.mgt.common.ProfileFeature();
org.wso2.carbon.device.mgt.common.policy.mgt.ProfileFeature profileFeature =
new org.wso2.carbon.device.mgt.common.policy.mgt.ProfileFeature();
profileFeature.setProfileId(mdmProfileFeature.getProfileId());
profileFeature.setContent(mdmProfileFeature.getPayLoad());
profileFeature.setDeviceType(mdmProfileFeature.getDeviceTypeId());

@ -17,7 +17,7 @@
*/
package org.wso2.carbon.policy.mgt.common;
package org.wso2.carbon.device.mgt.common.policy.mgt;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

@ -15,7 +15,7 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.policy.mgt.common;
package org.wso2.carbon.device.mgt.common.policy.mgt;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

@ -17,23 +17,15 @@
*/
package org.wso2.carbon.policy.mgt.common.spi;
package org.wso2.carbon.device.mgt.common.policy.mgt;
import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.policy.mgt.common.monitor.ComplianceData;
import org.wso2.carbon.policy.mgt.common.monitor.ComplianceFeature;
import org.wso2.carbon.policy.mgt.common.monitor.PolicyComplianceException;
import org.wso2.carbon.policy.mgt.common.Policy;
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.List;
public interface PolicyMonitoringService {
public interface PolicyMonitoringManager {
void notifyDevices(List<Device> devices) throws PolicyComplianceException;
ComplianceData checkPolicyCompliance(DeviceIdentifier deviceIdentifier, Policy policy, Object response)
NonComplianceData checkPolicyCompliance(DeviceIdentifier deviceIdentifier, Policy policy, Object response)
throws PolicyComplianceException;
String getType();
}

@ -16,11 +16,10 @@
* under the License.
*/
package org.wso2.carbon.policy.mgt.common;
package org.wso2.carbon.device.mgt.common.policy.mgt;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

@ -16,7 +16,7 @@
* under the License.
*/
package org.wso2.carbon.policy.mgt.common;
package org.wso2.carbon.device.mgt.common.policy.mgt;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

@ -17,9 +17,9 @@
*/
package org.wso2.carbon.policy.mgt.common.monitor;
package org.wso2.carbon.device.mgt.common.policy.mgt.monitor;
import org.wso2.carbon.policy.mgt.common.ProfileFeature;
import org.wso2.carbon.device.mgt.common.policy.mgt.ProfileFeature;
public class ComplianceFeature {

@ -17,14 +17,14 @@
*/
package org.wso2.carbon.policy.mgt.common.monitor;
package org.wso2.carbon.device.mgt.common.policy.mgt.monitor;
import org.wso2.carbon.policy.mgt.common.Policy;
import org.wso2.carbon.device.mgt.common.policy.mgt.Policy;
import java.sql.Timestamp;
import java.util.List;
public class ComplianceData {
public class NonComplianceData {
private int id;
private int deviceId;

@ -23,6 +23,7 @@ import org.wso2.carbon.device.mgt.common.DeviceManager;
import org.wso2.carbon.device.mgt.common.OperationMonitoringTaskConfig;
import org.wso2.carbon.device.mgt.common.ProvisioningConfig;
import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager;
import org.wso2.carbon.device.mgt.common.policy.mgt.PolicyMonitoringManager;
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig;
/**
@ -45,4 +46,6 @@ public interface DeviceManagementService {
PushNotificationConfig getPushNotificationConfig();
PolicyMonitoringManager getPolicyMonitoringManager();
}

@ -31,6 +31,7 @@ import org.wso2.carbon.device.mgt.common.license.mgt.License;
import org.wso2.carbon.device.mgt.common.operation.mgt.Activity;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
import org.wso2.carbon.device.mgt.common.policy.mgt.PolicyMonitoringManager;
import java.util.Date;
import java.util.HashMap;
@ -304,4 +305,6 @@ public interface DeviceManagementProviderService {
boolean isDeviceMonitoringEnabled(String deviceType);
PolicyMonitoringManager getPolicyMonitoringManager(String deviceType);
}

@ -49,6 +49,7 @@ import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException;
import org.wso2.carbon.device.mgt.common.operation.mgt.Activity;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
import org.wso2.carbon.device.mgt.common.policy.mgt.PolicyMonitoringManager;
import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
import org.wso2.carbon.device.mgt.core.DeviceManagementConstants;
import org.wso2.carbon.device.mgt.core.DeviceManagementPluginRepository;
@ -1255,6 +1256,13 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
return operationMonitoringTaskConfig.isEnabled();
}
@Override
public PolicyMonitoringManager getPolicyMonitoringManager(String deviceType) {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
DeviceManagementService dms = pluginRepository.getDeviceManagementService(deviceType, tenantId);
return dms.getPolicyMonitoringManager();
}
@Override
public List<Device> getDevicesOfUser(String username) throws DeviceManagementException {
List<Device> devices = new ArrayList<>();

@ -22,6 +22,7 @@ import org.wso2.carbon.device.mgt.common.DeviceManager;
import org.wso2.carbon.device.mgt.common.OperationMonitoringTaskConfig;
import org.wso2.carbon.device.mgt.common.ProvisioningConfig;
import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager;
import org.wso2.carbon.device.mgt.common.policy.mgt.PolicyMonitoringManager;
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig;
import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
@ -69,4 +70,9 @@ public class TestDeviceManagementService implements DeviceManagementService {
return null;
}
@Override
public PolicyMonitoringManager getPolicyMonitoringManager() {
return null;
}
}

@ -19,8 +19,8 @@
package org.wso2.carbon.policy.evaluator;
import org.wso2.carbon.policy.mgt.common.Policy;
import org.wso2.carbon.policy.mgt.common.ProfileFeature;
import org.wso2.carbon.device.mgt.common.policy.mgt.Policy;
import org.wso2.carbon.device.mgt.common.policy.mgt.ProfileFeature;
import java.util.List;

@ -19,8 +19,8 @@
package org.wso2.carbon.policy.evaluator;
import org.wso2.carbon.policy.evaluator.utils.Constants;
import org.wso2.carbon.policy.mgt.common.Policy;
import org.wso2.carbon.policy.mgt.common.ProfileFeature;
import org.wso2.carbon.device.mgt.common.policy.mgt.Policy;
import org.wso2.carbon.device.mgt.common.policy.mgt.ProfileFeature;
import java.util.ArrayList;
import java.util.List;

@ -20,7 +20,7 @@ package org.wso2.carbon.policy.evaluator;
import org.wso2.carbon.policy.evaluator.spi.PDPService;
import org.wso2.carbon.policy.mgt.common.Feature;
import org.wso2.carbon.policy.mgt.common.Policy;
import org.wso2.carbon.device.mgt.common.policy.mgt.Policy;
import java.util.List;

@ -19,7 +19,7 @@
package org.wso2.carbon.policy.evaluator;
import org.wso2.carbon.policy.mgt.common.Policy;
import org.wso2.carbon.device.mgt.common.policy.mgt.Policy;
import java.util.List;

@ -18,7 +18,7 @@
package org.wso2.carbon.policy.evaluator;
import org.wso2.carbon.policy.mgt.common.Policy;
import org.wso2.carbon.device.mgt.common.policy.mgt.Policy;
import java.util.ArrayList;
import java.util.List;

@ -21,7 +21,7 @@ package org.wso2.carbon.policy.evaluator.spi;
import org.wso2.carbon.policy.evaluator.FeatureRules;
import org.wso2.carbon.policy.mgt.common.Feature;
import org.wso2.carbon.policy.mgt.common.Policy;
import org.wso2.carbon.device.mgt.common.policy.mgt.Policy;
import java.util.List;

@ -22,6 +22,9 @@ 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.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.policy.mgt.Policy;
import org.wso2.carbon.device.mgt.common.policy.mgt.Profile;
import org.wso2.carbon.device.mgt.common.policy.mgt.ProfileFeature;
import org.wso2.carbon.policy.mgt.common.*;
import org.wso2.carbon.policy.mgt.core.PolicyManagerService;
import org.wso2.carbon.policy.decision.point.internal.PolicyDecisionPointDataHolder;

@ -19,10 +19,10 @@
package org.wso2.carbon.policy.decision.point.simple;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.policy.mgt.common.Policy;
import org.wso2.carbon.device.mgt.common.policy.mgt.Policy;
import org.wso2.carbon.policy.mgt.common.PolicyEvaluationException;
import org.wso2.carbon.policy.mgt.common.PolicyEvaluationPoint;
import org.wso2.carbon.policy.mgt.common.ProfileFeature;
import org.wso2.carbon.device.mgt.common.policy.mgt.ProfileFeature;
import java.util.List;

@ -20,7 +20,7 @@
package org.wso2.carbon.policy.decision.point.simple;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.policy.mgt.common.Policy;
import org.wso2.carbon.device.mgt.common.policy.mgt.Policy;
import org.wso2.carbon.policy.mgt.common.PolicyEvaluationException;
public interface SimpleEvaluation {

@ -21,6 +21,7 @@ package org.wso2.carbon.policy.decision.point.simple;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.policy.mgt.Policy;
import org.wso2.carbon.policy.decision.point.internal.PolicyDecisionPointDataHolder;
import org.wso2.carbon.policy.mgt.common.*;
import org.wso2.carbon.policy.mgt.core.PolicyManagerService;

@ -21,7 +21,7 @@ package org.wso2.carbon.policy.information.point;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.Feature;
import org.wso2.carbon.policy.mgt.common.PIPDevice;
import org.wso2.carbon.policy.mgt.common.Policy;
import org.wso2.carbon.device.mgt.common.policy.mgt.Policy;
import org.wso2.carbon.policy.mgt.common.PolicyInformationPoint;
import java.util.List;

@ -17,8 +17,9 @@
*/
package org.wso2.carbon.policy.mgt.common;
import org.wso2.carbon.device.mgt.common.Feature;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.policy.mgt.Policy;
import org.wso2.carbon.device.mgt.common.policy.mgt.Profile;
import java.util.List;

@ -20,6 +20,8 @@
package org.wso2.carbon.policy.mgt.common;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.policy.mgt.Policy;
import org.wso2.carbon.device.mgt.common.policy.mgt.ProfileFeature;
import java.util.List;

@ -20,6 +20,7 @@
package org.wso2.carbon.policy.mgt.common;
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup;
import org.wso2.carbon.device.mgt.common.policy.mgt.Policy;
import java.util.List;
import java.util.Map;

@ -21,6 +21,7 @@ package org.wso2.carbon.policy.mgt.common;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.Feature;
import org.wso2.carbon.device.mgt.common.policy.mgt.Policy;
import java.util.List;

@ -22,7 +22,9 @@ package org.wso2.carbon.policy.mgt.common.monitor;
import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.policy.mgt.common.Policy;
import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.NonComplianceData;
import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.PolicyComplianceException;
import org.wso2.carbon.device.mgt.common.policy.mgt.Policy;
import java.util.List;
@ -38,7 +40,7 @@ public interface ComplianceDecisionPoint {
void setDeviceAsReachable(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException;
void reEnforcePolicy(DeviceIdentifier deviceIdentifier, ComplianceData complianceData) throws
void reEnforcePolicy(DeviceIdentifier deviceIdentifier, NonComplianceData complianceData) throws
PolicyComplianceException;
void markDeviceAsNoneCompliance(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException;
@ -49,7 +51,7 @@ public interface ComplianceDecisionPoint {
void activateDevice(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException;
void validateDevicePolicyCompliance(DeviceIdentifier deviceIdentifier, ComplianceData complianceData) throws
void validateDevicePolicyCompliance(DeviceIdentifier deviceIdentifier, NonComplianceData complianceData) throws
PolicyComplianceException;

@ -20,8 +20,8 @@ package org.wos2.carbon.policy.mgt.common.utils;
import org.wso2.carbon.device.mgt.common.Feature;
import org.wso2.carbon.policy.mgt.common.Policy;
import org.wso2.carbon.policy.mgt.common.Profile;
import org.wso2.carbon.device.mgt.common.policy.mgt.Policy;
import org.wso2.carbon.device.mgt.common.policy.mgt.Profile;
import java.util.ArrayList;
import java.util.List;

@ -21,10 +21,13 @@ package org.wso2.carbon.policy.mgt.core;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.Feature;
import org.wso2.carbon.device.mgt.common.policy.mgt.Policy;
import org.wso2.carbon.device.mgt.common.policy.mgt.Profile;
import org.wso2.carbon.device.mgt.common.policy.mgt.ProfileFeature;
import org.wso2.carbon.policy.mgt.common.*;
import org.wso2.carbon.policy.mgt.common.monitor.ComplianceData;
import org.wso2.carbon.policy.mgt.common.monitor.ComplianceFeature;
import org.wso2.carbon.policy.mgt.common.monitor.PolicyComplianceException;
import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.NonComplianceData;
import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.ComplianceFeature;
import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.PolicyComplianceException;
import org.wso2.carbon.policy.mgt.core.task.TaskScheduleService;
import java.util.List;
@ -75,7 +78,7 @@ public interface PolicyManagerService {
boolean checkCompliance(DeviceIdentifier deviceIdentifier, Object response) throws PolicyComplianceException;
ComplianceData getDeviceCompliance(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException;
NonComplianceData getDeviceCompliance(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException;
boolean isCompliant(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException;
}

@ -24,10 +24,13 @@ import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.Feature;
import org.wso2.carbon.device.mgt.common.InvalidDeviceException;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
import org.wso2.carbon.device.mgt.common.policy.mgt.Policy;
import org.wso2.carbon.device.mgt.common.policy.mgt.Profile;
import org.wso2.carbon.device.mgt.common.policy.mgt.ProfileFeature;
import org.wso2.carbon.policy.mgt.common.*;
import org.wso2.carbon.policy.mgt.common.monitor.ComplianceData;
import org.wso2.carbon.policy.mgt.common.monitor.ComplianceFeature;
import org.wso2.carbon.policy.mgt.common.monitor.PolicyComplianceException;
import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.NonComplianceData;
import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.ComplianceFeature;
import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.PolicyComplianceException;
import org.wso2.carbon.policy.mgt.core.impl.PolicyAdministratorPointImpl;
import org.wso2.carbon.policy.mgt.core.impl.PolicyInformationPointImpl;
import org.wso2.carbon.policy.mgt.core.internal.PolicyManagementDataHolder;
@ -210,7 +213,7 @@ public class PolicyManagerServiceImpl implements PolicyManagerService {
}
@Override
public ComplianceData getDeviceCompliance(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException {
public NonComplianceData getDeviceCompliance(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException {
return monitoringManager.getDevicePolicyCompliance(deviceIdentifier);
}

@ -19,7 +19,7 @@
package org.wso2.carbon.policy.mgt.core.cache;
import org.wso2.carbon.policy.mgt.common.Policy;
import org.wso2.carbon.device.mgt.common.policy.mgt.Policy;
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
import java.util.List;

@ -21,7 +21,7 @@ package org.wso2.carbon.policy.mgt.core.cache.impl;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.policy.mgt.common.Policy;
import org.wso2.carbon.device.mgt.common.policy.mgt.Policy;
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
import org.wso2.carbon.policy.mgt.core.cache.PolicyCacheManager;
import org.wso2.carbon.policy.mgt.core.mgt.PolicyManager;

@ -20,8 +20,8 @@
package org.wso2.carbon.policy.mgt.core.dao;
import org.wso2.carbon.device.mgt.common.Feature;
import org.wso2.carbon.policy.mgt.common.Profile;
import org.wso2.carbon.policy.mgt.common.ProfileFeature;
import org.wso2.carbon.device.mgt.common.policy.mgt.Profile;
import org.wso2.carbon.device.mgt.common.policy.mgt.ProfileFeature;
import java.util.List;

@ -19,11 +19,10 @@
package org.wso2.carbon.policy.mgt.core.dao;
import org.wso2.carbon.policy.mgt.common.monitor.ComplianceData;
import org.wso2.carbon.policy.mgt.common.monitor.ComplianceFeature;
import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.NonComplianceData;
import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.ComplianceFeature;
import org.wso2.carbon.policy.mgt.common.monitor.PolicyDeviceWrapper;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -50,11 +49,11 @@ public interface MonitoringDAO {
complianceFeatures)
throws MonitoringDAOException;
ComplianceData getCompliance(int deviceId, int enrolmentId) throws MonitoringDAOException;
NonComplianceData getCompliance(int deviceId, int enrolmentId) throws MonitoringDAOException;
List<ComplianceData> getCompliance(List<Integer> deviceIds) throws MonitoringDAOException;
List<NonComplianceData> getCompliance(List<Integer> deviceIds) throws MonitoringDAOException;
List<ComplianceData> getCompliance() throws MonitoringDAOException;
List<NonComplianceData> getCompliance() throws MonitoringDAOException;
List<ComplianceFeature> getNoneComplianceFeatures(int policyComplianceStatusId) throws MonitoringDAOException;

@ -20,9 +20,9 @@ package org.wso2.carbon.policy.mgt.core.dao;
import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.policy.mgt.common.Criterion;
import org.wso2.carbon.policy.mgt.common.DeviceGroupWrapper;
import org.wso2.carbon.policy.mgt.common.Policy;
import org.wso2.carbon.policy.mgt.common.PolicyCriterion;
import org.wso2.carbon.device.mgt.common.policy.mgt.DeviceGroupWrapper;
import org.wso2.carbon.device.mgt.common.policy.mgt.Policy;
import org.wso2.carbon.device.mgt.common.policy.mgt.PolicyCriterion;
import java.util.HashMap;
import java.util.List;

@ -19,8 +19,7 @@
package org.wso2.carbon.policy.mgt.core.dao;
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
import org.wso2.carbon.policy.mgt.common.Profile;
import org.wso2.carbon.device.mgt.common.policy.mgt.Profile;
import java.util.List;

@ -22,13 +22,12 @@ 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.device.mgt.common.policy.mgt.monitor.NonComplianceData;
import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.ComplianceFeature;
import org.wso2.carbon.policy.mgt.common.monitor.PolicyDeviceWrapper;
import org.wso2.carbon.policy.mgt.core.dao.MonitoringDAO;
import org.wso2.carbon.policy.mgt.core.dao.MonitoringDAOException;
import org.wso2.carbon.policy.mgt.core.dao.PolicyManagementDAOFactory;
import org.wso2.carbon.policy.mgt.core.dao.PolicyManagerDAOException;
import org.wso2.carbon.policy.mgt.core.dao.util.PolicyManagementDAOUtil;
import org.wso2.carbon.policy.mgt.core.util.PolicyManagerUtil;
@ -237,12 +236,12 @@ public class MonitoringDAOImpl implements MonitoringDAO {
}
@Override
public ComplianceData getCompliance(int deviceId, int enrolmentId) throws MonitoringDAOException {
public NonComplianceData getCompliance(int deviceId, int enrolmentId) throws MonitoringDAOException {
Connection conn;
PreparedStatement stmt = null;
ResultSet resultSet = null;
ComplianceData complianceData = new ComplianceData();
NonComplianceData complianceData = new NonComplianceData();
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
try {
@ -275,11 +274,11 @@ public class MonitoringDAOImpl implements MonitoringDAO {
}
@Override
public List<ComplianceData> getCompliance(List<Integer> deviceIds) throws MonitoringDAOException {
public List<NonComplianceData> getCompliance(List<Integer> deviceIds) throws MonitoringDAOException {
Connection conn;
PreparedStatement stmt = null;
ResultSet resultSet = null;
List<ComplianceData> complianceDataList = new ArrayList<>();
List<NonComplianceData> complianceDataList = new ArrayList<>();
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
try {
conn = this.getConnection();
@ -290,7 +289,7 @@ public class MonitoringDAOImpl implements MonitoringDAO {
resultSet = stmt.executeQuery();
while (resultSet.next()) {
ComplianceData complianceData = new ComplianceData();
NonComplianceData complianceData = new NonComplianceData();
complianceData.setId(resultSet.getInt("ID"));
complianceData.setDeviceId(resultSet.getInt("DEVICE_ID"));
complianceData.setEnrolmentId(resultSet.getInt("ENROLMENT_ID"));
@ -312,11 +311,11 @@ public class MonitoringDAOImpl implements MonitoringDAO {
}
@Override
public List<ComplianceData> getCompliance() throws MonitoringDAOException {
public List<NonComplianceData> getCompliance() throws MonitoringDAOException {
Connection conn;
PreparedStatement stmt = null;
ResultSet resultSet = null;
List<ComplianceData> complianceDataList = new ArrayList<>();
List<NonComplianceData> complianceDataList = new ArrayList<>();
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
try {
conn = this.getConnection();
@ -326,7 +325,7 @@ public class MonitoringDAOImpl implements MonitoringDAO {
resultSet = stmt.executeQuery();
while (resultSet.next()) {
ComplianceData complianceData = new ComplianceData();
NonComplianceData complianceData = new NonComplianceData();
complianceData.setId(resultSet.getInt("ID"));
complianceData.setDeviceId(resultSet.getInt("DEVICE_ID"));
complianceData.setEnrolmentId(resultSet.getInt("ENROLMENT_ID"));

@ -23,9 +23,9 @@ import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.policy.mgt.common.Criterion;
import org.wso2.carbon.policy.mgt.common.DeviceGroupWrapper;
import org.wso2.carbon.policy.mgt.common.Policy;
import org.wso2.carbon.policy.mgt.common.PolicyCriterion;
import org.wso2.carbon.device.mgt.common.policy.mgt.DeviceGroupWrapper;
import org.wso2.carbon.device.mgt.common.policy.mgt.Policy;
import org.wso2.carbon.device.mgt.common.policy.mgt.PolicyCriterion;
import org.wso2.carbon.policy.mgt.core.dao.PolicyDAO;
import org.wso2.carbon.policy.mgt.core.dao.PolicyManagementDAOFactory;
import org.wso2.carbon.policy.mgt.core.dao.PolicyManagerDAOException;

@ -21,10 +21,8 @@ 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.core.dto.DeviceType;
import org.wso2.carbon.policy.mgt.common.Profile;
import org.wso2.carbon.device.mgt.common.policy.mgt.Profile;
import org.wso2.carbon.policy.mgt.core.dao.PolicyManagementDAOFactory;
import org.wso2.carbon.policy.mgt.core.dao.PolicyManagerDAOException;
import org.wso2.carbon.policy.mgt.core.dao.ProfileDAO;
import org.wso2.carbon.policy.mgt.core.dao.ProfileManagerDAOException;
import org.wso2.carbon.policy.mgt.core.dao.util.PolicyManagementDAOUtil;

@ -22,8 +22,8 @@ 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;
import org.wso2.carbon.device.mgt.common.policy.mgt.Profile;
import org.wso2.carbon.device.mgt.common.policy.mgt.ProfileFeature;
import org.wso2.carbon.policy.mgt.core.dao.FeatureDAO;
import org.wso2.carbon.policy.mgt.core.dao.FeatureManagerDAOException;
import org.wso2.carbon.policy.mgt.core.dao.PolicyManagementDAOFactory;

@ -21,7 +21,7 @@ package org.wso2.carbon.policy.mgt.core.dao.impl.feature;
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.ProfileFeature;
import org.wso2.carbon.device.mgt.common.policy.mgt.ProfileFeature;
import org.wso2.carbon.policy.mgt.core.dao.FeatureManagerDAOException;
import org.wso2.carbon.policy.mgt.core.dao.PolicyManagementDAOFactory;
import org.wso2.carbon.policy.mgt.core.dao.util.PolicyManagementDAOUtil;

@ -21,7 +21,7 @@ package org.wso2.carbon.policy.mgt.core.dao.impl.feature;
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.ProfileFeature;
import org.wso2.carbon.device.mgt.common.policy.mgt.ProfileFeature;
import org.wso2.carbon.policy.mgt.core.dao.FeatureManagerDAOException;
import org.wso2.carbon.policy.mgt.core.dao.PolicyManagementDAOFactory;
import org.wso2.carbon.policy.mgt.core.dao.util.PolicyManagementDAOUtil;

@ -19,7 +19,7 @@
package org.wso2.carbon.policy.mgt.core.enforcement;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.policy.mgt.common.Policy;
import org.wso2.carbon.device.mgt.common.policy.mgt.Policy;
import java.util.List;

@ -25,11 +25,9 @@ import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.InvalidDeviceException;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager;
import org.wso2.carbon.device.mgt.core.operation.mgt.CommandOperation;
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManagerImpl;
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationMgtConstants;
import org.wso2.carbon.policy.mgt.common.Policy;
import org.wso2.carbon.device.mgt.common.policy.mgt.Policy;
import org.wso2.carbon.policy.mgt.common.PolicyAdministratorPoint;
import org.wso2.carbon.policy.mgt.common.PolicyEvaluationException;
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;

@ -27,12 +27,12 @@ import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementExcept
import org.wso2.carbon.device.mgt.core.operation.mgt.PolicyOperation;
import org.wso2.carbon.device.mgt.core.operation.mgt.ProfileOperation;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
import org.wso2.carbon.policy.mgt.common.Policy;
import org.wso2.carbon.policy.mgt.common.ProfileFeature;
import org.wso2.carbon.policy.mgt.common.monitor.ComplianceData;
import org.wso2.carbon.device.mgt.common.policy.mgt.Policy;
import org.wso2.carbon.device.mgt.common.policy.mgt.ProfileFeature;
import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.NonComplianceData;
import org.wso2.carbon.policy.mgt.common.monitor.ComplianceDecisionPoint;
import org.wso2.carbon.policy.mgt.common.monitor.ComplianceFeature;
import org.wso2.carbon.policy.mgt.common.monitor.PolicyComplianceException;
import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.ComplianceFeature;
import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.PolicyComplianceException;
import org.wso2.carbon.policy.mgt.core.internal.PolicyManagementDataHolder;
import org.wso2.carbon.policy.mgt.core.util.PolicyManagementConstants;
@ -120,7 +120,7 @@ public class ComplianceDecisionPointImpl implements ComplianceDecisionPoint {
}
@Override
public void reEnforcePolicy(DeviceIdentifier deviceIdentifier, ComplianceData complianceData) throws
public void reEnforcePolicy(DeviceIdentifier deviceIdentifier, NonComplianceData complianceData) throws
PolicyComplianceException {
try {
@ -261,7 +261,7 @@ public class ComplianceDecisionPointImpl implements ComplianceDecisionPoint {
}
@Override
public void validateDevicePolicyCompliance(DeviceIdentifier deviceIdentifier, ComplianceData complianceData) throws
public void validateDevicePolicyCompliance(DeviceIdentifier deviceIdentifier, NonComplianceData complianceData) throws
PolicyComplianceException {
Policy policy = complianceData.getPolicy();

@ -22,6 +22,8 @@ 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.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.policy.mgt.Policy;
import org.wso2.carbon.device.mgt.common.policy.mgt.Profile;
import org.wso2.carbon.ntask.common.TaskException;
import org.wso2.carbon.ntask.core.TaskInfo;
import org.wso2.carbon.ntask.core.TaskManager;

@ -22,8 +22,8 @@ package org.wso2.carbon.policy.mgt.core.impl;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup;
import org.wso2.carbon.policy.mgt.common.DeviceGroupWrapper;
import org.wso2.carbon.policy.mgt.common.Policy;
import org.wso2.carbon.device.mgt.common.policy.mgt.DeviceGroupWrapper;
import org.wso2.carbon.device.mgt.common.policy.mgt.Policy;
import org.wso2.carbon.policy.mgt.common.PolicyFilter;
import org.wso2.carbon.policy.mgt.core.util.PolicyManagementConstants;

@ -26,6 +26,7 @@ import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup;
import org.wso2.carbon.device.mgt.common.group.mgt.GroupManagementException;
import org.wso2.carbon.device.mgt.common.policy.mgt.Policy;
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
import org.wso2.carbon.device.mgt.common.Feature;
@ -40,7 +41,6 @@ import org.wso2.carbon.policy.mgt.core.mgt.impl.FeatureManagerImpl;
import org.wso2.carbon.policy.mgt.core.mgt.impl.PolicyManagerImpl;
import org.wso2.carbon.user.api.UserRealm;
import org.wso2.carbon.user.api.UserStoreException;
import org.wso2.carbon.user.api.UserStoreManager;
import java.util.ArrayList;
import java.util.HashMap;

@ -24,7 +24,6 @@ import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
import org.wso2.carbon.ntask.core.service.TaskService;
import org.wso2.carbon.policy.mgt.common.PolicyEvaluationPoint;
import org.wso2.carbon.policy.mgt.common.PolicyInformationPoint;
import org.wso2.carbon.policy.mgt.common.spi.PolicyMonitoringService;
import org.wso2.carbon.policy.mgt.core.mgt.MonitoringManager;
import org.wso2.carbon.policy.mgt.core.mgt.PolicyManager;
import org.wso2.carbon.user.core.service.RealmService;
@ -43,7 +42,6 @@ public class PolicyManagementDataHolder {
private DeviceManagementProviderService deviceManagementService;
private MonitoringManager monitoringManager;
private PolicyManager policyManager;
private Map<String, PolicyMonitoringService> policyMonitoringServiceMap = new HashMap<>();
private TaskService taskService;
private static PolicyManagementDataHolder thisInstance = new PolicyManagementDataHolder();
@ -122,18 +120,6 @@ public class PolicyManagementDataHolder {
this.deviceManagementService = deviceManagementService;
}
public PolicyMonitoringService getPolicyMonitoringService(String deviceType) {
return policyMonitoringServiceMap.get(deviceType);
}
public void setPolicyMonitoringService(String deviceType, PolicyMonitoringService policyMonitoringService) {
this.policyMonitoringServiceMap.put(deviceType, policyMonitoringService);
}
public void unsetPolicyMonitoringService(String deviceType) {
this.policyMonitoringServiceMap.remove(deviceType);
}
public TaskService getTaskService() {
return taskService;
}

@ -26,7 +26,6 @@ import org.wso2.carbon.device.mgt.core.config.policy.PolicyConfiguration;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
import org.wso2.carbon.ntask.core.service.TaskService;
import org.wso2.carbon.policy.mgt.common.PolicyEvaluationPoint;
import org.wso2.carbon.policy.mgt.common.spi.PolicyMonitoringService;
import org.wso2.carbon.policy.mgt.core.PolicyManagerService;
import org.wso2.carbon.policy.mgt.core.PolicyManagerServiceImpl;
import org.wso2.carbon.policy.mgt.core.config.PolicyConfigurationManager;
@ -58,12 +57,6 @@ import org.wso2.carbon.user.core.service.RealmService;
* policy="dynamic"
* bind="setDeviceManagementService"
* unbind="unsetDeviceManagementService"
* @scr.reference name="org.wso2.carbon.policy.mgt.common.policy.monitor"
* interface="org.wso2.carbon.policy.mgt.common.spi.PolicyMonitoringService"
* cardinality="0..n"
* policy="dynamic"
* bind="setPolicyMonitoringService"
* unbind="unsetPolicyMonitoringService"
* @scr.reference name="ntask.component"
* interface="org.wso2.carbon.ntask.core.service.TaskService"
* cardinality="1..1"
@ -183,24 +176,6 @@ public class PolicyManagementServiceComponent {
PolicyManagementDataHolder.getInstance().setDeviceManagementService(null);
}
protected void setPolicyMonitoringService(PolicyMonitoringService policyMonitoringService) {
if (log.isDebugEnabled()) {
log.debug("Setting Policy Monitoring Service for " + policyMonitoringService.getType());
}
// TODO: FIX THE device type by taking from properties
PolicyManagementDataHolder.getInstance().setPolicyMonitoringService(policyMonitoringService.getType(),
policyMonitoringService);
}
protected void unsetPolicyMonitoringService(PolicyMonitoringService policyMonitoringService) {
if (log.isDebugEnabled()) {
log.debug("Removing the Policy Monitoring Service for " + policyMonitoringService.getType());
}
// TODO: FIX THE device type by taking from properties
PolicyManagementDataHolder.getInstance().unsetPolicyMonitoringService(policyMonitoringService.getType());
}
protected void setTaskService(TaskService taskService) {
if (log.isDebugEnabled()) {
log.debug("Setting the task service.");

@ -22,8 +22,8 @@ package org.wso2.carbon.policy.mgt.core.mgt;
import org.wso2.carbon.device.mgt.common.Feature;
import org.wso2.carbon.policy.mgt.common.FeatureManagementException;
import org.wso2.carbon.policy.mgt.common.Profile;
import org.wso2.carbon.policy.mgt.common.ProfileFeature;
import org.wso2.carbon.device.mgt.common.policy.mgt.Profile;
import org.wso2.carbon.device.mgt.common.policy.mgt.ProfileFeature;
import java.util.List;

@ -21,9 +21,9 @@ package org.wso2.carbon.policy.mgt.core.mgt;
import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.policy.mgt.common.monitor.ComplianceData;
import org.wso2.carbon.policy.mgt.common.monitor.ComplianceFeature;
import org.wso2.carbon.policy.mgt.common.monitor.PolicyComplianceException;
import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.NonComplianceData;
import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.ComplianceFeature;
import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.PolicyComplianceException;
import java.util.List;
@ -35,7 +35,7 @@ public interface MonitoringManager {
boolean isCompliant(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException;
ComplianceData getDevicePolicyCompliance(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException;
NonComplianceData getDevicePolicyCompliance(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException;
void addMonitoringOperation(List<Device> devices) throws PolicyComplianceException;

@ -19,8 +19,7 @@ package org.wso2.carbon.policy.mgt.core.mgt;
import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
import org.wso2.carbon.policy.mgt.common.Policy;
import org.wso2.carbon.device.mgt.common.policy.mgt.Policy;
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
import java.util.HashMap;

@ -19,7 +19,7 @@
package org.wso2.carbon.policy.mgt.core.mgt;
import org.wso2.carbon.policy.mgt.common.Profile;
import org.wso2.carbon.device.mgt.common.policy.mgt.Profile;
import org.wso2.carbon.policy.mgt.common.ProfileManagementException;
import java.util.List;

@ -21,10 +21,9 @@ package org.wso2.carbon.policy.mgt.core.mgt.impl;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.common.Feature;
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
import org.wso2.carbon.policy.mgt.common.FeatureManagementException;
import org.wso2.carbon.policy.mgt.common.Profile;
import org.wso2.carbon.policy.mgt.common.ProfileFeature;
import org.wso2.carbon.device.mgt.common.policy.mgt.Profile;
import org.wso2.carbon.device.mgt.common.policy.mgt.ProfileFeature;
import org.wso2.carbon.policy.mgt.core.dao.FeatureDAO;
import org.wso2.carbon.policy.mgt.core.dao.FeatureManagerDAOException;
import org.wso2.carbon.policy.mgt.core.dao.PolicyManagementDAOFactory;

@ -26,15 +26,18 @@ import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.InvalidDeviceException;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
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 org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager;
import org.wso2.carbon.device.mgt.core.config.policy.PolicyConfiguration;
import org.wso2.carbon.device.mgt.core.operation.mgt.CommandOperation;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
import org.wso2.carbon.policy.mgt.common.Policy;
import org.wso2.carbon.device.mgt.common.policy.mgt.Policy;
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
import org.wso2.carbon.policy.mgt.common.ProfileFeature;
import org.wso2.carbon.device.mgt.common.policy.mgt.ProfileFeature;
import org.wso2.carbon.policy.mgt.common.monitor.*;
import org.wso2.carbon.policy.mgt.common.spi.PolicyMonitoringService;
import org.wso2.carbon.policy.mgt.core.dao.*;
import org.wso2.carbon.policy.mgt.core.impl.ComplianceDecisionPointImpl;
import org.wso2.carbon.policy.mgt.core.internal.PolicyManagementDataHolder;
@ -80,15 +83,15 @@ public class MonitoringManagerImpl implements MonitoringManager {
Device device = service.getDevice(deviceIdentifier);
Policy policy = manager.getAppliedPolicyToDevice(deviceIdentifier);
if (policy != null) {
PolicyMonitoringService monitoringService = PolicyManagementDataHolder.getInstance().
getPolicyMonitoringService(deviceIdentifier.getType());
PolicyMonitoringManager monitoringService = PolicyManagementDataHolder.getInstance().
getDeviceManagementService().getPolicyMonitoringManager(deviceIdentifier.getType());
ComplianceData complianceData;
NonComplianceData complianceData;
// This was retrieved from database because compliance id must be present for other dao operations to
// run.
try {
PolicyManagementDAOFactory.openConnection();
ComplianceData cmd = monitoringDAO.getCompliance(device.getId(), device.getEnrolmentInfo().getId());
NonComplianceData cmd = monitoringDAO.getCompliance(device.getId(), device.getEnrolmentInfo().getId());
complianceData = monitoringService.checkPolicyCompliance(deviceIdentifier,
policy, deviceResponse);
@ -177,7 +180,7 @@ public class MonitoringManagerImpl implements MonitoringManager {
PolicyManagementDataHolder.getInstance().getDeviceManagementService();
Device device = service.getDevice(deviceIdentifier);
PolicyManagementDAOFactory.openConnection();
ComplianceData complianceData = monitoringDAO.getCompliance(device.getId(), device.getEnrolmentInfo()
NonComplianceData complianceData = monitoringDAO.getCompliance(device.getId(), device.getEnrolmentInfo()
.getId());
if (complianceData == null || !complianceData.isStatus()) {
return false;
@ -198,9 +201,9 @@ public class MonitoringManagerImpl implements MonitoringManager {
}
@Override
public ComplianceData getDevicePolicyCompliance(DeviceIdentifier deviceIdentifier) throws
public NonComplianceData getDevicePolicyCompliance(DeviceIdentifier deviceIdentifier) throws
PolicyComplianceException {
ComplianceData complianceData;
NonComplianceData complianceData;
try {
PolicyManagementDAOFactory.openConnection();
DeviceManagementProviderService service =
@ -231,18 +234,18 @@ public class MonitoringManagerImpl implements MonitoringManager {
//int tenantId = PolicyManagerUtil.getTenantId();
Map<Integer, Device> deviceIds = new HashMap<>();
List<ComplianceData> complianceDatas = new ArrayList<>();
List<NonComplianceData> complianceDatas = new ArrayList<>();
HashMap<Integer, Integer> devicePolicyIdMap = new HashMap<>();
try {
PolicyManagementDAOFactory.openConnection();
//TODO: Return a map from getCompliance to reduce O(n^2) -> O(n)
List<ComplianceData> cd = monitoringDAO.getCompliance();
List<NonComplianceData> cd = monitoringDAO.getCompliance();
for (Device device : devices) {
deviceIds.put(device.getId(), device);
for (ComplianceData data : cd) {
for (NonComplianceData data : cd) {
if (device.getId() == data.getDeviceId() && device.getEnrolmentInfo().getId() == data
.getEnrolmentId()) {
complianceDatas.add(data);
@ -276,11 +279,11 @@ public class MonitoringManagerImpl implements MonitoringManager {
List<PolicyDeviceWrapper> firstTimeDevices = new ArrayList<>();
Map<Integer, ComplianceData> tempMap = new HashMap<>();
Map<Integer, NonComplianceData> tempMap = new HashMap<>();
try {
if (complianceDatas != null || !complianceDatas.isEmpty()) {
for (ComplianceData complianceData : complianceDatas) {
for (NonComplianceData complianceData : complianceDatas) {
tempMap.put(complianceData.getDeviceId(), complianceData);

@ -20,12 +20,16 @@ package org.wso2.carbon.policy.mgt.core.mgt.impl;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.CarbonContext;
import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup;
import org.wso2.carbon.device.mgt.common.group.mgt.GroupManagementException;
import org.wso2.carbon.device.mgt.common.policy.mgt.DeviceGroupWrapper;
import org.wso2.carbon.device.mgt.common.policy.mgt.Policy;
import org.wso2.carbon.device.mgt.common.policy.mgt.PolicyCriterion;
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.service.DeviceManagementProviderService;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderServiceImpl;
import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderService;

@ -20,14 +20,10 @@ package org.wso2.carbon.policy.mgt.core.mgt.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.core.dao.DeviceDAO;
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException;
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
import org.wso2.carbon.device.mgt.core.dao.DeviceTypeDAO;
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
import org.wso2.carbon.policy.mgt.common.Profile;
import org.wso2.carbon.policy.mgt.common.ProfileFeature;
import org.wso2.carbon.device.mgt.common.policy.mgt.Profile;
import org.wso2.carbon.device.mgt.common.policy.mgt.ProfileFeature;
import org.wso2.carbon.policy.mgt.common.ProfileManagementException;
import org.wso2.carbon.policy.mgt.core.dao.*;
import org.wso2.carbon.policy.mgt.core.mgt.ProfileManager;

@ -23,12 +23,12 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
import org.wso2.carbon.device.mgt.common.policy.mgt.PolicyMonitoringManager;
import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager;
import org.wso2.carbon.device.mgt.core.config.policy.PolicyConfiguration;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
import org.wso2.carbon.ntask.core.Task;
import org.wso2.carbon.policy.mgt.common.monitor.PolicyComplianceException;
import org.wso2.carbon.policy.mgt.common.spi.PolicyMonitoringService;
import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.PolicyComplianceException;
import org.wso2.carbon.policy.mgt.core.internal.PolicyManagementDataHolder;
import org.wso2.carbon.policy.mgt.core.mgt.MonitoringManager;
@ -80,8 +80,9 @@ public class MonitoringTask implements Task {
if (log.isDebugEnabled()) {
log.debug("Running task for device type : " + deviceType);
}
PolicyMonitoringService monitoringService =
PolicyManagementDataHolder.getInstance().getPolicyMonitoringService(deviceType);
PolicyMonitoringManager monitoringService =
PolicyManagementDataHolder.getInstance().getDeviceManagementService()
.getPolicyMonitoringManager(deviceType);
List<Device> devices = deviceManagementProviderService.getAllDevices(deviceType);
if (monitoringService != null && !devices.isEmpty()) {
List<Device> notifiableDevices = new ArrayList<>();
@ -110,7 +111,6 @@ public class MonitoringTask implements Task {
}
if (!notifiableDevices.isEmpty()) {
monitoringManager.addMonitoringOperation(notifiableDevices);
monitoringService.notifyDevices(notifiableDevices);
}
}
}

@ -22,7 +22,6 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.w3c.dom.Document;
import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationEntry;
import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationManagementException;
import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration;
@ -34,9 +33,9 @@ import org.wso2.carbon.device.mgt.core.config.policy.PolicyConfiguration;
import org.wso2.carbon.device.mgt.core.config.tenant.PlatformConfigurationManagementServiceImpl;
import org.wso2.carbon.device.mgt.core.operation.mgt.PolicyOperation;
import org.wso2.carbon.device.mgt.core.operation.mgt.ProfileOperation;
import org.wso2.carbon.policy.mgt.common.Policy;
import org.wso2.carbon.device.mgt.common.policy.mgt.Policy;
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
import org.wso2.carbon.policy.mgt.common.ProfileFeature;
import org.wso2.carbon.device.mgt.common.policy.mgt.ProfileFeature;
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;

@ -32,15 +32,15 @@ import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManagerImpl;
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.Policy;
import org.wso2.carbon.device.mgt.common.policy.mgt.Policy;
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
import org.wso2.carbon.policy.mgt.common.monitor.PolicyComplianceException;
import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.PolicyComplianceException;
import org.wso2.carbon.policy.mgt.core.internal.PolicyManagementDataHolder;
import org.wso2.carbon.policy.mgt.core.mgt.MonitoringManager;
import org.wso2.carbon.policy.mgt.core.mgt.PolicyManager;
import org.wso2.carbon.policy.mgt.core.mgt.impl.MonitoringManagerImpl;
import org.wso2.carbon.policy.mgt.core.mgt.impl.PolicyManagerImpl;
import org.wso2.carbon.policy.mgt.core.services.PolicyMonitoringServiceTest;
import org.wso2.carbon.policy.mgt.core.services.PolicyMonitoringManagerTest;
import java.util.List;
@ -154,9 +154,10 @@ public class MonitoringTestCase extends BasePolicyManagementDAOTest {
PolicyComplianceException {
PolicyMonitoringServiceTest monitoringServiceTest = new PolicyMonitoringServiceTest();
PolicyManagementDataHolder.getInstance().setPolicyMonitoringService(monitoringServiceTest.getType(),
monitoringServiceTest);
PolicyMonitoringManagerTest monitoringServiceTest = new PolicyMonitoringManagerTest();
TestDeviceManagementProviderService deviceManagementProviderService = new TestDeviceManagementProviderService();
deviceManagementProviderService.setPolicyMonitoringManager(monitoringServiceTest);
PolicyManagementDataHolder.getInstance().setDeviceManagementService(deviceManagementProviderService);
DeviceManagementProviderService adminService = new DeviceManagementProviderServiceImpl();
@ -170,8 +171,6 @@ public class MonitoringTestCase extends BasePolicyManagementDAOTest {
log.debug(device.getName());
}
monitoringServiceTest.notifyDevices(devices);
PolicyManager manager = new PolicyManagerImpl();
Policy policy = null;
@ -189,15 +188,15 @@ public class MonitoringTestCase extends BasePolicyManagementDAOTest {
public void checkCompliance() throws DeviceManagementException, PolicyComplianceException,
PolicyManagementException {
PolicyMonitoringServiceTest monitoringServiceTest = new PolicyMonitoringServiceTest();
PolicyManagementDataHolder.getInstance().setPolicyMonitoringService(monitoringServiceTest.getType(),
monitoringServiceTest);
DeviceManagementProviderService adminService = new DeviceManagementProviderServiceImpl();
PolicyMonitoringManagerTest monitoringServiceTest = new PolicyMonitoringManagerTest();
TestDeviceManagementProviderService deviceManagementProviderService = new TestDeviceManagementProviderService();
deviceManagementProviderService.setPolicyMonitoringManager(monitoringServiceTest);
PolicyManagementDataHolder.getInstance().setDeviceManagementService(deviceManagementProviderService);
DeviceManagementProviderService adminService = new DeviceManagementProviderServiceImpl();
List<Device> devices = adminService.getAllDevices();
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
deviceIdentifier.setId(devices.get(0).getDeviceIdentifier());
deviceIdentifier.setType(devices.get(0).getType());

@ -24,6 +24,10 @@ import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import org.wso2.carbon.device.mgt.common.*;
import org.wso2.carbon.device.mgt.common.Feature;
import org.wso2.carbon.device.mgt.common.policy.mgt.Policy;
import org.wso2.carbon.device.mgt.common.policy.mgt.PolicyCriterion;
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.*;
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;

@ -27,6 +27,7 @@ import org.testng.annotations.Test;
import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.policy.mgt.Policy;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderServiceImpl;
import org.wso2.carbon.ntask.common.TaskException;

@ -0,0 +1,36 @@
/*
* Copyright (c) 2016, 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;
import org.wso2.carbon.device.mgt.common.policy.mgt.PolicyMonitoringManager;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderServiceImpl;
import org.wso2.carbon.policy.mgt.core.services.PolicyMonitoringManagerTest;
public class TestDeviceManagementProviderService extends DeviceManagementProviderServiceImpl {
private PolicyMonitoringManager policyMonitoringManager;
@Override
public PolicyMonitoringManager getPolicyMonitoringManager(String deviceType) {
return policyMonitoringManager;
}
public void setPolicyMonitoringManager(PolicyMonitoringManager policyMonitoringManager) {
this.policyMonitoringManager = policyMonitoringManager;
}
}

@ -21,30 +21,24 @@ package org.wso2.carbon.policy.mgt.core.services;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.policy.mgt.common.Policy;
import org.wso2.carbon.policy.mgt.common.ProfileFeature;
import org.wso2.carbon.policy.mgt.common.monitor.ComplianceData;
import org.wso2.carbon.policy.mgt.common.monitor.ComplianceFeature;
import org.wso2.carbon.policy.mgt.common.monitor.PolicyComplianceException;
import org.wso2.carbon.policy.mgt.common.spi.PolicyMonitoringService;
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.NonComplianceData;
import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.ComplianceFeature;
import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.PolicyComplianceException;
import java.util.ArrayList;
import java.util.List;
public class PolicyMonitoringServiceTest implements PolicyMonitoringService {
public class PolicyMonitoringManagerTest implements PolicyMonitoringManager {
private static final Log log = LogFactory.getLog(PolicyMonitoringServiceTest.class);
private static final Log log = LogFactory.getLog(PolicyMonitoringManagerTest.class);
@Override
public void notifyDevices(List<Device> devices) throws PolicyComplianceException {
log.debug("Device notifying is called by the task.");
}
@Override
public ComplianceData checkPolicyCompliance(DeviceIdentifier deviceIdentifier, Policy policy, Object response)
public NonComplianceData checkPolicyCompliance(DeviceIdentifier deviceIdentifier, Policy policy, Object response)
throws PolicyComplianceException {
log.debug("Check compliance is called.");
@ -55,7 +49,7 @@ public class PolicyMonitoringServiceTest implements PolicyMonitoringService {
log.debug(deviceIdentifier.getId());
log.debug(deviceIdentifier.getType());
ComplianceData data = new ComplianceData();
NonComplianceData data = new NonComplianceData();
List<ComplianceFeature> complianceFeatures = new ArrayList<>();
@ -76,9 +70,4 @@ public class PolicyMonitoringServiceTest implements PolicyMonitoringService {
return data;
}
@Override
public String getType() {
return "android";
}
}

@ -22,6 +22,8 @@ package org.wso2.carbon.policy.mgt.core.services;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.policy.mgt.Policy;
import org.wso2.carbon.device.mgt.common.policy.mgt.ProfileFeature;
import org.wso2.carbon.policy.mgt.common.*;
import org.wso2.carbon.policy.mgt.core.PolicyManagerService;
import org.wso2.carbon.policy.mgt.core.PolicyManagerServiceImpl;

@ -18,9 +18,9 @@
package org.wso2.carbon.policy.mgt.core.util;
import org.wso2.carbon.policy.mgt.common.Policy;
import org.wso2.carbon.policy.mgt.common.PolicyCriterion;
import org.wso2.carbon.policy.mgt.common.Profile;
import org.wso2.carbon.device.mgt.common.policy.mgt.Policy;
import org.wso2.carbon.device.mgt.common.policy.mgt.PolicyCriterion;
import org.wso2.carbon.device.mgt.common.policy.mgt.Profile;
import java.util.ArrayList;
import java.util.List;

@ -18,9 +18,8 @@
package org.wso2.carbon.policy.mgt.core.util;
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
import org.wso2.carbon.device.mgt.common.Feature;
import org.wso2.carbon.policy.mgt.common.Profile;
import org.wso2.carbon.device.mgt.common.policy.mgt.Profile;
import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
import java.util.List;

@ -19,7 +19,7 @@
package org.wso2.carbon.policy.mgt.core.util;
import org.wso2.carbon.device.mgt.common.Feature;
import org.wso2.carbon.policy.mgt.common.ProfileFeature;
import org.wso2.carbon.device.mgt.common.policy.mgt.ProfileFeature;
import java.util.ArrayList;
import java.util.List;

@ -332,6 +332,11 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.application.deployer</artifactId>
<version>${carbon.kernel.version}</version>
</dependency>
<dependency>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.registry.core</artifactId>

Loading…
Cancel
Save