Search in sources :

Example 6 with AdminTask

use of web.AdminTask in project common by zenlunatics.

the class FileColumn method checkFilesInDatabase.

// --------------------------------------------------------------------------
@AdminTask({ "table", "column", "show only problems" })
public static void checkFilesInDatabase(String table, String column, boolean show_only_problems, Request request) {
    HTMLWriter writer = request.writer;
    try {
        FileColumn file_column = (FileColumn) request.site.getViewDef(table, request.db).getColumn(column);
        String dir_column = file_column.getDirColumn();
        StringBuilder sql = new StringBuilder("SELECT ").append(column);
        if (dir_column != null)
            sql.append(',').append(dir_column);
        sql.append(" FROM ").append(table).append(" ORDER BY ");
        if (dir_column != null)
            sql.append(dir_column).append(',');
        sql.append(column);
        ResultSet rs = request.db.select(sql.toString());
        writer.write("<table class=\"table table-condensed table-bordered\" style=\"width:auto;\"><tr><th>filename</th>");
        if (dir_column != null)
            writer.write("<th>dir column</th>");
        writer.write("<th>status</th></tr>");
        while (rs.next()) {
            String dir_column_value = null;
            String filename = rs.getString(1);
            String problem = null;
            if (filename == null)
                problem = column + " is null";
            else {
                if (dir_column != null)
                    dir_column_value = rs.getString(2);
                FilePathStringBuilder file_path = file_column.getDirectory(dir_column_value, request.site);
                file_path.append(filename);
                if (!new File(file_path.toString()).exists())
                    problem = "missing";
            }
            if (problem != null || !show_only_problems) {
                writer.write("<tr><td>");
                if (filename != null)
                    writer.write(filename);
                if (dir_column != null) {
                    writer.write("</td><td>");
                    if (dir_column_value != null)
                        writer.write(dir_column_value);
                }
                writer.write("</td><td>").write(problem == null ? "ok" : problem).write("</td></tr>");
            }
        }
        writer.write("</table>");
        rs.getStatement().close();
    } catch (SQLException e) {
        throw new RuntimeException(e);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : HTMLWriter(web.HTMLWriter) FilePathStringBuilder(web.FilePathStringBuilder) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) FilePathStringBuilder(web.FilePathStringBuilder) IOException(java.io.IOException) File(java.io.File) AdminTask(web.AdminTask)

Example 7 with AdminTask

use of web.AdminTask in project common by zenlunatics.

the class FileColumn method checkFilesNotInDatabase.

// --------------------------------------------------------------------------
@AdminTask({ "table", "column" })
public static void checkFilesNotInDatabase(final String table, final String column, final Request request) {
    try {
        FileColumn file_column = (FileColumn) request.site.getViewDef(table, request.db).getColumn(column);
        request.writer.h3("Files not in database");
        new File(file_column.getDirectory(request).toString()).list(new FilenameFilter() {

            @Override
            public boolean accept(File file, String filename) {
                if (!request.db.rowExists(table, column + "='" + DBConnection.escape(filename) + "'"))
                    try {
                        request.writer.write(filename).br();
                    } catch (IOException e) {
                    }
                return false;
            }
        });
    } catch (IOException e) {
        request.abort(e);
    }
}
Also used : FilenameFilter(java.io.FilenameFilter) IOException(java.io.IOException) File(java.io.File) AdminTask(web.AdminTask)

Example 8 with AdminTask

use of web.AdminTask in project common by zenlunatics.

the class Pictures method syncPictures.

// --------------------------------------------------------------------------
@AdminTask
public void syncPictures(Request request) {
    FilePathStringBuilder file_path = request.site.getBaseFilePath();
    file_path.append(m_table);
    String pictures_directory = file_path.toString() + File.separator;
    String[] files = new File(pictures_directory).list();
    for (String file : files) {
        String id = file;
        int index = id.indexOf('.');
        if (index != -1)
            id = id.substring(0, index);
        if (Character.isDigit(file.charAt(0)) && request.db.lookupString("id", "pictures", Integer.parseInt(id)) == null)
            new File(pictures_directory + file).delete();
    }
    files = new File(pictures_directory + "thumbs/").list();
    for (String file : files) if (Character.isDigit(file.charAt(0))) {
        String id = file;
        int index = id.indexOf('.');
        if (index != -1)
            id = id.substring(0, index);
        if (request.db.lookupString("id", "pictures", Integer.parseInt(id)) == null)
            new File(pictures_directory + "thumbs/" + file).delete();
    }
}
Also used : FilePathStringBuilder(web.FilePathStringBuilder) File(java.io.File) AdminTask(web.AdminTask)

Example 9 with AdminTask

use of web.AdminTask in project common by zenlunatics.

the class Pictures method recordAllSizes.

// --------------------------------------------------------------------------
@AdminTask
public void recordAllSizes(Request request) {
    ResultSet rs = request.db.select(new Select("id,file").from(m_table));
    try {
        while (rs.next()) {
            BufferedImage image = ImageIO.read(new File(request.site.getBaseFilePath().append(m_table).append(rs.getString("file")).toString()));
            request.db.update(m_table, "width=" + image.getWidth() + ",height=" + image.getHeight(), rs.getInt("id"));
        }
        rs.getStatement().close();
    } catch (SQLException e) {
        request.abort(e);
    } catch (IOException e) {
        request.abort(e);
    }
}
Also used : SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) Select(db.Select) IOException(java.io.IOException) File(java.io.File) BufferedImage(java.awt.image.BufferedImage) AdminTask(web.AdminTask)

