mirror of
https://repository.entgra.net/community/device-mgt-plugins.git
synced 2025-09-16 23:42:15 +00:00
Merge branch 'master' of https://github.com/wso2/carbon-device-mgt-plugins
This commit is contained in:
commit
d7527e95f0
@ -67,7 +67,8 @@
|
||||
org.wso2.carbon.core,
|
||||
org.wso2.carbon.core.util,
|
||||
org.wso2.carbon.event.output.adapter.core,
|
||||
org.wso2.carbon.event.output.adapter.core.exception
|
||||
org.wso2.carbon.event.output.adapter.core.exception,
|
||||
org.wso2.carbon.ndatasource.core
|
||||
</Import-Package>
|
||||
<Export-Package>
|
||||
!org.wso2.carbon.device.mgt.iot.androidsense.plugin.internal,
|
||||
|
||||
@ -25,7 +25,7 @@ import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceManager;
|
||||
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
|
||||
import org.wso2.carbon.device.mgt.common.FeatureManager;
|
||||
import org.wso2.carbon.device.mgt.common.configuration.mgt.TenantConfiguration;
|
||||
import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration;
|
||||
import org.wso2.carbon.device.mgt.common.license.mgt.License;
|
||||
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException;
|
||||
import org.wso2.carbon.device.mgt.iot.androidsense.plugin.exception.AndroidSenseDeviceMgtPluginException;
|
||||
@ -49,14 +49,14 @@ public class AndroidSenseManager implements DeviceManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean saveConfiguration(TenantConfiguration tenantConfiguration)
|
||||
public boolean saveConfiguration(PlatformConfiguration PlatformConfiguration)
|
||||
throws DeviceManagementException {
|
||||
//TODO implement this
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TenantConfiguration getConfiguration() throws DeviceManagementException {
|
||||
public PlatformConfiguration getConfiguration() throws DeviceManagementException {
|
||||
//TODO implement this
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -43,7 +43,7 @@ public class AndroidSenseDAOUtil {
|
||||
Context ctx = new InitialContext();
|
||||
dataSource = (DataSource) ctx.lookup(AndroidSenseConstants.DATA_SOURCE_NAME);
|
||||
} catch (NamingException e) {
|
||||
log.error("Error while looking up the data source: " + AndroidSenseConstants.DATA_SOURCE_NAME);
|
||||
log.error("Error while looking up the data source: " + AndroidSenseConstants.DATA_SOURCE_NAME, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -85,13 +85,12 @@ public class AndroidSenseUtils {
|
||||
try {
|
||||
Context ctx = new InitialContext();
|
||||
DataSource dataSource = (DataSource) ctx.lookup(AndroidSenseConstants.DATA_SOURCE_NAME);
|
||||
DeviceSchemaInitializer initializer =
|
||||
new DeviceSchemaInitializer(dataSource);
|
||||
DeviceSchemaInitializer initializer = new DeviceSchemaInitializer(dataSource);
|
||||
log.info("Initializing device management repository database schema");
|
||||
initializer.createRegistryDatabase();
|
||||
|
||||
} catch (NamingException e) {
|
||||
log.error("Error while looking up the data source: " + AndroidSenseConstants.DATA_SOURCE_NAME);
|
||||
log.error("Error while looking up the data source: " + AndroidSenseConstants.DATA_SOURCE_NAME, e);
|
||||
} catch (Exception e) {
|
||||
throw new AndroidSenseDeviceMgtPluginException("Error occurred while initializing Iot Device " +
|
||||
"Management database schema", e);
|
||||
|
||||
@ -20,6 +20,7 @@ package org.wso2.carbon.device.mgt.iot.androidsense.plugin.impl.util;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.device.mgt.iot.androidsense.plugin.constants.AndroidSenseConstants;
|
||||
import org.wso2.carbon.utils.CarbonUtils;
|
||||
import org.wso2.carbon.utils.dbcreator.DatabaseCreator;
|
||||
|
||||
@ -33,7 +34,8 @@ public class DeviceSchemaInitializer extends DatabaseCreator{
|
||||
|
||||
private static final Log log = LogFactory.getLog(DeviceSchemaInitializer.class);
|
||||
private static final String setupSQLScriptBaseLocation = CarbonUtils.getCarbonHome() + File.separator + "dbscripts"
|
||||
+ File.separator + "cdm" + File.separator + "plugins" + File.separator;
|
||||
+ File.separator + "cdm" + File.separator + "plugins" + File.separator + AndroidSenseConstants.DEVICE_TYPE
|
||||
+ File.separator;
|
||||
|
||||
public DeviceSchemaInitializer(DataSource dataSource) {
|
||||
super(dataSource);
|
||||
|
||||
@ -28,6 +28,7 @@ import org.wso2.carbon.device.mgt.iot.androidsense.plugin.impl.AndroidSenseManag
|
||||
import org.wso2.carbon.device.mgt.iot.androidsense.plugin.impl.util.AndroidSenseStartupListener;
|
||||
import org.wso2.carbon.device.mgt.iot.androidsense.plugin.impl.util.AndroidSenseUtils;
|
||||
import org.wso2.carbon.event.output.adapter.core.OutputEventAdapterService;
|
||||
import org.wso2.carbon.ndatasource.core.DataSourceService;
|
||||
|
||||
/**
|
||||
* @scr.component name="org.wso2.carbon.device.mgt.iot.android.internal.AndroidSenseManagementServiceComponent"
|
||||
@ -38,6 +39,12 @@ import org.wso2.carbon.event.output.adapter.core.OutputEventAdapterService;
|
||||
* policy="dynamic"
|
||||
* bind="setOutputEventAdapterService"
|
||||
* unbind="unsetOutputEventAdapterService"
|
||||
* @scr.reference name="org.wso2.carbon.ndatasource"
|
||||
* interface="org.wso2.carbon.ndatasource.core.DataSourceService"
|
||||
* cardinality="1..1"
|
||||
* policy="dynamic"
|
||||
* bind="setDataSourceService"
|
||||
* unbind="unsetDataSourceService"
|
||||
*/
|
||||
public class AndroidSenseManagementServiceComponent {
|
||||
|
||||
@ -57,8 +64,7 @@ public class AndroidSenseManagementServiceComponent {
|
||||
String setupOption = System.getProperty("setup");
|
||||
if (setupOption != null) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug(
|
||||
"-Dsetup is enabled. Iot Device management repository schema initialization is about " +
|
||||
log.debug("-Dsetup is enabled. Iot Device management repository schema initialization is about " +
|
||||
"to begin");
|
||||
}
|
||||
try {
|
||||
@ -108,4 +114,16 @@ public class AndroidSenseManagementServiceComponent {
|
||||
protected void unsetOutputEventAdapterService(OutputEventAdapterService outputEventAdapterService) {
|
||||
AndroidSenseManagementDataHolder.getInstance().setOutputEventAdapterService(null);
|
||||
}
|
||||
|
||||
protected void setDataSourceService(DataSourceService dataSourceService) {
|
||||
/* This is to avoid mobile device management component getting initialized before the underlying datasources
|
||||
are registered */
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Data source service set to service component");
|
||||
}
|
||||
}
|
||||
|
||||
protected void unsetDataSourceService(DataSourceService dataSourceService) {
|
||||
//do nothing
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* Licensed 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.
|
||||
*/
|
||||
.circle {
|
||||
background: none repeat scroll 0 0 #191919;
|
||||
border-radius: 50px;
|
||||
height: 50px;
|
||||
padding: 10px;
|
||||
width: 50px;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.padding-top-double {
|
||||
padding-top: 20px;
|
||||
}
|
||||
|
||||
.padding-double {
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.grey {
|
||||
color: #333;
|
||||
}
|
||||
|
||||
hr {
|
||||
display: block;
|
||||
height: 1px;
|
||||
border: 0;
|
||||
border-top: 1px solid #7f7f7f;
|
||||
margin: 1em 0;
|
||||
padding: 0;
|
||||
opacity: 0.2;
|
||||
}
|
||||
|
||||
.light-grey {
|
||||
color: #7c7c7c;
|
||||
}
|
||||
|
||||
.uppercase {
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.grey-bg {
|
||||
background-color: #f6f4f4;
|
||||
}
|
||||
|
||||
.doc-link {
|
||||
background: #11375B;
|
||||
padding: 20px;
|
||||
color: white;
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
.doc-link a {
|
||||
color: white;
|
||||
}
|
||||
@ -272,61 +272,9 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style type="text/css">
|
||||
.circle {
|
||||
background: none repeat scroll 0 0 #191919;
|
||||
border-radius: 50px;
|
||||
height: 50px;
|
||||
padding: 10px;
|
||||
width: 50px;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.padding-top-double {
|
||||
padding-top: 20px;
|
||||
}
|
||||
|
||||
.padding-double {
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.grey {
|
||||
color: #333;
|
||||
}
|
||||
|
||||
hr {
|
||||
display: block;
|
||||
height: 1px;
|
||||
border: 0;
|
||||
border-top: 1px solid #7f7f7f;
|
||||
margin: 1em 0;
|
||||
padding: 0;
|
||||
opacity: 0.2;
|
||||
}
|
||||
|
||||
.light-grey {
|
||||
color: #7c7c7c;
|
||||
}
|
||||
|
||||
.uppercase {
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.grey-bg {
|
||||
background-color: #f6f4f4;
|
||||
}
|
||||
|
||||
.doc-link {
|
||||
background: #11375B;
|
||||
padding: 20px;
|
||||
color: white;
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
.doc-link a {
|
||||
color: white;
|
||||
}
|
||||
</style>
|
||||
{{#zone "topCss"}}
|
||||
{{css "css/styles.css"}}
|
||||
{{/zone}}
|
||||
|
||||
{{#zone "bottomJs"}}
|
||||
{{js "/js/download.js"}}
|
||||
@ -342,4 +290,4 @@
|
||||
}
|
||||
</script>
|
||||
{{js "/js/jquery.validate.js"}}
|
||||
{{/zone}}
|
||||
{{/zone}}
|
||||
@ -69,7 +69,8 @@
|
||||
org.wso2.carbon.device.mgt.common,
|
||||
org.wso2.carbon.device.mgt.iot.*,
|
||||
org.wso2.carbon.device.mgt.extensions.feature.mgt.*,
|
||||
org.wso2.carbon.utils.*
|
||||
org.wso2.carbon.utils.*,
|
||||
org.wso2.carbon.ndatasource.core
|
||||
</Import-Package>
|
||||
|
||||
<Export-Package>
|
||||
|
||||
@ -27,7 +27,7 @@ import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceManager;
|
||||
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
|
||||
import org.wso2.carbon.device.mgt.common.FeatureManager;
|
||||
import org.wso2.carbon.device.mgt.common.configuration.mgt.TenantConfiguration;
|
||||
import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration;
|
||||
import org.wso2.carbon.device.mgt.common.license.mgt.License;
|
||||
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException;
|
||||
import org.wso2.carbon.device.mgt.iot.arduino.plugin.exception.ArduinoDeviceMgtPluginException;
|
||||
@ -51,14 +51,14 @@ public class ArduinoManager implements DeviceManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean saveConfiguration(TenantConfiguration tenantConfiguration)
|
||||
public boolean saveConfiguration(PlatformConfiguration PlatformConfiguration)
|
||||
throws DeviceManagementException {
|
||||
//TODO implement this
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TenantConfiguration getConfiguration() throws DeviceManagementException {
|
||||
public PlatformConfiguration getConfiguration() throws DeviceManagementException {
|
||||
//TODO implement this
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -45,7 +45,7 @@ public class ArduinoDAOUtil {
|
||||
Context ctx = new InitialContext();
|
||||
dataSource = (DataSource) ctx.lookup(ArduinoConstants.DATA_SOURCE_NAME);
|
||||
} catch (NamingException e) {
|
||||
log.error("Error while looking up the data source: " + ArduinoConstants.DATA_SOURCE_NAME);
|
||||
log.error("Error while looking up the data source: " + ArduinoConstants.DATA_SOURCE_NAME, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -97,13 +97,12 @@ public class ArduinoUtils {
|
||||
try {
|
||||
Context ctx = new InitialContext();
|
||||
DataSource dataSource = (DataSource) ctx.lookup(ArduinoConstants.DATA_SOURCE_NAME);
|
||||
DeviceSchemaInitializer initializer =
|
||||
new DeviceSchemaInitializer(dataSource);
|
||||
DeviceSchemaInitializer initializer = new DeviceSchemaInitializer(dataSource);
|
||||
log.info("Initializing device management repository database schema");
|
||||
initializer.createRegistryDatabase();
|
||||
|
||||
} catch (NamingException e) {
|
||||
log.error("Error while looking up the data source: " + ArduinoConstants.DATA_SOURCE_NAME);
|
||||
log.error("Error while looking up the data source: " + ArduinoConstants.DATA_SOURCE_NAME, e);
|
||||
} catch (Exception e) {
|
||||
throw new ArduinoDeviceMgtPluginException("Error occurred while initializing Iot Device " +
|
||||
"Management database schema", e);
|
||||
|
||||
@ -20,6 +20,7 @@ package org.wso2.carbon.device.mgt.iot.arduino.plugin.impl.util;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.device.mgt.iot.arduino.plugin.constants.ArduinoConstants;
|
||||
import org.wso2.carbon.utils.CarbonUtils;
|
||||
import org.wso2.carbon.utils.dbcreator.DatabaseCreator;
|
||||
|
||||
@ -33,7 +34,8 @@ public class DeviceSchemaInitializer extends DatabaseCreator{
|
||||
|
||||
private static final Log log = LogFactory.getLog(DeviceSchemaInitializer.class);
|
||||
private static final String setupSQLScriptBaseLocation = CarbonUtils.getCarbonHome() + File.separator + "dbscripts"
|
||||
+ File.separator + "cdm" + File.separator + "plugins" + File.separator;
|
||||
+ File.separator + "cdm" + File.separator + "plugins" + File.separator + ArduinoConstants.DEVICE_TYPE
|
||||
+ File.separator;
|
||||
|
||||
public DeviceSchemaInitializer(DataSource dataSource) {
|
||||
super(dataSource);
|
||||
|
||||
@ -27,9 +27,17 @@ import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
|
||||
import org.wso2.carbon.device.mgt.iot.arduino.plugin.exception.ArduinoDeviceMgtPluginException;
|
||||
import org.wso2.carbon.device.mgt.iot.arduino.plugin.impl.ArduinoManagerService;
|
||||
import org.wso2.carbon.device.mgt.iot.arduino.plugin.impl.util.ArduinoUtils;
|
||||
import org.wso2.carbon.ndatasource.core.DataSourceService;
|
||||
|
||||
/**
|
||||
* @scr.component name="org.wso2.carbon.device.mgt.iot.arduino.internal.ArduinoManagementServiceComponent"
|
||||
* immediate="true"
|
||||
* @scr.reference name="org.wso2.carbon.ndatasource"
|
||||
* interface="org.wso2.carbon.ndatasource.core.DataSourceService"
|
||||
* cardinality="1..1"
|
||||
* policy="dynamic"
|
||||
* bind="setDataSourceService"
|
||||
* unbind="unsetDataSourceService"
|
||||
*/
|
||||
public class ArduinoManagementServiceComponent {
|
||||
|
||||
@ -83,4 +91,16 @@ public class ArduinoManagementServiceComponent {
|
||||
log.error("Error occurred while de-activating Arduino Device Management bundle", e);
|
||||
}
|
||||
}
|
||||
|
||||
protected void setDataSourceService(DataSourceService dataSourceService) {
|
||||
/* This is to avoid mobile device management component getting initialized before the underlying datasources
|
||||
are registered */
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Data source service set to service component");
|
||||
}
|
||||
}
|
||||
|
||||
protected void unsetDataSourceService(DataSourceService dataSourceService) {
|
||||
//do nothing
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* Licensed 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.
|
||||
*/
|
||||
.circle {
|
||||
background: none repeat scroll 0 0 #191919;
|
||||
border-radius: 50px;
|
||||
height: 50px;
|
||||
padding: 10px;
|
||||
width: 50px;
|
||||
color: #fff;
|
||||
}
|
||||
.padding-top-double {
|
||||
padding-top: 20px;
|
||||
}
|
||||
.padding-double {
|
||||
padding: 20px;
|
||||
}
|
||||
.grey {
|
||||
color: #333;
|
||||
}
|
||||
hr {
|
||||
display: block;
|
||||
height: 1px;
|
||||
border: 0;
|
||||
border-top: 1px solid #7f7f7f;
|
||||
margin: 1em 0;
|
||||
padding: 0;
|
||||
opacity: 0.2;
|
||||
}
|
||||
.light-grey {
|
||||
color: #7c7c7c;
|
||||
}
|
||||
.uppercase {
|
||||
text-transform: uppercase;
|
||||
}
|
||||
.grey-bg {
|
||||
background-color: #f6f4f4;
|
||||
}
|
||||
.doc-link {
|
||||
background: #11375B;
|
||||
padding: 20px;
|
||||
color: white;
|
||||
}
|
||||
.doc-link a {
|
||||
color: white;
|
||||
}
|
||||
@ -289,51 +289,7 @@
|
||||
</div>
|
||||
|
||||
{{#zone "topCss"}}
|
||||
<style type="text/css">
|
||||
.circle {
|
||||
background: none repeat scroll 0 0 #191919;
|
||||
border-radius: 50px;
|
||||
height: 50px;
|
||||
padding: 10px;
|
||||
width: 50px;
|
||||
color: #fff;
|
||||
}
|
||||
.padding-top-double {
|
||||
padding-top: 20px;
|
||||
}
|
||||
.padding-double {
|
||||
padding: 20px;
|
||||
}
|
||||
.grey {
|
||||
color: #333;
|
||||
}
|
||||
hr {
|
||||
display: block;
|
||||
height: 1px;
|
||||
border: 0;
|
||||
border-top: 1px solid #7f7f7f;
|
||||
margin: 1em 0;
|
||||
padding: 0;
|
||||
opacity: 0.2;
|
||||
}
|
||||
.light-grey {
|
||||
color: #7c7c7c;
|
||||
}
|
||||
.uppercase {
|
||||
text-transform: uppercase;
|
||||
}
|
||||
.grey-bg {
|
||||
background-color: #f6f4f4;
|
||||
}
|
||||
.doc-link {
|
||||
background: #11375B;
|
||||
padding: 20px;
|
||||
color: white;
|
||||
}
|
||||
.doc-link a {
|
||||
color: white;
|
||||
}
|
||||
</style>
|
||||
{{css "css/styles.css"}}
|
||||
{{/zone}}
|
||||
|
||||
{{#zone "bottomJs"}}
|
||||
|
||||
@ -76,7 +76,8 @@
|
||||
org.wso2.carbon.core,
|
||||
org.wso2.carbon.core.util,
|
||||
org.wso2.carbon.event.output.adapter.core,
|
||||
org.wso2.carbon.event.output.adapter.core.exception
|
||||
org.wso2.carbon.event.output.adapter.core.exception,
|
||||
org.wso2.carbon.ndatasource.core
|
||||
</Import-Package>
|
||||
<Export-Package>
|
||||
!org.wso2.carbon.device.mgt.iot.raspberrypi.plugin.internal,
|
||||
|
||||
@ -26,7 +26,7 @@ import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceManager;
|
||||
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
|
||||
import org.wso2.carbon.device.mgt.common.FeatureManager;
|
||||
import org.wso2.carbon.device.mgt.common.configuration.mgt.TenantConfiguration;
|
||||
import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration;
|
||||
import org.wso2.carbon.device.mgt.common.license.mgt.License;
|
||||
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException;
|
||||
import org.wso2.carbon.device.mgt.iot.raspberrypi.plugin.exception.RaspberrypiDeviceMgtPluginException;
|
||||
@ -49,13 +49,13 @@ public class RaspberrypiManager implements DeviceManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean saveConfiguration(TenantConfiguration tenantConfiguration)
|
||||
public boolean saveConfiguration(PlatformConfiguration tenantConfiguration)
|
||||
throws DeviceManagementException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TenantConfiguration getConfiguration() throws DeviceManagementException {
|
||||
public PlatformConfiguration getConfiguration() throws DeviceManagementException {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@ -49,7 +49,7 @@ public class RaspberrypiDAOUtil {
|
||||
Context ctx = new InitialContext();
|
||||
dataSource = (DataSource) ctx.lookup(RaspberrypiConstants.DATA_SOURCE_NAME);
|
||||
} catch (NamingException e) {
|
||||
log.error("Error while looking up the data source: " + RaspberrypiConstants.DATA_SOURCE_NAME);
|
||||
log.error("Error while looking up the data source: " + RaspberrypiConstants.DATA_SOURCE_NAME, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -20,6 +20,7 @@ package org.wso2.carbon.device.mgt.iot.raspberrypi.plugin.impl.util;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.device.mgt.iot.raspberrypi.plugin.constants.RaspberrypiConstants;
|
||||
import org.wso2.carbon.utils.CarbonUtils;
|
||||
import org.wso2.carbon.utils.dbcreator.DatabaseCreator;
|
||||
|
||||
@ -33,7 +34,8 @@ public class DeviceSchemaInitializer extends DatabaseCreator{
|
||||
|
||||
private static final Log log = LogFactory.getLog(DeviceSchemaInitializer.class);
|
||||
private static final String setupSQLScriptBaseLocation = CarbonUtils.getCarbonHome() + File.separator + "dbscripts"
|
||||
+ File.separator + "cdm" + File.separator + "plugins" + File.separator;
|
||||
+ File.separator + "cdm" + File.separator + "plugins" + File.separator + RaspberrypiConstants.DEVICE_TYPE
|
||||
+ File.separator;
|
||||
|
||||
public DeviceSchemaInitializer(DataSource dataSource) {
|
||||
super(dataSource);
|
||||
|
||||
@ -87,12 +87,11 @@ public class RaspberrypiUtils {
|
||||
try {
|
||||
Context ctx = new InitialContext();
|
||||
DataSource dataSource = (DataSource) ctx.lookup(RaspberrypiConstants.DATA_SOURCE_NAME);
|
||||
DeviceSchemaInitializer initializer =
|
||||
new DeviceSchemaInitializer(dataSource);
|
||||
DeviceSchemaInitializer initializer = new DeviceSchemaInitializer(dataSource);
|
||||
log.info("Initializing device management repository database schema");
|
||||
initializer.createRegistryDatabase();
|
||||
} catch (NamingException e) {
|
||||
log.error("Error while looking up the data source: " + RaspberrypiConstants.DATA_SOURCE_NAME);
|
||||
log.error("Error while looking up the data source: " + RaspberrypiConstants.DATA_SOURCE_NAME, e);
|
||||
} catch (Exception e) {
|
||||
throw new RaspberrypiDeviceMgtPluginException("Error occurred while initializing Iot Device " +
|
||||
"Management database schema", e);
|
||||
|
||||
@ -30,6 +30,7 @@ import org.wso2.carbon.device.mgt.iot.raspberrypi.plugin.impl.RaspberrypiManager
|
||||
import org.wso2.carbon.device.mgt.iot.raspberrypi.plugin.impl.util.RaspberrypiStartupListener;
|
||||
import org.wso2.carbon.device.mgt.iot.raspberrypi.plugin.impl.util.RaspberrypiUtils;
|
||||
import org.wso2.carbon.event.output.adapter.core.OutputEventAdapterService;
|
||||
import org.wso2.carbon.ndatasource.core.DataSourceService;
|
||||
|
||||
/**
|
||||
* @scr.component name="org.wso2.carbon.device.mgt.iot.raspberrypi.internal.RaspberrypiManagementServiceComponent"
|
||||
@ -40,6 +41,12 @@ import org.wso2.carbon.event.output.adapter.core.OutputEventAdapterService;
|
||||
* policy="dynamic"
|
||||
* bind="setOutputEventAdapterService"
|
||||
* unbind="unsetOutputEventAdapterService"
|
||||
* @scr.reference name="org.wso2.carbon.ndatasource"
|
||||
* interface="org.wso2.carbon.ndatasource.core.DataSourceService"
|
||||
* cardinality="1..1"
|
||||
* policy="dynamic"
|
||||
* bind="setDataSourceService"
|
||||
* unbind="unsetDataSourceService"
|
||||
*/
|
||||
public class RaspberrypiManagementServiceComponent {
|
||||
|
||||
@ -110,4 +117,16 @@ public class RaspberrypiManagementServiceComponent {
|
||||
RaspberrypiManagementDataHolder.getInstance().setOutputEventAdapterService(null);
|
||||
}
|
||||
|
||||
protected void setDataSourceService(DataSourceService dataSourceService) {
|
||||
/* This is to avoid mobile device management component getting initialized before the underlying datasources
|
||||
are registered */
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Data source service set to service component");
|
||||
}
|
||||
}
|
||||
|
||||
protected void unsetDataSourceService(DataSourceService dataSourceService) {
|
||||
//do nothing
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* Licensed 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.
|
||||
*/
|
||||
.circle {
|
||||
background: none repeat scroll 0 0 #191919;
|
||||
border-radius: 50px;
|
||||
height: 50px;
|
||||
padding: 10px;
|
||||
width: 50px;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.padding-top-double {
|
||||
padding-top: 20px;
|
||||
}
|
||||
|
||||
.padding-double {
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.grey {
|
||||
color: #333;
|
||||
}
|
||||
|
||||
hr {
|
||||
display: block;
|
||||
height: 1px;
|
||||
border: 0;
|
||||
border-top: 1px solid #7f7f7f;
|
||||
margin: 1em 0;
|
||||
padding: 0;
|
||||
opacity: 0.2;
|
||||
}
|
||||
|
||||
.light-grey {
|
||||
color: #7c7c7c;
|
||||
}
|
||||
|
||||
.uppercase {
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.grey-bg {
|
||||
background-color: #f6f4f4;
|
||||
}
|
||||
|
||||
.doc-link {
|
||||
background: #11375B;
|
||||
padding: 20px;
|
||||
color: white;
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
.doc-link a {
|
||||
color: white;
|
||||
}
|
||||
@ -278,61 +278,7 @@
|
||||
</div>
|
||||
|
||||
{{#zone "topCss"}}
|
||||
<style type="text/css">
|
||||
.circle {
|
||||
background: none repeat scroll 0 0 #191919;
|
||||
border-radius: 50px;
|
||||
height: 50px;
|
||||
padding: 10px;
|
||||
width: 50px;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.padding-top-double {
|
||||
padding-top: 20px;
|
||||
}
|
||||
|
||||
.padding-double {
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.grey {
|
||||
color: #333;
|
||||
}
|
||||
|
||||
hr {
|
||||
display: block;
|
||||
height: 1px;
|
||||
border: 0;
|
||||
border-top: 1px solid #7f7f7f;
|
||||
margin: 1em 0;
|
||||
padding: 0;
|
||||
opacity: 0.2;
|
||||
}
|
||||
|
||||
.light-grey {
|
||||
color: #7c7c7c;
|
||||
}
|
||||
|
||||
.uppercase {
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.grey-bg {
|
||||
background-color: #f6f4f4;
|
||||
}
|
||||
|
||||
.doc-link {
|
||||
background: #11375B;
|
||||
padding: 20px;
|
||||
color: white;
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
.doc-link a {
|
||||
color: white;
|
||||
}
|
||||
</style>
|
||||
{{css "css/styles.css"}}
|
||||
{{/zone}}
|
||||
|
||||
{{#zone "bottomJs"}}
|
||||
|
||||
@ -91,7 +91,7 @@
|
||||
javax.xml.bind,
|
||||
javax.xml.bind.annotation,
|
||||
javax.xml.parsers,
|
||||
org.w3c.dom
|
||||
org.w3c.dom,
|
||||
</Import-Package>
|
||||
<Export-Package>
|
||||
!org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.internal,
|
||||
|
||||
@ -26,7 +26,7 @@ import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceManager;
|
||||
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
|
||||
import org.wso2.carbon.device.mgt.common.FeatureManager;
|
||||
import org.wso2.carbon.device.mgt.common.configuration.mgt.TenantConfiguration;
|
||||
import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration;
|
||||
import org.wso2.carbon.device.mgt.common.license.mgt.License;
|
||||
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException;
|
||||
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.exception.VirtualFirealarmDeviceMgtPluginException;
|
||||
@ -50,13 +50,13 @@ public class VirtualFireAlarmManager implements DeviceManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean saveConfiguration(TenantConfiguration tenantConfiguration)
|
||||
public boolean saveConfiguration(PlatformConfiguration PlatformConfiguration)
|
||||
throws DeviceManagementException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TenantConfiguration getConfiguration() throws DeviceManagementException {
|
||||
public PlatformConfiguration getConfiguration() throws DeviceManagementException {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@ -45,7 +45,7 @@ public class VirtualFireAlarmDAOUtil {
|
||||
Context ctx = new InitialContext();
|
||||
dataSource = (DataSource) ctx.lookup(VirtualFireAlarmConstants.DATA_SOURCE_NAME);
|
||||
} catch (NamingException e) {
|
||||
log.error("Error while looking up the data source: " + VirtualFireAlarmConstants.DATA_SOURCE_NAME);
|
||||
log.error("Error while looking up the data source: " + VirtualFireAlarmConstants.DATA_SOURCE_NAME, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -20,6 +20,7 @@ package org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.impl.util;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.constants.VirtualFireAlarmConstants;
|
||||
import org.wso2.carbon.utils.CarbonUtils;
|
||||
import org.wso2.carbon.utils.dbcreator.DatabaseCreator;
|
||||
|
||||
@ -33,7 +34,8 @@ public class DeviceSchemaInitializer extends DatabaseCreator{
|
||||
|
||||
private static final Log log = LogFactory.getLog(DeviceSchemaInitializer.class);
|
||||
private static final String setupSQLScriptBaseLocation = CarbonUtils.getCarbonHome() + File.separator + "dbscripts"
|
||||
+ File.separator + "cdm" + File.separator + "plugins" + File.separator;
|
||||
+ File.separator + "cdm" + File.separator + "plugins" + File.separator
|
||||
+ VirtualFireAlarmConstants.DEVICE_TYPE + File.separator;
|
||||
|
||||
public DeviceSchemaInitializer(DataSource dataSource) {
|
||||
super(dataSource);
|
||||
|
||||
@ -100,12 +100,11 @@ public class VirtualFireAlarmUtils {
|
||||
try {
|
||||
Context ctx = new InitialContext();
|
||||
DataSource dataSource = (DataSource) ctx.lookup(VirtualFireAlarmConstants.DATA_SOURCE_NAME);
|
||||
DeviceSchemaInitializer initializer =
|
||||
new DeviceSchemaInitializer(dataSource);
|
||||
DeviceSchemaInitializer initializer = new DeviceSchemaInitializer(dataSource);
|
||||
log.info("Initializing device management repository database schema");
|
||||
initializer.createRegistryDatabase();
|
||||
} catch (NamingException e) {
|
||||
log.error("Error while looking up the data source: " + VirtualFireAlarmConstants.DATA_SOURCE_NAME);
|
||||
log.error("Error while looking up the data source: " + VirtualFireAlarmConstants.DATA_SOURCE_NAME, e);
|
||||
} catch (Exception e) {
|
||||
throw new VirtualFirealarmDeviceMgtPluginException("Error occurred while initializing Iot Device " +
|
||||
"Management database schema", e);
|
||||
|
||||
@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* Licensed 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.
|
||||
*/
|
||||
.circle {
|
||||
background: none repeat scroll 0 0 #191919;
|
||||
border-radius: 50px;
|
||||
height: 50px;
|
||||
padding: 10px;
|
||||
width: 50px;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.padding-top-double {
|
||||
padding-top: 20px;
|
||||
}
|
||||
|
||||
.padding-double {
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.grey {
|
||||
color: #333;
|
||||
}
|
||||
|
||||
hr {
|
||||
display: block;
|
||||
height: 1px;
|
||||
border: 0;
|
||||
border-top: 1px solid #7f7f7f;
|
||||
margin: 1em 0;
|
||||
padding: 0;
|
||||
opacity: 0.2;
|
||||
}
|
||||
|
||||
.light-grey {
|
||||
color: #7c7c7c;
|
||||
}
|
||||
|
||||
.uppercase {
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.grey-bg {
|
||||
background-color: #f6f4f4;
|
||||
}
|
||||
|
||||
.doc-link {
|
||||
background: #11375B;
|
||||
padding: 20px;
|
||||
color: white;
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
.doc-link a {
|
||||
color: white;
|
||||
}
|
||||
@ -250,65 +250,10 @@
|
||||
</div>
|
||||
|
||||
{{#zone "topCss"}}
|
||||
<style type="text/css">
|
||||
.circle {
|
||||
background: none repeat scroll 0 0 #191919;
|
||||
border-radius: 50px;
|
||||
height: 50px;
|
||||
padding: 10px;
|
||||
width: 50px;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.padding-top-double {
|
||||
padding-top: 20px;
|
||||
}
|
||||
|
||||
.padding-double {
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.grey {
|
||||
color: #333;
|
||||
}
|
||||
|
||||
hr {
|
||||
display: block;
|
||||
height: 1px;
|
||||
border: 0;
|
||||
border-top: 1px solid #7f7f7f;
|
||||
margin: 1em 0;
|
||||
padding: 0;
|
||||
opacity: 0.2;
|
||||
}
|
||||
|
||||
.light-grey {
|
||||
color: #7c7c7c;
|
||||
}
|
||||
|
||||
.uppercase {
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.grey-bg {
|
||||
background-color: #f6f4f4;
|
||||
}
|
||||
|
||||
.doc-link {
|
||||
background: #11375B;
|
||||
padding: 20px;
|
||||
color: white;
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
.doc-link a {
|
||||
color: white;
|
||||
}
|
||||
|
||||
</style>
|
||||
{{css "css/styles.css"}}
|
||||
{{/zone}}
|
||||
|
||||
{{#zone "bottomJs"}}
|
||||
{{js "/js/download.js"}}
|
||||
{{js "/js/jquery.validate.js"}}
|
||||
{{/zone}}
|
||||
{{/zone}}
|
||||
@ -46,7 +46,7 @@
|
||||
<version>2.2</version>
|
||||
<configuration>
|
||||
<packagingExcludes>WEB-INF/lib/*cxf*.jar</packagingExcludes>
|
||||
<warName>${project.artifactId}</warName>
|
||||
<warName>mdm-android-agent</warName>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
@ -72,7 +72,7 @@
|
||||
<tasks>
|
||||
<copy todir="${basedir}/../../../repository/deployment/server/webapps" overwrite="true">
|
||||
<fileset dir="${basedir}/target">
|
||||
<include name="${project.artifactId}.war" />
|
||||
<include name="mdm-android-agent.war" />
|
||||
</fileset>
|
||||
</copy>
|
||||
</tasks>
|
||||
|
||||
@ -19,7 +19,7 @@
|
||||
package org.wso2.carbon.mdm.services.android.services.configuration;
|
||||
|
||||
import io.swagger.annotations.*;
|
||||
import org.wso2.carbon.device.mgt.common.configuration.mgt.TenantConfiguration;
|
||||
import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration;
|
||||
import org.wso2.carbon.mdm.services.android.exception.AndroidAgentException;
|
||||
import javax.ws.rs.*;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
@ -46,14 +46,14 @@ public interface ConfigurationMgtService {
|
||||
@ApiResponse(code = 500, message = "Internal Server Error")
|
||||
})
|
||||
Response configureSettings(@ApiParam(name = "configuration", value = "AndroidPlatformConfiguration")
|
||||
TenantConfiguration configuration) throws AndroidAgentException;
|
||||
PlatformConfiguration configuration) throws AndroidAgentException;
|
||||
|
||||
@GET
|
||||
@ApiOperation(
|
||||
httpMethod = "GET",
|
||||
value = "Getting Android Platform Configurations",
|
||||
notes = "Get the Android platform configuration details using this REST API",
|
||||
response = TenantConfiguration.class
|
||||
response = PlatformConfiguration.class
|
||||
)
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(code = 200, message = "Get Android Configurations"),
|
||||
@ -75,5 +75,5 @@ public interface ConfigurationMgtService {
|
||||
"Android platform")
|
||||
})
|
||||
Response updateConfiguration(@ApiParam(name = "configuration", value = "AndroidPlatformConfiguration")
|
||||
TenantConfiguration configuration) throws AndroidAgentException;
|
||||
PlatformConfiguration configuration) throws AndroidAgentException;
|
||||
}
|
||||
|
||||
@ -23,7 +23,7 @@ import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||
import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationEntry;
|
||||
import org.wso2.carbon.device.mgt.common.configuration.mgt.TenantConfiguration;
|
||||
import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration;
|
||||
import org.wso2.carbon.device.mgt.common.license.mgt.License;
|
||||
import org.wso2.carbon.mdm.services.android.exception.AndroidAgentException;
|
||||
import org.wso2.carbon.mdm.services.android.services.configuration.ConfigurationMgtService;
|
||||
@ -45,7 +45,7 @@ public class ConfigurationMgtServiceImpl implements ConfigurationMgtService {
|
||||
private static Log log = LogFactory.getLog(ConfigurationMgtServiceImpl.class);
|
||||
|
||||
@POST
|
||||
public Response configureSettings(TenantConfiguration configuration)
|
||||
public Response configureSettings(PlatformConfiguration configuration)
|
||||
throws AndroidAgentException {
|
||||
|
||||
Message responseMsg = new Message();
|
||||
@ -87,15 +87,15 @@ public class ConfigurationMgtServiceImpl implements ConfigurationMgtService {
|
||||
@GET
|
||||
public Response getConfiguration() throws AndroidAgentException {
|
||||
String msg;
|
||||
TenantConfiguration tenantConfiguration = null;
|
||||
PlatformConfiguration PlatformConfiguration = null;
|
||||
List<ConfigurationEntry> configs;
|
||||
try {
|
||||
tenantConfiguration = AndroidAPIUtils.getDeviceManagementService().
|
||||
PlatformConfiguration = AndroidAPIUtils.getDeviceManagementService().
|
||||
getConfiguration(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
|
||||
if (tenantConfiguration != null) {
|
||||
configs = tenantConfiguration.getConfiguration();
|
||||
if (PlatformConfiguration != null) {
|
||||
configs = PlatformConfiguration.getConfiguration();
|
||||
} else {
|
||||
tenantConfiguration = new TenantConfiguration();
|
||||
PlatformConfiguration = new PlatformConfiguration();
|
||||
configs = new ArrayList<>();
|
||||
}
|
||||
|
||||
@ -109,18 +109,18 @@ public class ConfigurationMgtServiceImpl implements ConfigurationMgtService {
|
||||
entry.setName(AndroidConstants.TenantConfigProperties.LICENSE_KEY);
|
||||
entry.setValue(license.getText());
|
||||
configs.add(entry);
|
||||
tenantConfiguration.setConfiguration(configs);
|
||||
PlatformConfiguration.setConfiguration(configs);
|
||||
}
|
||||
} catch (DeviceManagementException e) {
|
||||
msg = "Error occurred while retrieving the Android tenant configuration";
|
||||
log.error(msg, e);
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||
}
|
||||
return Response.status(Response.Status.OK).entity(tenantConfiguration).build();
|
||||
return Response.status(Response.Status.OK).entity(PlatformConfiguration).build();
|
||||
}
|
||||
|
||||
@PUT
|
||||
public Response updateConfiguration(TenantConfiguration configuration) throws AndroidAgentException {
|
||||
public Response updateConfiguration(PlatformConfiguration configuration) throws AndroidAgentException {
|
||||
String msg;
|
||||
Message responseMsg = new Message();
|
||||
ConfigurationEntry licenseEntry = null;
|
||||
@ -145,7 +145,7 @@ public class ConfigurationMgtServiceImpl implements ConfigurationMgtService {
|
||||
}
|
||||
configuration.setConfiguration(configs);
|
||||
AndroidAPIUtils.getDeviceManagementService().saveConfiguration(configuration);
|
||||
AndroidAPIUtils.getGCMService().resetTenantConfigCache();
|
||||
//AndroidAPIUtils.getGCMService().resetTenantConfigCache();
|
||||
Response.status(Response.Status.ACCEPTED);
|
||||
responseMsg.setResponseMessage("Android platform configuration has updated successfully.");
|
||||
responseMsg.setResponseCode(Response.Status.ACCEPTED.toString());
|
||||
|
||||
@ -46,7 +46,6 @@ import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceDetailsMgtExcept
|
||||
import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceInformationManager;
|
||||
import org.wso2.carbon.device.mgt.core.search.mgt.impl.Utils;
|
||||
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
||||
import org.wso2.carbon.device.mgt.mobile.impl.android.gcm.GCMService;
|
||||
import org.wso2.carbon.mdm.services.android.bean.DeviceState;
|
||||
import org.wso2.carbon.policy.mgt.common.monitor.PolicyComplianceException;
|
||||
import org.wso2.carbon.policy.mgt.core.PolicyManagerService;
|
||||
@ -94,16 +93,16 @@ public class AndroidAPIUtils {
|
||||
return deviceManagementProviderService;
|
||||
}
|
||||
|
||||
public static GCMService getGCMService() {
|
||||
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
||||
GCMService gcmService = (GCMService) ctx.getOSGiService(GCMService.class, null);
|
||||
if (gcmService == null) {
|
||||
String msg = "GCM service has not initialized.";
|
||||
log.error(msg);
|
||||
throw new IllegalStateException(msg);
|
||||
}
|
||||
return gcmService;
|
||||
}
|
||||
// public static GCMService getGCMService() {
|
||||
// PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
||||
// GCMService gcmService = (GCMService) ctx.getOSGiService(GCMService.class, null);
|
||||
// if (gcmService == null) {
|
||||
// String msg = "GCM service has not initialized.";
|
||||
// log.error(msg);
|
||||
// throw new IllegalStateException(msg);
|
||||
// }
|
||||
// return gcmService;
|
||||
// }
|
||||
|
||||
public static MediaType getResponseMediaType(String acceptHeader) {
|
||||
MediaType responseMediaType;
|
||||
@ -126,17 +125,17 @@ public class AndroidAPIUtils {
|
||||
List<DeviceIdentifier> validDeviceIds = deviceIDHolder.getValidDeviceIDList();
|
||||
Activity activity = getDeviceManagementService().addOperation(
|
||||
DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID, operation, validDeviceIds);
|
||||
if (activity != null) {
|
||||
GCMService gcmService = getGCMService();
|
||||
if (gcmService.isGCMEnabled()) {
|
||||
List<DeviceIdentifier> deviceIDList = deviceIDHolder.getValidDeviceIDList();
|
||||
List<Device> devices = new ArrayList<Device>(deviceIDList.size());
|
||||
for (DeviceIdentifier deviceIdentifier : deviceIDList) {
|
||||
devices.add(getDeviceManagementService().getDevice(deviceIdentifier));
|
||||
}
|
||||
getGCMService().sendNotification(operation.getCode(), devices);
|
||||
}
|
||||
}
|
||||
// if (activity != null) {
|
||||
// GCMService gcmService = getGCMService();
|
||||
// if (gcmService.isGCMEnabled()) {
|
||||
// List<DeviceIdentifier> deviceIDList = deviceIDHolder.getValidDeviceIDList();
|
||||
// List<Device> devices = new ArrayList<Device>(deviceIDList.size());
|
||||
// for (DeviceIdentifier deviceIdentifier : deviceIDList) {
|
||||
// devices.add(getDeviceManagementService().getDevice(deviceIdentifier));
|
||||
// }
|
||||
// getGCMService().sendNotification(operation.getCode(), devices);
|
||||
// }
|
||||
// }
|
||||
if (!deviceIDHolder.getErrorDeviceIdList().isEmpty()) {
|
||||
return javax.ws.rs.core.Response.status(AndroidConstants.StatusCodes.
|
||||
MULTI_STATUS_HTTP_CODE).type(
|
||||
|
||||
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* Licensed 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.
|
||||
*/
|
||||
.circle {
|
||||
background: none repeat scroll 0 0 #191919;
|
||||
border-radius: 50px;
|
||||
height: 50px;
|
||||
padding: 10px;
|
||||
width: 50px;
|
||||
color: #fff;
|
||||
}
|
||||
.padding-top-double {
|
||||
padding-top: 20px;
|
||||
}
|
||||
.padding-double {
|
||||
padding: 20px;
|
||||
}
|
||||
.grey {
|
||||
color: #333;
|
||||
}
|
||||
hr {
|
||||
display: block;
|
||||
height: 1px;
|
||||
border: 0;
|
||||
border-top: 1px solid #7f7f7f;
|
||||
margin: 1em 0;
|
||||
padding: 0;
|
||||
opacity: 0.2;
|
||||
}
|
||||
.light-grey {
|
||||
color: #7c7c7c;
|
||||
}
|
||||
.uppercase {
|
||||
text-transform: uppercase;
|
||||
}
|
||||
.grey-bg {
|
||||
background-color: #f6f4f4;
|
||||
}
|
||||
|
||||
.doc-link {
|
||||
background: #11375B;
|
||||
padding: 20px;
|
||||
color: white;
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
.doc-link a {
|
||||
color: white;
|
||||
}
|
||||
@ -79,59 +79,11 @@
|
||||
</div>
|
||||
|
||||
{{#zone "topCss"}}
|
||||
<style type="text/css">
|
||||
.circle {
|
||||
background: none repeat scroll 0 0 #191919;
|
||||
border-radius: 50px;
|
||||
height: 50px;
|
||||
padding: 10px;
|
||||
width: 50px;
|
||||
color: #fff;
|
||||
}
|
||||
.padding-top-double {
|
||||
padding-top: 20px;
|
||||
}
|
||||
.padding-double {
|
||||
padding: 20px;
|
||||
}
|
||||
.grey {
|
||||
color: #333;
|
||||
}
|
||||
hr {
|
||||
display: block;
|
||||
height: 1px;
|
||||
border: 0;
|
||||
border-top: 1px solid #7f7f7f;
|
||||
margin: 1em 0;
|
||||
padding: 0;
|
||||
opacity: 0.2;
|
||||
}
|
||||
.light-grey {
|
||||
color: #7c7c7c;
|
||||
}
|
||||
.uppercase {
|
||||
text-transform: uppercase;
|
||||
}
|
||||
.grey-bg {
|
||||
background-color: #f6f4f4;
|
||||
}
|
||||
|
||||
.doc-link {
|
||||
background: #11375B;
|
||||
padding: 20px;
|
||||
color: white;
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
.doc-link a {
|
||||
color: white;
|
||||
}
|
||||
</style>
|
||||
{{css "css/styles.css"}}
|
||||
{{/zone}}
|
||||
|
||||
{{#zone "bottomJs"}}
|
||||
<script type="text/javascript">
|
||||
|
||||
$(".download-link").click(function(){
|
||||
toggleEnrollment();
|
||||
});
|
||||
@ -141,6 +93,5 @@
|
||||
generateQRCode(".modalpopup-content .qr-code");
|
||||
showPopup();
|
||||
}
|
||||
|
||||
</script>
|
||||
{{/zone}}
|
||||
@ -35,6 +35,10 @@
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.felix</groupId>
|
||||
<artifactId>maven-scr-plugin</artifactId>
|
||||
|
||||
@ -27,7 +27,7 @@ import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceManager;
|
||||
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
|
||||
import org.wso2.carbon.device.mgt.common.FeatureManager;
|
||||
import org.wso2.carbon.device.mgt.common.configuration.mgt.TenantConfiguration;
|
||||
import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration;
|
||||
import org.wso2.carbon.device.mgt.common.license.mgt.License;
|
||||
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException;
|
||||
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManager;
|
||||
@ -85,7 +85,7 @@ public class AndroidDeviceManager implements DeviceManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean saveConfiguration(TenantConfiguration tenantConfiguration)
|
||||
public boolean saveConfiguration(PlatformConfiguration tenantConfiguration)
|
||||
throws DeviceManagementException {
|
||||
boolean status;
|
||||
try {
|
||||
@ -96,7 +96,7 @@ public class AndroidDeviceManager implements DeviceManager {
|
||||
DeviceManagementConstants.
|
||||
MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
|
||||
StringWriter writer = new StringWriter();
|
||||
JAXBContext context = JAXBContext.newInstance(TenantConfiguration.class);
|
||||
JAXBContext context = JAXBContext.newInstance(PlatformConfiguration.class);
|
||||
Marshaller marshaller = context.createMarshaller();
|
||||
marshaller.marshal(tenantConfiguration, writer);
|
||||
|
||||
@ -119,7 +119,7 @@ public class AndroidDeviceManager implements DeviceManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public TenantConfiguration getConfiguration() throws DeviceManagementException {
|
||||
public PlatformConfiguration getConfiguration() throws DeviceManagementException {
|
||||
Resource resource;
|
||||
try {
|
||||
String androidRegPath =
|
||||
@ -127,9 +127,9 @@ public class AndroidDeviceManager implements DeviceManager {
|
||||
MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
|
||||
resource = MobileDeviceManagementUtil.getRegistryResource(androidRegPath);
|
||||
if (resource != null) {
|
||||
JAXBContext context = JAXBContext.newInstance(TenantConfiguration.class);
|
||||
JAXBContext context = JAXBContext.newInstance(PlatformConfiguration.class);
|
||||
Unmarshaller unmarshaller = context.createUnmarshaller();
|
||||
return (TenantConfiguration) unmarshaller.unmarshal(
|
||||
return (PlatformConfiguration) unmarshaller.unmarshal(
|
||||
new StringReader(new String((byte[]) resource.getContent(), Charset.
|
||||
forName(MobilePluginConstants.CHARSET_UTF8))));
|
||||
}
|
||||
|
||||
@ -27,7 +27,7 @@ import org.wso2.carbon.context.CarbonContext;
|
||||
import org.wso2.carbon.device.mgt.common.Device;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||
import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationEntry;
|
||||
import org.wso2.carbon.device.mgt.common.configuration.mgt.TenantConfiguration;
|
||||
import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration;
|
||||
import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
|
||||
import org.wso2.carbon.device.mgt.mobile.android.impl.util.AndroidPluginConstants;
|
||||
import org.wso2.carbon.device.mgt.mobile.android.internal.AndroidDeviceManagementDataHolder;
|
||||
@ -56,7 +56,7 @@ public class GCMUtil {
|
||||
private static final int TIME_TO_LIVE = 60;
|
||||
private static final int HTTP_STATUS_CODE_OK = 200;
|
||||
|
||||
private static HashMap<Integer,TenantConfiguration> tenantConfigurationCache = new HashMap<>();
|
||||
private static HashMap<Integer, PlatformConfiguration> tenantConfigurationCache = new HashMap<>();
|
||||
|
||||
public static GCMResult sendWakeUpCall(String message, List<Device> devices) {
|
||||
GCMResult result = new GCMResult();
|
||||
@ -163,7 +163,7 @@ public class GCMUtil {
|
||||
getAndroidDeviceManagementService();
|
||||
try {
|
||||
//Get the TenantConfiguration from cache if not we'll get it from DM service
|
||||
TenantConfiguration tenantConfiguration = getTenantConfigurationFromCache();
|
||||
PlatformConfiguration tenantConfiguration = getTenantConfigurationFromCache();
|
||||
if (tenantConfiguration == null) {
|
||||
tenantConfiguration = androidDMService.getDeviceManager().getConfiguration();
|
||||
if (tenantConfiguration != null) {
|
||||
@ -190,11 +190,11 @@ public class GCMUtil {
|
||||
tenantConfigurationCache.remove(getTenantId());
|
||||
}
|
||||
|
||||
private static void addTenantConfigurationToCache(TenantConfiguration tenantConfiguration) {
|
||||
private static void addTenantConfigurationToCache(PlatformConfiguration tenantConfiguration) {
|
||||
tenantConfigurationCache.put(getTenantId(), tenantConfiguration);
|
||||
}
|
||||
|
||||
private static TenantConfiguration getTenantConfigurationFromCache() {
|
||||
private static PlatformConfiguration getTenantConfigurationFromCache() {
|
||||
return tenantConfigurationCache.get(getTenantId());
|
||||
}
|
||||
|
||||
|
||||
@ -1,70 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* you may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.impl.android;
|
||||
|
||||
import org.wso2.carbon.device.mgt.common.*;
|
||||
import org.wso2.carbon.device.mgt.common.app.mgt.Application;
|
||||
import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException;
|
||||
import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager;
|
||||
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
|
||||
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig;
|
||||
import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This represents the Android implementation of DeviceManagerService.
|
||||
*/
|
||||
public class AndroidDeviceManagementService implements DeviceManagementService {
|
||||
|
||||
private DeviceManager deviceManager;
|
||||
public static final String DEVICE_TYPE_ANDROID = "android";
|
||||
private static final String SUPER_TENANT_DOMAIN = "carbon.super";
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return AndroidDeviceManagementService.DEVICE_TYPE_ANDROID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() throws DeviceManagementException {
|
||||
this.deviceManager = new AndroidDeviceManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
public DeviceManager getDeviceManager() {
|
||||
return deviceManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApplicationManager getApplicationManager() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProvisioningConfig getProvisioningConfig() {
|
||||
return new ProvisioningConfig(SUPER_TENANT_DOMAIN, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PushNotificationConfig getPushNotificationConfig() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,342 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
package org.wso2.carbon.device.mgt.mobile.impl.android;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.device.mgt.common.*;
|
||||
import org.wso2.carbon.device.mgt.common.configuration.mgt.TenantConfiguration;
|
||||
import org.wso2.carbon.device.mgt.common.license.mgt.License;
|
||||
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException;
|
||||
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManager;
|
||||
import org.wso2.carbon.device.mgt.extensions.license.mgt.registry.RegistryBasedLicenseManager;
|
||||
import org.wso2.carbon.device.mgt.mobile.common.MobileDeviceMgtPluginException;
|
||||
import org.wso2.carbon.device.mgt.mobile.common.MobilePluginConstants;
|
||||
import org.wso2.carbon.device.mgt.mobile.dao.AbstractMobileDeviceManagementDAOFactory;
|
||||
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException;
|
||||
import org.wso2.carbon.device.mgt.mobile.dto.MobileDevice;
|
||||
import org.wso2.carbon.device.mgt.mobile.impl.android.dao.AndroidDAOFactory;
|
||||
import org.wso2.carbon.device.mgt.mobile.impl.android.util.AndroidPluginUtils;
|
||||
import org.wso2.carbon.device.mgt.mobile.util.MobileDeviceManagementUtil;
|
||||
import org.wso2.carbon.registry.api.RegistryException;
|
||||
import org.wso2.carbon.registry.api.Resource;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.Marshaller;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
import java.io.StringReader;
|
||||
import java.io.StringWriter;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class AndroidDeviceManager implements DeviceManager {
|
||||
|
||||
private AbstractMobileDeviceManagementDAOFactory daoFactory;
|
||||
private static final Log log = LogFactory.getLog(AndroidDeviceManagementService.class);
|
||||
private FeatureManager featureManager = new AndroidFeatureManager();
|
||||
private LicenseManager licenseManager;
|
||||
|
||||
public AndroidDeviceManager() {
|
||||
this.daoFactory = new AndroidDAOFactory();
|
||||
this.licenseManager = new RegistryBasedLicenseManager();
|
||||
License defaultLicense;
|
||||
|
||||
try {
|
||||
if (licenseManager.getLicense(AndroidDeviceManagementService.DEVICE_TYPE_ANDROID,
|
||||
MobilePluginConstants.LANGUAGE_CODE_ENGLISH_US) == null) {
|
||||
defaultLicense = AndroidPluginUtils.getDefaultLicense();
|
||||
licenseManager.addLicense(AndroidDeviceManagementService.DEVICE_TYPE_ANDROID, defaultLicense);
|
||||
}
|
||||
featureManager.addSupportedFeaturesToDB();
|
||||
} catch (LicenseManagementException e) {
|
||||
log.error("Error occurred while adding default license for Android devices", e);
|
||||
} catch (DeviceManagementException e) {
|
||||
throw new IllegalStateException("Error occurred while adding Android features to the DB.");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public FeatureManager getFeatureManager() {
|
||||
return featureManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean saveConfiguration(TenantConfiguration tenantConfiguration)
|
||||
throws DeviceManagementException {
|
||||
boolean status;
|
||||
try {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Persisting android configurations in Registry");
|
||||
}
|
||||
String resourcePath = MobileDeviceManagementUtil.getPlatformConfigPath(
|
||||
DeviceManagementConstants.
|
||||
MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
|
||||
StringWriter writer = new StringWriter();
|
||||
JAXBContext context = JAXBContext.newInstance(TenantConfiguration.class);
|
||||
Marshaller marshaller = context.createMarshaller();
|
||||
marshaller.marshal(tenantConfiguration, writer);
|
||||
|
||||
Resource resource = MobileDeviceManagementUtil.getConfigurationRegistry().newResource();
|
||||
resource.setContent(writer.toString());
|
||||
resource.setMediaType(MobilePluginConstants.MEDIA_TYPE_XML);
|
||||
MobileDeviceManagementUtil.putRegistryResource(resourcePath, resource);
|
||||
status = true;
|
||||
} catch (MobileDeviceMgtPluginException e) {
|
||||
throw new DeviceManagementException(
|
||||
"Error occurred while retrieving the Registry instance", e);
|
||||
} catch (RegistryException e) {
|
||||
throw new DeviceManagementException(
|
||||
"Error occurred while persisting the Registry resource of Android Configuration", e);
|
||||
} catch (JAXBException e) {
|
||||
throw new DeviceManagementException(
|
||||
"Error occurred while parsing the Android configuration", e);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TenantConfiguration getConfiguration() throws DeviceManagementException {
|
||||
Resource resource;
|
||||
try {
|
||||
String androidRegPath =
|
||||
MobileDeviceManagementUtil.getPlatformConfigPath(DeviceManagementConstants.
|
||||
MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
|
||||
resource = MobileDeviceManagementUtil.getRegistryResource(androidRegPath);
|
||||
if (resource != null) {
|
||||
JAXBContext context = JAXBContext.newInstance(TenantConfiguration.class);
|
||||
Unmarshaller unmarshaller = context.createUnmarshaller();
|
||||
return (TenantConfiguration) unmarshaller.unmarshal(
|
||||
new StringReader(new String((byte[]) resource.getContent(), Charset.
|
||||
forName(MobilePluginConstants.CHARSET_UTF8))));
|
||||
}
|
||||
return null;
|
||||
} catch (MobileDeviceMgtPluginException e) {
|
||||
throw new DeviceManagementException(
|
||||
"Error occurred while retrieving the Registry instance", e);
|
||||
} catch (JAXBException e) {
|
||||
throw new DeviceManagementException(
|
||||
"Error occurred while parsing the Android configuration", e);
|
||||
} catch (RegistryException e) {
|
||||
throw new DeviceManagementException(
|
||||
"Error occurred while retrieving the Registry resource of Android Configuration", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean enrollDevice(Device device) throws DeviceManagementException {
|
||||
boolean status = false;
|
||||
boolean isEnrolled = this.isEnrolled(
|
||||
new DeviceIdentifier(device.getDeviceIdentifier(), device.getType()));
|
||||
|
||||
try {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Enrolling a new Android device : " + device.getDeviceIdentifier());
|
||||
}
|
||||
|
||||
if (isEnrolled) {
|
||||
this.modifyEnrollment(device);
|
||||
} else {
|
||||
MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device);
|
||||
AndroidDAOFactory.beginTransaction();
|
||||
status = daoFactory.getMobileDeviceDAO().addMobileDevice(mobileDevice);
|
||||
AndroidDAOFactory.commitTransaction();
|
||||
}
|
||||
} catch (MobileDeviceManagementDAOException e) {
|
||||
try {
|
||||
AndroidDAOFactory.rollbackTransaction();
|
||||
} catch (MobileDeviceManagementDAOException mobileDAOEx) {
|
||||
String msg = "Error occurred while roll back the device enrol transaction :" + device.toString();
|
||||
log.warn(msg, mobileDAOEx);
|
||||
}
|
||||
String msg = "Error occurred while enrolling the Android device : " + device.getDeviceIdentifier();
|
||||
throw new DeviceManagementException(msg, e);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean modifyEnrollment(Device device) throws DeviceManagementException {
|
||||
boolean status;
|
||||
MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device);
|
||||
try {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Modifying the Android device enrollment data");
|
||||
}
|
||||
AndroidDAOFactory.beginTransaction();
|
||||
status = daoFactory.getMobileDeviceDAO().updateMobileDevice(mobileDevice);
|
||||
AndroidDAOFactory.commitTransaction();
|
||||
} catch (MobileDeviceManagementDAOException e) {
|
||||
try {
|
||||
AndroidDAOFactory.rollbackTransaction();
|
||||
} catch (MobileDeviceManagementDAOException mobileDAOEx) {
|
||||
String msg = "Error occurred while roll back the update device transaction :" + device.toString();
|
||||
log.warn(msg, mobileDAOEx);
|
||||
}
|
||||
String msg = "Error occurred while updating the enrollment of the Android device : " +
|
||||
device.getDeviceIdentifier();
|
||||
throw new DeviceManagementException(msg, e);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
|
||||
//Here we don't have anything specific to do. Hence returning.
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException {
|
||||
boolean isEnrolled = false;
|
||||
try {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Checking the enrollment of Android device : " + deviceId.getId());
|
||||
}
|
||||
MobileDevice mobileDevice =
|
||||
daoFactory.getMobileDeviceDAO().getMobileDevice(deviceId.getId());
|
||||
if (mobileDevice != null) {
|
||||
isEnrolled = true;
|
||||
}
|
||||
} catch (MobileDeviceManagementDAOException e) {
|
||||
String msg = "Error occurred while checking the enrollment status of Android device : " + deviceId.getId();
|
||||
throw new DeviceManagementException(msg, e);
|
||||
}
|
||||
return isEnrolled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setActive(DeviceIdentifier deviceId, boolean status)
|
||||
throws DeviceManagementException {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
|
||||
Device device;
|
||||
try {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Getting the details of Android device : '" + deviceId.getId() + "'");
|
||||
}
|
||||
MobileDevice mobileDevice = daoFactory.getMobileDeviceDAO().
|
||||
getMobileDevice(deviceId.getId());
|
||||
device = MobileDeviceManagementUtil.convertToDevice(mobileDevice);
|
||||
} catch (MobileDeviceManagementDAOException e) {
|
||||
throw new DeviceManagementException(
|
||||
"Error occurred while fetching the Android device: '" + deviceId.getId() + "'", e);
|
||||
}
|
||||
return device;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType)
|
||||
throws DeviceManagementException {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isClaimable(DeviceIdentifier deviceIdentifier) throws DeviceManagementException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setStatus(DeviceIdentifier deviceIdentifier, String currentUser,
|
||||
EnrolmentInfo.Status status) throws DeviceManagementException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public License getLicense(String languageCode) throws LicenseManagementException {
|
||||
return licenseManager.
|
||||
getLicense(AndroidDeviceManagementService.DEVICE_TYPE_ANDROID, languageCode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addLicense(License license) throws LicenseManagementException {
|
||||
licenseManager.addLicense(AndroidDeviceManagementService.DEVICE_TYPE_ANDROID, license);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean requireDeviceAuthorization() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateDeviceInfo(DeviceIdentifier deviceIdentifier, Device device)
|
||||
throws DeviceManagementException {
|
||||
boolean status;
|
||||
Device existingDevice = this.getDevice(deviceIdentifier);
|
||||
// This object holds the current persisted device object
|
||||
MobileDevice existingMobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(existingDevice);
|
||||
// This object holds the newly received device object from response
|
||||
MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device);
|
||||
// Updating current object features using newer ones
|
||||
existingMobileDevice.setLatitude(mobileDevice.getLatitude());
|
||||
existingMobileDevice.setLongitude(mobileDevice.getLongitude());
|
||||
existingMobileDevice.setDeviceProperties(mobileDevice.getDeviceProperties());
|
||||
|
||||
try {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug(
|
||||
"updating the details of Android device : " + device.getDeviceIdentifier());
|
||||
}
|
||||
AndroidDAOFactory.beginTransaction();
|
||||
status = daoFactory.getMobileDeviceDAO().updateMobileDevice(existingMobileDevice);
|
||||
AndroidDAOFactory.commitTransaction();
|
||||
} catch (MobileDeviceManagementDAOException e) {
|
||||
try {
|
||||
AndroidDAOFactory.rollbackTransaction();
|
||||
} catch (MobileDeviceManagementDAOException e1) {
|
||||
log.warn("Error occurred while roll back the update device info transaction : '" +
|
||||
device.toString() + "'", e1);
|
||||
}
|
||||
throw new DeviceManagementException(
|
||||
"Error occurred while updating the Android device: '" + device.getDeviceIdentifier() + "'", e);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Device> getAllDevices() throws DeviceManagementException {
|
||||
List<Device> devices = null;
|
||||
try {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Fetching the details of all Android devices");
|
||||
}
|
||||
List<MobileDevice> mobileDevices =
|
||||
daoFactory.getMobileDeviceDAO().getAllMobileDevices();
|
||||
if (mobileDevices != null) {
|
||||
devices = new ArrayList<>(mobileDevices.size());
|
||||
for (MobileDevice mobileDevice : mobileDevices) {
|
||||
devices.add(MobileDeviceManagementUtil.convertToDevice(mobileDevice));
|
||||
}
|
||||
}
|
||||
} catch (MobileDeviceManagementDAOException e) {
|
||||
throw new DeviceManagementException("Error occurred while fetching all Android devices", e);
|
||||
}
|
||||
return devices;
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,296 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
package org.wso2.carbon.device.mgt.mobile.impl.android;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
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.mobile.dao.AbstractMobileDeviceManagementDAOFactory;
|
||||
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException;
|
||||
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOFactory;
|
||||
import org.wso2.carbon.device.mgt.mobile.dao.MobileFeatureDAO;
|
||||
import org.wso2.carbon.device.mgt.mobile.dto.MobileFeature;
|
||||
import org.wso2.carbon.device.mgt.mobile.impl.android.dao.AndroidDAOFactory;
|
||||
import org.wso2.carbon.device.mgt.mobile.util.MobileDeviceManagementUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class AndroidFeatureManager implements FeatureManager {
|
||||
|
||||
private MobileFeatureDAO featureDAO;
|
||||
private static final Log log = LogFactory.getLog(AndroidFeatureManager.class);
|
||||
|
||||
public AndroidFeatureManager() {
|
||||
MobileDeviceManagementDAOFactory daoFactory = new AndroidDAOFactory();
|
||||
this.featureDAO = daoFactory.getMobileFeatureDAO();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addFeature(Feature feature) throws DeviceManagementException {
|
||||
try {
|
||||
AndroidDAOFactory.beginTransaction();
|
||||
MobileFeature mobileFeature = MobileDeviceManagementUtil.convertToMobileFeature(feature);
|
||||
featureDAO.addFeature(mobileFeature);
|
||||
AndroidDAOFactory.commitTransaction();
|
||||
return true;
|
||||
} catch (MobileDeviceManagementDAOException e) {
|
||||
try {
|
||||
AndroidDAOFactory.rollbackTransaction();
|
||||
} catch (MobileDeviceManagementDAOException e1) {
|
||||
log.warn("Error occurred while roll-backing the transaction", e);
|
||||
}
|
||||
throw new DeviceManagementException("Error occurred while adding the feature", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addFeatures(List<Feature> features) throws DeviceManagementException {
|
||||
List<MobileFeature> mobileFeatures = new ArrayList<MobileFeature>(features.size());
|
||||
for (Feature feature : features) {
|
||||
mobileFeatures.add(MobileDeviceManagementUtil.convertToMobileFeature(feature));
|
||||
}
|
||||
try {
|
||||
AndroidDAOFactory.beginTransaction();
|
||||
featureDAO.addFeatures(mobileFeatures);
|
||||
AndroidDAOFactory.commitTransaction();
|
||||
return true;
|
||||
} catch (MobileDeviceManagementDAOException e) {
|
||||
try {
|
||||
AndroidDAOFactory.rollbackTransaction();
|
||||
} catch (MobileDeviceManagementDAOException e1) {
|
||||
log.warn("Error occurred while roll-backing the transaction", e);
|
||||
}
|
||||
throw new DeviceManagementException("Error occurred while adding the features", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Feature getFeature(String name) throws DeviceManagementException {
|
||||
try {
|
||||
MobileFeature mobileFeature = featureDAO.getFeatureByCode(name);
|
||||
Feature feature = MobileDeviceManagementUtil.convertToFeature(mobileFeature);
|
||||
return feature;
|
||||
} catch (MobileDeviceManagementDAOException e) {
|
||||
throw new DeviceManagementException("Error occurred while retrieving the feature", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Feature> getFeatures() throws DeviceManagementException {
|
||||
try {
|
||||
List<MobileFeature> mobileFeatures = featureDAO.getAllFeatures();
|
||||
List<Feature> featureList = new ArrayList<Feature>(mobileFeatures.size());
|
||||
for (MobileFeature mobileFeature : mobileFeatures) {
|
||||
featureList.add(MobileDeviceManagementUtil.convertToFeature(mobileFeature));
|
||||
}
|
||||
return featureList;
|
||||
} catch (MobileDeviceManagementDAOException e) {
|
||||
throw new DeviceManagementException("Error occurred while retrieving the list of features registered for " +
|
||||
"Android platform", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeFeature(String code) throws DeviceManagementException {
|
||||
boolean status;
|
||||
try {
|
||||
AndroidDAOFactory.beginTransaction();
|
||||
featureDAO.deleteFeatureByCode(code);
|
||||
AndroidDAOFactory.commitTransaction();
|
||||
status = true;
|
||||
} catch (MobileDeviceManagementDAOException e) {
|
||||
try {
|
||||
AndroidDAOFactory.rollbackTransaction();
|
||||
} catch (MobileDeviceManagementDAOException e1) {
|
||||
log.warn("Error occurred while roll-backing the transaction", e);
|
||||
}
|
||||
throw new DeviceManagementException("Error occurred while removing the feature", e);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addSupportedFeaturesToDB() throws DeviceManagementException {
|
||||
synchronized (this) {
|
||||
List<Feature> supportedFeatures = getSupportedFeatures();
|
||||
List<Feature> existingFeatures = this.getFeatures();
|
||||
List<Feature> missingFeatures = MobileDeviceManagementUtil.
|
||||
getMissingFeatures(supportedFeatures, existingFeatures);
|
||||
if (missingFeatures.size() > 0) {
|
||||
return this.addFeatures(missingFeatures);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
//Get the supported feature list.
|
||||
private static List<Feature> getSupportedFeatures() {
|
||||
List<Feature> supportedFeatures = new ArrayList<Feature>();
|
||||
|
||||
Feature feature = new Feature();
|
||||
feature.setCode("DEVICE_LOCK");
|
||||
feature.setName("Device Lock");
|
||||
feature.setDescription("Lock the device");
|
||||
supportedFeatures.add(feature);
|
||||
|
||||
feature = new Feature();
|
||||
feature.setCode("DEVICE_UNLOCK");
|
||||
feature.setName("Device Unlock");
|
||||
feature.setDescription("Unlock the device");
|
||||
supportedFeatures.add(feature);
|
||||
|
||||
feature = new Feature();
|
||||
feature.setCode("DEVICE_LOCATION");
|
||||
feature.setName("Location");
|
||||
feature.setDescription("Request coordinates of device location");
|
||||
supportedFeatures.add(feature);
|
||||
|
||||
feature = new Feature();
|
||||
feature.setCode("WIFI");
|
||||
feature.setName("wifi");
|
||||
feature.setDescription("Setting up wifi configuration");
|
||||
supportedFeatures.add(feature);
|
||||
|
||||
feature = new Feature();
|
||||
feature.setCode("CAMERA");
|
||||
feature.setName("camera");
|
||||
feature.setDescription("Enable or disable camera");
|
||||
supportedFeatures.add(feature);
|
||||
|
||||
feature = new Feature();
|
||||
feature.setCode("EMAIL");
|
||||
feature.setName("Email");
|
||||
feature.setDescription("Configure email settings");
|
||||
supportedFeatures.add(feature);
|
||||
|
||||
feature = new Feature();
|
||||
feature.setCode("DEVICE_MUTE");
|
||||
feature.setName("Mute");
|
||||
feature.setDescription("Enable mute in the device");
|
||||
supportedFeatures.add(feature);
|
||||
|
||||
feature = new Feature();
|
||||
feature.setCode("DEVICE_INFO");
|
||||
feature.setName("Device info");
|
||||
feature.setDescription("Request device information");
|
||||
supportedFeatures.add(feature);
|
||||
|
||||
feature = new Feature();
|
||||
feature.setCode("ENTERPRISE_WIPE");
|
||||
feature.setName("Enterprise Wipe");
|
||||
feature.setDescription("Remove enterprise applications");
|
||||
supportedFeatures.add(feature);
|
||||
|
||||
feature = new Feature();
|
||||
feature.setCode("CLEAR_PASSWORD");
|
||||
feature.setName("Clear Password");
|
||||
feature.setDescription("Clear current password");
|
||||
supportedFeatures.add(feature);
|
||||
|
||||
feature = new Feature();
|
||||
feature.setCode("WIPE_DATA");
|
||||
feature.setName("Wipe Data");
|
||||
feature.setDescription("Factory reset the device");
|
||||
supportedFeatures.add(feature);
|
||||
|
||||
feature = new Feature();
|
||||
feature.setCode("APPLICATION_LIST");
|
||||
feature.setName("Application List");
|
||||
feature.setDescription("Request list of current installed applications");
|
||||
supportedFeatures.add(feature);
|
||||
|
||||
feature = new Feature();
|
||||
feature.setCode("CHANGE_LOCK_CODE");
|
||||
feature.setName("Change Lock-code");
|
||||
feature.setDescription("Change current lock code");
|
||||
supportedFeatures.add(feature);
|
||||
|
||||
feature = new Feature();
|
||||
feature.setCode("INSTALL_APPLICATION");
|
||||
feature.setName("Install App");
|
||||
feature.setDescription("Install Enterprise or Market application");
|
||||
supportedFeatures.add(feature);
|
||||
|
||||
feature = new Feature();
|
||||
feature.setCode("UPDATE_APPLICATION");
|
||||
feature.setName("Update App");
|
||||
feature.setDescription("Update Enterprise or Market application");
|
||||
supportedFeatures.add(feature);
|
||||
|
||||
feature = new Feature();
|
||||
feature.setCode("UNINSTALL_APPLICATION");
|
||||
feature.setName("Uninstall App");
|
||||
feature.setDescription("Uninstall application");
|
||||
supportedFeatures.add(feature);
|
||||
|
||||
feature = new Feature();
|
||||
feature.setCode("BLACKLIST_APPLICATIONS");
|
||||
feature.setName("Blacklist app");
|
||||
feature.setDescription("Blacklist applications");
|
||||
supportedFeatures.add(feature);
|
||||
|
||||
feature = new Feature();
|
||||
feature.setCode("ENCRYPT_STORAGE");
|
||||
feature.setName("Encrypt storage");
|
||||
feature.setDescription("Encrypt storage");
|
||||
supportedFeatures.add(feature);
|
||||
|
||||
feature = new Feature();
|
||||
feature.setCode("DEVICE_RING");
|
||||
feature.setName("Ring");
|
||||
feature.setDescription("Ring the device");
|
||||
supportedFeatures.add(feature);
|
||||
|
||||
feature = new Feature();
|
||||
feature.setCode("PASSCODE_POLICY");
|
||||
feature.setName("Password Policy");
|
||||
feature.setDescription("Set passcode policy");
|
||||
supportedFeatures.add(feature);
|
||||
|
||||
feature = new Feature();
|
||||
feature.setCode("NOTIFICATION");
|
||||
feature.setName("Message");
|
||||
feature.setDescription("Send message");
|
||||
supportedFeatures.add(feature);
|
||||
|
||||
feature = new Feature();
|
||||
feature.setCode("DEVICE_REBOOT");
|
||||
feature.setName("Reboot");
|
||||
feature.setDescription("Reboot the device");
|
||||
supportedFeatures.add(feature);
|
||||
|
||||
feature = new Feature();
|
||||
feature.setCode("UPGRADE_FIRMWARE");
|
||||
feature.setName("Upgrade Firmware");
|
||||
feature.setDescription("Upgrade Firmware");
|
||||
supportedFeatures.add(feature);
|
||||
|
||||
feature = new Feature();
|
||||
feature.setCode("VPN");
|
||||
feature.setName("Configure VPN");
|
||||
feature.setDescription("Configure VPN settings");
|
||||
supportedFeatures.add(feature);
|
||||
|
||||
return supportedFeatures;
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,100 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
|
||||
package org.wso2.carbon.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.LogFactory;
|
||||
import org.wso2.carbon.device.mgt.common.Device;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
|
||||
import org.wso2.carbon.device.mgt.mobile.impl.android.gcm.GCMService;
|
||||
import org.wso2.carbon.device.mgt.mobile.internal.MobileDeviceManagementDataHolder;
|
||||
import org.wso2.carbon.policy.mgt.common.Policy;
|
||||
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 java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class AndroidPolicyMonitoringService implements PolicyMonitoringService {
|
||||
|
||||
private static Log log = LogFactory.getLog(AndroidPolicyMonitoringService.class);
|
||||
|
||||
@Override
|
||||
public void notifyDevices(List<Device> list) throws PolicyComplianceException {
|
||||
GCMService gcmService = MobileDeviceManagementDataHolder.getInstance().getGCMService();
|
||||
if (gcmService.isGCMEnabled() && !list.isEmpty()) {
|
||||
gcmService.sendNotification("POLICY_BUNDLE", list);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ComplianceData checkPolicyCompliance(DeviceIdentifier deviceIdentifier, Policy policy,
|
||||
Object compliancePayload) throws PolicyComplianceException {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Checking policy compliance status of device '" + deviceIdentifier.getId() + "'");
|
||||
}
|
||||
ComplianceData complianceData = new ComplianceData();
|
||||
if (compliancePayload == null || policy == null) {
|
||||
return complianceData;
|
||||
}
|
||||
String compliancePayloadString = new Gson().toJson(compliancePayload);
|
||||
// Parsing json string to get compliance features.
|
||||
JsonElement jsonElement;
|
||||
if (compliancePayloadString instanceof String) {
|
||||
jsonElement = new JsonParser().parse(compliancePayloadString);
|
||||
} else {
|
||||
throw new PolicyComplianceException("Invalid policy compliance payload");
|
||||
}
|
||||
|
||||
JsonArray jsonArray = jsonElement.getAsJsonArray();
|
||||
Gson gson = new Gson();
|
||||
ComplianceFeature complianceFeature;
|
||||
List<ComplianceFeature> complianceFeatures = new ArrayList<ComplianceFeature>(jsonArray.size());
|
||||
List<ComplianceFeature> nonComplianceFeatures = new ArrayList<>();
|
||||
|
||||
for (JsonElement element : jsonArray) {
|
||||
complianceFeature = gson.fromJson(element, ComplianceFeature.class);
|
||||
complianceFeatures.add(complianceFeature);
|
||||
}
|
||||
|
||||
for (ComplianceFeature cf : complianceFeatures) {
|
||||
if (!cf.isCompliant()) {
|
||||
complianceData.setStatus(false);
|
||||
nonComplianceFeatures.add(cf);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
complianceData.setComplianceFeatures(nonComplianceFeatures);
|
||||
return complianceData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID;
|
||||
}
|
||||
}
|
||||
@ -1,117 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* you may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.impl.android.dao;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
|
||||
import org.wso2.carbon.device.mgt.mobile.dao.*;
|
||||
import org.wso2.carbon.device.mgt.mobile.impl.android.dao.impl.AndroidDeviceDAOImpl;
|
||||
import org.wso2.carbon.device.mgt.mobile.impl.android.dao.impl.AndroidFeatureDAOImpl;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class AndroidDAOFactory extends AbstractMobileDeviceManagementDAOFactory {
|
||||
|
||||
private static final Log log = LogFactory.getLog(AndroidDAOFactory.class);
|
||||
protected static DataSource dataSource;
|
||||
private static ThreadLocal<Connection> currentConnection = new ThreadLocal<>();
|
||||
|
||||
public AndroidDAOFactory() {
|
||||
this.dataSource = getDataSourceMap().get(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MobileDeviceDAO getMobileDeviceDAO() {
|
||||
return new AndroidDeviceDAOImpl();
|
||||
}
|
||||
|
||||
public MobileFeatureDAO getMobileFeatureDAO() {
|
||||
return new AndroidFeatureDAOImpl();
|
||||
}
|
||||
|
||||
public static void beginTransaction() throws MobileDeviceManagementDAOException {
|
||||
try {
|
||||
Connection conn = dataSource.getConnection();
|
||||
conn.setAutoCommit(false);
|
||||
currentConnection.set(conn);
|
||||
} catch (SQLException e) {
|
||||
throw new MobileDeviceManagementDAOException("Error occurred while retrieving datasource connection", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static Connection getConnection() throws MobileDeviceManagementDAOException {
|
||||
if (currentConnection.get() == null) {
|
||||
try {
|
||||
currentConnection.set(dataSource.getConnection());
|
||||
} catch (SQLException e) {
|
||||
throw new MobileDeviceManagementDAOException("Error occurred while retrieving data source connection",
|
||||
e);
|
||||
}
|
||||
}
|
||||
return currentConnection.get();
|
||||
}
|
||||
|
||||
public static void commitTransaction() throws MobileDeviceManagementDAOException {
|
||||
try {
|
||||
Connection conn = currentConnection.get();
|
||||
if (conn != null) {
|
||||
conn.commit();
|
||||
} else {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Datasource connection associated with the current thread is null, hence commit " +
|
||||
"has not been attempted");
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new MobileDeviceManagementDAOException("Error occurred while committing the transaction", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void closeConnection() throws MobileDeviceManagementDAOException {
|
||||
Connection conn = currentConnection.get();
|
||||
try {
|
||||
if (conn != null) {
|
||||
conn.close();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
log.error("Error occurred while close the connection");
|
||||
}
|
||||
currentConnection.remove();
|
||||
}
|
||||
|
||||
public static void rollbackTransaction() throws MobileDeviceManagementDAOException {
|
||||
try {
|
||||
Connection conn = currentConnection.get();
|
||||
if (conn != null) {
|
||||
conn.rollback();
|
||||
} else {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Datasource connection associated with the current thread is null, hence rollback " +
|
||||
"has not been attempted");
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new MobileDeviceManagementDAOException("Error occurred while rollback the transaction", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,79 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
package org.wso2.carbon.device.mgt.mobile.impl.android.dao;
|
||||
|
||||
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException;
|
||||
|
||||
public class AndroidFeatureManagementDAOException extends MobileDeviceManagementDAOException {
|
||||
|
||||
private String message;
|
||||
private static final long serialVersionUID = 2021891706072918865L;
|
||||
|
||||
/**
|
||||
* Constructs a new MobileDeviceManagementDAOException with the specified detail message and
|
||||
* nested exception.
|
||||
*
|
||||
* @param message error message
|
||||
* @param nestedException exception
|
||||
*/
|
||||
public AndroidFeatureManagementDAOException(String message, Exception nestedException) {
|
||||
super(message, nestedException);
|
||||
setErrorMessage(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new MobileDeviceManagementDAOException with the specified detail message
|
||||
* and cause.
|
||||
*
|
||||
* @param message the detail message.
|
||||
* @param cause the cause of this exception.
|
||||
*/
|
||||
public AndroidFeatureManagementDAOException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
setErrorMessage(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new MobileDeviceManagementDAOException with the specified detail message.
|
||||
*
|
||||
* @param message the detail message.
|
||||
*/
|
||||
public AndroidFeatureManagementDAOException(String message) {
|
||||
super(message);
|
||||
setErrorMessage(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new MobileDeviceManagementDAOException with the specified and cause.
|
||||
*
|
||||
* @param cause the cause of this exception.
|
||||
*/
|
||||
public AndroidFeatureManagementDAOException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setErrorMessage(String errorMessage) {
|
||||
this.message = errorMessage;
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,265 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* you may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.impl.android.dao.impl;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceDAO;
|
||||
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException;
|
||||
import org.wso2.carbon.device.mgt.mobile.dao.util.MobileDeviceManagementDAOUtil;
|
||||
import org.wso2.carbon.device.mgt.mobile.dto.MobileDevice;
|
||||
import org.wso2.carbon.device.mgt.mobile.impl.android.dao.AndroidDAOFactory;
|
||||
import org.wso2.carbon.device.mgt.mobile.impl.android.util.AndroidPluginConstants;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Implements MobileDeviceDAO for Android Devices.
|
||||
*/
|
||||
public class AndroidDeviceDAOImpl implements MobileDeviceDAO{
|
||||
|
||||
private static final Log log = LogFactory.getLog(AndroidDeviceDAOImpl.class);
|
||||
|
||||
@Override
|
||||
public MobileDevice getMobileDevice(String mblDeviceId) throws MobileDeviceManagementDAOException {
|
||||
Connection conn;
|
||||
PreparedStatement stmt = null;
|
||||
MobileDevice mobileDevice = null;
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
conn = AndroidDAOFactory.getConnection();
|
||||
String selectDBQuery =
|
||||
"SELECT DEVICE_ID, GCM_TOKEN, DEVICE_INFO, DEVICE_MODEL, SERIAL, " +
|
||||
"VENDOR, MAC_ADDRESS, DEVICE_NAME, LATITUDE, LONGITUDE, IMEI, IMSI, OS_VERSION" +
|
||||
" FROM AD_DEVICE WHERE DEVICE_ID = ?";
|
||||
stmt = conn.prepareStatement(selectDBQuery);
|
||||
stmt.setString(1, mblDeviceId);
|
||||
rs = stmt.executeQuery();
|
||||
|
||||
if (rs.next()) {
|
||||
mobileDevice = new MobileDevice();
|
||||
mobileDevice.setMobileDeviceId(rs.getString(AndroidPluginConstants.DEVICE_ID));
|
||||
mobileDevice.setModel(rs.getString(AndroidPluginConstants.DEVICE_MODEL));
|
||||
mobileDevice.setSerial(rs.getString(AndroidPluginConstants.SERIAL));
|
||||
mobileDevice.setVendor(rs.getString(AndroidPluginConstants.VENDOR));
|
||||
mobileDevice.setLatitude(rs.getString(AndroidPluginConstants.LATITUDE));
|
||||
mobileDevice.setLongitude(rs.getString(AndroidPluginConstants.LONGITUDE));
|
||||
mobileDevice.setImei(rs.getString(AndroidPluginConstants.IMEI));
|
||||
mobileDevice.setImsi(rs.getString(AndroidPluginConstants.IMSI));
|
||||
mobileDevice.setOsVersion(rs.getString(AndroidPluginConstants.OS_VERSION));
|
||||
|
||||
Map<String, String> propertyMap = new HashMap<String, String>();
|
||||
propertyMap.put(AndroidPluginConstants.GCM_TOKEN, rs.getString(AndroidPluginConstants.GCM_TOKEN));
|
||||
propertyMap.put(AndroidPluginConstants.DEVICE_INFO, rs.getString(AndroidPluginConstants.DEVICE_INFO));
|
||||
propertyMap.put(AndroidPluginConstants.DEVICE_NAME, rs.getString(AndroidPluginConstants.DEVICE_NAME));
|
||||
mobileDevice.setDeviceProperties(propertyMap);
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Android device " + mblDeviceId + " data has been fetched from " +
|
||||
"Android database.");
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while fetching Android device : '" + mblDeviceId + "'";
|
||||
log.error(msg, e);
|
||||
throw new MobileDeviceManagementDAOException(msg, e);
|
||||
} finally {
|
||||
MobileDeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
||||
AndroidDAOFactory.closeConnection();
|
||||
}
|
||||
|
||||
return mobileDevice;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addMobileDevice(MobileDevice mobileDevice) throws MobileDeviceManagementDAOException {
|
||||
boolean status = false;
|
||||
Connection conn;
|
||||
PreparedStatement stmt = null;
|
||||
try {
|
||||
conn = AndroidDAOFactory.getConnection();
|
||||
String createDBQuery =
|
||||
"INSERT INTO AD_DEVICE(DEVICE_ID, GCM_TOKEN, DEVICE_INFO, SERIAL, " +
|
||||
"VENDOR, MAC_ADDRESS, DEVICE_NAME, LATITUDE, LONGITUDE, IMEI, IMSI, " +
|
||||
"OS_VERSION, DEVICE_MODEL) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
||||
|
||||
stmt = conn.prepareStatement(createDBQuery);
|
||||
stmt.setString(1, mobileDevice.getMobileDeviceId());
|
||||
|
||||
Map<String, String> properties = mobileDevice.getDeviceProperties();
|
||||
stmt.setString(2, properties.get(AndroidPluginConstants.GCM_TOKEN));
|
||||
stmt.setString(3, properties.get(AndroidPluginConstants.DEVICE_INFO));
|
||||
stmt.setString(4, mobileDevice.getSerial());
|
||||
stmt.setString(5, mobileDevice.getVendor());
|
||||
stmt.setString(6, mobileDevice.getMobileDeviceId());
|
||||
stmt.setString(7, properties.get(AndroidPluginConstants.DEVICE_NAME));
|
||||
stmt.setString(8, mobileDevice.getLatitude());
|
||||
stmt.setString(9, mobileDevice.getLongitude());
|
||||
stmt.setString(10, mobileDevice.getImei());
|
||||
stmt.setString(11, mobileDevice.getImsi());
|
||||
stmt.setString(12, mobileDevice.getOsVersion());
|
||||
stmt.setString(13, mobileDevice.getModel());
|
||||
int rows = stmt.executeUpdate();
|
||||
if (rows > 0) {
|
||||
status = true;
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Android device " + mobileDevice.getMobileDeviceId() + " data has been" +
|
||||
" added to the Android database.");
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new MobileDeviceManagementDAOException("Error occurred while adding the Android device '" +
|
||||
mobileDevice.getMobileDeviceId() + "' information to the Android plugin data store.", e);
|
||||
} finally {
|
||||
MobileDeviceManagementDAOUtil.cleanupResources(stmt, null);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateMobileDevice(MobileDevice mobileDevice) throws MobileDeviceManagementDAOException {
|
||||
boolean status = false;
|
||||
Connection conn;
|
||||
PreparedStatement stmt = null;
|
||||
try {
|
||||
conn = AndroidDAOFactory.getConnection();
|
||||
String updateDBQuery =
|
||||
"UPDATE AD_DEVICE SET GCM_TOKEN = ?, DEVICE_INFO = ?, SERIAL = ?, VENDOR = ?, " +
|
||||
"MAC_ADDRESS = ?, DEVICE_NAME = ?, LATITUDE = ?, LONGITUDE = ?, IMEI = ?, " +
|
||||
"IMSI = ?, OS_VERSION = ?, DEVICE_MODEL = ? WHERE DEVICE_ID = ?";
|
||||
stmt = conn.prepareStatement(updateDBQuery);
|
||||
|
||||
Map<String, String> properties = mobileDevice.getDeviceProperties();
|
||||
stmt.setString(1, properties.get(AndroidPluginConstants.GCM_TOKEN));
|
||||
stmt.setString(2, properties.get(AndroidPluginConstants.DEVICE_INFO));
|
||||
stmt.setString(3, mobileDevice.getSerial());
|
||||
stmt.setString(4, mobileDevice.getVendor());
|
||||
stmt.setString(5, mobileDevice.getMobileDeviceId());
|
||||
stmt.setString(6, properties.get(AndroidPluginConstants.DEVICE_NAME));
|
||||
stmt.setString(7, mobileDevice.getLatitude());
|
||||
stmt.setString(8, mobileDevice.getLongitude());
|
||||
stmt.setString(9, mobileDevice.getImei());
|
||||
stmt.setString(10, mobileDevice.getImsi());
|
||||
stmt.setString(11, mobileDevice.getOsVersion());
|
||||
stmt.setString(12, mobileDevice.getModel());
|
||||
stmt.setString(13, mobileDevice.getMobileDeviceId());
|
||||
int rows = stmt.executeUpdate();
|
||||
if (rows > 0) {
|
||||
status = true;
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Android device " + mobileDevice.getMobileDeviceId() + " data has been" +
|
||||
" modified.");
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while modifying the Android device '" +
|
||||
mobileDevice.getMobileDeviceId() + "' data.";
|
||||
log.error(msg, e);
|
||||
throw new MobileDeviceManagementDAOException(msg, e);
|
||||
} finally {
|
||||
MobileDeviceManagementDAOUtil.cleanupResources(stmt, null);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteMobileDevice(String mblDeviceId)
|
||||
throws MobileDeviceManagementDAOException {
|
||||
boolean status = false;
|
||||
Connection conn;
|
||||
PreparedStatement stmt = null;
|
||||
try {
|
||||
conn = AndroidDAOFactory.getConnection();
|
||||
String deleteDBQuery =
|
||||
"DELETE FROM AD_DEVICE WHERE DEVICE_ID = ?";
|
||||
stmt = conn.prepareStatement(deleteDBQuery);
|
||||
stmt.setString(1, mblDeviceId);
|
||||
int rows = stmt.executeUpdate();
|
||||
if (rows > 0) {
|
||||
status = true;
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Android device " + mblDeviceId + " data has deleted" +
|
||||
" from the Android database.");
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new MobileDeviceManagementDAOException("Error occurred while deleting android device '" +
|
||||
mblDeviceId + "'", e);
|
||||
} finally {
|
||||
MobileDeviceManagementDAOUtil.cleanupResources(stmt, null);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MobileDevice> getAllMobileDevices() throws MobileDeviceManagementDAOException {
|
||||
Connection conn;
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
MobileDevice mobileDevice;
|
||||
List<MobileDevice> mobileDevices = new ArrayList<MobileDevice>();
|
||||
try {
|
||||
conn = AndroidDAOFactory.getConnection();
|
||||
String selectDBQuery =
|
||||
"SELECT DEVICE_ID, GCM_TOKEN, DEVICE_INFO, DEVICE_MODEL, SERIAL, " +
|
||||
"VENDOR, MAC_ADDRESS, DEVICE_NAME, LATITUDE, LONGITUDE, IMEI, IMSI, OS_VERSION " +
|
||||
"FROM AD_DEVICE";
|
||||
stmt = conn.prepareStatement(selectDBQuery);
|
||||
rs = stmt.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
mobileDevice = new MobileDevice();
|
||||
mobileDevice.setMobileDeviceId(rs.getString(AndroidPluginConstants.DEVICE_ID));
|
||||
mobileDevice.setModel(rs.getString(AndroidPluginConstants.DEVICE_MODEL));
|
||||
mobileDevice.setSerial(rs.getString(AndroidPluginConstants.SERIAL));
|
||||
mobileDevice.setVendor(rs.getString(AndroidPluginConstants.VENDOR));
|
||||
mobileDevice.setLatitude(rs.getString(AndroidPluginConstants.LATITUDE));
|
||||
mobileDevice.setLongitude(rs.getString(AndroidPluginConstants.LONGITUDE));
|
||||
mobileDevice.setImei(rs.getString(AndroidPluginConstants.IMEI));
|
||||
mobileDevice.setImsi(rs.getString(AndroidPluginConstants.IMSI));
|
||||
mobileDevice.setOsVersion(rs.getString(AndroidPluginConstants.OS_VERSION));
|
||||
|
||||
Map<String, String> propertyMap = new HashMap<>();
|
||||
propertyMap.put(AndroidPluginConstants.GCM_TOKEN, rs.getString(AndroidPluginConstants.GCM_TOKEN));
|
||||
propertyMap.put(AndroidPluginConstants.DEVICE_INFO, rs.getString(AndroidPluginConstants.DEVICE_INFO));
|
||||
propertyMap.put(AndroidPluginConstants.DEVICE_NAME, rs.getString(AndroidPluginConstants.DEVICE_NAME));
|
||||
mobileDevice.setDeviceProperties(propertyMap);
|
||||
|
||||
mobileDevices.add(mobileDevice);
|
||||
}
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("All Android device details have fetched from Android database.");
|
||||
}
|
||||
return mobileDevices;
|
||||
} catch (SQLException e) {
|
||||
throw new MobileDeviceManagementDAOException("Error occurred while fetching all Android device data", e);
|
||||
} finally {
|
||||
MobileDeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
||||
AndroidDAOFactory.closeConnection();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,285 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
package org.wso2.carbon.device.mgt.mobile.impl.android.dao.impl;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
|
||||
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException;
|
||||
import org.wso2.carbon.device.mgt.mobile.dao.MobileFeatureDAO;
|
||||
import org.wso2.carbon.device.mgt.mobile.dao.util.MobileDeviceManagementDAOUtil;
|
||||
import org.wso2.carbon.device.mgt.mobile.dto.MobileFeature;
|
||||
import org.wso2.carbon.device.mgt.mobile.impl.android.dao.AndroidDAOFactory;
|
||||
import org.wso2.carbon.device.mgt.mobile.impl.android.dao.AndroidFeatureManagementDAOException;
|
||||
import org.wso2.carbon.device.mgt.mobile.impl.android.util.AndroidPluginConstants;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class AndroidFeatureDAOImpl implements MobileFeatureDAO {
|
||||
|
||||
private static final Log log = LogFactory.getLog(AndroidFeatureDAOImpl.class);
|
||||
|
||||
public AndroidFeatureDAOImpl() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addFeature(MobileFeature mobileFeature) throws MobileDeviceManagementDAOException {
|
||||
PreparedStatement stmt = null;
|
||||
boolean status = false;
|
||||
Connection conn;
|
||||
try {
|
||||
conn = AndroidDAOFactory.getConnection();
|
||||
String sql = "INSERT INTO AD_FEATURE(CODE, NAME, DESCRIPTION) VALUES (?, ?, ?)";
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setString(1, mobileFeature.getCode());
|
||||
stmt.setString(2, mobileFeature.getName());
|
||||
stmt.setString(3, mobileFeature.getDescription());
|
||||
stmt.executeUpdate();
|
||||
status = true;
|
||||
} catch (SQLException e) {
|
||||
throw new AndroidFeatureManagementDAOException(
|
||||
"Error occurred while adding android feature '" +
|
||||
mobileFeature.getName() + "' into the metadata repository", e);
|
||||
} finally {
|
||||
MobileDeviceManagementDAOUtil.cleanupResources(stmt, null);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addFeatures(List<MobileFeature> mobileFeatures) throws MobileDeviceManagementDAOException {
|
||||
PreparedStatement stmt = null;
|
||||
MobileFeature mobileFeature;
|
||||
boolean status = false;
|
||||
Connection conn;
|
||||
try {
|
||||
conn = AndroidDAOFactory.getConnection();
|
||||
stmt = conn.prepareStatement("INSERT INTO AD_FEATURE(CODE, NAME, DESCRIPTION) VALUES (?, ?, ?)");
|
||||
for (int i = 0; i < mobileFeatures.size(); i++) {
|
||||
mobileFeature = mobileFeatures.get(i);
|
||||
stmt.setString(1, mobileFeature.getCode());
|
||||
stmt.setString(2, mobileFeature.getName());
|
||||
stmt.setString(3, mobileFeature.getDescription());
|
||||
stmt.addBatch();
|
||||
}
|
||||
stmt.executeBatch();
|
||||
status = true;
|
||||
} catch (SQLException e) {
|
||||
throw new AndroidFeatureManagementDAOException(
|
||||
"Error occurred while adding android features into the metadata repository", e);
|
||||
} finally {
|
||||
MobileDeviceManagementDAOUtil.cleanupResources(stmt, null);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateFeature(MobileFeature mobileFeature) throws MobileDeviceManagementDAOException {
|
||||
boolean status = false;
|
||||
Connection conn;
|
||||
PreparedStatement stmt = null;
|
||||
try {
|
||||
conn = AndroidDAOFactory.getConnection();
|
||||
String updateDBQuery =
|
||||
"UPDATE AD_FEATURE SET NAME = ?, DESCRIPTION = ?" +
|
||||
"WHERE CODE = ?";
|
||||
|
||||
stmt = conn.prepareStatement(updateDBQuery);
|
||||
stmt.setString(1, mobileFeature.getName());
|
||||
stmt.setString(2, mobileFeature.getDescription());
|
||||
stmt.setString(3, mobileFeature.getCode());
|
||||
|
||||
int rows = stmt.executeUpdate();
|
||||
if (rows > 0) {
|
||||
status = true;
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Android Feature " + mobileFeature.getCode() + " data has been " +
|
||||
"modified.");
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while updating the Android Feature '" +
|
||||
mobileFeature.getCode() + "' to the Android db.";
|
||||
log.error(msg, e);
|
||||
throw new AndroidFeatureManagementDAOException(msg, e);
|
||||
} finally {
|
||||
MobileDeviceManagementDAOUtil.cleanupResources(stmt, null);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteFeatureById(int mblFeatureId) throws MobileDeviceManagementDAOException {
|
||||
|
||||
PreparedStatement stmt = null;
|
||||
boolean status = false;
|
||||
Connection conn;
|
||||
try {
|
||||
conn = AndroidDAOFactory.getConnection();
|
||||
String sql = "DELETE FROM AD_FEATURE WHERE ID = ?";
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setInt(1, mblFeatureId);
|
||||
stmt.execute();
|
||||
status = true;
|
||||
} catch (SQLException e) {
|
||||
throw new AndroidFeatureManagementDAOException(
|
||||
"Error occurred while deleting android feature '" +
|
||||
mblFeatureId + "' from Android database.", e);
|
||||
} finally {
|
||||
MobileDeviceManagementDAOUtil.cleanupResources(stmt, null);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteFeatureByCode(String mblFeatureCode) throws MobileDeviceManagementDAOException {
|
||||
PreparedStatement stmt = null;
|
||||
boolean status = false;
|
||||
Connection conn;
|
||||
try {
|
||||
conn = AndroidDAOFactory.getConnection();
|
||||
String sql = "DELETE FROM AD_FEATURE WHERE CODE = ?";
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setString(1, mblFeatureCode);
|
||||
stmt.execute();
|
||||
status = true;
|
||||
} catch (SQLException e) {
|
||||
throw new AndroidFeatureManagementDAOException(
|
||||
"Error occurred while deleting android feature '" +
|
||||
mblFeatureCode + "' from Android database.", e);
|
||||
} finally {
|
||||
MobileDeviceManagementDAOUtil.cleanupResources(stmt, null);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MobileFeature getFeatureById(int mblFeatureId) throws MobileDeviceManagementDAOException {
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
Connection conn;
|
||||
try {
|
||||
conn = AndroidDAOFactory.getConnection();
|
||||
String sql = "SELECT ID, CODE, NAME, DESCRIPTION FROM AD_FEATURE WHERE ID = ?";
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setInt(1, mblFeatureId);
|
||||
rs = stmt.executeQuery();
|
||||
|
||||
MobileFeature mobileFeature = null;
|
||||
if (rs.next()) {
|
||||
mobileFeature = new MobileFeature();
|
||||
mobileFeature.setId(rs.getInt(AndroidPluginConstants.ANDROID_FEATURE_ID));
|
||||
mobileFeature.setCode(rs.getString(AndroidPluginConstants.ANDROID_FEATURE_CODE));
|
||||
mobileFeature.setName(rs.getString(AndroidPluginConstants.ANDROID_FEATURE_NAME));
|
||||
mobileFeature.setDescription(rs.getString(AndroidPluginConstants.
|
||||
ANDROID_FEATURE_DESCRIPTION));
|
||||
mobileFeature.setDeviceType(
|
||||
DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
|
||||
}
|
||||
return mobileFeature;
|
||||
} catch (SQLException e) {
|
||||
throw new AndroidFeatureManagementDAOException(
|
||||
"Error occurred while retrieving android feature '" +
|
||||
mblFeatureId + "' from the Android database.", e);
|
||||
} finally {
|
||||
MobileDeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
||||
AndroidDAOFactory.closeConnection();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public MobileFeature getFeatureByCode(String mblFeatureCode) throws MobileDeviceManagementDAOException {
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
Connection conn;
|
||||
|
||||
try {
|
||||
conn = AndroidDAOFactory.getConnection();
|
||||
String sql = "SELECT ID, CODE, NAME, DESCRIPTION FROM AD_FEATURE WHERE CODE = ?";
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setString(1, mblFeatureCode);
|
||||
rs = stmt.executeQuery();
|
||||
|
||||
MobileFeature mobileFeature = null;
|
||||
if (rs.next()) {
|
||||
mobileFeature = new MobileFeature();
|
||||
mobileFeature.setId(rs.getInt(AndroidPluginConstants.ANDROID_FEATURE_ID));
|
||||
mobileFeature.setCode(rs.getString(AndroidPluginConstants.ANDROID_FEATURE_CODE));
|
||||
mobileFeature.setName(rs.getString(AndroidPluginConstants.ANDROID_FEATURE_NAME));
|
||||
mobileFeature.setDescription(rs.getString(AndroidPluginConstants.
|
||||
ANDROID_FEATURE_DESCRIPTION));
|
||||
mobileFeature.setDeviceType(
|
||||
DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
|
||||
}
|
||||
return mobileFeature;
|
||||
} catch (SQLException e) {
|
||||
throw new AndroidFeatureManagementDAOException(
|
||||
"Error occurred while retrieving android feature '" +
|
||||
mblFeatureCode + "' from the Android database.", e);
|
||||
} finally {
|
||||
MobileDeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
||||
AndroidDAOFactory.closeConnection();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MobileFeature> getFeatureByDeviceType(String deviceType)
|
||||
throws MobileDeviceManagementDAOException {
|
||||
return this.getAllFeatures();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MobileFeature> getAllFeatures() throws MobileDeviceManagementDAOException {
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
Connection conn = null;
|
||||
List<MobileFeature> features = new ArrayList<>();
|
||||
try {
|
||||
conn = AndroidDAOFactory.getConnection();
|
||||
String sql = "SELECT ID, CODE, NAME, DESCRIPTION FROM AD_FEATURE";
|
||||
stmt = conn.prepareStatement(sql);
|
||||
rs = stmt.executeQuery();
|
||||
MobileFeature mobileFeature = null;
|
||||
|
||||
while (rs.next()) {
|
||||
mobileFeature = new MobileFeature();
|
||||
mobileFeature.setId(rs.getInt(AndroidPluginConstants.ANDROID_FEATURE_ID));
|
||||
mobileFeature.setCode(rs.getString(AndroidPluginConstants.ANDROID_FEATURE_CODE));
|
||||
mobileFeature.setName(rs.getString(AndroidPluginConstants.ANDROID_FEATURE_NAME));
|
||||
mobileFeature.setDescription(rs.getString(AndroidPluginConstants.ANDROID_FEATURE_DESCRIPTION));
|
||||
mobileFeature.setDeviceType(
|
||||
DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
|
||||
features.add(mobileFeature);
|
||||
}
|
||||
return features;
|
||||
} catch (SQLException e) {
|
||||
throw new AndroidFeatureManagementDAOException("Error occurred while retrieving all " +
|
||||
"android features from the android database.", e);
|
||||
} finally {
|
||||
MobileDeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
||||
AndroidDAOFactory.closeConnection();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,53 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* you may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.impl.android.gcm;
|
||||
|
||||
/**
|
||||
* Represents model object for holding GCM response data.
|
||||
*/
|
||||
public class GCMResult {
|
||||
|
||||
private String errorMsg;
|
||||
private String msg;
|
||||
private int statusCode;
|
||||
|
||||
public String getErrorMsg() {
|
||||
return errorMsg;
|
||||
}
|
||||
|
||||
public void setErrorMsg(String errorMsg) {
|
||||
this.errorMsg = errorMsg;
|
||||
}
|
||||
|
||||
public String getMsg() {
|
||||
return msg;
|
||||
}
|
||||
|
||||
public void setMsg(String msg) {
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
public int getStatusCode() {
|
||||
return statusCode;
|
||||
}
|
||||
|
||||
public void setStatusCode(int statusCode) {
|
||||
this.statusCode = statusCode;
|
||||
}
|
||||
}
|
||||
@ -1,64 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* you may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.impl.android.gcm;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.device.mgt.common.Device;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* GCM notification service implementation for Android platform.
|
||||
*/
|
||||
public class GCMService {
|
||||
|
||||
private static final Log log = LogFactory.getLog(GCMService.class);
|
||||
private static final String NOTIFIER_TYPE = "notifierType";
|
||||
private static final String GCM_NOTIFIER_CODE = "2";
|
||||
|
||||
public boolean isGCMEnabled() {
|
||||
String notifierType = GCMUtil.getConfigurationProperty(NOTIFIER_TYPE);
|
||||
if (GCM_NOTIFIER_CODE.equals(notifierType)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void sendNotification(String messageData, Device device) {
|
||||
List<Device> devices = new ArrayList<>(1);
|
||||
devices.add(device);
|
||||
GCMResult result = GCMUtil.sendWakeUpCall(messageData, devices);
|
||||
if (result.getStatusCode() != 200) {
|
||||
log.error("Exception occurred while sending the GCM notification : " + result.getErrorMsg());
|
||||
}
|
||||
}
|
||||
|
||||
public void sendNotification(String messageData, List<Device> devices) {
|
||||
GCMResult result = GCMUtil.sendWakeUpCall(messageData, devices);
|
||||
if (result.getStatusCode() != 200) {
|
||||
log.error("Exception occurred while sending the GCM notification : " + result.getErrorMsg());
|
||||
}
|
||||
}
|
||||
|
||||
public void resetTenantConfigCache() {
|
||||
GCMUtil.resetTenantConfigCache();
|
||||
}
|
||||
}
|
||||
@ -1,198 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* you may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.impl.android.gcm;
|
||||
|
||||
import com.google.gson.*;
|
||||
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.DeviceManagementException;
|
||||
import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationEntry;
|
||||
import org.wso2.carbon.device.mgt.common.configuration.mgt.TenantConfiguration;
|
||||
import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
|
||||
import org.wso2.carbon.device.mgt.mobile.impl.android.util.AndroidPluginConstants;
|
||||
import org.wso2.carbon.device.mgt.mobile.internal.MobileDeviceManagementDataHolder;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.ProtocolException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Implements utility methods used by GCMService.
|
||||
*/
|
||||
public class GCMUtil {
|
||||
|
||||
private static final Log log = LogFactory.getLog(GCMService.class);
|
||||
|
||||
private final static String GCM_ENDPOINT = "https://gcm-http.googleapis.com/gcm/send";
|
||||
private static final String GCM_API_KEY = "gcmAPIKey";
|
||||
private static final int TIME_TO_LIVE = 60;
|
||||
private static final int HTTP_STATUS_CODE_OK = 200;
|
||||
|
||||
private static HashMap<Integer,TenantConfiguration> tenantConfigurationCache = new HashMap<>();
|
||||
|
||||
public static GCMResult sendWakeUpCall(String message, List<Device> devices) {
|
||||
GCMResult result = new GCMResult();
|
||||
|
||||
byte[] bytes = getGCMRequest(message, getGCMTokens(devices)).getBytes();
|
||||
HttpURLConnection conn;
|
||||
try {
|
||||
conn = (HttpURLConnection) (new URL(GCM_ENDPOINT)).openConnection();
|
||||
conn.setDoOutput(true);
|
||||
conn.setUseCaches(false);
|
||||
conn.setFixedLengthStreamingMode(bytes.length);
|
||||
conn.setRequestMethod("POST");
|
||||
conn.setRequestProperty("Content-Type", "application/json");
|
||||
conn.setRequestProperty("Authorization", "key=" + getConfigurationProperty(GCM_API_KEY));
|
||||
|
||||
OutputStream out = conn.getOutputStream();
|
||||
out.write(bytes);
|
||||
out.close();
|
||||
|
||||
int status = conn.getResponseCode();
|
||||
result.setStatusCode(status);
|
||||
if (status != HTTP_STATUS_CODE_OK) {
|
||||
result.setErrorMsg(getString(conn.getErrorStream()));
|
||||
} else {
|
||||
result.setMsg(getString(conn.getInputStream()));
|
||||
}
|
||||
} catch (ProtocolException e) {
|
||||
log.error("Exception occurred while setting the HTTP protocol.", e);
|
||||
} catch (IOException ex) {
|
||||
log.error("Exception occurred while sending the GCM request.", ex);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static String getString(InputStream stream) throws IOException {
|
||||
if (stream != null) {
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
|
||||
StringBuilder content = new StringBuilder();
|
||||
|
||||
String newLine;
|
||||
do {
|
||||
newLine = reader.readLine();
|
||||
if (newLine != null) {
|
||||
content.append(newLine).append('\n');
|
||||
}
|
||||
} while (newLine != null);
|
||||
|
||||
if (content.length() > 0) {
|
||||
content.setLength(content.length() - 1);
|
||||
}
|
||||
|
||||
return content.toString();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static String getGCMRequest(String message, List<String> registrationIds) {
|
||||
JsonObject gcmRequest = new JsonObject();
|
||||
gcmRequest.addProperty("delay_while_idle", false);
|
||||
gcmRequest.addProperty("time_to_live", TIME_TO_LIVE);
|
||||
|
||||
//Add message to GCM request
|
||||
JsonObject data = new JsonObject();
|
||||
if (message != null && !message.isEmpty()) {
|
||||
data.addProperty("data", message);
|
||||
gcmRequest.add("data", data);
|
||||
}
|
||||
|
||||
//Set device reg-ids
|
||||
JsonArray regIds = new JsonArray();
|
||||
for (String regId : registrationIds) {
|
||||
if (regId == null || regId.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
regIds.add(new JsonPrimitive(regId));
|
||||
}
|
||||
|
||||
gcmRequest.add("registration_ids", regIds);
|
||||
return gcmRequest.toString();
|
||||
}
|
||||
|
||||
private static List<String> getGCMTokens(List<Device> devices) {
|
||||
List<String> tokens = new ArrayList<>(devices.size());
|
||||
for (Device device : devices) {
|
||||
tokens.add(getGCMToken(device.getProperties()));
|
||||
}
|
||||
return tokens;
|
||||
}
|
||||
|
||||
private static String getGCMToken(List<Device.Property> properties) {
|
||||
String gcmToken = null;
|
||||
for (Device.Property property : properties) {
|
||||
if (AndroidPluginConstants.GCM_TOKEN.equals(property.getName())) {
|
||||
gcmToken = property.getValue();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return gcmToken;
|
||||
}
|
||||
|
||||
public static String getConfigurationProperty(String property) {
|
||||
DeviceManagementService androidDMService = MobileDeviceManagementDataHolder.getInstance().
|
||||
getAndroidDeviceManagementService();
|
||||
try {
|
||||
//Get the TenantConfiguration from cache if not we'll get it from DM service
|
||||
TenantConfiguration tenantConfiguration = getTenantConfigurationFromCache();
|
||||
if (tenantConfiguration == null) {
|
||||
tenantConfiguration = androidDMService.getDeviceManager().getConfiguration();
|
||||
if (tenantConfiguration != null) {
|
||||
addTenantConfigurationToCache(tenantConfiguration);
|
||||
}
|
||||
}
|
||||
|
||||
if (tenantConfiguration != null) {
|
||||
List<ConfigurationEntry> configs = tenantConfiguration.getConfiguration();
|
||||
for (ConfigurationEntry entry : configs) {
|
||||
if (property.equals(entry.getName())) {
|
||||
return (String) entry.getValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
return "";
|
||||
} catch (DeviceManagementException e) {
|
||||
log.error("Exception occurred while fetching the tenant-config.",e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void resetTenantConfigCache() {
|
||||
tenantConfigurationCache.remove(getTenantId());
|
||||
}
|
||||
|
||||
private static void addTenantConfigurationToCache(TenantConfiguration tenantConfiguration) {
|
||||
tenantConfigurationCache.put(getTenantId(), tenantConfiguration);
|
||||
}
|
||||
|
||||
private static TenantConfiguration getTenantConfigurationFromCache() {
|
||||
return tenantConfigurationCache.get(getTenantId());
|
||||
}
|
||||
|
||||
private static int getTenantId() {
|
||||
return CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
}
|
||||
}
|
||||
@ -1,47 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* you may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.impl.android.util;
|
||||
|
||||
/**
|
||||
* Defines constants used by android plugin.
|
||||
*/
|
||||
public class AndroidPluginConstants {
|
||||
|
||||
//Properties related to AD_DEVICE table
|
||||
public static final String DEVICE_ID = "DEVICE_ID";
|
||||
public static final String GCM_TOKEN = "GCM_TOKEN";
|
||||
public static final String DEVICE_INFO = "DEVICE_INFO";
|
||||
public static final String SERIAL = "SERIAL";
|
||||
public static final String DEVICE_MODEL = "DEVICE_MODEL";
|
||||
public static final String DEVICE_NAME = "DEVICE_NAME";
|
||||
public static final String LATITUDE = "LATITUDE";
|
||||
public static final String LONGITUDE = "LONGITUDE";
|
||||
public static final String IMEI = "IMEI";
|
||||
public static final String IMSI = "IMSI";
|
||||
public static final String VENDOR = "VENDOR";
|
||||
public static final String OS_VERSION = "OS_VERSION";
|
||||
public static final String MAC_ADDRESS = "MAC_ADDRESS";
|
||||
|
||||
//Properties related to AD_FEATURE table
|
||||
public static final String ANDROID_FEATURE_ID = "ID";
|
||||
public static final String ANDROID_FEATURE_CODE = "CODE";
|
||||
public static final String ANDROID_FEATURE_NAME = "NAME";
|
||||
public static final String ANDROID_FEATURE_DESCRIPTION = "DESCRIPTION";
|
||||
|
||||
}
|
||||
@ -1,58 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* you may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.impl.android.util;
|
||||
|
||||
import org.wso2.carbon.device.mgt.common.license.mgt.License;
|
||||
import org.wso2.carbon.device.mgt.mobile.impl.android.AndroidDeviceManagementService;
|
||||
|
||||
/**
|
||||
* Contains utility methods used by Android plugin.
|
||||
*/
|
||||
public class AndroidPluginUtils {
|
||||
|
||||
public static License getDefaultLicense() {
|
||||
License license = new License();
|
||||
license.setName(AndroidDeviceManagementService.DEVICE_TYPE_ANDROID);
|
||||
license.setLanguage("en_US");
|
||||
license.setVersion("1.0.0");
|
||||
license.setText("This End User License Agreement (\"Agreement\") is a legal agreement between you (\"You\") " +
|
||||
"and WSO2, Inc., regarding the enrollment of Your personal mobile device (\"Device\") in SoR's " +
|
||||
"mobile device management program, and the loading to and removal from Your Device and Your use " +
|
||||
"of certain applications and any associated software and user documentation, whether provided in " +
|
||||
"\"online\" or electronic format, used in connection with the operation of or provision of services " +
|
||||
"to WSO2, Inc., BY SELECTING \"I ACCEPT\" DURING INSTALLATION, YOU ARE ENROLLING YOUR DEVICE, AND " +
|
||||
"THEREBY AUTHORIZING SOR OR ITS AGENTS TO INSTALL, UPDATE AND REMOVE THE APPS FROM YOUR DEVICE AS " +
|
||||
"DESCRIBED IN THIS AGREEMENT. YOU ARE ALSO EXPLICITLY ACKNOWLEDGING AND AGREEING THAT (1) THIS IS " +
|
||||
"A BINDING CONTRACT AND (2) YOU HAVE READ AND AGREE TO THE TERMS OF THIS AGREEMENT.\n" +
|
||||
"\n" +
|
||||
"IF YOU DO NOT ACCEPT THESE TERMS, DO NOT ENROLL YOUR DEVICE AND DO NOT PROCEED ANY FURTHER.\n" +
|
||||
"\n" +
|
||||
"You agree that: (1) You understand and agree to be bound by the terms and conditions contained " +
|
||||
"in this Agreement, and (2) You are at least 21 years old and have the legal capacity to enter " +
|
||||
"into this Agreement as defined by the laws of Your jurisdiction. SoR shall have the right, " +
|
||||
"without prior notice, to terminate or suspend (i) this Agreement, (ii) the enrollment of Your " +
|
||||
"Device, or (iii) the functioning of the Apps in the event of a violation of this Agreement or " +
|
||||
"the cessation of Your relationship with SoR (including termination of Your employment if You are " +
|
||||
"an employee or expiration or termination of Your applicable franchise or supply agreement if You " +
|
||||
"are a franchisee of or supplier to the WSO2 WSO2, Inc., system). SoR expressly reserves all " +
|
||||
"rights not expressly granted herein.");
|
||||
return license;
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,31 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* you may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.impl.android.util;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Contains utility methods used by Android plugin.
|
||||
*/
|
||||
public class AndroidUtils {
|
||||
|
||||
public static String getDeviceProperty(Map<String, String> deviceProperties, String property) {
|
||||
return deviceProperties.get(property);
|
||||
}
|
||||
}
|
||||
@ -1,73 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.impl.windows;
|
||||
|
||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceManager;
|
||||
import org.wso2.carbon.device.mgt.common.ProvisioningConfig;
|
||||
import org.wso2.carbon.device.mgt.common.app.mgt.Application;
|
||||
import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException;
|
||||
import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager;
|
||||
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
|
||||
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig;
|
||||
import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This represents the Windows implementation of DeviceManagerService.
|
||||
*/
|
||||
public class WindowsDeviceManagementService implements DeviceManagementService {
|
||||
|
||||
private DeviceManager deviceManager;
|
||||
public static final String DEVICE_TYPE_WINDOWS = "windows";
|
||||
private static final String SUPER_TENANT_DOMAIN = "carbon.super";
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return WindowsDeviceManagementService.DEVICE_TYPE_WINDOWS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() throws DeviceManagementException {
|
||||
this.deviceManager = new WindowsDeviceManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
public DeviceManager getDeviceManager() {
|
||||
return deviceManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApplicationManager getApplicationManager() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProvisioningConfig getProvisioningConfig() {
|
||||
return new ProvisioningConfig(SUPER_TENANT_DOMAIN, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PushNotificationConfig getPushNotificationConfig() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,312 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.impl.windows;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.device.mgt.common.*;
|
||||
import org.wso2.carbon.device.mgt.common.configuration.mgt.TenantConfiguration;
|
||||
import org.wso2.carbon.device.mgt.common.license.mgt.License;
|
||||
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException;
|
||||
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManager;
|
||||
import org.wso2.carbon.device.mgt.extensions.license.mgt.registry.RegistryBasedLicenseManager;
|
||||
import org.wso2.carbon.device.mgt.mobile.common.MobileDeviceMgtPluginException;
|
||||
import org.wso2.carbon.device.mgt.mobile.common.MobilePluginConstants;
|
||||
import org.wso2.carbon.device.mgt.mobile.dao.AbstractMobileDeviceManagementDAOFactory;
|
||||
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException;
|
||||
import org.wso2.carbon.device.mgt.mobile.dto.MobileDevice;
|
||||
import org.wso2.carbon.device.mgt.mobile.impl.windows.dao.WindowsDAOFactory;
|
||||
import org.wso2.carbon.device.mgt.mobile.impl.windows.util.WindowsPluginUtils;
|
||||
import org.wso2.carbon.device.mgt.mobile.util.MobileDeviceManagementUtil;
|
||||
import org.wso2.carbon.registry.api.RegistryException;
|
||||
import org.wso2.carbon.registry.api.Resource;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.Marshaller;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
import java.io.StringReader;
|
||||
import java.io.StringWriter;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class WindowsDeviceManager implements DeviceManager {
|
||||
|
||||
private AbstractMobileDeviceManagementDAOFactory daoFactory;
|
||||
private LicenseManager licenseManager;
|
||||
private FeatureManager featureManager = new WindowsFeatureManager();
|
||||
private static final Log log = LogFactory.getLog(WindowsDeviceManagementService.class);
|
||||
|
||||
public WindowsDeviceManager() {
|
||||
this.daoFactory = new WindowsDAOFactory();
|
||||
this.licenseManager = new RegistryBasedLicenseManager();
|
||||
|
||||
License defaultLicense = WindowsPluginUtils.getDefaultLicense();
|
||||
|
||||
try {
|
||||
if (licenseManager.getLicense(WindowsDeviceManagementService.DEVICE_TYPE_WINDOWS,
|
||||
MobilePluginConstants.LANGUAGE_CODE_ENGLISH_US) == null) {
|
||||
licenseManager.addLicense(WindowsDeviceManagementService.DEVICE_TYPE_WINDOWS, defaultLicense);
|
||||
}
|
||||
featureManager.addSupportedFeaturesToDB();
|
||||
} catch (LicenseManagementException e) {
|
||||
log.error("Error occurred while adding default license for Windows devices", e);
|
||||
} catch (DeviceManagementException e) {
|
||||
throw new IllegalStateException("Error occurred while adding windows features to the DB.");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public FeatureManager getFeatureManager() {
|
||||
return featureManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean saveConfiguration(TenantConfiguration tenantConfiguration) throws DeviceManagementException {
|
||||
boolean status;
|
||||
Resource resource;
|
||||
try {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Persisting windows configurations in Registry");
|
||||
}
|
||||
String resourcePath = MobileDeviceManagementUtil.getPlatformConfigPath(
|
||||
DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS);
|
||||
StringWriter writer = new StringWriter();
|
||||
JAXBContext context = JAXBContext.newInstance(TenantConfiguration.class);
|
||||
Marshaller marshaller = context.createMarshaller();
|
||||
marshaller.marshal(tenantConfiguration, writer);
|
||||
|
||||
resource = MobileDeviceManagementUtil.getConfigurationRegistry().newResource();
|
||||
resource.setContent(writer.toString());
|
||||
resource.setMediaType(MobilePluginConstants.MEDIA_TYPE_XML);
|
||||
MobileDeviceManagementUtil.putRegistryResource(resourcePath, resource);
|
||||
status = true;
|
||||
} catch (MobileDeviceMgtPluginException e) {
|
||||
throw new DeviceManagementException(
|
||||
"Error occurred while retrieving the Registry instance", e);
|
||||
} catch (RegistryException e) {
|
||||
throw new DeviceManagementException(
|
||||
"Error occurred while persisting the Registry resource of Windows configuration", e);
|
||||
} catch (JAXBException e) {
|
||||
throw new DeviceManagementException(
|
||||
"Error occurred while parsing the Windows configuration", e);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TenantConfiguration getConfiguration() throws DeviceManagementException {
|
||||
Resource resource;
|
||||
try {
|
||||
String windowsTenantRegistryPath = MobileDeviceManagementUtil.
|
||||
getPlatformConfigPath(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS);
|
||||
resource = MobileDeviceManagementUtil.getRegistryResource(windowsTenantRegistryPath);
|
||||
if (resource != null) {
|
||||
JAXBContext context = JAXBContext.newInstance(TenantConfiguration.class);
|
||||
Unmarshaller unmarshaller = context.createUnmarshaller();
|
||||
return (TenantConfiguration) unmarshaller.unmarshal(new StringReader(
|
||||
new String((byte[]) resource.getContent(), Charset.
|
||||
forName(MobilePluginConstants.CHARSET_UTF8))));
|
||||
}
|
||||
return null;
|
||||
} catch (MobileDeviceMgtPluginException e) {
|
||||
throw new DeviceManagementException(
|
||||
"Error occurred while retrieving the Registry instance", e);
|
||||
} catch (JAXBException e) {
|
||||
throw new DeviceManagementException(
|
||||
"Error occurred while parsing the Windows configuration", e);
|
||||
} catch (RegistryException e) {
|
||||
throw new DeviceManagementException(
|
||||
"Error occurred while retrieving the Registry resource of Windows configuration", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean modifyEnrollment(Device device) throws DeviceManagementException {
|
||||
boolean status = false;
|
||||
MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device);
|
||||
try {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Modifying the Windows device enrollment data");
|
||||
}
|
||||
WindowsDAOFactory.beginTransaction();
|
||||
if (daoFactory.getMobileDeviceDAO() != null) {
|
||||
status = daoFactory.getMobileDeviceDAO().updateMobileDevice(mobileDevice);
|
||||
}
|
||||
WindowsDAOFactory.commitTransaction();
|
||||
} catch (MobileDeviceManagementDAOException e) {
|
||||
WindowsDAOFactory.rollbackTransaction();
|
||||
throw new DeviceManagementException("Error occurred while updating the enrollment of the " +
|
||||
"Windows device : " + device.getDeviceIdentifier(), e);
|
||||
} finally {
|
||||
WindowsDAOFactory.closeConnection();
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
|
||||
//Here we don't have anything specific to do. Hence returning.
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException {
|
||||
MobileDevice mobileDevice;
|
||||
try {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Checking the enrollment of Windows device : " + deviceId.getId());
|
||||
}
|
||||
if (daoFactory.getMobileDeviceDAO() != null) {
|
||||
mobileDevice = daoFactory.getMobileDeviceDAO().getMobileDevice(deviceId.getId());
|
||||
} else {
|
||||
throw new DeviceManagementException("Error occurred while getting DAO object.");
|
||||
}
|
||||
} catch (MobileDeviceManagementDAOException e) {
|
||||
String msg = "Error occurred while checking the enrollment status of Windows device : " + deviceId.getId();
|
||||
throw new DeviceManagementException(msg, e);
|
||||
}
|
||||
return (mobileDevice != null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setActive(DeviceIdentifier deviceId, boolean status)
|
||||
throws DeviceManagementException {
|
||||
return true;
|
||||
}
|
||||
|
||||
public List<Device> getAllDevices() throws DeviceManagementException {
|
||||
List<Device> devices = null;
|
||||
List<MobileDevice> mobileDevices = null;
|
||||
try {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Fetching the details of all Windows devices");
|
||||
}
|
||||
WindowsDAOFactory.openConnection();
|
||||
if (daoFactory.getMobileDeviceDAO() != null) {
|
||||
mobileDevices = daoFactory.getMobileDeviceDAO().getAllMobileDevices();
|
||||
}
|
||||
if (mobileDevices != null) {
|
||||
devices = new ArrayList<>(mobileDevices.size());
|
||||
for (MobileDevice mobileDevice : mobileDevices) {
|
||||
devices.add(MobileDeviceManagementUtil.convertToDevice(mobileDevice));
|
||||
}
|
||||
}
|
||||
} catch (MobileDeviceManagementDAOException e) {
|
||||
throw new DeviceManagementException("Error occurred while fetching all Windows devices", e);
|
||||
} finally {
|
||||
WindowsDAOFactory.closeConnection();
|
||||
}
|
||||
return devices;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
|
||||
Device device = null;
|
||||
MobileDevice mobileDevice = null;
|
||||
try {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Getting the details of Windows device : '" + deviceId.getId() + "'");
|
||||
}
|
||||
WindowsDAOFactory.openConnection();
|
||||
if (daoFactory.getMobileDeviceDAO() != null) {
|
||||
mobileDevice = daoFactory.getMobileDeviceDAO().getMobileDevice(deviceId.getId());
|
||||
}
|
||||
device = MobileDeviceManagementUtil.convertToDevice(mobileDevice);
|
||||
} catch (MobileDeviceManagementDAOException e) {
|
||||
throw new DeviceManagementException(
|
||||
"Error occurred while fetching the Windows device: '" + deviceId.getId() + "'", e);
|
||||
} finally {
|
||||
WindowsDAOFactory.closeConnection();
|
||||
}
|
||||
return device;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType)
|
||||
throws DeviceManagementException {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isClaimable(DeviceIdentifier deviceIdentifier) throws DeviceManagementException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setStatus(DeviceIdentifier deviceIdentifier, String currentUser,
|
||||
EnrolmentInfo.Status status) throws DeviceManagementException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public License getLicense(String languageCode) throws LicenseManagementException {
|
||||
return licenseManager.getLicense(WindowsDeviceManagementService.DEVICE_TYPE_WINDOWS, languageCode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addLicense(License license) throws LicenseManagementException {
|
||||
licenseManager.addLicense(WindowsDeviceManagementService.DEVICE_TYPE_WINDOWS, license);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean requireDeviceAuthorization() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateDeviceInfo(DeviceIdentifier deviceIdentifier,
|
||||
Device device) throws DeviceManagementException {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean enrollDevice(Device device) throws DeviceManagementException {
|
||||
boolean status = false;
|
||||
MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device);
|
||||
try {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Enrolling a new windows device : " + device.getDeviceIdentifier());
|
||||
}
|
||||
boolean isEnrolled = this.isEnrolled(
|
||||
new DeviceIdentifier(device.getDeviceIdentifier(), device.getType()));
|
||||
if (isEnrolled) {
|
||||
this.modifyEnrollment(device);
|
||||
} else {
|
||||
WindowsDAOFactory.beginTransaction();
|
||||
if (daoFactory.getMobileDeviceDAO() != null) {
|
||||
status = daoFactory.getMobileDeviceDAO().addMobileDevice(mobileDevice);
|
||||
}
|
||||
WindowsDAOFactory.commitTransaction();
|
||||
}
|
||||
} catch (MobileDeviceManagementDAOException e) {
|
||||
WindowsDAOFactory.rollbackTransaction();
|
||||
throw new DeviceManagementException("Error occurred while enrolling the windows device : "
|
||||
+ device.getDeviceIdentifier(), e);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,198 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.impl.windows;
|
||||
|
||||
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.mobile.dao.MobileDeviceManagementDAOException;
|
||||
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOFactory;
|
||||
import org.wso2.carbon.device.mgt.mobile.dao.MobileFeatureDAO;
|
||||
import org.wso2.carbon.device.mgt.mobile.dto.MobileFeature;
|
||||
import org.wso2.carbon.device.mgt.mobile.impl.windows.dao.WindowsDAOFactory;
|
||||
import org.wso2.carbon.device.mgt.mobile.impl.windows.util.WindowsUtils;
|
||||
import org.wso2.carbon.device.mgt.mobile.util.MobileDeviceManagementUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class WindowsFeatureManager implements FeatureManager {
|
||||
|
||||
private MobileFeatureDAO featureDAO;
|
||||
|
||||
public WindowsFeatureManager() {
|
||||
MobileDeviceManagementDAOFactory daoFactory = new WindowsDAOFactory();
|
||||
this.featureDAO = daoFactory.getMobileFeatureDAO();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addFeature(Feature feature) throws DeviceManagementException {
|
||||
try {
|
||||
WindowsDAOFactory.beginTransaction();
|
||||
MobileFeature mobileFeature = MobileDeviceManagementUtil.convertToMobileFeature(feature);
|
||||
featureDAO.addFeature(mobileFeature);
|
||||
WindowsDAOFactory.commitTransaction();
|
||||
return true;
|
||||
} catch (MobileDeviceManagementDAOException e) {
|
||||
WindowsDAOFactory.rollbackTransaction();
|
||||
throw new DeviceManagementException("Error occurred while adding the feature", e);
|
||||
} finally {
|
||||
WindowsDAOFactory.closeConnection();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addFeatures(List<Feature> features) throws DeviceManagementException {
|
||||
List<MobileFeature> mobileFeatures = new ArrayList<MobileFeature>(features.size());
|
||||
for (Feature feature : features) {
|
||||
mobileFeatures.add(MobileDeviceManagementUtil.convertToMobileFeature(feature));
|
||||
}
|
||||
try {
|
||||
WindowsDAOFactory.beginTransaction();
|
||||
featureDAO.addFeatures(mobileFeatures);
|
||||
WindowsDAOFactory.commitTransaction();
|
||||
return true;
|
||||
} catch (MobileDeviceManagementDAOException e) {
|
||||
WindowsDAOFactory.rollbackTransaction();
|
||||
throw new DeviceManagementException("Error occurred while adding the features", e);
|
||||
} finally {
|
||||
WindowsDAOFactory.closeConnection();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Feature getFeature(String name) throws DeviceManagementException {
|
||||
try {
|
||||
WindowsDAOFactory.openConnection();
|
||||
MobileFeature mobileFeature = featureDAO.getFeatureByCode(name);
|
||||
Feature feature = MobileDeviceManagementUtil.convertToFeature(mobileFeature);
|
||||
return feature;
|
||||
} catch (MobileDeviceManagementDAOException e) {
|
||||
throw new DeviceManagementException("Error occurred while retrieving the feature", e);
|
||||
} finally {
|
||||
WindowsDAOFactory.closeConnection();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Feature> getFeatures() throws DeviceManagementException {
|
||||
|
||||
try {
|
||||
WindowsDAOFactory.openConnection();
|
||||
List<MobileFeature> mobileFeatures = featureDAO.getAllFeatures();
|
||||
List<Feature> featureList = new ArrayList<Feature>(mobileFeatures.size());
|
||||
for (MobileFeature mobileFeature : mobileFeatures) {
|
||||
featureList.add(MobileDeviceManagementUtil.convertToFeature(mobileFeature));
|
||||
}
|
||||
return featureList;
|
||||
} catch (MobileDeviceManagementDAOException e) {
|
||||
throw new DeviceManagementException("Error occurred while retrieving the list of features registered for " +
|
||||
"Windows platform", e);
|
||||
} finally {
|
||||
WindowsDAOFactory.closeConnection();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeFeature(String code) throws DeviceManagementException {
|
||||
boolean status;
|
||||
try {
|
||||
WindowsDAOFactory.beginTransaction();
|
||||
featureDAO.deleteFeatureByCode(code);
|
||||
WindowsDAOFactory.commitTransaction();
|
||||
status = true;
|
||||
return status;
|
||||
} catch (MobileDeviceManagementDAOException e) {
|
||||
WindowsDAOFactory.rollbackTransaction();
|
||||
throw new DeviceManagementException("Error occurred while removing the feature", e);
|
||||
} finally {
|
||||
WindowsDAOFactory.closeConnection();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addSupportedFeaturesToDB() throws DeviceManagementException {
|
||||
synchronized (this) {
|
||||
List<Feature> supportedFeatures = getSupportedFeatures();
|
||||
List<Feature> existingFeatures = this.getFeatures();
|
||||
List<Feature> missingFeatures = MobileDeviceManagementUtil.
|
||||
getMissingFeatures(supportedFeatures, existingFeatures);
|
||||
if (missingFeatures.size() > 0) {
|
||||
return this.addFeatures(missingFeatures);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get supported Windows features.
|
||||
*
|
||||
* @return Supported features.
|
||||
*/
|
||||
public static List<Feature> getSupportedFeatures() {
|
||||
List<Feature> supportedFeatures = new ArrayList<>();
|
||||
Feature feature;
|
||||
feature = WindowsUtils.getMobileFeature();
|
||||
feature.setCode("DEVICE_LOCK");
|
||||
feature.setName("Device Lock");
|
||||
feature.setDescription("Lock the device");
|
||||
supportedFeatures.add(feature);
|
||||
feature = WindowsUtils.getMobileFeature();
|
||||
feature.setCode("CAMERA");
|
||||
feature.setName("camera");
|
||||
feature.setDescription("Enable or disable camera");
|
||||
supportedFeatures.add(feature);
|
||||
feature = WindowsUtils.getMobileFeature();
|
||||
feature.setCode("DEVICE_INFO");
|
||||
feature.setName("Device info");
|
||||
feature.setDescription("Request device information");
|
||||
supportedFeatures.add(feature);
|
||||
feature = WindowsUtils.getMobileFeature();
|
||||
feature.setCode("WIPE_DATA");
|
||||
feature.setName("Wipe Data");
|
||||
feature.setDescription("Factory reset the device");
|
||||
supportedFeatures.add(feature);
|
||||
feature = WindowsUtils.getMobileFeature();
|
||||
feature.setCode("ENCRYPT_STORAGE");
|
||||
feature.setName("Encrypt storage");
|
||||
feature.setDescription("Encrypt storage");
|
||||
supportedFeatures.add(feature);
|
||||
feature = WindowsUtils.getMobileFeature();
|
||||
feature.setCode("DEVICE_RING");
|
||||
feature.setName("Ring");
|
||||
feature.setDescription("Ring the device");
|
||||
supportedFeatures.add(feature);
|
||||
feature = WindowsUtils.getMobileFeature();
|
||||
feature.setCode("PASSCODE_POLICY");
|
||||
feature.setName("Password Policy");
|
||||
feature.setDescription("Set passcode policy");
|
||||
supportedFeatures.add(feature);
|
||||
feature = WindowsUtils.getMobileFeature();
|
||||
feature.setCode("DISENROLL");
|
||||
feature.setName("DisEnroll");
|
||||
feature.setDescription("DisEnroll the device");
|
||||
supportedFeatures.add(feature);
|
||||
feature = WindowsUtils.getMobileFeature();
|
||||
feature.setCode("LOCK_RESET");
|
||||
feature.setName("LockReset");
|
||||
feature.setDescription("Lock Reset device");
|
||||
supportedFeatures.add(feature);
|
||||
return supportedFeatures;
|
||||
}
|
||||
}
|
||||
@ -1,73 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.impl.windows;
|
||||
|
||||
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.device.mgt.common.DeviceManagementConstants;
|
||||
import org.wso2.carbon.policy.mgt.common.Policy;
|
||||
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 java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class WindowsPolicyMonitoringService implements PolicyMonitoringService {
|
||||
|
||||
private static Log log = LogFactory.getLog(WindowsPolicyMonitoringService.class);
|
||||
|
||||
@Override
|
||||
public void notifyDevices(List<Device> list) throws PolicyComplianceException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ComplianceData checkPolicyCompliance(DeviceIdentifier deviceIdentifier, Policy policy, Object compliancePayload)
|
||||
throws PolicyComplianceException {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("checking policy compliance status of device '" + deviceIdentifier.getId() + "'");
|
||||
}
|
||||
List<ComplianceFeature> complianceFeatures = (List<ComplianceFeature>) compliancePayload;
|
||||
List<ComplianceFeature> nonComplianceFeatures = new ArrayList<>();
|
||||
ComplianceData complianceData = new ComplianceData();
|
||||
|
||||
if (policy == null || compliancePayload == null) {
|
||||
return complianceData;
|
||||
}
|
||||
|
||||
for (ComplianceFeature complianceFeature : complianceFeatures) {
|
||||
if (!complianceFeature.isCompliant()) {
|
||||
complianceData.setStatus(false);
|
||||
nonComplianceFeatures.add(complianceFeature);
|
||||
break;
|
||||
}
|
||||
}
|
||||
complianceData.setComplianceFeatures(nonComplianceFeatures);
|
||||
return complianceData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS;
|
||||
}
|
||||
}
|
||||
@ -1,132 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.impl.windows.dao;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
|
||||
import org.wso2.carbon.device.mgt.mobile.dao.AbstractMobileDeviceManagementDAOFactory;
|
||||
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceDAO;
|
||||
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException;
|
||||
import org.wso2.carbon.device.mgt.mobile.dao.MobileFeatureDAO;
|
||||
import org.wso2.carbon.device.mgt.mobile.impl.windows.dao.impl.WindowsDeviceDAOImpl;
|
||||
import org.wso2.carbon.device.mgt.mobile.impl.windows.dao.impl.WindowsFeatureDAOImpl;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class WindowsDAOFactory extends AbstractMobileDeviceManagementDAOFactory {
|
||||
|
||||
private static final Log log = LogFactory.getLog(WindowsDAOFactory.class);
|
||||
protected static DataSource dataSource;
|
||||
private static ThreadLocal<Connection> currentConnection = new ThreadLocal<>();
|
||||
|
||||
public WindowsDAOFactory() {
|
||||
this.dataSource = getDataSourceMap().get(
|
||||
DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MobileDeviceDAO getMobileDeviceDAO() {
|
||||
return new WindowsDeviceDAOImpl();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MobileFeatureDAO getMobileFeatureDAO() {
|
||||
return new WindowsFeatureDAOImpl();
|
||||
}
|
||||
|
||||
public static void beginTransaction() throws MobileDeviceManagementDAOException {
|
||||
try {
|
||||
Connection conn = dataSource.getConnection();
|
||||
conn.setAutoCommit(false);
|
||||
currentConnection.set(conn);
|
||||
} catch (SQLException e) {
|
||||
throw new MobileDeviceManagementDAOException("Error occurred while retrieving datasource connection", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void openConnection() throws MobileDeviceManagementDAOException {
|
||||
if (currentConnection.get() == null) {
|
||||
Connection conn;
|
||||
try {
|
||||
conn = dataSource.getConnection();
|
||||
currentConnection.set(conn);
|
||||
} catch (SQLException e) {
|
||||
throw new MobileDeviceManagementDAOException
|
||||
("Error occurred while retrieving data source connection", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Connection getConnection() throws MobileDeviceManagementDAOException {
|
||||
if (currentConnection.get() == null) {
|
||||
try {
|
||||
currentConnection.set(dataSource.getConnection());
|
||||
} catch (SQLException e) {
|
||||
throw new MobileDeviceManagementDAOException
|
||||
("Error occurred while retrieving data source connection", e);
|
||||
}
|
||||
}
|
||||
return currentConnection.get();
|
||||
}
|
||||
|
||||
public static void commitTransaction() {
|
||||
try {
|
||||
Connection conn = currentConnection.get();
|
||||
if (conn != null) {
|
||||
conn.commit();
|
||||
} else {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Datasource connection associated with the current thread is null, hence commit " +
|
||||
"has not been attempted");
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
log.error("Error occurred while committing the transaction", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void closeConnection() {
|
||||
Connection con = currentConnection.get();
|
||||
try {
|
||||
con.close();
|
||||
} catch (SQLException e) {
|
||||
log.error("Error occurred while close the connection");
|
||||
}
|
||||
currentConnection.remove();
|
||||
}
|
||||
|
||||
public static void rollbackTransaction() {
|
||||
try {
|
||||
Connection conn = currentConnection.get();
|
||||
if (conn != null) {
|
||||
conn.rollback();
|
||||
} else {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Datasource connection associated with the current thread is null, hence rollback " +
|
||||
"has not been attempted");
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
log.warn("Error occurred while roll-backing the transaction", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,80 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.impl.windows.dao;
|
||||
|
||||
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException;
|
||||
|
||||
/**
|
||||
* This class responsible for wrapping exceptions related on Windows device features.
|
||||
*/
|
||||
public class WindowsFeatureManagementDAOException extends MobileDeviceManagementDAOException {
|
||||
|
||||
private String message;
|
||||
private static final long serialVersionUID = 2021891706072918865L;
|
||||
|
||||
/**
|
||||
* Constructs a new MobileDeviceManagementDAOException with the specified detail message and
|
||||
* nested exception.
|
||||
*
|
||||
* @param message error message
|
||||
* @param nestedException exception
|
||||
*/
|
||||
public WindowsFeatureManagementDAOException(String message, Exception nestedException) {
|
||||
super(message, nestedException);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new MobileDeviceManagementDAOException with the specified detail message
|
||||
* and cause.
|
||||
*
|
||||
* @param message the detail message.
|
||||
* @param cause the cause of this exception.
|
||||
*/
|
||||
public WindowsFeatureManagementDAOException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
setErrorMessage(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new MobileDeviceManagementDAOException with the specified detail message.
|
||||
*
|
||||
* @param message the detail message.
|
||||
*/
|
||||
public WindowsFeatureManagementDAOException(String message) {
|
||||
super(message);
|
||||
setErrorMessage(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new MobileDeviceManagementDAOException with the specified and cause.
|
||||
*
|
||||
* @param cause the cause of this exception.
|
||||
*/
|
||||
public WindowsFeatureManagementDAOException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setErrorMessage(String errorMessage) {
|
||||
this.message = errorMessage;
|
||||
}
|
||||
}
|
||||
@ -1,238 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.wso2.carbon.device.mgt.mobile.impl.windows.dao.impl;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceDAO;
|
||||
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException;
|
||||
import org.wso2.carbon.device.mgt.mobile.dao.util.MobileDeviceManagementDAOUtil;
|
||||
import org.wso2.carbon.device.mgt.mobile.dto.MobileDevice;
|
||||
import org.wso2.carbon.device.mgt.mobile.impl.windows.dao.WindowsDAOFactory;
|
||||
import org.wso2.carbon.device.mgt.mobile.impl.windows.util.WindowsPluginConstants;
|
||||
import org.wso2.carbon.device.mgt.mobile.impl.windows.util.WindowsUtils;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Implements MobileDeviceDAO for Windows Devices.
|
||||
*/
|
||||
public class WindowsDeviceDAOImpl implements MobileDeviceDAO {
|
||||
|
||||
private static final Log log = LogFactory.getLog(WindowsDeviceDAOImpl.class);
|
||||
|
||||
@Override
|
||||
public MobileDevice getMobileDevice(String mblDeviceId) throws MobileDeviceManagementDAOException {
|
||||
Connection conn;
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
MobileDevice mobileDevice = null;
|
||||
try {
|
||||
conn = WindowsDAOFactory.getConnection();
|
||||
String selectDBQuery =
|
||||
"SELECT DEVICE_ID, CHANNEL_URI, DEVICE_INFO, IMEI, IMSI, " +
|
||||
"OS_VERSION, DEVICE_MODEL, VENDOR, LATITUDE, LONGITUDE, SERIAL, MAC_ADDRESS," +
|
||||
" OS_VERSION, DEVICE_NAME " +
|
||||
"FROM WIN_DEVICE WHERE DEVICE_ID = ?";
|
||||
stmt = conn.prepareStatement(selectDBQuery);
|
||||
stmt.setString(1, mblDeviceId);
|
||||
rs = stmt.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
mobileDevice = WindowsUtils.loadMobileDevices(rs);
|
||||
Map<String, String> propertyMap = new HashMap<>();
|
||||
propertyMap.put(WindowsPluginConstants.CHANNEL_URI, rs.getString(WindowsPluginConstants.CHANNEL_URI));
|
||||
propertyMap.put(WindowsPluginConstants.DEVICE_INFO, rs.getString(WindowsPluginConstants.DEVICE_INFO));
|
||||
propertyMap.put(WindowsPluginConstants.MAC_ADDRESS, rs.getString(WindowsPluginConstants.MAC_ADDRESS));
|
||||
propertyMap.put(WindowsPluginConstants.DEVICE_NAME, rs.getString(WindowsPluginConstants.DEVICE_NAME));
|
||||
|
||||
mobileDevice.setDeviceProperties(propertyMap);
|
||||
}
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("All Windows device details have fetched from Windows database.");
|
||||
}
|
||||
return mobileDevice;
|
||||
} catch (SQLException e) {
|
||||
throw new MobileDeviceManagementDAOException("Error occurred while fetching all Windows device data", e);
|
||||
} finally {
|
||||
MobileDeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addMobileDevice(MobileDevice mobileDevice) throws MobileDeviceManagementDAOException {
|
||||
boolean status = false;
|
||||
Connection conn;
|
||||
PreparedStatement stmt = null;
|
||||
try {
|
||||
conn = WindowsDAOFactory.getConnection();
|
||||
String createDBQuery =
|
||||
"INSERT INTO WIN_DEVICE(DEVICE_ID, CHANNEL_URI, DEVICE_INFO, IMEI, " +
|
||||
"IMSI, OS_VERSION, DEVICE_MODEL, VENDOR, LATITUDE, LONGITUDE, SERIAL, " +
|
||||
"MAC_ADDRESS, DEVICE_NAME) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
||||
|
||||
stmt = conn.prepareStatement(createDBQuery);
|
||||
stmt.setString(1, mobileDevice.getMobileDeviceId());
|
||||
|
||||
Map<String, String> properties = mobileDevice.getDeviceProperties();
|
||||
stmt.setString(2, properties.get(WindowsPluginConstants.CHANNEL_URI));
|
||||
stmt.setString(3, properties.get(WindowsPluginConstants.DEVICE_INFO));
|
||||
stmt.setString(4, mobileDevice.getImei());
|
||||
stmt.setString(5, mobileDevice.getImsi());
|
||||
stmt.setString(6, mobileDevice.getOsVersion());
|
||||
stmt.setString(7, mobileDevice.getModel());
|
||||
stmt.setString(8, mobileDevice.getVendor());
|
||||
stmt.setString(9, mobileDevice.getLatitude());
|
||||
stmt.setString(10, mobileDevice.getLongitude());
|
||||
stmt.setString(11, mobileDevice.getSerial());
|
||||
stmt.setString(12, properties.get(WindowsPluginConstants.MAC_ADDRESS));
|
||||
stmt.setString(13, properties.get(WindowsPluginConstants.DEVICE_NAME));
|
||||
int rows = stmt.executeUpdate();
|
||||
if (rows > 0) {
|
||||
status = true;
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Windows device " + mobileDevice.getMobileDeviceId() + " data has been" +
|
||||
" added to the Windows database.");
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new MobileDeviceManagementDAOException("Error occurred while adding the Windows device '" +
|
||||
mobileDevice.getMobileDeviceId() + "' to the Windows db.", e);
|
||||
} finally {
|
||||
MobileDeviceManagementDAOUtil.cleanupResources(stmt, null);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateMobileDevice(MobileDevice mobileDevice) throws MobileDeviceManagementDAOException {
|
||||
boolean status = false;
|
||||
Connection conn;
|
||||
PreparedStatement stmt = null;
|
||||
try {
|
||||
conn = WindowsDAOFactory.getConnection();
|
||||
String updateDBQuery =
|
||||
"UPDATE WIN_DEVICE SET CHANNEL_URI = ?, DEVICE_INFO = ?, IMEI = ?, IMSI = ?, " +
|
||||
"OS_VERSION = ?, DEVICE_MODEL = ?, VENDOR = ?, LATITUDE = ?, LONGITUDE = ?, " +
|
||||
"SERIAL = ?, MAC_ADDRESS = ?, DEVICE_NAME = ? WHERE DEVICE_ID = ?";
|
||||
|
||||
stmt = conn.prepareStatement(updateDBQuery);
|
||||
|
||||
Map<String, String> properties = mobileDevice.getDeviceProperties();
|
||||
stmt.setString(1, properties.get(WindowsPluginConstants.CHANNEL_URI));
|
||||
stmt.setString(2, properties.get(WindowsPluginConstants.DEVICE_INFO));
|
||||
stmt.setString(3, mobileDevice.getImei());
|
||||
stmt.setString(4, mobileDevice.getImsi());
|
||||
stmt.setString(5, mobileDevice.getOsVersion());
|
||||
stmt.setString(6, mobileDevice.getModel());
|
||||
stmt.setString(7, mobileDevice.getVendor());
|
||||
stmt.setString(8, mobileDevice.getLatitude());
|
||||
stmt.setString(9, mobileDevice.getLongitude());
|
||||
stmt.setString(10, mobileDevice.getSerial());
|
||||
stmt.setString(11, properties.get(WindowsPluginConstants.MAC_ADDRESS));
|
||||
stmt.setString(12, properties.get(WindowsPluginConstants.DEVICE_NAME));
|
||||
stmt.setString(13, mobileDevice.getMobileDeviceId());
|
||||
int rows = stmt.executeUpdate();
|
||||
if (rows > 0) {
|
||||
status = true;
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Windows device " + mobileDevice.getMobileDeviceId() + " data has been" +
|
||||
" modified.");
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new MobileDeviceManagementDAOException("Error occurred while modifying the Windows device '" +
|
||||
mobileDevice.getMobileDeviceId() + "' data.", e);
|
||||
} finally {
|
||||
MobileDeviceManagementDAOUtil.cleanupResources(stmt, null);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteMobileDevice(String mblDeviceId) throws MobileDeviceManagementDAOException {
|
||||
boolean status = false;
|
||||
Connection conn;
|
||||
PreparedStatement stmt = null;
|
||||
try {
|
||||
conn = WindowsDAOFactory.getConnection();
|
||||
String deleteDBQuery = "DELETE FROM WIN_DEVICE WHERE DEVICE_ID = ?";
|
||||
stmt = conn.prepareStatement(deleteDBQuery);
|
||||
stmt.setString(1, mblDeviceId);
|
||||
int rows = stmt.executeUpdate();
|
||||
if (rows > 0) {
|
||||
status = true;
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Windows device " + mblDeviceId + " data has deleted" +
|
||||
" from the windows database.");
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new MobileDeviceManagementDAOException("Error occurred while deleting windows device '" +
|
||||
mblDeviceId + "'", e);
|
||||
} finally {
|
||||
MobileDeviceManagementDAOUtil.cleanupResources(stmt, null);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MobileDevice> getAllMobileDevices() throws MobileDeviceManagementDAOException {
|
||||
Connection conn;
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
MobileDevice mobileDevice;
|
||||
List<MobileDevice> mobileDevices = new ArrayList<>();
|
||||
try {
|
||||
conn = WindowsDAOFactory.getConnection();
|
||||
String selectDBQuery =
|
||||
"SELECT DEVICE_ID, CHANNEL_URI, DEVICE_INFO, IMEI, IMSI, " +
|
||||
"OS_VERSION, DEVICE_MODEL, VENDOR, LATITUDE, LONGITUDE, SERIAL, MAC_ADDRESS," +
|
||||
" OS_VERSION, DEVICE_NAME " +
|
||||
"FROM WIN_DEVICE";
|
||||
stmt = conn.prepareStatement(selectDBQuery);
|
||||
rs = stmt.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
mobileDevice = WindowsUtils.loadMobileDevices(rs);
|
||||
Map<String, String> propertyMap = new HashMap<>();
|
||||
propertyMap.put(WindowsPluginConstants.CHANNEL_URI, rs.getString(WindowsPluginConstants.CHANNEL_URI));
|
||||
propertyMap.put(WindowsPluginConstants.DEVICE_INFO, rs.getString(WindowsPluginConstants.DEVICE_INFO));
|
||||
propertyMap.put(WindowsPluginConstants.DEVICE_NAME, rs.getString(WindowsPluginConstants.DEVICE_NAME));
|
||||
mobileDevice.setDeviceProperties(propertyMap);
|
||||
mobileDevices.add(mobileDevice);
|
||||
}
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("All Windows device details have fetched from Windows database.");
|
||||
}
|
||||
return mobileDevices;
|
||||
} catch (SQLException e) {
|
||||
throw new MobileDeviceManagementDAOException("Error occurred while fetching all Windows device data", e);
|
||||
} finally {
|
||||
MobileDeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,267 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.impl.windows.dao.impl;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
|
||||
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException;
|
||||
import org.wso2.carbon.device.mgt.mobile.dao.MobileFeatureDAO;
|
||||
import org.wso2.carbon.device.mgt.mobile.dao.util.MobileDeviceManagementDAOUtil;
|
||||
import org.wso2.carbon.device.mgt.mobile.dto.MobileFeature;
|
||||
import org.wso2.carbon.device.mgt.mobile.impl.windows.dao.WindowsDAOFactory;
|
||||
import org.wso2.carbon.device.mgt.mobile.impl.windows.dao.WindowsFeatureManagementDAOException;
|
||||
import org.wso2.carbon.device.mgt.mobile.impl.windows.util.WindowsPluginConstants;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Implement MobileFeatureDAO for Windows devices.
|
||||
*/
|
||||
public class WindowsFeatureDAOImpl implements MobileFeatureDAO {
|
||||
|
||||
private static final Log log = LogFactory.getLog(WindowsFeatureDAOImpl.class);
|
||||
|
||||
@Override
|
||||
public boolean addFeature(MobileFeature mobileFeature) throws MobileDeviceManagementDAOException {
|
||||
PreparedStatement stmt = null;
|
||||
boolean status;
|
||||
Connection conn;
|
||||
try {
|
||||
conn = WindowsDAOFactory.getConnection();
|
||||
String sql = "INSERT INTO WIN_FEATURE(CODE, NAME, DESCRIPTION) VALUES (?, ?, ?)";
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setString(1, mobileFeature.getCode());
|
||||
stmt.setString(2, mobileFeature.getName());
|
||||
stmt.setString(3, mobileFeature.getDescription());
|
||||
stmt.executeUpdate();
|
||||
status = true;
|
||||
} catch (SQLException e) {
|
||||
throw new WindowsFeatureManagementDAOException(
|
||||
"Error occurred while adding windows feature '" +
|
||||
mobileFeature.getName() + "' into the metadata repository", e);
|
||||
} finally {
|
||||
MobileDeviceManagementDAOUtil.cleanupResources(stmt, null);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addFeatures(List<MobileFeature> mobileFeatures) throws MobileDeviceManagementDAOException {
|
||||
PreparedStatement stmt = null;
|
||||
boolean status = false;
|
||||
Connection conn;
|
||||
try {
|
||||
conn = WindowsDAOFactory.getConnection();
|
||||
stmt = conn.prepareStatement("INSERT INTO WIN_FEATURE(CODE, NAME, DESCRIPTION) VALUES (?, ?, ?)");
|
||||
for (MobileFeature mobileFeature : mobileFeatures) {
|
||||
stmt.setString(1, mobileFeature.getCode());
|
||||
stmt.setString(2, mobileFeature.getName());
|
||||
stmt.setString(3, mobileFeature.getDescription());
|
||||
stmt.addBatch();
|
||||
}
|
||||
stmt.executeBatch();
|
||||
status = true;
|
||||
} catch (SQLException e) {
|
||||
throw new WindowsFeatureManagementDAOException(
|
||||
"Error occurred while adding windows features into the metadata repository", e);
|
||||
} finally {
|
||||
MobileDeviceManagementDAOUtil.cleanupResources(stmt, null);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateFeature(MobileFeature mobileFeature) throws MobileDeviceManagementDAOException {
|
||||
boolean status = false;
|
||||
Connection conn;
|
||||
PreparedStatement stmt = null;
|
||||
try {
|
||||
conn = WindowsDAOFactory.getConnection();
|
||||
String updateDBQuery =
|
||||
"UPDATE WIN_FEATURE SET NAME = ?, DESCRIPTION = ?" +
|
||||
"WHERE CODE = ?";
|
||||
stmt = conn.prepareStatement(updateDBQuery);
|
||||
stmt.setString(1, mobileFeature.getName());
|
||||
stmt.setString(2, mobileFeature.getDescription());
|
||||
stmt.setString(3, mobileFeature.getCode());
|
||||
int rows = stmt.executeUpdate();
|
||||
if (rows > 0) {
|
||||
status = true;
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Windows Feature " + mobileFeature.getCode() + " data has been " +
|
||||
"modified.");
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new WindowsFeatureManagementDAOException("Error occurred while updating the Windows Feature '" +
|
||||
mobileFeature.getCode() + "' to the Windows db.", e);
|
||||
} finally {
|
||||
MobileDeviceManagementDAOUtil.cleanupResources(stmt, null);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteFeatureById(int mblFeatureId) throws MobileDeviceManagementDAOException {
|
||||
PreparedStatement stmt = null;
|
||||
boolean status = false;
|
||||
Connection conn;
|
||||
try {
|
||||
conn = WindowsDAOFactory.getConnection();
|
||||
String sql = "DELETE FROM WIN_FEATURE WHERE ID = ?";
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setInt(1, mblFeatureId);
|
||||
stmt.execute();
|
||||
status = true;
|
||||
} catch (SQLException e) {
|
||||
throw new WindowsFeatureManagementDAOException(
|
||||
"Error occurred while deleting windows feature '" +
|
||||
mblFeatureId + "' from Windows database.", e);
|
||||
} finally {
|
||||
MobileDeviceManagementDAOUtil.cleanupResources(stmt, null);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteFeatureByCode(String mblFeatureCode) throws MobileDeviceManagementDAOException {
|
||||
PreparedStatement stmt = null;
|
||||
boolean status = false;
|
||||
Connection conn;
|
||||
try {
|
||||
conn = WindowsDAOFactory.getConnection();
|
||||
String sql = "DELETE FROM WIN_FEATURE WHERE CODE = ?";
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setString(1, mblFeatureCode);
|
||||
stmt.execute();
|
||||
status = true;
|
||||
} catch (SQLException e) {
|
||||
throw new WindowsFeatureManagementDAOException(
|
||||
"Error occurred while deleting windows feature '" +
|
||||
mblFeatureCode + "' from Windows database.", e);
|
||||
} finally {
|
||||
MobileDeviceManagementDAOUtil.cleanupResources(stmt, null);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MobileFeature getFeatureById(int mblFeatureId) throws MobileDeviceManagementDAOException {
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
Connection conn;
|
||||
try {
|
||||
conn = WindowsDAOFactory.getConnection();
|
||||
String sql = "SELECT ID, CODE, NAME, DESCRIPTION FROM WIN_FEATURE WHERE ID = ?";
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setInt(1, mblFeatureId);
|
||||
rs = stmt.executeQuery();
|
||||
MobileFeature mobileFeature = null;
|
||||
if (rs.next()) {
|
||||
mobileFeature = new MobileFeature();
|
||||
mobileFeature.setId(rs.getInt(WindowsPluginConstants.WINDOWS_FEATURE_ID));
|
||||
mobileFeature.setCode(rs.getString(WindowsPluginConstants.WINDOWS_FEATURE_CODE));
|
||||
mobileFeature.setName(rs.getString(WindowsPluginConstants.WINDOWS_FEATURE_NAME));
|
||||
mobileFeature.setDescription(rs.getString(WindowsPluginConstants.WINDOWS_FEATURE_DESCRIPTION));
|
||||
mobileFeature.setDeviceType(
|
||||
DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS);
|
||||
}
|
||||
return mobileFeature;
|
||||
} catch (SQLException e) {
|
||||
throw new WindowsFeatureManagementDAOException(
|
||||
"Error occurred while retrieving windows feature '" +
|
||||
mblFeatureId + "' from the Windows database.", e);
|
||||
} finally {
|
||||
MobileDeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public MobileFeature getFeatureByCode(String mblFeatureCode) throws MobileDeviceManagementDAOException {
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
Connection conn;
|
||||
try {
|
||||
conn = WindowsDAOFactory.getConnection();
|
||||
String sql = "SELECT ID, CODE, NAME, DESCRIPTION FROM WIN_FEATURE WHERE CODE = ?";
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setString(1, mblFeatureCode);
|
||||
rs = stmt.executeQuery();
|
||||
MobileFeature mobileFeature = null;
|
||||
if (rs.next()) {
|
||||
mobileFeature = new MobileFeature();
|
||||
mobileFeature.setId(rs.getInt(WindowsPluginConstants.WINDOWS_FEATURE_ID));
|
||||
mobileFeature.setCode(rs.getString(WindowsPluginConstants.WINDOWS_FEATURE_CODE));
|
||||
mobileFeature.setName(rs.getString(WindowsPluginConstants.WINDOWS_FEATURE_NAME));
|
||||
mobileFeature.setDescription(rs.getString(WindowsPluginConstants.WINDOWS_FEATURE_DESCRIPTION));
|
||||
mobileFeature.setDeviceType(
|
||||
DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS);
|
||||
}
|
||||
return mobileFeature;
|
||||
} catch (SQLException e) {
|
||||
throw new WindowsFeatureManagementDAOException(
|
||||
"Error occurred while retrieving windows feature '" +
|
||||
mblFeatureCode + "' from the Windows database.", e);
|
||||
} finally {
|
||||
MobileDeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MobileFeature> getFeatureByDeviceType(String deviceType) throws MobileDeviceManagementDAOException {
|
||||
return this.getAllFeatures();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MobileFeature> getAllFeatures() throws MobileDeviceManagementDAOException {
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
Connection conn;
|
||||
List<MobileFeature> features = new ArrayList<>();
|
||||
try {
|
||||
conn = WindowsDAOFactory.getConnection();
|
||||
String sql = "SELECT ID, CODE, NAME, DESCRIPTION FROM WIN_FEATURE";
|
||||
stmt = conn.prepareStatement(sql);
|
||||
rs = stmt.executeQuery();
|
||||
MobileFeature mobileFeature;
|
||||
while (rs.next()) {
|
||||
mobileFeature = new MobileFeature();
|
||||
mobileFeature.setId(rs.getInt(WindowsPluginConstants.WINDOWS_FEATURE_ID));
|
||||
mobileFeature.setCode(rs.getString(WindowsPluginConstants.WINDOWS_FEATURE_CODE));
|
||||
mobileFeature.setName(rs.getString(WindowsPluginConstants.WINDOWS_FEATURE_NAME));
|
||||
mobileFeature.setDescription(rs.getString(WindowsPluginConstants.WINDOWS_FEATURE_DESCRIPTION));
|
||||
mobileFeature.setDeviceType(
|
||||
DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS);
|
||||
features.add(mobileFeature);
|
||||
}
|
||||
return features;
|
||||
} catch (SQLException e) {
|
||||
throw new WindowsFeatureManagementDAOException("Error occurred while retrieving all " +
|
||||
"windows features from the Windows database.", e);
|
||||
} finally {
|
||||
MobileDeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,48 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.impl.windows.util;
|
||||
|
||||
/**
|
||||
* Define constance used by Windows plugin.
|
||||
*/
|
||||
public class WindowsPluginConstants {
|
||||
|
||||
//properties related to database table WINDOWS_DEVICE
|
||||
public static final String DEVICE_ID = "DEVICE_ID";
|
||||
public static final String CHANNEL_URI = "CHANNEL_URI";
|
||||
public static final String DEVICE_INFO = "DEVICE_INFO";
|
||||
public static final String IMEI = "IMEI";
|
||||
public static final String IMSI = "IMSI";
|
||||
public static final String OS_VERSION = "OS_VERSION";
|
||||
public static final String DEVICE_MODEL = "DEVICE_MODEL";
|
||||
public static final String VENDOR = "VENDOR";
|
||||
public static final String LATITUDE = "LATITUDE";
|
||||
public static final String LONGITUDE = "LONGITUDE";
|
||||
public static final String SERIAL = "SERIAL";
|
||||
public static final String MAC_ADDRESS = "MAC_ADDRESS";
|
||||
public static final String DEVICE_NAME = "DEVICE_NAME";
|
||||
|
||||
//Properties related to WIN_FEATURE table
|
||||
public static final String WINDOWS_FEATURE_ID = "ID";
|
||||
public static final String WINDOWS_FEATURE_CODE = "CODE";
|
||||
public static final String WINDOWS_FEATURE_NAME = "NAME";
|
||||
public static final String WINDOWS_FEATURE_DESCRIPTION = "DESCRIPTION";
|
||||
|
||||
|
||||
}
|
||||
@ -1,58 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
* /
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.impl.windows.util;
|
||||
|
||||
import org.wso2.carbon.device.mgt.common.license.mgt.License;
|
||||
import org.wso2.carbon.device.mgt.mobile.impl.windows.WindowsDeviceManagementService;
|
||||
|
||||
/**
|
||||
* Contains utility method used by Windows plugin.
|
||||
*/
|
||||
public class WindowsPluginUtils {
|
||||
|
||||
public static License getDefaultLicense() {
|
||||
License license = new License();
|
||||
license.setName(WindowsDeviceManagementService.DEVICE_TYPE_WINDOWS);
|
||||
license.setLanguage("en_US");
|
||||
license.setVersion("1.0.0");
|
||||
license.setText("This End User License Agreement (\"Agreement\") is a legal agreement between you (\"You\") " +
|
||||
"and WSO2, Inc., regarding the enrollment of Your personal mobile device (\"Device\") in SoR's " +
|
||||
"mobile device management program, and the loading to and removal from Your Device and Your use " +
|
||||
"of certain applications and any associated software and user documentation, whether provided in " +
|
||||
"\"online\" or electronic format, used in connection with the operation of or provision of services " +
|
||||
"to WSO2, Inc., BY SELECTING \"I ACCEPT\" DURING INSTALLATION, YOU ARE ENROLLING YOUR DEVICE, AND " +
|
||||
"THEREBY AUTHORIZING SOR OR ITS AGENTS TO INSTALL, UPDATE AND REMOVE THE APPS FROM YOUR DEVICE AS " +
|
||||
"DESCRIBED IN THIS AGREEMENT. YOU ARE ALSO EXPLICITLY ACKNOWLEDGING AND AGREEING THAT (1) THIS IS " +
|
||||
"A BINDING CONTRACT AND (2) YOU HAVE READ AND AGREE TO THE TERMS OF THIS AGREEMENT.\n" +
|
||||
"\n" +
|
||||
"IF YOU DO NOT ACCEPT THESE TERMS, DO NOT ENROLL YOUR DEVICE AND DO NOT PROCEED ANY FURTHER.\n" +
|
||||
"\n" +
|
||||
"You agree that: (1) You understand and agree to be bound by the terms and conditions contained " +
|
||||
"in this Agreement, and (2) You are at least 21 years old and have the legal capacity to enter " +
|
||||
"into this Agreement as defined by the laws of Your jurisdiction. SoR shall have the right, " +
|
||||
"without prior notice, to terminate or suspend (i) this Agreement, (ii) the enrollment of Your " +
|
||||
"Device, or (iii) the functioning of the Apps in the event of a violation of this Agreement or " +
|
||||
"the cessation of Your relationship with SoR (including termination of Your employment if You are " +
|
||||
"an employee or expiration or termination of Your applicable franchise or supply agreement if You " +
|
||||
"are a franchisee of or supplier to the WSO2 WSO2, Inc., system). SoR expressly reserves all " +
|
||||
"rights not expressly granted herein.");
|
||||
return license;
|
||||
}
|
||||
}
|
||||
@ -1,50 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.impl.windows.util;
|
||||
|
||||
import org.wso2.carbon.device.mgt.common.Feature;
|
||||
import org.wso2.carbon.device.mgt.mobile.dto.MobileDevice;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* Contains utility methods which are used by Windows plugin.
|
||||
*/
|
||||
public class WindowsUtils {
|
||||
|
||||
public static MobileDevice loadMobileDevices(ResultSet rs) throws SQLException {
|
||||
MobileDevice mobileDevice = new MobileDevice();
|
||||
mobileDevice.setMobileDeviceId(rs.getString(WindowsPluginConstants.DEVICE_ID));
|
||||
mobileDevice.setImei(rs.getString(WindowsPluginConstants.IMEI));
|
||||
mobileDevice.setImsi(rs.getString(WindowsPluginConstants.IMSI));
|
||||
mobileDevice.setModel(rs.getString(WindowsPluginConstants.DEVICE_MODEL));
|
||||
mobileDevice.setVendor(rs.getString(WindowsPluginConstants.VENDOR));
|
||||
mobileDevice.setLatitude(rs.getString(WindowsPluginConstants.LATITUDE));
|
||||
mobileDevice.setLongitude(rs.getString(WindowsPluginConstants.LONGITUDE));
|
||||
mobileDevice.setSerial(rs.getString(WindowsPluginConstants.SERIAL));
|
||||
mobileDevice.setOsVersion(rs.getString(WindowsPluginConstants.LATITUDE));
|
||||
return mobileDevice;
|
||||
}
|
||||
|
||||
public static Feature getMobileFeature() {
|
||||
Feature feature = new Feature();
|
||||
return feature;
|
||||
}
|
||||
}
|
||||
@ -19,7 +19,6 @@
|
||||
package org.wso2.carbon.device.mgt.mobile.internal;
|
||||
|
||||
import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
|
||||
import org.wso2.carbon.device.mgt.mobile.impl.android.gcm.GCMService;
|
||||
import org.wso2.carbon.registry.core.service.RegistryService;
|
||||
|
||||
/**
|
||||
@ -29,7 +28,6 @@ public class MobileDeviceManagementDataHolder {
|
||||
|
||||
private RegistryService registryService;
|
||||
private DeviceManagementService androidDeviceManagementService;
|
||||
private GCMService gcmService;
|
||||
|
||||
private static MobileDeviceManagementDataHolder thisInstance = new MobileDeviceManagementDataHolder();
|
||||
|
||||
@ -57,11 +55,4 @@ public class MobileDeviceManagementDataHolder {
|
||||
this.androidDeviceManagementService = androidDeviceManagementService;
|
||||
}
|
||||
|
||||
public GCMService getGCMService() {
|
||||
return gcmService;
|
||||
}
|
||||
|
||||
public void setGCMService(GCMService gcmService) {
|
||||
this.gcmService = gcmService;
|
||||
}
|
||||
}
|
||||
|
||||
@ -23,20 +23,13 @@ import org.apache.commons.logging.LogFactory;
|
||||
import org.osgi.framework.BundleContext;
|
||||
import org.osgi.framework.ServiceRegistration;
|
||||
import org.osgi.service.component.ComponentContext;
|
||||
import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
|
||||
import org.wso2.carbon.device.mgt.mobile.common.MobileDeviceMgtPluginException;
|
||||
import org.wso2.carbon.device.mgt.mobile.config.MobileDeviceConfigurationManager;
|
||||
import org.wso2.carbon.device.mgt.mobile.config.MobileDeviceManagementConfig;
|
||||
import org.wso2.carbon.device.mgt.mobile.config.datasource.MobileDataSourceConfig;
|
||||
import org.wso2.carbon.device.mgt.mobile.dao.AbstractMobileDeviceManagementDAOFactory;
|
||||
import org.wso2.carbon.device.mgt.mobile.dao.util.MobileDeviceManagementDAOUtil;
|
||||
import org.wso2.carbon.device.mgt.mobile.impl.android.AndroidDeviceManagementService;
|
||||
import org.wso2.carbon.device.mgt.mobile.impl.android.AndroidPolicyMonitoringService;
|
||||
import org.wso2.carbon.device.mgt.mobile.impl.android.gcm.GCMService;
|
||||
import org.wso2.carbon.device.mgt.mobile.impl.windows.WindowsDeviceManagementService;
|
||||
import org.wso2.carbon.device.mgt.mobile.impl.windows.WindowsPolicyMonitoringService;
|
||||
import org.wso2.carbon.ndatasource.core.DataSourceService;
|
||||
import org.wso2.carbon.policy.mgt.common.spi.PolicyMonitoringService;
|
||||
import org.wso2.carbon.registry.core.service.RegistryService;
|
||||
|
||||
import java.util.Map;
|
||||
@ -60,8 +53,6 @@ import java.util.Map;
|
||||
*/
|
||||
public class MobileDeviceManagementServiceComponent {
|
||||
|
||||
private ServiceRegistration androidServiceRegRef;
|
||||
private ServiceRegistration windowsServiceRegRef;
|
||||
private ServiceRegistration gcmServiceRegRef;
|
||||
|
||||
private static final Log log = LogFactory.getLog(MobileDeviceManagementServiceComponent.class);
|
||||
@ -100,30 +91,7 @@ public class MobileDeviceManagementServiceComponent {
|
||||
log.error("Exception occurred while initializing mobile device management database schema", e);
|
||||
}
|
||||
}
|
||||
DeviceManagementService androidDeviceManagementService = new AndroidDeviceManagementService();
|
||||
GCMService gcmService = new GCMService();
|
||||
|
||||
androidServiceRegRef =
|
||||
bundleContext.registerService(DeviceManagementService.class.getName(),
|
||||
androidDeviceManagementService, null);
|
||||
windowsServiceRegRef =
|
||||
bundleContext.registerService(DeviceManagementService.class.getName(),
|
||||
new WindowsDeviceManagementService(), null);
|
||||
|
||||
gcmServiceRegRef =
|
||||
bundleContext.registerService(GCMService.class.getName(), gcmService, null);
|
||||
|
||||
|
||||
// Policy management service
|
||||
|
||||
bundleContext.registerService(PolicyMonitoringService.class,
|
||||
new AndroidPolicyMonitoringService(), null);
|
||||
bundleContext.registerService(PolicyMonitoringService.class,
|
||||
new WindowsPolicyMonitoringService(), null);
|
||||
|
||||
MobileDeviceManagementDataHolder.getInstance().setAndroidDeviceManagementService(
|
||||
androidDeviceManagementService);
|
||||
MobileDeviceManagementDataHolder.getInstance().setGCMService(gcmService);
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Mobile Device Management Service Component has been successfully activated");
|
||||
}
|
||||
@ -137,12 +105,6 @@ public class MobileDeviceManagementServiceComponent {
|
||||
log.debug("De-activating Mobile Device Management Service Component");
|
||||
}
|
||||
try {
|
||||
if (androidServiceRegRef != null) {
|
||||
androidServiceRegRef.unregister();
|
||||
}
|
||||
if (windowsServiceRegRef != null) {
|
||||
windowsServiceRegRef.unregister();
|
||||
}
|
||||
if (gcmServiceRegRef != null) {
|
||||
gcmServiceRegRef.unregister();
|
||||
}
|
||||
|
||||
@ -27,7 +27,7 @@ import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||
import org.wso2.carbon.device.mgt.common.configuration.mgt.TenantConfiguration;
|
||||
import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration;
|
||||
import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementService;
|
||||
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
|
||||
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
|
||||
@ -165,7 +165,7 @@ public class WindowsAPIUtils {
|
||||
getDeviceManagementService().updateOperation(deviceIdentifier, operation);
|
||||
}
|
||||
|
||||
public static TenantConfiguration getTenantConfiguration() throws DeviceManagementException {
|
||||
public static PlatformConfiguration getTenantConfiguration() throws DeviceManagementException {
|
||||
return getDeviceManagementService().getConfiguration(
|
||||
DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS);
|
||||
}
|
||||
|
||||
@ -22,7 +22,7 @@ import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiResponse;
|
||||
import io.swagger.annotations.ApiResponses;
|
||||
import org.wso2.carbon.device.mgt.common.configuration.mgt.TenantConfiguration;
|
||||
import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.common.exceptions.WindowsConfigurationException;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.common.util.Message;
|
||||
|
||||
@ -58,7 +58,7 @@ public interface ConfigurationMgtService {
|
||||
@ApiResponse(code = 201, message = "Windows platform configuration saved successfully"),
|
||||
@ApiResponse(code = 500, message = "Internal Server Error")
|
||||
})
|
||||
Message ConfigureSettings(TenantConfiguration configuration) throws WindowsConfigurationException;
|
||||
Message ConfigureSettings(PlatformConfiguration configuration) throws WindowsConfigurationException;
|
||||
|
||||
/**
|
||||
* Retrieve Tenant configurations according to the device type.
|
||||
@ -71,13 +71,13 @@ public interface ConfigurationMgtService {
|
||||
httpMethod = "GET",
|
||||
value = "Getting Windows Platform Configurations",
|
||||
notes = "Get the Windows platform configuration details using this REST API",
|
||||
response = TenantConfiguration.class
|
||||
response = PlatformConfiguration.class
|
||||
)
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(code = 200, message = "Get Windows Configurations"),
|
||||
@ApiResponse(code = 500, message = "Server Error")
|
||||
})
|
||||
TenantConfiguration getConfiguration() throws WindowsConfigurationException;
|
||||
PlatformConfiguration getConfiguration() throws WindowsConfigurationException;
|
||||
|
||||
/**
|
||||
* Update Tenant Configurations for the specific Device type.
|
||||
@ -99,5 +99,5 @@ public interface ConfigurationMgtService {
|
||||
@ApiResponse(code = 500, message = "Error occurred while modifying configuration settings of " +
|
||||
"windows platform")
|
||||
})
|
||||
Message updateConfiguration(TenantConfiguration configuration) throws WindowsConfigurationException;
|
||||
Message updateConfiguration(PlatformConfiguration configuration) throws WindowsConfigurationException;
|
||||
}
|
||||
|
||||
@ -23,7 +23,8 @@ import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||
import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationEntry;
|
||||
import org.wso2.carbon.device.mgt.common.configuration.mgt.TenantConfiguration;
|
||||
import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration;
|
||||
import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration;
|
||||
import org.wso2.carbon.device.mgt.common.license.mgt.License;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.common.PluginConstants;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.common.exceptions.WindowsConfigurationException;
|
||||
@ -54,7 +55,7 @@ public class ConfigurationMgtServiceImpl {
|
||||
* @throws WindowsConfigurationException
|
||||
*/
|
||||
@POST
|
||||
public Message ConfigureSettings(TenantConfiguration configuration) throws WindowsConfigurationException {
|
||||
public Message ConfigureSettings(PlatformConfiguration configuration) throws WindowsConfigurationException {
|
||||
Message responseMsg = new Message();
|
||||
ConfigurationEntry licenseEntry = null;
|
||||
String message;
|
||||
@ -106,15 +107,15 @@ public class ConfigurationMgtServiceImpl {
|
||||
* @throws WindowsConfigurationException
|
||||
*/
|
||||
@GET
|
||||
public TenantConfiguration getConfiguration() throws WindowsConfigurationException {
|
||||
public PlatformConfiguration getConfiguration() throws WindowsConfigurationException {
|
||||
String msg;
|
||||
TenantConfiguration tenantConfiguration = null;
|
||||
PlatformConfiguration PlatformConfiguration = null;
|
||||
try {
|
||||
if (WindowsAPIUtils.getDeviceManagementService().
|
||||
getConfiguration(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS) != null) {
|
||||
tenantConfiguration = WindowsAPIUtils.getDeviceManagementService().
|
||||
PlatformConfiguration = WindowsAPIUtils.getDeviceManagementService().
|
||||
getConfiguration(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS);
|
||||
List<ConfigurationEntry> configs = tenantConfiguration.getConfiguration();
|
||||
List<ConfigurationEntry> configs = PlatformConfiguration.getConfiguration();
|
||||
ConfigurationEntry entry = new ConfigurationEntry();
|
||||
License license = WindowsAPIUtils.getDeviceManagementService().getLicense(
|
||||
DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS, PluginConstants.
|
||||
@ -124,7 +125,7 @@ public class ConfigurationMgtServiceImpl {
|
||||
entry.setName(PluginConstants.TenantConfigProperties.LICENSE_KEY);
|
||||
entry.setValue(license.getText());
|
||||
configs.add(entry);
|
||||
tenantConfiguration.setConfiguration(configs);
|
||||
PlatformConfiguration.setConfiguration(configs);
|
||||
}
|
||||
}
|
||||
} catch (DeviceManagementException e) {
|
||||
@ -132,7 +133,7 @@ public class ConfigurationMgtServiceImpl {
|
||||
log.error(msg, e);
|
||||
throw new WindowsConfigurationException(msg, e);
|
||||
}
|
||||
return tenantConfiguration;
|
||||
return PlatformConfiguration;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -143,7 +144,7 @@ public class ConfigurationMgtServiceImpl {
|
||||
* @throws WindowsConfigurationException
|
||||
*/
|
||||
@PUT
|
||||
public Message updateConfiguration(TenantConfiguration configuration) throws WindowsConfigurationException {
|
||||
public Message updateConfiguration(PlatformConfiguration configuration) throws WindowsConfigurationException {
|
||||
String message;
|
||||
Message responseMsg = new Message();
|
||||
ConfigurationEntry licenseEntry = null;
|
||||
|
||||
@ -32,7 +32,7 @@ import org.wso2.carbon.certificate.mgt.core.service.CertificateManagementService
|
||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||
import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationEntry;
|
||||
import org.wso2.carbon.device.mgt.common.configuration.mgt.TenantConfiguration;
|
||||
import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.common.PluginConstants;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.common.beans.CacheEntry;
|
||||
import org.wso2.carbon.mdm.mobileservices.windows.common.exceptions.CertificateGenerationException;
|
||||
@ -372,7 +372,7 @@ public class CertificateEnrollmentServiceImpl implements CertificateEnrollmentSe
|
||||
*/
|
||||
private List<ConfigurationEntry> getTenantConfigurationData() throws DeviceManagementException {
|
||||
if (WindowsAPIUtils.getTenantConfiguration() != null) {
|
||||
TenantConfiguration configuration = WindowsAPIUtils.getTenantConfiguration();
|
||||
PlatformConfiguration configuration = WindowsAPIUtils.getTenantConfiguration();
|
||||
return configuration.getConfiguration();
|
||||
} else {
|
||||
return null;
|
||||
|
||||
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* Licensed 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.
|
||||
*/
|
||||
.circle {
|
||||
background: none repeat scroll 0 0 #191919;
|
||||
border-radius: 50px;
|
||||
height: 50px;
|
||||
padding: 10px;
|
||||
width: 50px;
|
||||
color: #fff;
|
||||
}
|
||||
.padding-top-double {
|
||||
padding-top: 20px;
|
||||
}
|
||||
.padding-double {
|
||||
padding: 20px;
|
||||
}
|
||||
.grey {
|
||||
color: #333;
|
||||
}
|
||||
hr {
|
||||
display: block;
|
||||
height: 1px;
|
||||
border: 0;
|
||||
border-top: 1px solid #7f7f7f;
|
||||
margin: 1em 0;
|
||||
padding: 0;
|
||||
opacity: 0.2;
|
||||
}
|
||||
.light-grey {
|
||||
color: #7c7c7c;
|
||||
}
|
||||
.uppercase {
|
||||
text-transform: uppercase;
|
||||
}
|
||||
.grey-bg {
|
||||
background-color: #f6f4f4;
|
||||
}
|
||||
|
||||
.doc-link {
|
||||
background: #11375B;
|
||||
padding: 20px;
|
||||
color: white;
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
.doc-link a {
|
||||
color: white;
|
||||
}
|
||||
@ -16,7 +16,7 @@
|
||||
under the License.
|
||||
}}
|
||||
<div class="col-lg-12 margin-top-double">
|
||||
<h1 class="grey ">Windows Mobile</h1>
|
||||
<h1 class="grey">Windows Mobile</h1>
|
||||
<hr>
|
||||
</div>
|
||||
<div class="col-xs-12 col-sm-4 col-md-4 col-lg-4 padding-top">
|
||||
@ -24,28 +24,26 @@
|
||||
</div>
|
||||
|
||||
<div class="col-xs-12 col-sm-8 col-md-8 col-lg-8 padding-top">
|
||||
<h4 class="doc-link">Click <a href="https://docs.wso2.com/display/IoTS100/Windows"
|
||||
target="_blank">[ here ]</a> for latest instructions and troubleshooting.</h4>
|
||||
<h4 class="doc-link">Click <a href="https://docs.wso2.com/display/IoTS100/Windows" target="_blank">[ here ]</a> for
|
||||
latest instructions and troubleshooting.</h4>
|
||||
</div>
|
||||
|
||||
<div class="col-xs-12 col-sm-8 col-md-8 col-lg-8 padding-top">
|
||||
|
||||
<h3 class="uppercase">What it Does</h3>
|
||||
<hr>
|
||||
<hr />
|
||||
<p class="grey margin-top">Connect and manage your Windows device with WSO2 IoT Server.</p>
|
||||
<br>
|
||||
|
||||
<h3 class="uppercase">What You Need</h3>
|
||||
<hr>
|
||||
<ul class="list-unstyled">
|
||||
<li class="padding-top-double"><span class="circle">STEP 01</span> Windows
|
||||
Mobile.
|
||||
<li class="padding-top-double"><span class="circle">STEP 01</span> Windows Mobile.</li>
|
||||
<li class="padding-top-double"><span class="circle">STEP 02</span> Go ahead and click [Enroll
|
||||
Device].
|
||||
</li>
|
||||
<li class="padding-top-double"><span class="circle">STEP 02</span> Go ahead
|
||||
and click [Enroll Device].
|
||||
</li>
|
||||
<li class="padding-top-double"><span class="circle">STEP 03</span> Proceed
|
||||
to [Prepare] section.
|
||||
<li class="padding-top-double"><span class="circle">STEP 03</span> Proceed to [Prepare]
|
||||
section.
|
||||
</li>
|
||||
</ul>
|
||||
<br>
|
||||
@ -53,7 +51,7 @@
|
||||
<a href="#" class="download-link btn-operations"><i class="fw fw-mobile fw-inverse fw-lg"></i>
|
||||
Enroll Device</a>
|
||||
|
||||
<br/><br/>
|
||||
<br /><br />
|
||||
</div>
|
||||
|
||||
<div class="col-xs-12 col-sm-12 col-md-8 col-lg-12 padding-double grey-bg">
|
||||
@ -61,11 +59,8 @@
|
||||
<hr>
|
||||
<ul class="list-unstyled">
|
||||
<li class="padding-top-double"><span class="circle">01</span> Scan QR code.</li>
|
||||
<li class="padding-top-double"><span class="circle">02</span> Follow instructions in wizard.
|
||||
</li>
|
||||
<li class="padding-top-double"><span class="circle">03</span> Configure your workspace
|
||||
account
|
||||
</li>
|
||||
<li class="padding-top-double"><span class="circle">02</span> Follow instructions in wizard.</li>
|
||||
<li class="padding-top-double"><span class="circle">03</span> Configure your workspace account</li>
|
||||
</ul>
|
||||
<br>
|
||||
|
||||
@ -80,12 +75,12 @@
|
||||
</center>
|
||||
</div>
|
||||
|
||||
<br/>
|
||||
<br />
|
||||
|
||||
<div id="qr-code-modal"
|
||||
data-enrollment-url="{{@app.context}}/device/windows/enroll" class="hidden">
|
||||
|
||||
<div class="content">
|
||||
<div class="content">
|
||||
<div class="row">
|
||||
<div class="col-lg-5 col-md-6 col-centered">
|
||||
<h3>Scan QR code to start enrollment</h3>
|
||||
@ -100,60 +95,8 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{#zone "topCss"}}
|
||||
<style type="text/css">
|
||||
.circle {
|
||||
background: none repeat scroll 0 0 #191919;
|
||||
border-radius: 50px;
|
||||
height: 50px;
|
||||
padding: 10px;
|
||||
width: 50px;
|
||||
color: #fff;
|
||||
}
|
||||
.padding-top-double {
|
||||
padding-top: 20px;
|
||||
}
|
||||
.padding-double {
|
||||
padding: 20px;
|
||||
}
|
||||
.grey {
|
||||
color: #333;
|
||||
}
|
||||
hr {
|
||||
display: block;
|
||||
height: 1px;
|
||||
border: 0;
|
||||
border-top: 1px solid #7f7f7f;
|
||||
margin: 1em 0;
|
||||
padding: 0;
|
||||
opacity: 0.2;
|
||||
}
|
||||
.light-grey {
|
||||
color: #7c7c7c;
|
||||
}
|
||||
.uppercase {
|
||||
text-transform: uppercase;
|
||||
}
|
||||
.grey-bg {
|
||||
background-color: #f6f4f4;
|
||||
}
|
||||
|
||||
.doc-link {
|
||||
background: #11375B;
|
||||
padding: 20px;
|
||||
color: white;
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
.doc-link a {
|
||||
color: white;
|
||||
}
|
||||
</style>
|
||||
{{/zone}}
|
||||
|
||||
{{#zone "bottomJs"}}
|
||||
<script type="text/javascript">
|
||||
|
||||
$(".download-link").click(function () {
|
||||
toggleEnrollment();
|
||||
});
|
||||
@ -163,6 +106,9 @@
|
||||
generateQRCode(".modalpopup-content .qr-code");
|
||||
showPopup();
|
||||
}
|
||||
|
||||
</script>
|
||||
{{/zone}}
|
||||
|
||||
{{#zone "topCss"}}
|
||||
{{css "css/styles.css"}}
|
||||
{{/zone}}
|
||||
@ -21,7 +21,7 @@ package org.wso2.carbon.device.mgt.mobile.windows.impl;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.device.mgt.common.*;
|
||||
import org.wso2.carbon.device.mgt.common.configuration.mgt.TenantConfiguration;
|
||||
import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration;
|
||||
import org.wso2.carbon.device.mgt.common.license.mgt.License;
|
||||
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException;
|
||||
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManager;
|
||||
@ -79,7 +79,7 @@ public class WindowsDeviceManager implements DeviceManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean saveConfiguration(TenantConfiguration tenantConfiguration)
|
||||
public boolean saveConfiguration(PlatformConfiguration tenantConfiguration)
|
||||
throws DeviceManagementException {
|
||||
boolean status;
|
||||
Resource resource;
|
||||
@ -91,7 +91,7 @@ public class WindowsDeviceManager implements DeviceManager {
|
||||
DeviceManagementConstants.
|
||||
MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS);
|
||||
StringWriter writer = new StringWriter();
|
||||
JAXBContext context = JAXBContext.newInstance(TenantConfiguration.class);
|
||||
JAXBContext context = JAXBContext.newInstance(PlatformConfiguration.class);
|
||||
Marshaller marshaller = context.createMarshaller();
|
||||
marshaller.marshal(tenantConfiguration, writer);
|
||||
|
||||
@ -114,7 +114,7 @@ public class WindowsDeviceManager implements DeviceManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public TenantConfiguration getConfiguration() throws DeviceManagementException {
|
||||
public PlatformConfiguration getConfiguration() throws DeviceManagementException {
|
||||
Resource resource;
|
||||
try {
|
||||
String windowsTenantRegistryPath =
|
||||
@ -122,9 +122,9 @@ public class WindowsDeviceManager implements DeviceManager {
|
||||
MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS);
|
||||
resource = MobileDeviceManagementUtil.getRegistryResource(windowsTenantRegistryPath);
|
||||
if (resource != null) {
|
||||
JAXBContext context = JAXBContext.newInstance(TenantConfiguration.class);
|
||||
JAXBContext context = JAXBContext.newInstance(PlatformConfiguration.class);
|
||||
Unmarshaller unmarshaller = context.createUnmarshaller();
|
||||
return (TenantConfiguration) unmarshaller.unmarshal(
|
||||
return (PlatformConfiguration) unmarshaller.unmarshal(
|
||||
new StringReader(new String((byte[]) resource.getContent(), Charset.
|
||||
forName(MobilePluginConstants.CHARSET_UTF8))));
|
||||
}
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
-- -----------------------------------------------------
|
||||
-- Table `ANDROID_DEVICE`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS ANDROID_SENSE_DEVICE (
|
||||
CREATE TABLE ANDROID_SENSE_DEVICE (
|
||||
ANDROID_DEVICE_ID VARCHAR(45) NOT NULL ,
|
||||
DEVICE_NAME VARCHAR(100) NULL DEFAULT NULL,
|
||||
PRIMARY KEY (ANDROID_DEVICE_ID) );
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
-- -----------------------------------------------------
|
||||
-- Table for `ARDUINO_DEVICE`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS ARDUINO_DEVICE (
|
||||
CREATE TABLE ARDUINO_DEVICE (
|
||||
ARDUINO_DEVICE_ID VARCHAR(45) NOT NULL ,
|
||||
DEVICE_NAME VARCHAR(100) NULL DEFAULT NULL,
|
||||
PRIMARY KEY (ARDUINO_DEVICE_ID) );
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
-- -----------------------------------------------------
|
||||
-- Table `RASPBERRYPI_DEVICE`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS RASPBERRYPI_DEVICE (
|
||||
CREATE TABLE RASPBERRYPI_DEVICE (
|
||||
RASPBERRYPI_DEVICE_ID VARCHAR(45) NOT NULL ,
|
||||
DEVICE_NAME VARCHAR(100) NULL DEFAULT NULL,
|
||||
PRIMARY KEY (RASPBERRYPI_DEVICE_ID) );
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
-- -----------------------------------------------------
|
||||
-- Table `FIREALARM_DEVICE`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS VIRTUAL_FIREALARM_DEVICE (
|
||||
CREATE TABLE VIRTUAL_FIREALARM_DEVICE (
|
||||
VIRTUAL_FIREALARM_DEVICE_ID VARCHAR(45) NOT NULL ,
|
||||
DEVICE_NAME VARCHAR(100) NULL DEFAULT NULL,
|
||||
PRIMARY KEY (VIRTUAL_FIREALARM_DEVICE_ID) );
|
||||
|
||||
@ -112,8 +112,8 @@
|
||||
<artifactItems>
|
||||
<artifactItem>
|
||||
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
||||
<artifactId>org.wso2.carbon.device.mgt.mobile.android.api
|
||||
</artifactId>
|
||||
<artifactId>org.wso2.carbon.device.mgt.mobile.android.api</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<type>war</type>
|
||||
<overWrite>true</overWrite>
|
||||
<outputDirectory>${project.build.directory}/maven-shared-archive-resources/webapps/
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
instructions.configure = \
|
||||
org.eclipse.equinox.p2.touchpoint.natives.mkdir(path:${installFolder}/../../deployment/server/webapps/);\
|
||||
org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.mobile.android_${feature.version}/webapps/,target:${installFolder}/../../deployment/server/webapps/,overwrite:true);\
|
||||
org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.mobile.android_${feature.version}/webapps/mdm-android-agent.war,target:${installFolder}/../../deployment/server/webapps/mdm-android-agent.war,overwrite:true);\
|
||||
org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.mobile.android_${feature.version}/jaggeryapps/,target:${installFolder}/../../deployment/server/jaggeryapps/,overwrite:true);\
|
||||
org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.mobile.android_${feature.version}/conf/mobile-config.xml,target:${installFolder}/../../conf/mobile-config.xml,overwrite:true);\
|
||||
org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.mobile.android_${feature.version}/dbscripts/plugins/,target:${installFolder}/../../../dbscripts/cdm/plugins/android,overwrite:true);\
|
||||
|
||||
Loading…
Reference in New Issue
Block a user