@Override public boolean equals(Object obj) { if ( obj instanceof Segment ) { return this.name.equals( ((Segment) obj).name() ); } return false; }
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(); }
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; } }
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 name = count == 1 ? "" : segment.name(); ObjectId parentId = count == 1 ? null : last.getId();
URI refStateUri = refState.uri(); if (refStateUri != null) { id = new ResourcePath(refStateUri.toString()).tail().name();
return; String applicationPrefix = path.segments().get(0).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)); } }
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); } }
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()); }
private String getPrefix(ResourcePath path) { String prefix = "/" + path.head().name(); return prefix; }
private String getPrefix(ResourcePath path) { if (path.segments().size() < 1) { return null; } String prefix = "/" + path.head().name(); return prefix; }