Search in sources :

Example 1 with SearchServiceDatabaseException

use of org.opencastproject.search.impl.persistence.SearchServiceDatabaseException 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 2 with SearchServiceDatabaseException

use of org.opencastproject.search.impl.persistence.SearchServiceDatabaseException in project opencast by opencast.

the class SearchServiceImpl method populateIndex.

protected void populateIndex(String systemUserName) {
    long instancesInSolr = 0L;
    try {
        instancesInSolr = indexManager.count();
    } catch (Exception e) {
        throw new IllegalStateException(e);
    }
    if (instancesInSolr > 0) {
        logger.debug("Search index found");
        return;
    }
    if (instancesInSolr == 0L) {
        logger.info("No search index found");
        logger.info("Starting population of search index from database");
        Iterator<Tuple<MediaPackage, String>> mediaPackages;
        try {
            mediaPackages = persistence.getAllMediaPackages();
        } catch (SearchServiceDatabaseException e) {
            logger.error("Unable to load the search entries: {}", e.getMessage());
            throw new ServiceException(e.getMessage());
        }
        int errors = 0;
        while (mediaPackages.hasNext()) {
            try {
                Tuple<MediaPackage, String> mediaPackage = mediaPackages.next();
                String mediaPackageId = mediaPackage.getA().getIdentifier().toString();
                Organization organization = organizationDirectory.getOrganization(mediaPackage.getB());
                securityService.setOrganization(organization);
                securityService.setUser(SecurityUtil.createSystemUser(systemUserName, organization));
                AccessControlList acl = persistence.getAccessControlList(mediaPackageId);
                Date modificationDate = persistence.getModificationDate(mediaPackageId);
                Date deletionDate = persistence.getDeletionDate(mediaPackageId);
                indexManager.add(mediaPackage.getA(), acl, deletionDate, modificationDate);
            } catch (Exception e) {
                logger.error("Unable to index search instances:", e);
                if (retryToPopulateIndex(systemUserName)) {
                    logger.warn("Trying to re-index search index later. Aborting for now.");
                    return;
                }
                errors++;
            } finally {
                securityService.setOrganization(null);
                securityService.setUser(null);
            }
        }
        if (errors > 0)
            logger.error("Skipped {} erroneous search entries while populating the search index", errors);
        logger.info("Finished populating search index");
    }
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) Organization(org.opencastproject.security.api.Organization) ServiceException(org.osgi.framework.ServiceException) SolrServerException(org.apache.solr.client.solrj.SolrServerException) ConfigurationException(org.osgi.service.cm.ConfigurationException) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException) MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) SearchServiceDatabaseException(org.opencastproject.search.impl.persistence.SearchServiceDatabaseException) SearchException(org.opencastproject.search.api.SearchException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) Date(java.util.Date) SearchServiceDatabaseException(org.opencastproject.search.impl.persistence.SearchServiceDatabaseException) ServiceException(org.osgi.framework.ServiceException) MediaPackage(org.opencastproject.mediapackage.MediaPackage) Tuple(org.opencastproject.util.data.Tuple)

Example 3 with SearchServiceDatabaseException

use of org.opencastproject.search.impl.persistence.SearchServiceDatabaseException 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

Date (java.util.Date)3 SolrServerException (org.apache.solr.client.solrj.SolrServerException)3 SearchException (org.opencastproject.search.api.SearchException)3 SearchServiceDatabaseException (org.opencastproject.search.impl.persistence.SearchServiceDatabaseException)3 AccessControlList (org.opencastproject.security.api.AccessControlList)2 UnauthorizedException (org.opencastproject.security.api.UnauthorizedException)2 NotFoundException (org.opencastproject.util.NotFoundException)2 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 MediaPackage (org.opencastproject.mediapackage.MediaPackage)1 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)1 SearchQuery (org.opencastproject.search.api.SearchQuery)1 SearchResult (org.opencastproject.search.api.SearchResult)1 Organization (org.opencastproject.security.api.Organization)1 User (org.opencastproject.security.api.User)1 ServiceRegistryException (org.opencastproject.serviceregistry.api.ServiceRegistryException)1 Tuple (org.opencastproject.util.data.Tuple)1 ServiceException (org.osgi.framework.ServiceException)1 ConfigurationException (org.osgi.service.cm.ConfigurationException)1