@Override public BiMap<UUID, String> getApplicationsForOrganization( UUID organizationGroupId ) throws Exception { if ( organizationGroupId == null ) { return null; } final BiMap<UUID, String> applications = HashBiMap.create(); final EntityManager em = emf.getEntityManager(smf.getManagementAppId()); // query for application_info entities final Results results = em.getTargetEntities( new SimpleEntityRef(Group.ENTITY_TYPE, organizationGroupId), ORG_APP_RELATIONSHIP, CpNamingUtils.APPLICATION_INFO, Level.ALL_PROPERTIES); final PagingResultsIterator itr = new PagingResultsIterator( results ); String entityName; while ( itr.hasNext() ) { final Entity entity = ( Entity ) itr.next(); entityName = entity.getName(); if ( entityName != null ) { entityName = entityName.toLowerCase(); } // make sure we return applicationId and not the application_info UUID UUID applicationId = entity.getUuid(); applications.put( applicationId, entityName ); } return applications; }
c = (EntityRef) itr.next(); refs.add(c);
FileImport fi = (FileImport) itr.next();
private int getConnectionCountViaGet( final Import importRoot ) { try { EntityManager emMgmtApp = setup.getEmf() .getEntityManager(setup.getEmf().getManagementAppId() ); Results entities = emMgmtApp.getTargetEntities( importRoot, "includes", null, Query.Level.ALL_PROPERTIES); PagingResultsIterator itr = new PagingResultsIterator( entities ); int count = 0; while ( itr.hasNext() ) { itr.next(); count++; } return count; } catch ( Exception e ) { logger.error( "application doesn't exist within the current context" ); throw new RuntimeException( e ); } }
itr.next(); count++;
int count = 13; while ( pri.hasNext() ) { Entity e = ( Entity ) pri.next(); assertEquals( count --, e.getProperty( "index" ) );
@Test public void testConnectionsIterable() 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 ); final int connectionCount = 100; final Map<UUID, Entity> things = new HashMap<>(); for(int i = 0; i < connectionCount; i ++){ Map<String, Object> data = new HashMap<String, Object>(); data.put( "ordinal", i ); Entity entity = em.create( "thing", data ); em.createConnection( firstUserEntity, "likes", entity ); things.put( entity.getUuid(), entity ); } app.waitForQueueDrainAndRefreshIndex(); Results r = em.getTargetEntities(firstUserEntity, "likes", null, Level.ALL_PROPERTIES) ; PagingResultsIterator itr = new PagingResultsIterator( r ); int checkedIndex = 0; for(; checkedIndex < connectionCount && itr.hasNext(); checkedIndex ++){ final Entity returned = ( Entity ) itr.next(); final Entity expected = things.get( returned.getUuid() ); assertEquals("Entity expected", expected, returned); } assertEquals("Checked all entities", connectionCount, checkedIndex ); }