Search in sources :

Example 1 with Theme

use of org.opencastproject.index.service.impl.index.theme.Theme 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 2 with Theme

use of org.opencastproject.index.service.impl.index.theme.Theme in project opencast by opencast.

the class ThemeMessageReceiverImpl method execute.

@Override
protected void execute(ThemeItem themeItem) {
    String organization = getSecurityService().getOrganization().getId();
    User user = getSecurityService().getUser();
    switch(themeItem.getType()) {
        case Update:
            SerializableTheme serializableTheme = themeItem.getTheme();
            logger.debug("Update the theme with id '{}', name '{}', description '{}', organization '{}'", serializableTheme.getId(), serializableTheme.getName(), serializableTheme.getDescription(), organization);
            try {
                Theme theme = ThemeIndexUtils.getOrCreate(serializableTheme.getId(), organization, user, getSearchIndex());
                theme.setCreationDate(serializableTheme.getCreationDate());
                theme.setDefault(serializableTheme.isDefault());
                theme.setName(serializableTheme.getName());
                theme.setDescription(serializableTheme.getDescription());
                theme.setCreator(serializableTheme.getCreator());
                theme.setBumperActive(serializableTheme.isBumperActive());
                theme.setBumperFile(serializableTheme.getBumperFile());
                theme.setTrailerActive(serializableTheme.isTrailerActive());
                theme.setTrailerFile(serializableTheme.getTrailerFile());
                theme.setTitleSlideActive(serializableTheme.isTitleSlideActive());
                theme.setTitleSlideBackground(serializableTheme.getTitleSlideBackground());
                theme.setTitleSlideMetadata(serializableTheme.getTitleSlideMetadata());
                theme.setLicenseSlideActive(serializableTheme.isLicenseSlideActive());
                theme.setLicenseSlideBackground(serializableTheme.getLicenseSlideBackground());
                theme.setLicenseSlideDescription(serializableTheme.getLicenseSlideDescription());
                theme.setWatermarkActive(serializableTheme.isWatermarkActive());
                theme.setWatermarkFile(serializableTheme.getWatermarkFile());
                theme.setWatermarkPosition(serializableTheme.getWatermarkPosition());
                getSearchIndex().addOrUpdate(theme);
            } catch (SearchIndexException e) {
                logger.error("Error storing the theme {} to the search index: {}", serializableTheme.getId(), ExceptionUtils.getStackTrace(e));
                return;
            }
            break;
        case Delete:
            logger.debug("Received Delete Theme Event {}", themeItem.getThemeId());
            // Remove the theme from the search index
            try {
                getSearchIndex().delete(Theme.DOCUMENT_TYPE, Long.toString(themeItem.getThemeId()).concat(organization));
                logger.debug("Theme {} removed from {} search index", themeItem.getThemeId(), getSearchIndex().getIndexName());
            } catch (SearchIndexException e) {
                logger.error("Error deleting the group {} from the search index: {}", themeItem.getThemeId(), ExceptionUtils.getStackTrace(e));
                return;
            }
            return;
        default:
            throw new IllegalArgumentException("Unhandled type of ThemeItem");
    }
}
Also used : User(org.opencastproject.security.api.User) SearchIndexException(org.opencastproject.matterhorn.search.SearchIndexException) SerializableTheme(org.opencastproject.message.broker.api.theme.SerializableTheme) Theme(org.opencastproject.index.service.impl.index.theme.Theme) SerializableTheme(org.opencastproject.message.broker.api.theme.SerializableTheme)

Example 3 with Theme

use of org.opencastproject.index.service.impl.index.theme.Theme in project opencast by opencast.

the class SeriesEndpoint method getSeriesTheme.

@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("{seriesId}/theme.json")
@RestQuery(name = "getSeriesTheme", description = "Returns the series theme id and name as JSON", returnDescription = "Returns the series theme name and id as JSON", pathParameters = { @RestParameter(name = "seriesId", isRequired = true, description = "The series identifier", type = STRING) }, reponses = { @RestResponse(responseCode = SC_OK, description = "The series theme id and name as JSON."), @RestResponse(responseCode = SC_NOT_FOUND, description = "The series or theme has not been found") })
public Response getSeriesTheme(@PathParam("seriesId") String seriesId) {
    Long themeId;
    try {
        Opt<Series> series = indexService.getSeries(seriesId, searchIndex);
        if (series.isNone())
            return notFound("Cannot find a series with id {}", seriesId);
        themeId = series.get().getTheme();
    } catch (SearchIndexException e) {
        logger.error("Unable to get series {}: {}", seriesId, ExceptionUtils.getStackTrace(e));
        throw new WebApplicationException(e);
    }
    // If no theme is set return empty JSON
    if (themeId == null)
        return okJson(obj());
    try {
        Opt<Theme> themeOpt = getTheme(themeId);
        if (themeOpt.isNone())
            return notFound("Cannot find a theme with id {}", themeId);
        return getSimpleThemeJsonResponse(themeOpt.get());
    } catch (SearchIndexException e) {
        logger.error("Unable to get theme {}: {}", themeId, ExceptionUtils.getStackTrace(e));
        throw new WebApplicationException(e);
    }
}
Also used : Series(org.opencastproject.index.service.impl.index.series.Series) SearchIndexException(org.opencastproject.matterhorn.search.SearchIndexException) WebApplicationException(javax.ws.rs.WebApplicationException) Theme(org.opencastproject.index.service.impl.index.theme.Theme) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Example 4 with Theme

