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;
}
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);
}
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)));
}
Aggregations