Search in sources :

Example 11 with SearchQuery

use of org.opencastproject.search.api.SearchQuery in project opencast by opencast.

the class AggregationFeedService method loadFeedData.

/**
 * {@inheritDoc}
 *
 * @see org.opencastproject.feed.impl.AbstractFeedGenerator#loadFeedData(org.opencastproject.feed.api.Feed.Type,
 *      java.lang.String[], int, int)
 */
protected SearchResult loadFeedData(Type type, String[] query, int limit, int offset) {
    try {
        SearchQuery q = createBaseQuery(type, limit, offset);
        q.withQuery(solrQuery);
        return searchService.getByQuery(q);
    } catch (Exception e) {
        logger.error("Cannot retrieve result for aggregated feed", e);
        return null;
    }
}
Also used : SearchQuery(org.opencastproject.search.api.SearchQuery)

Example 12 with SearchQuery

use of org.opencastproject.search.api.SearchQuery in project opencast by opencast.

the class LiveScheduleServiceImpl method getMediaPackageFromSearch.

/**
 * Retrieves the media package from the search index.
 *
 * @param mediaPackageId
 *          the media package id
 * @return the media package in the search index or null if not there
 * @throws LiveException
 *           if found many media packages with the same id
 */
MediaPackage getMediaPackageFromSearch(String mediaPackageId) throws LiveScheduleException {
    // Look for the media package in the search index
    SearchQuery query = new SearchQuery().withId(mediaPackageId);
    SearchResult result = searchService.getByQuery(query);
    if (result.size() == 0) {
        logger.debug("The search service doesn't know live mediapackage {}", mediaPackageId);
        return null;
    } else if (result.size() > 1) {
        logger.warn("More than one live mediapackage with id {} returned from search service", mediaPackageId);
        throw new LiveScheduleException("More than one live mediapackage with id " + mediaPackageId + " found");
    }
    return result.getItems()[0].getMediaPackage();
}
Also used : SearchQuery(org.opencastproject.search.api.SearchQuery) SearchResult(org.opencastproject.search.api.SearchResult) LiveScheduleException(org.opencastproject.liveschedule.api.LiveScheduleException)

Example 13 with SearchQuery

use of org.opencastproject.search.api.SearchQuery in project opencast by opencast.

the class MediaPackagePostOperationHandler method start.

/**
 * {@inheritDoc}
 *
 * @see org.opencastproject.workflow.api.WorkflowOperationHandler#start(org.opencastproject.workflow.api.WorkflowInstance,
 *      JobContext)
 */
