info.pancancer.arch3.reportcli.ReportCLI.java Source code

Java tutorial

Introduction

Here is the source code for info.pancancer.arch3.reportcli.ReportCLI.java

Source

/*
 *     Consonance - workflow software for multiple clouds
 *     Copyright (C) 2016 OICR
 *
 *     This program is free software: you can redistribute it and/or modify
 *     it under the terms of the GNU General Public License as published by
 *     the Free Software Foundation, either version 3 of the License, or
 *     (at your option) any later version.
 *
 *     This program is distributed in the hope that it will be useful,
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *     GNU General Public License for more details.
 *
 *     You should have received a copy of the GNU General Public License
 *     along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */
package info.pancancer.arch3.reportcli;

import com.google.common.base.Joiner;
import info.pancancer.arch3.Base;
import info.pancancer.arch3.persistence.PostgreSQL;
import info.pancancer.arch3.reporting.ReportAPI;
import info.pancancer.arch3.reporting.ReportAPIFactory;
import info.pancancer.arch3.reporting.SlackRenderer;
import info.pancancer.arch3.utils.Utilities;
import java.io.IOException;
import java.util.List;
import java.util.Locale;
import org.apache.commons.configuration.HierarchicalINIConfiguration;

/**
 * This allows for ad-hoc reporting, should not be used at the same time as the ReportBot
 *
 * @author dyuen
 */
public class ReportCLI extends Base {

    public static final int SLEEP_IN_MILLISECONDS = 5000;

    public static void main(String[] argv) throws Exception {
        ReportCLI bot = new ReportCLI(argv);
        bot.doWork();
    }

    public ReportCLI(String[] argv) throws IOException {
        super();
        parseOptions(argv);
    }

    public void doWork() throws Exception {

        final HierarchicalINIConfiguration settings = Utilities.parseConfig(configFile);
        final PostgreSQL db = new PostgreSQL(settings);

        ReportAPI reportAPI = ReportAPIFactory.makeReportAPI(settings, db);
        // later, we'll replace his with a proper CLI renderer
        SlackRenderer renderer = new SlackRenderer(reportAPI);
        List<?> nonOptionArguments = options.nonOptionArguments();
        String joined = Joiner.on("").join(nonOptionArguments).toUpperCase(Locale.CANADA);
        SlackRenderer.FormattedMessage result = renderer.convertToResult(joined);
        if (result.message != null) {
            System.out.print(renderer.convertToResult(joined).message);
        }
        if (result.attachment != null) {
            System.out.print(renderer.convertToResult(joined).attachment.toString());
        }
    }
}