Example usage for org.springframework.boot SpringApplication SpringApplication

List of usage examples for org.springframework.boot SpringApplication SpringApplication

Introduction

In this page you can find the example usage for org.springframework.boot SpringApplication SpringApplication.

Prototype

public SpringApplication(Class<?>... primarySources) 

Source Link

Document

Create a new SpringApplication instance.

Usage

From source file:com.acapulcoapp.alloggiatiweb.FileReader.java

public static void main(String[] args) throws UnknownHostException, IOException {
    // TODO code application logic here

    SpringApplication app = new SpringApplication(AcapulcoappApp.class);
    SimpleCommandLinePropertySource source = new SimpleCommandLinePropertySource(args);
    addDefaultProfile(app, source);/*  www  .  jav a  2  s .co m*/

    ConfigurableApplicationContext context = app.run(args);

    initBeans(context);

    Map<LocalDate, List<List<String>>> map = new TreeMap<>();

    List<File> files = new ArrayList<>(FileUtils.listFiles(new File("/Users/chiccomask/Downloads/ALLOGGIATI"),
            new String[] { "txt" }, true));

    Collections.reverse(files);

    int count = 0;

    for (File file : files) {

        //            List<String> allLines = FileUtils.readLines(file, "windows-1252");
        List<String> allLines = FileUtils.readLines(file, "UTF-8");

        for (int i = 0; i < allLines.size();) {

            count++;

            List<String> record = new ArrayList<>();

            String line = allLines.get(i);
            String type = TIPO_ALLOGGIO.parse(line);

            switch (type) {
            case "16":
                record.add(line);
                i++;
                break;
            case "17": {
                record.add(line);
                boolean out = false;
                while (!out) {
                    i++;
                    if (i < allLines.size()) {
                        String subline = allLines.get(i);
                        String subtype = TIPO_ALLOGGIO.parse(subline);
                        if (!subtype.equals("19")) {
                            out = true;
                        } else {
                            record.add(subline);
                        }
                    } else {
                        out = true;
                    }
                }
                break;
            }
            case "18": {
                record.add(line);
                boolean out = false;
                while (!out) {
                    i++;
                    if (i < allLines.size()) {
                        String subline = allLines.get(i);
                        String subtype = TIPO_ALLOGGIO.parse(subline);
                        if (!subtype.equals("20")) {
                            out = true;
                        } else {
                            record.add(subline);
                        }
                    } else {
                        out = true;
                    }
                }
                break;
            }
            default:
                break;
            }

            LocalDate arrived = LocalDate.parse(DATA_ARRIVO.parse(line),
                    DateTimeFormatter.ofPattern(DATE_PATTERN));
            if (!map.containsKey(arrived)) {
                map.put(arrived, new ArrayList<>());
            }
            map.get(arrived).add(record);
        }
    }

    for (LocalDate date : map.keySet()) {

        System.out.println();
        System.out.println("process day " + date);

        for (List<String> record : map.get(date)) {

            System.out.println();
            System.out.println("process record ");
            for (String line : record) {
                System.out.println(line);
            }

            CheckinRecord checkinRecord = new CheckinRecord();

            //non lo setto per adesso
            String firstLine = record.get(0);

            String typeStr = TIPO_ALLOGGIO.parse(firstLine);
            CheckinType cht = checkinTypeRepository.find(typeStr);
            checkinRecord.setCheckinType(cht);

            int days = Integer.parseInt(PERMANENZA.parse(firstLine));
            checkinRecord.setDays(days);
            checkinRecord.setArrived(date);

            boolean isMain = true;

            List<Person> others = new ArrayList<>();

            for (String line : record) {
                Person p = extractPerson(line);

                if (p.getDistrictOfBirth() == null) {
                    System.out.println("district of birth not found " + p);
                }

                List<Person> duplicates = personRepository.findDuplicates(p.getSurname(), p.getName(),
                        p.getDateOfBirth());

                if (duplicates.isEmpty()) {
                    System.out.println("add new person " + p.getId() + " " + p);
                    personRepository.saveAndFlush(p);
                } else if (duplicates.size() == 1) {

                    Person found = duplicates.get(0);

                    if (p.getIdentityDocument() != null) {
                        //we sorted by date so we suppose 
                        //the file version is newer so we update the entity
                        p.setId(found.getId());
                        System.out.println("update person " + p.getId() + " " + p);
                        personRepository.saveAndFlush(p);

                    } else if (found.getIdentityDocument() != null) {
                        //on db there are more data so I use them.
                        p = found;
                        System.out.println("use already saved person " + p.getId() + " " + p);
                    } else {
                        p.setId(found.getId());
                        System.out.println("update person " + p.getId() + " " + p);
                        personRepository.saveAndFlush(p);
                    }

                } else {
                    throw new RuntimeException("More duplicated for " + p.getName());
                }

                if (isMain) {
                    checkinRecord.setMainPerson(p);
                    isMain = false;
                } else {
                    others.add(p);
                }
            }

            checkinRecord.setOtherPeople(new HashSet<>(others));

            if (checkinRecordRepository.alreadyExists(checkinRecord.getMainPerson(), date) != null) {
                System.out.println("already exists " + date + " p " + checkinRecord.getMainPerson());
            } else {
                System.out.println("save record ");
                checkinRecordRepository.saveAndFlush(checkinRecord);
            }
        }
    }

    //
    //            if (type.equals("16")) {
    //                List<String> record = new ArrayList<>();
    //                record.add(line);
    //                keepOpen = false;
    //            }
    //
    //            map.get(arrived).add(record);
    //        map.values().forEach((list) -> {
    //
    //            for (String line : list) {
    //
    //                Person p = null;
    //
    //                try {
    //
    //                    p = extractPerson(line);
    //
    //                    List<Person> duplicates = personRepository.findDuplicates(p.getSurname(), p.getName(), p.getDateOfBirth());
    //
    //                    if (duplicates.isEmpty()) {
    //                        personRepository.saveAndFlush(p);
    //
    //                    } else if (duplicates.size() > 1) {
    //                        System.out.println();
    //                        System.out.println("MULIPLE DUPLICATED");
    //
    //                        for (Person dd : duplicates) {
    //                            System.out.println(dd);
    //                        }
    //                        System.out.println("* " + p);
    //                        throw new RuntimeException();
    //                    } else {
    //
    ////                        if (!duplicates.get(0).getDistrictOfBirth().equals(p.getDistrictOfBirth())) {
    ////                        int index = 0;
    ////
    ////                        System.out.println();
    ////                        System.out.println("DUPLICATED");
    ////
    ////                        for (Person dd : duplicates) {
    ////                            System.out.println(dd);
    ////                            index++;
    ////                        }
    ////                        System.out.println("* " + p);
    ////                        System.out.println(file.getAbsolutePath() + " " + p);
    ////
    ////                        System.out.println();
    ////                        System.out.println();
    ////                        }
    ////                        duplicates.remove(0);
    ////                        personRepository.deleteInBatch(duplicates);
    ////                System.out.println();
    ////                System.out.println("Seleziona scelta");
    ////                Scanner s = new Scanner(System.in);
    ////                int selected;
    ////                try {
    ////                    selected = s.nextInt();
    ////                } catch (InputMismatchException e) {
    ////                    selected = 0;
    ////                }
    ////
    ////                if (duplicates.size() <= selected) {
    ////                    personRepository.deleteInBatch(duplicates);
    ////                    personRepository.saveAndFlush(p);
    ////                } else {
    ////                    duplicates.remove(selected);
    ////                    personRepository.deleteInBatch(duplicates);
    ////                }
    //                    }
    //
    //                } catch (Exception e) {
    //
    //                    System.out.println();
    ////                    System.out.println("ERROR READING lineCount=" + allLines.indexOf(line) + " line=" + line);
    ////                    System.out.println(file.getAbsolutePath());
    //                    System.out.println(p);
    //                    e.printStackTrace();
    //                    System.out.println();
    //                }
    //            }
    //        });
    context.registerShutdownHook();

    System.exit(0);
}

