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