for (Location detectorLocation : extractorsNode.getChildren()) { Node node = subgraph.getNode(detectorLocation); String name = stringValueOf(node, ModeShapeLexicon.READABLE_NAME); String[] classpath = stringValuesOf(node, ModeShapeLexicon.CLASSPATH); Map<String, Object> properties = new HashMap<String, Object>(); for (Property property : node.getProperties()) { Name propertyName = property.getName(); if (skipNamespaces.contains(propertyName.getNamespaceUri())) continue;
private UUID uuidFor( Node node ) { UUID uuid = null; if (node.getLocation().getUuid() != null) { uuid = node.getLocation().getUuid(); } if (uuid == null && (node.getProperty(JcrLexicon.UUID) != null)) { uuid = (UUID)node.getProperty(JcrLexicon.UUID).getFirstValue(); } return uuid; }
/** * {@inheritDoc} * * @see GraphSession.Operations#materialize(org.modeshape.graph.Node, GraphSession.Node) */ public void materialize( org.modeshape.graph.Node persistentNode, Node<Payload, PropertyPayload> node ) { // Create the map of property info objects ... Map<Name, PropertyInfo<PropertyPayload>> properties = new HashMap<Name, PropertyInfo<PropertyPayload>>(); for (Property property : persistentNode.getProperties()) { Name propertyName = property.getName(); PropertyInfo<PropertyPayload> info = new PropertyInfo<PropertyPayload>(property, property.isMultiple(), Status.UNCHANGED, null); properties.put(propertyName, info); } // Set only the children ... node.loadedWith(persistentNode.getChildren(), properties, persistentNode.getExpirationTime()); }
protected void matchProperties( Batch batch, Node actualNode, Node desiredNode ) { Location actualLocation = actualNode.getLocation(); assert actualLocation != null; Collection<Property> desiredProperties = desiredNode.getProperties(); if (desiredProperties.isEmpty()) return; for (Property desiredProperty : desiredProperties) { Name propertyName = desiredProperty.getName(); Property actual = actualNode.getProperty(propertyName); if (actual == null) { batch.set(desiredProperty).on(actualLocation); } else { PropertyMerger merger = MERGERS.get(propertyName); if (merger == null) merger = DEFAULT_MERGER; merger.mergeProperty(batch, actualLocation.getPath(), actual, desiredProperty); } } }
@Test public void shouldReadNode() { Location child1 = Location.create(createPath(validPath, "x")); Location child2 = Location.create(createPath(validPath, "y")); Location child3 = Location.create(createPath(validPath, "z")); setChildrenToReadOn(Location.create(validPath), child1, child2, child3); setPropertiesToReadOn(Location.create(validPath), validIdProperty1, validIdProperty2); Node node = graph.getNodeAt(validPath); assertThat(node, is(notNullValue())); assertThat(node.getChildren(), hasItems(child1, child2)); assertThat(node.getProperties(), hasItems(validIdProperty1, validIdProperty2)); assertThat(node.getLocation(), is(Location.create(validPath))); assertThat(node.getGraph(), is(sameInstance(graph))); assertThat(node.getPropertiesByName().get(validIdProperty1.getName()), is(validIdProperty1)); assertThat(node.getPropertiesByName().get(validIdProperty2.getName()), is(validIdProperty2)); assertThat(numberOfExecutions, is(1)); assertNextRequestReadNode(Location.create(validPath)); assertNoMoreRequests(); }
/** * Request to lock the specified node. This request is submitted to the repository immediately. * * @param at the node that is to be locked * @return an object that allows the scope of the lock to be defined */ public LockScope<LockTimeout<BatchConjunction>> lock( Node at ) { return lock(at.getLocation()); }
@Test( expected = SequencerException.class ) public void shouldExecuteSequencerOnExistingNodeWithMissingSequencedPropertyAndOutputToExistingNode() throws Exception { // Set up the repository for the test ... graph.create("/a").and().create("/a/b").and().create("/a/b/c").and(); graph.create("/d").and().create("/d/e").and(); Node nodeC = graph.getNodeAt("/a/b/c"); Node nodeE = graph.getNodeAt("/d/e"); assertThat(nodeC, is(notNullValue())); assertThat(nodeE, is(notNullValue())); assertThat(nodeE.getChildren().size(), is(0)); assertThat(nodeE.getProperties().size(), is(1)); // jcr:uuid // assertThat(nodeE.getProperty("jcr:primaryType").getString(), is("nt:unstructured")); // Set the property that will be sequenced ... // THIS TEST REQUIRES THIS PROPERTY TO BE NULL OR NON-EXISTANT graph.set("sequencedProperty").on(nodeC.getLocation()).to((String)null); // Set up the node changes ... Location location = Location.create(context.getValueFactories().getPathFactory().create("/a/b/c")); Property sequencedProperty = nodeC.getProperty("sequencedProperty"); NetChange nodeChange = new NetChange(repositoryWorkspaceName, location, EnumSet.of(ChangeType.PROPERTY_CHANGED), null, Collections.singleton(sequencedProperty), null, null, null, false); // Set up the output directory ... Set<RepositoryNodePath> outputPaths = new HashSet<RepositoryNodePath>(); outputPaths.add(new RepositoryNodePath(repositorySourceName, repositoryWorkspaceName, "/d/e")); // Generate the output data that the sequencer subclass will produce and that should be saved to the repository ... sequencerOutput.setProperty(path("alpha/beta"), name("isSomething"), true); // Call the sequencer, which should cause the exception ... sequencer.execute(nodeC, "sequencedProperty", nodeChange, outputPaths, seqContext, problems); }
@Test public void shouldExecuteSequencerOnExistingNodeAndOutputToExistingNode() throws Exception { // Set up the repository for the test ... graph.create("/a").and().create("/a/b").and().create("/a/b/c").and(); graph.create("/d").and().create("/d/e").and(); graph.set("sequencedProperty").on("/a/b/c").to(new ByteArrayInputStream(sampleData.getBytes())); Node nodeC = graph.getNodeAt("/a/b/c"); Node nodeE = graph.getNodeAt("/d/e"); assertThat(nodeC, is(notNullValue())); assertThat(nodeE, is(notNullValue())); assertThat(nodeE.getChildren().size(), is(0)); assertThat(nodeE.getProperties().size(), is(1)); // jcr:uuid // assertThat(nodeE.getProperty("jcr:primaryType").getString(), is("nt:unstructured")); // Set the property that will be sequenced ... // Set up the node changes ... Location location = Location.create(context.getValueFactories().getPathFactory().create("/a/b/c")); Property sequencedProperty = nodeC.getProperty("sequencedProperty"); NetChange nodeChange = new NetChange(repositoryWorkspaceName, location, EnumSet.of(ChangeType.PROPERTY_CHANGED), null, Collections.singleton(sequencedProperty), null, null, null, false); // Set up the output directory ... Set<RepositoryNodePath> outputPaths = new HashSet<RepositoryNodePath>(); outputPaths.add(new RepositoryNodePath(repositorySourceName, repositoryWorkspaceName, "/d/e")); // Generate the output data that the sequencer subclass will produce and that should be saved to the repository ... sequencerOutput.setProperty(path("alpha/beta"), name("isSomething"), true); // Call the sequencer ... sequencer.execute(nodeC, "sequencedProperty", nodeChange, outputPaths, seqContext, problems); }
Path path = node.getLocation().getPath(); Map<Name, Property> properties = node.getPropertiesByName(); for (Location childLocation : node.getChildren()) { assert childLocation.hasPath(); Path childPath = childLocation.getPath();
assert !persistentNode.getChildren().isEmpty(); for (Location location : persistentNode.getChildren()) { Name childName = location.getPath().getLastSegment().getName(); List<Node<Payload, PropertyPayload>> currentChildren = childrenByName.get(childName);
@Override public boolean matchesSafely( Node node ) { Property prop = propertyNameStr != null ? node.getProperty(propertyNameStr) : node.getProperty(propertyName); if (prop != null) { return valueMatcher.matches(prop); } return false; }
/** * Assert that the two supplied nodes represent the exact same node with the same path, same ID properties, same properties, * and same children. * * @param node1 the first node; may not be null * @param node2 the second node; may not be null */ public static void assertSameNode( Node node1, Node node2 ) { assertThat(node1, is(notNullValue())); assertThat(node2, is(notNullValue())); // Check the locations ... Location location1 = node1.getLocation(); Location location2 = node2.getLocation(); assertThat(location1.isSame(location2), is(true)); // Check the paths ... assertThat(location1.getPath(), is(location2.getPath())); // Check the ID properties ... assertThat(location1.getIdProperties(), is(location2.getIdProperties())); // Check the properties ... // Check the children ... assertThat(node1.getChildren(), is(node2.getChildren())); assertThat(node1.getChildrenSegments(), is(node2.getChildrenSegments())); }
assertThat(rootNode.getChildren().size(), is(1)); props = nodeA.getPropertiesByName(); assertThat(nodeA.getChildren().size(), is(2)); assertThat(props.size(), is(2)); // Need to add one to account for dna:uuid assertThat(props.get(nameFor("property1")).getFirstValue().toString(), is("value1")); props = nodeB.getPropertiesByName(); props = nodeB2.getPropertiesByName(); props = nodeC.getPropertiesByName();
/** * {@inheritDoc} * * @see GraphSession.Operations#materializeProperties(org.modeshape.graph.Node, GraphSession.Node) */ public void materializeProperties( org.modeshape.graph.Node persistentNode, Node<Payload, PropertyPayload> node ) { // Create the map of property info objects ... Map<Name, PropertyInfo<PropertyPayload>> properties = new HashMap<Name, PropertyInfo<PropertyPayload>>(); for (Property property : persistentNode.getProperties()) { Name propertyName = property.getName(); PropertyInfo<PropertyPayload> info = new PropertyInfo<PropertyPayload>(property, property.isMultiple(), Status.UNCHANGED, null); properties.put(propertyName, info); } // Set only the children ... node.loadedWith(properties); }
assertThat(node1.getLocation().hasPath(), is(true)); assertThat(node2.getLocation().hasPath(), is(true)); if (pathsShouldMatch) { assertThat(node1.getLocation().getPath(), is(node2.getLocation().getPath())); } else { Path relativeNode1 = node1.getLocation().getPath().relativeTo(rootPath1); Path relativeNode2 = node2.getLocation().getPath().relativeTo(rootPath2); assertThat(relativeNode1, is(relativeNode2)); assertThat(node1.getLocation().getIdProperties(), is(node2.getLocation().getIdProperties())); Map<Name, Property> properties1 = new HashMap<Name, Property>(node1.getPropertiesByName()); Map<Name, Property> properties2 = new HashMap<Name, Property>(node2.getPropertiesByName()); if (!idPropertiesShouldMatch) { for (Property idProperty : node1.getLocation().getIdProperties()) { properties1.remove(idProperty.getName()); for (Property idProperty : node2.getLocation().getIdProperties()) { properties2.remove(idProperty.getName()); assertThat(node1.getChildrenSegments(), is(node2.getChildrenSegments()));
assertThat("The node that was read doesn't have the expected location", result.getLocation(), is(location)); } else { result.getLocation().equals(location), is(true)); assertThat(graph.getChildren().of(location), is(result.getChildren()));
assertThat(graph.getNodeAt("/segmentTestUuids").getChildren(), hasChildren(segment("node1"), segment("node1[2]"))); assertThat(graph.getNodeAt("/segmentTestUuids/node1[1]").getProperty("identifier"), is(nullValue())); assertThat(graph.getNodeAt("/segmentTestUuids/node1[2]").getProperty("identifier").getFirstValue().toString(), is("backup copy"));
/** * Assert that the node has all of the supplied properties. * * @param node the node; may not be null * @param properties the expected properties */ public static void assertSameProperties( Node node, Iterable<Property> properties ) { assertThat(node, is(notNullValue())); assertThat(properties, is(notNullValue())); Set<Name> names = new HashSet<Name>(node.getPropertiesByName().keySet()); for (Property prop1 : properties) { Name name = prop1.getName(); assertThat(names.remove(name), is(true)); assertThat(prop1, is(node.getProperty(name))); } assertThat(names.isEmpty(), is(true)); }
protected StreamSequencerContext createStreamSequencerContext( Node input, Property sequencedProperty, SequencerContext context, Problems problems ) { assert input != null; assert sequencedProperty != null; assert context != null; assert problems != null; ValueFactories factories = context.getExecutionContext().getValueFactories(); Path path = factories.getPathFactory().create(input.getLocation().getPath()); Set<org.modeshape.graph.property.Property> props = Collections.<Property>unmodifiableSet(input.getPropertiesByName() .values()); Name fileName = path.getLastSegment().getName(); if (JcrLexicon.CONTENT.equals(fileName) && !path.isRoot()) { // We're actually sequencing the "jcr:content" child node of an "nt:file" node, but the name of // the file is actually the name of the "jcr:content" node's parent "nt:file" node. fileName = path.getParent().getLastSegment().getName(); } String mimeType = getMimeType(context, sequencedProperty, fileName.getLocalName()); return new StreamSequencerContext(context.getExecutionContext(), path, props, mimeType, problems); }
Node node = results.getNode(validPath); assertThat(node, is(notNullValue())); assertThat(node.getChildren(), hasItems(child1, child2, child3)); assertThat(node.getProperties(), hasItems(validIdProperty1, validIdProperty2)); assertThat(node.getLocation(), is(Location.create(validPath))); assertThat(node.getGraph(), is(sameInstance(graph))); assertThat(node.getPropertiesByName().get(validIdProperty1.getName()), is(validIdProperty1)); assertThat(node.getPropertiesByName().get(validIdProperty2.getName()), is(validIdProperty2)); assertThat(node.getChildren().size(), is(0)); assertThat(node.getProperties(), hasItems(validIdProperty1)); assertThat(node.getLocation(), is(child11)); assertThat(node.getGraph(), is(sameInstance(graph))); assertThat(node.getPropertiesByName().get(validIdProperty1.getName()), is(validIdProperty1)); assertThat(node.getChildren(), hasItems(child121, child122, child123)); assertThat(node.getProperties(), hasItems(validIdProperty2)); assertThat(node.getLocation(), is(child12)); assertThat(node.getGraph(), is(sameInstance(graph))); assertThat(node.getPropertiesByName().get(validIdProperty2.getName()), is(validIdProperty2));