Example usage for org.springframework.context.annotation AnnotationConfigApplicationContext getBean

List of usage examples for org.springframework.context.annotation AnnotationConfigApplicationContext getBean

Introduction

In this page you can find the example usage for org.springframework.context.annotation AnnotationConfigApplicationContext getBean.

Prototype

@Override
    public Object getBean(String name) throws BeansException 

Source Link

Usage

From source file:com.khartec.waltz.jobs.sample.OrgUnitGenerator.java

public static void main(String[] args) throws IOException {

    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
    DSLContext dsl = ctx.getBean(DSLContext.class);

    List<String> lines = readLines(OrgUnitGenerator.class.getResourceAsStream("/org-units.csv"));

    System.out.println("Deleting existing OU's");
    dsl.deleteFrom(ORGANISATIONAL_UNIT).execute();

    List<OrganisationalUnitRecord> records = lines.stream().skip(1)
            .map(line -> StringUtils.splitPreserveAllTokens(line, ",")).filter(cells -> cells.length == 4)
            .map(cells -> {// w w w .j a v a 2 s .  com
                OrganisationalUnitRecord record = new OrganisationalUnitRecord();
                record.setId(longVal(cells[0]));
                record.setParentId(longVal(cells[1]));
                record.setName(cells[2]);
                record.setDescription(cells[3]);
                record.setUpdatedAt(new Timestamp(System.currentTimeMillis()));

                System.out.println(record);
                return record;
            }).collect(Collectors.toList());

    System.out.println("Inserting new OU's");
    dsl.batchInsert(records).execute();

    System.out.println("Done");

}

From source file:com.khartec.waltz.jobs.JooqTest2.java

public static void main(String[] args) {

    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);

    DataSource dataSource = ctx.getBean(DataSource.class);

    DSLContext dsl = DSL.using(dataSource, SQLDialect.POSTGRES_9_4, new Settings().withRenderFormatted(true));

    Table<Record> orgTree = table(name("orgTree"));
    Field<Long> ouIdField = field(name("orgTree", "ouId"), Long.class);

    SelectJoinStep<Record1<Long>> with = dsl.withRecursive("orgTree", "ouId")
            .as(select(ORGANISATIONAL_UNIT.ID).from(ORGANISATIONAL_UNIT)
                    .where(ORGANISATIONAL_UNIT.ID.eq(Long.valueOf(210)))
                    .unionAll(select(ORGANISATIONAL_UNIT.ID).from(ORGANISATIONAL_UNIT, orgTree)
                            .where(ORGANISATIONAL_UNIT.PARENT_ID.eq(ouIdField))))
            .select(ouIdField).from(orgTree);

    Field[] fields = new Field[] { APPLICATION.NAME, APPLICATION.ORGANISATIONAL_UNIT_ID,
            PERSPECTIVE_RATING.CAPABILITY_ID, PERSPECTIVE_RATING.RATING };
    String sql = dsl.select(fields).from(PERSPECTIVE_RATING).innerJoin(APPLICATION)
            .on(PERSPECTIVE_RATING.PARENT_ID.eq(APPLICATION.ID))
            .where(PERSPECTIVE_RATING.PERSPECTIVE_CODE.eq("BUSINESS"))
            .and(APPLICATION.ORGANISATIONAL_UNIT_ID.in(with)).getSQL();

    System.out.println(sql);//w w w . jav a2  s  . c om

}

From source file:prospring3.ch6.Ch6Main.java

public static void main(String[] args) {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
    ctx.register(Ch6Config.class);
    ctx.refresh();/*  ww w  . j  a  v a 2s.c o m*/

    final TwitterServiceClient twitterService = ctx.getBean(TwitterServiceClient.class);
    twitterService.deassociateAll();

    System.out.println("Finish");
}

From source file:org.github.aenygmatic.payroll.PayrollSystem.java

public static void main(String[] args) {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
            "org.github.aenygmatic.payroll");
    PayrollSystem system = context.getBean(PayrollSystem.class);
    system.hireAndPayAll();//from w ww.j  av a  2  s.  c o m
}

From source file:com.khartec.waltz.jobs.sample.MeasurablesGenerator.java

public static void main(String[] args) throws IOException {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
    DSLContext dsl = ctx.getBean(DSLContext.class);

    generateRegions(dsl);/*from  w w w. j a  v a2s  .  c  o m*/
}

From source file:com.khartec.waltz.jobs.sample.AppGenerator.java

