Package org.eclipse.orion.server.core.tasks

Examples of org.eclipse.orion.server.core.tasks.TaskInfo.toJSON()


    if (job.getState() == Job.NONE || job.getRealResult() != null) {
      return writeResult(request, response, job, statusHandler, strategy);
    } else {
      TaskInfo task = job.startTask();
      task.setUnqualificationStrategy(strategy);
      JSONObject result = task.toJSON();
      URI taskLocation = createTaskLocation(ServletResourceHandler.getURI(request), task.getId(), task.isKeep());
      result.put(ProtocolConstants.KEY_LOCATION, taskLocation);
      if (!task.isRunning()) {
        job.removeTask(); // Task is not used, we may remove it
        return writeResult(request, response, job, statusHandler, strategy);
View Full Code Here


      } catch (JSONException e) {
        handleException(resp, e.getMessage(), e);
      }
      return;
    }
    JSONObject result = task.toJSON();
    if (task.isKeep()) {
      try {
        if (result.optString(ProtocolConstants.KEY_LOCATION, "").equals(""))
          result.put(ProtocolConstants.KEY_LOCATION, ServletResourceHandler.getURI(req));
      } catch (JSONException e) {
View Full Code Here

    } else {
      job = new SFTPExportJob(TaskJobHandler.getUserId(request), localFile, host, port, new Path(remotePath), user, passphrase, options);
    }
    job.schedule();
    TaskInfo task = job.getTask();
    JSONObject result = task.toJSON();
    //Not nice that the import service knows the location of the task servlet, but task service doesn't know this either
    URI requestLocation = ServletResourceHandler.getURI(request);
    URI taskLocation = new URI(requestLocation.getScheme(), requestLocation.getAuthority(), "/task/temp/" + task.getId(), null, null); //$NON-NLS-1$
    result.put(ProtocolConstants.KEY_LOCATION, taskLocation);
    response.setHeader(ProtocolConstants.HEADER_LOCATION, ServletResourceHandler.resovleOrionURI(request, taskLocation).toString());
View Full Code Here

*/
public class TaskInfoTest extends TestCase {
  @Test
  public void testBadJSON() {
    TaskInfo task = AllTaskTests.createTestTask("test");
    String json = task.toJSON().toString();
    json = json.replace('}', ')');
    boolean exceptionThrown = false;
    try {
      TaskInfo.fromJSON(new TaskDescription(task.getUserId(), task.getId(), true), json);
    } catch (CorruptedTaskException e) {
View Full Code Here

  @Test
  public void testRoundTrip() throws CorruptedTaskException {
    TaskInfo task = AllTaskTests.createTestTask("test");
    TaskStore store = new TaskStore(tempDir);
    store.writeTask(new TaskDescription(task.getUserId(), task.getId(), true), task.toJSON().toString());

    TaskInfo task2 = TaskInfo.fromJSON(new TaskDescription(task.getUserId(), task.getId(), true), store.readTask(new TaskDescription(task.getUserId(), task.getId(), true)));
    AllTaskTests.assertEqualTasks(task, task2);
  }
View Full Code Here

  @Test
  public void testDeleteTask() {
    TaskInfo task = AllTaskTests.createTestTask("test");
    task.done(Status.OK_STATUS);
    TaskStore store = new TaskStore(tempDir);
    store.writeTask(new TaskDescription(task.getUserId(), task.getId(), true), task.toJSON().toString());
    assertNotNull(store.readTask(new TaskDescription(task.getUserId(), task.getId(), true)));
    assertTrue(store.removeTask(new TaskDescription(task.getUserId(), task.getId(), true)));
    assertNull(store.readTask(new TaskDescription(task.getUserId(), task.getId(), true)));
  }
View Full Code Here

    TaskInfo task2 = new TaskInfo("test", "taskid2", true);
    task2.done(Status.OK_STATUS);
    TaskStore store = new TaskStore(tempDir);
    store.writeTask(new TaskDescription("test", task1.getId(), true), task1.toJSON().toString());
    assertEquals(1, store.readAllTasks("test"));
    store.writeTask(new TaskDescription("test", task2.getId(), true), task2.toJSON().toString());
    assertEquals(2, store.readAllTasks("test"));
    store.removeTask(new TaskDescription("test", task1.getId(), true));
    assertEquals(1, store.readAllTasks("test"));
  }
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.