com.electronicpanopticon.wb.shell.commands.CoreCommands.java Source code

Java tutorial

Introduction

Here is the source code for com.electronicpanopticon.wb.shell.commands.CoreCommands.java

Source

package com.electronicpanopticon.wb.shell.commands;

import java.io.IOException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.shell.core.CommandMarker;
import org.springframework.shell.core.annotation.CliCommand;
import org.springframework.stereotype.Component;

import com.electronicpanopticon.wb.shell.plugins.CorePlugin;

@Component
public class CoreCommands implements CommandMarker {

    private static final String LICENSE_FILENAME = "LICENSE";

    @Autowired
    CorePlugin coreplugin;

    @Autowired
    DriverManagerDataSource dataSource;

    @CliCommand(value = "license", help = "Prints the license for this application.")
    public String licenseCommand() throws IOException {
        return this.coreplugin.getClasspathResourceAsString(LICENSE_FILENAME);
    }

    /**
     *
     * @return
     * @throws IOException
     */
    @CliCommand(value = "ping", help = "Tests the database connection.")
    public String pingCommand() throws IOException {

        JdbcTemplate jdbcTemplate = new JdbcTemplate(this.dataSource);
        jdbcTemplate.execute("SELECT relname FROM pg_class WHERE pg_table_is_visible(oid);");

        return "ping";
    }
}