@SuppressWarnings("unchecked") @JsonSerialize(include = Inclusion.NON_NULL) public <E extends Entity> List<E> getList() { List<Entity> l = getEntities(); return ( List<E> ) l; }
@Override public JobStat getStatsForJob( String jobName, UUID jobId ) throws Exception { EntityManager em = emf.getEntityManager( emf.getManagementAppId() ); Query query = Query.fromQL( "select * where " + JOB_NAME + " = '" + jobName + "' AND " + JOB_ID + " = " + jobId ); Results r = em.searchCollection( em.getApplicationRef(), "job_stats", query ); if ( r.size() == 1 ) { return ( JobStat ) r.getEntity(); } return null; }
/** * 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 Results findForProperty( String propertyName, Object propertyValue, int count ) { if ( propertyValue == null ) { return new Results(); } List<Entity> l = getEntities(); if ( l == null ) { return new Results(); } List<Entity> found = new ArrayList<Entity>(); for ( Entity e : l ) { if ( propertyValue.equals( e.getProperty( propertyName ) ) ) { found.add( e ); if ( ( count > 0 ) && ( found.size() == count ) ) { break; } } } return Results.fromEntities(found); }
if(overrideLevel != null){ level=overrideLevel; if(results.getIds()!=null){ List<EntityRef> userRefs = results.getIds().stream() .map( uuid -> new SimpleEntityRef("user", uuid)).collect(Collectors.toList()); results.setRefs(userRefs); switch ( level ) { case IDS: currentPage = results.getIds(); level = origLevel; break; case REFS: currentPage = results.getRefs(); level = origLevel; break; default: currentPage = results.getEntities(); level = origLevel;
public void merge( Results results ) { getEntitiesMap(); results.getEntitiesMap(); if ( entitiesMap != null || results.entitiesMap != null ) { getRefsMap(); results.getRefsMap(); if ( ( refsMap != null ) || ( results.refsMap != null ) ) { getIdSet(); results.getIdSet(); if ( ( idSet != null ) && ( results.idSet != null ) ) {
@Override public List<OrganizationInfo> getOrganizations( UUID startResult, int count ) throws Exception { // still need the bimap to search for existing BiMap<UUID, String> organizations = HashBiMap.create(); EntityManager em = emf.getEntityManager(smf.getManagementAppId()); Results results = em.getCollection(em.getApplicationRef(), Schema.COLLECTION_GROUPS, startResult, count, Level.ALL_PROPERTIES, false); List<OrganizationInfo> orgs = new ArrayList<>( results.size() ); OrganizationInfo orgInfo; for ( Entity entity : results.getEntities() ) { String path = ( String ) entity.getProperty( PROPERTY_PATH ); if ( organizations.containsValue( path ) ) { path += "DUPLICATE"; } orgInfo = new OrganizationInfo( entity.getUuid(), path ); orgs.add( orgInfo ); organizations.put( entity.getUuid(), path ); } return orgs; }
@Test public void nameIdentifierTest() throws Exception { logger.debug( "nameIdentifierTest" ); EntityManager em = app.getEntityManager(); assertNotNull( em ); Map<String, Object> properties = new LinkedHashMap<String, Object>(); properties.put( "keywords", "blah,test,game" ); properties.put( "title", "Solitaire" ); properties.put( "name", "test" ); Entity game1 = em.create( "games", properties ); assertNotNull( game1 ); //we create 2 entities, otherwise this test will pass when it shouldn't properties.put( "name", "test2" ); Entity game2 = em.create( "game", properties ); assertNotNull( game2 ); app.waitForQueueDrainAndRefreshIndex(); // overlap Query query = new Query(); query.addIdentifier( Identifier.fromName( "test" ) ); Results r = em.searchCollection( em.getApplicationRef(), "games", query ); assertEquals( "We should only get 1 result", 1, r.size() ); assertNull( "No cursor should be present", r.getCursor() ); assertEquals( "Saved entity returned", game1, r.getEntity() ); }
em.getApplicationId(), "things", null, Level.ALL_PROPERTIES).getEntities(); Results results = importService.getFileImports( appId, importId, null, null ); assertEquals( "There is one", 1, results.size() ); FileImport.class, results.getEntity().getClass() ); FileImport fileImport = (FileImport)results.getEntity();
logger.info( JsonUtils.mapToFormattedJsonString( r.getEntities() ) ); assertEquals( pageSize, r.size() ); final UUID entityId = entityIds.get( expectedIndex ); final UUID returnedId = r.getEntities().get( j ).getUuid(); r = r.getNextPageResults(); assertEquals( 0, r.size() ); assertNull(r.getCursor());
for ( int i = 0; i < results.size(); i++, currentExpectedIndex++ ) { final UUID returnedUUID = results.getEntities().get( i ).getUuid(); query.setCursor( results.getCursor() ); while ( results.getCursor() != null );
int size = size(); if ( size <= count ) { return this; List<UUID> ids = getIds(); UUID nextResult = null; String cursor = null; Results r = new Results( this ); if ( r.entities != null ) { r.entities = r.entities.subList( 0, count ); r.ids = r.ids.subList( 0, count ); r.setNextResult( nextResult ); r.setCursor( cursor );
public void distribute( EntityRef group, EntityRef user, Entity activity ) throws Exception { if ( activity == null ) { return; } em.addToCollection( user, "feed", activity ); Results r1 = em.getCollection( group, "users", null, 10000, Level.IDS, false ); if ( ( r1 == null ) || ( r1.isEmpty() ) ) { return; } Results r2 = em.getSourceEntities(new SimpleEntityRef(user.getType(), user.getUuid()), "following", User.ENTITY_TYPE, Level.IDS); if ( ( r2 == null ) || ( r2.isEmpty() ) ) { return; } r1.and( r2 ); List<EntityRef> refs = Results.fromIdList( r1.getIds(), User.ENTITY_TYPE ).getRefs(); if ( refs != null ) { em.addToCollections( refs, "feed", activity ); } } }
public boolean isEmpty() { return size() == 0; }
for (Entity eachEntity : collection.getEntities() ) { for (int i = 0; i < 2; i++) { r = em.getTargetEntities(entities.get(i), "related", null, Level.IDS); connections = r.getConnections(); assertNotNull(connections);
assertTrue( r.size() == 1 ); assertEquals( entity.getUuid(), r.getId() ); assertEquals( "connection must match", 1, r.size() ); assertEquals( entity.getUuid(), r.getId() ); final Entity entityResults = r.getEntity(); assertEquals( "ed@anuff.com", entityResults.getProperty( "username" ) ); assertEquals( "ed@anuff.com", entityResults.getProperty( "email" ) );
private int countEntities( EntityManager em, String collectionName, int expectedEntities) throws Exception { app.waitForQueueDrainAndRefreshIndex(); Query q = Query.fromQL( "select * where key1=1000" ).withLimit( 1000 ); Results results = em.searchCollectionConsistent( em.getApplicationRef(), collectionName, q, expectedEntities ); int count = 0; while ( true ) { count += results.size(); if ( results.hasCursor() ) { logger.info( "Counted {} : query again with cursor", count ); q.setCursor( results.getCursor() ); results = em.searchCollection( em.getApplicationRef(), collectionName, q ); } else { break; } } assertEquals( "Did not get expected entities", expectedEntities, count ); return count; }
for ( Entity entity : results.getEntities() ) { results = results.hasMoreResults() ? results.getNextPageResults() : null ;
@Override public Map<String, String> getServiceProperties() { Map<String, String> props = new HashMap<String,String>(); EntityManager em = getEntityManager(getManagementAppId()); Query q = Query.fromQL("select *"); Results results = null; try { results = em.searchCollection( em.getApplicationRef(), "propertymaps", q); } catch (Exception ex) { logger.error("Error getting system properties", ex); } if ( results == null || results.isEmpty() ) { return props; } org.apache.usergrid.persistence.Entity e = results.getEntity(); for ( String key : e.getProperties().keySet() ) { props.put( key, props.get(key).toString() ); } return props; }
@JsonSerialize(include = Inclusion.NON_NULL) public EntityRef getRef() { if ( ref != null ) { return ref; } ref = getEntity(); if ( ref != null ) { return ref; } UUID u = getId(); if ( u != null ) { String type= null; if(refs!=null && refs.size()>0){ type = refs.get(0).getType(); } return ref( type,u ); } return null; }