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