changed response payload definition for pull notification

revert-70aa11f8
ayyoob 7 years ago
parent c46cbfafe5
commit a1b20f1663

@ -20,9 +20,9 @@ package org.wso2.carbon.device.mgt.extensions.pull.notification;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
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.operation.mgt.OperationManagementException; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
import org.wso2.carbon.device.mgt.common.pull.notification.NotificationContext;
import org.wso2.carbon.device.mgt.common.pull.notification.PullNotificationExecutionFailedException; import org.wso2.carbon.device.mgt.common.pull.notification.PullNotificationExecutionFailedException;
import org.wso2.carbon.device.mgt.common.pull.notification.PullNotificationSubscriber; import org.wso2.carbon.device.mgt.common.pull.notification.PullNotificationSubscriber;
import org.wso2.carbon.device.mgt.extensions.pull.notification.internal.PullNotificationDataHolder; import org.wso2.carbon.device.mgt.extensions.pull.notification.internal.PullNotificationDataHolder;
@ -37,13 +37,11 @@ public class PullNotificationSubscriberImpl implements PullNotificationSubscribe
} }
public void execute(NotificationContext ctx) throws PullNotificationExecutionFailedException { @Override
Operation operation = new Operation(); public void execute(DeviceIdentifier deviceIdentifier, Operation operation) throws PullNotificationExecutionFailedException {
operation.setId(ctx.getNotificationPayload().getOperationId());
operation.setPayLoad(ctx.getNotificationPayload().getPayload());
try { try {
PullNotificationDataHolder.getInstance().getDeviceManagementProviderService().updateOperation( PullNotificationDataHolder.getInstance().getDeviceManagementProviderService().updateOperation(
ctx.getDeviceId(), operation); deviceIdentifier, operation);
} catch (OperationManagementException e) { } catch (OperationManagementException e) {
throw new PullNotificationExecutionFailedException(e); throw new PullNotificationExecutionFailedException(e);
} }

@ -22,6 +22,7 @@ import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import javax.validation.constraints.Size; import javax.validation.constraints.Size;
import java.util.Map;
/** /**
* This class is used to wrap the events which receive from the agent application. * This class is used to wrap the events which receive from the agent application.
@ -31,13 +32,13 @@ import javax.validation.constraints.Size;
public class EventBeanWrapper { public class EventBeanWrapper {
@ApiModelProperty(name = "payloadData", value = "Event payload payload.", required = true) @ApiModelProperty(name = "payloadData", value = "Event payload payload.", required = true)
Object[] payloadData; Map<String, Object> payloadData;
public Object[] getPayloadData() { public Map<String, Object> getPayloadData() {
return payloadData; return payloadData;
} }
public void setPayloadData(Object[] payloadData) { public void setPayloadData(Map<String, Object> payloadData) {
this.payloadData = payloadData; this.payloadData = payloadData;
} }

@ -59,6 +59,7 @@ import javax.ws.rs.core.Response;
import java.rmi.RemoteException; import java.rmi.RemoteException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map;
@Path("/device/agent") @Path("/device/agent")
public class DeviceAgentServiceImpl implements DeviceAgentService { public class DeviceAgentServiceImpl implements DeviceAgentService {
@ -205,7 +206,6 @@ public class DeviceAgentServiceImpl implements DeviceAgentService {
public Response publishEvents(@Valid EventBeanWrapper eventBeanWrapper, @PathParam("type") String type public Response publishEvents(@Valid EventBeanWrapper eventBeanWrapper, @PathParam("type") String type
, @PathParam("deviceId") String deviceId) { , @PathParam("deviceId") String deviceId) {
String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(); String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
try { try {
if (eventBeanWrapper == null) { if (eventBeanWrapper == null) {
@ -238,7 +238,7 @@ public class DeviceAgentServiceImpl implements DeviceAgentService {
, AttributeType.valueOf(eventStreamAttributeDto.getAttributeType().toUpperCase()))); , AttributeType.valueOf(eventStreamAttributeDto.getAttributeType().toUpperCase())));
} }
if (eventBeanWrapper.getPayloadData().length != attributes.size()) { if (eventBeanWrapper.getPayloadData().size() != attributes.size()) {
String msg = "payload does not match the stream definition"; String msg = "payload does not match the stream definition";
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} }
@ -247,13 +247,16 @@ public class DeviceAgentServiceImpl implements DeviceAgentService {
DeviceMgtAPIUtils.getDynamicEventCache().put(type, eventAttributeList); DeviceMgtAPIUtils.getDynamicEventCache().put(type, eventAttributeList);
} }
} }
Object[] payload = eventBeanWrapper.getPayloadData(); Map<String, Object> payload = eventBeanWrapper.getPayloadData();
int i = 0; int i = 0;
Object[] payloadData = new Object[eventAttributeList.getList().size()];
for (Attribute attribute : eventAttributeList.getList()) { for (Attribute attribute : eventAttributeList.getList()) {
if (attribute.getType() == AttributeType.INT) { if (attribute.getType() == AttributeType.INT) {
payload[i] = ((Double) payload[i]).intValue(); payloadData[i] = ((Double) payload.get(attribute.getName())).intValue();
} else if (attribute.getType() == AttributeType.LONG) { } else if (attribute.getType() == AttributeType.LONG) {
payload[i] = ((Double) payload[i]).longValue(); payloadData[i] = ((Double) payload.get(attribute.getName())).longValue();
} else {
payloadData[i] = payload.get(attribute.getName());
} }
i++; i++;
} }
@ -262,7 +265,7 @@ public class DeviceAgentServiceImpl implements DeviceAgentService {
if (DeviceMgtAPIUtils.getEventPublisherService().publishEvent(DeviceMgtAPIUtils.getStreamDefinition(type if (DeviceMgtAPIUtils.getEventPublisherService().publishEvent(DeviceMgtAPIUtils.getStreamDefinition(type
, PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain()) , PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain())
, Constants.DEFAULT_STREAM_VERSION, metaData , Constants.DEFAULT_STREAM_VERSION, metaData
, null, eventBeanWrapper.getPayloadData())) { , null, payloadData)) {
return Response.status(Response.Status.OK).build(); return Response.status(Response.Status.OK).build();
} else { } else {
String msg = "Error occurred while publishing the event."; String msg = "Error occurred while publishing the event.";

@ -1,49 +0,0 @@
/*
* 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;
}
}

@ -1,41 +0,0 @@
/*
* 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;
}
}

@ -19,6 +19,9 @@
package org.wso2.carbon.device.mgt.common.pull.notification; package org.wso2.carbon.device.mgt.common.pull.notification;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
import java.util.Map; import java.util.Map;
/** /**
@ -28,7 +31,7 @@ public interface PullNotificationSubscriber {
void init(Map<String, String> properties); void init(Map<String, String> properties);
void execute(NotificationContext ctx) throws PullNotificationExecutionFailedException; void execute(DeviceIdentifier deviceIdentifier, Operation operation) throws PullNotificationExecutionFailedException;
void clean(); void clean();
} }

@ -32,7 +32,6 @@ import org.wso2.carbon.device.mgt.common.operation.mgt.Activity;
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.operation.mgt.OperationManagementException; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
import org.wso2.carbon.device.mgt.common.policy.mgt.PolicyMonitoringManager; import org.wso2.carbon.device.mgt.common.policy.mgt.PolicyMonitoringManager;
import org.wso2.carbon.device.mgt.common.pull.notification.NotificationContext;
import org.wso2.carbon.device.mgt.common.pull.notification.PullNotificationExecutionFailedException; import org.wso2.carbon.device.mgt.common.pull.notification.PullNotificationExecutionFailedException;
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.spi.DeviceManagementService; import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
@ -356,6 +355,6 @@ public interface DeviceManagementProviderService {
* This retrieves the device pull notification payload and passes to device type executor. * This retrieves the device pull notification payload and passes to device type executor.
* @throws PullNotificationExecutionFailedException * @throws PullNotificationExecutionFailedException
*/ */
void executePullNotification(String deviceType, NotificationContext notificationContext) void updatePullNotificationOperation(DeviceIdentifier deviceIdentifier, Operation operation)
throws PullNotificationExecutionFailedException; throws PullNotificationExecutionFailedException;
} }

