use of org.opencastproject.util.LocalHashMap in project opencast by opencast.
the class IncidentServiceEndpoint method postIncident.
@POST
@Produces(MediaType.APPLICATION_XML)
@Path("/")
@RestQuery(name = "postincident", description = "Creates a new job incident and returns it as XML", returnDescription = "Returns the created job incident as XML", restParameters = { @RestParameter(name = "job", isRequired = true, description = "The job on where to create the incident", type = Type.TEXT), @RestParameter(name = "date", isRequired = true, description = "The incident creation date", type = Type.STRING), @RestParameter(name = "code", isRequired = true, description = "The incident error code", type = Type.STRING), @RestParameter(name = "severity", isRequired = true, description = "The incident error code", type = Type.STRING), @RestParameter(name = "details", isRequired = false, description = "The incident details", type = Type.TEXT), @RestParameter(name = "params", isRequired = false, description = "The incident parameters", type = Type.TEXT) }, reponses = { @RestResponse(responseCode = SC_CREATED, description = "New job incident has been created"), @RestResponse(responseCode = SC_BAD_REQUEST, description = "Unable to parse the one of the form params"), @RestResponse(responseCode = SC_CONFLICT, description = "No job incident related job exists") })
public Response postIncident(@FormParam("job") String jobXml, @FormParam("date") String date, @FormParam("code") String code, @FormParam("severity") String severityString, @FormParam("details") String details, @FormParam("params") LocalHashMap params) {
Job job;
Date timestamp;
Severity severity;
Map<String, String> map = new HashMap<String, String>();
List<Tuple<String, String>> list = new ArrayList<Tuple<String, String>>();
try {
job = JobParser.parseJob(jobXml);
timestamp = new Date(DateTimeSupport.fromUTC(date));
severity = Severity.valueOf(severityString);
if (params != null)
map = params.getMap();
if (StringUtils.isNotBlank(details)) {
final JSONArray array = (JSONArray) JSONValue.parse(details);
for (int i = 0; i < array.size(); i++) {
JSONObject tuple = (JSONObject) array.get(i);
list.add(Tuple.tuple((String) tuple.get("title"), (String) tuple.get("content")));
}
}
} catch (Exception e) {
return Response.status(Status.BAD_REQUEST).entity(e.getMessage()).build();
}
try {
Incident incident = svc.storeIncident(job, timestamp, code, severity, map, list);
String uri = UrlSupport.concat(serverUrl, serviceUrl, Long.toString(incident.getId()), ".xml");
return Response.created(new URI(uri)).entity(new JaxbIncident(incident)).build();
} catch (IllegalStateException e) {
return Response.status(Status.CONFLICT).build();
} catch (Exception e) {
logger.warn("Unable to post incident for job {}: {}", job.getId(), e);
throw new WebApplicationException(INTERNAL_SERVER_ERROR);
}
}
use of org.opencastproject.util.LocalHashMap in project opencast by opencast.
the class WorkflowRestService method startWorkflow.
private WorkflowInstanceImpl startWorkflow(WorkflowDefinition workflowDefinition, MediaPackageImpl mp, String parentWorkflowId, LocalHashMap localMap) {
Map<String, String> properties = new HashMap<String, String>();
if (localMap != null)
properties = localMap.getMap();
Long parentIdAsLong = null;
if (StringUtils.isNotEmpty(parentWorkflowId)) {
try {
parentIdAsLong = Long.parseLong(parentWorkflowId);
} catch (NumberFormatException e) {
throw new WebApplicationException(e, Status.BAD_REQUEST);
}
}
try {
return (WorkflowInstanceImpl) service.start(workflowDefinition, mp, parentIdAsLong, properties);
} catch (WorkflowException e) {
throw new WebApplicationException(e);
} catch (NotFoundException e) {
throw new WebApplicationException(e);
}
}
Aggregations