Skip to content
Merged
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 @@ -40,9 +40,12 @@
import jakarta.ws.rs.QueryParam;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.core.Context;
import jakarta.ws.rs.core.UriInfo;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Map;

@Path("/api/superuser/tickets")
@Produces(MediaType.APPLICATION_JSON)
Expand Down Expand Up @@ -109,6 +112,33 @@ public SupportTicketApiResource.SupportTicketListResponse list(
meta.page(), meta.pageSize(), meta.totalItems(), meta.totalPages());
}

@GET
@Path("/search")
@Transactional
public SupportTicketApiResource.SupportTicketListResponse search(@Context UriInfo uriInfo,
@QueryParam("page") Integer page, @QueryParam("pageSize") Integer pageSize, @QueryParam("sort") String sort,
@QueryParam("dir") String dir) {
User user = currentUser.get();
SuperuserResource.SupportTicketData data = superuserResource.buildTicketDataForUser(user);
List<Ticket> scoped = TicketSearchSupport.combineTickets(data.assignedTickets, data.openTickets,
data.closedTickets);
TicketAdvancedSearchSupport.Criteria criteria = TicketAdvancedSearchSupport.parse(uriInfo, user,
ticketCustomFieldService);
List<Ticket> tickets = TicketAdvancedSearchSupport.filter(scoped, criteria, user, data.messageDates,
ticketCustomFieldService);
Map<Long, Ticket> displayTickets = TicketAdvancedSearchSupport.indexById(scoped);
int totalItems = tickets.size();
List<SupportTicketApiResource.SupportTicketSummary> allSummaries = tickets.stream()
.map(ticket -> toSummary(displayTickets.getOrDefault(ticket.id, ticket), data)).toList();
List<SupportTicketApiResource.SupportTicketSummary> pageItems = PaginationSupport.sortAndPaginate(allSummaries,
sort, dir, SupportTicketApiResource.ticketSortColumns(), page, pageSize);
PaginationSupport.PaginationMeta meta = PaginationSupport.meta(page, pageSize, totalItems);
return new SupportTicketApiResource.SupportTicketListResponse("advanced", "Search results",
data.assignedTickets == null ? 0 : data.assignedTickets.size(),
data.openTickets == null ? 0 : data.openTickets.size(), "/superuser/tickets/new", criteria.q(),
pageItems, meta.page(), meta.pageSize(), meta.totalItems(), meta.totalPages());
}

