@Override public void copyRelationships( String srcRelationName, EntityRef dstEntityRef, String dstRelationName ) throws Exception { headEntity = em.validate( headEntity ); dstEntityRef = em.validate( dstEntityRef ); CollectionInfo srcCollection = getDefaultSchema().getCollection( headEntity.getType(), srcRelationName ); CollectionInfo dstCollection = getDefaultSchema().getCollection( dstEntityRef.getType(), dstRelationName ); Results results = null; do { if ( srcCollection != null ) { results = em.getCollection( headEntity, srcRelationName, null, 5000, Level.REFS, false ); } else { results = em.getTargetEntities( headEntity, srcRelationName, null, Level.REFS ); } if ( ( results != null ) && ( results.size() > 0 ) ) { List<EntityRef> refs = results.getRefs(); for ( EntityRef ref : refs ) { if ( dstCollection != null ) { em.addToCollection( dstEntityRef, dstRelationName, ref ); } else { em.createConnection( dstEntityRef, dstRelationName, ref ); } } } } while ( ( results != null ) && ( results.hasMoreResults() ) ); }
@Override 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.isTraceEnabled() ) { logger.trace( "createConnection(): Indexing connection type '{}'\n from source {}:{}]\n to target {}:{}\n app {}", 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 ); // create graph edge connection from head entity to member entity final Edge edge = createConnectionEdge( cpHeadEntity.getId(), connectionType, targetEntity.getId() ); final GraphManager gm = managerCache.getGraphManager( applicationScope ); //write new edge gm.writeEdge(edge).toBlocking().lastOrDefault(null); //throw an exception if this fails String entityType = targetEntity.getId().getType(); if ( !skipIndexingForType( entityType ) ) { QueueIndexingStrategy queueIndexingStrategy = getIndexingStrategyForType(entityType); indexService.queueNewEdge(applicationScope, targetEntity.getId(), edge, queueIndexingStrategy); } // remove any duplicate edges (keeps the duplicate edge with same timestamp) removeDuplicateEdgesAsync(gm, edge); return connection; }
headEntity = em.validate( headEntity );
headEntity = em.validate( headEntity );