Search in sources :

Example 41 with WorkflowDatabaseException

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);
}
Also used : WorkflowDatabaseException(org.opencastproject.workflow.api.WorkflowDatabaseException) HttpDelete(org.apache.http.client.methods.HttpDelete) HttpResponse(org.apache.http.HttpResponse) NotFoundException(org.opencastproject.util.NotFoundException)

Example 42 with WorkflowDatabaseException

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());
}
Also used : WorkflowDatabaseException(org.opencastproject.workflow.api.WorkflowDatabaseException) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) ArrayList(java.util.ArrayList) UnsupportedEncodingException(java.io.UnsupportedEncodingException) HttpResponse(org.apache.http.HttpResponse) UrlEncodedFormEntity(org.apache.http.client.entity.UrlEncodedFormEntity) HttpPut(org.apache.http.client.methods.HttpPut) ParseException(org.apache.http.ParseException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException) WorkflowException(org.opencastproject.workflow.api.WorkflowException) WorkflowDatabaseException(org.opencastproject.workflow.api.WorkflowDatabaseException) IOException(java.io.IOException) WorkflowParsingException(org.opencastproject.workflow.api.WorkflowParsingException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 43 with WorkflowDatabaseException

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");
}
Also used : BasicNameValuePair(org.apache.http.message.BasicNameValuePair) NameValuePair(org.apache.http.NameValuePair) WorkflowDatabaseException(org.opencastproject.workflow.api.WorkflowDatabaseException) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) HttpGet(org.apache.http.client.methods.HttpGet) ArrayList(java.util.ArrayList) HttpResponse(org.apache.http.HttpResponse) QueryTerm(org.opencastproject.workflow.api.WorkflowQuery.QueryTerm) ParseException(org.apache.http.ParseException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException) WorkflowException(org.opencastproject.workflow.api.WorkflowException) WorkflowDatabaseException(org.opencastproject.workflow.api.WorkflowDatabaseException) IOException(java.io.IOException) WorkflowParsingException(org.opencastproject.workflow.api.WorkflowParsingException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 44 with WorkflowDatabaseException

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);
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) WorkflowDatabaseException(org.opencastproject.workflow.api.WorkflowDatabaseException) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) ArrayList(java.util.ArrayList) UnsupportedEncodingException(java.io.UnsupportedEncodingException) HttpResponse(org.apache.http.HttpResponse) NotFoundException(org.opencastproject.util.NotFoundException) UrlEncodedFormEntity(org.apache.http.client.entity.UrlEncodedFormEntity) ParseException(org.apache.http.ParseException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException) WorkflowException(org.opencastproject.workflow.api.WorkflowException) WorkflowDatabaseException(org.opencastproject.workflow.api.WorkflowDatabaseException) IOException(java.io.IOException) WorkflowParsingException(org.opencastproject.workflow.api.WorkflowParsingException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Aggregations

WorkflowDatabaseException (org.opencastproject.workflow.api.WorkflowDatabaseException)44 NotFoundException (org.opencastproject.util.NotFoundException)30 IOException (java.io.IOException)23 WorkflowParsingException (org.opencastproject.workflow.api.WorkflowParsingException)23 UnauthorizedException (org.opencastproject.security.api.UnauthorizedException)21 WorkflowException (org.opencastproject.workflow.api.WorkflowException)20 ArrayList (java.util.ArrayList)15 WorkflowInstance (org.opencastproject.workflow.api.WorkflowInstance)15 HttpResponse (org.apache.http.HttpResponse)14 ServiceRegistryException (org.opencastproject.serviceregistry.api.ServiceRegistryException)14 UnsupportedEncodingException (java.io.UnsupportedEncodingException)11 ParseException (org.apache.http.ParseException)11 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)8 WorkflowQuery (org.opencastproject.workflow.api.WorkflowQuery)8 SolrServerException (org.apache.solr.client.solrj.SolrServerException)7 UrlEncodedFormEntity (org.apache.http.client.entity.UrlEncodedFormEntity)6 Job (org.opencastproject.job.api.Job)6 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)6 Collections.mkString (org.opencastproject.util.data.Collections.mkString)6 WorkflowDefinition (org.opencastproject.workflow.api.WorkflowDefinition)6