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

Examples of org.eclipse.orion.server.core.tasks.TaskInfo


  protected final String userId;
  protected final String requestLocation;

  @Override
  public synchronized TaskInfo startTask() {
    TaskInfo task = super.startTask();
    task.setUnqualificationStrategy(JsonURIUnqualificationStrategy.LOCATION_ONLY);
    return task;
  }
View Full Code Here


    job.removeJobChangeListener(jobListener);

    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);
      }
      response.setHeader(ProtocolConstants.HEADER_LOCATION, ServletResourceHandler.resovleOrionURI(request, taskLocation).toString());
      OrionServlet.writeJSONResponse(request, response, result, strategy);
View Full Code Here

      handleException(resp, "Task service is unavailable", null);
      return;
    }
    String taskId = path.segment(1);
    boolean keep = "id".equals(path.segment(0));
    TaskInfo task = taskService.getTask(TaskJobHandler.getUserId(req), taskId, keep);

    if (task == null) {
      JSONObject errorDescription = new JSONObject();
      try {
        errorDescription.put("taskNotFound", taskId);
        handleException(resp, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_NOT_FOUND, "Task not found: " + taskId, errorDescription, null));
        //        handleException(resp, "Task not found: " + taskId, null, HttpServletResponse.SC_NOT_FOUND);
      } 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) {
        handleException(resp, e.getMessage(), e);
      }
    }
    IURIUnqualificationStrategy strategy = task.getUnqualificationStrategy();
    writeJSONResponse(req, resp, result, strategy);
  }
View Full Code Here

      taskServiceRef = null;
    }
  }

  protected TaskInfo createTask(String userId, boolean keep) {
    TaskInfo info = getTaskService().createTask(userId, keep);
    getTaskService().updateTask(info);
    return info;
  }
View Full Code Here

      job = new SFTPImportJob(TaskJobHandler.getUserId(request), localFile, host, port, new Path(remotePath), user, passphrase, options);
    } 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());
    OrionServlet.writeJSONResponse(request, response, result);
    response.setStatus(HttpServletResponse.SC_ACCEPTED);
  }
View Full Code Here

* Tests for {@link TaskInfo}.
*/
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) {
      exceptionThrown = true;
    }
    assertTrue(json, exceptionThrown);
  }
View Full Code Here

   * Tests the JSON representation of tasks.
   * @throws CorruptedTaskException
   */
  @Test
  public void testJSONRoundTrip() throws CorruptedTaskException {
    TaskInfo info = AllTaskTests.createTestTask("test");
    TaskInfo task2 = TaskInfo.fromJSON(new TaskDescription(info.getUserId(), info.getId(), true), info.toJSON().toString());
    AllTaskTests.assertEqualTasks(info, task2);
  }
View Full Code Here

  /**
   * Helper method for creating a sample task for testing purposes.
   */
  public static TaskInfo createTestTask(String userId) {
    TaskInfo info = new TaskInfo(userId, "mytask", true);
    info.done(new Status(IStatus.ERROR, "pluginid", "status message"));
    return info;
  }
View Full Code Here

    assertNull(task);
  }

  @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

    AllTaskTests.assertEqualTasks(task, task2);
  }

  @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

TOP

Related Classes of org.eclipse.orion.server.core.tasks.TaskInfo

Copyright © 2018 www.massapicom. 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.