List of usage examples for org.springframework.context ConfigurableApplicationContext getBean
Object getBean(String name) throws BeansException;
From source file:org.openhie.openempi.util.PersonUtils.java
static private Dataset createTestPersonTable(PersonDao personDao, PersonManagerService personManagerService, String tableName, String fieldNamePostfix, DatasetDao datasetDao, boolean fetchFieldTypes, ConfigurableApplicationContext applicationContext, boolean explicitIds, List<Person> persons, List<Long> personIds) throws ApplicationException { FieldDao fieldDao = null;// ww w. jav a 2 s .c om if (fetchFieldTypes) fieldDao = (FieldDao) applicationContext.getBean("fieldDao"); List<ColumnInformation> columnInformation = new ArrayList<ColumnInformation>(); ColumnInformation ci = new ColumnInformation(); String origIdFieldName = ORIGINAL_ID + fieldNamePostfix; ci.setFieldName(origIdFieldName); if (fetchFieldTypes) { ci.setFieldType(fieldDao.findFieldTypeByName(FieldType.FieldTypeEnum.Integer.name())); ci.setFieldMeaning(fieldDao.findFieldMeaningByName(FieldMeaning.FieldMeaningEnum.OriginalId.name())); } else { ci.setFieldType(FieldType.FieldTypeEnum.Integer); ci.setFieldMeaning(FieldMeaning.FieldMeaningEnum.OriginalId); } columnInformation.add(ci); ci = new ColumnInformation(); String givenNameFieldName = GIVEN_NAME + fieldNamePostfix; ci.setFieldName(givenNameFieldName); FieldType stringFieldType = null; FieldType dateFieldType = null; if (fetchFieldTypes) { stringFieldType = fieldDao.findFieldTypeByName(FieldType.FieldTypeEnum.String.name()); ci.setFieldType(stringFieldType); ci.setFieldMeaning(fieldDao.findFieldMeaningByName(FieldMeaning.FieldMeaningEnum.GivenName.name())); dateFieldType = fieldDao.findFieldTypeByName(FieldType.FieldTypeEnum.Date.name()); } else { ci.setFieldType(FieldType.FieldTypeEnum.String); ci.setFieldMeaning(FieldMeaning.FieldMeaningEnum.GivenName); } ci.setFieldTypeModifier("64"); columnInformation.add(ci); ci = new ColumnInformation(); String familyNameFieldName = FAMILY_NAME + fieldNamePostfix; ci.setFieldName(familyNameFieldName); if (fetchFieldTypes) { ci.setFieldType(stringFieldType); ci.setFieldMeaning(fieldDao.findFieldMeaningByName(FieldMeaning.FieldMeaningEnum.FamilyName.name())); } else { ci.setFieldType(FieldType.FieldTypeEnum.String); ci.setFieldMeaning(FieldMeaning.FieldMeaningEnum.FamilyName); } ci.setFieldTypeModifier("64"); columnInformation.add(ci); ci = new ColumnInformation(); String middleNameFieldName = MIDDLE_NAME + fieldNamePostfix; ci.setFieldName(middleNameFieldName); if (fetchFieldTypes) { ci.setFieldType(stringFieldType); ci.setFieldMeaning(fieldDao.findFieldMeaningByName(FieldMeaning.FieldMeaningEnum.MiddleName.name())); } else { ci.setFieldType(FieldType.FieldTypeEnum.String); ci.setFieldMeaning(FieldMeaning.FieldMeaningEnum.MiddleName); } ci.setFieldTypeModifier("64"); columnInformation.add(ci); ci = new ColumnInformation(); String address1FieldName = ADDRESS1_NAME + fieldNamePostfix; ci.setFieldName(address1FieldName); if (fetchFieldTypes) { ci.setFieldType(stringFieldType); ci.setFieldMeaning(fieldDao.findFieldMeaningByName(FieldMeaning.FieldMeaningEnum.AddressLine1.name())); } else { ci.setFieldType(FieldType.FieldTypeEnum.String); ci.setFieldMeaning(FieldMeaning.FieldMeaningEnum.AddressLine1); } ci.setFieldTypeModifier("128"); columnInformation.add(ci); ci = new ColumnInformation(); String address2FieldName = ADDRESS2_NAME + fieldNamePostfix; ci.setFieldName(address2FieldName); if (fetchFieldTypes) { ci.setFieldType(stringFieldType); ci.setFieldMeaning(fieldDao.findFieldMeaningByName(FieldMeaning.FieldMeaningEnum.AddressLine2.name())); } else { ci.setFieldType(FieldType.FieldTypeEnum.String); ci.setFieldMeaning(FieldMeaning.FieldMeaningEnum.AddressLine2); } ci.setFieldTypeModifier("128"); columnInformation.add(ci); ci = new ColumnInformation(); String cityFieldName = CITY_NAME + fieldNamePostfix; ci.setFieldName(cityFieldName); if (fetchFieldTypes) { ci.setFieldType(stringFieldType); ci.setFieldMeaning(fieldDao.findFieldMeaningByName(FieldMeaning.FieldMeaningEnum.City.name())); } else { ci.setFieldType(FieldType.FieldTypeEnum.String); ci.setFieldMeaning(FieldMeaning.FieldMeaningEnum.City); } ci.setFieldTypeModifier("64"); columnInformation.add(ci); ci = new ColumnInformation(); String stateFieldName = STATE_NAME + fieldNamePostfix; ci.setFieldName(stateFieldName); if (fetchFieldTypes) { ci.setFieldType(stringFieldType); ci.setFieldMeaning(fieldDao.findFieldMeaningByName(FieldMeaning.FieldMeaningEnum.State.name())); } else { ci.setFieldType(FieldType.FieldTypeEnum.String); ci.setFieldMeaning(FieldMeaning.FieldMeaningEnum.State); } ci.setFieldTypeModifier("64"); columnInformation.add(ci); ci = new ColumnInformation(); String postalCodeFieldName = POSTALCODE_NAME + fieldNamePostfix; ci.setFieldName(postalCodeFieldName); if (fetchFieldTypes) { ci.setFieldType(stringFieldType); ci.setFieldMeaning(fieldDao.findFieldMeaningByName(FieldMeaning.FieldMeaningEnum.PostalCode.name())); } else { ci.setFieldType(FieldType.FieldTypeEnum.String); ci.setFieldMeaning(FieldMeaning.FieldMeaningEnum.PostalCode); } ci.setFieldTypeModifier("16"); columnInformation.add(ci); ci = new ColumnInformation(); String nationalityFieldName = NATIONALITY_NAME + fieldNamePostfix; ci.setFieldName(nationalityFieldName); if (fetchFieldTypes) { ci.setFieldType(stringFieldType); ci.setFieldMeaning(fieldDao.findFieldMeaningByName(FieldMeaning.FieldMeaningEnum.Nationality.name())); } else { ci.setFieldType(FieldType.FieldTypeEnum.String); ci.setFieldMeaning(FieldMeaning.FieldMeaningEnum.Nationality); } ci.setFieldTypeModifier("64"); columnInformation.add(ci); ci = new ColumnInformation(); String genderFieldName = GENDER_NAME + fieldNamePostfix; ci.setFieldName(genderFieldName); if (fetchFieldTypes) { ci.setFieldType(stringFieldType); ci.setFieldMeaning(fieldDao.findFieldMeaningByName(FieldMeaning.FieldMeaningEnum.Gender.name())); } else { ci.setFieldType(FieldType.FieldTypeEnum.String); ci.setFieldMeaning(FieldMeaning.FieldMeaningEnum.Gender); } ci.setFieldTypeModifier("64"); columnInformation.add(ci); ci = new ColumnInformation(); String ssnFieldName = SSN_NAME + fieldNamePostfix; ci.setFieldName(ssnFieldName); if (fetchFieldTypes) { ci.setFieldType(stringFieldType); ci.setFieldMeaning(fieldDao.findFieldMeaningByName(FieldMeaning.FieldMeaningEnum.SSN.name())); } else { ci.setFieldType(FieldType.FieldTypeEnum.String); ci.setFieldMeaning(FieldMeaning.FieldMeaningEnum.SSN); } ci.setFieldTypeModifier("32"); columnInformation.add(ci); ci = new ColumnInformation(); String dateOfBirthFieldName = DOB_NAME + fieldNamePostfix; ci.setFieldName(dateOfBirthFieldName); if (fetchFieldTypes) { ci.setFieldType(dateFieldType); ci.setFieldMeaning(fieldDao.findFieldMeaningByName(FieldMeaning.FieldMeaningEnum.DateOfBirth.name())); } else { ci.setFieldType(FieldType.FieldTypeEnum.Date); ci.setFieldMeaning(FieldMeaning.FieldMeaningEnum.DateOfBirth); } ci.setFieldTypeModifier("16"); columnInformation.add(ci); ci = new ColumnInformation(); String accountFieldName = ACCOUNT_NAME + fieldNamePostfix; ci.setFieldName(accountFieldName); if (fetchFieldTypes) { ci.setFieldType(stringFieldType); ci.setFieldMeaning(fieldDao.findFieldMeaningByName(FieldMeaning.FieldMeaningEnum.Custom1.name())); } else { ci.setFieldType(FieldType.FieldTypeEnum.String); ci.setFieldMeaning(FieldMeaning.FieldMeaningEnum.Custom1); } ci.setFieldTypeModifier("16"); columnInformation.add(ci); Dataset dataset = null; PersonManagerService pms = personManagerService; if (pms != null) { dataset = pms.createDatasetTable(tableName, columnInformation, 6, false, false); } else { personDao.createTable(tableName, columnInformation, false); if (datasetDao != null) { dataset = new Dataset(tableName, "N/A"); dataset.setImported("Y"); dataset.setColumnInformation(columnInformation); dataset.setTotalRecords(6L); UserDao userDao = (UserDao) applicationContext.getBean("userDao"); User user = (User) userDao.loadUserByUsername("admin"); dataset.setOwner(user); dataset.setDateCreated(new java.util.Date()); dataset = datasetDao.saveDataset(dataset); } } Person person = new Person(); if (explicitIds) person.setPersonId(100L); person.setAttribute(origIdFieldName, 100L); person.setAttribute(givenNameFieldName, "Odysseas"); person.setAttribute(familyNameFieldName, "Pentakalos"); person.setAttribute(address1FieldName, "2930 Oak Shadow Drive"); person.setAttribute(cityFieldName, "Herndon"); person.setAttribute(stateFieldName, "Virginia"); person.setAttribute(ssnFieldName, "555-55-5555"); person.setAttribute(nationalityFieldName, "USA"); person.setAttribute(genderFieldName, "M"); if (pms != null) pms.addPerson(tableName, person, false, false); else personDao.addPerson(tableName, person); if (persons != null) persons.add(person); if (personIds != null) personIds.add(person.getPersonId()); person = new Person(); if (explicitIds) person.setPersonId(101L); person.setAttribute(origIdFieldName, 101L); person.setAttribute(givenNameFieldName, "Demi"); person.setAttribute(familyNameFieldName, "Moorxe"); person.setAttribute(cityFieldName, "Greenville"); person.setAttribute(stateFieldName, "California"); person.setAttribute(nationalityFieldName, "USA"); person.setAttribute(genderFieldName, "F"); if (pms != null) pms.addPerson(tableName, person, false, false); else personDao.addPerson(tableName, person); if (persons != null) persons.add(person); if (personIds != null) personIds.add(person.getPersonId()); person = new Person(); if (explicitIds) person.setPersonId(102L); person.setAttribute(origIdFieldName, 102L); person.setAttribute(givenNameFieldName, "Steve"); person.setAttribute(middleNameFieldName, "L"); person.setAttribute(familyNameFieldName, "Nyemba"); person.setAttribute(cityFieldName, "Hermitage"); person.setAttribute(stateFieldName, "Tennessee"); person.setAttribute(nationalityFieldName, "Cameroon"); person.setAttribute(genderFieldName, "M"); if (pms != null) pms.addPerson(tableName, person, false, false); else personDao.addPerson(tableName, person); if (persons != null) persons.add(person); if (personIds != null) personIds.add(person.getPersonId()); List<Person> innerCircle = new ArrayList<Person>(); person = new Person(); if (explicitIds) person.setPersonId(103L); person.setAttribute(origIdFieldName, 103L); person.setAttribute(givenNameFieldName, "Beth"); person.setAttribute(middleNameFieldName, "Anne"); person.setAttribute(familyNameFieldName, "Weinman"); person.setAttribute(cityFieldName, "St Paul"); person.setAttribute(stateFieldName, "Minnesota"); person.setAttribute(nationalityFieldName, "USA"); person.setAttribute(genderFieldName, "F"); innerCircle.add(person); person = new Person(); if (explicitIds) person.setPersonId(104L); person.setAttribute(origIdFieldName, 104L); person.setAttribute(givenNameFieldName, "Attila"); person.setAttribute(familyNameFieldName, "Toth"); person.setAttribute(cityFieldName, "Birmingham"); person.setAttribute(stateFieldName, "Alabama"); person.setAttribute(nationalityFieldName, "Hungary"); person.setAttribute(genderFieldName, "M"); innerCircle.add(person); person = new Person(); if (explicitIds) person.setPersonId(105L); person.setAttribute(origIdFieldName, 105L); person.setAttribute(givenNameFieldName, "Csaba"); person.setAttribute(familyNameFieldName, "Toth"); person.setAttribute(cityFieldName, "Nashville"); person.setAttribute(stateFieldName, "Tennessee"); person.setAttribute(nationalityFieldName, "Hungary"); person.setAttribute(genderFieldName, "M"); innerCircle.add(person); if (pms != null) pms.addPersons(tableName, innerCircle, false, false); else personDao.addPersons(tableName, innerCircle); for (Person innerPerson : innerCircle) { if (persons != null) persons.add(innerPerson); if (personIds != null) personIds.add(innerPerson.getPersonId()); } if (pms != null) pms.addIndexesAndConstraintsToDatasetTable(tableName, 106L); else personDao.addIndexesAndConstraints(tableName, 106L); return dataset; }
From source file:org.copperengine.core.test.persistent.BaseSpringTxnPersistentWorkflowTest.java
public void testSpringTxnUnitTestWorkflow(String dsContext) throws Exception { assumeFalse(skipTests());//from www. j av a 2s. co m final ConfigurableApplicationContext context = createContext(dsContext); cleanDB(context.getBean(DataSource.class)); final PersistentScottyEngine engine = context.getBean(PersistentScottyEngine.class); final BackChannelQueue backChannelQueue = context.getBean(BackChannelQueue.class); try { engine.startup(); engine.run("org.copperengine.core.test.persistent.springtxn.SpringTxnUnitTestWorkflow", "TestData"); WorkflowResult x = backChannelQueue.dequeue(60, TimeUnit.SECONDS); assertNotNull(x); assertNotNull(x.getResult()); assertNull(x.getException()); // check new RetryingTransaction<Void>(context.getBean(DataSource.class)) { @Override protected Void execute() throws Exception { Statement stmt = getConnection().createStatement(); ResultSet rs = stmt.executeQuery("select count(*) from COP_AUDIT_TRAIL_EVENT"); assertTrue(rs.next()); int c = rs.getInt(1); assertEquals(7, c); rs.close(); stmt.close(); return null; } }.run(); } finally { closeContext(context); } assertEquals(EngineState.STOPPED, engine.getEngineState()); assertEquals(0, engine.getNumberOfWorkflowInstances()); }
From source file:de.olivergierke.samples.datanucleus.SpringTestCase.java
@Test public void bootstrapJpa() { ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(Config.class); EntityManagerFactory factory = context.getBean(EntityManagerFactory.class); SimpleTestCase.executeTestWith(factory); context.close();/* w w w . j av a 2s. c om*/ }
From source file:org.fcrepo.migration.f4clients.StatelessFedora4ClientIT.java
@Before public void setup() throws BeansException, XMLStreamException { final ConfigurableApplicationContext context = new ClassPathXmlApplicationContext("spring/it-setup.xml"); client = (Fedora4Client) context.getBean("fedora4Client"); }
From source file:com.provenance.cloudprovenance.policycontroller.utility.test.XPathUtilityTest.java
@Before public void setUp() throws XMLDBException, URISyntaxException { ConfigurableApplicationContext ctx = new ClassPathXmlApplicationContext(new String[] { "beans.xml" }); xpathUtility = (XPathProvenanceConditionUtility) ctx.getBean("xPathProvenanceConditionUtility"); ctx.close();//from www . j a v a2 s .com // initilizeStore(); }
From source file:org.fcrepo.migration.LegacyFoxmlStorageMigratorTest.java
@Before public synchronized void processFoxml() throws XMLStreamException, IOException { if (getResult() == null) { final ConfigurableApplicationContext context = new ClassPathXmlApplicationContext( "spring/stored-legacy-foxml.xml"); this.result = (DummyHandler) context.getBean("dummyHandler"); this.fetcher = (DummyURLFetcher) context.getBean("dummyFetcher"); final Migrator m = (Migrator) context.getBean("migrator"); m.run();//from ww w . ja va 2 s. com context.close(); } }
From source file:org.alfresco.integrations.google.docs.webscripts.GoogleDocsWebScripts.java
protected void getGoogleDocsServiceSubsystem() { try {//from w w w . j av a2 s. c o m ApplicationContextFactory subsystem = (ApplicationContextFactory) applicationContext .getBean(GOOGLEDOCS_V2_SUBSYSTEM); ConfigurableApplicationContext childContext = (ConfigurableApplicationContext) subsystem .getApplicationContext(); setGoogledocsService((GoogleDocsService) childContext.getBean(GOOGLEDOCSSERVICE)); } catch (NoSuchBeanDefinitionException nsbde) { // googledocs_v2 bean is not present on Community } }
From source file:org.syncope.core.persistence.beans.AbstractDerAttr.java
/** * @see http://commons.apache.org/jexl/reference/index.html * @param attributes the set of attributes against which evaluate this * derived attribute/*ww w.j a v a 2 s. c om*/ * @return the value of this derived attribute */ public String getValue(final Collection<? extends AbstractAttr> attributes) { final ConfigurableApplicationContext context = ApplicationContextManager.getApplicationContext(); final JexlUtil jexlUtil = context.getBean(JexlUtil.class); // Prepare context using user attributes final JexlContext jexlContext = jexlUtil.addAttrsToContext(attributes, null); final AbstractAttributable owner = getOwner(); if (owner instanceof SyncopeUser) { jexlContext.set("username", ((SyncopeUser) owner).getUsername() != null ? ((SyncopeUser) owner).getUsername() : ""); jexlContext.set("creationDate", ((SyncopeUser) owner).getCreationDate() != null ? ((SyncopeUser) owner).getDateFormatter().format(((SyncopeUser) owner).getCreationDate()) : ""); jexlContext.set("lastLoginDate", ((SyncopeUser) owner).getLastLoginDate() != null ? ((SyncopeUser) owner).getDateFormatter().format(((SyncopeUser) owner).getLastLoginDate()) : ""); jexlContext.set("failedLogins", ((SyncopeUser) owner).getFailedLogins() != null ? ((SyncopeUser) owner).getFailedLogins() : ""); jexlContext.set("changePwdDate", ((SyncopeUser) owner).getChangePwdDate() != null ? ((SyncopeUser) owner).getDateFormatter().format(((SyncopeUser) owner).getChangePwdDate()) : ""); } // Evaluate expression using the context prepared before return jexlUtil.evaluate(getDerivedSchema().getExpression(), jexlContext); }
From source file:demo.vmware.commands.CommandRebalance.java
@Override public CommandResult run(ConfigurableApplicationContext mainContext, List<String> parameters) { List<String> messages = new ArrayList<String>(); Cache cache = (Cache) mainContext.getBean("cache"); ResourceManager manager = cache.getResourceManager(); RebalanceOperation op = manager.createRebalanceFactory().start(); // Wait until the rebalance is complete RebalanceResults results;/*from w ww.ja v a 2 s . c o m*/ try { results = op.getResults(); messages.add("Rebalance Took " + results.getTotalTime() + " milliseconds\n"); messages.add("Rebalance Transfered " + results.getTotalBucketTransferBytes() + "bytes\n"); } catch (CancellationException e) { LOG.warn("Rebalance failed: ", e); } catch (InterruptedException e) { LOG.warn("Rebalance failed: ", e); } return new CommandResult(null, messages); }