public MultiQueryIterator( EntityManager entityManager, Iterator<EntityRef> source, Query query ) { if ( query.getCollection() == null && query.getConnectionType() == null ) { throw new IllegalArgumentException( "Query must have a collection or connectionType value" ); } this.entityManager = entityManager; this.source = source; this.query = query; }
/** * chained * * @param source the source query we're chaining from * @param query the query - must have a collection or connectType value set */ public PathQuery( PathQuery source, Query query ) { if ( query.getCollection() == null && query.getConnectionType() == null ) { throw new IllegalArgumentException( "Query must have a collection or connectionType value" ); } this.source = source; this.query = query; }
/** * top level * @param head the top-level entity * @param query the query - must have a collection or connectType value set */ public PathQuery(EntityRef head, Query query) { if ( query.getCollection() == null && query.getConnectionType() == null ) { throw new IllegalArgumentException( "Query must have a collection or connectionType value" ); } this.uuid = head.getUuid(); this.type = head.getType(); this.query = query; }
@Override public ServiceResults getServiceMetadata( ServiceContext context, String metadataType ) throws Exception { if ( "indexes".equals( metadataType ) ) { String cType = context.getQuery().getConnectionType(); if ( cType != null ) { Set<String> indexes = cast( em.getConnectionIndexes( context.getOwner(), cType ) ); return new ServiceResults( this, context.getRequest().withPath( context.getRequest().getPath() + "/indexes" ), context.getPreviousResults(), context.getChildPath(), Type.GENERIC, Results.fromData( indexes ), null, null ); } } return null; }
final String connection = query.getConnectionType();
@Override public ServiceResults deleteItemsByQuery( ServiceContext context, Query query ) throws Exception { checkPermissionsForCollection( context ); if ( !query.hasQueryPredicates() && ( query.getEntityType() != null ) && query .containsNameOrEmailIdentifiersOnly() ) { String name = query.getSingleNameOrEmailIdentifier(); String nameProperty = Schema.getDefaultSchema().aliasProperty( query.getEntityType() ); if ( nameProperty == null ) { nameProperty = "name"; } // use unique index repair here before any write logic if there are problems Entity entity = em.getUniqueEntityFromAlias( query.getEntityType(), name, true); if ( entity == null ) { throw new ServiceResourceNotFoundException( context ); } entity = importEntity( context, entity ); deleteConnection( em.connectionRef( context.getOwner(), query.getConnectionType(), entity ) ); return new ServiceResults( null, context, Type.CONNECTION, Results.fromEntity( entity ), null, null ); } return getItemsByQuery( context, query ); }
@Override public ServiceResults postItemsByQuery( ServiceContext context, Query query ) throws Exception { checkPermissionsForCollection( context ); if ( !query.hasQueryPredicates() && ( query.getEntityType() != null ) ) { Entity entity; if ( query.containsSingleNameOrEmailIdentifier() ) { String name = query.getSingleNameOrEmailIdentifier(); // use unique index repair here before any write logic if there are problems entity = em.getUniqueEntityFromAlias( query.getEntityType(), name, true); if ( entity == null ) { throw new ServiceResourceNotFoundException( context ); } } else { entity = em.create( query.getEntityType(), context.getProperties() ); //if entity is null here it throws NPE. Fixing it to throw 404. if ( entity == null ) { throw new ServiceResourceNotFoundException( context ); } } entity = importEntity( context, entity ); createConnection( context.getOwner(), query.getConnectionType(), entity ); return new ServiceResults( null, context, Type.CONNECTION, Results.fromEntity( entity ), null, null ); } return getItemsByQuery( context, query ); }