ToolsEndpoint implements ManagedService { MediaPackage addSmilToArchive(MediaPackage mediaPackage, final Smil smil) throws IOException { MediaPackageElementFlavor mediaPackageElementFlavor = adminUIConfiguration.getSmilCatalogFlavor(); String catalogId = smil.getId(); Catalog[] catalogs = mediaPackage.getCatalogs(); for (Catalog p: catalogs) { if (p.getFlavor().matches(mediaPackageElementFlavor)) { logger.debug("Set Identifier for Smil-Catalog to: {}", p.getIdentifier()); catalogId = p.getIdentifier(); break; } } Catalog catalog = mediaPackage.getCatalog(catalogId); URI smilURI; try (InputStream is = IOUtils.toInputStream(smil.toXML(), "UTF-8")) { smilURI = workspace.put(mediaPackage.getIdentifier().toString(), catalogId, TARGET_FILE_NAME, is); } catch (SAXException e) { logger.error("Error while serializing the SMIL catalog to XML: {}", e.getMessage()); throw new IOException(e); } catch (JAXBException e) { logger.error("Error while serializing the SMIL catalog to XML: {}", e.getMessage()); throw new IOException(e); } if (catalog == null) { MediaPackageElementBuilder mpeBuilder = MediaPackageElementBuilderFactory.newInstance().newElementBuilder(); catalog = (Catalog) mpeBuilder.elementFromURI(smilURI, MediaPackageElement.Type.Catalog, adminUIConfiguration.getSmilCatalogFlavor()); mediaPackage.add(catalog); } catalog.setURI(smilURI); catalog.setIdentifier(catalogId); catalog.setMimeType(MimeTypes.XML); for (String tag : adminUIConfiguration.getSmilCatalogTags()) { catalog.addTag(tag); } catalog.setChecksum(null); try { assetManager.takeSnapshot(mediaPackage); } catch (AssetManagerException e) { logger.error("Error while adding the updated media package ({}) to the archive", mediaPackage.getIdentifier(), e); throw new IOException(e); } return mediaPackage; }  @Override void updated(Dictionary<String, ?> properties); @GET @Path("{mediapackageid}.json") @RestQuery(name = "getAvailableTools", description = "Returns a list of tools which are currently available for the given media package.", returnDescription = "A JSON array with tools identifiers", pathParameters = { @RestParameter(name = "mediapackageid", description = "The id of the media package", isRequired = true, type = RestParameter.Type.STRING) }, responses = { @RestResponse(description = "Available tools evaluated", responseCode = HttpServletResponse.SC_OK) }) Response getAvailableTools(@PathParam("mediapackageid") final String mediaPackageId); @GET @Path("{mediapackageid}/editor.json") @Produces(MediaType.APPLICATION_JSON) @RestQuery(name = "getVideoEditor", description = "Returns all the information required to get the editor tool started", returnDescription = "JSON object", pathParameters = { @RestParameter(name = "mediapackageid", description = "The id of the media package", isRequired = true, type = RestParameter.Type.STRING) }, responses = { @RestResponse(description = "Media package found", responseCode = SC_OK), @RestResponse(description = "Media package not found", responseCode = SC_NOT_FOUND) }) Response getVideoEditor(@PathParam("mediapackageid") final String mediaPackageId); @POST @Consumes(MediaType.MULTIPART_FORM_DATA) @Produces(MediaType.APPLICATION_JSON) @Path("{mediapackageid}/thumbnail.json") Response changeThumbnail(@PathParam("mediapackageid") final String mediaPackageId,
    @Context HttpServletRequest request); @POST @Path("{mediapackageid}/editor.json") @Consumes(MediaType.APPLICATION_JSON) @RestQuery(name = "editVideo", description = "Takes editing information from the client side and processes it", returnDescription = "", pathParameters = { @RestParameter(name = "mediapackageid", description = "The id of the media package", isRequired = true, type = RestParameter.Type.STRING) }, responses = { @RestResponse(description = "Editing information saved and processed", responseCode = HttpServletResponse.SC_OK), @RestResponse(description = "Media package not found", responseCode = HttpServletResponse.SC_NOT_FOUND), @RestResponse(description = "The editing information cannot be parsed", responseCode = HttpServletResponse.SC_BAD_REQUEST) }) Response editVideo(@PathParam("mediapackageid") final String mediaPackageId,
          @Context HttpServletRequest request);  }
@Test public void testAddSmilToArchive() throws Exception { final String mpId = UUID.randomUUID().toString(); final URI archiveElementURI = new URI("http: final String smilId = "s-afe311c6-9161-41f4-98d0-e951fe66d89e"; Workspace workspace = createNiceMock(Workspace.class); expect(workspace.put(same(mpId), same(smilId), same("cut.smil"), anyObject(InputStream.class))) .andReturn(archiveElementURI); replay(workspace); endpoint.setWorkspace(workspace); AssetManager assetManager = createNiceMock(AssetManager.class); replay(assetManager); endpoint.setAssetManager(assetManager); MediaPackage mp = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().createNew(new IdImpl(mpId)); endpoint.addSmilToArchive(mp, smil); assertEquals(1, mp.getCatalogs().length); assertEquals(smil.getId(), mp.getCatalogs()[0].getIdentifier()); assertEquals("smil/cutting", mp.getCatalogs()[0].getFlavor().toString()); }