EntityConfigResource extends AbstractBrooklynRestResource implements EntityConfigApi { @SuppressWarnings({ "rawtypes", "unchecked" }) @Override public void setFromMap(String application, String entityToken, Boolean recurse, Map newValues) { final Entity entity = brooklyn().getEntity(application, entityToken); if (!Entitlements.isEntitled(mgmt().getEntitlementManager(), Entitlements.MODIFY_ENTITY, entity)) { throw WebResourceUtils.forbidden("User '%s' is not authorized to modify entity '%s'", Entitlements.getEntitlementContext().user(), entity); } if (LOG.isDebugEnabled()) LOG.debug("REST user " + Entitlements.getEntitlementContext() + " setting configs " + newValues); for (Object entry : newValues.entrySet()) { String configName = Strings.toString(((Map.Entry) entry).getKey()); Object newValue = ((Map.Entry) entry).getValue(); ConfigKey ck = findConfig(entity, configName); ((EntityInternal) entity).config().set(ck, TypeCoercions.coerce(newValue, ck.getTypeToken())); if (Boolean.TRUE.equals(recurse)) { for (Entity e2 : Entities.descendantsWithoutSelf(entity)) { ((EntityInternal) e2).config().set(ck, newValue); } } } }  @Override List<ConfigSummary> list(final String application, final String entityToken); @Override Map<String, Object> batchConfigRead(String application, String entityToken, Boolean raw); @Override Object get(String application, String entityToken, String configKeyName, Boolean raw); @Override String getPlain(String application, String entityToken, String configKeyName, Boolean raw); Object get(boolean preferJson, String application, String entityToken, String configKeyName, Boolean raw); @SuppressWarnings({ "rawtypes", "unchecked" }) @Override void setFromMap(String application, String entityToken, Boolean recurse, Map newValues); @SuppressWarnings({ "rawtypes", "unchecked" }) @Override void set(String application, String entityToken, String configName, Boolean recurse, Object newValue);  }
@Test public void testSetFromMap() throws Exception { try { String uri = "/applications/simple-app/entities/simple-ent/config"; Response response = client().path(uri) .type(MediaType.APPLICATION_JSON_TYPE) .post(MutableMap.of( RestMockSimpleEntity.SAMPLE_CONFIG.getName(), "hello world")); assertEquals(response.getStatus(), Response.Status.NO_CONTENT.getStatusCode()); assertEquals(entity.getConfig(RestMockSimpleEntity.SAMPLE_CONFIG), "hello world"); String value = client().path(uri+"/"+RestMockSimpleEntity.SAMPLE_CONFIG.getName()).accept(MediaType.APPLICATION_JSON_TYPE).get(String.class); assertEquals(value, "\"hello world\""); } finally { entity.config().set(RestMockSimpleEntity.SAMPLE_CONFIG, RestMockSimpleEntity.SAMPLE_CONFIG.getDefaultValue()); } }