/** * Add a request to read the properties and number of children of a node at the supplied location. * * @param of the location of the node whose children are to be read * @param workspaceName the name of the workspace * @return the request; never null * @throws IllegalArgumentException if the location or workspace name is null */ public ReadAllPropertiesRequest readAllProperties( Location of, String workspaceName ) { return process(new ReadAllPropertiesRequest(of, workspaceName)); }
@Override public void process( ReadAllPropertiesRequest request ) { WorkspaceType workspace = getWorkspace(request, request.inWorkspace()); NodeType node = getTargetNode(workspace, request, request.at()); if (node == null) { assert request.hasError(); return; } // Get the properties of the node ... Location actualLocation = getActualLocation(workspace, request.at(), node); request.addProperty(propertyFactory.create(ModeShapeLexicon.UUID, node.getUuid())); request.addProperties(node.getProperties().values()); assert actualLocation != null; request.setActualLocationOfNode(actualLocation); setCacheableInfo(request); }
/** * {@inheritDoc} * * @see org.modeshape.graph.request.processor.RequestProcessor#process(org.modeshape.graph.request.ReadAllPropertiesRequest) */ @Override public void process( ReadAllPropertiesRequest request ) { ReadAllPropertiesRequest source = (ReadAllPropertiesRequest)federatedRequest.getFirstProjectedRequest().getRequest(); if (checkErrorOrCancel(request, source)) return; request.setActualLocationOfNode(source.getActualLocationOfNode()); for (Property propertyInSource : source.getProperties()) { request.addProperties(propertyInSource); } request.setCachePolicy(getDefaultCachePolicy()); setCacheableInfo(request, source.getCachePolicy()); }
/** * {@inheritDoc} * * @see java.lang.Object#equals(java.lang.Object) */ @Override public boolean equals( Object obj ) { if (obj == this) return true; if (this.getClass().isInstance(obj)) { ReadAllPropertiesRequest that = (ReadAllPropertiesRequest)obj; if (!this.at().isSame(that.at())) return false; if (!this.inWorkspace().equals(that.inWorkspace())) return false; return true; } return false; }
Map<Name, Property> properties = request.getPropertiesByName(); ProjectedRequest projectedRequest = federatedRequest.getFirstProjectedRequest(); request.setCachePolicy(getDefaultCachePolicy()); Location actualLocation = request.at(); int numMerged = 0; while (projectedRequest != null) { ReadAllPropertiesRequest readFromSource = (ReadAllPropertiesRequest)projectedRequest.getRequest(); if (readFromSource.hasError()) { projectedRequest = projectedRequest.next(); continue; if (readFromSource.isCancelled()) { request.cancel(); return; Location sourceLocation = readFromSource.getActualLocationOfNode(); actualLocation = determineActualLocation(actualLocation, sourceLocation, projectedRequest.getProjection()); for (Property propertyInSource : readFromSource.getProperties()) { Name name = propertyInSource.getName(); Property existing = properties.get(name); setCacheableInfo(request, readFromSource.getCachePolicy()); projectedRequest = projectedRequest.next(); ++numMerged; setPathNotFound(request, request.at(), federatedRequest.getFirstProjectedRequest()); } else {
/** * Process a request to verify that a node exists at the supplied location. * <p> * This method does nothing if the request is null. Unless overridden, this method converts the request that * {@link ReadAllPropertiesRequest reads the node} and uses the result to determine if the node exists. * </p> * * @param request the read request */ public void process( VerifyNodeExistsRequest request ) { if (request == null) return; ReadAllPropertiesRequest readNode = new ReadAllPropertiesRequest(request.at(), request.inWorkspace()); process(readNode); if (readNode.hasError()) { request.setError(readNode.getError()); return; } // Set the actual location ... request.setActualLocationOfNode(readNode.getActualLocationOfNode()); setCacheableInfo(request); }
@Test public void shouldAllowAddingProperties() { request = new ReadAllPropertiesRequest(validPathLocation, workspace1); request.addProperty(validProperty1); request.addProperty(validProperty2); assertThat(request.getProperties().size(), is(2)); assertThat(request.getProperties(), hasItems(validProperty1, validProperty2)); assertThat(request.getPropertiesByName().get(validProperty1.getName()), is(validProperty1)); assertThat(request.getPropertiesByName().get(validProperty2.getName()), is(validProperty2)); } }
@Test public void shouldCreateValidRequestWithValidLocation() { request = new ReadAllPropertiesRequest(validPathLocation1, workspace1); assertThat(request.at(), is(sameInstance(validPathLocation1))); assertThat(request.hasError(), is(false)); assertThat(request.getError(), is(nullValue())); }
public void process( ReadAllPropertiesRequest request ) { ProjectedNode projectedNode = project(request.at(), request.inWorkspace(), request, false); PlaceholderNode placeholder = projectedNode.asPlaceholder(); ReadAllPropertiesRequest placeholderRequest = new ReadAllPropertiesRequest(placeholder.location(), request.inWorkspace()); placeholderRequest.addProperties(placeholder.properties().values()); placeholderRequest.setActualLocationOfNode(placeholder.location()); federatedRequest.add(placeholderRequest, true, true, null); } else if (projectedNode.isProxy()) { ProxyNode proxy = projectedNode.asProxy(); ReadAllPropertiesRequest pushDownRequest = new ReadAllPropertiesRequest(proxy.location(), proxy.workspaceName()); federatedRequest.add(pushDownRequest, proxy.isSameLocationAsOriginal(), false, proxy.projection());
@Override public void process( ReadAllPropertiesRequest request ) { PathWorkspace workspace = getWorkspace(request, request.inWorkspace()); if (workspace == null) return; PathNode node = getTargetNode(workspace, request, request.at()); if (node == null) { request.setError(new PathNotFoundException(request.at(), workspace.getLowestExistingPath(request.at().getPath()))); return; } // Get the properties of the node ... request.addProperties(node.getProperties().values()); request.setActualLocationOfNode(Location.create(node.getPath(), node.getUuid())); setCacheableInfo(request); }
@Override public void process( ReadAllPropertiesRequest request ) { // Read the properties from the map ... if (properties.containsKey(request.at())) { for (Property property : properties.get(request.at())) { request.addProperty(property); } } // Set the actual location request.setActualLocationOfNode(actualLocationOf(request.at())); }
protected void indexProperties( String workspaceName, Location location ) { ReadAllPropertiesRequest readProps = new ReadAllPropertiesRequest(location, workspaceName); try { channel.addAndAwait(readProps); } catch (InterruptedException e) { // Clear the interrupted status of the thread and continue ... Thread.interrupted(); } checkRequestForErrors(readProps); // Now update the properties in the search engine ... location = readProps.getActualLocationOfNode(); Map<Name, Property> properties = readProps.getPropertiesByName(); UpdatePropertiesRequest request = new UpdatePropertiesRequest(location, workspaceName, properties, true); request.setActualLocationOfNode(location); process(request); checkRequestForErrors(readProps); }
protected void assertNextRequestReadProperties( Location at, Property... properties ) { Request request = executedRequests.poll(); assertThat(request, is(instanceOf(ReadAllPropertiesRequest.class))); ReadAllPropertiesRequest readAll = (ReadAllPropertiesRequest)request; assertThat(readAll.at(), is(at)); Map<Name, Property> propsByName = new HashMap<Name, Property>(readAll.getPropertiesByName()); for (Property prop : properties) { assertThat(propsByName.remove(prop.getName()), is(prop)); } assertThat(propsByName.isEmpty(), is(true)); }
@Test public void shouldConsiderNotEqualTwoRequestsWithDifferentWorkspaceNames() { request = new ReadAllPropertiesRequest(validPathLocation1, workspace1); ReadAllPropertiesRequest request2 = new ReadAllPropertiesRequest(validPathLocation1, workspace2); assertThat(request.equals(request2), is(false)); }
ReadAllPropertiesRequest readAll = (ReadAllPropertiesRequest)request; expires = computeExpirationTime(readAll); getOrCreateNode(readAll.getActualLocationOfNode(), expires).setProperties(readAll.getPropertiesByName()); break; case READ_PROPERTY:
/** * {@inheritDoc} * * @see java.lang.Iterable#iterator() */ public Iterator<Property> iterator() { return getProperties().iterator(); }
public Map<Name, Property> on( Location location ) { return requests.readAllProperties(location, getCurrentWorkspaceName()).getPropertiesByName(); }
/** * Process a request to read a single property of a node at the supplied location. * <p> * This method does nothing if the request is null. Unless overridden, this method converts the request that * {@link ReadAllPropertiesRequest reads the node} and simply returns the one property. * </p> * * @param request the read request */ public void process( ReadPropertyRequest request ) { if (request == null) return; ReadAllPropertiesRequest readNode = new ReadAllPropertiesRequest(request.on(), request.inWorkspace()); process(readNode); if (readNode.hasError()) { request.setError(readNode.getError()); return; } Property property = readNode.getPropertiesByName().get(request.named()); request.setProperty(property); // Set the actual location ... request.setActualLocationOfNode(readNode.getActualLocationOfNode()); setCacheableInfo(request); }
@Test public void shouldConsiderNotEqualTwoRequestsWithDifferentLocations() { request = new ReadAllPropertiesRequest(validPathLocation1, workspace1); ReadAllPropertiesRequest request2 = new ReadAllPropertiesRequest(validPathLocation2, workspace1); assertThat(request.equals(request2), is(false)); }