Repository: incubator-usergrid Updated Branches: refs/heads/USERGRID-501 1a61e0eec -> a9eafb875
remove context Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/a9eafb87 Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/a9eafb87 Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/a9eafb87 Branch: refs/heads/USERGRID-501 Commit: a9eafb8757988cb875f4677eaeeb261615ccc95f Parents: 1a61e0e Author: Shawn Feldman <[email protected]> Authored: Tue Mar 24 11:16:36 2015 -0600 Committer: Shawn Feldman <[email protected]> Committed: Tue Mar 24 11:16:36 2015 -0600 ---------------------------------------------------------------------- .../data/DataMigrationManagerImpl.java | 9 +- .../persistence/index/impl/DeIndexRequest.java | 42 ++-- .../index/impl/EntityToMapConverter.java | 169 ++++++++++++++ .../impl/EsApplicationEntityIndexImpl.java | 9 +- .../index/impl/EsEntityIndexBatchImpl.java | 220 +------------------ .../persistence/index/impl/IndexRequest.java | 19 +- 6 files changed, 221 insertions(+), 247 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/a9eafb87/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/migration/data/DataMigrationManagerImpl.java ---------------------------------------------------------------------- diff --git a/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/migration/data/DataMigrationManagerImpl.java b/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/migration/data/DataMigrationManagerImpl.java index ad87724..158315d 100644 --- a/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/migration/data/DataMigrationManagerImpl.java +++ b/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/migration/data/DataMigrationManagerImpl.java @@ -98,13 +98,10 @@ public class DataMigrationManagerImpl implements DataMigrationManager { /** * Invoke each plugin to attempt a migration */ - for(final MigrationPlugin plugin: executionOrder){ + executionOrder.forEach(plugin -> { final ProgressObserver observer = new CassandraProgressObserver(plugin.getName()); - - plugin.run( observer ); - } - - + plugin.run(observer); + }); } http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/a9eafb87/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/DeIndexRequest.java ---------------------------------------------------------------------- diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/DeIndexRequest.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/DeIndexRequest.java index 9f3ce66..98aa8cf 100644 --- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/DeIndexRequest.java +++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/DeIndexRequest.java @@ -21,7 +21,13 @@ package org.apache.usergrid.persistence.index.impl; import java.util.Arrays; +import java.util.UUID; +import org.apache.usergrid.persistence.core.scope.ApplicationScope; +import org.apache.usergrid.persistence.index.IndexScope; +import org.apache.usergrid.persistence.index.SearchType; +import org.apache.usergrid.persistence.index.SearchTypes; +import org.apache.usergrid.persistence.model.entity.Id; import org.elasticsearch.action.bulk.BulkRequestBuilder; import org.elasticsearch.action.delete.DeleteRequestBuilder; import org.elasticsearch.client.Client; @@ -30,6 +36,9 @@ import com.fasterxml.jackson.annotation.JsonSubTypes; import com.fasterxml.jackson.annotation.JsonTypeInfo; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import static org.apache.usergrid.persistence.index.impl.IndexingUtils.createContextName; +import static org.apache.usergrid.persistence.index.impl.IndexingUtils.createIndexDocId; + /** * Represent the properties required to build an index request @@ -37,19 +46,21 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize; @JsonTypeInfo(use=JsonTypeInfo.Id.CLASS, include=JsonTypeInfo.As.PROPERTY, property="@class") public class DeIndexRequest implements BatchRequest { - public String[] indexes; - public String entityType; - public String documentId; + private String[] entityTypes; + private String[] indexes; + private String documentId; - public DeIndexRequest( final String[] indexes, final String entityType, final String documentId) { - this.indexes = indexes; - this.entityType = entityType; - this.documentId = documentId; + public DeIndexRequest( ) { + } - public DeIndexRequest() { + public DeIndexRequest(String[] indexes, ApplicationScope applicationScope, IndexScope indexScope, Id id, UUID version) { + String context = createContextName(applicationScope,indexScope); + this.indexes = indexes; + this.entityTypes = SearchType.fromId(id).getTypeNames(applicationScope); + this.documentId = createIndexDocId(id, version,context); } @@ -58,9 +69,10 @@ public class DeIndexRequest implements BatchRequest { for(final String index: indexes) { - final DeleteRequestBuilder builder = client.prepareDelete( index, entityType, documentId); - - bulkRequest.add( builder ); + for(String entityType : entityTypes) { + final DeleteRequestBuilder builder = client.prepareDelete(index, entityType, documentId); + bulkRequest.add(builder); + } } } @@ -70,8 +82,8 @@ public class DeIndexRequest implements BatchRequest { } - public String getEntityType() { - return entityType; + public String[] getEntityTypes() { + return entityTypes; } @@ -94,7 +106,7 @@ public class DeIndexRequest implements BatchRequest { if ( !documentId.equals( that.documentId ) ) { return false; } - if ( !entityType.equals( that.entityType ) ) { + if ( !entityTypes.equals( that.entityTypes ) ) { return false; } if ( !Arrays.equals( indexes, that.indexes ) ) { @@ -108,7 +120,7 @@ public class DeIndexRequest implements BatchRequest { @Override public int hashCode() { int result = Arrays.hashCode( indexes ); - result = 31 * result + entityType.hashCode(); + result = 31 * result + entityTypes.hashCode(); result = 31 * result + documentId.hashCode(); return result; } http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/a9eafb87/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EntityToMapConverter.java ---------------------------------------------------------------------- diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EntityToMapConverter.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EntityToMapConverter.java new file mode 100644 index 0000000..6e72159 --- /dev/null +++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EntityToMapConverter.java @@ -0,0 +1,169 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.usergrid.persistence.index.impl; + +import org.apache.usergrid.persistence.model.entity.Entity; +import org.apache.usergrid.persistence.model.field.*; +import org.apache.usergrid.persistence.model.field.value.EntityObject; + +import java.util.*; + +import static org.apache.usergrid.persistence.index.impl.IndexingUtils.*; +import static org.apache.usergrid.persistence.index.impl.IndexingUtils.STRING_PREFIX; + +/** + * Classy class class. + */ +public class EntityToMapConverter { + /** + * Set the entity as a map with the context + * + * @param entity The entity + * @param context The context this entity appears in + */ + public static Map convert( final Entity entity, final String context ) { + final Map entityMap = entityToMap( entity ); + + //add the context for filtering later + entityMap.put( ENTITY_CONTEXT_FIELDNAME, context ); + + //but the fieldname we have to prefix because we use query equality to seek this later. + // TODO see if we can make this more declarative + entityMap.put( ENTITYID_ID_FIELDNAME, IndexingUtils.idString(entity.getId()).toLowerCase()); + + return entityMap; + } + + + /** + * Convert Entity to Map and Adding prefixes for types: + * <pre> + * su_ - String unanalyzed field + * sa_ - String analyzed field + * go_ - Location field nu_ - Number field + * bu_ - Boolean field + * </pre> + */ + private static Map entityToMap( EntityObject entity ) { + + Map<String, Object> entityMap = new HashMap<String, Object>(); + + for ( Object f : entity.getFields().toArray() ) { + + Field field = ( Field ) f; + + + if ( f instanceof ArrayField) { + List list = ( List ) field.getValue(); + entityMap.put( field.getName().toLowerCase(), + new ArrayList( processCollectionForMap( list ) ) ); + } + else if ( f instanceof ListField) { + List list = ( List ) field.getValue(); + entityMap.put(field.getName().toLowerCase(), + new ArrayList( processCollectionForMap( list ) ) ); + + if ( !list.isEmpty() ) { + if ( list.get( 0 ) instanceof String ) { + entityMap.put( ANALYZED_STRING_PREFIX + field.getName().toLowerCase(), + new ArrayList( processCollectionForMap( list ) ) ); + } + } + } + else if ( f instanceof SetField) { + Set set = ( Set ) field.getValue(); + entityMap.put( field.getName().toLowerCase(), + new ArrayList( processCollectionForMap( set ) ) ); + } + else if ( f instanceof EntityObjectField) { + EntityObject eo = ( EntityObject ) field.getValue(); + entityMap.put(EO_PREFIX + field.getName().toLowerCase(), entityToMap(eo) ); // recursion + } + else if ( f instanceof StringField ) { + + // index in lower case because Usergrid queries are case insensitive + entityMap.put( ANALYZED_STRING_PREFIX + field.getName().toLowerCase(), + ( ( String ) field.getValue() ).toLowerCase() ); + entityMap.put( STRING_PREFIX + field.getName().toLowerCase(), + ( ( String ) field.getValue() ).toLowerCase() ); + } + else if ( f instanceof LocationField ) { + LocationField locField = ( LocationField ) f; + Map<String, Object> locMap = new HashMap<String, Object>(); + + // field names lat and lon trigger ElasticSearch geo location + locMap.put( "lat", locField.getValue().getLatitude() ); + locMap.put( "lon", locField.getValue().getLongitude() ); + entityMap.put( GEO_PREFIX + field.getName().toLowerCase(), locMap ); + } + else if( f instanceof DoubleField || f instanceof FloatField){ + entityMap.put( DOUBLE_PREFIX + field.getName().toLowerCase(), field.getValue() ); + } + else if( f instanceof LongField || f instanceof IntegerField){ + entityMap.put( LONG_PREFIX + field.getName().toLowerCase(), field.getValue() ); + } + else if ( f instanceof BooleanField ) { + + entityMap.put( BOOLEAN_PREFIX + field.getName().toLowerCase(), field.getValue() ); + } + else if ( f instanceof UUIDField ) { + + entityMap.put( STRING_PREFIX + field.getName().toLowerCase(), + field.getValue().toString().toLowerCase() ); + } + else { + entityMap.put( field.getName().toLowerCase(), field.getValue() ); + } + } + + return entityMap; + } + + + private static Collection processCollectionForMap( final Collection c ) { + if ( c.isEmpty() ) { + return c; + } + List processed = new ArrayList(); + Object sample = c.iterator().next(); + + if ( sample instanceof Entity ) { + for ( Object o : c.toArray() ) { + Entity e = ( Entity ) o; + processed.add( entityToMap( e ) ); + } + } + else if ( sample instanceof List ) { + for ( Object o : c.toArray() ) { + List list = ( List ) o; + processed.add( processCollectionForMap( list ) ); // recursion; + } + } + else if ( sample instanceof Set ) { + for ( Object o : c.toArray() ) { + Set set = ( Set ) o; + processed.add( processCollectionForMap( set ) ); // recursion; + } + } + else { + for ( Object o : c.toArray() ) { + processed.add( o ); + } + } + return processed; + } +} http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/a9eafb87/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsApplicationEntityIndexImpl.java ---------------------------------------------------------------------- diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsApplicationEntityIndexImpl.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsApplicationEntityIndexImpl.java index 2d01697..4c3e42c 100644 --- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsApplicationEntityIndexImpl.java +++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsApplicationEntityIndexImpl.java @@ -148,16 +148,13 @@ public class EsApplicationEntityIndexImpl implements ApplicationEntityIndex{ public CandidateResults search(final IndexScope indexScope, final SearchTypes searchTypes, final Query query ) { - final String context = IndexingUtils.createContextName(applicationScope,indexScope); - final String[] entityTypes = searchTypes.getTypeNames(applicationScope); - QueryBuilder qb = query.createQueryBuilder(context); SearchResponse searchResponse; if ( query.getCursor() == null ) { SearchRequestBuilder srb = esProvider.getClient().prepareSearch( alias.getReadAlias() ) - .setTypes(entityTypes) + .setTypes(searchTypes.getTypeNames(applicationScope)) .setScroll(cursorTimeout + "m") - .setQuery(qb); + .setQuery(query.createQueryBuilder(createContextName(applicationScope, indexScope))); final FilterBuilder fb = query.createFilterBuilder(); @@ -216,7 +213,7 @@ public class EsApplicationEntityIndexImpl implements ApplicationEntityIndex{ if ( logger.isDebugEnabled() ) { logger.debug( "Searching index (read alias): {}\n scope: {} \n type: {}\n query: {} ", - this.alias.getReadAlias(), context, entityTypes, srb ); + this.alias.getReadAlias(), indexScope.getOwner(), searchTypes.getTypeNames(applicationScope), srb ); } try { http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/a9eafb87/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexBatchImpl.java ---------------------------------------------------------------------- diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexBatchImpl.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexBatchImpl.java index 3a6f019..8f8ac5e 100644 --- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexBatchImpl.java +++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexBatchImpl.java @@ -21,11 +21,7 @@ package org.apache.usergrid.persistence.index.impl; import java.util.*; import org.apache.usergrid.persistence.core.future.BetterFuture; -import org.apache.usergrid.persistence.core.metrics.MetricsFactory; import org.apache.usergrid.persistence.index.*; -import org.elasticsearch.action.delete.DeleteRequestBuilder; -import org.elasticsearch.action.index.IndexRequestBuilder; -import org.elasticsearch.client.Client; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -35,28 +31,7 @@ import org.apache.usergrid.persistence.index.query.CandidateResult; import org.apache.usergrid.persistence.index.utils.IndexValidationUtils; import org.apache.usergrid.persistence.model.entity.Entity; import org.apache.usergrid.persistence.model.entity.Id; -import org.apache.usergrid.persistence.model.field.ArrayField; -import org.apache.usergrid.persistence.model.field.BooleanField; -import org.apache.usergrid.persistence.model.field.DoubleField; -import org.apache.usergrid.persistence.model.field.EntityObjectField; -import org.apache.usergrid.persistence.model.field.Field; -import org.apache.usergrid.persistence.model.field.FloatField; -import org.apache.usergrid.persistence.model.field.IntegerField; -import org.apache.usergrid.persistence.model.field.ListField; -import org.apache.usergrid.persistence.model.field.LocationField; -import org.apache.usergrid.persistence.model.field.LongField; -import org.apache.usergrid.persistence.model.field.SetField; -import org.apache.usergrid.persistence.model.field.StringField; -import org.apache.usergrid.persistence.model.field.UUIDField; -import org.apache.usergrid.persistence.model.field.value.EntityObject; - -import com.codahale.metrics.*; -import com.codahale.metrics.Timer; - -import rx.Observable; -import rx.functions.Func1; - -import static org.apache.usergrid.persistence.index.impl.IndexingUtils.*; + public class EsEntityIndexBatchImpl implements EntityIndexBatch { @@ -95,33 +70,7 @@ public class EsEntityIndexBatchImpl implements EntityIndexBatch { ValidationUtils.verifyEntityWrite( entity ); ValidationUtils.verifyVersion( entity.getVersion() ); //add app id for indexing - - final String context = createContextName(applicationScope,indexScope); - - if ( log.isDebugEnabled() ) { - log.debug( "Indexing entity {}:{}\n alias: {}\n" + - " app: {}\n scope owner: {}\n scope name: {}\n context: {}", - entity.getId().getType(), entity.getId().getUuid(), alias.getWriteAlias(), - applicationScope.getApplication(), indexScope.getOwner(), indexScope.getName(), context ); - } - - ValidationUtils.verifyEntityWrite( entity ); - - Map<String, Object> entityAsMap = entityToMap( entity, context ); - //add app id - entityAsMap.put(APPLICATION_ID_FIELDNAME, idString(applicationScope.getApplication())); - // need prefix here because we index UUIDs as strings - - // let caller add these fields if needed - // entityAsMap.put("created", entity.getId().getUuid().timestamp(); - // entityAsMap.put("updated", entity.getVersion().timestamp()); - - String indexId = createIndexDocId( entity, context ); - - log.debug( "Indexing entity documentId {} data {} ", indexId, entityAsMap ); - final SearchType entityType =SearchType.fromId(entity.getId()); - container.addIndexRequest(new IndexRequest(alias.getWriteAlias(), entityType.getTypeName(applicationScope), indexId, entityAsMap)); - + container.addIndexRequest(new IndexRequest(alias.getWriteAlias(), applicationScope,indexScope, entity)); return this; } @@ -133,38 +82,13 @@ public class EsEntityIndexBatchImpl implements EntityIndexBatch { ValidationUtils.verifyIdentity(id); ValidationUtils.verifyVersion( version ); - final String context = createContextName(applicationScope,indexScope); - final SearchType entityType =SearchType.fromId(id); - - final String indexId = createIndexDocId( id, version, context ); - - - if ( log.isDebugEnabled() ) { - log.debug( "De-indexing entity {}:{} in scope\n app {}\n owner {}\n " - + "name {} context{}, type {},", - new Object[] { - id.getType(), - id.getUuid(), - applicationScope.getApplication(), - indexScope.getOwner(), - indexScope.getName(), - context, - entityType - } ); - } - - String[] indexes = entityIndex.getIndexes(AliasedEntityIndex.AliasType.Read); + String[] indexes = entityIndex.getUniqueIndexes(); //get the default index if no alias exists yet if(indexes == null ||indexes.length == 0){ indexes = new String[]{indexIdentifier.getIndex(null)}; } - - String[] typeNames = entityType.getTypeNames(applicationScope); - for(String type : typeNames) { - container.addDeIndexRequest(new DeIndexRequest(indexes, type, indexId)); - } - log.debug("Deindexed Entity with index id " + indexId); + container.addDeIndexRequest(new DeIndexRequest(indexes, applicationScope,indexScope,id,version)); return this; } @@ -205,142 +129,6 @@ public class EsEntityIndexBatchImpl implements EntityIndexBatch { } - /** - * Set the entity as a map with the context - * - * @param entity The entity - * @param context The context this entity appears in - */ - private static Map entityToMap( final Entity entity, final String context ) { - final Map entityMap = entityToMap( entity ); - - //add the context for filtering later - entityMap.put( ENTITY_CONTEXT_FIELDNAME, context ); - - //but the fieldname we have to prefix because we use query equality to seek this later. - // TODO see if we can make this more declarative - entityMap.put( ENTITYID_ID_FIELDNAME, IndexingUtils.idString(entity.getId()).toLowerCase()); - - return entityMap; - } - /** - * Convert Entity to Map and Adding prefixes for types: - * <pre> - * su_ - String unanalyzed field - * sa_ - String analyzed field - * go_ - Location field nu_ - Number field - * bu_ - Boolean field - * </pre> - */ - private static Map entityToMap( EntityObject entity ) { - - Map<String, Object> entityMap = new HashMap<String, Object>(); - - for ( Object f : entity.getFields().toArray() ) { - - Field field = ( Field ) f; - - - if ( f instanceof ArrayField ) { - List list = ( List ) field.getValue(); - entityMap.put( field.getName().toLowerCase(), - new ArrayList( processCollectionForMap( list ) ) ); - } - else if ( f instanceof ListField ) { - List list = ( List ) field.getValue(); - entityMap.put(field.getName().toLowerCase(), - new ArrayList( processCollectionForMap( list ) ) ); - - if ( !list.isEmpty() ) { - if ( list.get( 0 ) instanceof String ) { - entityMap.put( ANALYZED_STRING_PREFIX + field.getName().toLowerCase(), - new ArrayList( processCollectionForMap( list ) ) ); - } - } - } - else if ( f instanceof SetField ) { - Set set = ( Set ) field.getValue(); - entityMap.put( field.getName().toLowerCase(), - new ArrayList( processCollectionForMap( set ) ) ); - } - else if ( f instanceof EntityObjectField ) { - EntityObject eo = ( EntityObject ) field.getValue(); - entityMap.put(EO_PREFIX + field.getName().toLowerCase(), entityToMap(eo) ); // recursion - } - else if ( f instanceof StringField ) { - - // index in lower case because Usergrid queries are case insensitive - entityMap.put( ANALYZED_STRING_PREFIX + field.getName().toLowerCase(), - ( ( String ) field.getValue() ).toLowerCase() ); - entityMap.put( STRING_PREFIX + field.getName().toLowerCase(), - ( ( String ) field.getValue() ).toLowerCase() ); - } - else if ( f instanceof LocationField ) { - LocationField locField = ( LocationField ) f; - Map<String, Object> locMap = new HashMap<String, Object>(); - - // field names lat and lon trigger ElasticSearch geo location - locMap.put( "lat", locField.getValue().getLatitude() ); - locMap.put( "lon", locField.getValue().getLongitude() ); - entityMap.put( GEO_PREFIX + field.getName().toLowerCase(), locMap ); - } - else if( f instanceof DoubleField || f instanceof FloatField){ - entityMap.put( DOUBLE_PREFIX + field.getName().toLowerCase(), field.getValue() ); - } - else if( f instanceof LongField || f instanceof IntegerField){ - entityMap.put( LONG_PREFIX + field.getName().toLowerCase(), field.getValue() ); - } - else if ( f instanceof BooleanField ) { - - entityMap.put( BOOLEAN_PREFIX + field.getName().toLowerCase(), field.getValue() ); - } - else if ( f instanceof UUIDField ) { - - entityMap.put( STRING_PREFIX + field.getName().toLowerCase(), - field.getValue().toString().toLowerCase() ); - } - else { - entityMap.put( field.getName().toLowerCase(), field.getValue() ); - } - } - - return entityMap; - } - - - private static Collection processCollectionForMap( final Collection c ) { - if ( c.isEmpty() ) { - return c; - } - List processed = new ArrayList(); - Object sample = c.iterator().next(); - - if ( sample instanceof Entity ) { - for ( Object o : c.toArray() ) { - Entity e = ( Entity ) o; - processed.add( entityToMap( e ) ); - } - } - else if ( sample instanceof List ) { - for ( Object o : c.toArray() ) { - List list = ( List ) o; - processed.add( processCollectionForMap( list ) ); // recursion; - } - } - else if ( sample instanceof Set ) { - for ( Object o : c.toArray() ) { - Set set = ( Set ) o; - processed.add( processCollectionForMap( set ) ); // recursion; - } - } - else { - for ( Object o : c.toArray() ) { - processed.add( o ); - } - } - return processed; - } - } http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/a9eafb87/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/IndexRequest.java ---------------------------------------------------------------------- diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/IndexRequest.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/IndexRequest.java index 4ec4092..23f3d08 100644 --- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/IndexRequest.java +++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/IndexRequest.java @@ -22,12 +22,20 @@ package org.apache.usergrid.persistence.index.impl; import java.util.Map; +import org.apache.usergrid.persistence.core.scope.ApplicationScope; +import org.apache.usergrid.persistence.index.IndexScope; +import org.apache.usergrid.persistence.index.SearchType; +import org.apache.usergrid.persistence.model.entity.Entity; import org.elasticsearch.action.bulk.BulkRequestBuilder; import org.elasticsearch.action.index.IndexRequestBuilder; import org.elasticsearch.client.Client; import com.fasterxml.jackson.annotation.JsonTypeInfo; +import static org.apache.usergrid.persistence.index.impl.IndexingUtils.APPLICATION_ID_FIELDNAME; +import static org.apache.usergrid.persistence.index.impl.IndexingUtils.createContextName; +import static org.apache.usergrid.persistence.index.impl.IndexingUtils.idString; + /** * Represent the properties required to build an index request @@ -42,11 +50,14 @@ public class IndexRequest implements BatchRequest { public Map<String, Object> data; - public IndexRequest( final String writeAlias, final String entityType, final String documentId, - final Map<String, Object> data ) { + public IndexRequest( final String writeAlias, final ApplicationScope applicationScope, IndexScope indexScope, Entity entity) { + String context = createContextName(applicationScope,indexScope); + SearchType searchType = SearchType.fromId(entity.getId()); + final Map<String, Object> data = EntityToMapConverter.convert(entity,context); + data.put(APPLICATION_ID_FIELDNAME, idString(applicationScope.getApplication())); this.writeAlias = writeAlias; - this.entityType = entityType; - this.documentId = documentId; + this.entityType = searchType.getTypeName(applicationScope); + this.documentId = IndexingUtils.createIndexDocId(entity,context); this.data = data; }
