/** * {@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); }
@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(); }
/** * {@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()); }
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, is(notNullValue())); assertThat(node.getChildren().size(), is(0)); assertThat(node.getProperties(), hasItems(validIdProperty1)); assertThat(node.getLocation(), is(child11)); assertThat(node.getGraph(), is(sameInstance(graph))); assertThat(node, is(notNullValue())); assertThat(node.getChildren(), hasItems(child121, child122, child123)); assertThat(node.getProperties(), hasItems(validIdProperty2)); assertThat(node.getLocation(), is(child12)); assertThat(node.getGraph(), is(sameInstance(graph)));
for (Property property : clusterNode.getProperties()) { Name propertyName = property.getName(); if (skipNamespaces.contains(propertyName.getNamespaceUri())) continue;
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;
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;
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); } } }
for (Property property : sequencerNode.getProperties()) { Name propertyName = property.getName(); if (skipNamespaces.contains(propertyName.getNamespaceUri())) continue;
/** * 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, Map<Name, Property> properties ) { assertThat(node, is(notNullValue())); assertThat(properties, is(notNullValue())); Set<Name> names = new HashSet<Name>(properties.keySet()); for (Property prop1 : node.getProperties()) { Name name = prop1.getName(); assertThat(names.remove(name), is(true)); assertThat(prop1, is(properties.get(name))); } assertThat(names.isEmpty(), is(true)); }
@Test public void shouldIncludeTimeLoadedInReadPropertyRequests() { // Get each of the properties on the first child ... String workspaceName = graph.getCurrentWorkspaceName(); Location firstChildLocation = graph.getChildren().of("/").get(0); Node firstChild = graph.getNodeAt(firstChildLocation); // Don't use the graph so that we can obtain and interrogate the request ... for (Property property : firstChild.getProperties()) { CacheableRequest request = new ReadPropertyRequest(firstChildLocation, workspaceName, property.getName()); execute(request); assertThat(request.getTimeLoaded(), is(notNullValue())); } }
@Test public void shouldReadIndividualPropertiesOfNodes() { // Read each node that is a child of the root... for (Location childLocation : graph.getChildren().of("/")) { // For each node ... Node child = graph.getNodeAt(childLocation); for (Property property : child.getProperties()) { Name name = property.getName(); // Re-read the property and verify the value(s) match the value(s) in 'property' Property singleProperty = graph.getProperty(name).on(childLocation); assertThat(singleProperty, is(notNullValue())); assertThat(singleProperty, is(property)); } } }
@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); }
assertThat(nodeE, is(notNullValue())); assertThat(nodeE.getChildren().size(), is(0)); assertThat(nodeE.getProperties().size(), is(1)); // jcr:uuid
@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); }
assertThat(root.getProperties(), hasItems(validIdProperty1, validIdProperty2)); assertThat(node1.getProperties(), hasItems(validIdProperty1)); assertThat(node2.getProperties(), hasItems(validIdProperty2)); assertThat(node3.getProperties().isEmpty(), is(true)); assertThat(root.getProperties(), hasItems(validIdProperty1, validIdProperty2)); assertThat(node1.getProperties(), hasItems(validIdProperty1)); assertThat(node2.getProperties(), hasItems(validIdProperty2)); assertThat(node3.getProperties().isEmpty(), is(true));