public StatusResource(URI uri, ResourceProcessingException e) { this.uri = uri; this.error = e; id = new ResourcePath(uri.toString()).tail().toString(); }
private String selfHrefId(String field, Object val) { if (val == null || val instanceof ResourceState == false) { throw new RuntimeException("Invalid value for '" + field + "': " + val); } String href = null; if (val instanceof ResourceRef) { href = ((ResourceRef) val).uri().toString(); if (href == null) { throw new RuntimeException("Not a valid resource reference - empty uri - for '" + field + "': " + val); } } else { Object self = ((ResourceState) val).getProperty(LiveOak.SELF); if (self == null || self instanceof ResourceState == false) { throw new RuntimeException("Not a valid resource reference - no 'self' - for '" + field + "': " + val); } href = ((ResourceState) self).getPropertyAsString(LiveOak.HREF); if (href == null) { throw new RuntimeException("Not a valid resource reference - no 'self/href' - for '" + field + "': " + val); } } return new ResourcePath(href).tail().toString(); }
protected void addURIPolicyRule(ResourcePath resourcePath, Collection<String> requestTypes, Collection<String> allowedRoles, Collection<String> deniedRoles, Collection<String> allowedUsers, Collection<String> deniedUsers) { RolesContainer rolesContainer = new RolesContainer() .addAllAllowedRoles(allowedRoles).addAllDeniedRoles(deniedRoles) .addAllAllowedUsers(allowedUsers).addAllDeniedUsers(deniedUsers); URIPolicyRule rule = new URIPolicyRule(resourcePath, requestTypes, rolesContainer); // We want to support '/foo/bar*' which is mapped to both '/foo/bar' and '/foo/bar/*' String tailName = resourcePath.tail().name(); if (tailName.endsWith("*") && !tailName.equals("*")) { String lastSegment = tailName.substring(0, tailName.length() - 1); resourcePath = resourcePath.parent(); resourcePath.appendSegment(lastSegment); ResourcePath wildcardPath = new ResourcePath(resourcePath); wildcardPath.appendSegment("*"); this.rulesTree.addObject(rule, resourcePath); this.rulesTree.addObject(rule, wildcardPath); } else { this.rulesTree.addObject(rule, resourcePath); } log.debug("Added new URIPolicyRule for resourcePath " + resourcePath + ". Rule: " + rule); } }
String id = null; if (resRef instanceof ResourceRef) { id = ((ResourceRef) resRef).resourcePath().tail().toString(); } else if (resRef instanceof ResourceState) { ResourceState refState = (ResourceState) resRef; URI refStateUri = refState.uri(); if (refStateUri != null) { id = new ResourcePath(refStateUri.toString()).tail().name();
@Override public Resource member(RequestContext ctx, String id) throws Exception { if (BATCH_ENDPOINT.equals(id)) { return new PgSqlBatchResource(this, BATCH_ENDPOINT); } String tableId = id; boolean schemaReq = false; ResourcePath.Segment tail = ctx.resourcePath() != null ? ctx.resourcePath().tail() : null; if (tail != null && tail.matrixParameters().containsKey("schema")) { tableId = tail.name(); schemaReq = true; } List<String> tables = catalog().tableIds(); int pos = tables.indexOf(tableId); if (pos == -1) { return null; } else if (schemaReq) { return new PgSqlTableSchemaResource(this, tail.name()); } else { return new PgSqlTableResource(this, tables.get(pos)); } }
id = new ResourcePath(id).tail().toString();