CopyUtil.copyGraph(tempGraph, this.getBaseContextNode().getGraph(), null);
CopyUtil.copyGraph(tempGraph, this.getBaseContextNode().getGraph(), null);
public final LightMessagingResponse makeLightMessagingResponse() { if (! this.isFinished()) throw new Xdi2RuntimeException("Execution result has not been finished yet.", this.resultGraphFinishedEx); // result graph Graph resultGraph = MemoryGraphFactory.getInstance().openGraph(); for (Graph operationResultGraph : this.operationResultGraphs.values()) { if (operationResultGraph == null) continue; CopyUtil.copyGraph(operationResultGraph, resultGraph, null); } // create messaging response LightMessagingResponse lightMessagingResponse = LightMessagingResponse.fromResultGraph(resultGraph); // done return lightMessagingResponse; }
@Override public InterceptorResult after(Operation operation, Graph operationResultGraph, ExecutionContext executionContext) throws Xdi2MessagingException { // look through the message result to process result $has relations if (operation instanceof GetOperation && operation.getTargetXDIAddress() != null) { List<Relation> hasRelations = new IteratorListMaker<Relation> (Aggregation.getAllAggregationRelations(operationResultGraph.getRootContextNode(true))).list(); for (Relation hasRelation : hasRelations) { if (log.isDebugEnabled()) log.debug("In message result: Found $has relation: " + hasRelation); XDIAddress hasTargetXDIAddress = hasRelation.getTargetXDIAddress(); // $get feedback on the target of the $has relation Graph feedbackResultGraph = feedbackGetTargetOfHasRelation(hasTargetXDIAddress, operation, executionContext); // merge the message result CopyUtil.copyGraph(feedbackResultGraph, operationResultGraph, null); // done with this $has relation if (log.isDebugEnabled()) log.debug("In message result: After $get feedback on $has relation " + hasRelation + " we now have: " + operationResultGraph); } } // done return InterceptorResult.DEFAULT; }
@SuppressWarnings("resource") @Override public Writer write(Graph graph, Writer writer) throws IOException { // write ordered? Graph orderedGraph = null; if (this.isWriteOrdered()) { MemoryGraphFactory memoryGraphFactory = new MemoryGraphFactory(); memoryGraphFactory.setSortmode(MemoryGraphFactory.SORTMODE_ALPHA); orderedGraph = memoryGraphFactory.openGraph(); CopyUtil.copyGraph(graph, orderedGraph, null); graph = orderedGraph; } // write JsonObject jsonObject = new JsonObject(); this.writeInternal(graph, jsonObject); JsonWriter jsonWriter = new JsonWriter(writer); if (this.isWritePretty()) jsonWriter.setIndent(" "); gson.toJson(jsonObject, jsonWriter); jsonWriter.flush(); writer.flush(); return writer; }
@SuppressWarnings("resource") @Override public Writer write(Graph graph, Writer writer) throws IOException { // write ordered? Graph orderedGraph = null; if (this.isWriteOrdered()) { MemoryGraphFactory memoryGraphFactory = new MemoryGraphFactory(); memoryGraphFactory.setSortmode(MemoryGraphFactory.SORTMODE_ALPHA); orderedGraph = memoryGraphFactory.openGraph(); CopyUtil.copyGraph(graph, orderedGraph, null); graph = orderedGraph; } // write JsonArray jsonArray = new JsonArray(); this.writeInternal(graph, jsonArray); JsonWriter jsonWriter = new JsonWriter(writer); if (this.isWritePretty()) jsonWriter.setIndent(" "); gson.toJson(jsonArray , jsonWriter); jsonWriter.flush(); writer.flush(); return writer; }
public static boolean isValid(Graph graph) { // TODO: need better way to distinguish full response from light response Graph tempGraph = MemoryGraphFactory.getInstance().openGraph(); CopyUtil.copyGraph(graph, tempGraph, null); MessageEnvelope tempMessageEnvelope = MessageEnvelope.fromGraph(tempGraph); for (Message tempMessage : tempMessageEnvelope.getMessages()) { if (tempMessage.getOperationResults().hasNext()) return true; } return false; }
private void processConnect(LinkContractTemplate linkContractTemplate, ConnectOperation operation, Graph operationResultGraph, ExecutionContext executionContext) throws Xdi2MessagingException { if (log.isDebugEnabled()) log.debug("Preparing to instantiate link contract template " + linkContractTemplate); // set variable values Map<XDIArc, Object> variableValues = operation.getVariableValues(); variableValues.put(XDILinkContractConstants.XDI_ARC_V_FROM, operation.getMessage().getSenderXDIAddress()); variableValues.put(XDILinkContractConstants.XDI_ARC_V_TO, executionContext.getCurrentMessagingContainer().getOwnerXDIAddress()); // instantiate link contract LinkContractInstantiation linkContractInstantiation = new LinkContractInstantiation(linkContractTemplate); linkContractInstantiation.setVariableValues(variableValues); LinkContract linkContract; try { linkContract = linkContractInstantiation.execute(); } catch (Exception ex) { throw new Xdi2MessagingException("Cannot instantiate link contract: " + ex.getMessage(), ex, executionContext); } // write link contract and index into operation result graph CopyUtil.copyGraph(linkContract.getContextNode().getGraph(), operationResultGraph, null); // first delete link contract in target graph if it exists already ContextNode linkContractContextNode = this.getTargetGraph(executionContext).getDeepContextNode(linkContract.getContextNode().getXDIAddress()); if (linkContractContextNode != null) linkContractContextNode.delete(); // write link contract and index into target graph if (this.getTargetGraph(executionContext) != null) { CopyUtil.copyGraph(linkContract.getContextNode().getGraph(), this.getTargetGraph(executionContext), null); XdiEntityCollection xdiLinkContractIndex = Index.getEntityIndex(this.getTargetGraph(executionContext), XDILinkContractConstants.XDI_ARC_CONTRACT, true); Index.setEntityIndexAggregation(xdiLinkContractIndex, linkContract.getXdiEntity()); } }
memoryGraphFactory.setSortmode(MemoryGraphFactory.SORTMODE_ALPHA); orderedGraph = memoryGraphFactory.openGraph(); CopyUtil.copyGraph(graph, orderedGraph, null);
private void writeInternal(Graph graph, JsonObject jsonObject) throws IOException { // write ordered? Graph orderedGraph = null; IterableIterator<Statement> statements; if (this.isWriteOrdered()) { MemoryGraphFactory memoryGraphFactory = new MemoryGraphFactory(); memoryGraphFactory.setSortmode(MemoryGraphFactory.SORTMODE_ALPHA); orderedGraph = memoryGraphFactory.openGraph(); CopyUtil.copyGraph(graph, orderedGraph, null); List<Iterator<? extends Statement>> list = new ArrayList<Iterator<? extends Statement>> (); list.add(new MappingContextNodeStatementIterator(orderedGraph.getRootContextNode(true).getAllContextNodes())); list.add(new MappingRelationStatementIterator(orderedGraph.getRootContextNode(true).getAllRelations())); list.add(new MappingLiteralNodeStatementIterator(orderedGraph.getRootContextNode(true).getAllLiteralNodes())); statements = new CompositeIterator<Statement> (list.iterator()); } else { statements = graph.getRootContextNode(true).getAllStatements(); } // ignore implied statements if (! this.isWriteImplied()) statements = new SelectingNotImpliedStatementIterator(statements); // write the statements for (Statement statement : statements) { XDIStatement XDIstatement = statement.getXDIStatement(); // put the statement into the JSON object this.putStatementIntoJsonObject(XDIstatement, jsonObject); } // done if (orderedGraph != null) orderedGraph.close(); }
private void processPush(Message pushedMessage, Operation operation, Graph operationResultGraph, ExecutionContext executionContext) throws Xdi2MessagingException { if (log.isDebugEnabled()) log.debug("Preparing to process pushed message " + pushedMessage); // TODO: how exactly is the $push message a response, and to what? FullMessagingResponse pushedMessagingResponse = FullMessagingResponse.fromMessageEnvelope(operation.getMessage().getMessageEnvelope()); // TODO: correctly store statements of $set operation? Graph resultGraph = ((TransportMessagingResponse) pushedMessagingResponse).getResultGraph(); if (resultGraph != null) { MessageEnvelope innerMe = MessageEnvelope.fromGraph(operation.getTargetXdiInnerRoot().getInnerGraph()); Message innerM = innerMe == null ? null : innerMe.getMessages().next(); Iterator<SetOperation> innerSOs = innerM == null ? new EmptyIterator<SetOperation> () : innerM.getSetOperations(); SetOperation innerSO = innerSOs.hasNext() ? innerSOs.next() : null; XdiInnerRoot innerIR = innerSO == null ? null : innerSO.getTargetXdiInnerRoot(); if (innerIR != null) { CopyUtil.copyGraph(innerIR.getInnerGraph(), this.getTargetGraph(executionContext), null); } } // TODO: correctly store any contracts we got? // see comment in pushedMessagingResponse.getLinkContracts() if (log.isDebugEnabled()) log.debug("Looking for link contracts from result graph of pushed messaging response " + pushedMessagingResponse.getResultGraph()); for (LinkContract pushedLinkContract : TransportMessagingResponse.getLinkContracts(pushedMessagingResponse)) { if (log.isDebugEnabled()) log.debug("Obtained link contract from result graph of pushed messaging response " + pushedLinkContract); // first delete link contract in target graph if it exists already ContextNode linkContractContextNode = this.getTargetGraph(executionContext).getDeepContextNode(pushedLinkContract.getContextNode().getXDIAddress()); if (linkContractContextNode != null) linkContractContextNode.delete(); // write link contract and index into target graph CopyUtil.copyContextNode(pushedLinkContract.getContextNode(), this.getTargetGraph(executionContext), null); XdiEntityCollection xdiLinkContractIndex = Index.getEntityIndex(this.getTargetGraph(executionContext), XDILinkContractConstants.XDI_ARC_CONTRACT, true); Index.setEntityIndexAggregation(xdiLinkContractIndex, pushedLinkContract.getXdiEntity().getXDIAddress()); } }
memoryGraphFactory.setSortmode(MemoryGraphFactory.SORTMODE_ALPHA); orderedGraph = memoryGraphFactory.openGraph(); CopyUtil.copyGraph(graph, orderedGraph, null);
memoryGraphFactory.setSortmode(MemoryGraphFactory.SORTMODE_ALPHA); orderedGraph = memoryGraphFactory.openGraph(); CopyUtil.copyGraph(graph, orderedGraph, null);
CopyUtil.copyGraph(graph10, graph11, null); testGraph(graph11);
public void testCopyUtil() throws Exception { Graph graph = MemoryGraphFactory.getInstance().openGraph(); graph.setStatement(XDIStatement.create("=markus<#email>/&/\"markus@projectdanube.org\"")); graph.setStatement(XDIStatement.create("=markus/#friend/=neustar=animesh")); graph.setStatement(XDIStatement.create("=neustar=animesh<#email>/&/\"animesh@gmail.com\"")); graph.setStatement(XDIStatement.create("=neustar=animesh/#friend/=markus")); Graph graph2 = MemoryGraphFactory.getInstance().openGraph(); CopyUtil.copyGraph(graph, graph2, null); Graph graph3 = MemoryGraphFactory.getInstance().openGraph(); CopyUtil.copyGraph(graph, graph3, null); CopyUtil.copyGraph(graph2, graph3, null); assertEquals(graph, graph2); assertEquals(graph2, graph3); assertEquals(graph3, graph); graph.close(); graph2.close(); graph3.close(); }
public void testMultipleReplacements() throws Exception { Graph graph1 = MemoryGraphFactory.getInstance().openGraph(); Graph graph2 = MemoryGraphFactory.getInstance().openGraph(); graph1.setStatement(XDIStatement.create("=a=b=c/+e/=f")); XDIArc from1 = XDIArc.create("=b"); List<XDIAddress> to1 = new ArrayList<XDIAddress> (); to1.add(XDIAddress.create("=x")); to1.add(XDIAddress.create("=y")); XDIArc from2 = XDIArc.create("=f"); List<XDIAddress> to2 = new ArrayList<XDIAddress> (); to2.add(XDIAddress.create("=m")); to2.add(XDIAddress.create("=n")); Map<XDIArc, Object> replacements = new HashMap<XDIArc, Object> (); replacements.put(from1, to1); replacements.put(from2, to2); CopyUtil.copyGraph(graph1, graph2, new ReplaceXDIAddressCopyStrategy(replacements)); assertTrue(graph2.containsStatement(XDIStatement.create("=a=x=c/+e/=m"))); assertTrue(graph2.containsStatement(XDIStatement.create("=a=x=c/+e/=n"))); assertTrue(graph2.containsStatement(XDIStatement.create("=a=y=c/+e/=m"))); assertTrue(graph2.containsStatement(XDIStatement.create("=a=y=c/+e/=n"))); assertEquals(graph2.getAllStatementCount(), 11); graph1.close(); graph2.close(); }
public void testExtractXDIAddressCopyStrategyLight() throws Exception { String graphString = "" + "(=z)//=a"; String copiedGraphString = "" + "//=a"; Graph graph1 = MemoryGraphFactory.getInstance().parseGraph(graphString); Graph graph2 = MemoryGraphFactory.getInstance().parseGraph(copiedGraphString); Graph graph3 = MemoryGraphFactory.getInstance().openGraph(); CopyUtil.copyGraph(graph1, graph3, new ExtractXDIAddressCopyStrategy(XdiPeerRoot.class, false, false, false, false, true)); assertNotEquals(graph1, graph2); assertNotEquals(graph1, graph3); assertEquals(graph2, graph3); graph1.close(); graph2.close(); graph3.close(); }
public void testConcatXDIAddressCopyStrategyLight() throws Exception { String graphString = "" + "//=a"; String copiedGraphString = "" + "=x=y//=a"; Graph graph1 = MemoryGraphFactory.getInstance().parseGraph(graphString); Graph graph2 = MemoryGraphFactory.getInstance().parseGraph(copiedGraphString); Graph graph3 = MemoryGraphFactory.getInstance().openGraph(); CopyUtil.copyGraph(graph1, graph3, new ConcatXDIAddressCopyStrategy(XDIAddress.create("=x=y"))); assertNotEquals(graph1, graph2); assertNotEquals(graph1, graph3); assertEquals(graph2, graph3); graph1.close(); graph2.close(); graph3.close(); }
public void testExtractXDIAddressCopyStrategy() throws Exception { String graphString = "" + "(=z)=a=b<#c>/&/123" + "\n" + "(=z)=a/#e/(=z)=f" + "\n" + "(=z)=f/#g/(=z)=a=b"; String copiedGraphString = "" + "=a=b<#c>/&/123" + "\n" + "=a/#e/=f" + "\n" + "=f/#g/=a=b"; Graph graph1 = MemoryGraphFactory.getInstance().parseGraph(graphString); Graph graph2 = MemoryGraphFactory.getInstance().parseGraph(copiedGraphString); Graph graph3 = MemoryGraphFactory.getInstance().openGraph(); CopyUtil.copyGraph(graph1, graph3, new ExtractXDIAddressCopyStrategy(XdiPeerRoot.class, false, false, false, false, true)); assertNotEquals(graph1, graph2); assertNotEquals(graph1, graph3); assertEquals(graph2, graph3); graph1.close(); graph2.close(); graph3.close(); } }
public void testConcatXDIAddressCopyStrategy() throws Exception { String graphString = "" + "=a=b<#c>/&/123" + "\n" + "=a/#e/=f" + "\n" + "=f/#g/=a=b"; String copiedGraphString = "" + "=x=y=a=b<#c>/&/123" + "\n" + "=x=y=a/#e/=x=y=f" + "\n" + "=x=y=f/#g/=x=y=a=b"; Graph graph1 = MemoryGraphFactory.getInstance().parseGraph(graphString); Graph graph2 = MemoryGraphFactory.getInstance().parseGraph(copiedGraphString); Graph graph3 = MemoryGraphFactory.getInstance().openGraph(); CopyUtil.copyGraph(graph1, graph3, new ConcatXDIAddressCopyStrategy(XDIAddress.create("=x=y"))); assertNotEquals(graph1, graph2); assertNotEquals(graph1, graph3); assertEquals(graph2, graph3); graph1.close(); graph2.close(); graph3.close(); }