PC-966 Implement support for teams to be assigned to a report

This commit is contained in:
Keir Nellyer 2016-09-13 17:01:47 +01:00
parent f1d1585585
commit d115097eb9
2 changed files with 41 additions and 2 deletions

View File

@ -8,6 +8,7 @@ import java.util.Set;
import mineplex.core.report.ReportCategory;
import mineplex.core.report.ReportHandlerTask;
import mineplex.core.report.ReportResult;
import mineplex.core.report.ReportTeam;
/**
* Holds data for a Report.
@ -22,6 +23,7 @@ public class Report
private Integer _handlerId = null;
private Integer _snapshotId = null;
private ReportResult _reportResult = null;
private ReportTeam _assignedTeam = null;
private ReportHandlerTask _handlerTask = null;
@ -107,6 +109,16 @@ public class Report
_reportResult = reportResult;
}
public Optional<ReportTeam> getAssignedTeam()
{
return Optional.ofNullable(_assignedTeam);
}
public void setAssignedTeam(ReportTeam assignedTeam)
{
_assignedTeam = assignedTeam;
}
public ReportMessage getLatestMessage()
{
ReportMessage latest = null;

View File

@ -36,6 +36,7 @@ import mineplex.core.report.ReportManager;
import mineplex.core.report.ReportResult;
import mineplex.core.report.ReportResultType;
import mineplex.core.report.ReportRole;
import mineplex.core.report.ReportTeam;
import mineplex.serverdata.database.DBPool;
import org.apache.commons.lang3.StringUtils;
@ -47,7 +48,7 @@ public class ReportRepository
private static final String INSERT_REPORT = "INSERT INTO reports (suspectId, categoryId, snapshotId)\n" +
"VALUES (?, ?, ?);";
private static final String UPDATE_REPORT = "UPDATE reports SET snapshotId = ? WHERE id = ?;";
private static final String UPDATE_REPORT = "UPDATE reports SET snapshotId = ?, assignedTeam = ? WHERE id = ?;";
private static final String SET_REPORT_MESSAGE = "REPLACE INTO reportReasons (reportId, reporterId, reason, `server`, weight, `time`)" +
" VALUES (?, ?, ?, ?, ?, ?);";
@ -326,6 +327,21 @@ public class ReportRepository
report.setHandlerId(handlerId);
}
short teamId = resultSet.getShort("assignedTeam");
if (!resultSet.wasNull())
{
ReportTeam team = ReportTeam.getById(teamId);
if (team != null)
{
report.setAssignedTeam(team);
}
else
{
_logger.log(Level.WARNING, "Unrecognised report team found in database: " + teamId);
}
}
Set<ReportMessage> reportMessages = getReportReasons(connection, reportId);
reportMessages.forEach(report::addReportReason);
@ -511,7 +527,18 @@ public class ReportRepository
{
PreparedStatement updateReportStatement = connection.prepareStatement(UPDATE_REPORT);
updateReportStatement.setInt(1, snapshotIdOptional.get());
updateReportStatement.setLong(2, reportId);
Optional<ReportTeam> teamOptional = report.getAssignedTeam();
if (teamOptional.isPresent())
{
updateReportStatement.setShort(2, teamOptional.get().getDatabaseId());
}
else
{
updateReportStatement.setNull(2, Types.TINYINT);
}
updateReportStatement.setLong(3, reportId);
updateReportStatement.execute();
}
}