use of org.opencastproject.themes.Theme in project opencast by opencast.
the class ThemesEndpoint method getThemes.
@GET
@Produces({ MediaType.APPLICATION_JSON })
@Path("themes.json")
@RestQuery(name = "getThemes", description = "Return all of the known themes on the system", restParameters = { @RestParameter(name = "filter", isRequired = false, description = "The filter used for the query. They should be formated like that: 'filter1:value1,filter2:value2'", type = STRING), @RestParameter(defaultValue = "0", description = "The maximum number of items to return per page.", isRequired = false, name = "limit", type = RestParameter.Type.INTEGER), @RestParameter(defaultValue = "0", description = "The page number.", isRequired = false, name = "offset", type = RestParameter.Type.INTEGER), @RestParameter(name = "sort", isRequired = false, description = "The sort order. May include any of the following: NAME, CREATOR. Add '_DESC' to reverse the sort order (e.g. CREATOR_DESC).", type = STRING) }, reponses = { @RestResponse(description = "A JSON representation of the themes", responseCode = HttpServletResponse.SC_OK) }, returnDescription = "")
public Response getThemes(@QueryParam("filter") String filter, @QueryParam("limit") int limit, @QueryParam("offset") int offset, @QueryParam("sort") String sort) {
Option<Integer> optLimit = Option.option(limit);
Option<Integer> optOffset = Option.option(offset);
Option<String> optSort = Option.option(trimToNull(sort));
ThemeSearchQuery query = new ThemeSearchQuery(securityService.getOrganization().getId(), securityService.getUser());
// If the limit is set to 0, this is not taken into account
if (optLimit.isSome() && limit == 0) {
optLimit = Option.none();
}
if (optLimit.isSome())
query.withLimit(optLimit.get());
if (optOffset.isSome())
query.withOffset(offset);
Map<String, String> filters = RestUtils.parseFilter(filter);
for (String name : filters.keySet()) {
if (ThemesListQuery.FILTER_CREATOR_NAME.equals(name))
query.withCreator(filters.get(name));
if (ThemesListQuery.FILTER_TEXT_NAME.equals(name))
query.withText(QueryPreprocessor.sanitize(filters.get(name)));
}
if (optSort.isSome()) {
Set<SortCriterion> sortCriteria = RestUtils.parseSortQueryParameter(optSort.get());
for (SortCriterion criterion : sortCriteria) {
switch(criterion.getFieldName()) {
case ThemeIndexSchema.NAME:
query.sortByName(criterion.getOrder());
break;
case ThemeIndexSchema.DESCRIPTION:
query.sortByDescription(criterion.getOrder());
break;
case ThemeIndexSchema.CREATOR:
query.sortByCreator(criterion.getOrder());
break;
case ThemeIndexSchema.DEFAULT:
query.sortByDefault(criterion.getOrder());
break;
case ThemeIndexSchema.CREATION_DATE:
query.sortByCreatedDateTime(criterion.getOrder());
break;
default:
logger.info("Unknown sort criteria {}", criterion.getFieldName());
return Response.status(SC_BAD_REQUEST).build();
}
}
}
logger.trace("Using Query: " + query.toString());
SearchResult<org.opencastproject.index.service.impl.index.theme.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 list:", e);
return RestUtil.R.serverError();
}
List<JValue> themesJSON = new ArrayList<JValue>();
// If the results list if empty, we return already a response.
if (results.getPageSize() == 0) {
logger.debug("No themes match the given filters.");
return okJsonList(themesJSON, nul(offset).getOr(0), nul(limit).getOr(0), 0);
}
for (SearchResultItem<org.opencastproject.index.service.impl.index.theme.Theme> item : results.getItems()) {
org.opencastproject.index.service.impl.index.theme.Theme theme = item.getSource();
themesJSON.add(themeToJSON(theme, false));
}
return okJsonList(themesJSON, nul(offset).getOr(0), nul(limit).getOr(0), results.getHitCount());
}
use of org.opencastproject.themes.Theme in project opencast by opencast.
the class TestThemesEndpoint method addData.
private void addData() throws MailServiceException, ThemesServiceDatabaseException {
Theme theme = new Theme(Option.some(theme1Id), creationDate, true, user, "The Theme name", "The Theme description", true, "bumper-file", true, "trailer-file", true, "title,room,date", "title-background-file", true, "license-background-file", "The license description", true, "watermark-file", "top-left");
themesServiceDatabaseImpl.updateTheme(theme);
}
use of org.opencastproject.themes.Theme in project opencast by opencast.
the class ThemesServiceDatabaseImpl method repopulate.
@Override
public void repopulate(final String indexName) {
final String destinationId = ThemeItem.THEME_QUEUE_PREFIX + WordUtils.capitalize(indexName);
for (final Organization organization : organizationDirectoryService.getOrganizations()) {
SecurityUtil.runAs(securityService, organization, SecurityUtil.createSystemUser(cc, organization), new Effect0() {
@Override
protected void run() {
try {
final List<Theme> themes = getThemes();
int total = themes.size();
int current = 1;
logger.info("Re-populating '{}' index with themes from organization {}. There are {} theme(s) to add to the index.", indexName, securityService.getOrganization().getId(), total);
for (Theme theme : themes) {
messageSender.sendObjectMessage(destinationId, MessageSender.DestinationType.Queue, ThemeItem.update(toSerializableTheme(theme)));
messageSender.sendObjectMessage(IndexProducer.RESPONSE_QUEUE, MessageSender.DestinationType.Queue, IndexRecreateObject.update(indexName, IndexRecreateObject.Service.Themes, total, current));
current++;
}
} catch (ThemesServiceDatabaseException e) {
logger.error("Unable to get themes from the database because: {}", ExceptionUtils.getStackTrace(e));
throw new IllegalStateException(e);
}
}
});
}
Organization organization = new DefaultOrganization();
SecurityUtil.runAs(securityService, organization, SecurityUtil.createSystemUser(cc, organization), new Effect0() {
@Override
protected void run() {
messageSender.sendObjectMessage(IndexProducer.RESPONSE_QUEUE, MessageSender.DestinationType.Queue, IndexRecreateObject.end(indexName, IndexRecreateObject.Service.Themes));
}
});
}
use of org.opencastproject.themes.Theme in project opencast by opencast.
the class ThemesServiceDatabaseImpl method getThemes.
private List<Theme> getThemes() throws ThemesServiceDatabaseException {
EntityManager em = null;
try {
em = emf.createEntityManager();
String orgId = securityService.getOrganization().getId();
TypedQuery<ThemeDto> q = em.createNamedQuery("Themes.findByOrg", ThemeDto.class).setParameter("org", orgId);
List<ThemeDto> themeDtos = q.getResultList();
List<Theme> themes = new ArrayList<>();
for (ThemeDto themeDto : themeDtos) {
themes.add(themeDto.toTheme(userDirectoryService));
}
return themes;
} catch (Exception e) {
logger.error("Could not get themes: {}", ExceptionUtils.getStackTrace(e));
throw new ThemesServiceDatabaseException(e);
} finally {
if (em != null)
em.close();
}
}
Aggregations