use of org.dataportabilityproject.gateway.action.startjob.StartJobActionRequest in project data-transfer-project by google.
the class StartCopyHandler method handle.
@Override
public void handle(HttpExchange exchange) throws IOException {
Preconditions.checkArgument(ReferenceApiUtils.validateRequest(exchange, HttpMethods.POST, PATH));
UUID jobId = ReferenceApiUtils.validateJobId(exchange.getRequestHeaders(), tokenManager);
// Validate auth data is present in cookies
String exportAuthCookieValue = ReferenceApiUtils.getCookie(exchange.getRequestHeaders(), JsonKeys.EXPORT_AUTH_DATA_COOKIE_KEY);
Preconditions.checkArgument(!Strings.isNullOrEmpty(exportAuthCookieValue), "Export auth cookie required");
String importAuthCookieValue = ReferenceApiUtils.getCookie(exchange.getRequestHeaders(), JsonKeys.IMPORT_AUTH_DATA_COOKIE_KEY);
Preconditions.checkArgument(!Strings.isNullOrEmpty(importAuthCookieValue), "Import auth cookie required");
// We have the data, now update to 'pending worker assignment' so a worker may be assigned
StartJobActionRequest request = new StartJobActionRequest(jobId, exportAuthCookieValue, importAuthCookieValue);
StartJobActionResponse response = startJobAction.handle(request);
// TODO: Determine if we need more fields populated or a new object
DataTransferResponse dataTransferResponse = new DataTransferResponse(// job.exportService(),
"", // job.importService(),
"", // job.transferDataType(),
"", Status.INPROCESS, // FrontendConstantUrls.URL_COPY_PAGE);
"");
// Mark the response as type Json and send
exchange.getResponseHeaders().set(HttpHeaders.CONTENT_TYPE, "application/json; charset=" + StandardCharsets.UTF_8.name());
exchange.sendResponseHeaders(200, 0);
objectMapper.writeValue(exchange.getResponseBody(), dataTransferResponse);
}
Aggregations