Search in sources :

Example 1 with AuditType

use of com.gamebuster19901.excite.bot.audit.AuditType in project ExciteBot by TheGameCommunity.

the class Pardon method addPardonByAuditID.

@Nullable
@SuppressWarnings("rawtypes")
public static Pardon addPardonByAuditID(MessageContext context, long id) {
    try {
        Audit pardoned = Audit.getAuditById(context, id);
        if (pardoned == null) {
            context.sendMessage("Could not find audit #" + id);
            return null;
        }
        AuditType type = pardoned.getType();
        if (type == BAN) {
            Ban ban = (Ban) pardoned;
            if (ban.isPardoned()) {
                context.sendMessage(type + " #" + id + " is already pardoned.");
                return null;
            }
            Audit parent = Audit.addAudit(context, PARDON, context.getAuthor().getIdentifierName() + " pardoned " + ban.getBannedUsername());
            PreparedStatement st;
            st = Insertion.insertInto(AUDIT_PARDONS).setColumns(AUDIT_ID, PARDONED_AUDIT_ID).to(parent.getID(), pardoned.getID()).prepare(context, true);
            st.execute();
            Pardon ret = getPardonByAuditID(context, parent.getID());
            ret.parentData = parent;
            return ret;
        } else {
            context.sendMessage("Audit #" + id + " is a " + type + ", not a " + BAN);
            return null;
        }
    } catch (SQLException e) {
        throw new IOError(e);
    }
}
Also used : Audit(com.gamebuster19901.excite.bot.audit.Audit) AuditType(com.gamebuster19901.excite.bot.audit.AuditType) SQLException(java.sql.SQLException) IOError(java.io.IOError) PreparedStatement(com.gamebuster19901.excite.bot.database.sql.PreparedStatement) Nullable(javax.annotation.Nullable)

Example 2 with AuditType

use of com.gamebuster19901.excite.bot.audit.AuditType in project ExciteBot by TheGameCommunity.

the class Audit method createAudit.

@Nullable
@SuppressWarnings({ "rawtypes", "unchecked" })
protected static Audit createAudit(MessageContext context, Row row) throws SQLException {
    AuditType type = AuditType.getType(row);
    long auditID = row.getLong(AUDIT_ID);
    Class<? extends Audit> auditTypeClazz = AuditType.getType(row).getType();
    try {
        Constructor<? extends Audit> constructor = auditTypeClazz.getDeclaredConstructor(Row.class);
        constructor.setAccessible(true);
        Result result = Table.selectAllFromJoinedUsingWhere(new MessageContext(context.getAuthor()), AUDITS, type.getTable(), AUDIT_ID, new Comparison(AUDIT_ID, EQUALS, auditID));
        result.next();
        if (result.cursorValid()) {
            Row resultRow = result.getRow();
            return constructor.newInstance(resultRow);
        }
        return null;
    } catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
        throw new AssertionError(e);
    }
}
Also used : InvocationTargetException(java.lang.reflect.InvocationTargetException) Result(com.gamebuster19901.excite.bot.database.Result) Comparison(com.gamebuster19901.excite.bot.database.Comparison) MessageContext(com.gamebuster19901.excite.bot.command.MessageContext) Row(com.gamebuster19901.excite.bot.database.Row) Nullable(javax.annotation.Nullable)

Example 3 with AuditType

use of com.gamebuster19901.excite.bot.audit.AuditType in project ExciteBot by TheGameCommunity.

the class Audit method addAudit.

@Deprecated
@SuppressWarnings("rawtypes")
protected static Audit addAudit(MessageContext executor, MessageContext context, AuditType type, String description, Instant dateIssued) {
    PreparedStatement ps;
    try {
        ps = Insertion.insertInto(AUDITS).setColumns(AUDIT_TYPE, ISSUER_ID, ISSUER_NAME, DESCRIPTION, DATE_ISSUED).to(type, context.getAuthor().getID(), context.getAuthor().getName(), description, Instant.now()).prepare(executor, true);
        ps.execute();
        ResultSet results = ps.getGeneratedKeys();
        results.next();
        long auditID = results.getLong(GENERATED_KEY);
        Row row = Table.selectAllFromWhere(executor, AUDITS, new Comparison(AUDIT_ID, EQUALS, auditID)).getRow(true);
        return new Audit(row, type);
    } catch (SQLException e) {
        throw new IOError(e);
    }
}
Also used : Comparison(com.gamebuster19901.excite.bot.database.Comparison) SQLException(java.sql.SQLException) IOError(java.io.IOError) ResultSet(com.gamebuster19901.excite.bot.database.sql.ResultSet) PreparedStatement(com.gamebuster19901.excite.bot.database.sql.PreparedStatement) Row(com.gamebuster19901.excite.bot.database.Row)

Aggregations

Comparison (com.gamebuster19901.excite.bot.database.Comparison)2 Row (com.gamebuster19901.excite.bot.database.Row)2 PreparedStatement (com.gamebuster19901.excite.bot.database.sql.PreparedStatement)2 IOError (java.io.IOError)2 SQLException (java.sql.SQLException)2 Nullable (javax.annotation.Nullable)2 Audit (com.gamebuster19901.excite.bot.audit.Audit)1 AuditType (com.gamebuster19901.excite.bot.audit.AuditType)1 MessageContext (com.gamebuster19901.excite.bot.command.MessageContext)1 Result (com.gamebuster19901.excite.bot.database.Result)1 ResultSet (com.gamebuster19901.excite.bot.database.sql.ResultSet)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1