public WorkflowOperationResult start(final WorkflowInstance workflowInstance, JobContext context) throws WorkflowOperationException {
    // get configuration
    WorkflowOperationInstance currentOperation = workflowInstance.getCurrentOperation();
    Configuration config = new Configuration(currentOperation);
    MediaPackage workflowMP = workflowInstance.getMediaPackage();
    MediaPackage mp = workflowMP;
    /* Check if we need to replace the Mediapackage we got with the published
     * Mediapackage from the Search Service */
    if (config.mpFromSearch()) {
        SearchQuery searchQuery = new SearchQuery();
        searchQuery.withId(mp.getIdentifier().toString());
        SearchResult result = searchService.getByQuery(searchQuery);
        if (result.size() != 1) {
            throw new WorkflowOperationException("Received multiple results for identifier" + "\"" + mp.getIdentifier().toString() + "\" from search service. ");
        }
        logger.info("Getting Mediapackage from Search Service");
        mp = result.getItems()[0].getMediaPackage();
    }
    logger.info("Submitting \"" + mp.getTitle() + "\" (" + mp.getIdentifier().toString() + ") as " + config.getFormat().name() + " to " + config.getUrl().toString());
    try {
        // serialize MediaPackage to target format
        String mpStr;
        if (config.getFormat() == Configuration.Format.JSON) {
            mpStr = MediaPackageParser.getAsJSON(mp);
        } else {
            mpStr = MediaPackageParser.getAsXml(mp);
        }
        // Log mediapackge
        if (config.debug()) {
            logger.info(mpStr);
        }
        // constrcut message body
        List<NameValuePair> data = new ArrayList<NameValuePair>();
        data.add(new BasicNameValuePair("mediapackage", mpStr));
        data.addAll(config.getAdditionalFields());
        // construct POST
        HttpPost post = new HttpPost(config.getUrl());
        post.setEntity(new UrlEncodedFormEntity(data, config.getEncoding()));
        // execute POST
        DefaultHttpClient client = new DefaultHttpClient();
        // Handle authentication
        if (config.authenticate()) {
            URL targetUrl = config.getUrl().toURL();
            client.getCredentialsProvider().setCredentials(new AuthScope(targetUrl.getHost(), targetUrl.getPort()), config.getCredentials());
        }
        HttpResponse response = client.execute(post);
        // throw Exception if target host did not return 200
        int status = response.getStatusLine().getStatusCode();
        if ((status >= 200) && (status < 300)) {
            if (config.debug()) {
                logger.info("Successfully submitted \"" + mp.getTitle() + "\" (" + mp.getIdentifier().toString() + ") to " + config.getUrl().toString() + ": " + status);
            }
        } else if (status == 418) {
            logger.warn("Submitted \"" + mp.getTitle() + "\" (" + mp.getIdentifier().toString() + ") to " + config.getUrl().toString() + ": The target claims to be a teapot. " + "The Reason for this is probably an insane programmer.");
        } else {
            throw new WorkflowOperationException("Faild to submit \"" + mp.getTitle() + "\" (" + mp.getIdentifier().toString() + "), " + config.getUrl().toString() + " answered with: " + Integer.toString(status));
        }
    } catch (Exception e) {
        if (e instanceof WorkflowOperationException) {
            throw (WorkflowOperationException) e;
        } else {
            logger.error("Submitting mediapackage failed: {}", e.toString());
            throw new WorkflowOperationException(e);
        }
    }
    return createResult(workflowMP, Action.CONTINUE);
}
Also used : SearchQuery(org.opencastproject.search.api.SearchQuery) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) NameValuePair(org.apache.http.NameValuePair) HttpPost(org.apache.http.client.methods.HttpPost) ArrayList(java.util.ArrayList) HttpResponse(org.apache.http.HttpResponse) SearchResult(org.opencastproject.search.api.SearchResult) UrlEncodedFormEntity(org.apache.http.client.entity.UrlEncodedFormEntity) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) URL(java.net.URL) WorkflowOperationException(org.opencastproject.workflow.api.WorkflowOperationException) WorkflowOperationInstance(org.opencastproject.workflow.api.WorkflowOperationInstance) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) MediaPackage(org.opencastproject.mediapackage.MediaPackage) WorkflowOperationException(org.opencastproject.workflow.api.WorkflowOperationException) AuthScope(org.apache.http.auth.AuthScope)

Example 14 with SearchQuery

use of org.opencastproject.search.api.SearchQuery in project opencast by opencast.

the class PublishEngageWorkflowOperationHandler method getDistributedMediapackage.

protected MediaPackage getDistributedMediapackage(String mediaPackageID) throws WorkflowOperationException {
    MediaPackage mediaPackage = null;
    SearchQuery query = new SearchQuery().withId(mediaPackageID);
    query.includeEpisodes(true);
    query.includeSeries(false);
    SearchResult result = searchService.getByQuery(query);
    if (result.size() == 0) {
        logger.info("The search service doesn't know mediapackage {}.", mediaPackageID);
        // i.e. null
        return mediaPackage;
    } else if (result.size() > 1) {
        logger.warn("More than one mediapackage with id {} returned from search service", mediaPackageID);
        throw new WorkflowOperationException("More than one mediapackage with id " + mediaPackageID + " found");
    } else {
        // else, merge the new with the existing (new elements will overwrite existing elements)
        mediaPackage = result.getItems()[0].getMediaPackage();
    }
    return mediaPackage;
}
Also used : SearchQuery(org.opencastproject.search.api.SearchQuery) MediaPackage(org.opencastproject.mediapackage.MediaPackage) WorkflowOperationException(org.opencastproject.workflow.api.WorkflowOperationException) SearchResult(org.opencastproject.search.api.SearchResult)

Example 15 with SearchQuery

use of org.opencastproject.search.api.SearchQuery in project opencast by opencast.

the class RetractEngageWorkflowOperationHandler method start.

/**
 * {@inheritDoc}
 *
 * @see org.opencastproject.workflow.api.WorkflowOperationHandler#start(WorkflowInstance, JobContext)
 */
