use of org.activityinfo.model.job.JobStatus in project activityinfo by bedatadriven.
the class JobResourceTest method startJob.
@Test
public void startJob() {
final org.activityinfo.json.JsonParser parser = new org.activityinfo.json.JsonParser();
final Queue queue = QueueFactory.getDefaultQueue();
final AuthenticatedUser user = new AuthenticatedUser("XYZ", 1, "akbertram@gmail.com");
final JobResource resource = new JobResource(Providers.of(user), queue);
// First request starts the job
final String jobId = ObjectifyService.run(new Work<String>() {
@Override
public String run() {
TableModel tableModel = ImmutableTableModel.builder().formId(ResourceId.valueOf("FORM1")).build();
ExportFormJob exportForm = new ExportFormJob(tableModel);
JobRequest request = new JobRequest(exportForm, "en");
Response response = resource.start(request.toJsonObject().toJson());
JsonValue resultObject = parser.parse((String) response.getEntity());
JobStatus result = JobStatus.fromJson(resultObject);
assertThat(result.getState(), equalTo(JobState.STARTED));
return result.getId();
}
});
// Second request retrieves status
ObjectifyService.run(new VoidWork() {
@Override
public void vrun() {
Response statusResponse = resource.get(jobId);
JsonValue statusObject = parser.parse(((String) statusResponse.getEntity()));
JobStatus status = JobStatus.fromJson(statusObject);
assertThat(status.getState(), equalTo(JobState.STARTED));
}
});
}
use of org.activityinfo.model.job.JobStatus in project activityinfo by bedatadriven.
the class JobResource method get.
/**
* Retrieves the status of a long-running job
*/
@GET
@Path("{jobId}")
public Response get(@PathParam("jobId") String jobId) {
if (user.get().isAnonymous()) {
return Response.status(Response.Status.UNAUTHORIZED).build();
}
JobEntity job = JobStore.getUserJob(jobId).now();
if (job == null) {
return Response.status(Response.Status.NOT_FOUND).build();
}
if (job.getUserId() != user.get().getUserId()) {
return Response.status(Response.Status.FORBIDDEN).build();
}
JobStatus status = buildStatus(job);
return Response.ok().entity(status.toJsonObject().toJson()).build();
}
use of org.activityinfo.model.job.JobStatus in project activityinfo by bedatadriven.
the class ExportOptionsDialog method onOk.
private void onOk(SelectEvent event) {
ExportFormJob exportFormJob = new ExportFormJob(exportModel.get());
dialog.hide();
Observable<JobStatus<ExportFormJob, ExportResult>> jobStatus = formStore.startJob(exportFormJob);
ExportJobDialog statusDialog = new ExportJobDialog(jobStatus);
statusDialog.show();
}
Aggregations