@GET
@Path("/suggest")
@Transactional
Expand All @@ -132,7 +162,8 @@ public SupportTicketApiResource.TicketSuggestionResponse suggest(
@Path("/bootstrap")
@Transactional
public SupportTicketApiResource.SupportTicketBootstrapResponse bootstrap(@QueryParam("companyId") Long companyId,
@QueryParam("companyEntitlementId") Long companyEntitlementId) {
@QueryParam("companyEntitlementId") Long companyEntitlementId,
@QueryParam("allVersions") @DefaultValue("false") boolean allVersions) {
User user = currentUser.get();
SuperuserResource.SupportTicketData data = superuserResource.buildTicketDataForUser(user);
List<Company> companies = directoryService.allowedCompanies(user);
Expand All @@ -142,8 +173,11 @@ public SupportTicketApiResource.SupportTicketBootstrapResponse bootstrap(@QueryP
Long selectedCompanyEntitlementId = TicketBootstrapService.selectEntitlementId(entitlements,
companyEntitlementId);
Long versionsEntitlementId = entitlementIdForVersions(selectedCompanyEntitlementId, entitlements);
List<TicketBootstrapService.VersionOption> versions = versionsEntitlementId == null ? List.of()
: ticketBootstrapService.versionOptionsForEntitlement(versionsEntitlementId);
List<TicketBootstrapService.VersionOption> versions = allVersions
? ticketBootstrapService
.versionOptionsForCompanies(companies.stream().map(company -> company.id).toList())
: versionsEntitlementId == null ? List.of()
: ticketBootstrapService.versionOptionsForEntitlement(versionsEntitlementId);
TicketBootstrapService.VersionOption defaultVersion = TicketBootstrapService
.selectDefaultVersionOption(versions);
Category defaultCategory = Category.findDefault();
Expand Down Expand Up @@ -218,7 +252,8 @@ public UserTicketApiResource.RoleTicketDetailResponse detail(@PathParam("id") Lo
List<SupportTicketApiResource.EventEntry> eventEntries = rawEvents.stream().map(this::toEventEntry).toList();

return new UserTicketApiResource.RoleTicketDetailResponse(ticket.id, ticket.name, ticket.displayTitle(),
normalizeDisplayStatus(ticket.status), data.assignedTickets == null ? 0 : data.assignedTickets.size(),
TicketSearchSupport.displayStatus(ticket.status, user),
data.assignedTickets == null ? 0 : data.assignedTickets.size(),
data.openTickets == null ? 0 : data.openTickets.size(),
ticket.company == null ? null : ticket.company.id, ticket.company == null ? null : ticket.company.name,
ticket.category == null ? null : ticket.category.id,
Expand Down Expand Up @@ -260,7 +295,8 @@ private SupportTicketApiResource.SupportTicketSummary toSummary(Ticket ticket,
SuperuserResource.SupportTicketData data) {
User assignedSupport = data.supportAssignmentUsers.get(ticket.id);
return new SupportTicketApiResource.SupportTicketSummary(ticket.id, ticket.name, ticket.displayTitle(),
normalizeDisplayStatus(ticket.status), data.messageDateLabels.get(ticket.id),
TicketSearchSupport.displayStatus(ticket.status, currentUser.get()),
data.messageDateLabels.get(ticket.id),
data.messageDates.get(ticket.id) == null ? null : data.messageDates.get(ticket.id).toString(),
data.messageDirectionArrows.get(ticket.id), data.slaColors.get(ticket.id),
ticket.category == null ? null : ticket.category.name,
Expand Down Expand Up @@ -317,16 +353,6 @@ private String normalizeView(String view) {
return "assigned";
}

private String normalizeDisplayStatus(String status) {
if (status == null || status.isBlank()) {
return "Open";
}
if ("Waiting for External Feedback".equalsIgnoreCase(status.trim())) {
return "In Progress";
}
return status;
}

private Company selectCompany(List<Company> companies, Long companyId) {
if (companies == null || companies.isEmpty()) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,14 @@
import jakarta.ws.rs.QueryParam;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.core.Context;
import jakarta.ws.rs.core.UriInfo;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;

@Path("/api/support/tickets")
Expand Down Expand Up @@ -103,6 +106,32 @@ public SupportTicketListResponse list(@QueryParam("view") @DefaultValue("assigne
meta.totalPages());
}

@GET
@Path("/search")
@Transactional
public SupportTicketListResponse search(@Context UriInfo uriInfo, @QueryParam("page") Integer page,
@QueryParam("pageSize") Integer pageSize, @QueryParam("sort") String sort, @QueryParam("dir") String dir) {
User user = currentUser.get();
SupportTicketViewSupport.SupportTicketData data = SupportTicketViewSupport.buildTicketData(user);
SupportTicketViewSupport.SupportTicketCounts counts = SupportTicketViewSupport.loadTicketCounts(user);
List<Ticket> scoped = TicketSearchSupport.combineTickets(data.assignedTickets(), data.openTickets(),
data.closedTickets());
TicketAdvancedSearchSupport.Criteria criteria = TicketAdvancedSearchSupport.parse(uriInfo, user,
ticketCustomFieldService);
List<Ticket> tickets = TicketAdvancedSearchSupport.filter(scoped, criteria, user, data.messageDates(),
ticketCustomFieldService);
Map<Long, Ticket> displayTickets = TicketAdvancedSearchSupport.indexById(scoped);
int totalItems = tickets.size();
List<SupportTicketSummary> allSummaries = tickets.stream()
.map(ticket -> toSummary(displayTickets.getOrDefault(ticket.id, ticket), data)).toList();
List<SupportTicketSummary> pageItems = PaginationSupport.sortAndPaginate(allSummaries, sort, dir,
ticketSortColumns(), page, pageSize);
PaginationSupport.PaginationMeta meta = PaginationSupport.meta(page, pageSize, totalItems);
return new SupportTicketListResponse("advanced", "Search results", counts.assignedCount(), counts.openCount(),
"/support/tickets/new", criteria.q(), pageItems, meta.page(), meta.pageSize(), meta.totalItems(),
meta.totalPages());
}

@GET
@Path("/suggest")
@Transactional
Expand All @@ -125,7 +154,8 @@ public TicketSuggestionResponse suggest(@QueryParam("view") @DefaultValue("assig
@Path("/bootstrap")
@Transactional
public SupportTicketBootstrapResponse bootstrap(@QueryParam("companyId") Long companyId,
@QueryParam("companyEntitlementId") Long companyEntitlementId) {
@QueryParam("companyEntitlementId") Long companyEntitlementId,
@QueryParam("allVersions") @DefaultValue("false") boolean allVersions) {
User user = currentUser.get();
SupportTicketViewSupport.SupportTicketCounts counts = SupportTicketViewSupport.loadTicketCounts(user);
List<TicketBootstrapService.CompanyOption> companies = ticketBootstrapService.allCompanyOptions();
Expand All @@ -136,8 +166,11 @@ public SupportTicketBootstrapResponse bootstrap(@QueryParam("companyId") Long co
Long selectedCompanyEntitlementId = TicketBootstrapService.selectEntitlementId(entitlements,
companyEntitlementId);
Long versionsEntitlementId = entitlementIdForVersions(selectedCompanyEntitlementId, entitlements);
List<TicketBootstrapService.VersionOption> versions = versionsEntitlementId == null ? List.of()
: ticketBootstrapService.versionOptionsForEntitlement(versionsEntitlementId);
List<TicketBootstrapService.VersionOption> versions = allVersions
? ticketBootstrapService.versionOptionsForCompanies(
companies.stream().map(TicketBootstrapService.CompanyOption::id).toList())
: versionsEntitlementId == null ? List.of()
: ticketBootstrapService.versionOptionsForEntitlement(versionsEntitlementId);
TicketBootstrapService.VersionOption defaultVersion = TicketBootstrapService
.selectDefaultVersionOption(versions);
Category defaultCategory = Category.findDefault();
Expand Down
Loading
Loading