Search in sources :

Example 1 with SearchIndexException

use of org.opencastproject.matterhorn.search.SearchIndexException in project opencast by opencast.

the class IndexServiceImpl method updateAllEventMetadata.

@Override
public MetadataList updateAllEventMetadata(String id, String metadataJSON, AbstractSearchIndex index) throws IllegalArgumentException, IndexServiceException, NotFoundException, SearchIndexException, UnauthorizedException {
    MetadataList metadataList;
    try {
        metadataList = getMetadataListWithAllEventCatalogUIAdapters();
        metadataList.fromJSON(metadataJSON);
    } catch (Exception e) {
        logger.warn("Not able to parse the event metadata {}: {}", metadataJSON, getStackTrace(e));
        throw new IllegalArgumentException("Not able to parse the event metadata " + metadataJSON, e);
    }
    return updateEventMetadata(id, metadataList, index);
}
Also used : MetadataList(org.opencastproject.index.service.catalog.adapter.MetadataList) SchedulerException(org.opencastproject.scheduler.api.SchedulerException) IngestException(org.opencastproject.ingest.api.IngestException) WebApplicationException(javax.ws.rs.WebApplicationException) MetadataParsingException(org.opencastproject.metadata.dublincore.MetadataParsingException) EventCommentException(org.opencastproject.event.comment.EventCommentException) IOException(java.io.IOException) JSONException(org.codehaus.jettison.json.JSONException) SearchIndexException(org.opencastproject.matterhorn.search.SearchIndexException) ParseException(java.text.ParseException) SeriesException(org.opencastproject.series.api.SeriesException) WorkflowException(org.opencastproject.workflow.api.WorkflowException) MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) IndexServiceException(org.opencastproject.index.service.exception.IndexServiceException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException) WorkflowDatabaseException(org.opencastproject.workflow.api.WorkflowDatabaseException) AssetManagerException(org.opencastproject.assetmanager.api.AssetManagerException)

Example 2 with SearchIndexException

use of org.opencastproject.matterhorn.search.SearchIndexException in project opencast by opencast.

the class EventIndexUtils method updateComments.

/**
 * Update an event with the given has comments and has open comments status.
 *
 * @param eventId
 *          the event id
 * @param hasComments
 *          whether it has comments
 * @param hasOpenComments
 *          whether it has open comments
 * @param organization
 *          the organization
 * @param user
 *          the user
 * @param searchIndex
 *          the serach index
 * @throws SearchIndexException
 *           if error occurs
 * @throws NotFoundException
 *           if event has not been found
 */
public static void updateComments(String eventId, boolean hasComments, boolean hasOpenComments, boolean needsCutting, String organization, User user, AbstractSearchIndex searchIndex) throws SearchIndexException, NotFoundException {
    if (!hasComments && hasOpenComments)
        throw new IllegalStateException("Invalid comment update request: You can't have open comments without having any comments!");
    if (!hasOpenComments && needsCutting)
        throw new IllegalStateException("Invalid comment update request: You can't have an needs cutting comment without having any open comments!");
    Event event = getEvent(eventId, organization, user, searchIndex);
    if (event == null)
        throw new NotFoundException("No event with id " + eventId + " found.");
    event.setHasComments(hasComments);
    event.setHasOpenComments(hasOpenComments);
    event.setNeedsCutting(needsCutting);
    try {
        searchIndex.addOrUpdate(event);
    } catch (SearchIndexException e) {
        logger.warn("Unable to update event '{}': {}", event, ExceptionUtils.getStackTrace(e));
    }
}
Also used : SearchIndexException(org.opencastproject.matterhorn.search.SearchIndexException) NotFoundException(org.opencastproject.util.NotFoundException)

Example 3 with SearchIndexException

use of org.opencastproject.matterhorn.search.SearchIndexException in project opencast by opencast.

the class AbstractSearchIndex method addOrUpdate.

/**
 * Add or update a series in the search index.
 *
 * @param series
 * @throws SearchIndexException
 */
public void addOrUpdate(Series series) throws SearchIndexException {
    logger.debug("Adding resource {} to search index", series);
    // if (!preparedIndices.contains(resource.getURI().getSite().getIdentifier())) {
    // try {
    // createIndex(resource.getURI().getSite());
    // } catch (IOException e) {
    // throw new SearchIndexException(e);
    // }
    // }
    // Add the resource to the index
    SearchMetadataCollection inputDocument = SeriesIndexUtils.toSearchMetadata(series);
    List<SearchMetadata<?>> resourceMetadata = inputDocument.getMetadata();
    ElasticsearchDocument doc = new ElasticsearchDocument(inputDocument.getIdentifier(), inputDocument.getDocumentType(), resourceMetadata);
    try {
        update(doc);
    } catch (Throwable t) {
        throw new SearchIndexException("Cannot write resource " + series + " to index", t);
    }
}
Also used : SearchMetadataCollection(org.opencastproject.matterhorn.search.impl.SearchMetadataCollection) SearchIndexException(org.opencastproject.matterhorn.search.SearchIndexException) SearchMetadata(org.opencastproject.matterhorn.search.SearchMetadata) ElasticsearchDocument(org.opencastproject.matterhorn.search.impl.ElasticsearchDocument)

