Search in sources :

Example 1 with SeriesEntity

use of org.opencastproject.series.impl.persistence.SeriesEntity in project opencast by opencast.

the class SeriesServiceImpl method repopulate.

@Override
public void repopulate(final String indexName) {
    final String destinationId = SeriesItem.SERIES_QUEUE_PREFIX + indexName.substring(0, 1).toUpperCase() + indexName.substring(1);
    try {
        final int total = persistence.countSeries();
        logger.info("Re-populating '{}' index with series. There are {} series to add to the index.", indexName, total);
        final int responseInterval = (total < 100) ? 1 : (total / 100);
        List<SeriesEntity> databaseSeries = persistence.getAllSeries();
        int current = 1;
        for (SeriesEntity series : databaseSeries) {
            Organization organization = orgDirectory.getOrganization(series.getOrganization());
            SecurityUtil.runAs(securityService, organization, SecurityUtil.createSystemUser(systemUserName, organization), new Function0.X<Void>() {

                @Override
                public Void xapply() throws Exception {
                    String id = series.getSeriesId();
                    logger.trace("Adding series '{}' for org '{}'", id, series.getOrganization());
                    DublinCoreCatalog catalog = DublinCoreXmlFormat.read(series.getDublinCoreXML());
                    messageSender.sendObjectMessage(destinationId, MessageSender.DestinationType.Queue, SeriesItem.updateCatalog(catalog));
                    AccessControlList acl = AccessControlParser.parseAcl(series.getAccessControl());
                    if (acl != null) {
                        messageSender.sendObjectMessage(destinationId, MessageSender.DestinationType.Queue, SeriesItem.updateAcl(id, acl));
                    }
                    messageSender.sendObjectMessage(destinationId, MessageSender.DestinationType.Queue, SeriesItem.updateOptOut(id, series.isOptOut()));
                    for (Entry<String, String> property : persistence.getSeriesProperties(id).entrySet()) {
                        messageSender.sendObjectMessage(destinationId, MessageSender.DestinationType.Queue, SeriesItem.updateProperty(id, property.getKey(), property.getValue()));
                    }
                    return null;
                }
            });
            if ((current % responseInterval == 0) || (current == total)) {
                logger.info("Initializing {} series index rebuild {}/{}: {} percent", indexName, current, total, current * 100 / total);
            }
            current++;
        }
        logger.info("Finished initializing '{}' index rebuild", indexName);
    } catch (Exception e) {
        logger.warn("Unable to index series instances:", e);
        throw new ServiceException(e.getMessage());
    }
    Organization organization = new DefaultOrganization();
    SecurityUtil.runAs(securityService, organization, SecurityUtil.createSystemUser(systemUserName, organization), new Effect0() {

        @Override
        protected void run() {
            messageSender.sendObjectMessage(IndexProducer.RESPONSE_QUEUE, MessageSender.DestinationType.Queue, IndexRecreateObject.end(indexName, IndexRecreateObject.Service.Series));
        }
    });
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) Organization(org.opencastproject.security.api.Organization) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) SeriesEntity(org.opencastproject.series.impl.persistence.SeriesEntity) Function0(org.opencastproject.util.data.Function0) ServiceException(org.osgi.framework.ServiceException) SeriesException(org.opencastproject.series.api.SeriesException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException) FunctionException(org.opencastproject.util.data.FunctionException) Entry(java.util.Map.Entry) ServiceException(org.osgi.framework.ServiceException) Effect0(org.opencastproject.util.data.Effect0) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization)

Example 2 with SeriesEntity

use of org.opencastproject.series.impl.persistence.SeriesEntity in project opencast by opencast.

the class SeriesServiceImpl method populateSolr.

/**
 * If the solr index is empty, but there are series in the database, populate the solr index.
 */
private void populateSolr(String systemUserName) {
    long instancesInSolr;
    try {
        instancesInSolr = index.count();
    } catch (Exception e) {
        throw new IllegalStateException("Repopulating series Solr index failed", e);
    }
    if (instancesInSolr != 0L) {
        return;
    }
    logger.info("The series index is empty. Populating it now with series");
    try {
        List<SeriesEntity> allSeries = persistence.getAllSeries();
        final int total = allSeries.size();
        if (total == 0) {
            logger.info("No series found. Repopulating index finished.");
            return;
        }
        int current = 0;
        for (SeriesEntity series : allSeries) {
            current++;
            // Run as the superuser so we get all series, regardless of organization or role
            Organization organization = orgDirectory.getOrganization(series.getOrganization());
            securityService.setOrganization(organization);
            securityService.setUser(SecurityUtil.createSystemUser(systemUserName, organization));
            index.updateIndex(DublinCoreXmlFormat.read(series.getDublinCoreXML()));
            String id = series.getSeriesId();
            AccessControlList acl = AccessControlParser.parseAcl(series.getAccessControl());
            if (acl != null) {
                index.updateSecurityPolicy(id, acl);
            }
            index.updateOptOutStatus(id, series.isOptOut());
            // log progress
            if (current % 100 == 0) {
                logger.info("Indexing series {}/{} ({} percent done)", current, total, current * 100 / total);
            }
        }
        logger.info("Finished populating series search index");
    } catch (Exception e) {
        logger.warn("Unable to index series instances", e);
        throw new ServiceException(e.getMessage());
    } finally {
        securityService.setOrganization(null);
        securityService.setUser(null);
    }
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) Organization(org.opencastproject.security.api.Organization) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) ServiceException(org.osgi.framework.ServiceException) SeriesEntity(org.opencastproject.series.impl.persistence.SeriesEntity) ServiceException(org.osgi.framework.ServiceException) SeriesException(org.opencastproject.series.api.SeriesException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException) FunctionException(org.opencastproject.util.data.FunctionException)

Aggregations

AccessControlList (org.opencastproject.security.api.AccessControlList)2 DefaultOrganization (org.opencastproject.security.api.DefaultOrganization)2 Organization (org.opencastproject.security.api.Organization)2 UnauthorizedException (org.opencastproject.security.api.UnauthorizedException)2 SeriesException (org.opencastproject.series.api.SeriesException)2 SeriesEntity (org.opencastproject.series.impl.persistence.SeriesEntity)2 NotFoundException (org.opencastproject.util.NotFoundException)2 FunctionException (org.opencastproject.util.data.FunctionException)2 ServiceException (org.osgi.framework.ServiceException)2 Entry (java.util.Map.Entry)1 DublinCoreCatalog (org.opencastproject.metadata.dublincore.DublinCoreCatalog)1 Effect0 (org.opencastproject.util.data.Effect0)1 Function0 (org.opencastproject.util.data.Function0)1