@Override
public WorkflowOperationResult start(WorkflowInstance workflowInstance, JobContext context) throws WorkflowOperationException {
    MediaPackage mediaPackage = workflowInstance.getMediaPackage();
    try {
        List<Job> jobs = new ArrayList<Job>();
        SearchQuery query = new SearchQuery().withId(mediaPackage.getIdentifier().toString());
        SearchResult result = searchService.getByQuery(query);
        if (result.size() == 0) {
            logger.info("The search service doesn't know mediapackage {}", mediaPackage);
            return createResult(mediaPackage, Action.SKIP);
        } else if (result.size() > 1) {
            logger.warn("More than one mediapackage with id {} returned from search service", mediaPackage.getIdentifier());
            throw new WorkflowOperationException("More than one mediapackage with id " + mediaPackage.getIdentifier() + " found");
        } else {
            Set<String> retractElementIds = new HashSet<String>();
            MediaPackage searchMediaPackage = result.getItems()[0].getMediaPackage();
            logger.info("Retracting media package {} from download/streaming distribution channel", searchMediaPackage);
            for (MediaPackageElement element : searchMediaPackage.getElements()) {
                retractElementIds.add(element.getIdentifier());
            }
            if (retractElementIds.size() > 0) {
                Job retractDownloadDistributionJob = downloadDistributionService.retract(CHANNEL_ID, searchMediaPackage, retractElementIds);
                if (retractDownloadDistributionJob != null) {
                    jobs.add(retractDownloadDistributionJob);
                }
            }
            if (distributeStreaming) {
                for (MediaPackageElement element : searchMediaPackage.getElements()) {
                    if (distributeStreaming) {
                        Job retractStreamingJob = streamingDistributionService.retract(CHANNEL_ID, searchMediaPackage, element.getIdentifier());
                        if (retractStreamingJob != null) {
                            jobs.add(retractStreamingJob);
                        }
                    }
                }
            }
        }
        // Wait for retraction to finish
        if (!waitForStatus(jobs.toArray(new Job[jobs.size()])).isSuccess()) {
            throw new WorkflowOperationException("One of the download/streaming retract job did not complete successfully");
        }
        logger.debug("Retraction operation complete");
        logger.info("Removing media package {} from the search index", mediaPackage);
        Job deleteFromSearch = searchService.delete(mediaPackage.getIdentifier().toString());
        if (!waitForStatus(deleteFromSearch).isSuccess())
            throw new WorkflowOperationException("Removing media package from search did not complete successfully");
        logger.debug("Remove from search operation complete");
        // Remove publication element
        logger.info("Removing engage publication element from media package {}", mediaPackage);
        Publication[] publications = mediaPackage.getPublications();
        for (Publication publication : publications) {
            if (CHANNEL_ID.equals(publication.getChannel())) {
                mediaPackage.remove(publication);
                logger.debug("Remove engage publication element '{}' complete", publication);
            }
        }
        return createResult(mediaPackage, Action.CONTINUE);
    } catch (Throwable t) {
        throw new WorkflowOperationException(t);
    }
}
Also used : SearchQuery(org.opencastproject.search.api.SearchQuery) HashSet(java.util.HashSet) Set(java.util.Set) ArrayList(java.util.ArrayList) Publication(org.opencastproject.mediapackage.Publication) SearchResult(org.opencastproject.search.api.SearchResult) MediaPackageElement(org.opencastproject.mediapackage.MediaPackageElement) MediaPackage(org.opencastproject.mediapackage.MediaPackage) WorkflowOperationException(org.opencastproject.workflow.api.WorkflowOperationException) Job(org.opencastproject.job.api.Job)

Aggregations

SearchQuery (org.opencastproject.search.api.SearchQuery)25 MediaPackage (org.opencastproject.mediapackage.MediaPackage)14 Job (org.opencastproject.job.api.Job)12 Test (org.junit.Test)11 JobBarrier (org.opencastproject.job.api.JobBarrier)10 SearchResult (org.opencastproject.search.api.SearchResult)10 AccessControlEntry (org.opencastproject.security.api.AccessControlEntry)5 ArrayList (java.util.ArrayList)4 Date (java.util.Date)4 GET (javax.ws.rs.GET)3 Path (javax.ws.rs.Path)3 Produces (javax.ws.rs.Produces)3 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)3 User (org.opencastproject.security.api.User)3 RestQuery (org.opencastproject.util.doc.rest.RestQuery)3 WorkflowOperationException (org.opencastproject.workflow.api.WorkflowOperationException)3 SearchException (org.opencastproject.search.api.SearchException)2 SearchResultItem (org.opencastproject.search.api.SearchResultItem)2 JaxbRole (org.opencastproject.security.api.JaxbRole)2 JaxbUser (org.opencastproject.security.api.JaxbUser)2