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