Skip to content

Commit

Permalink
Fix: #59
Browse files Browse the repository at this point in the history
  • Loading branch information
jkingster committed Jun 7, 2024
1 parent 8ecad1f commit 04f5c29
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 80 deletions.
4 changes: 2 additions & 2 deletions src/main/java/io/jacobking/quickticket/gui/alert/Alerts.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ public static void showErrorOverride(final String title, final String content) {
.showAndWait();
}

public static Optional<String> showInput(final String title, final String content, final String defaultValue) {
return new InputDialogBuilder(defaultValue)
public static Optional<String> showInput(final String title, final String content) {
return new InputDialogBuilder()
.buildDialog(title, content)
.result();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@
public class InputDialogBuilder {

private final Dialog<String> dialog;
private final String defaultValue;

public InputDialogBuilder(String defaultValue) {
public InputDialogBuilder() {
this.dialog = new Dialog<>();
this.defaultValue = defaultValue;
initializeStyle();
}

Expand Down Expand Up @@ -49,9 +47,10 @@ public InputDialogBuilder buildDialog(final String title, final String content)
if (type == ButtonType.YES) {
return textArea.getText();
} else if (type == ButtonType.NO) {
return null;
final String comment = textArea.getText();
return comment.isEmpty() ? "" : comment;
}
return defaultValue;
return "";
});
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,43 +217,48 @@ private void addListener(final Label label, final ObservableList<TicketModel> ta
ticketModel.statusProperty().setValue(StatusType.RESOLVED);

if (ticket.update(ticketModel, originalStatus)) {
Alerts.showInput(
"Notify Employee",
"Would you like to notify the employee the ticket is resolved along with adding an ending comment?",
"No resolving comment was added."
).ifPresentOrElse(comment -> {
final EmployeeModel model = employee.getModel(ticketModel.getEmployeeId());
if (model == null) {
Alerts.showError("Error notifying employee.", "Could not retrieve employee.", "Is there an employee attached to this ticket?");
return;
}
pushNotifyAlert(ticketModel);
}
}

final String email = model.getEmail();
if (email.isEmpty()) {
Alerts.showError(
"Error notifying employee.",
"Could not send notification e-mail.",
"There is no e-mail attached for this employee."
);
return;
}
private void pushNotifyAlert(final TicketModel ticketModel) {
Alerts.showInput("Resolving Ticket", "Would you like to notify the employee this ticket is resolved? Please provide any closing comments.")
.ifPresentOrElse(resolvingComment -> {
if (resolvingComment.isEmpty()) {
postCommentOnTicket(ticketModel, "No resolving comment added.");
return;
}

new EmailBuilder(email, EmailBuilder.EmailType.RESOLVED)
.format(
ticketModel.getId(),
ticketModel.getTitle(),
DateUtil.formatDateTime(DateUtil.DateFormat.DATE_TIME_ONE, ticketModel.getCreation()),
model.getFullName(),
comment
)
.email(emailConfig)
.setSubject(getSubject(ticketModel))
.sendEmail();

postCommentOnTicket(ticketModel, comment);
}, () -> postCommentOnTicket(ticketModel, "No resolving comment."));
ticketTable.refresh();
}
final int employeeId = ticketModel.getEmployeeId();
final EmployeeModel employeeModel = employee.getModel(employeeId);
if (employeeModel == null) {
Alerts.showError("Failed to send e-mail.", "Could not notify employee ticket is resolved.", "Could not fetch employee record.");
return;
}

final String employeeEmail = employeeModel.getEmail();
if (employeeEmail.isEmpty()) {
Alerts.showError("Failed to send e-mail.", "Could not notify employee ticket is resolved.", "Employee has no e-mail attached to employee record.");
return;
}

postCommentOnTicket(ticketModel, resolvingComment);
sendResolvedEmail(ticketModel, employeeEmail, resolvingComment, employeeModel);
}, () -> postCommentOnTicket(ticketModel, "No resolving comment added."));
}

private void sendResolvedEmail(final TicketModel ticketModel, final String email, final String resolvingComment, final EmployeeModel employeeModel) {
new EmailBuilder(email, EmailBuilder.EmailType.RESOLVED)
.format(
ticketModel.getId(),
ticketModel.getTitle(),
DateUtil.formatDateTime(DateUtil.DateFormat.DATE_TIME_ONE, ticketModel.getCreation()),
employeeModel.getFullName(),
resolvingComment
)
.email(emailConfig)
.setSubject(getSubject(ticketModel))
.sendEmail();
}

private String getSubject(final TicketModel ticketModel) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,48 +243,59 @@ private <T> void reloadPostUpdate(final SearchableComboBox<T> box, final PopOver
}

@FXML private void onMarkResolved() {
final StatusType originalStatus = ticketModel.statusProperty().getValue();
ticketModel.statusProperty().setValue(StatusType.RESOLVED);
postSystemComment("System", "This ticket has been marked resolved.");

if (ticket.update(ticketModel)) {
refreshTable();

Alerts.showInput(
"Notify Employee",
"Would you like to notify the employee the ticket is resolved along with adding an ending comment?",
"No resolving comment was added."
).ifPresentOrElse(comment -> {
final EmployeeModel model = employee.getModel(ticketModel.getEmployeeId());
if (model == null) {
Alerts.showError("Error notifying employee.", "Could not retrieve employee.", "Is there an employee attached to this ticket?");
return;
}
if (ticket.update(ticketModel, originalStatus)) {
System.out.println("?");
pushNotifyAlert(ticketModel);
}
}

final String email = model.getEmail();
if (email.isEmpty()) {
Alerts.showError(
"Error notifying employee.",
"Could not send notification e-mail.",
"There is no e-mail attached for this employee."
);
return;
}
private void pushNotifyAlert(final TicketModel ticketModel) {
Alerts.showInput("Resolving Ticket", "Would you like to notify the employee this ticket is resolved? Please provide any closing comments.")
.ifPresentOrElse(resolvingComment -> {
if (resolvingComment.isEmpty()) {
postCommentOnTicket(ticketModel, "No resolving comment added.");
return;
}

final int employeeId = ticketModel.getEmployeeId();
final EmployeeModel employeeModel = employee.getModel(employeeId);
if (employeeModel == null) {
Alerts.showError("Failed to send e-mail.", "Could not notify employee ticket is resolved.", "Could not fetch employee record.");
return;
}

final String employeeEmail = employeeModel.getEmail();
if (employeeEmail.isEmpty()) {
Alerts.showError("Failed to send e-mail.", "Could not notify employee ticket is resolved.", "Employee has no e-mail attached to employee record.");
return;
}

postCommentOnTicket(ticketModel, resolvingComment);
sendResolvedEmail(ticketModel, employeeEmail, resolvingComment, employeeModel);
}, () -> postCommentOnTicket(ticketModel, "No resolving comment added."));
}

new EmailBuilder(email, EmailBuilder.EmailType.RESOLVED)
.format(
ticketModel.getId(),
ticketModel.getTitle(),
DateUtil.formatDateTime(DateUtil.DateFormat.DATE_TIME_ONE, ticketModel.getCreation()),
model.getFullName(),
comment
)
.email(emailConfig)
.setSubject(getSubject(ticketModel))
.sendEmail();

postSystemComment("Ticket Resolved", comment);
}, () -> postSystemComment("Ticket Resolved", "No resolving comment."));
}
private void postCommentOnTicket(final TicketModel ticketModel, final String systemComment) {
comment.createModel(new Comment().setTicketId(ticketModel.getId())
.setPostedOn(DateUtil.nowAsLocalDateTime(DateUtil.DateFormat.DATE_TIME_ONE))
.setPost(String.format("[%s]: %s", "System", systemComment)));
}

private void sendResolvedEmail(final TicketModel ticketModel, final String email, final String resolvingComment, final EmployeeModel employeeModel) {
new EmailBuilder(email, EmailBuilder.EmailType.RESOLVED)
.format(
ticketModel.getId(),
ticketModel.getTitle(),
DateUtil.formatDateTime(DateUtil.DateFormat.DATE_TIME_ONE, ticketModel.getCreation()),
employeeModel.getFullName(),
resolvingComment
)
.email(emailConfig)
.setSubject(getSubject(ticketModel))
.sendEmail();
}

private String getSubject(final TicketModel ticketModel) {
Expand Down

0 comments on commit 04f5c29

Please sign in to comment.