public UUID getManagementAppId() { return emf.getManagementAppId(); }
public QueueManager getQm() { if ( qm == null ) { this.qm = qmf.getQueueManager( emf.getManagementAppId()); } return qm; }
public EntityManager getEm() { if ( em == null ) { this.em = emf.getEntityManager( emf.getManagementAppId() ); } return em; }
@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 ); } }
/** * 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(); }
@Override public Import getImport(final UUID applicationId, final UUID importId) { Preconditions.checkNotNull(applicationId, "applicationId must be specified"); Preconditions.checkNotNull(importId, "importId must be specified"); try { final EntityManager rootEm = emf.getEntityManager(emf.getManagementAppId()); final Entity appInfo = getApplicationInfoEntity(rootEm, applicationId); final Import importEntity = rootEm.get(importId, Import.class); // check if it's on the path if (!rootEm.isConnectionMember(appInfo, APP_IMPORT_CONNECTION, importEntity)) { return null; } return importEntity; } catch (Exception e) { throw new RuntimeException("Unable to get import entity", e); } }
/** * Query Entity Manager for the state of the Import Entity. This corresponds to the GET /import */ @Override public Import.State getState(UUID uuid) throws Exception { Preconditions.checkNotNull(uuid, "uuid cannot be null"); EntityManager rootEm = emf.getEntityManager(emf.getManagementAppId()); //retrieve the import entity. Import importUG = rootEm.get(uuid, Import.class); if (importUG == null) { throw new EntityNotFoundException("Could not find entity with uuid " + uuid); } return importUG.getState(); }
/** * Returns the Import Entity that stores all meta-data for the particular import Job * * @param jobExecution the import job details * @return Import Entity */ @Override public Import getImportEntity(final JobExecution jobExecution) throws Exception { UUID importId = (UUID) jobExecution.getJobData().getProperty(IMPORT_ID); EntityManager importManager = emf.getEntityManager(emf.getManagementAppId()); return importManager.get(importId, Import.class); }
@Override public Results getImports(final UUID applicationId, @Nullable final String ql, @Nullable final String cursor) { Preconditions.checkNotNull(applicationId, "applicationId must be specified"); try { final EntityManager rootEm = emf.getEntityManager(emf.getManagementAppId()); final Entity appInfo = getApplicationInfoEntity(rootEm, applicationId); Query query = Query.fromQLNullSafe(ql); query.setCursor(cursor); //set our entity type query.setEntityType(Schema.getDefaultSchema().getEntityType(Import.class)); return rootEm.searchCollection(appInfo, APP_IMPORT_CONNECTION, query); } catch (Exception e) { throw new RuntimeException("Unable to get import entity", e); } }
/** * Returns the File Import Entity that stores all meta-data for the particular sub File import Job * * @return File Import Entity */ @Override public FileImport getFileImportEntity(final JobExecution jobExecution) throws Exception { UUID fileImportId = (UUID) jobExecution.getJobData().getProperty(FILE_IMPORT_ID); EntityManager em = emf.getEntityManager(emf.getManagementAppId()); return em.get(fileImportId, FileImport.class); }
public Export getExportEntity( final JobExecution jobExecution ) throws Exception { UUID exportId = ( UUID ) jobExecution.getJobData().getProperty( EXPORT_ID ); EntityManager exportManager = emf.getEntityManager( emf.getManagementAppId() ); return exportManager.get( exportId, Export.class ); }
/** * This method is called when the job is retried maximum times by the * scheduler but still fails. Thus the scheduler marks it as DEAD. */ @Override public void dead( final JobExecution execution ) throws Exception { // marks the job as failed as it will not be retried by the scheduler. EntityManager rootEm = emf.getEntityManager( emf.getManagementAppId()); Import importUG = importService.getImportEntity(execution); importUG.setErrorMessage("The Job has been tried maximum times but still failed"); importUG.setState(Import.State.FAILED); rootEm.update(importUG); } }
/** * Invoked when a connection cannot be written */ public void connectionFailed( final String message ) { connectionsFailed.incrementAndGet(); FailedImportConnection failedImportConnection = new FailedImportConnection(); failedImportConnection.setErrorMessage( message ); try { EntityManager entityManager = emf.getEntityManager(emf.getManagementAppId()); failedImportConnection = entityManager.create( failedImportConnection ); entityManager.createConnection( fileImport, ERRORS_CONNECTION_NAME, failedImportConnection ); } catch ( Exception e ) { throw new PersistenceException( "Unable to save failed entity import message", e ); } maybeFlush(); }
@Override public JobStat getStatsForJob( String jobName, UUID jobId ) throws Exception { EntityManager em = emf.getEntityManager( emf.getManagementAppId() ); Query query = Query.fromQL( "select * where " + JOB_NAME + " = '" + jobName + "' AND " + JOB_ID + " = " + jobId ); Results r = em.searchCollection( em.getApplicationRef(), "job_stats", query ); if ( r.size() == 1 ) { return ( JobStat ) r.getEntity(); } return null; }
/** * Invoke when an entity fails to write correctly */ public void entityFailed( final String message ) { entitiesFailed.incrementAndGet(); FailedImportEntity failedImportEntity = new FailedImportEntity(); failedImportEntity.setErrorMessage( message ); try { EntityManager entityManager = emf.getEntityManager(emf.getManagementAppId()); failedImportEntity = entityManager.create( failedImportEntity ); entityManager.createConnection( fileImport, ERRORS_CONNECTION_NAME, failedImportEntity ); } catch ( Exception e ) { throw new PersistenceException( "Unable to save failed entity import message", e ); } maybeFlush(); }
@Test public void testGetTokenForPrincipalUser() throws Exception { // create a user Map<String, Object> properties = new LinkedHashMap<String, Object>(); properties.put( "username", "edanuff" ); properties.put( "email", "ed@anuff.com" ); Entity user = setup.getEmf().getEntityManager( applicationId ).create( "user", properties ); assertNotNull( user ); String token = ( ( ManagementServiceImpl ) setup.getMgmtSvc() ) .getTokenForPrincipal( TokenCategory.ACCESS, null, setup.getEmf().getManagementAppId(), AuthPrincipalType.APPLICATION_USER, user.getUuid(), 0 ); assertNotNull( token ); }
when( emf.getEntityManager( emf.getManagementAppId() ) ).thenReturn( em );
private User createUser() throws Exception { String rando = RandomStringUtils.randomAlphanumeric( 10 ); String username = "user_" + rando; String email = username + "@example.com"; Map<String, Object> properties = new HashMap<String, Object>() {{ put( "username", username ); put( "email", email ); }}; EntityManager em = setup.getEmf().getEntityManager( setup.getEmf().getManagementAppId() ); Entity entity = em.create( "user", properties ); return em.get( new SimpleEntityRef( User.ENTITY_TYPE, entity.getUuid() ), User.class ); }
@Test public void testCreateSampleApplicationAltName() throws Exception { final String orgName = uniqueOrg(); final String appName = uniqueApp(); final String sampleAppName = "messagee" ; final String expectedName = orgName + "/" + sampleAppName; OrganizationOwnerInfo orgOwner = setup.getMgmtSvc().createOwnerAndOrganization( orgName, appName, uniqueUsername(), uniqueEmail(), "password", true, false ); ApplicationCreatorImpl customCreator = new ApplicationCreatorImpl( setup.getEmf(), setup.getMgmtSvc() ); customCreator.setSampleAppName(sampleAppName); ApplicationInfo appInfo = customCreator.createSampleFor( orgOwner.getOrganization() ); if(appInfo == null){ setup.refreshIndex(setup.getEmf().getManagementAppId()); } assertNotNull( appInfo ); assertEquals( expectedName, appInfo.getName() ); } }
@Test public void skipAllEmailConfiguration() throws Exception { setup.set( PROPERTIES_SYSADMIN_APPROVES_ORGANIZATIONS, "false" ); setup.set( PROPERTIES_ORGANIZATIONS_REQUIRE_CONFIRMATION, "false" ); setup.set( PROPERTIES_SYSADMIN_APPROVES_ADMIN_USERS, "false" ); setup.set( PROPERTIES_ADMIN_USERS_REQUIRE_CONFIRMATION, "false" ); final String orgName = uniqueOrg(); final String userName = uniqueUsername(); final String email = uniqueEmail(); OrganizationOwnerInfo ooi = setup.getMgmtSvc() .createOwnerAndOrganization(orgName, userName, "Test User", email, "testpassword"); EntityManager em = setup.getEmf().getEntityManager( setup.getEmf().getManagementAppId() ); User user = em.get( ooi.getOwner().getUuid(), User.class ); assertTrue( user.activated() ); assertFalse( user.disabled() ); assertTrue( user.confirmed() ); }