/** * Persists the connection for this entity. */ private void saveConnections( Entity entity, EntityManager em, JsonGenerator jg ) throws Exception { jg.writeFieldName( "connections" ); jg.writeStartObject(); Set<String> connectionTypes = em.getConnectionTypes( entity ); for ( String connectionType : connectionTypes ) { jg.writeFieldName( connectionType ); jg.writeStartArray(); Results results = em.getTargetEntities( new SimpleEntityRef(entity.getType(), entity.getUuid()), connectionType, null, Level.IDS); List<ConnectionRef> connections = results.getConnections(); for ( ConnectionRef connectionRef : connections ) { jg.writeObject( connectionRef.getTargetRefs().getUuid() ); } jg.writeEndArray(); } jg.writeEndObject(); }
public Map<String, Map<String, List<UUID>>> testEntityConnections( UUID applicationId, UUID entityId, String connectionType, String entityType, int expectedCount ) throws Exception { logger.info( "----------------------------------------------------" ); logger.info( "Checking connections for " + entityId.toString() ); EntityManager em = setup.getEmf().getEntityManager( applicationId ); Entity en = em.get( new SimpleEntityRef( entityType, entityId)); Results results = em.getTargetEntities(en, connectionType, null, Level.REFS); logger.info( "----------------------------------------------------" ); assertEquals( "Expected " + expectedCount + " connections", expectedCount, results.getConnections().size() ); // return connections; return null; }
for (int i = 0; i < 2; i++) { r = em.getTargetEntities(entities.get(i), "related", null, Level.IDS); connections = r.getConnections(); assertNotNull(connections);
for (int i = 0; i < 2; i++) { r = em.getTargetEntities(entities.get(i), "related", null, Level.IDS); connections = r.getConnections(); assertNotNull(connections);
for ( Entity e : importedThings ) { Results r = emApp2.getTargetEntities(e, "related", null, Level.IDS); List<ConnectionRef> connections = r.getConnections(); conCount += connections.size();
@Test public void testEntityConnectionsSimple() throws Exception { EntityManager em = app.getEntityManager(); assertNotNull( em ); User first = new User(); first.setUsername( "first" ); first.setEmail( "first@usergrid.com" ); Entity firstUserEntity = em.create( first ); assertNotNull( firstUserEntity ); User second = new User(); second.setUsername( "second" ); second.setEmail( "second@usergrid.com" ); Entity secondUserEntity = em.create( second ); assertNotNull( secondUserEntity ); em.createConnection( firstUserEntity, "likes", secondUserEntity ); Set<String> connectionTypes = em.getConnectionTypes(firstUserEntity); assertEquals( 1, connectionTypes.size()); assertEquals("likes", connectionTypes.iterator().next()); app.waitForQueueDrainAndRefreshIndex(); Results r = em.getTargetEntities(firstUserEntity, "likes", null, Level.IDS); List<ConnectionRef> connections = r.getConnections(); assertNotNull( connections ); assertEquals(1, connections.size()); assertEquals( secondUserEntity.getUuid(), connections.get( 0 ).getTargetRefs().getUuid() ); assertEquals( firstUserEntity.getUuid(), connections.get( 0 ).getSourceRefs().getUuid() ); }
List<ConnectionRef> connections = r.getConnections(); connections = r.getConnections();