|
|
@ -22,17 +22,21 @@ import org.apache.commons.logging.Log;
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
|
|
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
|
|
|
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
|
|
|
|
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.policy.mgt.Profile;
|
|
|
|
import org.wso2.carbon.device.mgt.common.push.notification.NotificationContext;
|
|
|
|
import org.wso2.carbon.device.mgt.common.push.notification.NotificationContext;
|
|
|
|
import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy;
|
|
|
|
import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy;
|
|
|
|
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig;
|
|
|
|
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig;
|
|
|
|
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationExecutionFailedException;
|
|
|
|
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationExecutionFailedException;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.operation.mgt.ProfileOperation;
|
|
|
|
import org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt.internal.MQTTDataHolder;
|
|
|
|
import org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt.internal.MQTTDataHolder;
|
|
|
|
import org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt.internal.util.MQTTAdapterConstants;
|
|
|
|
import org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt.internal.util.MQTTAdapterConstants;
|
|
|
|
import org.wso2.carbon.event.output.adapter.core.MessageType;
|
|
|
|
import org.wso2.carbon.event.output.adapter.core.MessageType;
|
|
|
|
import org.wso2.carbon.event.output.adapter.core.OutputEventAdapterConfiguration;
|
|
|
|
import org.wso2.carbon.event.output.adapter.core.OutputEventAdapterConfiguration;
|
|
|
|
import org.wso2.carbon.event.output.adapter.core.exception.OutputEventAdapterException;
|
|
|
|
import org.wso2.carbon.event.output.adapter.core.exception.OutputEventAdapterException;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.operation.mgt.PolicyOperation;
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Properties;
|
|
|
|
import java.util.Properties;
|
|
|
|
|
|
|
|
|
|
|
@ -79,12 +83,33 @@ public class MQTTNotificationStrategy implements NotificationStrategy {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void execute(NotificationContext ctx) throws PushNotificationExecutionFailedException {
|
|
|
|
public void execute(NotificationContext ctx) throws PushNotificationExecutionFailedException {
|
|
|
|
Map<String, String> dynamicProperties = new HashMap<>();
|
|
|
|
|
|
|
|
Operation operation = ctx.getOperation();
|
|
|
|
Operation operation = ctx.getOperation();
|
|
|
|
Properties properties = operation.getProperties();
|
|
|
|
Properties properties = operation.getProperties();
|
|
|
|
if (properties != null && properties.get(MQTT_ADAPTER_TOPIC) != null) {
|
|
|
|
if (properties != null && properties.get(MQTT_ADAPTER_TOPIC) != null) {
|
|
|
|
|
|
|
|
Map<String, String> dynamicProperties = new HashMap<>();
|
|
|
|
dynamicProperties.put("topic", (String) properties.get(MQTT_ADAPTER_TOPIC));
|
|
|
|
dynamicProperties.put("topic", (String) properties.get(MQTT_ADAPTER_TOPIC));
|
|
|
|
|
|
|
|
MQTTDataHolder.getInstance().getOutputEventAdapterService().publish(mqttAdapterName, dynamicProperties,
|
|
|
|
|
|
|
|
operation.getPayLoad());
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
if (PolicyOperation.POLICY_OPERATION_CODE.equals(operation.getCode())) {
|
|
|
|
|
|
|
|
PolicyOperation policyOperation = (PolicyOperation) operation;
|
|
|
|
|
|
|
|
List<ProfileOperation> profileOperations = policyOperation.getProfileOperations();
|
|
|
|
|
|
|
|
String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(true);
|
|
|
|
|
|
|
|
String deviceType = ctx.getDeviceId().getType();
|
|
|
|
|
|
|
|
String deviceId = ctx.getDeviceId().getId();
|
|
|
|
|
|
|
|
for (ProfileOperation profileOperation : profileOperations) {
|
|
|
|
|
|
|
|
Map<String, String> dynamicProperties = new HashMap<>();
|
|
|
|
|
|
|
|
String topic = tenantDomain + "/"
|
|
|
|
|
|
|
|
+ deviceType + "/" + deviceId + "/" + profileOperation.getType()
|
|
|
|
|
|
|
|
.toString().toLowerCase() + "/" + profileOperation.getCode().toLowerCase();
|
|
|
|
|
|
|
|
dynamicProperties.put("topic", topic);
|
|
|
|
|
|
|
|
MQTTDataHolder.getInstance().getOutputEventAdapterService().publish(mqttAdapterName, dynamicProperties,
|
|
|
|
|
|
|
|
profileOperation.getPayLoad());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
|
|
|
|
Map<String, String> dynamicProperties = new HashMap<>();
|
|
|
|
String topic = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(true) + "/"
|
|
|
|
String topic = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(true) + "/"
|
|
|
|
+ ctx.getDeviceId().getType() + "/" + ctx.getDeviceId().getId() + "/" + operation.getType()
|
|
|
|
+ ctx.getDeviceId().getType() + "/" + ctx.getDeviceId().getId() + "/" + operation.getType()
|
|
|
|
.toString().toLowerCase() + "/" + operation.getCode();
|
|
|
|
.toString().toLowerCase() + "/" + operation.getCode();
|
|
|
@ -92,10 +117,14 @@ public class MQTTNotificationStrategy implements NotificationStrategy {
|
|
|
|
if (operation.getPayLoad() == null) {
|
|
|
|
if (operation.getPayLoad() == null) {
|
|
|
|
operation.setPayLoad("");
|
|
|
|
operation.setPayLoad("");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MQTTDataHolder.getInstance().getOutputEventAdapterService().publish(mqttAdapterName, dynamicProperties,
|
|
|
|
MQTTDataHolder.getInstance().getOutputEventAdapterService().publish(mqttAdapterName, dynamicProperties,
|
|
|
|
operation.getPayLoad());
|
|
|
|
operation.getPayLoad());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
@ -109,3 +138,4 @@ public class MQTTNotificationStrategy implements NotificationStrategy {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|