Search in sources :

Example 1 with ActiveSearch

use of org.codice.ddf.resourcemanagement.query.plugin.ActiveSearch in project ddf by codice.

the class PrintActiveSearchesCommand method printActiveSearchesToConsole.

/**
     * Called by the execute method when the catalog:printacticesearches command is called by the shell.
     * Loops through the {@link ActiveSearch} {@link Map} to print a formatted table representation
     * of all {@link ActiveSearch}'s in the {@link ActiveSearch} {@link Map}
     */
void printActiveSearchesToConsole() {
    if (queryMonitor == null) {
        LOGGER.debug("QueryMonitorImpl not yet instantiated. Cannot printActiveSearchesToConsole().");
        return;
    }
    Map<UUID, ActiveSearch> activeSearchMap = queryMonitor.getActiveSearches();
    console.println();
    String colorString = Ansi.ansi().fg(Ansi.Color.CYAN).toString();
    console.print(colorString);
    console.print(String.format(FORMAT_STRING, "User Info", "Source", "Search Criteria", "Start Time", "Unique ID"));
    console.println(Ansi.ansi().reset().toString());
    if (activeSearchMap == null) {
        LOGGER.debug("Retrieving ActiveSearch information from queryMonitor returned null. Cannot printActiveSearchesToConsole().");
        return;
    }
    for (ActiveSearch as : activeSearchMap.values()) {
        console.print(as.toFormattedString());
    }
}
Also used : ActiveSearch(org.codice.ddf.resourcemanagement.query.plugin.ActiveSearch) UUID(java.util.UUID)

Example 2 with ActiveSearch

use of org.codice.ddf.resourcemanagement.query.plugin.ActiveSearch in project ddf by codice.

the class MonitorCommandsTest method testPrintSearchTableToConsole.

@Test
public void testPrintSearchTableToConsole() {
    final ByteArrayOutputStream[] baos = new ByteArrayOutputStream[1];
    PrintActiveSearchesCommand printCommand = new PrintActiveSearchesCommand(qmpi) {

        @Override
        PrintStream getPrintStream() {
            baos[0] = new ByteArrayOutputStream();
            return new PrintStream(baos[0]);
        }
    };
    qmpi.setRemoveSearchAfterComplete(false);
    UUID u = UUID.randomUUID();
    ActiveSearch as = new ActiveSearch(QUERY_TEXT, null, u, CLIENT_TEXT);
    qmpi.addActiveSearch(as);
    printCommand.printActiveSearchesToConsole();
    assertThat(baos[0].toString(), containsString(QUERY_TEXT));
    assertThat(baos[0].toString(), containsString(u.toString()));
}
Also used : PrintStream(java.io.PrintStream) ActiveSearch(org.codice.ddf.resourcemanagement.query.plugin.ActiveSearch) ByteArrayOutputStream(java.io.ByteArrayOutputStream) UUID(java.util.UUID) Test(org.junit.Test)

Example 3 with ActiveSearch

use of org.codice.ddf.resourcemanagement.query.plugin.ActiveSearch in project ddf by codice.

the class TestQueryMonitor method generateActiveSearch.

private ActiveSearch generateActiveSearch(String name, String uuid) {
    Source source = mock(Source.class);
    doReturn(SOURCE).when(source).getId();
    Date date = new Date();
    ActiveSearch activeSearch = mock(ActiveSearch.class);
    doReturn(source).when(activeSearch).getSource();
    doReturn(name).when(activeSearch).getClientInfo();
    doReturn(CQL).when(activeSearch).getCQL();
    doReturn(date).when(activeSearch).getStartTime();
    doReturn(UUID.fromString(uuid)).when(activeSearch).getUniqueID();
    return activeSearch;
}
Also used : ActiveSearch(org.codice.ddf.resourcemanagement.query.plugin.ActiveSearch) Source(ddf.catalog.source.Source) Date(java.util.Date)

Aggregations

ActiveSearch (org.codice.ddf.resourcemanagement.query.plugin.ActiveSearch)3 UUID (java.util.UUID)2 Source (ddf.catalog.source.Source)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 PrintStream (java.io.PrintStream)1 Date (java.util.Date)1 Test (org.junit.Test)1