From source file:com.devnexus.ting.DevNexusApplication.java

public static void main(String[] args) throws Exception {
    TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
    final SpringApplication application = new SpringApplication(DevNexusApplication.class);
    application.addInitializers(new DefaultApplicationContextInitializer());
    application.run(args);//from www . ja  v  a  2  s  .  c o  m
}

From source file:com.pubkit.PubKitApplication.java

public static void main(String[] args) {
    SpringApplication app = new SpringApplication(PubKitApplication.class);
    app.run(args);
}

From source file:com.hillert.botanic.MainApp.java

/**
 * Main class initializes the Spring Application Context and populates seed
 * data using {@link SeedDataService}.//from ww w .j a  v  a  2  s.  c  o m
 *
 * @param args Not used.
 */
public static void main(String[] args) {
    Map<String, Object> props = new HashMap<String, Object>();
    props.put("redisPort", SocketUtils.findAvailableTcpPort());

    SpringApplication app = new SpringApplication(MainApp.class);
    app.setDefaultProperties(props);

    ConfigurableApplicationContext context = app.run(args);

    MapPropertySource propertySource = new MapPropertySource("ports", props);

    context.getEnvironment().getPropertySources().addFirst(propertySource);

    SeedDataService seedDataService = context.getBean(SeedDataService.class);
    seedDataService.populateSeedData();
}

From source file:lab.example.service.LotteryService.java

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

    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
    ctx.register(LotteryService.class);

    SpringApplication application = new SpringApplication(LotteryService.class);

    application.setApplicationContextClass(AnnotationConfigApplicationContext.class);
    SpringApplication.run(LotteryService.class, args);
}

From source file:com.uimirror.auth.StartApp.java

/**
 * Application entry point./*from  w w w. j a v  a2s.  c om*/
 * @param args command line args
 */