@ -28,7 +28,6 @@ import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.DeviceManager; import org.wso2.carbon.device.mgt.common.DeviceManager;
import org.wso2.carbon.device.mgt.common.DeviceNotFoundException; import org.wso2.carbon.device.mgt.common.DeviceNotFoundException;
import org.wso2.carbon.device.mgt.common.pull.notification.NotificationContext;
import org.wso2.carbon.device.mgt.common.pull.notification.PullNotificationExecutionFailedException; import org.wso2.carbon.device.mgt.common.pull.notification.PullNotificationExecutionFailedException;
import org.wso2.carbon.device.mgt.common.pull.notification.PullNotificationSubscriber; import org.wso2.carbon.device.mgt.common.pull.notification.PullNotificationSubscriber;
import org.wso2.carbon.device.mgt.core.dto.DeviceTypeServiceIdentifier; import org.wso2.carbon.device.mgt.core.dto.DeviceTypeServiceIdentifier;
@ -2207,12 +2206,12 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
} }
@Override @Override
public void executePullNotification(String deviceType, NotificationContext notificationContext) public void updatePullNotificationOperation(DeviceIdentifier deviceIdentifier, Operation operation)
throws PullNotificationExecutionFailedException { throws PullNotificationExecutionFailedException {
DeviceManagementService dms = DeviceManagementService dms =
pluginRepository.getDeviceManagementService(deviceType, this.getTenantId()); pluginRepository.getDeviceManagementService(deviceIdentifier.getType(), this.getTenantId());
if (dms == null) { if (dms == null) {
String message = "Device type '" + deviceType + "' does not have an associated device management " + String message = "Device type '" + deviceIdentifier.getType() + "' does not have an associated device management " +
"plugin registered within the framework"; "plugin registered within the framework";
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug(message); log.debug(message);
@ -2222,8 +2221,8 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
PullNotificationSubscriber pullNotificationSubscriber = dms.getPullNotificationSubscriber(); PullNotificationSubscriber pullNotificationSubscriber = dms.getPullNotificationSubscriber();
if (pullNotificationSubscriber == null) { if (pullNotificationSubscriber == null) {
throw new PullNotificationExecutionFailedException("Pull Notification Subscriber is not configured " + throw new PullNotificationExecutionFailedException("Pull Notification Subscriber is not configured " +
"for device type" + deviceType); "for device type" + deviceIdentifier.getType());
} }
pullNotificationSubscriber.execute(notificationContext); pullNotificationSubscriber.execute(deviceIdentifier, operation);
} }
} }

