public EntityManager getEm() { if ( em == null ) { this.em = emf.getEntityManager( emf.getManagementAppId() ); } return em; }
@Override public UUID createApplication( String organizationName, String applicationName ) throws Exception { Entity appInfo = emf.createApplicationV2(organizationName, applicationName); UUID applicationId = appInfo.getUuid(); return applicationId; }
@Override public ApplicationInfo getApplicationInfo( String applicationName ) throws Exception { if ( applicationName == null ) { return null; } UUID applicationId = emf.lookupApplication(applicationName); if ( applicationId == null ) { return null; } return new ApplicationInfo( applicationId, applicationName.toLowerCase() ); }
@Override public void initMgmtApp() throws Exception { try { emf.initializeApplicationV2( DEFAULT_ORGANIZATION, emf.getManagementAppId(), MANAGEMENT_APPLICATION, null, false); } catch ( ApplicationAlreadyExistsException ex ) { logger.warn( "Application {}/{} already exists", DEFAULT_ORGANIZATION, MANAGEMENT_APPLICATION ); } catch ( OrganizationAlreadyExistsException oaee ) { logger.warn( "Organization {} already exists", DEFAULT_ORGANIZATION ); } }
@Override public void setAppUserCredentialsInfo( final UUID applicationId, final UUID userId, final CredentialsInfo credentialsInfo ) throws Exception { Preconditions.checkNotNull( applicationId, "applicationId is required" ); Preconditions.checkNotNull( userId, "userId is required" ); Preconditions.checkNotNull( credentialsInfo, "credentialsInfo is required" ); final User user = emf.getEntityManager( applicationId ).get(userId, User.class); if(user == null){ throw new EntityNotFoundException( "User with id " + userId + " cannot be found" ); } writeUserPassword(applicationId, user, credentialsInfo); }
setup.getEmf().createApplicationV2( "testCounterOrg", "testEntityCounters" + UUIDGenerator.newTimeUUID() ); UUID applicationId = appInfo.getUuid(); new SimpleEntityRef( CpNamingUtils.APPLICATION_INFO, applicationId ) ); em = setup.getEmf().getEntityManager( applicationId ); properties = new LinkedHashMap<String, Object>(); properties.put( "username", "edanuff" ); Entity user = em.create( "user", properties ); em = setup.getEmf().getEntityManager( setup.getEmf().getManagementAppId() ); Map<String, Long> counts = em.getEntityCounters( setup.getEmf().getManagementAppId() ); logger.info( "Entity counters: {}", counts ); assertNotNull( counts ); assertEquals( "testCounterOrg", entity.getName() ); em = setup.getEmf().getEntityManager( applicationId ); counts = em.getEntityCounters( applicationId ); logger.info( "Entity counters: {}", counts );
EntityManager em = setup.getEmf().getEntityManager(deletedAppId); if ( setup.getEmf().lookupApplication( orgName + "/" + appName ) != null ) { break; Map<String,UUID> apps = setup.getEmf().getApplications(); boolean found = findApps.call(deletedAppId, apps); assertTrue("Restored app not found in apps collection", found); setup.getEmf().deleteApplication(deletedAppId); found = findApps.call( deletedAppId, emf.getDeletedApplications() ); found = setup.getEmf().lookupApplication( orgName + "/" + appName ) != null; found = findApps.call( deletedAppId, emf.getApplications()); assertFalse("Deleted app must not be found in apps collection", found); emf.restoreApplication(deletedAppId); final ReIndexRequestBuilder builder = reIndexService.getBuilder().withApplicationId( deletedAppId ); found = findApps.call( deletedAppId, emf.getDeletedApplications()); assertFalse("Restored app found in deleted apps collection", found); this.app.waitForQueueDrainAndRefreshIndex(); apps = setup.getEmf().getApplications(); found = findApps.call(deletedAppId, apps); assertTrue(setup.getEmf().lookupApplication( orgName + "/" + appName ) != null );
Entity appInfo = setup.getEmf().createApplicationV2(orgName, appName); UUID applicationId = appInfo.getUuid(); EntityManager em = setup.getEmf().getEntityManager( applicationId );
if ( emf.lookupApplication( app.getName() ) != null ) { throw new ConflictException("Cannot restore application, one with that name already exists."); EntityManager em = emf.getEntityManager( emf.getManagementAppId() ); Entity appInfo = emf.restoreApplication(applicationId);
appIds.add( appId ); EntityManager em = setup.getEmf().getEntityManager( appId ); for ( int j=0; j<10; j++ ) { final String entityName = "thing" + j; UUID mgmtAppId = setup.getEmf().getManagementAppId(); setup.refreshIndex(mgmtAppId); EntityManager rootEm = setup.getEmf().getEntityManager( mgmtAppId ); setup.getEmf().initializeApplicationV2( CassandraService.DEFAULT_ORGANIZATION, AppInfoMigrationPlugin.SYSTEM_APP_ID, "systemapp", null, false); EntityManager systemAppEm = setup.getEmf().getEntityManager( AppInfoMigrationPlugin.SYSTEM_APP_ID ); setup.getEmf().flushEntityManagerCaches();
public UUID getManagementAppId() { return emf.getManagementAppId(); }
private void checkApplicationsOk( String orgName) throws Exception { if (logger.isDebugEnabled()) { logger.debug("\n\nChecking applications OK\n"); } for (int i=0; i<10; i++) { String appName = orgName + "/application" + i; UUID uuid = setup.getEmf().lookupApplication(appName); assertTrue ("Should be able to get application", uuid != null ); EntityManager em = setup.getEmf().getEntityManager( uuid ); Application app = em.getApplication(); assertEquals( appName, app.getName() ); Results results = em.searchCollection( em.getApplicationRef(), "things", Query.fromQL("select *")); assertEquals( "Should have 10 entities", 10, results.size() ); } }
private Entity getApplicationInfo( UUID appId ) throws Exception { Map<String, UUID> apps = setup.getEmf().getApplications(); if(apps.containsValue(appId)){ return setup.getEmf().getManagementEntityManager().get(appId); }else{ fail("no app " + appId); return null; } } }
@Override public void deleteApplication(UUID applicationId) throws Exception { emf.deleteApplication( applicationId ); }
private void migrateAppInfo( org.apache.usergrid.persistence.model.entity.Entity oldAppInfoEntity, ProgressObserver observer ) { final EntityManager managementEm = emf.getManagementEntityManager();
@Override public boolean newAppUsersNeedAdminApproval( UUID applicationId ) throws Exception { EntityManager em = emf.getEntityManager(applicationId); Boolean registration_requires_admin_approval = ( Boolean ) em .getProperty( new SimpleEntityRef( Application.ENTITY_TYPE, applicationId ), REGISTRATION_REQUIRES_ADMIN_APPROVAL ); return registration_requires_admin_approval != null && registration_requires_admin_approval; }
@Test public void testCommunityCounters() throws Exception { EntityManager em = setup.getEmf().getEntityManager( setup.getEmf().getManagementAppId() ); organizationEntity = em.create( organizationEntity ); Entity appInfo = setup.getEmf().createApplicationV2( orgName, appName ); UUID applicationId = appInfo.getUuid();
@Test public void authenticateUser() throws Exception { String username = uniqueUsername(); String password = "test"; String orgName = uniqueOrg(); String appName = uniqueApp(); Entity appInfo = setup.getEmf().createApplicationV2( orgName, appName ); UUID appId = appInfo.getUuid(); User user = new User(); user.setActivated( true ); user.setUsername( username ); EntityManager em = setup.getEmf().getEntityManager( appId ); User storedUser = em.create( user ); setup.getEntityIndex().refresh(applicationId); UUID userId = storedUser.getUuid(); //set the password setup.getMgmtSvc().setAppUserPassword( appId, userId, password ); //verify authorization works User authedUser = setup.getMgmtSvc().verifyAppUserPasswordCredentials( appId, username, password ); assertEquals( userId, authedUser.getUuid() ); //test we can change the password String newPassword = "test2"; setup.getMgmtSvc().setAppUserPassword( appId, userId, password, newPassword ); setup.getEntityIndex().refresh(applicationId); //verify authorization works authedUser = setup.getMgmtSvc().verifyAppUserPasswordCredentials( appId, username, newPassword ); }
public QueueManager getQm() { if ( qm == null ) { this.qm = qmf.getQueueManager( emf.getManagementAppId()); } return qm; }
/** * Query Entity Manager for the error message generated for an import job. */ @Override public String getErrorMessage(final UUID uuid) throws Exception { //get application entity manager if (uuid == null) { logger.error("getErrorMessage(): UUID passed in cannot be null."); return "UUID passed in cannot be null"; } EntityManager rootEm = emf.getEntityManager(emf.getManagementAppId()); //retrieve the import entity. Import importUG = rootEm.get(uuid, Import.class); if (importUG == null) { logger.error("getErrorMessage(): no entity with that uuid was found"); return "No Such Element found"; } return importUG.getErrorMessage(); }