@Override public void addToCollection( Entity user, String collection, Entity item ) throws Exception { em.addToCollection( user, collection, item ); }
public void distribute( EntityRef group, Entity activity ) throws Exception { if ( activity == null ) { return; } em.addToCollection( group, "feed", activity ); Results r = em.getCollection( group, "users", null, 10000, Level.REFS, false ); List<EntityRef> refs = r.getRefs(); if ( refs != null ) { em.addToCollections( refs, "feed", activity ); } } }
@Override public void addAdminUserToOrganization( UserInfo user, OrganizationInfo organization, boolean email ) throws Exception { if ( ( user == null ) || ( organization == null ) ) { return; } EntityManager em = emf.getEntityManager( smf.getManagementAppId() ); EntityRef orgRef = new SimpleEntityRef( Group.ENTITY_TYPE, organization.getUuid() ); EntityRef userRef = new SimpleEntityRef( User.ENTITY_TYPE, user.getUuid() ); if(em.isCollectionMember(orgRef, Schema.COLLECTION_USERS, userRef)) { if(logger.isDebugEnabled()) { logger.debug( "addAdminUserToOrganization - Found value: {} already in collection", user.getName() ); } return; } em.addToCollection(orgRef, Schema.COLLECTION_USERS, userRef); invalidateManagementAppAuthCache(); if ( email ) { sendAdminUserInvitedEmail(user, organization); } }
em.addToCollection( user, "feed", activity );
@Override public ServiceResults putItemByName( ServiceContext context, String name ) throws Exception { if ( context.moreParameters() ) { return getItemByName( context, name ); } // use unique index repair here before any write logic if there are problems Entity entity = em.getUniqueEntityFromAlias( getEntityType(), name, true); if ( entity == null ) { // null entity ref means we tried to put a non-existing entity // before we create a new entity for it, we should check for permission checkPermissionsForCollection(context); Map<String, Object> properties = context.getPayload().getProperties(); if ( !properties.containsKey( "name" ) || !( ( String ) properties.get( "name" ) ).trim().equalsIgnoreCase( name ) ) { properties.put( "name", name ); } entity = em.create( getEntityType(), properties ); } else { entity = importEntity( context, entity ); checkPermissionsForEntity( context, entity ); if( context.getOwner().getType().equals(TYPE_APPLICATION)) { // this will repair any missing edges em.addToCollection(context.getOwner(), context.getCollectionName(), entity); } updateEntity( context, entity ); } return new ServiceResults( this, context, Type.COLLECTION, Results.fromEntity( entity ), null, null ); }
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 ); } } }
properties.put( "content", "I ate a sammich" ); em.addToCollection( user, "activities", em.create( "activity", properties ) ); properties.put( "content", "I wrote a blog post" ); em.addToCollection(user, "activities", em.create("activity", properties)); properties.put( "content", "I ate another sammich" ); em.addToCollection(user, "activities", em.create("activity", properties)); properties.put( "content", "I wrote another blog post" ); em.addToCollection( user, "activities", em.create( "activity", properties ) );
@Test public void testFilteringOfDuplicateEdges() throws Exception { logger.info( "EntityManagerIT.testFilteringOfDuplicateEdges" ); EntityManager em = app.getEntityManager(); Map<String, Object> properties = new LinkedHashMap<String, Object>(); properties.put( "name", "fluffy1" ); Entity entity = em.create( "fluffy", properties ); EntityRef appRef = new SimpleEntityRef("application", app.getId()); EntityRef entityRef = new SimpleEntityRef(entity.getType(), entity.getUuid()); assertNotNull( entity ); // create duplicate edges em.addToCollection(appRef, "fluffies", entityRef); em.addToCollection(appRef, "fluffies", entityRef); //app.waitForQueueDrainAndRefreshIndex(); Results results = em.getCollection(appRef, "fluffies", null, 10, Level.ALL_PROPERTIES, true); // we should be filtering duplicate edges so only assert 1 result back and not the # of edges assertEquals(1, results.getEntities().size()); }
em.addToCollection( organizationEntity, "users", new SimpleEntityRef( User.ENTITY_TYPE, user.getUuid() ) );
assertNotNull(group); em.addToCollection( group, "users", user1 ); em.addToCollection( group, "users", user2 );
"collection {}", id, context.getOwner(), context.getCollectionName()); em.addToCollection( context.getOwner(), context.getCollectionName(), entity);
@Override public ServiceResults postItemById( ServiceContext context, UUID id ) throws Exception { if ( context.moreParameters() ) { return getItemById( context, id, true ); } checkPermissionsForEntity( context, id ); Entity entity = em.get( new SimpleEntityRef( this.getEntityType(), id) ); if ( entity == null ) { throw new ServiceResourceNotFoundException( context ); } validateEntityType( entity, id ); entity = importEntity( context, entity ); em.addToCollection( context.getOwner(), context.getCollectionName(), entity ); return new ServiceResults( null, context, Type.COLLECTION, Results.fromEntity( entity ), null, null ); }
@Override public ServiceResults putItemById( ServiceContext context, UUID id ) throws Exception { if ( context.moreParameters() ) { return getItemById( context, id, true ); } checkPermissionsForEntity( context, id ); Entity item = em.get( id ); if ( item != null ) { validateEntityType( item, id ); if( context.getOwner().getType().equals(TYPE_APPLICATION)) { // this will repair any missing edges em.addToCollection(context.getOwner(), context.getCollectionName(), item); } updateEntity( context, item, context.getPayload() ); item = importEntity( context, item ); } else { String entityType = getEntityType(); item = em.create( id, entityType, context.getPayload().getProperties() ); } return new ServiceResults( this, context, Type.COLLECTION, Results.fromEntity( item ), null, null ); }
properties.put( "username", group.getProperty( "path" ) + " user " + i ); Entity created = em.create( "user", properties ); em.addToCollection( group, "users", created ); users.add( created ); Entity created = em.create( "device", properties ); devices.add( created ); em.addToCollection( user, "devices", created );
Entity created = em.create( "device", properties ); deviceRefs.add( created ); em.addToCollection( user, "devices", created );
@Override public void copyRelationships( String srcRelationName, EntityRef dstEntityRef, String dstRelationName ) throws Exception { headEntity = em.validate( headEntity ); dstEntityRef = em.validate( dstEntityRef ); CollectionInfo srcCollection = getDefaultSchema().getCollection( headEntity.getType(), srcRelationName ); CollectionInfo dstCollection = getDefaultSchema().getCollection( dstEntityRef.getType(), dstRelationName ); Results results = null; do { if ( srcCollection != null ) { results = em.getCollection( headEntity, srcRelationName, null, 5000, Level.REFS, false ); } else { results = em.getTargetEntities( headEntity, srcRelationName, null, Level.REFS ); } if ( ( results != null ) && ( results.size() > 0 ) ) { List<EntityRef> refs = results.getRefs(); for ( EntityRef ref : refs ) { if ( dstCollection != null ) { em.addToCollection( dstEntityRef, dstRelationName, ref ); } else { em.createConnection( dstEntityRef, dstRelationName, ref ); } } } } while ( ( results != null ) && ( results.hasMoreResults() ) ); }
assertNotNull( user ); em.addToCollection( group, "users", user );