Merge pull request #270 from milanperera/apim

Implemented API publishing to Synapse Gateway
revert-dabc3590
Milan Perera 9 years ago
commit 3c5aaaef61

@ -53,7 +53,6 @@ public interface VirtualFireAlarmService {
@Feature(code = "buzz", name = "Buzzer On / Off", description = "Switch on/off Virtual Fire Alarm Buzzer. (On / Off)") @Feature(code = "buzz", name = "Buzzer On / Off", description = "Switch on/off Virtual Fire Alarm Buzzer. (On / Off)")
Response switchBuzzer(@PathParam("deviceId") String deviceId, @QueryParam("protocol") String protocol, Response switchBuzzer(@PathParam("deviceId") String deviceId, @QueryParam("protocol") String protocol,
@FormParam("state") String state); @FormParam("state") String state);
/** /**
* Retrieve Sensor data for the device type * Retrieve Sensor data for the device type

@ -54,15 +54,7 @@ import org.wso2.carbon.identity.jwt.client.extension.dto.AccessTokenInfo;
import org.wso2.carbon.identity.jwt.client.extension.exception.JWTClientException; import org.wso2.carbon.identity.jwt.client.extension.exception.JWTClientException;
import org.wso2.carbon.user.api.UserStoreException; import org.wso2.carbon.user.api.UserStoreException;
import javax.ws.rs.Consumes; import javax.ws.rs.*;
import javax.ws.rs.FormParam;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import java.io.IOException; import java.io.IOException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
@ -73,6 +65,7 @@ import java.util.*;
public class VirtualFireAlarmServiceImpl implements VirtualFireAlarmService { public class VirtualFireAlarmServiceImpl implements VirtualFireAlarmService {
private static final String XMPP_PROTOCOL = "XMPP"; private static final String XMPP_PROTOCOL = "XMPP";
private static final String MQTT_PROTOCOL = "MQTT";
private static final String KEY_TYPE = "PRODUCTION"; private static final String KEY_TYPE = "PRODUCTION";
private static ApiApplicationKey apiApplicationKey; private static ApiApplicationKey apiApplicationKey;
private static Log log = LogFactory.getLog(VirtualFireAlarmServiceImpl.class); private static Log log = LogFactory.getLog(VirtualFireAlarmServiceImpl.class);
@ -81,13 +74,24 @@ public class VirtualFireAlarmServiceImpl implements VirtualFireAlarmService {
@Path("device/{deviceId}/buzz") @Path("device/{deviceId}/buzz")
public Response switchBuzzer(@PathParam("deviceId") String deviceId, @QueryParam("protocol") String protocol, public Response switchBuzzer(@PathParam("deviceId") String deviceId, @QueryParam("protocol") String protocol,
@FormParam("state") String state) { @FormParam("state") String state) {
if (state == null || state.isEmpty()) {
log.error("State is not defined for the buzzer operation");
return Response.status(Response.Status.BAD_REQUEST).build();
}
String switchToState = state.toUpperCase(); String switchToState = state.toUpperCase();
if (!switchToState.equals(VirtualFireAlarmConstants.STATE_ON) && !switchToState.equals( if (!switchToState.equals(VirtualFireAlarmConstants.STATE_ON) && !switchToState.equals(
VirtualFireAlarmConstants.STATE_OFF)) { VirtualFireAlarmConstants.STATE_OFF)) {
log.error("The requested state change shoud be either - 'ON' or 'OFF'"); log.error("The requested state change shoud be either - 'ON' or 'OFF'");
return Response.status(Response.Status.BAD_REQUEST).build(); return Response.status(Response.Status.BAD_REQUEST).build();
} }
String protocolString = protocol.toUpperCase(); String protocolString;
if (protocol == null || protocol.isEmpty()) {
protocolString = MQTT_PROTOCOL;
} else {
protocolString = protocol.toUpperCase();
}
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Sending request to switch-bulb of device [" + deviceId + "] via " + log.debug("Sending request to switch-bulb of device [" + deviceId + "] via " +
protocolString); protocolString);

@ -37,7 +37,7 @@
</Permission> </Permission>
<Permission> <Permission>
<name>Control Buzz</name> <name>Control Buzz</name>
<path>/device-mgt/user/operations</path> <path>/device-mgt/user/operation</path>
<url>/device/*/buzz</url> <url>/device/*/buzz</url>
<method>POST</method> <method>POST</method>
<scope>virtual_firealarm_user</scope> <scope>virtual_firealarm_user</scope>
@ -47,6 +47,6 @@
<path>/device-mgt/user/stats</path> <path>/device-mgt/user/stats</path>
<url>/device/stats/*</url> <url>/device/stats/*</url>
<method>GET</method> <method>GET</method>
<scope>virtual_firealarm_device</scope> <scope>virtual_firealarm_user</scope>
</Permission> </Permission>
</PermissionConfiguration> </PermissionConfiguration>
Loading…
Cancel
Save