private Inflector<ContainerRequestContext, Response> addRemoveTypesHandler() {
return new Inflector<ContainerRequestContext, Response>() {
public Response apply(ContainerRequestContext ctx) {
String appid = Config.APP_NAME_NS; // TODO
App app = dao.read(new App(appid).getId());
Map<String, Object> tmap = RestUtils.getMapFromEntity(ctx.getEntityStream());
if (app != null && tmap != null) {
String datatype = (String) tmap.get("type");
if (StringUtils.isBlank(datatype)) {
if (POST.equals(ctx.getMethod())) {
app.addDatatypes(datatype);
} else if (DELETE.equals(ctx.getMethod())) {
app.removeDatatypes(datatype);
}
return Response.ok(app.getDatatypes()).build();
} else {
return RestUtils.getStatusResponse(Response.Status.BAD_REQUEST, "'type' cannot be empty.");
}
} else {
return RestUtils.getStatusResponse(Response.Status.BAD_REQUEST);