Example 10 with AdminTask

use of web.AdminTask in project common by zenlunatics.

the class News method rebuild.

// --------------------------------------------------------------------------
@AdminTask
public void rebuild(String provider_name, Request request) throws IOException {
    NewsProvider provider = getProvider(provider_name);
    if (provider == null) {
        request.writer.write("provider " + provider_name + " not found");
        return;
    }
    request.db.delete("news", "provider='" + provider_name + "'");
    try {
        ResultSet rs = request.db.select(new Select("*").from(provider.getTable()));
        NameValuePairs name_value_pairs = new NameValuePairs();
        while (rs.next()) {
            name_value_pairs.clear();
            name_value_pairs.set("provider", provider_name);
            name_value_pairs.set("item_id", rs.getInt("id"));
            name_value_pairs.set("_owner_", rs.getInt("_owner_"));
            String timestamp = rs.getString("_timestamp_");
            name_value_pairs.set("_timestamp_", timestamp);
            name_value_pairs.set("last_update", timestamp);
            for (JDBCColumn column : provider.m_duplicate_columns) name_value_pairs.set(column.name, rs.getString(column.name));
            request.db.insert("news", name_value_pairs);
        }
        rs.getStatement().close();
    } catch (SQLException e) {
        request.abort(e);
    }
}
Also used : NameValuePairs(db.NameValuePairs) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) Select(db.Select) JDBCColumn(db.JDBCColumn) AdminTask(web.AdminTask)

Aggregations

AdminTask (web.AdminTask)16 IOException (java.io.IOException)9 File (java.io.File)7 SQLException (java.sql.SQLException)7 Select (db.Select)6 ResultSet (java.sql.ResultSet)5 Session (javax.mail.Session)4 FilePathStringBuilder (web.FilePathStringBuilder)4 LocalDate (java.time.LocalDate)3 Properties (java.util.Properties)3 MessagingException (javax.mail.MessagingException)3 AddressException (javax.mail.internet.AddressException)3 MimeMessage (javax.mail.internet.MimeMessage)3 ICalendar (biweekly.ICalendar)2 VEvent (biweekly.component.VEvent)2 MailConnectException (com.sun.mail.util.MailConnectException)2 DBConnection (db.DBConnection)2 NameValuePairs (db.NameValuePairs)2 FileNotFoundException (java.io.FileNotFoundException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2