public Observable<MarkedEdge> getApplicationInfoEdges( final UUID applicationId ) { final ApplicationScope managementAppScope = getApplicationScope( CpNamingUtils.MANAGEMENT_APPLICATION_ID ); final GraphManager gm = graphManagerFactory.createEdgeManager( managementAppScope ); String edgeType = CpNamingUtils.getEdgeTypeFromCollectionName( CpNamingUtils.APPLICATION_INFOS ); final SimpleSearchByEdge simpleSearchByEdgeType = new SimpleSearchByEdge( CpNamingUtils.generateApplicationId( CpNamingUtils.MANAGEMENT_APPLICATION_ID ), edgeType, CpNamingUtils.generateApplicationId( applicationId ), Long.MAX_VALUE, SearchByEdgeType.Order.DESCENDING, Optional.absent() ); return gm.loadEdgeVersions( simpleSearchByEdgeType ); } }
@Override public Observable<FilterResult<Id>> call( final Observable<FilterResult<Id>> filterValueObservable ) { final GraphManager gm = graphManagerFactory.createEdgeManager( pipelineContext.getApplicationScope() ); return filterValueObservable.flatMap( filterValue -> { final String edgeTypeName = getEdgeName(); final Id id = filterValue.getValue(); //create our search final SearchByEdge searchByEdge = new SimpleSearchByEdge( id, edgeTypeName, targetId, Long.MAX_VALUE, SearchByEdgeType.Order.DESCENDING, Optional.absent() ); //load the versions of the edge, take the first since that's all we need to validate existence, then emit the target node return gm.loadEdgeVersions( searchByEdge ).take( 1 ).map( edge -> edge.getTargetNode() ).map( targetId -> new FilterResult<>(targetId, filterValue.getPath())); } ); }
private void removeDuplicateEdgesAsync(GraphManager gm, Edge edge){ //now read all older versions of an edge, and remove them. Finally calling delete final SearchByEdge searchByEdge = new SimpleSearchByEdge( edge.getSourceNode(), edge.getType(), edge.getTargetNode(), Long.MAX_VALUE, SearchByEdgeType.Order.DESCENDING, Optional.absent() ); //load our versions, only retain the most recent one gm.loadEdgeVersions(searchByEdge).skip(1).flatMap(edgeToDelete -> { if (logger.isDebugEnabled()) { logger.debug("Duplicate edge. Marking edge {} for deletion", edgeToDelete); } return gm.markEdge(edgeToDelete ); }).lastOrDefault(null).doOnNext(lastEdge -> { //no op if we hit our default if (lastEdge == null) { return; } //don't queue delete b/c that de-indexes, we need to delete the edges only since we have a version still existing to index. gm.deleteEdge(lastEdge).toBlocking().lastOrDefault(null); // this should throw an exception }).toBlocking().lastOrDefault(null);//this should throw an exception }
new SimpleSearchByEdge( edge.getSourceNode(), edge.getType(), edge.getTargetNode(), Long.MAX_VALUE, SearchByEdgeType.Order.DESCENDING, Optional.absent() ); return gm.loadEdgeVersions( searchByEdge )
@Override public boolean isConnectionMember( String connectionType, EntityRef entity ) throws Exception { Id entityId = new SimpleId( entity.getUuid(), entity.getType() ); if (logger.isTraceEnabled()) { logger.trace("isConnectionMember(): Checking for edge type {} from {}:{} to {}:{}", connectionType, headEntity.getType(), headEntity.getUuid(), entity.getType(), entity.getUuid() ); } GraphManager gm = managerCache.getGraphManager( applicationScope ); Observable<MarkedEdge> edges = gm.loadEdgeVersions( CpNamingUtils .createEdgeFromConnectionType( new SimpleId( headEntity.getUuid(), headEntity.getType() ), connectionType, entityId ) ); return edges.toBlocking().firstOrDefault( null ) != null; }
@SuppressWarnings( "unchecked" ) @Override public boolean isCollectionMember( String collectionName, EntityRef entity ) throws Exception { Id entityId = new SimpleId( entity.getUuid(), entity.getType() ); if (logger.isTraceEnabled()) { logger.trace("isCollectionMember(): Checking for edge type {} from {}:{} to {}:{}", collectionName, headEntity.getType(), headEntity.getUuid(), entity.getType(), entity.getUuid() ); } GraphManager gm = managerCache.getGraphManager( applicationScope ); Observable<MarkedEdge> edges = gm.loadEdgeVersions( CpNamingUtils .createEdgeFromCollectionName( new SimpleId( headEntity.getUuid(), headEntity.getType() ), collectionName, entityId ) ); return edges.toBlocking().firstOrDefault( null ) != null; }
List<MarkedEdge> edgeList = graphManager.loadEdgeVersions(searchByEdge).toList().toBlocking().last(); boolean timestampAllowsDelete = false; if (edgeList.size() > 0) {
@Override public void removeItemFromCollection( String collectionName, EntityRef itemRef ) throws Exception { Id entityId = new SimpleId( itemRef.getUuid(), itemRef.getType() ); // remove edge from collection to item GraphManager gm = managerCache.getGraphManager( applicationScope ); // mark the edge versions and take the first for later delete edge queue event ( load is descending ) final Edge markedSourceEdge = gm.loadEdgeVersions( CpNamingUtils.createEdgeFromCollectionName( cpHeadEntity.getId(), collectionName, entityId ) ) .flatMap(edge -> gm.markEdge(edge)).toBlocking().firstOrDefault(null); Edge markedReversedEdge = null; CollectionInfo collection = getDefaultSchema().getCollection( headEntity.getType(), collectionName ); if (collection != null && collection.getLinkedCollection() != null) { // delete reverse edges final String pluralType = InflectionUtils.pluralize( cpHeadEntity.getId().getType() ); markedReversedEdge = gm.loadEdgeVersions( CpNamingUtils.createEdgeFromCollectionName( entityId, pluralType, cpHeadEntity.getId() ) ) .flatMap(reverseEdge -> gm.markEdge(reverseEdge)).toBlocking().firstOrDefault(null); } /** * Remove from the index. This will call gm.deleteEdge which also deletes the reverse edge(s) and de-indexes * older versions of the edge(s). * */ if( markedSourceEdge != null ) { indexService.queueDeleteEdge(applicationScope, markedSourceEdge); } if( markedReversedEdge != null ){ indexService.queueDeleteEdge(applicationScope, markedReversedEdge); } }
@Override public void deleteConnection( ConnectionRef connectionRef ) throws Exception { // First, clean up the dictionary records of the connection EntityRef connectingEntityRef = connectionRef.getSourceRefs(); // source EntityRef connectedEntityRef = connectionRef.getTargetRefs(); // target String connectionType = connectionRef.getTargetRefs().getConnectionType(); if ( logger.isTraceEnabled() ) { logger.trace( "Deleting connection '{}' from source {}:{} \n to target {}:{}", connectionType, connectingEntityRef.getType(), connectingEntityRef.getUuid(), connectedEntityRef.getType(), connectedEntityRef.getUuid() ); } Id entityId = new SimpleId( connectedEntityRef.getUuid(), connectedEntityRef.getType() ); org.apache.usergrid.persistence.model.entity.Entity targetEntity = ( ( CpEntityManager ) em ).load( entityId ); GraphManager gm = managerCache.getGraphManager( applicationScope ); final Id sourceId = new SimpleId( connectingEntityRef.getUuid(), connectingEntityRef.getType() ); final SearchByEdge search = createConnectionSearchByEdge( sourceId, connectionType, targetEntity.getId() ); //delete all the edges and queue their processing gm.loadEdgeVersions( search ).flatMap( returnedEdge -> gm.markEdge( returnedEdge ) ) .doOnNext( returnedEdge -> { if ( !skipIndexingForType( returnedEdge.getSourceNode().getType() ) || !skipIndexingForType( returnedEdge.getTargetNode().getType() ) ) { indexService.queueDeleteEdge(applicationScope, returnedEdge); } }).toBlocking() .lastOrDefault( null ); }
SearchByEdgeType.Order.DESCENDING, Optional.<Edge>absent() ); final Observable<MarkedEdge> edgesDescending = gm.loadEdgeVersions( searchDescending ); SearchByEdgeType.Order.ASCENDING, Optional.<Edge>absent() ); Observable<MarkedEdge> edgesAscending = gm.loadEdgeVersions( searchAscending );
@Test public void testSingleConnection() { final ApplicationScope applicationScope = new ApplicationScopeImpl( new SimpleId( "application" ) ); final GraphManager gm = graphManagerFactory.createEdgeManager( applicationScope ); //now write a single connection final Id source = new SimpleId( "source" ); //add to a collection final String collectionName = "testCollection"; final Edge collectionEdge = CpNamingUtils.createCollectionEdge( applicationScope.getApplication(), collectionName, source ); final Edge writtenCollection = gm.writeEdge( collectionEdge ).toBlocking().last(); assertNotNull("Collection edge written", writtenCollection); final Id target = new SimpleId( "target" ); final String connectionType = "testConnection"; final Edge connectionEdge = CpNamingUtils.createConnectionEdge( source, connectionType, target ); final Edge writtenConnection = gm.writeEdge( connectionEdge ).toBlocking().last(); //now run the cleanup final int count = connectionService.deDupeConnections( Observable.just( applicationScope ) ).count().toBlocking().last(); assertEquals( "No edges deleted", 0, count ); //now ensure we can read the edge. final SearchByEdge simpleSearchByEdge = new SimpleSearchByEdge( source, connectionEdge.getType(), target, Long.MAX_VALUE, SearchByEdgeType.Order.DESCENDING, Optional.absent() ); final List<MarkedEdge> edges = gm.loadEdgeVersions( simpleSearchByEdge ).toList().toBlocking().last(); assertEquals( 1, edges.size() ); assertEquals( writtenConnection, edges.get( 0 ) ); }
final List<MarkedEdge> edges = gm.loadEdgeVersions( simpleSearchByEdge ).toList().toBlocking().last();
createGetByEdge( edge.getSourceNode(), edge.getType(), edge.getTargetNode(), edge.getTimestamp(), null ); returned = gm.loadEdgeVersions( searchByEdge ).toBlocking().single(); returned = gm.loadEdgeVersions( searchByEdge ).toBlocking().singleOrDefault( null );