Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;

import org.apache.commons.lang3.StringUtils;

Expand All @@ -23,7 +24,7 @@ public class QueueTicketAssignments {

/**
* The object has: service point/room name as key for ease of search and update and object with
* status and ticket number
* status, ticket number, and location
*/
private static final Map<String, TicketAssignment> ACTIVE_QUEUE_TICKETS = new HashMap<>();

Expand All @@ -33,44 +34,65 @@ public class QueueTicketAssignments {
* @param servicePointName
* @param ticketNumber
* @param status
* @param locationUuid - optional location UUID to associate with the ticket
*/
synchronized public static void updateTicketAssignment(String servicePointName, String ticketNumber, String status) {
synchronized public static void updateTicketAssignment(String servicePointName, String ticketNumber, String status,
String locationUuid) {

if (StringUtils.isNotBlank(servicePointName) && StringUtils.isNotBlank(ticketNumber)
&& StringUtils.isNotBlank(status)) {

/** remove the ticket number from any assignment */

// Remove the ticket number from any assignment
for (String key : ACTIVE_QUEUE_TICKETS.keySet()) {
TicketAssignment assignment = ACTIVE_QUEUE_TICKETS.get(key);
if (assignment.getTicketNumber().equals(ticketNumber)) {
ACTIVE_QUEUE_TICKETS.remove(key);
if (status.equals("completed")) {
return;
}
break;
}
ACTIVE_QUEUE_TICKETS.entrySet().removeIf(entry -> ticketNumber.equals(entry.getValue().getTicketNumber()));

// If ticket is completed, no need to reassign
if ("completed".equalsIgnoreCase(status)) {
return;
}

/** Assign ticket to a room if the room already exist */
// Assign ticket to a room if the room already exists
if (ACTIVE_QUEUE_TICKETS.containsKey(servicePointName)) {
TicketAssignment tAssignment = ACTIVE_QUEUE_TICKETS.get(servicePointName);
tAssignment.setStatus(status);
tAssignment.setTicketNumber(ticketNumber);
tAssignment.setLocationUuid(locationUuid);
ACTIVE_QUEUE_TICKETS.put(servicePointName, tAssignment);
} else {
// Else create a new assignment
TicketAssignment ticketAssignment = new TicketAssignment(status, ticketNumber);
TicketAssignment ticketAssignment = new TicketAssignment(status, ticketNumber, locationUuid);
ACTIVE_QUEUE_TICKETS.put(servicePointName, ticketAssignment);
}
}
}

/**
* Overloaded method for backward compatibility - calls main method with null location
*/
synchronized public static void updateTicketAssignment(String servicePointName, String ticketNumber, String status) {
updateTicketAssignment(servicePointName, ticketNumber, status, null);
}

public static Map<String, TicketAssignment> getActiveTicketAssignments() {
return ACTIVE_QUEUE_TICKETS;
}

/**
* Get active ticket assignments filtered by location
*
* @param locationUuid - the location UUID to filter by
* @return Map of filtered ticket assignments for the specified location
*/
public static Map<String, TicketAssignment> getActiveTicketAssignmentsByLocation(String locationUuid) {
if (StringUtils.isBlank(locationUuid)) {
return ACTIVE_QUEUE_TICKETS;
}

return ACTIVE_QUEUE_TICKETS.entrySet().stream().filter(entry -> {
String ticketLocation = entry.getValue().getLocationUuid();
return ticketLocation != null && ticketLocation.equals(locationUuid);
}).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
}

/**
* Extracts the request body and returns it as a string
*
Expand All @@ -97,9 +119,17 @@ public static class TicketAssignment {

private String ticketNumber;

public TicketAssignment(String status, String ticketNumber) {
private String locationUuid;

public TicketAssignment(String status, String ticketNumber, String locationUuid) {
this.status = status;
this.ticketNumber = ticketNumber;
this.locationUuid = locationUuid;
}

// Backward compatible constructor
public TicketAssignment(String status, String ticketNumber) {
this(status, ticketNumber, null);
}

public String getStatus() {
Expand All @@ -117,5 +147,13 @@ public String getTicketNumber() {
public void setTicketNumber(String ticketNumber) {
this.ticketNumber = ticketNumber;
}

public String getLocationUuid() {
return locationUuid;
}

public void setLocationUuid(String locationUuid) {
this.locationUuid = locationUuid;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
Expand Down Expand Up @@ -110,7 +111,8 @@ public Object getVisitQueueEntries(HttpServletRequest request, HttpServletRespon
result.add("results", visitQueueEntries);
RequestContext requestContext = RestUtil.getRequestContext(request, response, Representation.REF);
Map<String, String[]> parameters = new HashMap<String, String[]>(requestContext.getRequest().getParameterMap());
// The queueEntryResource does not limit to active by default, but the legacy resource does
// The queueEntryResource does not limit to active by default, but the legacy
// resource does
if (!parameters.containsKey("isEnded")) {
parameters.put("isEnded", new String[] { "false" });
}
Expand Down Expand Up @@ -211,19 +213,32 @@ public Object assignTicketToServicePoint(HttpServletRequest request) throws Exce
String ticketNumber = actualObj.get("ticketNumber").textValue();
String status = actualObj.get("status").textValue();

// Location is optional
String locationUuid = actualObj.has("locationUuid") ? actualObj.get("locationUuid").textValue() : null;

if (servicePointName.isEmpty() || ticketNumber.isEmpty() || status.isEmpty()) {
return new ResponseEntity<Object>("One of the required fields is empty", new HttpHeaders(), BAD_REQUEST);
}

QueueTicketAssignments.updateTicketAssignment(servicePointName, ticketNumber, status);
QueueTicketAssignments.updateTicketAssignment(servicePointName, ticketNumber, status, locationUuid);
return new ResponseEntity<Object>("Ticket successfully assigned!", new HttpHeaders(), HttpStatus.OK);
}
return new ResponseEntity<Object>("The request could not be interpreted", new HttpHeaders(), BAD_REQUEST);
}

@RequestMapping(method = GET, value = "/rest/" + RestConstants.VERSION_1 + "/queueutil/active-tickets")
public Object getActiveTickets() {
return new ResponseEntity<>(QueueTicketAssignments.getActiveTicketAssignments(), new HttpHeaders(), HttpStatus.OK);
@ResponseBody
public Object getActiveTickets(@RequestParam(value = "locationUuid", required = false) String locationUuid) {
Map<String, QueueTicketAssignments.TicketAssignment> activeTickets;

// If locationUuid parameter is provided, filter by locationUuid
if (StringUtils.isNotBlank(locationUuid)) {
activeTickets = QueueTicketAssignments.getActiveTicketAssignmentsByLocation(locationUuid);
} else {
activeTickets = QueueTicketAssignments.getActiveTicketAssignments();
}

return new ResponseEntity<>(activeTickets, new HttpHeaders(), HttpStatus.OK);
}

@RequestMapping(method = { GET, POST }, value = "/rest/" + RestConstants.VERSION_1 + "/queue-entry-number")
Expand Down