-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DT-1143: Passthrough APIs for support requests and content uploads (#…
- Loading branch information
Showing
24 changed files
with
402 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/main/java/org/broadinstitute/consent/http/models/support/TicketFields.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package org.broadinstitute.consent.http.models.support; | ||
|
||
import java.util.List; | ||
import org.broadinstitute.consent.http.enumeration.SupportRequestType; | ||
import org.zendesk.client.v2.model.Comment; | ||
import org.zendesk.client.v2.model.CustomFieldValue; | ||
import org.zendesk.client.v2.model.Ticket; | ||
|
||
public record TicketFields(String name, SupportRequestType type, String email, String subject, | ||
String description, String url, List<String> uploads) { | ||
|
||
private static void validate(boolean condition, String prefix) { | ||
if (condition) { | ||
throw new IllegalArgumentException(prefix + " is required"); | ||
} | ||
} | ||
|
||
public void validate() { | ||
validate(name == null || email == null, "Name and email of user requesting support"); | ||
validate(subject == null, "Subject"); | ||
validate(description == null, "Description"); | ||
validate(type == null, "Type"); | ||
validate(url == null, "URL"); | ||
} | ||
|
||
Ticket toTicket() { | ||
Ticket ticket = new Ticket(new Ticket.Requester(name, email), subject, createComment()); | ||
ticket.setCustomFields(createCustomFields()); | ||
// This value specifies tickets as belonging to the DUOS group defined in Zendesk | ||
ticket.setTicketFormId(360000669472L); | ||
return ticket; | ||
} | ||
|
||
private Comment createComment() { | ||
Comment comment = new Comment(); | ||
comment.setBody(description + "\n\n------------------\nSubmitted from: " + url); | ||
if (uploads != null && !uploads.isEmpty()) { | ||
comment.setUploads(uploads); | ||
} | ||
return comment; | ||
} | ||
|
||
/** | ||
* Custom fields consist of predefined long values corresponding to field types in the Zendesk UI | ||
* | ||
* @return List<CustomFieldValue> List of custom fields | ||
*/ | ||
private List<CustomFieldValue> createCustomFields() { | ||
return List.of(new CustomFieldValue(360012744452L, new String[]{type.name()}), | ||
new CustomFieldValue(360007369412L, new String[]{description}), | ||
new CustomFieldValue(360012744292L, new String[]{name}), | ||
new CustomFieldValue(360012782111L, new String[]{email}), | ||
new CustomFieldValue(360018545031L, new String[]{email})); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
src/main/java/org/broadinstitute/consent/http/resources/SupportResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package org.broadinstitute.consent.http.resources; | ||
|
||
import com.google.api.client.http.HttpStatusCodes; | ||
import com.google.gson.Gson; | ||
import com.google.gson.JsonObject; | ||
import com.google.inject.Inject; | ||
import jakarta.ws.rs.Consumes; | ||
import jakarta.ws.rs.POST; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.Produces; | ||
import jakarta.ws.rs.core.MediaType; | ||
import jakarta.ws.rs.core.Response; | ||
import org.broadinstitute.consent.http.models.support.DuosTicket; | ||
import org.broadinstitute.consent.http.models.support.TicketFactory; | ||
import org.broadinstitute.consent.http.models.support.TicketFields; | ||
import org.broadinstitute.consent.http.service.SupportRequestService; | ||
import org.broadinstitute.consent.http.util.gson.GsonUtil; | ||
import org.owasp.fileio.FileValidator; | ||
import org.zendesk.client.v2.model.Request; | ||
|
||
@Path("support") | ||
public class SupportResource extends Resource { | ||
|
||
private final SupportRequestService supportRequestService; | ||
private static final Gson gson = GsonUtil.getInstance(); | ||
static final long MAX_FILE_UPLOAD_SIZE = new FileValidator().getMaxFileUploadSize(); | ||
|
||
@Inject | ||
public SupportResource(SupportRequestService supportRequestService) { | ||
this.supportRequestService = supportRequestService; | ||
} | ||
|
||
@POST | ||
@Path("request") | ||
@Consumes(MediaType.APPLICATION_JSON) | ||
@Produces(MediaType.APPLICATION_JSON) | ||
public Response postRequest(String body) { | ||
try { | ||
TicketFields ticketFields = gson.fromJson(body, TicketFields.class); | ||
DuosTicket ticket = TicketFactory.createTicket(ticketFields); | ||
logInfo("Support Request Ticket: " + ticket); | ||
Request request = supportRequestService.postTicketToSupport(ticket); | ||
return Response.status(HttpStatusCodes.STATUS_CODE_CREATED).entity(request).build(); | ||
} catch (Exception e) { | ||
return createExceptionResponse(e); | ||
} | ||
} | ||
|
||
@POST | ||
@Path("upload") | ||
@Consumes("application/binary") | ||
@Produces(MediaType.APPLICATION_JSON) | ||
public Response postUpload(byte[] content) { | ||
try { | ||
if (content.length > MAX_FILE_UPLOAD_SIZE) { | ||
return Response.status(Response.Status.BAD_REQUEST).build(); | ||
} | ||
JsonObject token = supportRequestService.postAttachmentToSupport(content); | ||
logInfo("Support Request Content Upload: " + content.length + " bytes"); | ||
return Response.status(HttpStatusCodes.STATUS_CODE_CREATED).entity(token).build(); | ||
} catch (Exception e) { | ||
return createExceptionResponse(e); | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.