Example usage for com.amazonaws.services.sns.model InvalidParameterException getMessage

List of usage examples for com.amazonaws.services.sns.model InvalidParameterException getMessage

Introduction

In this page you can find the example usage for com.amazonaws.services.sns.model InvalidParameterException getMessage.

Prototype

@Override
    public String getMessage() 

Source Link

Usage

From source file:edu.byu.mpn.rest.DeviceController.java

License:Apache License

@POST
public Response createDevice(@DefaultValue("") @QueryParam("proxyId") String proxyId,
        @DefaultValue("false") @QueryParam("testTopic") boolean testTopic, Device device) {
    LOG.info("/v1/devices POST");

    Response errorResponse = validateCreateDevice(device, proxyId);
    if (errorResponse != null) {
        return errorResponse;
    }/* w  ww  . j  ava 2s . co  m*/

    //      Checks whether device already exists
    Device deviceByToken = deviceDao.getDeviceByTokenAndPlatform(device.getToken(), device.getDevicePlatform());
    if (deviceByToken != null) {
        if (device.getPersonId().equals(deviceByToken.getPersonId())) {
            return Response.status(Response.Status.OK).entity(deviceByToken).build();
        } else {
            return Response.status(Response.Status.FORBIDDEN).entity(EX_NACHO_DEVICE).build();
        }
    }

    device.setDateRegistered(new Date());
    final String platformApplicationArn = APPLE.equals(device.getDevicePlatform()) ? applePlatformApplicationArn
            : androidPlatformApplicationArn;

    try {
        device.setEndpointArn(
                mpnClient.createPlatformEndpoint(device.getToken(), platformApplicationArn).getEndpointArn());
        device.setSubscriptionArn(mpnClient.subscribeDevice(device.getEndpointArn(), topicArn,
                device.getPersonId(), device.getDeviceName()).getSubscriptionArn());
        if (testTopic) {
            mpnClient.subscribeDevice(device.getEndpointArn(), testTopicArn, device.getPersonId(),
                    device.getDeviceName());
        }
    } catch (InvalidParameterException e) {
        LOG.error(e.getMessage(), e);
        return Response.status(Response.Status.BAD_REQUEST).entity(new ResponseMessage(e.getMessage())).build();
    }

    deviceDao.saveOrUpdateDevice(device, getLoggedInPersonId());
    return Response.status(Response.Status.CREATED).entity(device).build();
}

From source file:edu.byu.mpn.rest.DeviceController.java

License:Apache License

@Path("/{id}")
@PUT/*from   ww w. j  a  v a  2 s  . c  o m*/
public Response updateDevice(@PathParam("id") Integer id,
        @DefaultValue("") @QueryParam("proxyId") String proxyId, Device device) {
    LOG.info("/v1/devices/{id} PUT");

    Response errorResponse = validateUpdateDevice(id, device, proxyId);
    if (errorResponse != null) {
        return errorResponse;
    }

    Device currentDevice = deviceDao.getDeviceById(id);
    //      If deviceId or deviceName are included in the request body, update them in the database
    currentDevice
            .setDeviceId(device.getDeviceId() == null ? currentDevice.getDeviceId() : device.getDeviceId());
    currentDevice.setDeviceName(
            device.getDeviceName() == null ? currentDevice.getDeviceName() : device.getDeviceName());
    if (currentDevice.getPersonId() == null) {
        //         If device is being registered, set new dateRegistered
        currentDevice.setDateRegistered(new Date());
        currentDevice.setPersonId(device.getPersonId());
        currentDevice.setSubscriptionArn(mpnClient.subscribeDevice(currentDevice.getEndpointArn(), topicArn,
                currentDevice.getPersonId(), currentDevice.getDeviceName()).getSubscriptionArn());
    }

    if (!currentDevice.getToken().equals(device.getToken())) {
        currentDevice.setToken(device.getToken());
        try {
            mpnClient.updatePlatformEndpoint(currentDevice.getToken(), currentDevice.getEndpointArn());
        } catch (InvalidParameterException e) {
            LOG.error(e.getMessage(), e);
            return Response.status(Response.Status.BAD_REQUEST).entity(new ResponseMessage(e.getMessage()))
                    .build();
        }
    }

    deviceDao.saveOrUpdateDevice(currentDevice, getLoggedInPersonId());
    return Response.status(Response.Status.OK).entity(currentDevice).build();
}