Search in sources :

Example 1 with Ansi

use of com.fathomdb.cli.commands.Ansi in project platformlayer by platformlayer.

the class ListJobs method formatRaw.

@Override
public void formatRaw(Object o, PrintWriter writer) {
    JobDataList jobs = (JobDataList) o;
    switch(getFormat()) {
        case JSON:
            JsonHelper<JobDataList> jsonHelper = JsonHelper.build(JobDataList.class);
            boolean formatted = true;
            try {
                String json = jsonHelper.marshal(jobs, formatted);
                writer.println(json);
                return;
            } catch (IOException e) {
                throw new CliException("Error formatting for output", e);
            }
    }
    Ansi ansi = new Ansi(writer);
    for (JobData job : jobs.getJobs()) {
        // JobState state = job.state;
        // if (state != null) {
        // ansi.setColorBlue();
        // switch (job.state) {
        // case FAILED:
        // ansi.setColorRed();
        // break;
        // 
        // case SUCCESS:
        // ansi.setColorGreen();
        // break;
        // 
        // case RUNNING:
        // ansi.setColorBlue();
        // break;
        // 
        // default:
        // ansi.setColorBlue();
        // break;
        // }
        // }
        writer.println(job.key);
    }
    ansi.reset();
}
Also used : CliException(com.fathomdb.cli.CliException) JobDataList(org.platformlayer.jobs.model.JobDataList) IOException(java.io.IOException) JobData(org.platformlayer.jobs.model.JobData) Ansi(com.fathomdb.cli.commands.Ansi)

Example 2 with Ansi

use of com.fathomdb.cli.commands.Ansi in project platformlayer by platformlayer.

the class ListRoots method formatRaw.

@Override
public void formatRaw(Object o, PrintWriter writer) {
    Ansi ansi = new Ansi(writer);
    Iterable<UntypedItem> items = (Iterable<UntypedItem>) o;
    for (UntypedItem item : items) {
        UntypedItemFormatter.formatItem(item, ansi, true);
    }
    ansi.reset();
}
Also used : UntypedItem(org.platformlayer.common.UntypedItem) Ansi(com.fathomdb.cli.commands.Ansi)

Example 3 with Ansi

use of com.fathomdb.cli.commands.Ansi in project platformlayer by platformlayer.

the class PlatformLayerCommandRunnerBase method formatRaw.

@Override
public void formatRaw(Object o, PrintWriter writer) {
    String data;
    if (o instanceof UntypedItemXml) {
        UntypedItemXml item = (UntypedItemXml) o;
        Source src = new DOMSource(item.getRoot());
        String xml = DomUtils.toXml(src, 4);
        data = xml;
    } else if (o instanceof UntypedItemJson) {
        UntypedItemJson item = (UntypedItemJson) o;
        JSONObject root = item.getRoot();
        try {
            data = root.toString(2);
        } catch (JSONException e) {
            throw new IllegalStateException("Error formatting JSON", e);
        }
    } else {
        super.formatRaw(o, writer);
        return;
    }
    Ansi ansi = new Ansi(writer);
    ansi.print(data);
    ansi.println();
    ansi.reset();
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) JSONObject(org.json.JSONObject) UntypedItemXml(org.platformlayer.UntypedItemXml) UntypedItemJson(org.platformlayer.UntypedItemJson) JSONException(org.json.JSONException) Ansi(com.fathomdb.cli.commands.Ansi) DOMSource(javax.xml.transform.dom.DOMSource) Source(javax.xml.transform.Source)

Example 4 with Ansi

use of com.fathomdb.cli.commands.Ansi in project platformlayer by platformlayer.

the class ListChildren method formatRaw.

@Override
public void formatRaw(Object o, PrintWriter writer) {
    Ansi ansi = new Ansi(writer);
    Iterable<UntypedItem> items = (Iterable<UntypedItem>) o;
    for (UntypedItem item : items) {
        UntypedItemFormatter.formatItem(item, ansi, true);
    }
    ansi.reset();
}
Also used : UntypedItem(org.platformlayer.common.UntypedItem) Ansi(com.fathomdb.cli.commands.Ansi)

Example 5 with Ansi

use of com.fathomdb.cli.commands.Ansi in project platformlayer by platformlayer.

the class ListJobExecutions method formatRaw.

@Override
public void formatRaw(Object o, PrintWriter writer) {
    JobExecutionList jobs = (JobExecutionList) o;
    switch(getFormat()) {
        case JSON:
            JsonHelper<JobExecutionList> jsonHelper = JsonHelper.build(JobExecutionList.class);
            boolean formatted = true;
            try {
                String json = jsonHelper.marshal(jobs, formatted);
                writer.println(json);
                return;
            } catch (IOException e) {
                throw new CliException("Error formatting for output", e);
            }
    }
    Ansi ansi = new Ansi(writer);
    for (JobExecutionData job : jobs) {
        JobState state = job.state;
        if (state != null) {
            switch(job.state) {
                case FAILED:
                    ansi.setColorRed();
                    break;
                case SUCCESS:
                    ansi.setColorGreen();
                    break;
                case RUNNING:
                    ansi.setColorBlue();
                    break;
                default:
                    ansi.setColorBlue();
                    break;
            }
        } else {
            ansi.setColorBlue();
        }
        writer.println(job.getJobId() + "/" + job.executionId);
    }
    ansi.reset();
}
Also used : CliException(com.fathomdb.cli.CliException) JobExecutionData(org.platformlayer.jobs.model.JobExecutionData) JobState(org.platformlayer.jobs.model.JobState) IOException(java.io.IOException) JobExecutionList(org.platformlayer.jobs.model.JobExecutionList) Ansi(com.fathomdb.cli.commands.Ansi)

Aggregations

Ansi (com.fathomdb.cli.commands.Ansi)7 UntypedItem (org.platformlayer.common.UntypedItem)3 CliException (com.fathomdb.cli.CliException)2 IOException (java.io.IOException)2 UntypedItemXml (org.platformlayer.UntypedItemXml)2 Source (javax.xml.transform.Source)1 DOMSource (javax.xml.transform.dom.DOMSource)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1 UntypedItemJson (org.platformlayer.UntypedItemJson)1 PlatformLayerKey (org.platformlayer.core.model.PlatformLayerKey)1 JobData (org.platformlayer.jobs.model.JobData)1 JobDataList (org.platformlayer.jobs.model.JobDataList)1 JobExecutionData (org.platformlayer.jobs.model.JobExecutionData)1 JobExecutionList (org.platformlayer.jobs.model.JobExecutionList)1 JobState (org.platformlayer.jobs.model.JobState)1