public static SimpleRoleRef forRoleEntity( Entity role ) { if ( role == null ) { return null; } UUID groupId = ( UUID ) role.getProperty( "group" ); String name = role.getName(); return new SimpleRoleRef( groupId, name ); }
@Test public void testNestedRetrieveNameWithSpace() throws Exception { Entity contributor = app.doCreate( "contributor", "Malaka Mahanama" ); app.testRequest( ServiceAction.GET, 1, "contributors" ); app.testRequest( ServiceAction.GET, 1, "contributor", contributor.getName()); Entity project = app.doCreate( "project", "Usergrid" ); app.testRequest( ServiceAction.GET, 1, "projects" ); app.testRequest( ServiceAction.POST, 1, "projects", project.getName(), "contains", "contributors", contributor.getName()); app.testRequest( ServiceAction.GET, 1, "projects", project.getName(), "contains", "contributors", contributor.getName()); }
@Test public void testNestedRetrieveNameWithoutSpace() throws Exception { Entity contributor = app.doCreate( "contributor", "Malaka" ); app.testRequest( ServiceAction.GET, 1, "contributors" ); app.testRequest( ServiceAction.GET, 1, "contributor", contributor.getName()); Entity project = app.doCreate( "project", "Usergrid" ); app.testRequest( ServiceAction.GET, 1, "projects" ); app.testRequest( ServiceAction.POST, 1, "projects", project.getName(), "contains", "contributors", contributor.getName()); app.testRequest( ServiceAction.GET, 1, "projects", project.getName(), "contains", "contributors", contributor.getName()); }
@Override public ApplicationInfo getApplicationInfo( UUID applicationId ) throws Exception { if ( applicationId == null ) { return null; } EntityManager em = emf.getEntityManager( smf.getManagementAppId() ); Entity entity = em.get(new SimpleEntityRef(CpNamingUtils.APPLICATION_INFO, applicationId)); if ( entity != null ) { return new ApplicationInfo( applicationId, entity.getName() ); } return null; }
@Override public ApplicationInfo getDeletedApplicationInfo(UUID applicationId) throws Exception { if ( applicationId == null ) { return null; } EntityManager em = emf.getEntityManager( smf.getManagementAppId() ); final Entity entity = em.get( new SimpleEntityRef( CpNamingUtils.DELETED_APPLICATION_INFO, applicationId ) ); if ( entity != null ) { return new ApplicationInfo( applicationId, entity.getName() ); } return null; }
private void checkApplicationsBroken( List<Entity> deletedApps ) throws Exception { if (logger.isDebugEnabled()) { logger.debug("\n\nChecking applications broken\n"); } for ( Entity applicationInfo : deletedApps ) { String appName = applicationInfo.getName(); boolean isPresent = setup.getEmf().lookupApplication( appName ) != null; // missing application_info does not completely break applications, but we... assertFalse("Should not be able to lookup deleted application by name" + appName, isPresent); } }
@Override public BiMap<UUID, String> getApplicationsForOrganization( UUID organizationGroupId ) throws Exception { if ( organizationGroupId == null ) { return null; } final BiMap<UUID, String> applications = HashBiMap.create(); final EntityManager em = emf.getEntityManager(smf.getManagementAppId()); // query for application_info entities final Results results = em.getTargetEntities( new SimpleEntityRef(Group.ENTITY_TYPE, organizationGroupId), ORG_APP_RELATIONSHIP, CpNamingUtils.APPLICATION_INFO, Level.ALL_PROPERTIES); final PagingResultsIterator itr = new PagingResultsIterator( results ); String entityName; while ( itr.hasNext() ) { final Entity entity = ( Entity ) itr.next(); entityName = entity.getName(); if ( entityName != null ) { entityName = entityName.toLowerCase(); } // make sure we return applicationId and not the application_info UUID UUID applicationId = entity.getUuid(); applications.put( applicationId, entityName ); } return applications; }
final String name = results.getEntities().get( i ).getName();
@Test public void testRetrieveNameWithSpace() throws Exception { Entity contributor = app.doCreate( "contributor", "Malaka Mahanama" ); app.testRequest( ServiceAction.GET, 1, "contributors" ); app.testRequest( ServiceAction.GET, 1, "contributor", contributor.getName()); }
@Test public void testRetrieveNameWithoutSpace() throws Exception { Entity contributor = app.doCreate( "contributor", "Malaka" ); app.testRequest( ServiceAction.GET, 1, "contributors" ); app.testRequest( ServiceAction.GET, 1, "contributor", contributor.getName()); }
assertEquals( String.valueOf( count ), results.getEntities().get( i ).getName() ); count++;
assertEquals( String.valueOf( size - count -1 ), results.getEntities().get( i ).getName() ); count++;
public UserInfo getUserInfo( UUID applicationId, Entity entity ) { if ( entity == null ) { return null; } return new UserInfo( applicationId, entity.getUuid(), ( String ) entity.getProperty( "username" ), entity.getName(), ( String ) entity.getProperty( "email" ), ConversionUtils.getBoolean( entity.getProperty( "confirmed" ) ), ConversionUtils.getBoolean( entity.getProperty( "activated" ) ), ConversionUtils.getBoolean( entity.getProperty( "disabled" ) ), entity.getDynamicProperties(), ConversionUtils.getBoolean( entity.getProperty( "admin" ))); }
@Override public ServiceResults deleteItemById( ServiceContext context, UUID id ) throws Exception { User user = em.get( context.getOwner(), User.class ); ServiceResults results = getItemById( context, id ); if ( !results.isEmpty() ) { em.removeUserFromRole( user.getUuid(), results.getEntity().getName() ); ScopedCache scopedCache = cacheFactory.getScopedCache(new CacheScope(em.getApplication().asId())); scopedCache.invalidate(); localShiroCache.invalidateAll(); } return results; }
@Override public ServiceResults deleteItemByName( ServiceContext context, String name ) throws Exception { User user = em.get( context.getOwner(), User.class ); ServiceResults results = getItemByName( context, name ); if ( !results.isEmpty() ) { em.removeUserFromRole( user.getUuid(), results.getEntity().getName() ); ScopedCache scopedCache = cacheFactory.getScopedCache(new CacheScope(em.getApplication().asId())); scopedCache.invalidate(); localShiroCache.invalidateAll(); } return results; } }
@Override public ServiceResults postItemById( ServiceContext context, UUID id ) throws Exception { User user = em.get( context.getOwner(), User.class ); Entity entity = sm.getService( "/roles" ).getEntity( context.getRequest(), id ); if ( entity != null ) { em.addUserToRole( user.getUuid(), entity.getName() ); ScopedCache scopedCache = cacheFactory.getScopedCache(new CacheScope(em.getApplication().asId())); scopedCache.invalidate(); localShiroCache.invalidateAll(); } return new ServiceResults( this, context, Type.COLLECTION, Results.fromRef( entity ), null, null ); }
@Override public ServiceResults postItemByName( ServiceContext context, String name ) throws Exception { User user = em.get( context.getOwner(), User.class ); Entity entity = sm.getService( "/roles" ).getEntity( context.getRequest(), name ); if ( entity != null ) { em.addUserToRole( user.getUuid(), entity.getName() ); ScopedCache scopedCache = cacheFactory.getScopedCache(new CacheScope(em.getApplication().asId())); scopedCache.invalidate(); localShiroCache.invalidateAll(); } return new ServiceResults( this, context, Type.COLLECTION, Results.fromRef( entity ), null, null ); }
assertNotNull( returnedDevice ); assertEquals( "device1", returnedDevice.getName() );
@Test public void testGetByIdAndNameEdgeReadRepair() throws Exception { EntityManager em = setup.getEmf().getEntityManager( app.getId() ); Entity contributor = app.doCreate( "contributor", "Malaka" ); EntityRef appRef = new SimpleEntityRef("application", app.getId()); em.removeItemFromCollection(appRef, InflectionUtils.pluralize(contributor.getType()), contributor); assertFalse("Entity should not have an edge from app to entity", em.isCollectionMember(appRef, InflectionUtils.pluralize(contributor.getType()), contributor)); app.testRequest( ServiceAction.GET, 1, "contributor", contributor.getName()); assertTrue("Entity should now be member of the collection", em.isCollectionMember(appRef, InflectionUtils.pluralize(contributor.getType()), contributor)); } }
@Test public void testSizeReturnedInMetadata() throws Exception { app.put( "name", "Tom" ); Entity cat = app.testRequest( ServiceAction.POST, 1, "cats" ).getEntity(); assertNotNull( cat ); Entity getEntityByName = app.testRequest( ServiceAction.GET, 1, "cats", cat.getName() ).getEntity(); Entity getEntityByUUID = app.testRequest( ServiceAction.GET, 1, "cats", cat.getUuid() ).getEntity(); assertNotNull(getEntityByName.getSize()); assertNotNull(getEntityByUUID.getSize()); app.clear(); }