use of org.opencastproject.workflow.api.WorkflowDatabaseException in project opencast by opencast.
the class WorkflowServiceRemoteImpl method remove.
/**
* {@inheritDoc}
*
* @see org.opencastproject.workflow.api.WorkflowService#remove(long)
*/
@Override
public void remove(long workflowInstanceId) throws WorkflowDatabaseException, WorkflowParsingException, NotFoundException, UnauthorizedException {
HttpDelete delete = new HttpDelete("/remove/" + Long.toString(workflowInstanceId));
HttpResponse response = getResponse(delete, SC_NO_CONTENT, SC_NOT_FOUND);
try {
if (response != null) {
if (SC_NOT_FOUND == response.getStatusLine().getStatusCode()) {
throw new NotFoundException("Workflow id not found: " + workflowInstanceId);
} else {
logger.info("Workflow '{}' removed", workflowInstanceId);
return;
}
}
} finally {
closeConnection(response);
}
throw new WorkflowDatabaseException("Unable to remove workflow instance " + workflowInstanceId);
}
use of org.opencastproject.workflow.api.WorkflowDatabaseException in project opencast by opencast.
the class WorkflowServiceRemoteImpl method registerWorkflowDefinition.
/**
* {@inheritDoc}
*
* @see org.opencastproject.workflow.api.WorkflowService#registerWorkflowDefinition(org.opencastproject.workflow.api.WorkflowDefinition)
*/
@Override
public void registerWorkflowDefinition(WorkflowDefinition workflow) throws WorkflowDatabaseException {
HttpPut put = new HttpPut("/definition");
try {
List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();
params.add(new BasicNameValuePair("workflowDefinition", WorkflowParser.toXml(workflow)));
put.setEntity(new UrlEncodedFormEntity(params));
} catch (UnsupportedEncodingException e) {
throw new IllegalStateException("Unable to assemble a remote workflow service request", e);
} catch (Exception e) {
throw new IllegalStateException("unable to serialize workflow definition to xml");
}
HttpResponse response = getResponse(put, SC_CREATED, SC_PRECONDITION_FAILED);
try {
if (response != null) {
if (SC_PRECONDITION_FAILED == response.getStatusLine().getStatusCode()) {
throw new IllegalStateException("A workflow definition with ID '" + workflow.getId() + "' is already registered.");
} else {
logger.info("Workflow definition '{}' registered", workflow);
return;
}
}
} finally {
closeConnection(response);
}
throw new WorkflowDatabaseException("Unable to register workflow definition " + workflow.getId());
}
use of org.opencastproject.workflow.api.WorkflowDatabaseException in project opencast by opencast.
the class WorkflowServiceRemoteImpl method getWorkflowInstances.
/**
* {@inheritDoc}
*
* @see org.opencastproject.workflow.api.WorkflowService
* #getWorkflowInstances(org.opencastproject.workflow.api.WorkflowQuery)
*/
@Override
public WorkflowSet getWorkflowInstances(WorkflowQuery query) throws WorkflowDatabaseException {
List<NameValuePair> queryStringParams = new ArrayList<NameValuePair>();
if (query.getText() != null)
queryStringParams.add(new BasicNameValuePair("q", query.getText()));
if (query.getStates() != null) {
for (QueryTerm stateQueryTerm : query.getStates()) {
String value = stateQueryTerm.isInclude() ? stateQueryTerm.getValue() : "-" + stateQueryTerm.getValue();
queryStringParams.add(new BasicNameValuePair("state", value));
}
}
if (query.getCurrentOperations() != null) {
for (QueryTerm opQueryTerm : query.getCurrentOperations()) {
String value = opQueryTerm.isInclude() ? opQueryTerm.getValue() : "-" + opQueryTerm.getValue();
queryStringParams.add(new BasicNameValuePair("op", value));
}
}
if (query.getSeriesId() != null)
queryStringParams.add(new BasicNameValuePair("seriesId", query.getSeriesId()));
if (query.getSeriesTitle() != null)
queryStringParams.add(new BasicNameValuePair("seriesTitle", query.getSeriesTitle()));
if (query.getMediaPackageId() != null)
queryStringParams.add(new BasicNameValuePair("mp", query.getMediaPackageId()));
if (query.getWorkflowDefinitionId() != null)
queryStringParams.add(new BasicNameValuePair("workflowdefinition", query.getWorkflowDefinitionId()));
if (query.getFromDate() != null)
queryStringParams.add(new BasicNameValuePair("fromdate", SolrUtils.serializeDate(query.getFromDate())));
if (query.getToDate() != null)
queryStringParams.add(new BasicNameValuePair("todate", SolrUtils.serializeDate(query.getToDate())));
if (query.getCreator() != null)
queryStringParams.add(new BasicNameValuePair("creator", query.getCreator()));
if (query.getContributor() != null)
queryStringParams.add(new BasicNameValuePair("contributor", query.getContributor()));
if (query.getLanguage() != null)
queryStringParams.add(new BasicNameValuePair("language", query.getLanguage()));
if (query.getLicense() != null)
queryStringParams.add(new BasicNameValuePair("license", query.getLicense()));
if (query.getTitle() != null)
queryStringParams.add(new BasicNameValuePair("title", query.getTitle()));
if (query.getSubject() != null)
queryStringParams.add(new BasicNameValuePair("subject", query.getSubject()));
if (query.getSort() != null) {
String sort = query.getSort().toString();
if (!query.isSortAscending()) {
sort += "_DESC";
}
queryStringParams.add(new BasicNameValuePair("sort", sort));
}
if (query.getStartPage() > 0)
queryStringParams.add(new BasicNameValuePair("startPage", Long.toString(query.getStartPage())));
if (query.getCount() > 0)
queryStringParams.add(new BasicNameValuePair("count", Long.toString(query.getCount())));
StringBuilder url = new StringBuilder();
url.append("/instances.xml");
if (queryStringParams.size() > 0)
url.append("?" + URLEncodedUtils.format(queryStringParams, "UTF-8"));
HttpGet get = new HttpGet(url.toString());
HttpResponse response = getResponse(get);
try {
if (response != null)
return WorkflowParser.parseWorkflowSet(response.getEntity().getContent());
} catch (Exception e) {
throw new WorkflowDatabaseException(e);
} finally {
closeConnection(response);
}
throw new WorkflowDatabaseException("Workflow instances can not be loaded from a remote workflow service");
}
use of org.opencastproject.workflow.api.WorkflowDatabaseException in project opencast by opencast.
the class WorkflowServiceRemoteImpl method stop.
/**
* {@inheritDoc}
*
* @see org.opencastproject.workflow.api.WorkflowService#stop(long)
*/
@Override
public WorkflowInstance stop(long workflowInstanceId) throws WorkflowDatabaseException, NotFoundException {
HttpPost post = new HttpPost("/stop");
List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();
params.add(new BasicNameValuePair("id", Long.toString(workflowInstanceId)));
try {
post.setEntity(new UrlEncodedFormEntity(params));
} catch (UnsupportedEncodingException e) {
throw new IllegalStateException("Unable to assemble a remote workflow service request", e);
}
HttpResponse response = getResponse(post, SC_OK, SC_NOT_FOUND);
try {
if (response != null) {
if (response.getStatusLine().getStatusCode() == SC_NOT_FOUND) {
throw new NotFoundException("Workflow instance with id='" + workflowInstanceId + "' not found");
} else {
logger.info("Workflow '{}' stopped", workflowInstanceId);
return WorkflowParser.parseWorkflowInstance(response.getEntity().getContent());
}
}
} catch (NotFoundException e) {
throw e;
} catch (Exception e) {
throw new WorkflowDatabaseException(e);
} finally {
closeConnection(response);
}
throw new WorkflowDatabaseException("Unable to stop workflow instance " + workflowInstanceId);
}
Aggregations