forked from community/device-mgt-plugins
parent
562ac197af
commit
6c24f44abc
@ -1,46 +0,0 @@
|
||||
/*
|
||||
* 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.androidsense.plugin.impl.util;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.core.ServerStartupObserver;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Startup listener to create an output adapter after server starts up.
|
||||
*/
|
||||
public class AndroidSenseStartupListener implements ServerStartupObserver {
|
||||
private static final Log log = LogFactory.getLog(AndroidSenseStartupListener.class);
|
||||
|
||||
@Override
|
||||
public void completingServerStartup() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void completedServerStartup() {
|
||||
try {
|
||||
AndroidSenseUtils.setupMqttOutputAdapter();
|
||||
} catch (IOException e) {
|
||||
log.error("Failed to intilaize the virtual firealarm output adapter", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,60 +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.iot.androidsense.plugin.mqtt;
|
||||
|
||||
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.device.mgt.iot.androidsense.plugin.impl.util.AndroidSenseUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Properties;
|
||||
|
||||
public class MqttConfig {
|
||||
|
||||
private static String brokerEndpoint;
|
||||
|
||||
private static MqttConfig mqttConfig = new MqttConfig();
|
||||
private static final Log log = LogFactory.getLog(MqttConfig.class);
|
||||
|
||||
private MqttConfig() {
|
||||
File configFile = new File(AndroidSenseConstants.MQTT_CONFIG_LOCATION);
|
||||
if (configFile.exists()) {
|
||||
try {
|
||||
InputStream propertyStream = configFile.toURI().toURL().openStream();
|
||||
Properties properties = new Properties();
|
||||
properties.load(propertyStream);
|
||||
brokerEndpoint = AndroidSenseUtils.replaceMqttProperty(
|
||||
properties.getProperty(AndroidSenseConstants.BROKER_URL_PROPERTY_KEY));
|
||||
} catch (IOException e) {
|
||||
log.error("Failed to read the mqtt.properties file" + e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static MqttConfig getInstance() {
|
||||
return mqttConfig;
|
||||
}
|
||||
|
||||
public String getBrokerEndpoint() {
|
||||
return brokerEndpoint;
|
||||
}
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* 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.arduino.plugin.internal;
|
||||
|
||||
import org.wso2.carbon.device.mgt.iot.devicetype.DeviceTypeConfigService;
|
||||
|
||||
/**
|
||||
* DataHolder class of plugins component.
|
||||
*/
|
||||
public class ArduinoManagementDataHolder {
|
||||
|
||||
private DeviceTypeConfigService deviceTypeConfigService;
|
||||
private static ArduinoManagementDataHolder thisInstance = new ArduinoManagementDataHolder();
|
||||
|
||||
private ArduinoManagementDataHolder() {
|
||||
}
|
||||
|
||||
public static ArduinoManagementDataHolder getInstance() {
|
||||
return thisInstance;
|
||||
}
|
||||
|
||||
public DeviceTypeConfigService getDeviceTypeConfigService() {
|
||||
return deviceTypeConfigService;
|
||||
}
|
||||
|
||||
public void setDeviceTypeConfigService(
|
||||
DeviceTypeConfigService deviceTypeConfigService) {
|
||||
this.deviceTypeConfigService = deviceTypeConfigService;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* 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.devicetype;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* This class holds key for the configuration of the device type and its provider tenant.
|
||||
*/
|
||||
public class DeviceTypeConfigIdentifier implements Serializable {
|
||||
|
||||
private String deviceType;
|
||||
private String tenantDomain;
|
||||
|
||||
public DeviceTypeConfigIdentifier(String deviceType, String tenantDomain) {
|
||||
this.deviceType = deviceType;
|
||||
this.tenantDomain = tenantDomain;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = this.deviceType.hashCode();
|
||||
result = 31 * result + ("@" + this.tenantDomain).hashCode();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return (obj instanceof DeviceTypeConfigIdentifier) && deviceType.equals(
|
||||
((DeviceTypeConfigIdentifier) obj).deviceType) && tenantDomain.equals(
|
||||
((DeviceTypeConfigIdentifier) obj).tenantDomain);
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package org.wso2.carbon.device.mgt.iot.devicetype;
|
||||
|
||||
import org.wso2.carbon.device.mgt.iot.devicetype.config.DeviceManagementConfiguration;
|
||||
|
||||
/**
|
||||
* Service to retrieve device type configs.
|
||||
*/
|
||||
public interface DeviceTypeConfigService {
|
||||
|
||||
/**
|
||||
* This service will read the device type configuration files from conf/etc/device-type-plugins
|
||||
*
|
||||
* @param deviceType retrive the device type configuration.
|
||||
* @param tenantDomain retrieve the device type of this tenant domain.
|
||||
* @return device management configuratio for the device type owned by the given tenant domain.
|
||||
*/
|
||||
DeviceManagementConfiguration getConfiguration(String deviceType, String tenantDomain);
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
package org.wso2.carbon.device.mgt.iot.devicetype;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.w3c.dom.Document;
|
||||
import org.wso2.carbon.device.mgt.iot.devicetype.config.DeviceManagementConfiguration;
|
||||
import org.wso2.carbon.device.mgt.iot.devicetype.config.exception.DeviceTypeConfigurationException;
|
||||
import org.wso2.carbon.device.mgt.iot.devicetype.util.DeviceTypeConfigUtil;
|
||||
import org.wso2.carbon.utils.CarbonUtils;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class DeviceTypeConfigServiceImpl implements DeviceTypeConfigService {
|
||||
|
||||
private static final Log log = LogFactory.getLog(DeviceTypeConfigServiceImpl.class);
|
||||
private static final String DEVICE_TYPE_CONFIG_PATH =
|
||||
CarbonUtils.getEtcCarbonConfigDirPath() + File.separator + "device-mgt-plugins";
|
||||
private Map<DeviceTypeConfigIdentifier, DeviceManagementConfiguration> deviceTypeConfigurationMap = new HashMap<>();
|
||||
|
||||
public void initialize() {
|
||||
File configurationDirectory = new File(DEVICE_TYPE_CONFIG_PATH);
|
||||
File[] deviceTypeConfigurationFiles = configurationDirectory.listFiles();
|
||||
if (deviceTypeConfigurationFiles != null) {
|
||||
for (File file : deviceTypeConfigurationFiles) {
|
||||
String filename = file.getName();
|
||||
if (filename.endsWith(".xml") || filename.endsWith(".XML")) {
|
||||
try {
|
||||
DeviceManagementConfiguration deviceManagementConfiguration = getDeviceTypeConfiguration(file);
|
||||
String deviceType = deviceManagementConfiguration.getDeviceType();
|
||||
String tenantDomain = deviceManagementConfiguration.getDeviceManagementConfigRepository()
|
||||
.getProvisioningConfig().getTenantDomain();
|
||||
if ( deviceType != null && !deviceType.isEmpty() && tenantDomain != null
|
||||
&& !tenantDomain.isEmpty()) {
|
||||
deviceTypeConfigurationMap.put(new DeviceTypeConfigIdentifier(deviceType, tenantDomain),
|
||||
deviceManagementConfiguration);
|
||||
}
|
||||
|
||||
} catch (DeviceTypeConfigurationException e) {
|
||||
//continue reading other files
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private DeviceManagementConfiguration getDeviceTypeConfiguration(File configurationFile)
|
||||
throws DeviceTypeConfigurationException {
|
||||
try {
|
||||
Document doc = DeviceTypeConfigUtil.convertToDocument(configurationFile);
|
||||
|
||||
/* Un-marshaling Webapp Authenticator configuration */
|
||||
JAXBContext ctx = JAXBContext.newInstance(DeviceManagementConfiguration.class);
|
||||
Unmarshaller unmarshaller = ctx.createUnmarshaller();
|
||||
//unmarshaller.setSchema(getSchema());
|
||||
return (DeviceManagementConfiguration) unmarshaller.unmarshal(doc);
|
||||
} catch (JAXBException e) {
|
||||
throw new DeviceTypeConfigurationException("Error occurred while un-marshalling the file " +
|
||||
configurationFile.getAbsolutePath(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public DeviceManagementConfiguration getConfiguration(String deviceType, String tenantDomain) {
|
||||
return deviceTypeConfigurationMap.get(new DeviceTypeConfigIdentifier(deviceType, tenantDomain));
|
||||
}
|
||||
}
|
5
components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/internal/config/DataSourceConfig.java → components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/devicetype/config/DataSourceConfig.java
5
components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/internal/config/DataSourceConfig.java → components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/devicetype/config/DataSourceConfig.java
12
components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/internal/config/DeviceManagementConfigRepository.java → components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/devicetype/config/DeviceManagementConfigRepository.java
12
components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/internal/config/DeviceManagementConfigRepository.java → components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/devicetype/config/DeviceManagementConfigRepository.java
@ -0,0 +1,66 @@
|
||||
/*
|
||||
* 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.devicetype.config;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
@XmlRootElement(name = "DeviceManagementConfiguration")
|
||||
public class DeviceManagementConfiguration {
|
||||
|
||||
private DeviceManagementConfigRepository deviceManagementConfigRepository;
|
||||
private PushNotificationConfig pushNotificationConfig;
|
||||
private String deviceType;
|
||||
|
||||
private static final Log log = LogFactory.getLog(DeviceManagementConfiguration.class);
|
||||
|
||||
private DeviceManagementConfiguration() {
|
||||
}
|
||||
|
||||
@XmlElement(name = "DeviceType", required = false)
|
||||
public String getDeviceType() {
|
||||
return deviceType;
|
||||
}
|
||||
|
||||
public void setDeviceType(String deviceType) {
|
||||
this.deviceType = deviceType;
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
}
|
10
components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/internal/config/JNDILookupDefinition.java → components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/devicetype/config/JNDILookupDefinition.java
10
components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/internal/config/JNDILookupDefinition.java → components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/devicetype/config/JNDILookupDefinition.java
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* 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.devicetype.config;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
/**
|
||||
* Class for holding device type configuration and parsing with JAXB.
|
||||
*/
|
||||
@XmlRootElement(name = "ProvisioningConfig")
|
||||
public class ProvisioningConfig {
|
||||
|
||||
private String tenantDomain;
|
||||
private boolean sharedWithAllTenants;
|
||||
|
||||
@XmlElement(name = "TenantDomain", required = true)
|
||||
public String getTenantDomain() {
|
||||
return tenantDomain;
|
||||
}
|
||||
|
||||
public void setTenantDomain(String tenantDomain) {
|
||||
this.tenantDomain = tenantDomain;
|
||||
}
|
||||
|
||||
@XmlElement(name = "SharedWithAllTenants", required = true)
|
||||
public boolean isSharedWithAllTenants() {
|
||||
return sharedWithAllTenants;
|
||||
}
|
||||
|
||||
public void setSharedWithAllTenants(boolean sharedWithAllTenants) {
|
||||
this.sharedWithAllTenants = sharedWithAllTenants;
|
||||
}
|
||||
}
|
18
components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/internal/config/PushNotificationConfig.java → components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/devicetype/config/PushNotificationConfig.java
18
components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/internal/config/PushNotificationConfig.java → components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/devicetype/config/PushNotificationConfig.java
18
components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/internal/config/exception/VirtualFireAlarmConfigurationException.java → components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/devicetype/config/exception/DeviceTypeConfigurationException.java
18
components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/internal/config/exception/VirtualFireAlarmConfigurationException.java → components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/devicetype/config/exception/DeviceTypeConfigurationException.java
2
components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/internal/config/exception/InvalidConfigurationStateException.java → components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/devicetype/config/exception/InvalidConfigurationStateException.java
2
components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/internal/config/exception/InvalidConfigurationStateException.java → components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/devicetype/config/exception/InvalidConfigurationStateException.java
16
components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/internal/util/VirtualFireAlarmUtil.java → components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/devicetype/util/DeviceTypeConfigUtil.java
16
components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/internal/util/VirtualFireAlarmUtil.java → components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/devicetype/util/DeviceTypeConfigUtil.java
@ -1,46 +0,0 @@
|
||||
/*
|
||||
* 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.raspberrypi.plugin.impl.util;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.core.ServerStartupObserver;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Startup listener to create an output adapter after server starts up.
|
||||
*/
|
||||
public class RaspberrypiStartupListener implements ServerStartupObserver {
|
||||
private static final Log log = LogFactory.getLog(RaspberrypiStartupListener.class);
|
||||
|
||||
@Override
|
||||
public void completingServerStartup() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void completedServerStartup() {
|
||||
try {
|
||||
RaspberrypiUtils.setupMqttOutputAdapter();
|
||||
} catch (IOException e) {
|
||||
log.error("Failed to intilaize the virtual firealarm output adapter", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,60 +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.iot.raspberrypi.plugin.mqtt;
|
||||
|
||||
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.device.mgt.iot.raspberrypi.plugin.impl.util.RaspberrypiUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Properties;
|
||||
|
||||
public class MqttConfig {
|
||||
|
||||
private static String brokerEndpoint;
|
||||
|
||||
private static MqttConfig mqttConfig = new MqttConfig();
|
||||
private static final Log log = LogFactory.getLog(MqttConfig.class);
|
||||
|
||||
private MqttConfig() {
|
||||
File configFile = new File(RaspberrypiConstants.MQTT_CONFIG_LOCATION);
|
||||
if (configFile.exists()) {
|
||||
try {
|
||||
InputStream propertyStream = configFile.toURI().toURL().openStream();
|
||||
Properties properties = new Properties();
|
||||
properties.load(propertyStream);
|
||||
brokerEndpoint = RaspberrypiUtils.replaceMqttProperty(
|
||||
properties.getProperty(RaspberrypiConstants.BROKER_URL_PROPERTY_KEY));
|
||||
} catch (IOException e) {
|
||||
log.error("Failed to read the mqtt.properties file" + e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static MqttConfig getInstance() {
|
||||
return mqttConfig;
|
||||
}
|
||||
|
||||
public String getBrokerEndpoint() {
|
||||
return brokerEndpoint;
|
||||
}
|
||||
}
|
@ -1,93 +0,0 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
package org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.xmpp;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
|
||||
import org.apache.http.conn.ssl.SSLContextBuilder;
|
||||
import org.apache.http.conn.ssl.TrustSelfSignedStrategy;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.constants.VirtualFireAlarmConstants;
|
||||
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.exception.VirtualFirealarmDeviceMgtPluginException;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.security.KeyManagementException;
|
||||
import java.security.KeyStoreException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
/**
|
||||
* This holds the utility class related to XMPP.
|
||||
*/
|
||||
public class XmppUtil {
|
||||
private static final Log log = LogFactory.getLog(XmppUtil.class);
|
||||
|
||||
public static void createXMPPAccountForDeviceType() {
|
||||
if (!XmppConfig.getInstance().isEnabled()) {
|
||||
return;
|
||||
}
|
||||
XmppServerClient xmppServerClient = new XmppServerClient();
|
||||
try {
|
||||
XmppAccount xmppAccount = new XmppAccount();
|
||||
xmppAccount.setAccountName(XmppConfig.getInstance().getVirtualFirealarmAdminUsername());
|
||||
xmppAccount.setUsername(XmppConfig.getInstance().getVirtualFirealarmAdminUsername());
|
||||
xmppAccount.setPassword(XmppConfig.getInstance().getVirtualFirealarmAdminPassword());
|
||||
xmppAccount.setEmail(XmppConfig.getInstance().getVirtualFirealarmAdminJID());
|
||||
xmppServerClient.createAccount(xmppAccount);
|
||||
} catch (VirtualFirealarmDeviceMgtPluginException e) {
|
||||
String errorMsg = "An error was encountered whilst trying to create Server XMPP account for device-type - "
|
||||
+ VirtualFireAlarmConstants.DEVICE_TYPE;
|
||||
log.error(errorMsg, e);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
<?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>
|
||||
<DeviceType>android_sense</DeviceType>
|
||||
<ManagementRepository>
|
||||
<DataSourceConfiguration>
|
||||
<JndiLookupDefinition>
|
||||
<Name>jdbc/AndroidSenseDM_DB</Name>
|
||||
</JndiLookupDefinition>
|
||||
</DataSourceConfiguration>
|
||||
<ProvisioningConfig>
|
||||
<TenantDomain>carbon.super</TenantDomain>
|
||||
<SharedWithAllTenants>false</SharedWithAllTenants>
|
||||
</ProvisioningConfig>
|
||||
</ManagementRepository>
|
||||
<PushNotificationConfiguration>
|
||||
<!--MQTT Config-->
|
||||
<PushNotificationProvider>MQTT</PushNotificationProvider>
|
||||
<Properties>
|
||||
<Property Name="mqtt.adapter.name">androidsense.mqtt.adapter</Property>
|
||||
<Property Name="url">tcp://localhost:1883</Property>
|
||||
<Property Name="username">admin</Property>
|
||||
<Property Name="dcrUrl">https://localhost:9443/dynamic-client-web/register</Property>
|
||||
<Property Name="qos">0</Property>
|
||||
<Property Name="scopes"/>
|
||||
<Property Name="clearSession">true</Property>
|
||||
</Properties>
|
||||
</PushNotificationConfiguration>
|
||||
</DeviceManagementConfiguration>
|
@ -0,0 +1,33 @@
|
||||
<?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>
|
||||
<DeviceType>arduino</DeviceType>
|
||||
<ManagementRepository>
|
||||
<DataSourceConfiguration>
|
||||
<JndiLookupDefinition>
|
||||
<Name>jdbc/ArduinoDM_DB</Name>
|
||||
</JndiLookupDefinition>
|
||||
</DataSourceConfiguration>
|
||||
<ProvisioningConfig>
|
||||
<TenantDomain>carbon.super</TenantDomain>
|
||||
<SharedWithAllTenants>false</SharedWithAllTenants>
|
||||
</ProvisioningConfig>
|
||||
</ManagementRepository>
|
||||
</DeviceManagementConfiguration>
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue