Source:
public ConnectionRef createConnection( String connectionType, EntityRef connectedEntityRef ) throws Exception { headEntity = em.validate( headEntity ); connectedEntityRef = em.validate( connectedEntityRef ); ConnectionRefImpl connection = new ConnectionRefImpl( headEntity, connectionType, connectedEntityRef ); if ( logger.isDebugEnabled() ) { logger.debug( "createConnection(): " + "Indexing connection type '{}'\n from source {}:{}]\n" + " to target {}:{}\n app {}", new Object[] { connectionType, headEntity.getType(), headEntity.getUuid(), connectedEntityRef.getType(), connectedEntityRef.getUuid(), applicationScope } ); } final Id entityId = new SimpleId( connectedEntityRef.getUuid(), connectedEntityRef.getType() ); final org.apache.usergrid.persistence.model.entity.Entity targetEntity = ( ( CpEntityManager ) em ).load( entityId ); final Edge edge = createConnectionEdge( cpHeadEntity.getId(), connectionType, targetEntity.getId() ); final GraphManager gm = managerCache.getGraphManager( applicationScope ); gm.writeEdge( edge ).subscribe(); indexService.queueNewEdge( applicationScope, targetEntity, edge ); final SearchByEdge searchByEdge = new SimpleSearchByEdge( edge.getSourceNode(), edge.getType(), edge.getTargetNode(), Long.MAX_VALUE, SearchByEdgeType.Order.DESCENDING, Optional.absent() ); gm.loadEdgeVersions( searchByEdge ).skip( 1 ).flatMap( edgeToDelete -> { if ( logger.isDebugEnabled() ) { logger.debug( "Marking edge for deletion", edgeToDelete ); } return gm.markEdge( edge ); } ).lastOrDefault( null ).doOnNext( lastEdge -> { if(lastEdge == null){ return; } indexService.queueDeleteEdge( applicationScope, lastEdge ); }).subscribe(); return connection; }

Target:
public ConnectionRef createConnection( String connectionType, EntityRef connectedEntityRef ) throws Exception { headEntity = em.validate( headEntity ); connectedEntityRef = em.validate( connectedEntityRef ); ConnectionRefImpl connection = new ConnectionRefImpl( headEntity, connectionType, connectedEntityRef ); if ( logger.isDebugEnabled() ) { logger.debug( "createConnection(): " + "Indexing connection type '{}'\n from source {}:{}]\n" + " to target {}:{}\n app {}", new Object[] { connectionType, headEntity.getType(), headEntity.getUuid(), connectedEntityRef.getType(), connectedEntityRef.getUuid(), applicationScope } ); } final Id entityId = new SimpleId( connectedEntityRef.getUuid(), connectedEntityRef.getType() ); final org.apache.usergrid.persistence.model.entity.Entity targetEntity = ( ( CpEntityManager ) em ).load( entityId ); final Edge edge = createConnectionEdge( cpHeadEntity.getId(), connectionType, targetEntity.getId() ); final GraphManager gm = managerCache.getGraphManager( applicationScope ); gm.writeEdge( edge ).subscribe(); indexService.queueNewEdge( applicationScope, targetEntity, edge ); final SearchByEdge searchByEdge = new SimpleSearchByEdge( edge.getSourceNode(), edge.getType(), edge.getTargetNode(), Long.MAX_VALUE, SearchByEdgeType.Order.DESCENDING, Optional.absent() ); gm.loadEdgeVersions( searchByEdge ).skip( 1 ).flatMap( edgeToDelete -> { if ( logger.isDebugEnabled() ) { logger.debug( "Marking edge for deletion", edgeToDelete ); } return gm.markEdge( edgeToDelete ); } ).lastOrDefault( null ).doOnNext( lastEdge -> { if(lastEdge == null){ return; } gm.deleteEdge( lastEdge ).subscribe(); }).subscribe(); return connection; }