ThemesEndpoint { @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) }, responses = { @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 (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 (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()); }  void setThemesServiceDatabase(ThemesServiceDatabase themesServiceDatabase); void setSecurityService(SecurityService securityService); void setIndex(AdminUISearchIndex index); void setSeriesService(SeriesService seriesService); void setStaticFileService(StaticFileService staticFileService); void setStaticFileRestService(StaticFileRestService staticFileRestService); void activate(BundleContext bundleContext); @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) }, responses = { @RestResponse(description = "A JSON representation of the themes", responseCode = HttpServletResponse.SC_OK) }, returnDescription = "") Response getThemes(@QueryParam("filter") String filter, @QueryParam("limit") int limit,
          @QueryParam("offset") int offset, @QueryParam("sort") String sort); @GET @Path("{themeId}.json") @Produces(MediaType.APPLICATION_JSON) @RestQuery(name = "getTheme", description = "Returns the theme by the given id as JSON", returnDescription = "The theme as JSON", pathParameters = { @RestParameter(name = "themeId", description = "The theme id", isRequired = true, type = RestParameter.Type.INTEGER) }, responses = { @RestResponse(description = "Returns the theme as JSON", responseCode = HttpServletResponse.SC_OK), @RestResponse(description = "No theme with this identifier was found.", responseCode = HttpServletResponse.SC_NOT_FOUND) }) Response getThemeResponse(@PathParam("themeId") long id); @GET @Path("{themeId}/usage.json") @Produces(MediaType.APPLICATION_JSON) @RestQuery(name = "getThemeUsage", description = "Returns the theme usage by the given id as JSON", returnDescription = "The theme usage as JSON", pathParameters = { @RestParameter(name = "themeId", description = "The theme id", isRequired = true, type = RestParameter.Type.INTEGER) }, responses = { @RestResponse(description = "Returns the theme usage as JSON", responseCode = HttpServletResponse.SC_OK), @RestResponse(description = "Theme with the given id does not exist", responseCode = HttpServletResponse.SC_NOT_FOUND) }) Response getThemeUsage(@PathParam("themeId") long themeId); @POST @Path("") @RestQuery(name = "createTheme", description = "Add a theme", returnDescription = "Return the created theme", restParameters = { @RestParameter(name = "default", description = "Whether the theme is default", isRequired = true, type = Type.BOOLEAN), @RestParameter(name = "name", description = "The theme name", isRequired = true, type = Type.STRING), @RestParameter(name = "description", description = "The theme description", isRequired = false, type = Type.TEXT), @RestParameter(name = "bumperActive", description = "Whether the theme bumper is active", isRequired = false, type = Type.BOOLEAN), @RestParameter(name = "trailerActive", description = "Whether the theme trailer is active", isRequired = false, type = Type.BOOLEAN), @RestParameter(name = "titleSlideActive", description = "Whether the theme title slide is active", isRequired = false, type = Type.BOOLEAN), @RestParameter(name = "licenseSlideActive", description = "Whether the theme license slide is active", isRequired = false, type = Type.BOOLEAN), @RestParameter(name = "watermarkActive", description = "Whether the theme watermark is active", isRequired = false, type = Type.BOOLEAN), @RestParameter(name = "bumperFile", description = "The theme bumper file", isRequired = false, type = Type.STRING), @RestParameter(name = "trailerFile", description = "The theme trailer file", isRequired = false, type = Type.STRING), @RestParameter(name = "watermarkFile", description = "The theme watermark file", isRequired = false, type = Type.STRING), @RestParameter(name = "titleSlideBackground", description = "The theme title slide background file", isRequired = false, type = Type.STRING), @RestParameter(name = "licenseSlideBackground", description = "The theme license slide background file", isRequired = false, type = Type.STRING), @RestParameter(name = "titleSlideMetadata", description = "The theme title slide metadata", isRequired = false, type = Type.STRING), @RestParameter(name = "licenseSlideDescription", description = "The theme license slide description", isRequired = false, type = Type.STRING), @RestParameter(name = "watermarkPosition", description = "The theme watermark position", isRequired = false, type = Type.STRING), }, responses = { @RestResponse(responseCode = SC_OK, description = "Theme created"), @RestResponse(responseCode = SC_BAD_REQUEST, description = "The theme references a non-existing file") }) Response createTheme(@FormParam("default") boolean isDefault, @FormParam("name") String name,
          @FormParam("description") String description, @FormParam("bumperActive") Boolean bumperActive,
          @FormParam("trailerActive") Boolean trailerActive, @FormParam("titleSlideActive") Boolean titleSlideActive,
          @FormParam("licenseSlideActive") Boolean licenseSlideActive,
          @FormParam("watermarkActive") Boolean watermarkActive, @FormParam("bumperFile") String bumperFile,
          @FormParam("trailerFile") String trailerFile, @FormParam("watermarkFile") String watermarkFile,
          @FormParam("titleSlideBackground") String titleSlideBackground,
          @FormParam("licenseSlideBackground") String licenseSlideBackground,
          @FormParam("titleSlideMetadata") String titleSlideMetadata,
          @FormParam("licenseSlideDescription") String licenseSlideDescription,
          @FormParam("watermarkPosition") String watermarkPosition); @PUT @Path("{themeId}") @RestQuery(name = "updateTheme", description = "Updates a theme", returnDescription = "Return the updated theme", pathParameters = { @RestParameter(name = "themeId", description = "The theme identifier", isRequired = true, type = Type.INTEGER) }, restParameters = { @RestParameter(name = "default", description = "Whether the theme is default", isRequired = false, type = Type.BOOLEAN), @RestParameter(name = "name", description = "The theme name", isRequired = false, type = Type.STRING), @RestParameter(name = "description", description = "The theme description", isRequired = false, type = Type.TEXT), @RestParameter(name = "bumperActive", description = "Whether the theme bumper is active", isRequired = false, type = Type.BOOLEAN), @RestParameter(name = "trailerActive", description = "Whether the theme trailer is active", isRequired = false, type = Type.BOOLEAN), @RestParameter(name = "titleSlideActive", description = "Whether the theme title slide is active", isRequired = false, type = Type.BOOLEAN), @RestParameter(name = "licenseSlideActive", description = "Whether the theme license slide is active", isRequired = false, type = Type.BOOLEAN), @RestParameter(name = "watermarkActive", description = "Whether the theme watermark is active", isRequired = false, type = Type.BOOLEAN), @RestParameter(name = "bumperFile", description = "The theme bumper file", isRequired = false, type = Type.STRING), @RestParameter(name = "trailerFile", description = "The theme trailer file", isRequired = false, type = Type.STRING), @RestParameter(name = "watermarkFile", description = "The theme watermark file", isRequired = false, type = Type.STRING), @RestParameter(name = "titleSlideBackground", description = "The theme title slide background file", isRequired = false, type = Type.STRING), @RestParameter(name = "licenseSlideBackground", description = "The theme license slide background file", isRequired = false, type = Type.STRING), @RestParameter(name = "titleSlideMetadata", description = "The theme title slide metadata", isRequired = false, type = Type.STRING), @RestParameter(name = "licenseSlideDescription", description = "The theme license slide description", isRequired = false, type = Type.STRING), @RestParameter(name = "watermarkPosition", description = "The theme watermark position", isRequired = false, type = Type.STRING), }, responses = { @RestResponse(responseCode = SC_OK, description = "Theme updated"), @RestResponse(responseCode = SC_NOT_FOUND, description = "If the theme has not been found."), }) Response updateTheme(@PathParam("themeId") long themeId, @FormParam("default") Boolean isDefault,
          @FormParam("name") String name, @FormParam("description") String description,
          @FormParam("bumperActive") Boolean bumperActive, @FormParam("trailerActive") Boolean trailerActive,
          @FormParam("titleSlideActive") Boolean titleSlideActive,
          @FormParam("licenseSlideActive") Boolean licenseSlideActive,
          @FormParam("watermarkActive") Boolean watermarkActive, @FormParam("bumperFile") String bumperFile,
          @FormParam("trailerFile") String trailerFile, @FormParam("watermarkFile") String watermarkFile,
          @FormParam("titleSlideBackground") String titleSlideBackground,
          @FormParam("licenseSlideBackground") String licenseSlideBackground,
          @FormParam("titleSlideMetadata") String titleSlideMetadata,
          @FormParam("licenseSlideDescription") String licenseSlideDescription,
          @FormParam("watermarkPosition") String watermarkPosition); @DELETE @Path("{themeId}") @RestQuery(name = "deleteTheme", description = "Deletes a theme", returnDescription = "The method doesn't return any content", pathParameters = { @RestParameter(name = "themeId", isRequired = true, description = "The theme identifier", type = RestParameter.Type.INTEGER) }, responses = { @RestResponse(responseCode = SC_NOT_FOUND, description = "If the theme has not been found."), @RestResponse(responseCode = SC_NO_CONTENT, description = "The method does not return any content"), @RestResponse(responseCode = SC_UNAUTHORIZED, description = "If the current user is not authorized to perform this action") }) Response deleteTheme(@PathParam("themeId") long themeId);  }
@Test public void testGetThemes() throws ParseException, IOException { String themesString = IOUtils.toString(getClass().getResource("/themes.json"), "UTF-8"); String result = given().expect().statusCode(HttpStatus.SC_OK).when().get(rt.host("/themes.json")).asString(); logger.info("Expected" + themesString); logger.info("Result" + result); assertThat(themesString, SameJSONAs.sameJSONAs(result).allowingAnyArrayOrdering()); }