Search in sources :

Example 26 with ShellTable

use of org.apache.karaf.shell.support.table.ShellTable in project ddf by codice.

the class RangeCommand method executeWithSubject.

@Override
protected Object executeWithSubject() throws Exception {
    Filter filter;
    Date wayInTheFuture = new DateTime().plusYears(5000).toDate();
    Date endDate = wayInTheFuture;
    SimpleDateFormat formatter = new SimpleDateFormat(DATE_FORMAT);
    if (WILDCARD.equals(rangeBeginning) && WILDCARD.equals(rangeEnd)) {
        filter = filterBuilder.attribute(attributeName).before().date(endDate);
    } else if (WILDCARD.equals(rangeBeginning) && !WILDCARD.equals(rangeEnd)) {
        try {
            endDate = formatter.parse(rangeEnd);
        } catch (ParseException e) {
            throw new InterruptedException("Could not parse second parameter [" + rangeEnd + "]");
        }
        filter = filterBuilder.attribute(attributeName).before().date(endDate);
    } else if (!WILDCARD.equals(rangeBeginning) && WILDCARD.equals(rangeEnd)) {
        try {
            Date startDate = formatter.parse(rangeBeginning);
            filter = filterBuilder.attribute(attributeName).during().dates(startDate, endDate);
        } catch (ParseException e) {
            throw new InterruptedException("Could not parse first parameter [" + rangeBeginning + "]");
        }
    } else {
        try {
            Date startDate = formatter.parse(rangeBeginning);
            endDate = formatter.parse(rangeEnd);
            filter = filterBuilder.attribute(attributeName).during().dates(startDate, endDate);
        } catch (ParseException e) {
            throw new InterruptedException("Could not parse date parameters.");
        }
    }
    QueryImpl query = new QueryImpl(filter);
    query.setPageSize(MAX_RESULTS);
    query.setSortBy(new SortByImpl(attributeName, SortOrder.DESCENDING.name()));
    QueryRequest queryRequest = new QueryRequestImpl(query);
    SourceResponse response = getCatalog().query(queryRequest);
    List<Result> results = response.getResults();
    final ShellTable table = new ShellTable();
    table.column(NUMBER);
    table.column(ID);
    table.column(attributeName);
    table.column(TITLE).maxSize(MAX_LENGTH);
    table.emptyTableText("No results");
    int i = 1;
    for (Result result : results) {
        Attribute attribute = result.getMetacard().getAttribute(attributeName);
        if (attribute != null && attribute.getValue() != null) {
            String returnedDate = new DateTime(attribute.getValue()).toString(DATETIME_FORMATTER);
            String title = result.getMetacard().getTitle();
            final Row row = table.addRow();
            row.addContent(i, result.getMetacard().getId(), returnedDate, title);
        }
        i++;
    }
    table.print(console, true);
    return null;
}
Also used : QueryRequest(ddf.catalog.operation.QueryRequest) SourceResponse(ddf.catalog.operation.SourceResponse) Attribute(ddf.catalog.data.Attribute) Date(java.util.Date) DateTime(org.joda.time.DateTime) Result(ddf.catalog.data.Result) QueryImpl(ddf.catalog.operation.impl.QueryImpl) ShellTable(org.apache.karaf.shell.support.table.ShellTable) Filter(org.opengis.filter.Filter) SortByImpl(ddf.catalog.filter.impl.SortByImpl) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) ParseException(java.text.ParseException) Row(org.apache.karaf.shell.support.table.Row) SimpleDateFormat(java.text.SimpleDateFormat)

Example 27 with ShellTable

use of org.apache.karaf.shell.support.table.ShellTable in project cxf by apache.

the class ListEndpointsCommand method execute.

