Search in sources :

Example 6 with SearchException

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);
    }
}
Also used : ArrayList(java.util.ArrayList) SearchException(org.opencastproject.search.api.SearchException) NotFoundException(org.opencastproject.util.NotFoundException) MediaPackageElement(org.opencastproject.mediapackage.MediaPackageElement) MediaPackage(org.opencastproject.mediapackage.MediaPackage) WorkflowOperationException(org.opencastproject.workflow.api.WorkflowOperationException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) DistributionException(org.opencastproject.distribution.api.DistributionException) Job(org.opencastproject.job.api.Job) HashSet(java.util.HashSet)

Example 7 with SearchException

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");
}
Also used : HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) SearchException(org.opencastproject.search.api.SearchException) SearchException(org.opencastproject.search.api.SearchException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException)

Example 8 with SearchException

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");
}
Also used : HttpDelete(org.apache.http.client.methods.HttpDelete) HttpResponse(org.apache.http.HttpResponse) SearchException(org.opencastproject.search.api.SearchException) Job(org.opencastproject.job.api.Job) SearchException(org.opencastproject.search.api.SearchException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException)

Example 9 with SearchException

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);
    }
}
Also used : SearchQuery(org.opencastproject.search.api.SearchQuery) SearchServiceDatabaseException(org.opencastproject.search.impl.persistence.SearchServiceDatabaseException) SolrServerException(org.apache.solr.client.solrj.SolrServerException) NotFoundException(org.opencastproject.util.NotFoundException) SearchException(org.opencastproject.search.api.SearchException) SearchResult(org.opencastproject.search.api.SearchResult) Date(java.util.Date)

Example 10 with SearchException

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);
    }
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) SearchServiceDatabaseException(org.opencastproject.search.impl.persistence.SearchServiceDatabaseException) User(org.opencastproject.security.api.User) SolrServerException(org.apache.solr.client.solrj.SolrServerException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) SearchException(org.opencastproject.search.api.SearchException) Date(java.util.Date)

Aggregations

SearchException (org.opencastproject.search.api.SearchException)11 UnauthorizedException (org.opencastproject.security.api.UnauthorizedException)9 HttpResponse (org.apache.http.HttpResponse)5 Job (org.opencastproject.job.api.Job)5 ArrayList (java.util.ArrayList)4 NotFoundException (org.opencastproject.util.NotFoundException)4 HttpGet (org.apache.http.client.methods.HttpGet)3 SolrServerException (org.apache.solr.client.solrj.SolrServerException)3 DistributionException (org.opencastproject.distribution.api.DistributionException)3 MediaPackage (org.opencastproject.mediapackage.MediaPackage)3 URI (java.net.URI)2 Date (java.util.Date)2 HashSet (java.util.HashSet)2 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)2 Attachment (org.opencastproject.mediapackage.Attachment)2 MediaPackageElement (org.opencastproject.mediapackage.MediaPackageElement)2 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)2 SearchQuery (org.opencastproject.search.api.SearchQuery)2 SearchResult (org.opencastproject.search.api.SearchResult)2 SearchServiceDatabaseException (org.opencastproject.search.impl.persistence.SearchServiceDatabaseException)2