revert-dabc3590
mharindu 9 years ago
commit cbb1f44138

@ -263,11 +263,11 @@ public class MQTTAdapterListener implements MqttCallback, Runnable {
@Override
public void run() {
int connectionDuration = MQTTEventAdapterConstants.initialReconnectDuration;
while (!connectionSucceeded) {
try {
MQTTEventAdapterConstants.initialReconnectDuration = MQTTEventAdapterConstants.initialReconnectDuration
* MQTTEventAdapterConstants.reconnectionProgressionFactor;
Thread.sleep(MQTTEventAdapterConstants.initialReconnectDuration);
connectionDuration = connectionDuration * MQTTEventAdapterConstants.reconnectionProgressionFactor;
Thread.sleep(connectionDuration);
startListener();
connectionSucceeded = true;
log.info("MQTT Connection successful");

@ -48,7 +48,7 @@ public class MQTTEventAdapterConstants {
public static final int ADAPTER_CONF_DEFAULT_KEEP_ALIVE = 60000;
public static int initialReconnectDuration = 2000;
public static final int reconnectionProgressionFactor = 4;
public static final int reconnectionProgressionFactor = 2;
public static final String EMPTY_STRING = "";
public static final String GRANT_TYPE = "urn:ietf:params:oauth:grant-type:jwt-bearer refresh_token";

@ -203,10 +203,10 @@ public class XMPPAdapterListener implements Runnable {
@Override
public void run() {
while (!connectionSucceeded) {
int connectionDuration = XMPPEventAdapterConstants.initialReconnectDuration;
try {
XMPPEventAdapterConstants.initialReconnectDuration = XMPPEventAdapterConstants.initialReconnectDuration
* XMPPEventAdapterConstants.reconnectionProgressionFactor;
Thread.sleep(XMPPEventAdapterConstants.initialReconnectDuration);
connectionDuration = connectionDuration * XMPPEventAdapterConstants.reconnectionProgressionFactor;
Thread.sleep(connectionDuration);
startListener();
connectionSucceeded = true;
log.info("XMPP Connection successful");

@ -50,7 +50,7 @@ public class XMPPEventAdapterConstants {
public static final int DEFAULT_TIMEOUT_INTERVAL = 5000;
public static int initialReconnectDuration = 2000;
public static final int reconnectionProgressionFactor = 4;
public static final int reconnectionProgressionFactor = 2;
public static final String DEFAULT = "default";

@ -34,6 +34,9 @@ import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationException;
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroupConstants;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
import org.wso2.carbon.device.mgt.core.operation.mgt.CommandOperation;
import org.wso2.carbon.device.mgt.iot.util.ZipArchive;
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.constants.VirtualFireAlarmConstants;
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.exception.VirtualFirealarmDeviceMgtPluginException;
@ -121,6 +124,19 @@ public class VirtualFireAlarmServiceImpl implements VirtualFireAlarmService {
dynamicProperties.put(VirtualFireAlarmConstants.ADAPTER_TOPIC_PROPERTY, publishTopic);
APIUtil.getOutputEventAdapterService().publish(VirtualFireAlarmConstants.MQTT_ADAPTER_NAME,
dynamicProperties, encryptedMsg);
Operation commandOp = new CommandOperation();
commandOp.setCode("buzz");
commandOp.setType(Operation.Type.COMMAND);
commandOp.setEnabled(true);
commandOp.setPayLoad(encryptedMsg);
Properties props = new Properties();
props.setProperty(VirtualFireAlarmConstants.MQTT_ADAPTER_TOPIC_PROPERTY_NAME, publishTopic);
commandOp.setProperties(props);
List<DeviceIdentifier> deviceIdentifiers = new ArrayList<>();
deviceIdentifiers.add(new DeviceIdentifier(VirtualFireAlarmConstants.DEVICE_TYPE, deviceId));
APIUtil.getDeviceManagementService().addOperation(VirtualFireAlarmConstants.DEVICE_TYPE, commandOp, deviceIdentifiers);
break;
}
return Response.ok().build();
@ -131,6 +147,10 @@ public class VirtualFireAlarmServiceImpl implements VirtualFireAlarmService {
String errorMsg = "Preparing Secure payload failed for device - [" + deviceId + "]";
log.error(errorMsg);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
} catch (OperationManagementException e) {
String msg = "Error occurred while executing command operation upon ringing the buzzer";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
}
}

@ -88,7 +88,11 @@
org.wso2.carbon.device.mgt.analytics.data.publisher.service,
org.wso2.carbon.event.input.adapter.core,
org.wso2.carbon.event.input.adapter.core.exception,
org.jivesoftware.smack.*
org.jivesoftware.smack.*,
javax.xml.bind,
javax.xml.bind.annotation,
javax.xml.parsers,
org.w3c.dom
</Import-Package>
<Export-Package>
!org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.internal,

@ -90,4 +90,6 @@ public class VirtualFireAlarmConstants {
+ "mqtt.properties";
public static final String XMPP_CONFIG_LOCATION = CarbonUtils.getEtcCarbonConfigDirPath() + File.separator
+ "xmpp.properties";
public static final String MQTT_ADAPTER_TOPIC_PROPERTY_NAME = "mqtt.adapter.topic";
}

@ -25,10 +25,15 @@ import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager;
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig;
import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.constants.VirtualFireAlarmConstants;
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.internal.config.VirtualFireAlarmConfig;
import java.util.HashMap;
import java.util.Map;
public class VirtualFireAlarmManagerService implements DeviceManagementService {
private DeviceManager deviceManager;
private PushNotificationConfig pushNotificationConfig;
@Override
public String getType() {
@ -38,6 +43,18 @@ public class VirtualFireAlarmManagerService implements DeviceManagementService {
@Override
public void init() throws DeviceManagementException {
this.deviceManager = new VirtualFireAlarmManager();
this.pushNotificationConfig = this.populatePushNotificationConfig();
}
private PushNotificationConfig populatePushNotificationConfig() {
org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.internal.config.PushNotificationConfig sourceConfig =
VirtualFireAlarmConfig.getInstance().getPushNotificationConfig();
Map<String, String> staticProps = new HashMap<>();
for (org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.internal.config.PushNotificationConfig.Property
property : sourceConfig.getProperties()) {
staticProps.put(property.getName(), property.getValue());
}
return new PushNotificationConfig("MQTT", staticProps);
}
@Override
@ -57,7 +74,7 @@ public class VirtualFireAlarmManagerService implements DeviceManagementService {
@Override
public PushNotificationConfig getPushNotificationConfig() {
return null;
return pushNotificationConfig;
}
}

@ -32,6 +32,7 @@ import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.impl.VirtualFireAl
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.impl.util.VirtualFireAlarmUtils;
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.impl.util.VirtualFirealarmSecurityManager;
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.impl.util.VirtualFirealarmStartupListener;
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.internal.config.VirtualFireAlarmConfig;
import org.wso2.carbon.event.input.adapter.core.InputEventAdapterService;
import org.wso2.carbon.event.output.adapter.core.OutputEventAdapterService;
@ -74,6 +75,9 @@ public class VirtualFirealarmManagementServiceComponent {
log.debug("Activating Virtual Firealarm Device Management Service Component");
}
try {
/* Initializing Virtual Fire Alarm Configuration */
VirtualFireAlarmConfig.init();
VirtualFireAlarmManagerService virtualFireAlarmManagerService = new VirtualFireAlarmManagerService();
BundleContext bundleContext = ctx.getBundleContext();
firealarmServiceRegRef = bundleContext.registerService(DeviceManagementService.class.getName()

@ -0,0 +1,41 @@
/*
* Copyright (c) 2014, 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.iot.virtualfirealarm.plugin.internal.config;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
/**
* Class for holding data source configuration in malformed-cdm-config-no-mgt-repo.xml at parsing
* with JAXB.
*/
@XmlRootElement(name = "DataSourceConfiguration")
public class DataSourceConfig {
private JNDILookupDefinition jndiLookupDefinition;
@XmlElement(name = "JndiLookupDefinition", required = true)
public JNDILookupDefinition getJndiLookupDefinition() {
return jndiLookupDefinition;
}
public void setJndiLookupDefinition(JNDILookupDefinition jndiLookupDefinition) {
this.jndiLookupDefinition = jndiLookupDefinition;
}
}

@ -0,0 +1,40 @@
/*
* Copyright (c) 2014, 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.iot.virtualfirealarm.plugin.internal.config;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
/**
* Class for holding management repository data.
*/
@XmlRootElement(name = "ManagementRepository")
public class DeviceManagementConfigRepository {
private DataSourceConfig dataSourceConfig;
@XmlElement(name = "DataSourceConfiguration", required = true)
public DataSourceConfig getDataSourceConfig() {
return dataSourceConfig;
}
public void setDataSourceConfig(DataSourceConfig dataSourceConfig) {
this.dataSourceConfig = dataSourceConfig;
}
}

@ -0,0 +1,79 @@
/*
* Copyright (c) 2014, 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.iot.virtualfirealarm.plugin.internal.config;
import javax.xml.bind.annotation.*;
import java.util.List;
/**
* Class for hold JndiLookupDefinition of rss-manager.xml at parsing with JAXB.
*/
@XmlRootElement(name = "JndiLookupDefinition")
public class JNDILookupDefinition {
private String jndiName;
private List<JNDIProperty> jndiProperties;
@XmlElement(name = "Name", required = false)
public String getJndiName() {
return jndiName;
}
public void setJndiName(String jndiName) {
this.jndiName = jndiName;
}
@XmlElementWrapper(name = "Environment", required = false)
@XmlElement(name = "Property", nillable = false)
public List<JNDIProperty> getJndiProperties() {
return jndiProperties;
}
public void setJndiProperties(List<JNDIProperty> jndiProperties) {
this.jndiProperties = jndiProperties;
}
@XmlRootElement(name = "Property")
public static class JNDIProperty {
private String name;
private String value;
@XmlAttribute(name = "Name")
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@XmlValue
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
}
}

@ -0,0 +1,65 @@
/*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.internal.config;
import javax.xml.bind.annotation.*;
import java.util.List;
@XmlRootElement(name = "PushNotificationConfiguration")
public class PushNotificationConfig {
private List<Property> properties;
@XmlElementWrapper(name = "Properties", required = true)
@XmlElement(name = "Property", required = true)
public List<Property> getProperties() {
return properties;
}
public void setProperties(List<Property> properties) {
this.properties = properties;
}
@XmlRootElement(name = "Property")
public static class Property {
private String name;
private String value;
@XmlAttribute(name = "Name", required = true)
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@XmlValue
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
}
}

@ -0,0 +1,93 @@
/*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.internal.config;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.w3c.dom.Document;
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.internal.config.exception.InvalidConfigurationStateException;
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.internal.config.exception.VirtualFireAlarmConfigurationException;
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.internal.util.VirtualFireAlarmUtil;
import org.wso2.carbon.utils.CarbonUtils;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import java.io.File;
@XmlRootElement(name = "DeviceManagementConfiguration")
public class VirtualFireAlarmConfig {
private DeviceManagementConfigRepository deviceManagementConfigRepository;
private PushNotificationConfig pushNotificationConfig;
private static VirtualFireAlarmConfig config;
private static final Log log = LogFactory.getLog(VirtualFireAlarmConfig.class);
private static final String VIRTUAL_FIRE_ALARM_CONFIG_PATH =
CarbonUtils.getEtcCarbonConfigDirPath() + File.separator + "device-mgt-plugins" + File.separator +
"virtual-fire-alarm" + File.separator + "virtual-fire-alarm-config.xml";
private VirtualFireAlarmConfig() {
}
public static VirtualFireAlarmConfig getInstance() {
if (config == null) {
throw new InvalidConfigurationStateException("Webapp Authenticator Configuration is not " +
"initialized properly");
}
return config;
}
@XmlElement(name = "ManagementRepository", required = true)
public DeviceManagementConfigRepository getDeviceManagementConfigRepository() {
return deviceManagementConfigRepository;
}
public void setDeviceManagementConfigRepository(DeviceManagementConfigRepository deviceManagementConfigRepository) {
this.deviceManagementConfigRepository = deviceManagementConfigRepository;
}
@XmlElement(name = "PushNotificationConfiguration", required = false)
public PushNotificationConfig getPushNotificationConfig() {
return pushNotificationConfig;
}
public void setPushNotificationConfig(PushNotificationConfig pushNotificationConfig) {
this.pushNotificationConfig = pushNotificationConfig;
}
public static void init() throws VirtualFireAlarmConfigurationException {
try {
File authConfig = new File(VirtualFireAlarmConfig.VIRTUAL_FIRE_ALARM_CONFIG_PATH);
Document doc = VirtualFireAlarmUtil.convertToDocument(authConfig);
/* Un-marshaling Webapp Authenticator configuration */
JAXBContext ctx = JAXBContext.newInstance(VirtualFireAlarmConfig.class);
Unmarshaller unmarshaller = ctx.createUnmarshaller();
//unmarshaller.setSchema(getSchema());
config = (VirtualFireAlarmConfig) unmarshaller.unmarshal(doc);
} catch (JAXBException e) {
throw new VirtualFireAlarmConfigurationException("Error occurred while un-marshalling Virtual Fire Alarm " +
" Config", e);
}
}
}

@ -0,0 +1,53 @@
/*
* 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.iot.virtualfirealarm.plugin.internal.config.exception;
public class InvalidConfigurationStateException extends RuntimeException {
private static final long serialVersionUID = -3151279411229070297L;
public InvalidConfigurationStateException(int errorCode, String message) {
super(message);
}
public InvalidConfigurationStateException(int errorCode, String message, Throwable cause) {
super(message, cause);
}
public InvalidConfigurationStateException(String msg, Exception nestedEx) {
super(msg, nestedEx);
}
public InvalidConfigurationStateException(String message, Throwable cause) {
super(message, cause);
}
public InvalidConfigurationStateException(String msg) {
super(msg);
}
public InvalidConfigurationStateException() {
super();
}
public InvalidConfigurationStateException(Throwable cause) {
super(cause);
}
}

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

@ -0,0 +1,43 @@
/*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.internal.util;
import org.w3c.dom.Document;
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.internal.config.exception.VirtualFireAlarmConfigurationException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import java.io.File;
public class VirtualFireAlarmUtil {
public static Document convertToDocument(File file) throws VirtualFireAlarmConfigurationException {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
try {
DocumentBuilder docBuilder = factory.newDocumentBuilder();
return docBuilder.parse(file);
} catch (Exception e) {
throw new VirtualFireAlarmConfigurationException("Error occurred while parsing file, while converting " +
"to a org.w3c.dom.Document", e);
}
}
}

@ -24,7 +24,6 @@ import com.google.gson.JsonParser;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
@ -35,7 +34,6 @@ import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
import org.wso2.carbon.device.mgt.core.app.mgt.ApplicationManagementProviderService;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
import org.wso2.carbon.device.mgt.mobile.android.impl.gcm.GCMService;
import org.wso2.carbon.policy.mgt.common.monitor.PolicyComplianceException;
import org.wso2.carbon.policy.mgt.core.PolicyManagerService;
@ -80,16 +78,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;
@ -108,17 +106,19 @@ public class AndroidAPIUtils {
AndroidDeviceUtils deviceUtils = new AndroidDeviceUtils();
DeviceIDHolder deviceIDHolder = deviceUtils.validateDeviceIdentifiers(deviceIDs,
message, responseMediaType);
int status = getDeviceManagementService().addOperation(operation, deviceIDHolder.getValidDeviceIDList());
if (status > 0) {
GCMService gcmService = getGCMService();
if (gcmService.isGCMEnabled()) {
List<Device> devices = new ArrayList<Device>();
for (DeviceIdentifier deviceIdentifier : deviceIDHolder.getValidDeviceIDList()) {
devices.add(getDeviceManagementService().getDevice(deviceIdentifier));
}
getGCMService().sendNotification(operation.getCode(), devices);
}
}
int status =
getDeviceManagementService().addOperation("android", operation, deviceIDHolder.getValidDeviceIDList());
// if (status > 0) {
// GCMService gcmService = getGCMService();
// if (gcmService.isGCMEnabled()) {
// List<Device> devices = new ArrayList<Device>();
// for (DeviceIdentifier deviceIdentifier : deviceIDHolder.getValidDeviceIDList()) {
// 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(

@ -134,7 +134,7 @@ public class WindowsAPIUtils {
WindowsDeviceUtils deviceUtils = new WindowsDeviceUtils();
DeviceIDHolder deviceIDHolder = deviceUtils.validateDeviceIdentifiers(deviceIDs,
message, responseMediaType);
getDeviceManagementService().addOperation(operation, deviceIDHolder.getValidDeviceIDList());
getDeviceManagementService().addOperation("windows", operation, deviceIDHolder.getValidDeviceIDList());
if (!deviceIDHolder.getErrorDeviceIdList().isEmpty()) {
return javax.ws.rs.core.Response.status(PluginConstants.StatusCodes.
MULTI_STATUS_HTTP_CODE).type(

@ -0,0 +1,40 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
~
~ WSO2 Inc. licenses this file to you under the Apache License,
~ Version 2.0 (the "License"); you may not use this file except
~ in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing,
~ software distributed under the License is distributed on an
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
~ KIND, either express or implied. See the License for the
~ specific language governing permissions and limitations
~ under the License.
-->
<DeviceManagementConfiguration>
<ManagementRepository>
<DataSourceConfigurations>
<DataSourceConfiguration>
<JndiLookupDefinition>
<Name>jdbc/VirtualFireAlarmDM_DB</Name>
</JndiLookupDefinition>
</DataSourceConfiguration>
</DataSourceConfigurations>
</ManagementRepository>
<PushNotificationConfiguration>
<Properties>
<Property Name="url">tcp://${mqtt.broker.host}:${mqtt.broker.port}</Property>
<Property Name="username">admin</Property>
<Property Name="dcrUrl">https://localhost:${carbon.https.port}/dynamic-client-web/register</Property>
<Property Name="qos">0</Property>
<Property Name="scopes"/>
<Property Name="clearSession">true</Property>
</Properties>
</PushNotificationConfiguration>
</DeviceManagementConfiguration>

@ -15,6 +15,7 @@ org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../featur
org.eclipse.equinox.p2.touchpoint.natives.mkdir(path:${installFolder}/../../resources/security/);\
org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.iot.virtualfirealarm_${feature.version}/certs/,target:${installFolder}/../../resources/security/,overwrite:true);\
org.eclipse.equinox.p2.touchpoint.natives.mkdir(path:${installFolder}/../../resources/device-types/);\
org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.iot.virtualfirealarm_${feature.version}/conf/virtual-fire-alarm-config.xml,target:${installFolder}/../../conf/etc/device-mgt-plugins/virtual-fire-alarm/virtual-fire-alarm-config.xml,overwrite:true);\
instructions.unconfigure = \
org.eclipse.equinox.p2.touchpoint.natives.remove(path:${installFolder}/../../deployment/server/webapps/virtual_firealarm.war);\

Loading…
Cancel
Save