Handlers can now abort a report allowing it to be handled by another

member of staff
This commit is contained in:
Keir Nellyer 2016-08-18 14:42:53 +01:00
parent 3126d540e7
commit b4ae149d89
6 changed files with 104 additions and 7 deletions

View File

@ -331,6 +331,13 @@ public class ReportManager
return _reportRepository.updateReport(report);
}
public CompletableFuture<Void> setHandlerAborted(Report report, boolean aborted)
{
long reportId = report.getId().orElseThrow(() -> new IllegalStateException("Report id must be present."));
int handlerId = report.getHandlerId().orElseThrow(() -> new IllegalStateException("Handler must be assigned to report."));
return _reportRepository.setAborted(reportId, handlerId, aborted);
}
/**
* Checks if the player is allowed to create reports (ie not banned).
*

View File

@ -6,6 +6,7 @@ import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.MiniPlugin;
import mineplex.core.report.command.ReportAbortCommand;
import mineplex.core.report.command.ReportCloseCommand;
import mineplex.core.report.command.ReportCommand;
import mineplex.core.report.command.ReportHandleCommand;
@ -36,6 +37,7 @@ public class ReportPlugin extends MiniPlugin
addCommand(new ReportHandleCommand(this));
addCommand(new ReportCloseCommand(this));
addCommand(new ReportStatCommand(this));
addCommand(new ReportAbortCommand(this));
}
@EventHandler

View File

@ -0,0 +1,49 @@
package mineplex.core.report.command;
import org.bukkit.entity.Player;
import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.BukkitFuture;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.report.ReportManager;
import mineplex.core.report.ReportPlugin;
import mineplex.core.report.data.Report;
public class ReportAbortCommand extends CommandBase<ReportPlugin>
{
public ReportAbortCommand(ReportPlugin plugin)
{
super(plugin, Rank.MODERATOR, "reportabort");
}
@Override
public void Execute(Player player, String[] args)
{
if (args == null || args.length == 0)
{
ReportManager reportManager = Plugin.getReportManager();
reportManager.getReportHandling(player).thenApply(BukkitFuture.accept(reportOptional ->
{
if (reportOptional.isPresent())
{
Report report = reportOptional.get();
reportManager.setHandlerAborted(report, true).thenApply(BukkitFuture.accept(voidValue ->
UtilPlayer.message(player, F.main(ReportManager.getReportPrefix(report), "Aborted."))));
}
else
{
UtilPlayer.message(player, F.main(Plugin.getName(), "You aren't currently handling a report."));
}
}));
}
else
{
UtilPlayer.message(player, F.main(Plugin.getName(), C.cRed + "Invalid Usage: " + F.elem("/reportabort")));
}
}
}

View File

@ -34,6 +34,7 @@ public class ReportHandleCommand extends CommandBase<ReportPlugin>
{
ReportManager reportManager = Plugin.getReportManager();
ReportRepository reportRepository = reportManager.getReportRepository();
int accountId = _commandCenter.GetClientManager().getAccountId(player);
reportManager.isHandlingReport(player).thenAccept(isHandlingReport ->
{
@ -43,7 +44,7 @@ public class ReportHandleCommand extends CommandBase<ReportPlugin>
// the below fetches the ids of all unhandled reports and gets a Report object for each of these ids
// the priority of the report is then calculated and the results placed in a map
reportRepository.getUnhandledReports().thenCompose(reportRepository::getReports).thenAccept(reports ->
reportRepository.getUnhandledReports(accountId).thenCompose(reportRepository::getReports).thenAccept(reports ->
CompletableFuture.allOf(reports.stream().map(report ->
reportManager.calculatePriority(report).thenAccept(priority ->
{

View File

@ -57,20 +57,29 @@ public class ReportRepository
private static final String SET_REPORT_RESULT = "REPLACE INTO reportResults (reportId, resultId, reason, closedTime)" +
" VALUES (?, ?, ?, ?);";
private static final String SET_HANDLER_ABORTED = "UPDATE reportHandlers" +
" SET aborted = ?" +
" WHERE reportId = ?" +
" AND handlerId = ?;";
private static final String GET_REPORT = "SELECT * FROM reports" +
" LEFT JOIN reportHandlers ON reports.id = reportHandlers.reportId" +
" LEFT JOIN reportResults ON reports.id = reportResults.reportId" +
" WHERE reports.id = ?;";
" WHERE reports.id = ?" +
" AND reportHandlers.aborted = FALSE;";
private static final String GET_REPORT_REASONS = "SELECT * FROM reportReasons" +
" WHERE reportId = ?" +
" ORDER BY `time` ASC;";
// TODO confirm working
private static final String GET_UNHANDLED_REPORTS = "SELECT reports.id FROM reports" +
" LEFT JOIN reportResults ON reports.id = reportResults.reportId" +
" LEFT JOIN reportHandlers ON reports.id = reportHandlers.reportId" +
" WHERE reportResults.reportId IS NULL" +
" AND reportHandlers.reportId IS NULL;";
"WHERE reportResults.reportId IS NULL" +
" AND (reportHandlers.reportId IS NULL" +
" OR (reportHandlers.aborted IS TRUE" +
" AND reportHandlers.handlerId NOT ?));";
private static final String GET_ONGOING_REPORT = "SELECT reports.id FROM reports" +
" LEFT JOIN reportResults ON reports.id = reportResults.reportId" +
@ -137,7 +146,7 @@ public class ReportRepository
_logger = logger;
}
public CompletableFuture<List<Long>> getUnhandledReports()
public CompletableFuture<List<Long>> getUnhandledReports(int accountId)
{
CompletableFuture<List<Long>> future = CompletableFuture.supplyAsync(() ->
{
@ -146,6 +155,7 @@ public class ReportRepository
try (Connection connection = DBPool.getAccount().getConnection())
{
PreparedStatement preparedStatement = connection.prepareStatement(GET_UNHANDLED_REPORTS);
preparedStatement.setInt(1, accountId);
ResultSet resultSet = preparedStatement.executeQuery();
while (resultSet.next())
@ -546,6 +556,34 @@ public class ReportRepository
return future;
}
public CompletableFuture<Void> setAborted(long reportId, int handlerId, boolean aborted)
{
CompletableFuture<Void> future = CompletableFuture.supplyAsync(() ->
{
try (Connection connection = DBPool.getAccount().getConnection())
{
PreparedStatement preparedStatement = connection.prepareStatement(SET_HANDLER_ABORTED);
preparedStatement.setBoolean(1, aborted);
preparedStatement.setLong(2, reportId);
preparedStatement.setInt(3, handlerId);
preparedStatement.execute();
return null;
}
catch (SQLException e)
{
throw new RuntimeException(e);
}
});
future.exceptionally(throwable ->
{
_logger.log(Level.SEVERE, "Error setting handler report as aborted.", throwable);
return null;
});
return future;
}
public CompletableFuture<Multimap<ReportRole, Long>> getAccountStatistics(int accountId)
{
CompletableFuture<Multimap<ReportRole, Long>> future = CompletableFuture.supplyAsync(() ->

View File

@ -90,9 +90,9 @@
{
$connection = getConnection("ACCOUNT");
$statement = $connection->prepare('SELECT reports.suspectId, reports.categoryId, reportHandlers.handlerId FROM reports
LEFT JOIN reportHandlers ON reports.id = reportHandlers.reportId
LEFT JOIN reportHandlers ON reports.id = reportHandlers.reportId AND reportHandlers.aborted IS FALSE
LEFT JOIN reportResults ON reports.id = reportResults.reportId
WHERE reports.id = ?');
WHERE reports.id = ?;');
$statement->bind_param('i', $reportId);
$statement->execute();