@Test public void testSet() throws Exception { try { ClientResponse response = client().resource(SENSORS_ENDPOINT + "/" + SENSOR_NAME) .type(MediaType.APPLICATION_JSON_TYPE) .post(ClientResponse.class, 67890); assertEquals(response.getStatus(), Response.Status.NO_CONTENT.getStatusCode()); assertEquals(entity.getAttribute(SENSOR), (Integer)67890); String value = client().resource(SENSORS_ENDPOINT + "/" + SENSOR_NAME).accept(MediaType.TEXT_PLAIN_TYPE).get(String.class); assertEquals(value, "67890 frogs"); } finally { addAmphibianSensor(entity); } }
@SuppressWarnings({ "rawtypes", "unchecked" }) @Override public void set(String application, String entityToken, String sensorName, Object newValue) { final Entity entity = brooklyn().getEntity(application, entityToken); if (!Entitlements.isEntitled(mgmt().getEntitlementManager(), Entitlements.MODIFY_ENTITY, entity)) { throw WebResourceUtils.unauthorized("User '%s' is not authorized to modify entity '%s'", Entitlements.getEntitlementContext().user(), entity); } AttributeSensor sensor = findSensor(entity, sensorName); if (log.isDebugEnabled()) log.debug("REST user "+Entitlements.getEntitlementContext()+" setting sensor "+sensorName+" to "+newValue); entity.sensors().set(sensor, newValue); }
SensorResource extends AbstractBrooklynRestResource implements SensorApi { @SuppressWarnings({ "rawtypes", "unchecked" }) @Override public void set(String application, String entityToken, String sensorName, Object newValue) { final Entity entity = brooklyn().getEntity(application, entityToken); if (!Entitlements.isEntitled(mgmt().getEntitlementManager(), Entitlements.MODIFY_ENTITY, entity)) { throw WebResourceUtils.unauthorized("User '%s' is not authorized to modify entity '%s'", Entitlements.getEntitlementContext().user(), entity); } AttributeSensor sensor = findSensor(entity, sensorName); if (log.isDebugEnabled()) log.debug("REST user "+Entitlements.getEntitlementContext()+" setting sensor "+sensorName+" to "+newValue); entity.sensors().set(sensor, newValue); } }
SensorResource extends AbstractBrooklynRestResource implements SensorApi { @SuppressWarnings({ "rawtypes", "unchecked" }) @Override public void set(String application, String entityToken, String sensorName, Object newValue) { final Entity entity = brooklyn().getEntity(application, entityToken); if (!Entitlements.isEntitled(mgmt().getEntitlementManager(), Entitlements.MODIFY_ENTITY, entity)) { throw WebResourceUtils.unauthorized("User '%s' is not authorized to modify entity '%s'", Entitlements.getEntitlementContext().user(), entity); } AttributeSensor sensor = findSensor(entity, sensorName); if (log.isDebugEnabled()) log.debug("REST user "+Entitlements.getEntitlementContext()+" setting sensor "+sensorName+" to "+newValue); entity.sensors().set(sensor, newValue); }  }
SensorResource extends AbstractBrooklynRestResource implements SensorApi { @SuppressWarnings({ "rawtypes", "unchecked" }) @Override public void set(String application, String entityToken, String sensorName, Object newValue) { final Entity entity = brooklyn().getEntity(application, entityToken); if (!Entitlements.isEntitled(mgmt().getEntitlementManager(), Entitlements.MODIFY_ENTITY, entity)) { throw WebResourceUtils.unauthorized("User '%s' is not authorized to modify entity '%s'", Entitlements.getEntitlementContext().user(), entity); } AttributeSensor sensor = findSensor(entity, sensorName); if (log.isDebugEnabled()) log.debug("REST user "+Entitlements.getEntitlementContext()+" setting sensor "+sensorName+" to "+newValue); entity.sensors().set(sensor, newValue); }  @SuppressWarnings("rawtypes") @Override List<SensorSummary> list(final String application, final String entityToken); @Override Map<String, Object> batchSensorRead(final String application, final String entityToken, final Boolean raw); @Override String getPlain(String application, String entityToken, String sensorName, final Boolean raw); @Override Object get(final String application, final String entityToken, String sensorName, final Boolean raw); @SuppressWarnings({ "rawtypes", "unchecked" }) @Override void setFromMap(String application, String entityToken, Map newValues); @SuppressWarnings({ "rawtypes", "unchecked" }) @Override void set(String application, String entityToken, String sensorName, Object newValue); @Override void delete(String application, String entityToken, String sensorName); }
SensorResource extends AbstractBrooklynRestResource implements SensorApi { @SuppressWarnings({ "rawtypes", "unchecked" }) @Override public void set(String application, String entityToken, String sensorName, Object newValue) { final Entity entity = brooklyn().getEntity(application, entityToken); if (!Entitlements.isEntitled(mgmt().getEntitlementManager(), Entitlements.MODIFY_ENTITY, entity)) { throw WebResourceUtils.unauthorized("User '%s' is not authorized to modify entity '%s'", Entitlements.getEntitlementContext().user(), entity); } AttributeSensor sensor = findSensor(entity, sensorName); if (log.isDebugEnabled()) log.debug("REST user "+Entitlements.getEntitlementContext()+" setting sensor "+sensorName+" to "+newValue); entity.sensors().set(sensor, newValue); }  @SuppressWarnings("rawtypes") @Override List<SensorSummary> list(final String application, final String entityToken); @Override Map<String, Object> batchSensorRead(final String application, final String entityToken, final Boolean raw); @Override String getPlain(String application, String entityToken, String sensorName, final Boolean raw); @Override Object get(final String application, final String entityToken, String sensorName, final Boolean raw); @SuppressWarnings({ "rawtypes", "unchecked" }) @Override void setFromMap(String application, String entityToken, Map newValues); @SuppressWarnings({ "rawtypes", "unchecked" }) @Override void set(String application, String entityToken, String sensorName, Object newValue); @Override void delete(String application, String entityToken, String sensorName);  }