forked from community/device-mgt-core
parent
8a56161a43
commit
a0d7518cbe
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (c) 2017, 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.common.pull.notification;
|
||||
|
||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||
|
||||
public class NotificationContext {
|
||||
|
||||
private DeviceIdentifier deviceId;
|
||||
|
||||
private NotificationPayload notificationPayload;
|
||||
|
||||
public NotificationContext(DeviceIdentifier deviceId) {
|
||||
this.deviceId = deviceId;
|
||||
}
|
||||
|
||||
public NotificationContext(DeviceIdentifier deviceId, NotificationPayload notificationPayload) {
|
||||
this.deviceId = deviceId;
|
||||
this.notificationPayload = notificationPayload;
|
||||
}
|
||||
|
||||
public DeviceIdentifier getDeviceId() {
|
||||
return deviceId;
|
||||
}
|
||||
|
||||
public NotificationPayload getNotificationPayload() {
|
||||
return notificationPayload;
|
||||
}
|
||||
|
||||
public void setNotificationPayload(NotificationPayload notificationPayload) {
|
||||
this.notificationPayload = notificationPayload;
|
||||
}
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (c) 2017, 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.common.pull.notification;
|
||||
|
||||
public class NotificationPayload {
|
||||
|
||||
int operationId;
|
||||
private String payload;
|
||||
|
||||
public String getPayload() {
|
||||
return payload;
|
||||
}
|
||||
|
||||
public void setPayload(String payload) {
|
||||
this.payload = payload;
|
||||
}
|
||||
|
||||
public int getOperationId() {
|
||||
return operationId;
|
||||
}
|
||||
|
||||
public void setOperationId(int operationId) {
|
||||
this.operationId = operationId;
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (c) 2017, 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.common.pull.notification;
|
||||
|
||||
public class PullNotificationExecutionFailedException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = -3151279311923070297L;
|
||||
|
||||
public PullNotificationExecutionFailedException(String msg, Exception nestedEx) {
|
||||
super(msg, nestedEx);
|
||||
}
|
||||
|
||||
public PullNotificationExecutionFailedException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public PullNotificationExecutionFailedException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
public PullNotificationExecutionFailedException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public PullNotificationExecutionFailedException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (c) 2017, 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.common.pull.notification;
|
||||
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* This will handle the execution flow when a device sends a payload to IoT Server.
|
||||
*/
|
||||
public interface PullNotificationSubscriber {
|
||||
|
||||
void init(Map<String, String> properties);
|
||||
|
||||
void execute(NotificationContext ctx) throws PullNotificationExecutionFailedException;
|
||||
|
||||
void clean();
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (c) 2017, 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.core.config.pull.notification;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
/**
|
||||
* This class is for Pull notification related Configurations
|
||||
*/
|
||||
@XmlRootElement(name = "PullNotificationConfiguration")
|
||||
public class PullNotificationConfiguration {
|
||||
|
||||
private boolean enabled;
|
||||
|
||||
@XmlElement(name = "Enabled", required = true)
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,106 @@
|
||||
/*
|
||||
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
package org.wso2.carbon.device.mgt.extensions.device.type.template.config;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlAttribute;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlType;
|
||||
|
||||
|
||||
/**
|
||||
* <p>Java class for PullNotificationSubscriber complex type.
|
||||
*
|
||||
* <p>The following schema fragment specifies the expected content contained within this class.
|
||||
*
|
||||
* <pre>
|
||||
* <complexType name="PullNotificationSubscriber">
|
||||
* <complexContent>
|
||||
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
|
||||
* <sequence>
|
||||
* <element name="ConfigProperties" type="{}ConfigProperties"/>
|
||||
* </sequence>
|
||||
* <attribute name="type" type="{http://www.w3.org/2001/XMLSchema}string" />
|
||||
* </restriction>
|
||||
* </complexContent>
|
||||
* </complexType>
|
||||
* </pre>
|
||||
*
|
||||
*
|
||||
*/
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
@XmlType(name = "PullNotificationSubscriber", propOrder = {
|
||||
"configProperties"
|
||||
})
|
||||
public class PullNotificationSubscriber {
|
||||
@XmlElement(name = "ConfigProperties", required = true)
|
||||
protected ConfigProperties configProperties;
|
||||
@XmlAttribute(name = "className")
|
||||
protected String className;
|
||||
|
||||
/**
|
||||
* Gets the value of the configProperties property.
|
||||
*
|
||||
* @return
|
||||
* possible object is
|
||||
* {@link ConfigProperties }
|
||||
*
|
||||
*/
|
||||
public ConfigProperties getConfigProperties() {
|
||||
return configProperties;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of the configProperties property.
|
||||
*
|
||||
* @param value
|
||||
* allowed object is
|
||||
* {@link ConfigProperties }
|
||||
*
|
||||
*/
|
||||
public void setConfigProperties(ConfigProperties value) {
|
||||
this.configProperties = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of the type property.
|
||||
*
|
||||
* @return
|
||||
* possible object is
|
||||
* {@link String }
|
||||
*
|
||||
*/
|
||||
public String getClassName() {
|
||||
return className;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of the type property.
|
||||
*
|
||||
* @param value
|
||||
* allowed object is
|
||||
* {@link String }
|
||||
*
|
||||
*/
|
||||
public void setClassName(String value) {
|
||||
this.className = className;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
package org.wso2.carbon.device.mgt.extensions.device.type.template.pull.notification;
|
||||
|
||||
import org.wso2.carbon.device.mgt.common.pull.notification.PullNotificationSubscriber;
|
||||
import org.wso2.carbon.device.mgt.extensions.device.type.template.config.ConfigProperties;
|
||||
import org.wso2.carbon.device.mgt.extensions.device.type.template.config.Property;
|
||||
import org.wso2.carbon.device.mgt.extensions.device.type.template.exception.DeviceTypeDeployerPayloadException;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* This creates an instance of the pull notification executor strategy with the given class name.
|
||||
* makes sure the class name starts with the package prefix org.wso2.carbon.device.mgt.pull.notification.*
|
||||
*/
|
||||
public class PullNotificationSubscriberLoader {
|
||||
|
||||
private PullNotificationSubscriber pullNotificationSubscriber;
|
||||
|
||||
public PullNotificationSubscriberLoader(String className, ConfigProperties configProperties) {
|
||||
try {
|
||||
Class<? extends PullNotificationSubscriber> pullNotificationExecutorClass
|
||||
= Class.forName(className).asSubclass(PullNotificationSubscriber.class);
|
||||
Map<String, String> properties = new HashMap<>();
|
||||
if (configProperties != null) {
|
||||
for (Property property : configProperties.getProperty()) {
|
||||
properties.put(property.getName(), property.getValue());
|
||||
}
|
||||
}
|
||||
pullNotificationSubscriber = pullNotificationExecutorClass.newInstance();
|
||||
pullNotificationSubscriber.init(properties);
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new DeviceTypeDeployerPayloadException("Unable to find the class pull notification executor: " + className, e);
|
||||
} catch (InstantiationException e) {
|
||||
throw new DeviceTypeDeployerPayloadException("Unable to create an instance of :" + className, e);
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new DeviceTypeDeployerPayloadException("Access of the instance in not allowed.", e);
|
||||
}
|
||||
}
|
||||
|
||||
public PullNotificationSubscriber getPullNotificationSubscriber() {
|
||||
return pullNotificationSubscriber;
|
||||
}
|
||||
}
|
Loading…
Reference in new issue