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