@Override public EntityRef getAlias( EntityRef ownerRef, String collectionType, String aliasValue ) throws Exception { Assert.notNull( ownerRef, "ownerRef is required" ); Assert.notNull( collectionType, "collectionType is required" ); Assert.notNull( aliasValue, "aliasValue is required" ); if (logger.isTraceEnabled()) { logger.trace("getAlias() for collection type {} alias {}", collectionType, aliasValue); } String collName = Schema.defaultCollectionName( collectionType ); Map<String, EntityRef> results = getAlias( ownerRef, collName, Collections.singletonList( aliasValue ) ); if ( results == null || results.size() == 0 ) { return null; } // add a warn statement so we can see if we have data migration issues. // TODO When we get an event system, trigger a repair if this is detected if ( results.size() > 1 ) { logger.warn( "More than 1 entity with Owner id '{}' of type '{}' and alias '{}' exists. " + "This is a duplicate alias, and needs audited", ownerRef, collectionType, aliasValue ); } return results.get(aliasValue); }
private Map<String, Set<CollectionInfo>> addDynamicApplicationCollectionAsContainer( Map<String, Set<CollectionInfo>> containers, String entityType ) { Map<String, Set<CollectionInfo>> copy = new TreeMap<String, Set<CollectionInfo>>( String.CASE_INSENSITIVE_ORDER ); if ( containers != null ) { copy.putAll( containers ); } containers = copy; if ( !containers.containsKey( Application.ENTITY_TYPE ) ) { MapUtils.addMapSet( containers, true, Application.ENTITY_TYPE, getCollection( Application.ENTITY_TYPE, defaultCollectionName( entityType ) ) ); } return containers; }
private String lookupAuthoritativeRegionForType(String type ) { String region = null; String collectionName = Schema.defaultCollectionName( type ); // get collection settings for type CollectionSettings collectionSettings = collectionSettingsFactory .getInstance( new CollectionSettingsScopeImpl( getAppIdObject(), collectionName) ); Optional<Map<String, Object>> existingSettings = collectionSettings.getCollectionSettings( collectionName ); if ( existingSettings.isPresent() && existingSettings.get().get(AUTHORITATIVE_REGION_SETTING) != null ) { region = existingSettings.get().get(AUTHORITATIVE_REGION_SETTING).toString(); } return region; }
@Override public Map<String, EntityRef> getAlias( String aliasType, List<String> aliases ) throws Exception { String collName = Schema.defaultCollectionName( aliasType ); return getAlias(new SimpleEntityRef(Application.ENTITY_TYPE, applicationId), collName, aliases); }
private boolean skipIndexingForType( String type, ApplicationScope applicationScope ) { boolean skipIndexing = false; String collectionName = Schema.defaultCollectionName( type ); CollectionSettings collectionSettings = collectionSettingsFactory .getInstance( new CollectionSettingsScopeImpl(applicationScope.getApplication(), collectionName)); Optional<Map<String, Object>> collectionIndexingSchema = collectionSettings.getCollectionSettings( collectionName ); if ( collectionIndexingSchema.isPresent()) { Map jsonMapData = collectionIndexingSchema.get(); final ArrayList fields = (ArrayList) jsonMapData.get( "fields" ); if ( fields.size() == 1 && fields.get(0).equals("none")) { skipIndexing = true; } } return skipIndexing; }
private static String getFieldForType(UUID applicationId, CollectionSettingsFactory collectionSettingsFactory, String type, String keyName ) { String collectionName = Schema.defaultCollectionName( type ); CollectionSettings collectionSettings = collectionSettingsFactory .getInstance( new CollectionSettingsScopeImpl(getAppIdObject(applicationId), collectionName) ); Optional<Map<String, Object>> existingSettings = collectionSettings.getCollectionSettings( collectionName ); if ( existingSettings.isPresent()) { Map jsonMapData = existingSettings.get(); Object value = jsonMapData.get(keyName); if ( value != null) { return value.toString(); } } return null; }
private EntityRef getRoleRef( String roleName ) throws Exception { Results results = this.searchCollection( new SimpleEntityRef( Application.ENTITY_TYPE, applicationId ), Schema.defaultCollectionName( Role.ENTITY_TYPE ), Query.fromQL( "roleName = '" + roleName + "'" ) ); Iterator<Entity> iterator = results.iterator(); EntityRef roleRef = null; while ( iterator.hasNext() ) { roleRef = iterator.next(); } return roleRef; }
@Override public EntityRef getGroupRoleRef( UUID groupId, String roleName ) throws Exception { Results results = this.searchCollection( new SimpleEntityRef( Group.ENTITY_TYPE, groupId ), Schema.defaultCollectionName( Role.ENTITY_TYPE ), Query.fromQL( "roleName = '" + roleName + "'" ) ); Iterator<Entity> iterator = results.iterator(); EntityRef roleRef = null; while ( iterator.hasNext() ) { roleRef = iterator.next(); } return roleRef; }
private <A extends Entity> void updateIndexForEntity(String eType, A entity, long timestamp) throws Exception { String collectionName = Schema.defaultCollectionName( eType ); CpRelationManager cpr = ( CpRelationManager ) getRelationManager( getApplication() ); cpr.addToCollection( collectionName, entity ); // Invoke counters incrementEntityCollection( collectionName, timestamp ); }
/** * There are a series of steps that are kicked off by a delete * 1. Mark the entity in the entity collection manager as deleted * 2. Mark entity as deleted in the graph * 3. Kick off async process * 4. Delete all entity documents out of elasticsearch. * 5. Compact Graph so that it deletes the marked values. * 6. Delete entity from cassandra using the map manager. * * @param entityRef an entity reference * * @throws Exception */ @Override public void delete( EntityRef entityRef ) throws Exception { //Step 1 & 2 Currently to block so we ensure that marking is done immediately //If this returns null then nothing was marked null so the entity doesn't exist markEntity( entityRef ).toBlocking().lastOrDefault( null ); //Step 3 deleteAsync( entityRef ); decrementEntityCollection( Schema.defaultCollectionName( entityRef.getType() )); }
@Override public Entity getUniqueEntityFromAlias(String collectionType, String aliasType, boolean uniqueIndexRepair){ String collName = Schema.defaultCollectionName( collectionType ); String propertyName = Schema.getDefaultSchema().aliasProperty( collName );
String edgeTypeName = CpNamingUtils.getEdgeTypeFromCollectionName(Schema.defaultCollectionName(candidateId.getType())); final SearchByEdge searchByEdge = new SimpleSearchByEdge( applicationScope.getApplication(), edgeTypeName, candidateId, Long.MAX_VALUE, SearchByEdgeType.Order.DESCENDING,
@Override public UUID getUniqueIdFromAlias(String collectionType, String aliasType, boolean uniqueIndexRepair){ String collName = Schema.defaultCollectionName( collectionType ); String propertyName = Schema.getDefaultSchema().aliasProperty( collName ); StringField uniqueLookupRepairField = new StringField( propertyName, aliasType);
@Override public Results queryJobData( Query query ) throws Exception { if ( query == null ) { query = new Query(); } String jobDataType = Schema.getDefaultSchema().getEntityType(JobData.class); return getEm().searchCollection( getEm().getApplicationRef(), Schema.defaultCollectionName(jobDataType), query ); }
String collectionName = Schema.defaultCollectionName( entityRef.getType() );
getEntityRefsForUniqueProperty( Schema.defaultCollectionName( "user" ), "email", identifier.getEmail() );
@Override public void call( final Edge edge ) { final String edgeType = edge.getType(); final Id source = edge.getSourceNode(); //test if we're a collection, if so if ( EdgeTestUtils.isCollectionEdgeType( edgeType ) ) { final String collectionName = EdgeTestUtils.getNameForEdge( edgeType ); assertEquals("application source returned", createdApplication.getUuid(), source.getUuid()); final String expectedCollection = Schema.defaultCollectionName( target.getType() ); assertEquals("right type returned", expectedCollection, collectionName); return; } if ( !EdgeTestUtils.isConnectionEdgeType( edgeType ) ) { fail( "Only connection edges should be encountered" ); } final String connectionType = EdgeTestUtils.getNameForEdge( edgeType ); assertEquals( "Same connection type expected", "likes", connectionType ); assertTrue( "Element should be present on removal", sourceIdentities.remove( source ) ); } } ).toBlocking().lastOrDefault( null );