Search in sources :

Example 1 with JobStatus

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));
        }
    });
}
Also used : JsonValue(org.activityinfo.json.JsonValue) AuthenticatedUser(org.activityinfo.legacy.shared.AuthenticatedUser) ExportFormJob(org.activityinfo.model.job.ExportFormJob) Response(javax.ws.rs.core.Response) JobStatus(org.activityinfo.model.job.JobStatus) JobRequest(org.activityinfo.model.job.JobRequest) VoidWork(com.googlecode.objectify.VoidWork) Queue(com.google.appengine.api.taskqueue.Queue) TableModel(org.activityinfo.model.analysis.TableModel) ImmutableTableModel(org.activityinfo.model.analysis.ImmutableTableModel) Test(org.junit.Test)

Example 2 with JobStatus

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();
}
Also used : JobStatus(org.activityinfo.model.job.JobStatus)

Example 3 with JobStatus

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();
}
Also used : ExportFormJob(org.activityinfo.model.job.ExportFormJob) JobStatus(org.activityinfo.model.job.JobStatus)

Aggregations

JobStatus (org.activityinfo.model.job.JobStatus)3 ExportFormJob (org.activityinfo.model.job.ExportFormJob)2 Queue (com.google.appengine.api.taskqueue.Queue)1 VoidWork (com.googlecode.objectify.VoidWork)1 Response (javax.ws.rs.core.Response)1 JsonValue (org.activityinfo.json.JsonValue)1 AuthenticatedUser (org.activityinfo.legacy.shared.AuthenticatedUser)1 ImmutableTableModel (org.activityinfo.model.analysis.ImmutableTableModel)1 TableModel (org.activityinfo.model.analysis.TableModel)1 JobRequest (org.activityinfo.model.job.JobRequest)1 Test (org.junit.Test)1