public static void main(final String[] args) {
    LOG.info("CmdLine Args {}", Arrays.asList(args));
    try {
        SpringApplication sa = new SpringApplication(new Object[] { StartApp.class });
        sa.run(args);

    } catch (Exception e) {
        LOG.error("Unexpected error", e);
    }
}

From source file:com.uimirror.image.StartApp.java

/**
 * Application entry point./* w ww.ja  v a2 s  .  c om*/
 * @param args command line args
 */
public static void main(final String[] args) {
    LOG.info("CmdLine Args {}", Arrays.asList(args));
    try {
        SpringApplication sa = new SpringApplication(new Object[] { StartApp.class });
        sa.run(args);
    } catch (Exception e) {
        LOG.error("Unexpected error", e);
    }
}

From source file:lab.example.service.MessageListener.java

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

    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
    ctx.register(MessageListener.class);

    SpringApplication application = new SpringApplication(MessageListener.class);

    application.setApplicationContextClass(AnnotationConfigApplicationContext.class);
    SpringApplication.run(MessageListener.class, args);
}

From source file:de.petendi.ethereum.secure.proxy.Application.java

public static void main(String[] args) {

    try {/*from w ww. j a  v a 2  s.  c  om*/
        cmdLineResult = new CmdLineResult();
        cmdLineResult.parseArguments(args);
    } catch (CmdLineException e) {
        System.out.println(e.getMessage());
        System.out.println("Usage:");
        cmdLineResult.printExample();
        System.exit(-1);
        return;
    }

    File workingDirectory = new File(System.getProperty("user.home"));
    if (cmdLineResult.getWorkingDirectory().length() > 0) {
        workingDirectory = new File(cmdLineResult.getWorkingDirectory()).getAbsoluteFile();
    }

    ArgumentList argumentList = new ArgumentList();
    argumentList.setWorkingDirectory(workingDirectory);
    File certificate = new File(workingDirectory, "seccoco-secured/cert.p12");
    if (certificate.exists()) {
        char[] passwd = null;
        if (cmdLineResult.getPassword() != null) {
            System.out.println("Using password from commandline argument - DON'T DO THIS IN PRODUCTION !!");
            passwd = cmdLineResult.getPassword().toCharArray();
        } else {
            Console console = System.console();
            if (console != null) {
                passwd = console.readPassword("[%s]", "Enter application password:");
            } else {
                System.out.print("No suitable console found for entering password");
                System.exit(-1);
            }
        }
        argumentList.setTokenPassword(passwd);
    }
    try {
        SeccocoFactory seccocoFactory = new SeccocoFactory("seccoco-secured", argumentList);
        seccoco = seccocoFactory.create();
    } catch (InitializationException e) {
        System.out.println(e.getMessage());
        System.exit(-1);
    }
    try {
        System.out.println("Connecting to Ethereum RPC at " + cmdLineResult.getUrl());
        URL url = new URL(cmdLineResult.getUrl());
        HashMap<String, String> headers = new HashMap<String, String>();
        headers.put("Content-Type", "application/json");
        String additionalHeaders = cmdLineResult.getAdditionalHeaders();
        if (additionalHeaders != null) {
            StringTokenizer tokenizer = new StringTokenizer(additionalHeaders, ",");
            while (tokenizer.hasMoreTokens()) {
                String keyValue = tokenizer.nextToken();
                StringTokenizer innerTokenizer = new StringTokenizer(keyValue, ":");
                headers.put(innerTokenizer.nextToken(), innerTokenizer.nextToken());
            }
        }
        settings = new Settings(cmdLineResult.isExposeWhisper(), headers);
        jsonRpcHttpClient = new JsonRpcHttpClient(url);
        jsonRpcHttpClient.setRequestListener(new JsonRpcRequestListener());

        jsonRpcHttpClient.invoke("eth_protocolVersion", null, Object.class, headers);
        if (cmdLineResult.isExposeWhisper()) {
            jsonRpcHttpClient.invoke("shh_version", null, Object.class, headers);
        }
        System.out.println("Connection succeeded");
    } catch (Throwable e) {
        System.out.println("Connection failed: " + e.getMessage());
        System.exit(-1);
    }
    SpringApplication app = new SpringApplication(Application.class);
    app.setBanner(new Banner() {
        @Override
        public void printBanner(Environment environment, Class<?> aClass, PrintStream printStream) {
            //send the Spring Boot banner to /dev/null
        }
    });
    app.run(new String[] {});
}

From source file:com.ericsson.eiffel.remrem.publish.cli.CLI.java

public static void main(String args[]) {
    SpringApplication application = new SpringApplication(CLI.class);
    application.addInitializers(new SpringLoggingInitializer());
    application.setBannerMode(Banner.Mode.OFF);
    application.setLogStartupInfo(false);
    application.setWebEnvironment(false);
    CliOptions.parse(args);//from   ww  w  .j a v a  2s .  com
    application.run(args);
}