SeriesEndpoint implements ManagedService { private Opt<Theme> getTheme(long id) throws SearchIndexException { SearchResult<Theme> result = searchIndex.getByQuery(new ThemeSearchQuery(securityService.getOrganization().getId(), securityService.getUser()).withIdentifier(id)); if (result.getPageSize() == 0) { logger.debug("Didn't find theme with id {}", id); return Opt.<Theme> none(); } return Opt.some(result.getItems()[0].getSource()); }  void setSeriesService(SeriesService seriesService); void setIndex(AdminUISearchIndex index); void setIndexService(IndexService indexService); void setSecurityService(SecurityService securityService); void setAclServiceFactory(AclServiceFactory aclServiceFactory); @Override void updated(Dictionary<String, ?> properties); @GET @Path("{seriesId}/access.json") @SuppressWarnings("unchecked") @Produces(MediaType.APPLICATION_JSON) @RestQuery(name = "getseriesaccessinformation", description = "Get the access information of a series", returnDescription = "The access information", pathParameters = { @RestParameter(name = "seriesId", isRequired = true, description = "The series identifier", type = Type.STRING) }, responses = { @RestResponse(responseCode = SC_BAD_REQUEST, description = "The required form params were missing in the request."), @RestResponse(responseCode = SC_NOT_FOUND, description = "If the series has not been found."), @RestResponse(responseCode = SC_OK, description = "The access information ") }) Response getSeriesAccessInformation(@PathParam("seriesId") String seriesId); @GET @Produces(MediaType.APPLICATION_JSON) @Path("{seriesId}/metadata.json") @RestQuery(name = "getseriesmetadata", description = "Returns the series metadata as JSON", returnDescription = "Returns the series metadata as JSON", pathParameters = { @RestParameter(name = "seriesId", isRequired = true, description = "The series identifier", type = STRING) }, responses = { @RestResponse(responseCode = SC_OK, description = "The series metadata as JSON."), @RestResponse(responseCode = SC_NOT_FOUND, description = "The series has not been found"), @RestResponse(responseCode = SC_UNAUTHORIZED, description = "If the current user is not authorized to perform this action") }) Response getSeriesMetadata(@PathParam("seriesId") String series); @PUT @Path("{seriesId}/metadata") @RestQuery(name = "updateseriesmetadata", description = "Update the series metadata with the one given JSON", returnDescription = "Returns OK if the metadata have been saved.", pathParameters = { @RestParameter(name = "seriesId", isRequired = true, description = "The series identifier", type = STRING) }, restParameters = { @RestParameter(name = "metadata", isRequired = true, type = RestParameter.Type.TEXT, description = "The list of metadata to update") }, responses = { @RestResponse(responseCode = SC_OK, description = "The series metadata as JSON."), @RestResponse(responseCode = SC_NOT_FOUND, description = "The series has not been found"), @RestResponse(responseCode = SC_UNAUTHORIZED, description = "If the current user is not authorized to perform this action") }) Response updateSeriesMetadata(@PathParam("seriesId") String seriesID,
          @FormParam("metadata") String metadataJSON); @GET @Path("new/metadata") @RestQuery(name = "getNewMetadata", description = "Returns all the data related to the metadata tab in the new series modal as JSON", returnDescription = "All the data related to the series metadata tab as JSON", responses = { @RestResponse(responseCode = SC_OK, description = "Returns all the data related to the series metadata tab as JSON") }) Response getNewMetadata(); @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", responses = { @RestResponse(responseCode = SC_OK, description = "Returns all the data related to the series themes tab as JSON") }) Response getNewThemes(); @POST @Path("new") @RestQuery(name = "createNewSeries", description = "Creates a new series by the given metadata as JSON", returnDescription = "The created series id", restParameters = { @RestParameter(name = "metadata", isRequired = true, description = "The metadata as JSON", type = RestParameter.Type.TEXT) }, responses = { @RestResponse(responseCode = HttpServletResponse.SC_CREATED, description = "Returns the created series id"), @RestResponse(responseCode = HttpServletResponse.SC_BAD_REQUEST, description = "he request could not be fulfilled due to the incorrect syntax of the request"), @RestResponse(responseCode = SC_UNAUTHORIZED, description = "If user doesn't have rights to create the series") }) Response createNewSeries(@FormParam("metadata") String metadata); @DELETE @Path("{seriesId}") @Produces(MediaType.APPLICATION_JSON) @RestQuery(name = "deleteseries", description = "Delete a series.", returnDescription = "Ok if the series has been deleted.", pathParameters = { @RestParameter(name = "seriesId", isRequired = true, description = "The id of the series to delete.", type = STRING), }, responses = { @RestResponse(responseCode = SC_OK, description = "The series has been deleted."), @RestResponse(responseCode = HttpServletResponse.SC_NOT_FOUND, description = "The series could not be found.") }) Response deleteSeries(@PathParam("seriesId") String id); @POST @Path("deleteSeries") @Produces(MediaType.APPLICATION_JSON) @RestQuery(name = "deletemultipleseries", description = "Deletes a json list of series by their given ids e.g. [\"Series-1\", \"Series-2\"]", returnDescription = "A JSON object with arrays that show whether a series was deleted, was not found or there was an error deleting it.", responses = { @RestResponse(description = "Series have been deleted", responseCode = HttpServletResponse.SC_OK), @RestResponse(description = "The list of ids could not be parsed into a json list.", responseCode = HttpServletResponse.SC_BAD_REQUEST) }) Response deleteMultipleSeries(String seriesIdsContent); @GET @Produces(MediaType.APPLICATION_JSON) @Path("series.json") @RestQuery(name = "listSeriesAsJson", description = "Returns the series matching the query parameters", returnDescription = "Returns the series search results as JSON", restParameters = { @RestParameter(name = "sortorganizer", isRequired = false, description = "The sort type to apply to the series organizer or organizers either Ascending or Descending.", type = STRING), @RestParameter(name = "sort", description = "The order instructions used to sort the query result. Must be in the form '<field name>:(ASC|DESC)'", isRequired = false, type = STRING), @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(name = "offset", isRequired = false, description = "The page offset", type = INTEGER, defaultValue = "0"), @RestParameter(name = "limit", isRequired = false, description = "The limit to define the number of returned results (-1 for all)", type = INTEGER, defaultValue = "100") }, responses = { @RestResponse(responseCode = SC_OK, description = "The access control list."), @RestResponse(responseCode = SC_UNAUTHORIZED, description = "If the current user is not authorized to perform this action") }) Response getSeries(@QueryParam("filter") String filter, @QueryParam("sort") String sort,
          @QueryParam("offset") int offset, @QueryParam("limit") int limit); HashMap<String, String> getUserSeriesByAccess(boolean writeAccess); @SuppressWarnings("unchecked") @GET @Produces(MediaType.APPLICATION_JSON) @Path("{id}/properties") @RestQuery(name = "getSeriesProperties", description = "Returns the series properties", returnDescription = "Returns the series properties as JSON", pathParameters = { @RestParameter(name = "id", description = "ID of series", isRequired = true, type = Type.STRING) }, responses = { @RestResponse(responseCode = SC_OK, description = "The access control list."), @RestResponse(responseCode = SC_UNAUTHORIZED, description = "If the current user is not authorized to perform this action") }) Response getSeriesPropertiesAsJson(@PathParam("id") String seriesId); @GET @Produces(MediaType.APPLICATION_JSON) @Path("{seriesId}/property/{propertyName}.json") @RestQuery(name = "getSeriesProperty", description = "Returns a series property value", returnDescription = "Returns the series property value", pathParameters = { @RestParameter(name = "seriesId", description = "ID of series", isRequired = true, type = Type.STRING), @RestParameter(name = "propertyName", description = "Name of series property", isRequired = true, type = Type.STRING) }, responses = { @RestResponse(responseCode = SC_OK, description = "The access control list."), @RestResponse(responseCode = SC_UNAUTHORIZED, description = "If the current user is not authorized to perform this action") }) Response getSeriesProperty(@PathParam("seriesId") String seriesId,
          @PathParam("propertyName") String propertyName); @POST @Path("/{seriesId}/property") @RestQuery(name = "updateSeriesProperty", description = "Updates a series property", returnDescription = "No content.", restParameters = { @RestParameter(name = "name", isRequired = true, description = "The property's name", type = TEXT), @RestParameter(name = "value", isRequired = true, description = "The property's value", type = TEXT) }, pathParameters = { @RestParameter(name = "seriesId", isRequired = true, description = "The series identifier", type = STRING) }, responses = { @RestResponse(responseCode = SC_NOT_FOUND, description = "No series with this identifier was found."), @RestResponse(responseCode = SC_NO_CONTENT, description = "The access control list has been updated."), @RestResponse(responseCode = SC_UNAUTHORIZED, description = "If the current user is not authorized to perform this action"), @RestResponse(responseCode = SC_BAD_REQUEST, description = "The required path or form params were missing in the request.") }) Response updateSeriesProperty(@PathParam("seriesId") String seriesId, @FormParam("name") String name,
          @FormParam("value") String value); @DELETE @Path("{seriesId}/property/{propertyName}") @RestQuery(name = "deleteSeriesProperty", description = "Deletes a series property", returnDescription = "No Content", pathParameters = { @RestParameter(name = "seriesId", description = "ID of series", isRequired = true, type = Type.STRING), @RestParameter(name = "propertyName", description = "Name of series property", isRequired = true, type = Type.STRING) }, responses = { @RestResponse(responseCode = SC_NO_CONTENT, description = "The series property has been deleted."), @RestResponse(responseCode = SC_NOT_FOUND, description = "The series or property has not been found."), @RestResponse(responseCode = SC_UNAUTHORIZED, description = "If the current user is not authorized to perform this action") }) Response deleteSeriesProperty(@PathParam("seriesId") String seriesId,
          @PathParam("propertyName") String propertyName); @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) }, responses = { @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") }) Response getSeriesTheme(@PathParam("seriesId") String seriesId); @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") }, responses = { @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") }) Response updateSeriesTheme(@PathParam("seriesId") String seriesID, @FormParam("themeId") long themeId); @DELETE @Path("{seriesId}/theme") @RestQuery(name = "deleteSeriesTheme", description = "Removes the theme from the series", returnDescription = "Returns no content", pathParameters = { @RestParameter(name = "seriesId", isRequired = true, description = "The series identifier", type = STRING) }, responses = { @RestResponse(responseCode = SC_NO_CONTENT, description = "The series theme has been removed"), @RestResponse(responseCode = SC_NOT_FOUND, description = "The series has not been found"), @RestResponse(responseCode = SC_UNAUTHORIZED, description = "If the current user is not authorized to perform this action") }) Response deleteSeriesTheme(@PathParam("seriesId") String seriesID); @POST @Path("/{seriesId}/access") @RestQuery(name = "applyAclToSeries", description = "Immediate application of an ACL to a series", returnDescription = "Status code", pathParameters = { @RestParameter(name = "seriesId", isRequired = true, description = "The series ID", type = STRING) }, restParameters = { @RestParameter(name = "acl", isRequired = true, description = "The ACL to apply", type = STRING), @RestParameter(name = "override", isRequired = false, defaultValue = "false", description = "If true the series ACL will take precedence over any existing episode ACL", type = BOOLEAN) }, responses = { @RestResponse(responseCode = SC_OK, description = "The ACL has been successfully applied"), @RestResponse(responseCode = SC_BAD_REQUEST, description = "Unable to parse the given ACL"), @RestResponse(responseCode = SC_NOT_FOUND, description = "The series has not been found"), @RestResponse(responseCode = SC_INTERNAL_SERVER_ERROR, description = "Internal error") }) Response applyAclToSeries(@PathParam("seriesId") String seriesId, @FormParam("acl") String acl,
          @DefaultValue("false") @FormParam("override") boolean override); @GET @Path("{seriesId}/hasEvents.json") @Produces(MediaType.APPLICATION_JSON) @RestQuery(name = "hasEvents", description = "Check if given series has events", returnDescription = "true if series has events, otherwise false", pathParameters = { @RestParameter(name = "seriesId", isRequired = true, description = "The series identifier", type = Type.STRING) }, responses = { @RestResponse(responseCode = SC_BAD_REQUEST, description = "The required form params were missing in the request."), @RestResponse(responseCode = SC_NOT_FOUND, description = "If the series has not been found."), @RestResponse(responseCode = SC_OK, description = "The access information ") }) Response getSeriesEvents(@PathParam("seriesId") String seriesId); @GET @Path("configuration.json") @Produces(MediaType.APPLICATION_JSON) @RestQuery(name = "getseriesconfiguration", description = "Get the series configuration", returnDescription = "List of configuration keys", responses = { @RestResponse(responseCode = SC_BAD_REQUEST, description = "The required form params were missing in the request."), @RestResponse(responseCode = SC_NOT_FOUND, description = "If the series has not been found."), @RestResponse(responseCode = SC_OK, description = "The access information ") }) Response getSeriesOptions(); Boolean getOnlySeriesWithWriteAccessSeriesTab(); Boolean getOnlySeriesWithWriteAccessEventsFilter(); static final String THEME_KEY; static final String SERIES_HASEVENTS_DELETE_ALLOW_KEY; static final String SERIESTAB_ONLYSERIESWITHWRITEACCESS_KEY; static final String EVENTSFILTER_ONLYSERIESWITHWRITEACCESS_KEY; }
@Test public void testGetTheme() throws ParseException { String foundId = "1"; String seriesNotFound = "11"; String themeNotFound = "2"; String result = given().pathParam("seriesId", foundId).expect().statusCode(HttpStatus.SC_OK).when() .get(rt.host("/{seriesId}/theme.json")).asString(); JSONObject theme = ((JSONObject) parser.parse(result)); assertEquals("theme-1-name", theme.get(foundId)); given().pathParam("seriesId", seriesNotFound).expect().statusCode(HttpStatus.SC_NOT_FOUND).when() .get(rt.host("/{seriesId}/theme.json")).asString(); result = given().pathParam("seriesId", themeNotFound).expect().statusCode(HttpStatus.SC_OK).when() .get(rt.host("/{seriesId}/theme.json")).asString(); assertEquals("{}", result); }