public static void main(String[] args) throws IOException {

    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);

    DSLContext dsl = ctx.getBean(DSLContext.class);
    ApplicationService applicationDao = ctx.getBean(ApplicationService.class);
    OrganisationalUnitService ouDao = ctx.getBean(OrganisationalUnitService.class);

    List<String> animals = IOUtilities
            .readLines(AppGenerator.class.getClassLoader().getResourceAsStream("animals.txt"));
    OrganisationalUnit[] organisationalUnits = ouDao.findAll().toArray(new OrganisationalUnit[0]);

    List<AppRegistrationRequest> registrationRequests = new ArrayList<>();

    for (int i = 0; i < 5000; i++) {
        String animal = randomPick(animals.toArray(new String[0])) + " - " + i;

        OrganisationalUnit organisationalUnit = randomPick(organisationalUnits);

        LifecyclePhase phase = rnd.nextInt(10) > 7 ? randomPick(LifecyclePhase.values())
                : LifecyclePhase.PRODUCTION;

        AppRegistrationRequest app = ImmutableAppRegistrationRequest.builder().name(animal)
                .assetCode("wltz-0" + i).description("All about " + animal)
                .kind(randomPick(ApplicationKind.values())).lifecyclePhase(phase)
                .overallRating(randomPick(RagRating.R, RagRating.A, RagRating.A, RagRating.G, RagRating.G))
                .organisationalUnitId(organisationalUnit.id().get()).build();

        registrationRequests.add(app);//from   w ww  . j a va  2  s  .c  o  m
    }

    dsl.deleteFrom(AUTHORITATIVE_SOURCE).execute();
    dsl.deleteFrom(APPLICATION).execute();

    registrationRequests.forEach(applicationDao::registerApp);

}

From source file:com.khartec.waltz.jobs.UserPreferenceHarness.java

public static void main(String[] args) throws ParseException {

    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);

    UserPreferenceDao userPreferenceDao = ctx.getBean(UserPreferenceDao.class);

    List<UserPreference> preferences = new ArrayList<UserPreference>() {
        {//from   w ww . j  a  v  a 2 s  . c  o  m
            add(ImmutableUserPreference.builder().key("org-unit.section.technologies.collapsed").value("false")
                    .build());

            add(ImmutableUserPreference.builder().key("org-unit.section.indicators.collapsed").value("true")
                    .build());

            add(ImmutableUserPreference.builder().key("org-unit.section.logicalflows.collapsed").value("true")
                    .build());

        }
    };

    //        int result = userPreferenceDao.savePreferencesForUser("admin", preferences);
    //        System.out.println("result: " + result);

    int result = userPreferenceDao.savePreference("admin", ImmutableUserPreference.builder()
            .key("org-unit.section.logicalflows.hidden").value("true").build());
    System.out.println("result: " + result);

    //        List<UserPreference> prefs = userPreferenceDao.getPreferencesForUser("admin");
    //        prefs.forEach(u -> System.out.printf("user: %s, key: %s, value: %s\r\n", u.userName(), u.key(), u.value()));

    //        userPreferenceDao.clearPreferencesForUser("kamran");

}

From source file:com.khartec.waltz.jobs.sample.AssetCostGenerator.java

public static void main(String[] args) {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
    ApplicationService applicationService = ctx.getBean(ApplicationService.class);

    DSLContext dsl = ctx.getBean(DSLContext.class);

    List<AssetCostRecord> appDevCosts = generateRecords(applicationService, CostKind.APPLICATION_DEVELOPMENT,
            100_0000);//from  w w w  .java  2  s.c  o m
    List<AssetCostRecord> infraCosts = generateRecords(applicationService, CostKind.INFRASTRUCTURE, 5_000);

    dsl.deleteFrom(ASSET_COST).where(ASSET_COST.YEAR.eq(year)).and(ASSET_COST.PROVENANCE.eq(provenance))
            .execute();

    dsl.batchInsert(appDevCosts).execute();
    dsl.batchInsert(infraCosts).execute();
}

From source file:com.khartec.waltz.jobs.sample.PersonDataGenerator.java

public static void main(String[] args) {

    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);

    PersonService personService = ctx.getBean(PersonService.class);

    Person person = fairy.person();/*from  ww w .  ja  v  a 2 s.co m*/

    ImmutablePerson root = ImmutablePerson.builder().employeeId(person.passportNumber())
            .kind(PersonKind.EMPLOYEE).userPrincipalName(person.username()).title(randomPick(jobTitles[0]))
            .departmentName("CEO").displayName(person.fullName()).email(person.email()).build();

    peeps.add(root);

    visit(root, 1);

    System.out.println(peeps.size());

    personService.bulkSave(peeps);

}

From source file:com.github.pjungermann.config.Application.java

public static void main(final String[] arguments) throws ConfigValidationException {
    LOGGER.info("start config validation");

    final ApplicationCLI cli;
    try {/*from w  ww  .  jav  a 2s . c om*/
        cli = new ApplicationCLI(arguments);

    } catch (MissingArgumentException | MissingOptionException | UnrecognizedOptionException e) {
        ApplicationCLI.usage();
        return;

    } catch (ParseException e) {
        LOGGER.error("arguments parsing failed", e);
        ApplicationCLI.usage();
        return;
    }

    final AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
            Application.class);

    final ConfigValidator validator = context.getBean(ConfigValidator.class);
    validator.validate(cli.configs, cli.specs, cli.recursive, cli.profile, cli.strict);

    LOGGER.info("config validation finished");
}