Search in sources :

Example 1 with JobEndpointException

use of org.opencastproject.adminui.exception.JobEndpointException in project opencast by opencast.

the class JobEndpoint method getTasksAsJSON.

/**
 * Returns the list of tasks matching the given query as JSON Object
 *
 * @param query
 *          The worklfow query
 * @return The list of matching tasks as JSON Object
 * @throws JobEndpointException
 * @throws NotFoundException
 */
public JObject getTasksAsJSON(WorkflowQuery query) throws JobEndpointException, NotFoundException {
    // Get results
    WorkflowSet workflowInstances = null;
    long totalWithoutFilters = 0;
    List<JValue> jsonList = new ArrayList<>();
    try {
        workflowInstances = workflowService.getWorkflowInstances(query);
        totalWithoutFilters = workflowService.countWorkflowInstances();
    } catch (WorkflowDatabaseException e) {
        throw new JobEndpointException(String.format("Not able to get the list of job from the database: %s", e), e.getCause());
    }
    WorkflowInstance[] items = workflowInstances.getItems();
    for (WorkflowInstance instance : items) {
        long instanceId = instance.getId();
        String series = instance.getMediaPackage().getSeriesTitle();
        // Retrieve submission date with the workflow instance main job
        Date created;
        try {
            created = serviceRegistry.getJob(instanceId).getDateCreated();
        } catch (ServiceRegistryException e) {
            throw new JobEndpointException(String.format("Error when retrieving job %s from the service registry: %s", instanceId, e), e.getCause());
        }
        jsonList.add(obj(f("id", v(instanceId)), f("title", v(nul(instance.getMediaPackage().getTitle()).getOr(""))), f("series", v(series, Jsons.BLANK)), f("workflow", v(instance.getTitle(), Jsons.BLANK)), f("status", v(instance.getState().toString())), f("submitted", v(created != null ? DateTimeSupport.toUTC(created.getTime()) : ""))));
    }
    JObject json = obj(f("results", arr(jsonList)), f("count", v(workflowInstances.getTotalCount())), f("offset", v(query.getStartPage())), f("limit", v(jsonList.size())), f("total", v(totalWithoutFilters)));
    return json;
}
Also used : WorkflowSet(org.opencastproject.workflow.api.WorkflowSet) ArrayList(java.util.ArrayList) WorkflowInstance(org.opencastproject.workflow.api.WorkflowInstance) Date(java.util.Date) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException) WorkflowDatabaseException(org.opencastproject.workflow.api.WorkflowDatabaseException) JobEndpointException(org.opencastproject.adminui.exception.JobEndpointException) JValue(com.entwinemedia.fn.data.json.JValue) JObject(com.entwinemedia.fn.data.json.JObject)

Example 2 with JobEndpointException

use of org.opencastproject.adminui.exception.JobEndpointException in project opencast by opencast.

the class JobEndpoint method getIncidentsAsJSON.

/**
 * Returns the list of incidents for a given workflow instance
 *
 * @param jobId
 *          the workflow instance id
 * @param locale
 *          the language in which title and description shall be returned
 * @param cascade
 *          if true, return the incidents of the given job and those of of its descendants
 * @return the list incidents as JSON array
 * @throws JobEndpointException
 * @throws NotFoundException
 */
public JValue getIncidentsAsJSON(long jobId, final Locale locale, boolean cascade) throws JobEndpointException, NotFoundException {
    final List<Incident> incidents;
    try {
        final IncidentTree it = incidentService.getIncidentsOfJob(jobId, cascade);
        incidents = cascade ? flatten(it) : it.getIncidents();
    } catch (IncidentServiceException e) {
        throw new JobEndpointException(String.format("Not able to get the incidents for the job %d from the incident service : %s", jobId, e), e.getCause());
    }
    final Stream<JValue> json = $(incidents).map(new Fn<Incident, JValue>() {

        @Override
        public JValue apply(Incident i) {
            return obj(f("id", v(i.getId())), f("severity", v(i.getSeverity(), Jsons.BLANK)), f("timestamp", v(toUTC(i.getTimestamp().getTime()), Jsons.BLANK))).merge(localizeIncident(i, locale));
        }
    });
    return arr(json);
}
Also used : JobEndpointException(org.opencastproject.adminui.exception.JobEndpointException) IncidentServiceException(org.opencastproject.serviceregistry.api.IncidentServiceException) JValue(com.entwinemedia.fn.data.json.JValue) Incident(org.opencastproject.job.api.Incident) IncidentTree(org.opencastproject.job.api.IncidentTree)

