/** * {@inheritDoc} * * @see Location#with(Path) */ @Override public Location with( Path newPath ) { if (newPath == null) return this; Property idProperty = getIdProperties().get(0); // fast return Location.create(newPath, idProperty); }
protected String printable( Location location ) { if (location.hasPath()) { return "'" + location.getPath() + "'" + (location.hasIdProperties() ? " " + location.getIdProperties() + "" : ""); } return location.getIdProperties().toString(); }
/** * {@inheritDoc} * * @see java.lang.Comparable#compareTo(java.lang.Object) */ public int compareTo( Location that ) { if (this == that) return 0; if (this.hasPath() && that.hasPath()) { return this.getPath().compareTo(that.getPath()); } UUID thisUuid = this.getUuid(); UUID thatUuid = that.getUuid(); if (thisUuid != null && thatUuid != null) { return thisUuid.compareTo(thatUuid); } return this.hashCode() - that.hashCode(); }
/** * Return whether this branch contains the specified location. * * @param location the location * @return true if this branch includes the location, or false otherwise */ public boolean includes( Location location ) { if (location == null || !location.hasPath()) return false; return this.nodes.containsKey(location.getPath()); }
ProjectedRequest projectedRequest = federatedRequest.getFirstProjectedRequest(); Location actualLocation = Location.create(getExecutionContext().getValueFactories().getPathFactory().createRootPath()); while (projectedRequest != null) { VerifyNodeExistsRequest readFromSource = (VerifyNodeExistsRequest)projectedRequest.getRequest(); if (sourceLocation.hasIdProperties()) { for (Property propertyInSource : sourceLocation.getIdProperties()) { Name name = propertyInSource.getName(); Property existing = actualLocation.getIdProperty(name); if (existing != null) { actualLocation = actualLocation.with(propertyInSource);
@Test public void testTransitivityOfWithOperationForPathAndProperty() { Location locationA1 = Location.create(pathA); locationA1 = locationA1.with(propB); Location locationU1 = Location.create(propB); locationU1 = locationU1.with(pathA); assertThat("With() operation must be transitive for equals", locationA1.equals(locationU1), is(true)); assertThat("With() operation must be transitive for isSame", locationA1.isSame(locationU1), is(true)); assertThat("With() operation must be transitive for getString", locationA1.getString().equals(locationU1.getString()), is(true)); assertThat("With() operation must be transitive for hashCode", locationA1.hashCode() == locationU1.hashCode(), is(true)); }
Path federatedPath = request.of().getPath(); Map<Name, Integer> childSnsIndexes = new HashMap<Name, Integer>(); ProjectedRequest projectedRequest = federatedRequest.getFirstProjectedRequest(); projection); request.addChild(childInRepos); if (federatedPath == null) federatedPath = childInRepos.getPath().getParent(); } else { ReadAllChildrenRequest readFromSource = (ReadAllChildrenRequest)sourceRequest; Location sourceLocation = readFromSource.getActualLocationOfNode(); if (sourceLocation.hasIdProperties()) { for (Property propertyInSource : sourceLocation.getIdProperties()) { Name name = propertyInSource.getName(); Property existing = actualLocation.getIdProperty(name); if (existing != null) { actualLocation = actualLocation.with(propertyInSource); if (federatedPath == null) federatedPath = actualLocation.getPath(); if (!actualLocation.hasPath()) { assert federatedPath != null; actualLocation = actualLocation.with(federatedPath);
protected Location getActualLocation( Location location, MapNode node ) { Path path = location.getPath(); if (path == null) { // Find the path on the node ... LinkedList<Path.Segment> segments = new LinkedList<Path.Segment>(); MapNode n = node; while (n != null) { if (n.getParent() == null) break; segments.addFirst(n.getName()); n = n.getParent(); } path = pathFactory.createAbsolutePath(segments); } // If there is a UUID in the location, it should match the node's. assert location.getUuid() == null || location.getUuid().equals(node.getUuid()); if (location.hasIdProperties()) { return location.with(path); } return Location.create(path, node.getUuid()); }
protected Location determineActualLocation( Location actualInSource, Projection projection ) { assert projection != null; // Get the projection from the source-specific location ... Path pathInSource = actualInSource.getPath(); for (Path path : projection.getPathsInRepository(pathInSource, pathFactory)) { return actualInSource.with(path); } return actualInSource; }
projected1.setActualLocationOfNode(Location.create(projected1.at().getPath(), UUID.randomUUID())); projected1.addProperty(property("propA", "valueA")); projected1.addProperty(property("propB", "valueB")); projected2.setActualLocationOfNode(Location.create(projected2.at().getPath(), UUID.randomUUID())); projected2.addProperty(property("propC", "valueC")); projected2.addProperty(property("propD", "valueD")); assertThat(original.getActualLocationOfNode().getPath(), is(path("/a/b/c"))); assertThat(original.getActualLocationOfNode().getUuid(), is(projected1.getActualLocationOfNode().getUuid())); assertThat(original.getActualLocationOfNode().getIdProperty(ModeShapeLexicon.UUID).isMultiple(), is(true)); assertThat(original.getActualLocationOfNode().getIdProperty(ModeShapeLexicon.UUID).getValuesAsArray()[0], is((Object)projected1.getActualLocationOfNode().getUuid())); assertThat(original.getActualLocationOfNode().getIdProperty(ModeShapeLexicon.UUID).getValuesAsArray()[1], is((Object)projected2.getActualLocationOfNode().getUuid())); assertThat(original.getChildren().get(0).getPath(), is(path("/a/b/c/child1"))); assertThat(original.getChildren().get(1).getPath(), is(path("/a/b/c/child2"))); assertThat(original.getChildren().get(2).getPath(), is(path("/a/b/c/child2[2]"))); assertThat(original.getChildren().get(3).getPath(), is(path("/a/b/c/child3")));
public T to( Location desiredLocation ) { if (!desiredLocation.hasPath()) { throw new IllegalArgumentException(GraphI18n.unableToCopyToLocationWithoutAPath.text(this.from, desiredLocation)); } Path desiredPath = desiredLocation.getPath(); if (desiredPath.isRoot()) { throw new IllegalArgumentException(GraphI18n.unableToCopyToTheRoot.text(this.from, desiredLocation)); } Path parent = desiredPath.getParent(); return submit(this.fromWorkspaceName, this.from, Location.create(parent), desiredPath.getLastSegment().getName()); }
protected Location getActualLocation( WorkspaceType workspace, Location location, NodeType node ) { Path path = txn.pathFor(workspace, node); // the location's path might not be right if (location.hasIdProperties()) { return location.with(path); } return Location.create(path, node.getUuid()); }
protected Snapshot( Node<?, PropertyPayload> node, boolean pathsOnly, boolean includeProperties ) { this.location = pathsOnly && node.getLocation().hasIdProperties() ? Location.create(node.getLocation().getPath()) : node.getLocation(); this.isLoaded = node.isLoaded(); this.isChanged = node.isChanged(false); this.id = node.getNodeId(); this.properties = includeProperties ? node.getProperties() : null; }
public void addChild( Location parent, String childName ) { Path path = context.getValueFactories().getPathFactory().create(parent.getPath(), segment(childName)); Map<Name, Property> properties = Collections.emptyMap(); List<ProjectedNode> grandChildren = Collections.emptyList(); PlaceholderNode child = new PlaceholderNode(Location.create(path), properties, grandChildren); this.children.add(child); }
/** * Project the supplied location in a source into its federated location. The projection is used to find the location under * the supplied ancestor. Any errors are recorded on the original request. * * @param ancestorInFederation the ancestor in the federated repository; may not be null * @param projection the projection that should be used; may not be null * @param actualSourceLocation the actual location in the source that is to be projected back into the federated repository; * may not be null * @param originalRequest the original request, if there are errors; may not be null * @return the location in the federated repository */ protected Location projectToFederated( Location ancestorInFederation, Projection projection, Location actualSourceLocation, Request originalRequest ) { Path ancestorPath = ancestorInFederation.getPath(); Path actualPathInSource = actualSourceLocation.getPath(); // Project the actual location ... for (Path path : projection.getPathsInRepository(actualPathInSource, pathFactory)) { if (path.isAtOrBelow(ancestorPath)) { return actualSourceLocation.with(path); } } // Record that there was an error projecting the results ... String whereInSource = actualSourceLocation.getString(getExecutionContext().getNamespaceRegistry()); String msg = GraphI18n.unableToProjectSourceInformationIntoWorkspace.text(whereInSource, getSourceName(), projection); originalRequest.setError(new InvalidRequestException(msg)); return null; }
@Test public void shouldFindRootByUUID() { Node root = graph.getNodeAt("/"); Location rootLocation = root.getLocation(); UUID uuid = rootLocation.getUuid(); if (uuid != null) { // Find the root node using the identification properties ... Node anotherRoot = graph.getNodeAt(uuid); assertThat(anotherRoot.getLocation().isSame(root.getLocation()), is(true)); assertThat(anotherRoot.getLocation().getPath(), is(root.getLocation().getPath())); assertThat(anotherRoot.getLocation().getIdProperties(), is(root.getLocation().getIdProperties())); assertThat(anotherRoot.getLocation().getUuid(), is(root.getLocation().getUuid())); } }
/** * {@inheritDoc} * * @see org.modeshape.graph.connector.base.Transaction#verifyNodeExists(org.modeshape.graph.connector.base.Workspace, * org.modeshape.graph.Location) */ public Location verifyNodeExists( WorkspaceType workspace, Location location ) { NodeType node = getNode(workspace, location); if (location.hasPath() && location.getUuid() != null) return location; if (location.hasPath()) { if (location.getUuid() != null) return location; // Missing UUID ... return location.with(node.getUuid()); } Path path = pathFor(workspace, node); return location.with(path); }
private Location actualLocationOf( Location location ) { // If the location has a path, then use the location if (location.hasPath()) return location; // Otherwise, create a new location with an artificial path ... Path path = context.getValueFactories().getPathFactory().create("/a/b/c/d"); return Location.create(path, location.getIdProperties()); } }