changed response payload definition for pull notification

revert-70aa11f8
ayyoob 8 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.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.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.PullNotificationSubscriber;
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 {
Operation operation = new Operation();
operation.setId(ctx.getNotificationPayload().getOperationId());
operation.setPayLoad(ctx.getNotificationPayload().getPayload());
@Override
public void execute(DeviceIdentifier deviceIdentifier, Operation operation) throws PullNotificationExecutionFailedException {
try {
PullNotificationDataHolder.getInstance().getDeviceManagementProviderService().updateOperation(
ctx.getDeviceId(), operation);
deviceIdentifier, operation);
} catch (OperationManagementException e) {
throw new PullNotificationExecutionFailedException(e);
}

@ -22,6 +22,7 @@ import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import javax.validation.constraints.Size;
import java.util.Map;
/**
* 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 {
@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;
}
public void setPayloadData(Object[] payloadData) {
public void setPayloadData(Map<String, Object> payloadData) {
this.payloadData = payloadData;
}

@ -59,6 +59,7 @@ import javax.ws.rs.core.Response;
import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@Path("/device/agent")
public class DeviceAgentServiceImpl implements DeviceAgentService {
@ -205,7 +206,6 @@ public class DeviceAgentServiceImpl implements DeviceAgentService {
public Response publishEvents(@Valid EventBeanWrapper eventBeanWrapper, @PathParam("type") String type
, @PathParam("deviceId") String deviceId) {
String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
try {
if (eventBeanWrapper == null) {
@ -238,7 +238,7 @@ public class DeviceAgentServiceImpl implements DeviceAgentService {
, 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";
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
}
@ -247,13 +247,16 @@ public class DeviceAgentServiceImpl implements DeviceAgentService {
DeviceMgtAPIUtils.getDynamicEventCache().put(type, eventAttributeList);
}
}
Object[] payload = eventBeanWrapper.getPayloadData();
Map<String, Object> payload = eventBeanWrapper.getPayloadData();
int i = 0;
Object[] payloadData = new Object[eventAttributeList.getList().size()];
for (Attribute attribute : eventAttributeList.getList()) {
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) {
payload[i] = ((Double) payload[i]).longValue();
payloadData[i] = ((Double) payload.get(attribute.getName())).longValue();
} else {
payloadData[i] = payload.get(attribute.getName());
}
i++;
}
@ -262,7 +265,7 @@ public class DeviceAgentServiceImpl implements DeviceAgentService {
if (DeviceMgtAPIUtils.getEventPublisherService().publishEvent(DeviceMgtAPIUtils.getStreamDefinition(type
, PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain())
, Constants.DEFAULT_STREAM_VERSION, metaData
, null, eventBeanWrapper.getPayloadData())) {
, null, payloadData)) {
return Response.status(Response.Status.OK).build();
} else {
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;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
import java.util.Map;
/**
@ -28,7 +31,7 @@ public interface PullNotificationSubscriber {
void init(Map<String, String> properties);
void execute(NotificationContext ctx) throws PullNotificationExecutionFailedException;
void execute(DeviceIdentifier deviceIdentifier, Operation operation) throws PullNotificationExecutionFailedException;
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.OperationManagementException;
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.push.notification.NotificationStrategy;
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.
* @throws PullNotificationExecutionFailedException
*/
void executePullNotification(String deviceType, NotificationContext notificationContext)
void updatePullNotificationOperation(DeviceIdentifier deviceIdentifier, Operation operation)
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.DeviceManager;
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.PullNotificationSubscriber;
import org.wso2.carbon.device.mgt.core.dto.DeviceTypeServiceIdentifier;
@ -2207,12 +2206,12 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
}
@Override
public void executePullNotification(String deviceType, NotificationContext notificationContext)
public void updatePullNotificationOperation(DeviceIdentifier deviceIdentifier, Operation operation)
throws PullNotificationExecutionFailedException {
DeviceManagementService dms =
pluginRepository.getDeviceManagementService(deviceType, this.getTenantId());
pluginRepository.getDeviceManagementService(deviceIdentifier.getType(), this.getTenantId());
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";
if (log.isDebugEnabled()) {
log.debug(message);
@ -2222,8 +2221,8 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
PullNotificationSubscriber pullNotificationSubscriber = dms.getPullNotificationSubscriber();
if (pullNotificationSubscriber == null) {
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();
}
if (deviceTypeConfiguration.getPullNotificationExecutor() != null) {
String className = deviceTypeConfiguration.getPullNotificationExecutor().getClassName();
if (deviceTypeConfiguration.getPullNotificationSubscriber() != null) {
String className = deviceTypeConfiguration.getPullNotificationSubscriber().getClassName();
if (className != null && !className.isEmpty()) {
PullNotificationSubscriberLoader pullNotificationExecutorImpl = new PullNotificationSubscriberLoader(className
, deviceTypeConfiguration.getPullNotificationExecutor().getConfigProperties());
this.pullNotificationSubscriber = pullNotificationExecutorImpl.getPullNotificationSubscriber();
PullNotificationSubscriberLoader pullNotificationSubscriberLoader = new PullNotificationSubscriberLoader(className
, deviceTypeConfiguration.getPullNotificationSubscriber().getConfigProperties());
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.Property;
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.TaskConfiguration;
@ -50,6 +51,7 @@ import java.util.Map;
public class HTTPDeviceTypeManagerService extends DeviceTypeManagerService implements DeviceTypeDefinitionProvider {
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) {
super(getDeviceTypeConfigIdentifier(deviceTypeName), getDeviceTypeConfiguration(
@ -163,6 +165,9 @@ public class HTTPDeviceTypeManagerService extends DeviceTypeManagerService imple
deviceTypeConfiguration.setOperations(initialOperationConfig.getOperations());
}
}
PullNotificationSubscriber pullNotificationSubscriber = new PullNotificationSubscriber();
pullNotificationSubscriber.setClassName(DEFAULT_PULL_NOTIFICATION_CLASS_NAME);
deviceTypeConfiguration.setPullNotificationSubscriber(pullNotificationSubscriber);
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
* {@link PullNotificationSubscriber }
*/
public PullNotificationSubscriber getPullNotificationExecutor() {
public PullNotificationSubscriber getPullNotificationSubscriber() {
return pullNotificationSubscriber;
}
/**
* Sets the value of the pullNotificationSubscriber property.
* Sets the value of the PullNotificationSubscriber property.
*
* @param value allowed object is
* {@link PullNotificationSubscriber }
*/
public void setPullNotificationExecutor(PullNotificationSubscriber value) {
public void setPullNotificationSubscriber(PullNotificationSubscriber value) {
this.pullNotificationSubscriber = value;
}

Loading…
Cancel
Save