refactored windowsdevicemanager

revert-dabc3590
hasuniea 9 years ago
commit 6669d25f80

@ -76,7 +76,8 @@
org.wso2.carbon.registry.core.service, org.wso2.carbon.registry.core.service,
org.wso2.carbon.registry.core.session, org.wso2.carbon.registry.core.session,
org.wso2.carbon.registry.api, org.wso2.carbon.registry.api,
org.wso2.carbon.device.mgt.extensions.license.mgt.registry org.wso2.carbon.device.mgt.extensions.license.mgt.registry,
com.google.gson.*
</Import-Package> </Import-Package>
<Export-Package> <Export-Package>
!org.wso2.carbon.device.mgt.mobile.internal, !org.wso2.carbon.device.mgt.mobile.internal,
@ -165,5 +166,9 @@
<artifactId>h2-database-engine</artifactId> <artifactId>h2-database-engine</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
</dependencies> </dependencies>
</project> </project>

@ -75,8 +75,7 @@ public class AndroidDeviceManager implements DeviceManager {
@Override @Override
public boolean saveConfiguration(TenantConfiguration tenantConfiguration) public boolean saveConfiguration(TenantConfiguration tenantConfiguration)
throws DeviceManagementException { throws DeviceManagementException {
boolean status = false; boolean status;
Resource resource;
try { try {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Persisting android configurations in Registry"); log.debug("Persisting android configurations in Registry");
@ -89,7 +88,7 @@ public class AndroidDeviceManager implements DeviceManager {
Marshaller marshaller = context.createMarshaller(); Marshaller marshaller = context.createMarshaller();
marshaller.marshal(tenantConfiguration, writer); marshaller.marshal(tenantConfiguration, writer);
resource = MobileDeviceManagementUtil.getRegistry().newResource(); Resource resource = MobileDeviceManagementUtil.getConfigurationRegistry().newResource();
resource.setContent(writer.toString()); resource.setContent(writer.toString());
resource.setMediaType(MobilePluginConstants.MEDIA_TYPE_XML); resource.setMediaType(MobilePluginConstants.MEDIA_TYPE_XML);
MobileDeviceManagementUtil.putRegistryResource(resourcePath, resource); MobileDeviceManagementUtil.putRegistryResource(resourcePath, resource);
@ -115,12 +114,14 @@ public class AndroidDeviceManager implements DeviceManager {
MobileDeviceManagementUtil.getPlatformConfigPath(DeviceManagementConstants. MobileDeviceManagementUtil.getPlatformConfigPath(DeviceManagementConstants.
MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
resource = MobileDeviceManagementUtil.getRegistryResource(androidRegPath); resource = MobileDeviceManagementUtil.getRegistryResource(androidRegPath);
if(resource != null){
JAXBContext context = JAXBContext.newInstance(TenantConfiguration.class); JAXBContext context = JAXBContext.newInstance(TenantConfiguration.class);
Unmarshaller unmarshaller = context.createUnmarshaller(); Unmarshaller unmarshaller = context.createUnmarshaller();
return (TenantConfiguration) unmarshaller.unmarshal( return (TenantConfiguration) unmarshaller.unmarshal(
new StringReader(new String((byte[]) resource.getContent(), Charset new StringReader(new String((byte[]) resource.getContent(), Charset
.forName(MobilePluginConstants.CHARSET_UTF8)))); .forName(MobilePluginConstants.CHARSET_UTF8))));
}
return new TenantConfiguration();
} catch (MobileDeviceMgtPluginException e) { } catch (MobileDeviceMgtPluginException e) {
throw new DeviceManagementException( throw new DeviceManagementException(
"Error occurred while retrieving the Registry instance : " + e.getMessage(), e); "Error occurred while retrieving the Registry instance : " + e.getMessage(), e);

@ -19,6 +19,10 @@
package org.wso2.carbon.device.mgt.mobile.impl.android; package org.wso2.carbon.device.mgt.mobile.impl.android;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.Device;
@ -43,15 +47,28 @@ public class AndroidPolicyMonitoringService implements PolicyMonitoringService {
} }
@Override @Override
public ComplianceData checkPolicyCompliance(DeviceIdentifier deviceIdentifier, Policy policy, Object o) throws PolicyComplianceException { public ComplianceData checkPolicyCompliance(DeviceIdentifier deviceIdentifier, Policy policy,
ComplianceData complianceData = new ComplianceData(); Object compliancePayload) throws PolicyComplianceException {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Checking policy compliance status of device '" + deviceIdentifier.getId() + "'"); log.debug("Checking policy compliance status of device '" + deviceIdentifier.getId() + "'");
} }
if (o == null || policy == null) { ComplianceData complianceData = new ComplianceData();
return null; if (compliancePayload == null || policy == null) {
return complianceData;
} }
List<ComplianceFeature> complianceFeatures = (List<ComplianceFeature>) o; List<ComplianceFeature> complianceFeatures = new ArrayList<ComplianceFeature>();
// Parsing json string to get compliance features.
JsonElement jsonElement = new JsonParser().parse((String) compliancePayload);
JsonArray jsonArray = jsonElement.getAsJsonArray();
Gson gson = new Gson();
ComplianceFeature complianceFeature;
for (int i = 0; i < jsonArray.size(); i++) {
complianceFeature = gson.fromJson(jsonArray.get(i), ComplianceFeature.class);
complianceFeatures.add(complianceFeature);
}
complianceData.setComplianceFeatures(complianceFeatures); complianceData.setComplianceFeatures(complianceFeatures);
for (ComplianceFeature cf : complianceFeatures) { for (ComplianceFeature cf : complianceFeatures) {

@ -79,7 +79,7 @@ public class WindowsDeviceManager implements DeviceManager {
Marshaller marshaller = context.createMarshaller(); Marshaller marshaller = context.createMarshaller();
marshaller.marshal(tenantConfiguration, writer); marshaller.marshal(tenantConfiguration, writer);
resource = MobileDeviceManagementUtil.getRegistry().newResource(); resource = MobileDeviceManagementUtil.getConfigurationRegistry().newResource();
resource.setContent(writer.toString()); resource.setContent(writer.toString());
resource.setMediaType(MobilePluginConstants.MEDIA_TYPE_XML); resource.setMediaType(MobilePluginConstants.MEDIA_TYPE_XML);
MobileDeviceManagementUtil.putRegistryResource(resourcePath, resource); MobileDeviceManagementUtil.putRegistryResource(resourcePath, resource);

@ -198,7 +198,7 @@ public class MobileDeviceManagementUtil {
return feature; return feature;
} }
public static Registry getRegistry() throws MobileDeviceMgtPluginException { public static Registry getConfigurationRegistry() throws MobileDeviceMgtPluginException {
try { try {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
return MobileDeviceManagementDataHolder.getInstance().getRegistryService() return MobileDeviceManagementDataHolder.getInstance().getRegistryService()
@ -213,8 +213,10 @@ public class MobileDeviceManagementUtil {
public static Resource getRegistryResource(String path) throws MobileDeviceMgtPluginException { public static Resource getRegistryResource(String path) throws MobileDeviceMgtPluginException {
try { try {
return MobileDeviceManagementUtil.getRegistry().get(path); if(MobileDeviceManagementUtil.getConfigurationRegistry().resourceExists(path)){
return MobileDeviceManagementUtil.getConfigurationRegistry().get(path);
}
return null;
} catch (RegistryException e) { } catch (RegistryException e) {
throw new MobileDeviceMgtPluginException("Error in retrieving registry resource : " + throw new MobileDeviceMgtPluginException("Error in retrieving registry resource : " +
e.getMessage(), e); e.getMessage(), e);
@ -224,11 +226,11 @@ public class MobileDeviceManagementUtil {
public static boolean putRegistryResource(String path, public static boolean putRegistryResource(String path,
Resource resource) Resource resource)
throws MobileDeviceMgtPluginException { throws MobileDeviceMgtPluginException {
boolean status = false; boolean status;
try { try {
MobileDeviceManagementUtil.getRegistry().beginTransaction(); MobileDeviceManagementUtil.getConfigurationRegistry().beginTransaction();
MobileDeviceManagementUtil.getRegistry().put(path, resource); MobileDeviceManagementUtil.getConfigurationRegistry().put(path, resource);
MobileDeviceManagementUtil.getRegistry().commitTransaction(); MobileDeviceManagementUtil.getConfigurationRegistry().commitTransaction();
status = true; status = true;
} catch (RegistryException e) { } catch (RegistryException e) {
throw new MobileDeviceMgtPluginException( throw new MobileDeviceMgtPluginException(
@ -279,11 +281,11 @@ public class MobileDeviceManagementUtil {
public static boolean createRegistryCollection(String path) public static boolean createRegistryCollection(String path)
throws MobileDeviceMgtPluginException { throws MobileDeviceMgtPluginException {
try { try {
if (! MobileDeviceManagementUtil.getRegistry().resourceExists(path)) { if (! MobileDeviceManagementUtil.getConfigurationRegistry().resourceExists(path)) {
Resource resource = MobileDeviceManagementUtil.getRegistry().newCollection(); Resource resource = MobileDeviceManagementUtil.getConfigurationRegistry().newCollection();
MobileDeviceManagementUtil.getRegistry().beginTransaction(); MobileDeviceManagementUtil.getConfigurationRegistry().beginTransaction();
MobileDeviceManagementUtil.getRegistry().put(path, resource); MobileDeviceManagementUtil.getConfigurationRegistry().put(path, resource);
MobileDeviceManagementUtil.getRegistry().commitTransaction(); MobileDeviceManagementUtil.getConfigurationRegistry().commitTransaction();
} }
return true; return true;
} catch (MobileDeviceMgtPluginException e) { } catch (MobileDeviceMgtPluginException e) {

@ -58,6 +58,10 @@
<artifactId>org.wso2.carbon.device.mgt.extensions.feature</artifactId> <artifactId>org.wso2.carbon.device.mgt.extensions.feature</artifactId>
<type>zip</type> <type>zip</type>
</dependency> </dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
</dependencies> </dependencies>
<build> <build>

@ -511,6 +511,11 @@
<artifactId>axis2</artifactId> <artifactId>axis2</artifactId>
<version>${axis2.orbit.version}</version> <version>${axis2.orbit.version}</version>
</dependency> </dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>${google.gson.version}</version>
</dependency>
</dependencies> </dependencies>
</dependencyManagement> </dependencyManagement>
@ -577,6 +582,7 @@
<bouncycastle.version>1.49</bouncycastle.version> <bouncycastle.version>1.49</bouncycastle.version>
<apache.wss4j.version>2.0.0</apache.wss4j.version> <apache.wss4j.version>2.0.0</apache.wss4j.version>
<codehaus.plexus.version>3.0.21</codehaus.plexus.version> <codehaus.plexus.version>3.0.21</codehaus.plexus.version>
<google.gson.version>2.2.4</google.gson.version>
</properties> </properties>

Loading…
Cancel
Save