@Override
public Object execute() throws Exception {
    List<Bus> busses;
    if (name == null) {
        busses = getBusses();
    } else {
        Bus b = getBus(name);
        if (b != null) {
            busses = Collections.singletonList(getBus(name));
        } else {
            busses = Collections.emptyList();
        }
    }
    ShellTable table = new ShellTable();
    if (terminal != null && terminal.getWidth() > 0) {
        table.size(terminal.getWidth());
    }
    table.column("Name");
    table.column("State");
    table.column("Address");
    table.column("BusID");
    for (Bus b : busses) {
        ServerRegistry reg = b.getExtension(ServerRegistry.class);
        List<Server> servers = reg.getServers();
        for (Server serv : servers) {
            String qname = serv.getEndpoint().getEndpointInfo().getName().getLocalPart();
            String started = serv.isStarted() ? "Started" : "Stopped";
            String address = serv.getEndpoint().getEndpointInfo().getAddress();
            if (fullAddress) {
                address = toFullAddress(address);
            }
            String busId = b.getId();
            table.addRow().addContent(qname, started, address, busId);
        }
    }
    table.print(System.out, !noFormat);
    return null;
}
Also used : Bus(org.apache.cxf.Bus) ShellTable(org.apache.karaf.shell.support.table.ShellTable) Server(org.apache.cxf.endpoint.Server) ServerRegistry(org.apache.cxf.endpoint.ServerRegistry)

Example 28 with ShellTable

use of org.apache.karaf.shell.support.table.ShellTable in project cxf by apache.

the class ListBussesCommand method execute.

@Override
public Object execute() throws Exception {
    List<Bus> busses = getBusses();
    ShellTable table = new ShellTable();
    if (terminal != null && terminal.getWidth() > 0) {
        table.size(terminal.getWidth());
    }
    table.column("Name");
    table.column("State");
    for (Bus bus : busses) {
        String name = bus.getId();
        String state = bus.getState().toString();
        table.addRow().addContent(name, state);
    }
    table.print(System.out, !noFormat);
    return null;
}
Also used : Bus(org.apache.cxf.Bus) ShellTable(org.apache.karaf.shell.support.table.ShellTable)

Example 29 with ShellTable

use of org.apache.karaf.shell.support.table.ShellTable in project fuse-karaf by jboss-fuse.

the class ListCredentialStore method execute.

@Override
public Object execute() throws Exception {
    final ShellTable table = new ShellTable();
    table.column(new Col("Alias"));
    table.column(new Col("Reference"));
    final CredentialStore credentialStore = CredentialStoreHelper.credentialStoreFromEnvironment();
    for (final String alias : credentialStore.getAliases()) {
        table.addRow().addContent(alias, CredentialStoreHelper.referenceForAlias(alias));
    }
    table.print(System.out);
    return null;
}
Also used : Col(org.apache.karaf.shell.support.table.Col) ShellTable(org.apache.karaf.shell.support.table.ShellTable) CredentialStore(org.wildfly.security.credential.store.CredentialStore)

Example 30 with ShellTable

use of org.apache.karaf.shell.support.table.ShellTable in project karaf by apache.

the class GetCommand method execute.

@Override
public Object execute() throws Exception {
    ShellTable table = new ShellTable();
    table.column("ID");
    table.column("Flight");
    table.column("Customer");
    Booking booking = bookingService.get(id);
    table.addRow().addContent(booking.getId(), booking.getFlight(), booking.getCustomer());
    table.print(System.out);
    return null;
}
Also used : ShellTable(org.apache.karaf.shell.support.table.ShellTable) Booking(org.apache.karaf.examples.jpa.Booking)

Aggregations

ShellTable (org.apache.karaf.shell.support.table.ShellTable)59 Row (org.apache.karaf.shell.support.table.Row)10 Col (org.apache.karaf.shell.support.table.Col)7 ArrayList (java.util.ArrayList)4 Bundle (org.osgi.framework.Bundle)4 Map (java.util.Map)3 Feature (org.apache.karaf.features.Feature)3 Repository (org.apache.karaf.features.Repository)3 List (java.util.List)2 TreeMap (java.util.TreeMap)2 Bus (org.apache.cxf.Bus)2 Booking (org.apache.karaf.examples.jdbc.api.Booking)2 Booking (org.apache.karaf.examples.jpa.Booking)2 MavenRepositoryURL (org.apache.karaf.maven.core.MavenRepositoryURL)2 Attribute (ddf.catalog.data.Attribute)1 Result (ddf.catalog.data.Result)1 SortByImpl (ddf.catalog.filter.impl.SortByImpl)1 QueryRequest (ddf.catalog.operation.QueryRequest)1 SourceResponse (ddf.catalog.operation.SourceResponse)1 QueryImpl (ddf.catalog.operation.impl.QueryImpl)1