@ -80,12 +80,12 @@ public class DeviceTypeManagerService implements DeviceManagementService {
this.policyMonitoringManager = new DefaultPolicyMonitoringManager(); this.policyMonitoringManager = new DefaultPolicyMonitoringManager();
} }
if (deviceTypeConfiguration.getPullNotificationExecutor() != null) { if (deviceTypeConfiguration.getPullNotificationSubscriber() != null) {
String className = deviceTypeConfiguration.getPullNotificationExecutor().getClassName(); String className = deviceTypeConfiguration.getPullNotificationSubscriber().getClassName();
if (className != null && !className.isEmpty()) { if (className != null && !className.isEmpty()) {
PullNotificationSubscriberLoader pullNotificationExecutorImpl = new PullNotificationSubscriberLoader(className PullNotificationSubscriberLoader pullNotificationSubscriberLoader = new PullNotificationSubscriberLoader(className
, deviceTypeConfiguration.getPullNotificationExecutor().getConfigProperties()); , deviceTypeConfiguration.getPullNotificationSubscriber().getConfigProperties());
this.pullNotificationSubscriber = pullNotificationExecutorImpl.getPullNotificationSubscriber(); this.pullNotificationSubscriber = pullNotificationSubscriberLoader.getPullNotificationSubscriber();
} }
} }
} }

