From e1ccb191f4a9f5091d6e2759a7df4014c61c25eb Mon Sep 17 00:00:00 2001 From: peacekeeper Date: Wed, 14 Oct 2015 11:23:42 +0200 Subject: [PATCH] write index for new link contracts --- .../interceptor/impl/connect/ConnectInterceptor.java | 9 +++++++-- .../interceptor/impl/push/PushInInterceptor.java | 11 ++++++++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/messaging-target/src/main/java/xdi2/messaging/target/interceptor/impl/connect/ConnectInterceptor.java b/messaging-target/src/main/java/xdi2/messaging/target/interceptor/impl/connect/ConnectInterceptor.java index f91ced797..638e3c3bc 100644 --- a/messaging-target/src/main/java/xdi2/messaging/target/interceptor/impl/connect/ConnectInterceptor.java +++ b/messaging-target/src/main/java/xdi2/messaging/target/interceptor/impl/connect/ConnectInterceptor.java @@ -17,11 +17,14 @@ import xdi2.client.manipulator.impl.SetLinkContractMessageManipulator; import xdi2.core.ContextNode; import xdi2.core.Graph; +import xdi2.core.constants.XDILinkContractConstants; +import xdi2.core.features.index.Index; import xdi2.core.features.linkcontracts.LinkContractTemplates; import xdi2.core.features.linkcontracts.instance.LinkContract; import xdi2.core.features.linkcontracts.instance.PublicLinkContract; import xdi2.core.features.linkcontracts.instantiation.LinkContractInstantiation; import xdi2.core.features.linkcontracts.template.LinkContractTemplate; +import xdi2.core.features.nodetypes.XdiEntityCollection; import xdi2.core.features.nodetypes.XdiEntitySingleton; import xdi2.core.features.nodetypes.XdiInnerRoot; import xdi2.core.syntax.XDIAddress; @@ -249,15 +252,17 @@ private void processConnect(LinkContractTemplate linkContractTemplate, Operation LinkContract linkContract = linkContractInstantiation.execute(instanceXDIArc, true); - // write link contract into operation result graph + // write link contract and index into operation result graph CopyUtil.copyGraph(linkContract.getContextNode().getGraph(), operationResultGraph, null); - // link contract into target graph + // write link contract and index into target graph if (this.getTargetGraph() != null) { CopyUtil.copyGraph(linkContract.getContextNode().getGraph(), this.getTargetGraph(), null); + XdiEntityCollection xdiLinkContractIndex = Index.getEntityIndex(this.getTargetGraph(), XDILinkContractConstants.XDI_ARC_DO, true); + Index.setEntityIndexAggregation(xdiLinkContractIndex, linkContract.getXdiEntity()); } } diff --git a/messaging-target/src/main/java/xdi2/messaging/target/interceptor/impl/push/PushInInterceptor.java b/messaging-target/src/main/java/xdi2/messaging/target/interceptor/impl/push/PushInInterceptor.java index cf5111264..8e932ebd3 100644 --- a/messaging-target/src/main/java/xdi2/messaging/target/interceptor/impl/push/PushInInterceptor.java +++ b/messaging-target/src/main/java/xdi2/messaging/target/interceptor/impl/push/PushInInterceptor.java @@ -8,7 +8,10 @@ import org.slf4j.LoggerFactory; import xdi2.core.Graph; +import xdi2.core.constants.XDILinkContractConstants; +import xdi2.core.features.index.Index; import xdi2.core.features.linkcontracts.instance.LinkContract; +import xdi2.core.features.nodetypes.XdiEntityCollection; import xdi2.core.features.nodetypes.XdiInnerRoot; import xdi2.core.syntax.XDIAddress; import xdi2.core.util.CopyUtil; @@ -170,13 +173,15 @@ private void processPush(Message pushedMessage, Operation operation, Graph opera // TODO: use feedback message? or have member field private Graph targetGraph; ? // TODO: or have the XDIClient put it into our "origin" graph by adding a originGraph parameter to XDIClient? - if ((executionContext.getCurrentMessagingTarget() instanceof GraphMessagingTarget)) { + // write link contract and index into target graph - GraphMessagingTarget graphMessagingTarget = ((GraphMessagingTarget) executionContext.getCurrentMessagingTarget()); + if (this.getTargetGraph() != null) { for (LinkContract pushLinkContract : pushMessagingResponse.getPushLinkContracts()) { - CopyUtil.copyContextNode(pushLinkContract.getContextNode(), graphMessagingTarget.getGraph(), null); + CopyUtil.copyContextNode(pushLinkContract.getContextNode(), this.getTargetGraph(), null); + XdiEntityCollection xdiLinkContractIndex = Index.getEntityIndex(this.getTargetGraph(), XDILinkContractConstants.XDI_ARC_DO, true); + Index.setEntityIndexAggregation(xdiLinkContractIndex, pushLinkContract.getXdiEntity()); } } }