Example 3 with JobEndpointException

use of org.opencastproject.adminui.exception.JobEndpointException in project opencast by opencast.

the class JobEndpoint method getTasksAsJSON.

/**
 * Returns the single task with the given Id as JSON Object
 *
 * @param id
 * @return The job as JSON Object
 * @throws JobEndpointException
 * @throws NotFoundException
 */
public JObject getTasksAsJSON(long id) throws JobEndpointException, NotFoundException {
    WorkflowInstance instance = getWorkflowById(id);
    // Retrieve submission date with the workflow instance main job
    Date created;
    long duration = 0;
    try {
        Job job = serviceRegistry.getJob(id);
        created = job.getDateCreated();
        Date completed = job.getDateCompleted();
        if (completed == null)
            completed = new Date();
        duration = (completed.getTime() - created.getTime());
    } catch (ServiceRegistryException e) {
        throw new JobEndpointException(String.format("Error when retrieving job %s from the service registry: %s", id, e), e.getCause());
    }
    MediaPackage mp = instance.getMediaPackage();
    List<Field> fields = new ArrayList<>();
    for (String key : instance.getConfigurationKeys()) {
        fields.add(f(key, v(instance.getConfiguration(key), Jsons.BLANK)));
    }
    return obj(f("start", v(created != null ? toUTC(created.getTime()) : "", Jsons.BLANK)), f("state", v(instance.getState(), Jsons.BLANK)), f("description", v(instance.getDescription(), Jsons.BLANK)), f("duration", v(duration, Jsons.BLANK)), f("id", v(instance.getId(), Jsons.BLANK)), f("workflow", v(instance.getTitle(), Jsons.BLANK)), f("workflowId", v(instance.getTemplate(), Jsons.BLANK)), f("title", v(mp.getTitle(), Jsons.BLANK)), f("series", v(mp.getSeries(), Jsons.BLANK)), f("series_title", v(mp.getSeriesTitle(), Jsons.BLANK)), f("license", v(mp.getLicense(), Jsons.BLANK)), f("configuration", obj(fields)));
}
Also used : Field(com.entwinemedia.fn.data.json.Field) JobEndpointException(org.opencastproject.adminui.exception.JobEndpointException) MediaPackage(org.opencastproject.mediapackage.MediaPackage) ArrayList(java.util.ArrayList) WorkflowInstance(org.opencastproject.workflow.api.WorkflowInstance) Job(org.opencastproject.job.api.Job) Date(java.util.Date) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException)

Aggregations

JobEndpointException (org.opencastproject.adminui.exception.JobEndpointException)3 JValue (com.entwinemedia.fn.data.json.JValue)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 ServiceRegistryException (org.opencastproject.serviceregistry.api.ServiceRegistryException)2 WorkflowInstance (org.opencastproject.workflow.api.WorkflowInstance)2 Field (com.entwinemedia.fn.data.json.Field)1 JObject (com.entwinemedia.fn.data.json.JObject)1 Incident (org.opencastproject.job.api.Incident)1 IncidentTree (org.opencastproject.job.api.IncidentTree)1 Job (org.opencastproject.job.api.Job)1 MediaPackage (org.opencastproject.mediapackage.MediaPackage)1 IncidentServiceException (org.opencastproject.serviceregistry.api.IncidentServiceException)1 WorkflowDatabaseException (org.opencastproject.workflow.api.WorkflowDatabaseException)1 WorkflowSet (org.opencastproject.workflow.api.WorkflowSet)1