Config(String name, Properties properties) { this.name = name; //return only editable options this.body = getPropertyAsString(properties); }
@GET @Path("/{name}") public Response getConfigByName(@PathParam("name") String name) { switch (name) { case TOKEN_MAIL_BODY : return ok(new Config(name, textHolder.tokenBody).toString()); case SERVER_PROPERTIES_FILENAME : return ok(new Config(name, serverProperties).toString()); case MAIL_PROPERTIES_FILENAME : return ok(new Config(name, new MailProperties(Collections.emptyMap())).toString()); case GCM_PROPERTIES_FILENAME : return ok(new Config(name, new GCMProperties(Collections.emptyMap())).toString()); case TWITTER_PROPERTIES_FILENAME : return ok(new Config(name, new TwitterProperties(Collections.emptyMap())).toString()); default : return badRequest(); } }
@GET @Path("") public Response getConfigs(@QueryParam("_filters") String filterParam, @QueryParam("_page") int page, @QueryParam("_perPage") int size, @QueryParam("_sortField") String sortField, @QueryParam("_sortDir") String sortOrder) { List<Config> configs = new ArrayList<>(); configs.add(new Config(SERVER_PROPERTIES_FILENAME)); configs.add(new Config(MAIL_PROPERTIES_FILENAME)); configs.add(new Config(GCM_PROPERTIES_FILENAME)); configs.add(new Config(DB_PROPERTIES_FILENAME)); configs.add(new Config(TWITTER_PROPERTIES_FILENAME)); configs.add(new Config(TOKEN_MAIL_BODY)); return appendTotalCountHeader( ok(sort(configs, sortField, sortOrder), page, size), configs.size() ); }
@PUT @Consumes(value = MediaType.APPLICATION_JSON) @Path("/{name}") public Response updateConfig(@PathParam("name") String name, Config updatedConfig) { log.info("Updating config {}. New body : ", name); log.info("{}", updatedConfig.body); switch (name) { case TOKEN_MAIL_BODY: textHolder.tokenBody = updatedConfig.body; break; case SERVER_PROPERTIES_FILENAME : Properties properties = readPropertiesFromString(updatedConfig.body); serverProperties.putAll(properties); break; } return ok(updatedConfig.toString()); }