use of org.opencastproject.index.service.impl.index.theme.Theme in project opencast by opencast.

the class SeriesEndpoint method getNewThemes.

@GET
@Path("new/themes")
@SuppressWarnings("unchecked")
@RestQuery(name = "getNewThemes", description = "Returns all the data related to the themes tab in the new series modal as JSON", returnDescription = "All the data related to the series themes tab as JSON", reponses = { @RestResponse(responseCode = SC_OK, description = "Returns all the data related to the series themes tab as JSON") })
public Response getNewThemes() {
    ThemeSearchQuery query = new ThemeSearchQuery(securityService.getOrganization().getId(), securityService.getUser());
    // need to set limit because elasticsearch limit results by 10 per default
    query.withLimit(Integer.MAX_VALUE);
    query.withOffset(0);
    query.sortByName(SearchQuery.Order.Ascending);
    SearchResult<Theme> results = null;
    try {
        results = searchIndex.getByQuery(query);
    } catch (SearchIndexException e) {
        logger.error("The admin UI Search Index was not able to get the themes: {}", ExceptionUtils.getStackTrace(e));
        return RestUtil.R.serverError();
    }
    JSONObject themesJson = new JSONObject();
    for (SearchResultItem<Theme> item : results.getItems()) {
        JSONObject themeInfoJson = new JSONObject();
        Theme theme = item.getSource();
        themeInfoJson.put("name", theme.getName());
        themeInfoJson.put("description", theme.getDescription());
        themesJson.put(theme.getIdentifier(), themeInfoJson);
    }
    return Response.ok(themesJson.toJSONString()).build();
}
Also used : SearchIndexException(org.opencastproject.matterhorn.search.SearchIndexException) JSONObject(org.json.simple.JSONObject) ThemeSearchQuery(org.opencastproject.index.service.impl.index.theme.ThemeSearchQuery) Theme(org.opencastproject.index.service.impl.index.theme.Theme) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Example 5 with Theme

use of org.opencastproject.index.service.impl.index.theme.Theme in project opencast by opencast.

the class SeriesEndpoint method updateSeriesTheme.

@PUT
@Path("{seriesId}/theme")
@RestQuery(name = "updateSeriesTheme", description = "Update the series theme id", returnDescription = "Returns the id and name of the theme.", pathParameters = { @RestParameter(name = "seriesId", isRequired = true, description = "The series identifier", type = STRING) }, restParameters = { @RestParameter(name = "themeId", isRequired = true, type = RestParameter.Type.INTEGER, description = "The id of the theme for this series") }, reponses = { @RestResponse(responseCode = SC_OK, description = "The series theme has been updated and the theme id and name are returned as JSON."), @RestResponse(responseCode = SC_NOT_FOUND, description = "The series or theme has not been found"), @RestResponse(responseCode = SC_UNAUTHORIZED, description = "If the current user is not authorized to perform this action") })
public Response updateSeriesTheme(@PathParam("seriesId") String seriesID, @FormParam("themeId") long themeId) throws UnauthorizedException, NotFoundException {
    try {
        Opt<Theme> themeOpt = getTheme(themeId);
        if (themeOpt.isNone())
            return notFound("Cannot find a theme with id {}", themeId);
        seriesService.updateSeriesProperty(seriesID, THEME_KEY, Long.toString(themeId));
        return getSimpleThemeJsonResponse(themeOpt.get());
    } catch (SeriesException e) {
        logger.error("Unable to update series theme {}: {}", themeId, ExceptionUtils.getStackTrace(e));
        throw new WebApplicationException(e);
    } catch (SearchIndexException e) {
        logger.error("Unable to get theme {}: {}", themeId, ExceptionUtils.getStackTrace(e));
        throw new WebApplicationException(e);
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) SearchIndexException(org.opencastproject.matterhorn.search.SearchIndexException) Theme(org.opencastproject.index.service.impl.index.theme.Theme) SeriesException(org.opencastproject.series.api.SeriesException) Path(javax.ws.rs.Path) RestQuery(org.opencastproject.util.doc.rest.RestQuery) PUT(javax.ws.rs.PUT)

Aggregations

Theme (org.opencastproject.index.service.impl.index.theme.Theme)6 SearchIndexException (org.opencastproject.matterhorn.search.SearchIndexException)6 Path (javax.ws.rs.Path)3 RestQuery (org.opencastproject.util.doc.rest.RestQuery)3 GET (javax.ws.rs.GET)2 WebApplicationException (javax.ws.rs.WebApplicationException)2 ThemeSearchQuery (org.opencastproject.index.service.impl.index.theme.ThemeSearchQuery)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 PUT (javax.ws.rs.PUT)1 Produces (javax.ws.rs.Produces)1 SearchRequestBuilder (org.elasticsearch.action.search.SearchRequestBuilder)1 JSONObject (org.json.simple.JSONObject)1 ListProviderException (org.opencastproject.index.service.exception.ListProviderException)1 Series (org.opencastproject.index.service.impl.index.series.Series)1 ThemeQueryBuilder (org.opencastproject.index.service.impl.index.theme.ThemeQueryBuilder)1 SearchResult (org.opencastproject.matterhorn.search.SearchResult)1 SearchResultItem (org.opencastproject.matterhorn.search.SearchResultItem)1 SearchMetadataCollection (org.opencastproject.matterhorn.search.impl.SearchMetadataCollection)1 SerializableTheme (org.opencastproject.message.broker.api.theme.SerializableTheme)1