public Stream<T> objects(ResourcePath path) { if (path.isEmpty()) { return this.objects.stream(); } String name = path.head().name(); ObjectsTree<T> wildcardChild = this.children.get("*"); Stream<T> wildcardSubs = null; if ( wildcardChild != null ) { wildcardSubs = wildcardChild.objects.stream(); } ObjectsTree<T> child = this.children.get(name); Stream<T> childSubs = null; if (child != null) { childSubs = child.objects(path.subPath()); } if ( wildcardSubs != null && childSubs != null ) { return Stream.concat( childSubs, wildcardSubs ); } if ( wildcardSubs != null ) { return wildcardSubs; } if ( childSubs != null ) { return childSubs; } List<T> empty = Collections.emptyList(); return empty.stream(); }
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(); }
public void appendSegment(String segment) { this.segments.add( new Segment( segment) ); }
id = new ResourcePath(id).tail().toString();
if (!htmlApp.head().name().equals(this.id)) { htmlApp.prependSegment(this.id);
throw new IllegalArgumentException("Uri out of scope: " + uri); if (!pathSegments.get(0).name().equals(thisPath.get(0).name())) { throw new IllegalArgumentException("Uri out of scope of current application (" + thisPath.get(0) + "): " + uri); if (!pathSegments.get(1).name().equals(thisPath.get(1).name())) { throw new IllegalArgumentException("Uri out of scope of current service (" + thisPath.get(1) + "): " + uri); String tableName = pathSegments.get(2).name(); if (tableName.equals(this.id)) { continue; throw new IllegalArgumentException("Table not found: " + tableName + " (uri: " + uri + ")"); String itemId = pathSegments.get(3).name();
String filename = segments.size() < 1 ? "unknown" : segments.get(segments.size()-1).name(); factory.createAttribute(original, "filename", filename);
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();
boolean meta = segments.getLast().matrixParameters().containsKey("meta"); String name = count == 1 ? "" : segment.name(); ObjectId parentId = count == 1 ? null : last.getId();
return; String applicationPrefix = path.segments().get(0).name();
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); } }
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { if (msg instanceof ByteBuf) { bytesRead += ((ByteBuf) msg).readableBytes(); startTime = startTime != 0 ? startTime : System.currentTimeMillis(); } else if (msg instanceof DefaultHttpRequest) { DefaultHttpRequest req = (DefaultHttpRequest) msg; event = new AnalyticsEvent(); startTime = startTime != 0 ? startTime : System.currentTimeMillis(); event.setTimestamp(startTime); event.setMethod(req.getMethod().name()); event.setUri(req.getUri()); event.clientAddress(ctx.channel().remoteAddress()); //event.uri(req.resourcePath().toString()); } else if (msg instanceof ResourceRequest) { ResourceRequest req = (ResourceRequest) msg; event.setApplication(req.resourcePath().head().toString()); event.setUserId(req.requestContext().securityContext().getSubject()); event.setApiRequest(true); } super.channelRead(ctx, msg); }
public TraversalPlan(RequestType requestType, ResourcePath path) { List<ResourcePath.Segment> segments = path.segments(); for (ResourcePath.Segment segment : segments) { if (!segment.name().equals("")) { this.steps.add(new ReadStep(segment.name())); } } switch (requestType) { case CREATE: this.steps.add(new CreateStep()); break; case READ: // nothing break; case UPDATE: this.steps.add(new UpdateStep()); break; case DELETE: this.steps.add(new DeleteStep()); break; } }
@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)); } }
public synchronized void updateApplication(InternalApplication application) throws IOException { ObjectNode tree = read(); tree.put("name", application.name()); ResourcePath htmlAppPath = application.htmlApplicationResourcePath(); if (htmlAppPath != null) { if (htmlAppPath.head().name().equals(application.id())) { htmlAppPath = htmlAppPath.subPath(); } tree.put("html-app", htmlAppPath.toString()); } tree.put("visible", application.visible()); String versioningResourceId = application.versionResourceId(); if (versioningResourceId != null) { tree.put("version-resource-id", versioningResourceId); } write(tree); }
public ObjectsTree<T> findLeaf(ResourcePath path) { if (path.isEmpty()) { return this; } String id = path.head().name(); ObjectsTree<T> child = this.children.get(id); if (child == null) { child = new ObjectsTree<>(); this.children.put(path.head().name(), child); } // For now, support * just at the end if (id.equals("*") && !path.subPath().isEmpty()) { throw new IllegalArgumentException("* supported just at the end. Remaining path is " + path.subPath()); } return child.findLeaf(path.subPath()); }
/** * @param children * @return true if this resourcePath is equal to or is parent of argument */ public boolean isParentOf(ResourcePath children) { if (this.segments.size() > children.segments.size()) { return false; } for (int i=0 ; i<this.segments.size() ; i++) { if (!this.segments.get(i).equals(children.segments.get(i))) { return false; } } return true; }
public void prependSegment(String segment) { this.segments.add(0, new Segment( segment) ); }
private String getPrefix(ResourcePath path) { String prefix = "/" + path.head().name(); return prefix; }
@Override public boolean equals(Object obj) { if ( obj instanceof Segment ) { return this.name.equals( ((Segment) obj).name() ); } return false; }