use of org.opencastproject.search.api.SearchException in project opencast by opencast.
the class PublishEngageWorkflowOperationHandler method retractFromEngage.
/**
* Removes every Publication for Searchindex from Mediapackage
* Removes Mediapackage from Searchindex
* @param mediaPackage Mediapackage
* @param mediaPackageForSearch Mediapackage prepared for searchIndex
* @throws WorkflowOperationException
*/
private void retractFromEngage(MediaPackage mediaPackage) throws WorkflowOperationException {
List<Job> jobs = new ArrayList<Job>();
Set<String> elementIds = new HashSet<String>();
try {
MediaPackage distributedMediaPackage = getDistributedMediapackage(mediaPackage.toString());
if (distributedMediaPackage != null) {
for (MediaPackageElement element : distributedMediaPackage.getElements()) {
elementIds.add(element.getIdentifier());
}
// bulk retraction
if (elementIds.size() > 0) {
Job retractDownloadDistributionJob = downloadDistributionService.retract(CHANNEL_ID, distributedMediaPackage, elementIds);
if (retractDownloadDistributionJob != null) {
jobs.add(retractDownloadDistributionJob);
}
}
if (distributeStreaming) {
for (MediaPackageElement element : distributedMediaPackage.getElements()) {
Job retractStreamingJob = streamingDistributionService.retract(CHANNEL_ID, distributedMediaPackage, element.getIdentifier());
if (retractStreamingJob != null) {
jobs.add(retractStreamingJob);
}
}
}
Job deleteSearchJob = null;
logger.info("Retracting already published Elements for Mediapackage: {}", mediaPackage.getIdentifier().toString());
deleteSearchJob = searchService.delete(mediaPackage.getIdentifier().toString());
if (deleteSearchJob != null) {
jobs.add(deleteSearchJob);
}
}
// Wait until all retraction jobs have returned
if (!waitForStatus(jobs.toArray(new Job[jobs.size()])).isSuccess()) {
throw new WorkflowOperationException("One of the retraction jobs did not complete successfully");
}
} catch (DistributionException e) {
throw new WorkflowOperationException(e);
} catch (SearchException e) {
throw new WorkflowOperationException("Error retracting media package", e);
} catch (UnauthorizedException | NotFoundException ex) {
logger.error("Retraction failed of Mediapackage: { }", mediaPackage.getIdentifier().toString(), ex);
}
}
use of org.opencastproject.search.api.SearchException in project opencast by opencast.
the class SearchServiceRemoteImpl method getForAdministrativeRead.
/**
* {@inheritDoc}
*
* @see org.opencastproject.search.api.SearchService#getForAdministrativeRead(org.opencastproject.search.api.SearchQuery)
*/
@Override
public SearchResult getForAdministrativeRead(SearchQuery q) throws SearchException, UnauthorizedException {
HttpGet get = new HttpGet(getSearchUrl(q, true));
HttpResponse response = getResponse(get);
try {
if (response != null)
return SearchResultImpl.valueOf(response.getEntity().getContent());
} catch (Exception e) {
throw new SearchException("Unable to parse results of a getForAdministrativeRead request from remote search index: ", e);
} finally {
closeConnection(response);
}
throw new SearchException("Unable to perform getForAdministrativeRead from remote search index");
}
use of org.opencastproject.search.api.SearchException in project opencast by opencast.
the class SearchServiceRemoteImpl method delete.
/**
* {@inheritDoc}
*
* @see org.opencastproject.search.api.SearchService#delete(java.lang.String)
*/
@Override
public Job delete(String mediaPackageId) throws SearchException {
HttpDelete del = new HttpDelete(mediaPackageId);
HttpResponse response = getResponse(del);
try {
if (response != null) {
Job job = JobParser.parseJob(response.getEntity().getContent());
logger.info("Removing mediapackage '{}' from a remote search service", mediaPackageId);
return job;
}
} catch (Exception e) {
throw new SearchException("Unable to remove " + mediaPackageId + " from a remote search service", e);
} finally {
closeConnection(response);
}
throw new SearchException("Unable to remove " + mediaPackageId + " from a remote search service");
}
use of org.opencastproject.search.api.SearchException in project opencast by opencast.
the class SearchServiceImpl method deleteSynchronously.
/**
* Immediately removes the given mediapackage from the search service.
*
* @param mediaPackageId
* the mediapackage
* @return <code>true</code> if the mediapackage was deleted
* @throws SearchException
* if deletion failed
* @throws UnauthorizedException
* if the user did not have access to the media package
* @throws NotFoundException
* if the mediapackage did not exist
*/
public boolean deleteSynchronously(String mediaPackageId) throws SearchException, UnauthorizedException, NotFoundException {
SearchResult result;
try {
result = solrRequester.getForWrite(new SearchQuery().withId(mediaPackageId));
if (result.getItems().length == 0) {
logger.warn("Can not delete mediapackage {}, which is not available for the current user to delete from the search index.", mediaPackageId);
return false;
}
logger.info("Removing mediapackage {} from search index", mediaPackageId);
Date now = new Date();
try {
persistence.deleteMediaPackage(mediaPackageId, now);
logger.info("Removed mediapackage {} from search persistence", mediaPackageId);
} catch (NotFoundException e) {
// even if mp not found in persistence, it might still exist in search index.
logger.info("Could not find mediapackage with id {} in persistence, but will try remove it from index, anyway.", mediaPackageId);
} catch (SearchServiceDatabaseException e) {
logger.error("Could not delete media package with id {} from persistence storage", mediaPackageId);
throw new SearchException(e);
}
return indexManager.delete(mediaPackageId, now);
} catch (SolrServerException e) {
logger.info("Could not delete media package with id {} from search index", mediaPackageId);
throw new SearchException(e);
}
}
use of org.opencastproject.search.api.SearchException in project opencast by opencast.
the class SearchServiceImpl method addSynchronously.
/**
* Immediately adds the mediapackage to the search index.
*
* @param mediaPackage
* the media package
* @throws SearchException
* if the media package cannot be added to the search index
* @throws MediaPackageException
* if the mediapckage is invalid
* @throws IllegalArgumentException
* if the mediapackage is <code>null</code>
* @throws UnauthorizedException
* if the user does not have the rights to add the mediapackage
*/
public void addSynchronously(MediaPackage mediaPackage) throws SearchException, MediaPackageException, IllegalArgumentException, UnauthorizedException {
User currentUser = securityService.getUser();
String orgAdminRole = securityService.getOrganization().getAdminRole();
if (!currentUser.hasRole(orgAdminRole) && !currentUser.hasRole(GLOBAL_ADMIN_ROLE) && !authorizationService.hasPermission(mediaPackage, Permissions.Action.WRITE.toString())) {
throw new UnauthorizedException(currentUser, Permissions.Action.WRITE.toString());
}
if (mediaPackage == null) {
throw new IllegalArgumentException("Unable to add a null mediapackage");
}
logger.debug("Attempting to add mediapackage {} to search index", mediaPackage.getIdentifier());
AccessControlList acl = authorizationService.getActiveAcl(mediaPackage).getA();
Date now = new Date();
try {
if (indexManager.add(mediaPackage, acl, now)) {
logger.info("Added mediapackage `{}` to the search index, using ACL `{}`", mediaPackage, acl);
} else {
logger.warn("Failed to add mediapackage {} to the search index", mediaPackage.getIdentifier());
}
} catch (SolrServerException e) {
throw new SearchException(e);
}
try {
persistence.storeMediaPackage(mediaPackage, acl, now);
} catch (SearchServiceDatabaseException e) {
logger.error("Could not store media package to search database {}: {}", mediaPackage.getIdentifier(), e);
throw new SearchException(e);
}
}
Aggregations