@Override protected Results createResults( final ResultsPage resultsPage ) { final List<Entity> entityList = resultsPage.getEntityList(); final List<org.apache.usergrid.persistence.Entity> resultsEntities = new ArrayList<>( entityList.size() ); for ( final Entity entity : entityList ) { resultsEntities.add( mapEntity( entity ) ); } final Results results = Results.fromEntities( resultsEntities ); return results; }
return this; return Results.fromEntities( entities.subList( i, entities.size() ) );
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); }
@Override public Results get( Collection<UUID> entityIds, Class<? extends Entity> entityClass, Level resultsLevel ) throws Exception { String type = Schema.getDefaultSchema().getEntityType( entityClass ); ArrayList<Entity> entities = new ArrayList<Entity>(); for ( UUID uuid : entityIds ) { EntityRef ref = new SimpleEntityRef( type, uuid ); Entity entity = get( ref, entityClass ); if ( entity != null ) { entities.add( entity ); } } return Results.fromEntities( entities ); }
@Override public Results getSourceEntities( String connType, String fromEntityType, Level level, int count ) throws Exception { // looking for edges to the head entity String edgeType = CpNamingUtils.getEdgeTypeFromConnectionType( connType ); Map<EntityRef, Set<String>> containers = getContainers( count, edgeType, fromEntityType ); if ( Level.REFS.equals( level ) ) { List<EntityRef> refList = new ArrayList<EntityRef>( containers.keySet() ); return Results.fromRefList( refList ); } if ( Level.IDS.equals( level ) ) { // TODO: someday this should return a list of Core Persistence Ids List<UUID> idList = new ArrayList<UUID>(); for ( EntityRef ref : containers.keySet() ) { idList.add( ref.getUuid() ); } return Results.fromIdList( idList ); } List<Entity> entities = new ArrayList<Entity>(); for ( EntityRef ref : containers.keySet() ) { Entity entity = em.get( ref ); if (logger.isTraceEnabled()) { logger.trace(" Found connecting entity: " + entity.getProperties()); } entities.add( entity ); } return Results.fromEntities( entities ); }
return new ServiceResults( this, context, Type.COLLECTION, Results.fromEntities( entities ), null, null );
@Override public Results getEntities( List<UUID> ids, String type ) { List<Id> entityIds = new ArrayList<>(); for( UUID uuid : ids){ entityIds.add(new SimpleId( uuid, type )); } // leverage ecm.load so it's a batch fetch of all entities from Cassandra EntitySet entitySet = ecm.load( entityIds ).toBlocking().last(); List<Entity> entities = entitySet.getEntities().stream().map( mvccEntity -> { if( mvccEntity.getEntity().isPresent() ){ org.apache.usergrid.persistence.model.entity.Entity cpEntity = mvccEntity.getEntity().get(); Class clazz = Schema.getDefaultSchema().getEntityClass( mvccEntity.getId().getType() ); Entity entity = EntityFactory.newEntity( mvccEntity.getId().getUuid(), mvccEntity.getId().getType(), clazz ); entity.setProperties( cpEntity ); return entity; }else{ logger.warn("Tried fetching entity with id: {} and type: but was not found", mvccEntity.getId().getUuid(), mvccEntity.getId().getType() ); return null; } }).collect(Collectors.toList()); return Results.fromEntities( entities ); }