org.glassfish.jersey.process.Inflector Java Examples
The following examples show how to use
org.glassfish.jersey.process.Inflector.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Api1.java From para with Apache License 2.0 | 6 votes |
/** * @param a {@link App} * @return response */ @SuppressWarnings("unchecked") public static Inflector<ContainerRequestContext, Response> addConstrHandler(final App a) { return new Inflector<ContainerRequestContext, Response>() { public Response apply(ContainerRequestContext ctx) { App app = (a != null) ? a : getPrincipalApp(); String type = pathParam(Config._TYPE, ctx); String field = pathParam("field", ctx); String cname = pathParam("cname", ctx); if (app != null) { Response payloadRes = getEntity(ctx.getEntityStream(), Map.class); if (payloadRes.getStatusInfo() == Response.Status.OK) { Map<String, Object> payload = (Map<String, Object>) payloadRes.getEntity(); if (app.addValidationConstraint(type, field, Constraint.build(cname, payload))) { app.update(); } } return Response.ok(app.getAllValidationConstraints(type)).build(); } return getStatusResponse(Response.Status.NOT_FOUND, "App not found."); } }; }
Example #2
Source File: Api1.java From para with Apache License 2.0 | 6 votes |
private Inflector<ContainerRequestContext, Response> setupHandler() { return new Inflector<ContainerRequestContext, Response>() { public Response apply(ContainerRequestContext ctx) { String appid = pathParam(Config._APPID, ctx); if (!StringUtils.isBlank(appid)) { App app = SecurityUtils.getAuthenticatedApp(); if (app != null && app.isRootApp()) { boolean sharedIndex = "true".equals(queryParam("sharedIndex", ctx)); boolean sharedTable = "true".equals(queryParam("sharedTable", ctx)); return Response.ok(newApp(appid, queryParam("name", ctx), sharedIndex, sharedTable)).build(); } else { return getStatusResponse(Response.Status.FORBIDDEN, "Only root app can create and initialize other apps."); } } return Response.ok(setup()).build(); } }; }
Example #3
Source File: RouterTypeTest.java From lambadaframework with MIT License | 6 votes |
private ResourceMethod getResourceMethod() { org.glassfish.jersey.server.model.Resource.Builder resourceBuilder = org.glassfish.jersey.server.model.Resource.builder(); resourceBuilder.path("/helloworld/{id}"); org.glassfish.jersey.server.model.ResourceMethod resourceMethod = resourceBuilder .addMethod("GET") .consumes(MediaType.APPLICATION_JSON_TYPE) .produces(MediaType.APPLICATION_JSON_TYPE) .handledBy(new Inflector<ContainerRequestContext, Object>() { @Override public Object apply(ContainerRequestContext containerRequestContext) { return "HELLO"; } }) .build(); Resource resource = new Resource(resourceBuilder.build()); return resource.getResourceMethods().get(0); }
Example #4
Source File: Api1.java From para with Apache License 2.0 | 6 votes |
/** * @param a {@link App} * @return response */ public static Inflector<ContainerRequestContext, Response> revokePermitHandler(final App a) { return new Inflector<ContainerRequestContext, Response>() { public Response apply(ContainerRequestContext ctx) { App app = (a != null) ? a : getPrincipalApp(); String subjectid = pathParam("subjectid", ctx); String type = pathParam(Config._TYPE, ctx); if (app != null) { boolean revoked; if (type != null) { revoked = app.revokeResourcePermission(subjectid, type); } else { revoked = app.revokeAllResourcePermissions(subjectid); } if (revoked) { app.update(); } return Response.ok(app.getAllResourcePermissions(subjectid)).build(); } return getStatusResponse(Response.Status.NOT_FOUND, "App not found."); } }; }
Example #5
Source File: Api1.java From para with Apache License 2.0 | 6 votes |
/** * @param a {@link App} * @return response */ public static Inflector<ContainerRequestContext, Response> checkPermitHandler(final App a) { return new Inflector<ContainerRequestContext, Response>() { public Response apply(ContainerRequestContext ctx) { App app = (a != null) ? a : getPrincipalApp(); String subjectid = pathParam("subjectid", ctx); String resourcePath = pathParam(Config._TYPE, ctx); String httpMethod = pathParam("method", ctx); if (app != null) { return Response.ok(app.isAllowedTo(subjectid, resourcePath, httpMethod), MediaType.TEXT_PLAIN_TYPE).build(); } return getStatusResponse(Response.Status.NOT_FOUND, "App not found."); } }; }
Example #6
Source File: Api1.java From para with Apache License 2.0 | 6 votes |
/** * @param a {@link App} * @return response */ public static Inflector<ContainerRequestContext, Response> getPermitHandler(final App a) { return new Inflector<ContainerRequestContext, Response>() { public Response apply(ContainerRequestContext ctx) { App app = (a != null) ? a : getPrincipalApp(); String subjectid = pathParam("subjectid", ctx); if (app != null) { if (subjectid != null) { return Response.ok(app.getAllResourcePermissions(subjectid)).build(); } else { return Response.ok(app.getAllResourcePermissions()).build(); } } return getStatusResponse(Response.Status.NOT_FOUND, "App not found."); } }; }
Example #7
Source File: Api1.java From para with Apache License 2.0 | 6 votes |
/** * @param a {@link App} * @return response */ public static Inflector<ContainerRequestContext, Response> removeConstrHandler(final App a) { return new Inflector<ContainerRequestContext, Response>() { public Response apply(ContainerRequestContext ctx) { App app = (a != null) ? a : getPrincipalApp(); String type = pathParam(Config._TYPE, ctx); String field = pathParam("field", ctx); String cname = pathParam("cname", ctx); if (app != null) { if (app.removeValidationConstraint(type, field, cname)) { app.update(); } return Response.ok(app.getAllValidationConstraints(type)).build(); } return getStatusResponse(Response.Status.NOT_FOUND, "App not found."); } }; }
Example #8
Source File: Api1.java From para with Apache License 2.0 | 6 votes |
/** * @param a {@link App} * @return response */ public static Inflector<ContainerRequestContext, Response> getConstrHandler(final App a) { return new Inflector<ContainerRequestContext, Response>() { public Response apply(ContainerRequestContext ctx) { App app = (a != null) ? a : getPrincipalApp(); String type = pathParam(Config._TYPE, ctx); if (app != null) { if (type != null) { return Response.ok(app.getAllValidationConstraints(type)).build(); } else { return Response.ok(app.getAllValidationConstraints()).build(); } } return getStatusResponse(Response.Status.NOT_FOUND, "App not found."); } }; }
Example #9
Source File: Api1.java From para with Apache License 2.0 | 6 votes |
/** * @return response */ public static Inflector<ContainerRequestContext, Response> meHandler() { return new Inflector<ContainerRequestContext, Response>() { public Response apply(ContainerRequestContext ctx) { if (GET.equals(ctx.getMethod())) { User user = SecurityUtils.getAuthenticatedUser(); App app = SecurityUtils.getAuthenticatedApp(); if (user != null) { return Response.ok(user).build(); } else if (app != null) { return Response.ok(app).build(); } } return Response.status(Response.Status.UNAUTHORIZED).build(); } }; }
Example #10
Source File: Api1.java From para with Apache License 2.0 | 6 votes |
/** * @param a {@link App} * @return response */ @SuppressWarnings("unchecked") public static Inflector<ContainerRequestContext, Response> batchUpdateHandler(final App a) { return new Inflector<ContainerRequestContext, Response>() { public Response apply(ContainerRequestContext ctx) { App app = (a != null) ? a : getPrincipalApp(); Response entityRes = getEntity(ctx.getEntityStream(), List.class); if (entityRes.getStatusInfo() == Response.Status.OK) { List<Map<String, Object>> newProps = (List<Map<String, Object>>) entityRes.getEntity(); ArrayList<String> ids = new ArrayList<>(newProps.size()); for (Map<String, Object> props : newProps) { if (props != null && props.containsKey(Config._ID)) { ids.add((String) props.get(Config._ID)); } } return getBatchUpdateResponse(app, getDAO().readAll(app.getAppIdentifier(), ids, true), newProps); } else { return entityRes; } } }; }
Example #11
Source File: Api1.java From para with Apache License 2.0 | 6 votes |
private Inflector<ContainerRequestContext, Response> typeCrudHandler() { return new Inflector<ContainerRequestContext, Response>() { public Response apply(ContainerRequestContext ctx) { String typePlural = pathParam(Config._TYPE, ctx); App app = getPrincipalApp(); if (app != null && !StringUtils.isBlank(typePlural)) { String type = ParaObjectUtils.getAllTypes(app).get(typePlural); if (type == null) { type = typePlural; } return crudHandler(app, type).apply(ctx); } return getStatusResponse(Response.Status.NOT_FOUND, "App not found."); } }; }
Example #12
Source File: Api1.java From para with Apache License 2.0 | 6 votes |
/** * @param app {@link App} * @param type a type * @return response */ public static Inflector<ContainerRequestContext, Response> searchHandler(final App app, final String type) { return new Inflector<ContainerRequestContext, Response>() { public Response apply(ContainerRequestContext ctx) { App app1 = (app == null) ? getPrincipalApp() : app; MultivaluedMap<String, String> params = ctx.getUriInfo().getQueryParameters(); String query = params.getFirst("q"); if (!StringUtils.isBlank(query) && !getSearch().isValidQueryString(query)) { return getStatusResponse(Response.Status.BAD_REQUEST, "Invalid query string syntax q=" + query + " in request " + ctx.getMethod() + " " + ctx.getUriInfo().getRequestUri()); } String queryType = pathParam("querytype", ctx); if (StringUtils.isBlank(queryType)) { queryType = "default"; } return Response.ok(RestUtils.buildQueryAndSearch(app1, queryType, params, type)).build(); } }; }
Example #13
Source File: Api1.java From para with Apache License 2.0 | 6 votes |
/** * @return response */ public static Inflector<ContainerRequestContext, Response> reindexHandler() { return new Inflector<ContainerRequestContext, Response>() { public Response apply(ContainerRequestContext ctx) { App app = getPrincipalApp(); if (app != null) { long startTime = System.nanoTime(); MultivaluedMap<String, String> params = ctx.getUriInfo().getQueryParameters(); Pager pager = RestUtils.getPagerFromParams(params); String destinationIndex = params.getFirst("destinationIndex"); getSearch().rebuildIndex(getDAO(), app, destinationIndex, pager); long tookMillis = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime); Map<String, Object> response = new HashMap<>(2); response.put("reindexed", pager.getCount()); response.put("tookMillis", tookMillis); return Response.ok(response, JSON).build(); } return getStatusResponse(Response.Status.NOT_FOUND, "App not found."); } }; }
Example #14
Source File: Api1.java From para with Apache License 2.0 | 5 votes |
/** * @param a {@link App} * @return response */ public static Inflector<ContainerRequestContext, Response> batchCreateHandler(final App a) { return new Inflector<ContainerRequestContext, Response>() { public Response apply(ContainerRequestContext ctx) { App app = (a != null) ? a : getPrincipalApp(); return getBatchCreateResponse(app, ctx.getEntityStream()); } }; }
Example #15
Source File: Api1.java From para with Apache License 2.0 | 5 votes |
/** * @param a {@link App} * @return response */ @SuppressWarnings("unchecked") public static Inflector<ContainerRequestContext, Response> appSettingsHandler(final App a) { return new Inflector<ContainerRequestContext, Response>() { public Response apply(ContainerRequestContext ctx) { App app = (a != null) ? a : getPrincipalApp(); String key = pathParam("key", ctx); if (app != null) { if (PUT.equals(ctx.getMethod())) { Response resp = getEntity(ctx.getEntityStream(), Map.class); if (resp.getStatusInfo() == Response.Status.OK) { Map<String, Object> setting = (Map<String, Object>) resp.getEntity(); if (!StringUtils.isBlank(key) && setting.containsKey("value")) { app.addSetting(key, setting.get("value")); } else { app.clearSettings().addAllSettings(setting); } app.update(); return Response.ok().build(); } else { return getStatusResponse(Response.Status.BAD_REQUEST); } } else if (DELETE.equals(ctx.getMethod())) { app.removeSetting(key); app.update(); return Response.ok().build(); } else { if (StringUtils.isBlank(key)) { return Response.ok(app.getSettings()).build(); } else { return Response.ok(Collections.singletonMap("value", app.getSetting(key))).build(); } } } return getStatusResponse(Response.Status.FORBIDDEN, "Not allowed."); } }; }
Example #16
Source File: Api1.java From para with Apache License 2.0 | 5 votes |
/** * @param a {@link App} * @return response */ public static Inflector<ContainerRequestContext, Response> batchReadHandler(final App a) { return new Inflector<ContainerRequestContext, Response>() { public Response apply(ContainerRequestContext ctx) { App app = (a != null) ? a : getPrincipalApp(); return getBatchReadResponse(app, queryParams("ids", ctx)); } }; }
Example #17
Source File: Api1.java From para with Apache License 2.0 | 5 votes |
/** * @param a {@link App} * @param type a type * @return response */ public static Inflector<ContainerRequestContext, Response> deleteHandler(final App a, final String type) { return new Inflector<ContainerRequestContext, Response>() { public Response apply(ContainerRequestContext ctx) { App app = (a != null) ? a : getPrincipalApp(); ParaObject obj = ParaObjectUtils.toObject(app, type); obj.setId(pathParam(Config._ID, ctx)); return getDeleteResponse(app, obj); } }; }
Example #18
Source File: Api1.java From para with Apache License 2.0 | 5 votes |
/** * @param a {@link App} * @return response */ public static Inflector<ContainerRequestContext, Response> batchDeleteHandler(final App a) { return new Inflector<ContainerRequestContext, Response>() { public Response apply(ContainerRequestContext ctx) { App app = (a != null) ? a : getPrincipalApp(); return getBatchDeleteResponse(app, queryParams("ids", ctx)); } }; }
Example #19
Source File: Api1.java From para with Apache License 2.0 | 5 votes |
/** * @param a {@link App} * @param type a type * @return response */ public static Inflector<ContainerRequestContext, Response> overwriteHandler(final App a, final String type) { return new Inflector<ContainerRequestContext, Response>() { public Response apply(ContainerRequestContext ctx) { // full update - equivalent to PUT method App app = (a != null) ? a : getPrincipalApp(); return getOverwriteResponse(app, pathParam(Config._ID, ctx), type, ctx.getEntityStream()); } }; }
Example #20
Source File: Api1.java From para with Apache License 2.0 | 5 votes |
/** * @param a {@link App} * @param type a type * @return response */ public static Inflector<ContainerRequestContext, Response> updateHandler(final App a, final String type) { return new Inflector<ContainerRequestContext, Response>() { public Response apply(ContainerRequestContext ctx) { App app = (a != null) ? a : getPrincipalApp(); ParaObject obj = ParaObjectUtils.toObject(app, type); obj.setId(pathParam(Config._ID, ctx)); // allow apps to partially update themselves String appid = StringUtils.equals(type, Utils.type(App.class)) ? app.getAppid() : app.getAppIdentifier(); // partial update - equivalent to PATCH method return getUpdateResponse(app, getDAO().read(appid, obj.getId()), ctx.getEntityStream()); } }; }
Example #21
Source File: Api1.java From para with Apache License 2.0 | 5 votes |
/** * @param a {@link App} * @param type a type * @return response */ public static Inflector<ContainerRequestContext, Response> readHandler(final App a, final String type) { return new Inflector<ContainerRequestContext, Response>() { public Response apply(ContainerRequestContext ctx) { App app = (a != null) ? a : getPrincipalApp(); ParaObject obj = ParaObjectUtils.toObject(app, type); obj.setId(pathParam(Config._ID, ctx)); if (app.getId().equals(obj.getId())) { return getReadResponse(app, app); } return getReadResponse(app, getDAO().read(app.getAppIdentifier(), obj.getId())); } }; }
Example #22
Source File: Api1.java From para with Apache License 2.0 | 5 votes |
/** * @param a {@link App} * @param type a type * @return response */ public static Inflector<ContainerRequestContext, Response> createHandler(final App a, final String type) { return new Inflector<ContainerRequestContext, Response>() { public Response apply(ContainerRequestContext ctx) { App app = (a != null) ? a : getPrincipalApp(); return getCreateResponse(app, type, ctx.getEntityStream()); } }; }
Example #23
Source File: Api1.java From para with Apache License 2.0 | 5 votes |
private Inflector<ContainerRequestContext, Response> keysHandler() { return new Inflector<ContainerRequestContext, Response>() { public Response apply(ContainerRequestContext ctx) { App app = SecurityUtils.getAuthenticatedApp(); if (app != null) { app.resetSecret(); CoreUtils.getInstance().overwrite(app); Map<String, String> creds = app.getCredentials(); creds.put("info", "Save the secret key! It is showed only once!"); return Response.ok(creds).build(); } return getStatusResponse(Response.Status.UNAUTHORIZED, "Not an app."); } }; }
Example #24
Source File: Api1.java From para with Apache License 2.0 | 5 votes |
private Inflector<ContainerRequestContext, Response> listTypesHandler() { return new Inflector<ContainerRequestContext, Response>() { public Response apply(ContainerRequestContext ctx) { App app = getPrincipalApp(); if (app != null) { return Response.ok(ParaObjectUtils.getAllTypes(app)).build(); } return getStatusResponse(Response.Status.NOT_FOUND, "App not found."); } }; }
Example #25
Source File: Api1.java From para with Apache License 2.0 | 5 votes |
private static Inflector<ContainerRequestContext, Response> healthCheckHandler() { return new Inflector<ContainerRequestContext, Response>() { public Response apply(ContainerRequestContext ctx) { if (HealthUtils.getInstance().isHealthy()) { return Response.ok(Collections.singletonMap("message", "healthy")).build(); } else { return getStatusResponse(Response.Status.INTERNAL_SERVER_ERROR, "unhealthy"); } } }; }
Example #26
Source File: Api1.java From para with Apache License 2.0 | 5 votes |
/** * @param a {@link App} * @return response */ @SuppressWarnings("unchecked") public static Inflector<ContainerRequestContext, Response> grantPermitHandler(final App a) { return new Inflector<ContainerRequestContext, Response>() { public Response apply(ContainerRequestContext ctx) { App app = (a != null) ? a : getPrincipalApp(); String subjectid = pathParam("subjectid", ctx); String resourcePath = pathParam(Config._TYPE, ctx); if (app != null) { Response resp = getEntity(ctx.getEntityStream(), List.class); if (resp.getStatusInfo() == Response.Status.OK) { List<String> permission = (List<String>) resp.getEntity(); Set<App.AllowedMethods> set = new HashSet<>(permission.size()); for (String perm : permission) { if (!StringUtils.isBlank(perm)) { App.AllowedMethods method = App.AllowedMethods.fromString(perm); if (method != null) { set.add(method); } } } if (!set.isEmpty()) { if (app.grantResourcePermission(subjectid, resourcePath, EnumSet.copyOf(set))) { app.update(); } return Response.ok(app.getAllResourcePermissions(subjectid)).build(); } else { return getStatusResponse(Response.Status.BAD_REQUEST, "No allowed methods specified."); } } else { return resp; } } return getStatusResponse(Response.Status.NOT_FOUND, "App not found."); } }; }
Example #27
Source File: Api1.java From para with Apache License 2.0 | 5 votes |
/** * @return response */ public static Inflector<ContainerRequestContext, Response> readIdHandler() { return new Inflector<ContainerRequestContext, Response>() { public Response apply(ContainerRequestContext ctx) { App app = getPrincipalApp(); String id = pathParam(Config._ID, ctx); if (app != null) { return getReadResponse(app, getDAO().read(app.getAppIdentifier(), id)); } return getStatusResponse(Response.Status.NOT_FOUND, "App not found."); } }; }
Example #28
Source File: Api1.java From para with Apache License 2.0 | 5 votes |
/** * @param app {@link App} * @param type a type * @return response */ public static Inflector<ContainerRequestContext, Response> crudHandler(final App app, final String type) { return new Inflector<ContainerRequestContext, Response>() { public Response apply(ContainerRequestContext ctx) { String id = pathParam(Config._ID, ctx); if (StringUtils.isBlank(id)) { if (GET.equals(ctx.getMethod())) { return searchHandler(app, type).apply(ctx); } else if (POST.equals(ctx.getMethod())) { return createHandler(app, type).apply(ctx); } else if (ctx.getUriInfo().getPath().contains("search")) { return searchHandler(app, type).apply(ctx); } } else { if (GET.equals(ctx.getMethod())) { return readHandler(app, type).apply(ctx); } else if (PUT.equals(ctx.getMethod())) { return overwriteHandler(app, type).apply(ctx); } else if (PATCH.equals(ctx.getMethod())) { return updateHandler(app, type).apply(ctx); } else if (DELETE.equals(ctx.getMethod())) { return deleteHandler(app, type).apply(ctx); } } return getStatusResponse(Response.Status.NOT_FOUND, "Type '" + type + "' not found."); } }; }
Example #29
Source File: Api1.java From para with Apache License 2.0 | 5 votes |
private Inflector<ContainerRequestContext, Response> introHandler() { return new Inflector<ContainerRequestContext, Response>() { public Response apply(ContainerRequestContext ctx) { Map<String, String> info = new TreeMap<>(); info.put("info", "Para - the backend for busy developers."); if (Config.getConfigBoolean("print_version", true)) { info.put("version", StringUtils.replace(getVersion(), "-SNAPSHOT", "")); } return Response.ok(info).build(); } }; }
Example #30
Source File: Api1.java From para with Apache License 2.0 | 5 votes |
private void registerCrudApi(String path, Inflector<ContainerRequestContext, Response> handler, Inflector<ContainerRequestContext, Response> linksHandler) { Resource.Builder core = Resource.builder(path); // list endpoints (both do the same thing) core.addMethod(GET).produces(JSON).handledBy(handler); core.addChildResource("search/{querytype}").addMethod(GET).produces(JSON).handledBy(handler); core.addChildResource("search").addMethod(GET).produces(JSON).handledBy(handler); // CRUD endpoints (non-batch) core.addMethod(POST).produces(JSON).consumes(JSON).handledBy(handler); core.addChildResource("{id}").addMethod(GET).produces(JSON).handledBy(handler); core.addChildResource("{id}").addMethod(PUT).produces(JSON).consumes(JSON).handledBy(handler); core.addChildResource("{id}").addMethod(PATCH).produces(JSON).consumes(JSON).handledBy(handler); core.addChildResource("{id}").addMethod(DELETE).produces(JSON).handledBy(handler); // links CRUD endpoints core.addChildResource("{id}/links/{type2}/{id2}").addMethod(GET).produces(JSON).handledBy(linksHandler); core.addChildResource("{id}/links/{type2}").addMethod(GET).produces(JSON).handledBy(linksHandler); core.addChildResource("{id}/links/{id2}").addMethod(POST).produces(JSON).handledBy(linksHandler); core.addChildResource("{id}/links/{id2}").addMethod(PUT).produces(JSON).handledBy(linksHandler); core.addChildResource("{id}/links/{type2}/{id2}").addMethod(DELETE).produces(JSON).handledBy(linksHandler); core.addChildResource("{id}/links").addMethod(DELETE).produces(JSON).handledBy(linksHandler); // CRUD endpoints (batch) Resource.Builder batch = Resource.builder("_batch"); batch.addMethod(POST).produces(JSON).consumes(JSON).handledBy(batchCreateHandler(null)); batch.addMethod(GET).produces(JSON).handledBy(batchReadHandler(null)); batch.addMethod(PUT).produces(JSON).consumes(JSON).handledBy(batchCreateHandler(null)); batch.addMethod(PATCH).produces(JSON).consumes(JSON).handledBy(batchUpdateHandler(null)); batch.addMethod(DELETE).produces(JSON).handledBy(batchDeleteHandler(null)); registerResources(core.build()); registerResources(batch.build()); }