@ -36,6 +36,7 @@ import org.wso2.carbon.device.mgt.extensions.device.type.template.config.PolicyM
import org.wso2.carbon.device.mgt.extensions.device.type.template.config.Properties; import org.wso2.carbon.device.mgt.extensions.device.type.template.config.Properties;
import org.wso2.carbon.device.mgt.extensions.device.type.template.config.Property; import org.wso2.carbon.device.mgt.extensions.device.type.template.config.Property;
import org.wso2.carbon.device.mgt.extensions.device.type.template.config.ProvisioningConfig; import org.wso2.carbon.device.mgt.extensions.device.type.template.config.ProvisioningConfig;
import org.wso2.carbon.device.mgt.extensions.device.type.template.config.PullNotificationSubscriber;
import org.wso2.carbon.device.mgt.extensions.device.type.template.config.PushNotificationProvider; import org.wso2.carbon.device.mgt.extensions.device.type.template.config.PushNotificationProvider;
import org.wso2.carbon.device.mgt.extensions.device.type.template.config.TaskConfiguration; import org.wso2.carbon.device.mgt.extensions.device.type.template.config.TaskConfiguration;
@ -50,6 +51,7 @@ import java.util.Map;
public class HTTPDeviceTypeManagerService extends DeviceTypeManagerService implements DeviceTypeDefinitionProvider { public class HTTPDeviceTypeManagerService extends DeviceTypeManagerService implements DeviceTypeDefinitionProvider {
private DeviceTypeMetaDefinition deviceTypeMetaDefinition; private DeviceTypeMetaDefinition deviceTypeMetaDefinition;
private static final String DEFAULT_PULL_NOTIFICATION_CLASS_NAME = "org.wso2.carbon.device.mgt.extensions.pull.notification";
public HTTPDeviceTypeManagerService(String deviceTypeName, DeviceTypeMetaDefinition deviceTypeMetaDefinition) { public HTTPDeviceTypeManagerService(String deviceTypeName, DeviceTypeMetaDefinition deviceTypeMetaDefinition) {
super(getDeviceTypeConfigIdentifier(deviceTypeName), getDeviceTypeConfiguration( super(getDeviceTypeConfigIdentifier(deviceTypeName), getDeviceTypeConfiguration(
@ -163,6 +165,9 @@ public class HTTPDeviceTypeManagerService extends DeviceTypeManagerService imple
deviceTypeConfiguration.setOperations(initialOperationConfig.getOperations()); deviceTypeConfiguration.setOperations(initialOperationConfig.getOperations());
} }
} }
PullNotificationSubscriber pullNotificationSubscriber = new PullNotificationSubscriber();
pullNotificationSubscriber.setClassName(DEFAULT_PULL_NOTIFICATION_CLASS_NAME);
deviceTypeConfiguration.setPullNotificationSubscriber(pullNotificationSubscriber);
return deviceTypeConfiguration; return deviceTypeConfiguration;
} }

@ -233,22 +233,22 @@ public class DeviceTypeConfiguration {
} }
/** /**
* Gets the value of the pullNotificationSubscriber property. * Gets the value of the PullNotificationSubscriber property.
* *
* @return possible object is * @return possible object is
* {@link PullNotificationSubscriber } * {@link PullNotificationSubscriber }
*/ */
public PullNotificationSubscriber getPullNotificationExecutor() { public PullNotificationSubscriber getPullNotificationSubscriber() {
return pullNotificationSubscriber; return pullNotificationSubscriber;
} }
/** /**
* Sets the value of the pullNotificationSubscriber property. * Sets the value of the PullNotificationSubscriber property.
* *
* @param value allowed object is * @param value allowed object is
* {@link PullNotificationSubscriber } * {@link PullNotificationSubscriber }
*/ */
public void setPullNotificationExecutor(PullNotificationSubscriber value) { public void setPullNotificationSubscriber(PullNotificationSubscriber value) {
this.pullNotificationSubscriber = value; this.pullNotificationSubscriber = value;
} }

Loading…
Cancel
Save