@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; }
private String[] stringValuesOf( Node node, Name propertyName ) { Property property = node.getProperty(propertyName); if (property == null) { // Check whether the property exists with no namespace ... property = node.getProperty(context.getValueFactories().getNameFactory().create(propertyName.getLocalName())); if (property == null) return null; } return context.getValueFactories().getStringFactory().create(property.getValuesAsArray()); }
private String stringValueOf( Node node, Name propertyName ) { Property property = node.getProperty(propertyName); if (property == null) { // Check whether the property exists with no namespace ... property = node.getProperty(context.getValueFactories().getNameFactory().create(propertyName.getLocalName())); if (property == null) return null; } if (property.isEmpty()) return null; return context.getValueFactories().getStringFactory().create(property.getFirstValue()); }
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); } } }
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; }
Path path = nsLocation.getPath(); String actualPrefix = getPrefixFor(path); String actualUri = stringFactory.create(ns.getProperty(uriPropertyName).getFirstValue()); if (actualPrefix != null && actualUri != null) { existingUrisByPrefix.put(actualPrefix, actualUri);
/** * 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 boolean doUnregister( String uri ) { // Read the store ... ValueFactory<String> stringFactory = store.getContext().getValueFactories().getStringFactory(); boolean result = false; try { Subgraph nsGraph = store.getSubgraphOfDepth(2).at(parentOfNamespaceNodes); // Iterate over the existing mappings, looking for one that uses the prefix and uri ... Set<Location> locationsToRemove = new HashSet<Location>(); for (Location nsLocation : nsGraph.getRoot().getChildren()) { Node ns = nsGraph.getNode(nsLocation); String actualUri = stringFactory.create(ns.getProperty(uriPropertyName).getFirstValue()); if (actualUri.equals(uri)) { locationsToRemove.add(ns.getLocation()); result = true; } } // Remove any other nodes that have the same URI ... Graph.Batch batch = store.batch(); for (Location namespaceToRemove : locationsToRemove) { batch.delete(namespaceToRemove).and(); } // Execute all these changes ... batch.execute(); } catch (PathNotFoundException e) { // Nothing stored yet, so do nothing ... } return result; }
Node ns = nsGraph.getNode(nsLocation); String prefix = getPrefixFor(nsLocation.getPath()); String uri = stringFactory.create(ns.getProperty(uriPropertyName).getFirstValue()); if (prefix != null && uri != null) { if (uri.equals(namespaceUri)) return prefix; Property generatedProperty = ns.getProperty(generatedPropertyName); boolean generated = generatedProperty == null ? isGeneratedPrefix(prefix) : booleanFactory.create(generatedProperty.getFirstValue()); if (generated) {
Property sequencedProperty = nodeC.getProperty("sequencedProperty"); NetChange nodeChange = new NetChange(repositoryWorkspaceName, location, EnumSet.of(ChangeType.PROPERTY_CHANGED), null, Collections.singleton(sequencedProperty), null, null, null, false); assertThat(graph.getNodeAt("/d/e/alpha/beta").getProperty("isSomething").getFirstValue().toString(), is("true")); assertThat(graph.getNodeAt("/x/y/z/alpha/beta").getProperty("isSomething").getFirstValue().toString(), is("true")); assertThat(graph.getNodeAt("/x/z/alpha/beta").getProperty("isSomething").getFirstValue().toString(), is("true"));
Property sequencedProperty = nodeC.getProperty("sequencedProperty"); NetChange nodeChange = new NetChange(repositoryWorkspaceName, location, EnumSet.of(ChangeType.PROPERTY_CHANGED), null, Collections.singleton(sequencedProperty), null, null, null, false); assertThat(graph2.getNodeAt("/d/e/alpha/beta").getProperty("isSomething").getFirstValue().toString(), is("true")); assertThat(graph2.getNodeAt("/x/y/z/alpha/beta").getProperty("isSomething").getFirstValue().toString(), is("true")); assertThat(graph2.getNodeAt("/x/z/alpha/beta").getProperty("isSomething").getFirstValue().toString(), is("true"));
protected UUID getRootNodeUuid() { if (rootUuid == null) { Node root = graph.getNodeAt("/"); rootLocation = root.getLocation(); rootUuid = rootLocation.getUuid(); if (rootUuid == null) { Property uuid = root.getProperty(ModeShapeLexicon.UUID); if (uuid != null) { rootUuid = context.getValueFactories().getUuidFactory().create(uuid.getFirstValue()); } } if (rootUuid == null) { Property uuid = root.getProperty(JcrLexicon.UUID); if (uuid != null) { rootUuid = context.getValueFactories().getUuidFactory().create(uuid.getFirstValue()); } } } return rootUuid; }
Node ns = nsGraph.getNode(nsLocation); String uri = stringFactory.create(ns.getProperty(uriPropertyName).getFirstValue()); if (uri != null) { String prefix = getPrefixFor(nsLocation.getPath());
if (uuid == null) { Property uuidProperty = node.getProperty(ModeShapeLexicon.UUID); if (uuidProperty != null) { uuid = getContext().getValueFactories().getUuidFactory().create(uuidProperty.getFirstValue()); } else { uuidProperty = node.getProperty(JcrLexicon.UUID); if (uuidProperty != null) { uuid = getContext().getValueFactories().getUuidFactory().create(uuidProperty.getFirstValue());
@Test public void shouldExecuteSequencerOnExistingNodeAndOutputToNonExistingNode() throws Exception { // Set up the repository for the test ... graph.create("/a").and().create("/a/b").and().create("/a/b/c").and(); // Set the property that will be sequenced ... graph.set("sequencedProperty").on("/a/b/c").to(new ByteArrayInputStream(sampleData.getBytes())); Node nodeC = graph.getNodeAt("/a/b/c"); assertThat(nodeC, is(notNullValue())); assertNodeDoesNotExist(graph, "/d"); // 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); // Check to see that the "/d/e" node has been created ... assertThat(graph.getNodeAt("/d/e"), is(notNullValue())); }
@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); }
Property sequencedProperty = nodeC.getProperty("sequencedProperty"); NetChange nodeChange = new NetChange(repositoryWorkspaceName, location, EnumSet.of(ChangeType.PROPERTY_CHANGED), null, Collections.singleton(sequencedProperty), null, null, null, false);
protected void testSequencer( final StreamSequencer sequencer ) throws Throwable { StreamSequencer streamSequencer = new StreamSequencer() { @Override public void sequence( InputStream stream, SequencerOutput output, StreamSequencerContext context ) { sequencer.sequence(stream, output, context); } }; StreamSequencerAdapter adapter = new StreamSequencerAdapter(streamSequencer); 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 inputNode = graph.getNodeAt("/a/b/c"); Location location = Location.create(context.getValueFactories().getPathFactory().create("/a/b/c")); Property sequencedProperty = inputNode.getProperty("sequencedProperty"); NetChange nodeChange = new NetChange(repositoryWorkspaceName, location, EnumSet.of(ChangeType.PROPERTY_CHANGED), null, Collections.singleton(sequencedProperty), null, null, null, false); Set<RepositoryNodePath> outputPaths = new HashSet<RepositoryNodePath>(); outputPaths.add(new RepositoryNodePath(repositorySourceName, repositoryWorkspaceName, "/d/e")); sequencerOutput.setProperty(path("alpha/beta"), name("isSomething"), true); adapter.execute(inputNode, "sequencedProperty", nodeChange, outputPaths, seqContext, problems); }
@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(graph.getNodeAt("/segmentTestUuids/node1[1]").getProperty("identifier"), is(nullValue())); assertThat(graph.getNodeAt("/segmentTestUuids/node1[2]").getProperty("identifier").getFirstValue().toString(), is("backup copy"));