Example 4 with SearchIndexException

use of org.opencastproject.matterhorn.search.SearchIndexException in project opencast by opencast.

the class AbstractSearchIndex method getByQuery.

/**
 * @param query
 *          The query to use to retrieve the themes that match the query
 * @return {@link SearchResult} collection of {@link Theme} from a query.
 * @throws SearchIndexException
 *           Thrown if there is an error getting the results.
 */
public SearchResult<Theme> getByQuery(ThemeSearchQuery query) throws SearchIndexException {
    logger.debug("Searching index using theme query '{}'", query);
    // Create the request builder
    SearchRequestBuilder requestBuilder = getSearchRequestBuilder(query, new ThemeQueryBuilder(query));
    try {
        return executeQuery(query, requestBuilder, new Fn<SearchMetadataCollection, Theme>() {

            @Override
            public Theme apply(SearchMetadataCollection metadata) {
                try {
                    return ThemeIndexUtils.toTheme(metadata);
                } catch (IOException e) {
                    return chuck(e);
                }
            }
        });
    } catch (Throwable t) {
        throw new SearchIndexException("Error querying theme index", t);
    }
}
Also used : SearchRequestBuilder(org.elasticsearch.action.search.SearchRequestBuilder) SearchMetadataCollection(org.opencastproject.matterhorn.search.impl.SearchMetadataCollection) SearchIndexException(org.opencastproject.matterhorn.search.SearchIndexException) ThemeQueryBuilder(org.opencastproject.index.service.impl.index.theme.ThemeQueryBuilder) Theme(org.opencastproject.index.service.impl.index.theme.Theme) IOException(java.io.IOException)

Example 5 with SearchIndexException

use of org.opencastproject.matterhorn.search.SearchIndexException in project opencast by opencast.

the class AbstractSearchIndex method addOrUpdate.

/**
 * Adds or updates the theme in the search index.
 *
 * @param theme
 *          The theme to add
 * @throws SearchIndexException
 *           Thrown if unable to add or update the theme.
 */
public void addOrUpdate(Theme theme) throws SearchIndexException {
    logger.debug("Adding resource {} to search index", theme);
    // if (!preparedIndices.contains(resource.getURI().getSite().getIdentifier())) {
    // try {
    // createIndex(resource.getURI().getSite());
    // } catch (IOException e) {
    // throw new SearchIndexException(e);
    // }
    // }
    // Add the resource to the index
    SearchMetadataCollection inputDocument = ThemeIndexUtils.toSearchMetadata(theme);
    List<SearchMetadata<?>> resourceMetadata = inputDocument.getMetadata();
    ElasticsearchDocument doc = new ElasticsearchDocument(inputDocument.getIdentifier(), inputDocument.getDocumentType(), resourceMetadata);
    try {
        update(doc);
    } catch (Throwable t) {
        throw new SearchIndexException("Cannot write resource " + theme + " to index", t);
    }
}
Also used : SearchMetadataCollection(org.opencastproject.matterhorn.search.impl.SearchMetadataCollection) SearchIndexException(org.opencastproject.matterhorn.search.SearchIndexException) SearchMetadata(org.opencastproject.matterhorn.search.SearchMetadata) ElasticsearchDocument(org.opencastproject.matterhorn.search.impl.ElasticsearchDocument)

Aggregations

SearchIndexException (org.opencastproject.matterhorn.search.SearchIndexException)43 NotFoundException (org.opencastproject.util.NotFoundException)18 WebApplicationException (javax.ws.rs.WebApplicationException)15 Path (javax.ws.rs.Path)14 RestQuery (org.opencastproject.util.doc.rest.RestQuery)14 Event (org.opencastproject.index.service.impl.index.event.Event)11 IOException (java.io.IOException)10 IndexServiceException (org.opencastproject.index.service.exception.IndexServiceException)10 UnauthorizedException (org.opencastproject.security.api.UnauthorizedException)10 SearchMetadataCollection (org.opencastproject.matterhorn.search.impl.SearchMetadataCollection)9 Produces (javax.ws.rs.Produces)8 SchedulerException (org.opencastproject.scheduler.api.SchedulerException)8 User (org.opencastproject.security.api.User)8 GET (javax.ws.rs.GET)7 ParseException (java.text.ParseException)6 ArrayList (java.util.ArrayList)6 JSONException (org.codehaus.jettison.json.JSONException)6 EventCommentException (org.opencastproject.event.comment.EventCommentException)6 Series (org.opencastproject.index.service.impl.index.series.Series)6 Theme (org.opencastproject.index.service.impl.index.theme.Theme)6