StringBuilder sb = new StringBuilder(); boolean hasPath = this.hasPath(); boolean hasProps = this.hasIdProperties(); if (hasPath) { if (hasProps) {
/** * Determine whether this location has the same {@link #getPath() path} and {@link #getIdProperties() identification * properties}: if one location has a path, then both must have the same path; likewise, if one location has ID properties, * then both must have the same ID properties. * <p> * This is different than the behavior of {@link #equals(Object)}, which attempts to determine whether two locations are * <i>equivalent</i>. Two location objects are equivalent if they share the same path and/or ID properties: if both locations * have a path, they must have the same path; if both locations have ID properties, these properties must match. * </p> * * @param that the other location to be compared * @return true if they are the same, or false otherwise (or if the supplied location is null) * @see #equals(Object) */ public boolean isSame( Location that ) { if (that == null) return false; if (this.hasPath()) { if (!this.getPath().equals(that.getPath())) return false; } else if (that.hasPath()) { // this has no path, but that does return false; } if (this.hasIdProperties()) { if (that.hasIdProperties()) return this.getIdProperties().equals(that.getIdProperties()); return false; } return (!that.hasIdProperties()); }
protected String printable( Location location ) { if (location.hasPath()) { return "'" + location.getPath() + "'" + (location.hasIdProperties() ? " " + location.getIdProperties() + "" : ""); } return location.getIdProperties().toString(); }
protected String printable( Location location, Name child ) { if (location.hasPath()) { return "'" + location.getPath() + "/" + child + "'" + (location.hasIdProperties() ? " " + location.getIdProperties() + "" : ""); } return "'" + child + "' under " + location.getIdProperties().toString(); } }
sb.append(this.getPath().getString(namespaceRegistry, encoder, delimiterEncoder)); if (this.hasIdProperties()) { if (hasPath) sb.append(" && "); sb.append("[");
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()); }
this.childName = childName; this.conflictBehavior = conflictBehavior; int number = properties.length + (under.hasIdProperties() ? under.getIdProperties().size() : 0); List<Property> props = new ArrayList<Property>(number); for (Property property : properties) {
else sb.append(" "); if (location.hasIdProperties()) { sb.append(" "); if (location.getIdProperties().size() == 1 && location.getUuid() != null) {
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()); }
/** * Determine whether this move request can be determined to have no effect. * <p> * A move is known to have no effect when all of the following conditions are true: * <ul> * <li>the {@link #into() into} location has a {@link Location#hasPath() path} but no {@link Location#hasIdProperties() * identification properties};</li> * <li>the {@link #from() from} location has a {@link Location#getPath() path}; and</li> * <li>the {@link #from() from} location's {@link Path#getParent() parent} is the same as the {@link #into() into} location's * path.</li> * </ul> * If all of these conditions are not true, this method returns false. * </p> * * @return true if this move request really doesn't change the parent of the node, or false if it cannot be determined */ public boolean hasNoEffect() { if (into != null && into.hasPath() && into.hasIdProperties() == false && from.hasPath()) { if (!from.getPath().getParent().equals(into.getPath())) return false; if (desiredName() != null && !desiredName().equals(from.getPath().getLastSegment().getName())) return false; if (before != null) return false; return true; } // Can't be determined for certain return false; }
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; }
@Test public void shouldReturnRootNodeInMirrorProjection() { // Get the root node of the mirror projection using the actual graph ... Graph mirrorGraph = graphFor(mirrorSourceName, mirrorWorkspaceName); Node mirrorRoot = mirrorGraph.getNodeAt("/"); Location mirrorRootLocation = mirrorRoot.getLocation(); assertThat(mirrorRootLocation.hasIdProperties(), is(true)); assertThat(mirrorRootLocation.getUuid(), is(notNullValue())); // Get the same node through the federation source ... Node fedRoot = federated.getNodeAt("/"); Location fedRootLocation = fedRoot.getLocation(); assertThat(fedRootLocation.hasIdProperties(), is(true)); assertThat(fedRootLocation.getUuid(), is(notNullValue())); // The UUIDs of the nodes must be the same ... assertThat(fedRootLocation.getUuid(), is(mirrorRootLocation.getUuid())); }
@Test public void shouldAlwaysBeAbleToReadRootNode() { Node root = graph.getNodeAt("/"); assertThat("Connector must always have a root node", root, is(notNullValue())); assertThat("Root node must always have a path", root.getLocation().hasPath(), is(true)); assertThat("Root node must never have a null path", root.getLocation().getPath(), is(notNullValue())); assertThat("Root node's path must be the root path", root.getLocation().getPath().isRoot(), is(true)); List<Property> idProperties = root.getLocation().getIdProperties(); if (idProperties == null) { assertThat(root.getLocation().hasIdProperties(), is(false)); } else { assertThat(root.getLocation().hasIdProperties(), is(true)); } }
@Test public void shouldReturnRootNodeInBranchProjection() { // Get the top node of the branch projection using the actual graph ... Graph branchGraph = graphFor(branchSourceName, branchWorkspaceName); Node branchNode = branchGraph.getNodeAt("/Aircraft"); Location branchNodeLocation = branchNode.getLocation(); assertThat(branchNodeLocation.hasIdProperties(), is(true)); assertThat(branchNodeLocation.getUuid(), is(notNullValue())); // Get the same node through the federation source ... Node fedNode = federated.getNodeAt("/Aircraft"); Location fedNodeLocation = fedNode.getLocation(); assertThat(fedNodeLocation.hasIdProperties(), is(true)); assertThat(fedNodeLocation.getUuid(), is(notNullValue())); // The UUIDs of the nodes must be the same ... assertThat(fedNodeLocation.getUuid(), is(branchNodeLocation.getUuid())); }
@Test public void shouldFindRootByIdentificationProperties() { Node root = graph.getNodeAt("/"); Location rootLocation = root.getLocation(); if (rootLocation.hasIdProperties()) { List<Property> idProperties = rootLocation.getIdProperties(); assertThat("Root node's ID properties was null when there were supposed to be properties", idProperties, is(notNullValue())); Property firstProperty = idProperties.get(0); Property[] additionalProperties = new Property[] {}; if (idProperties.size() > 1) { List<Property> morePropertiesList = idProperties.subList(1, idProperties.size()); assertThat(morePropertiesList.isEmpty(), is(false)); additionalProperties = morePropertiesList.toArray(new Property[morePropertiesList.size()]); } // Find the root node using the identification properties ... Node anotherRoot = graph.getNodeAt(firstProperty, additionalProperties); assertThat(anotherRoot.getLocation().isSame(root.getLocation()), is(true)); assertThat(anotherRoot.getLocation().getPath(), is(root.getLocation().getPath())); assertThat(anotherRoot.getLocation().getIdProperties(), is(root.getLocation().getIdProperties())); } }
if (this.hasIdProperties()) return (this.getIdProperties().equals(that.getIdProperties()));
assertThat(location, is(notNullValue())); Node result = null; if (location.hasPath() && location.hasIdProperties()) { if (location.hasIdProperties()) { Node resultByIdProps = graph.getNodeAt(location.getIdProperties()); assertSameNode(resultByIdProps, result);
if (sourceLocation.hasIdProperties()) {
actualLocation = determineActualLocation(actualLocation, sourceLocation, projectedRequest.getProjection()); if (sourceLocation.hasIdProperties()) {
@Override public void process( MoveBranchRequest request ) { // Just update the actual location ... Name newName = request.desiredName(); if (newName == null && request.from().hasPath()) newName = request.from().getPath().getLastSegment().getName(); if (newName == null) newName = context.getValueFactories().getNameFactory().create("d"); // Figure out the new name and path (if needed)... Path newPath = null; if (request.into().hasPath()) { newPath = context.getValueFactories().getPathFactory().create(request.into().getPath(), newName); } else if (request.from().hasPath()) { newPath = context.getValueFactories().getPathFactory().create("/a/b/c"); newPath = context.getValueFactories().getPathFactory().create(newPath, newName); } else { newPath = context.getValueFactories().getPathFactory().create("/a/b/c"); newPath = context.getValueFactories().getPathFactory().create(newPath, newName); } // Figure out the old name and path ... Path oldPath = null; if (request.from().hasPath()) { oldPath = request.from().getPath(); } else { oldPath = context.getValueFactories().getPathFactory().create("/x/y/z"); oldPath = context.getValueFactories().getPathFactory().create(oldPath, newName); } Location fromLocation = request.from().hasIdProperties() ? Location.create(oldPath, request.from().getIdProperties()) : Location.create(oldPath); Location intoLocation = request.into().hasIdProperties() ? Location.create(newPath, request.into().getIdProperties()) : Location.create(newPath); request.setActualLocations(fromLocation, intoLocation); }