bda-controller/src/main/java/gr/ntua/ece/cslab/selis/bda/controller/resources/RecipeResource.java
@PUT
    @Path("{slug}/{recipeId}/{filename}")
    @Consumes(MediaType.APPLICATION_OCTET_STREAM)
    @Produces(MediaType.APPLICATION_JSON)
    public Response upload(@PathParam("slug") String slug,
                           @PathParam("recipeId") int recipeId,
                           @PathParam("filename") String recipeName,
                           InputStream recipeBinary)  {
        // Ensure a `Recipe` object with the given `id` exists for the specified SCN.
        Recipe recipe;
        try {
            recipe = Recipe.getRecipeById(slug, recipeId);
        } catch (SQLException | SystemConnectorException e) {
            e.printStackTrace();

            return Response.serverError().entity(
                new RequestResponse("ERROR", "Upload recipe FAILED")
            ).build();
        }

        // Ensure the storage location for the specified SCN exists.
        try {
            Recipe.ensureStorageForSlug(slug);
        } catch (IOException | SystemConnectorException  e) {
            e.printStackTrace();

            return Response.serverError().entity(
                new RequestResponse("ERROR", "Upload recipe FAILED")
            ).build();
        }

        // Save the binary file to the specified location.
        String recipeFilename;
        try {
            recipeFilename = Recipe.saveRecipeForSlug(
                slug, recipeBinary, recipeName
            );
        } catch (IOException | SystemConnectorException  e) {
            e.printStackTrace();

            return Response.serverError().entity(
                new RequestResponse("ERROR", "Upload recipe FAILED")
            ).build();
        }

        // Update the `Recipe` object.
        recipe.setExecutablePath(recipeFilename);

        try {
            recipe.save(slug);
        } catch (SQLException | SystemConnectorException e) {
            e.printStackTrace();

            return Response.serverError().entity(
                new RequestResponse("ERROR", "Upload recipe FAILED")
            ).build();
        }

        return Response.ok(
                new RequestResponse("OK", "")
        ).build();
    }
/**
     * Uploads a binary for the specified recipe id, SCN.
     *
     * Given an existing `Recipe` object, this REST endpoint, for a given SCN, receives a binary
     * and stores it in the configured storage backend. Then links the `Recipe` object to the
     * stored binary by running `recipe.setExecutablePath()`.
     *
     * TODO: Requires authentication/authorization.
     * TODO: Tests.
     *
     * @param slug          The SCN's slug.
     * @param recipeId      The `id` of the recipe object to which this binary corresponds.
     * @param recipeName    The name of the recipe's binary.
     * @param recipeBinary  The actual recipe binary.
     * @return              An javax `Response` object.
     */
Uploads a binary for the specified recipe id, SCN.
Given an existing `Recipe` object, this REST endpoint, for a given SCN, receives a binary
and stores it in the configured storage backend. Then links the `Recipe` object to the
stored binary by running `recipe.setExecutablePath()`.

Requires authentication/authorization.
TODO: Tests.

@param slug          The SCN's slug.
@param recipeId      The `id` of the recipe object to which this binary corresponds.
@param recipeName    The name of the recipe's binary.
@param recipeBinary  The actual recipe binary.
@return              An javax `Response` object.
Uploads a binary for the specified recipe id SCN . Given an existing ` Recipe ` object this REST endpoint for a given SCN receives a binary and stores it in the configured storage backend . Then links the ` Recipe ` object to the stored binary by running ` recipe . setExecutablePath () ` . Requires authentication / authorization . TODO : Tests . @param slug The SCN ' s slug . @param recipeId The ` id ` of the recipe object to which this binary corresponds . @param recipeName The name of the recipe ' s binary . @param recipeBinary The actual recipe binary . @return An javax ` Response ` object .
@PUT
    @Path("{slug}/{recipeId}/{filename}")
    @Consumes(MediaType.APPLICATION_OCTET_STREAM)
    @Produces(MediaType.APPLICATION_JSON)
    public Response upload(@PathParam("slug") String slug,
                           @PathParam("recipeId") int recipeId,
                           @PathParam("filename") String recipeName,
                           InputStream recipeBinary)  {
        Recipe recipe;
        try {
            recipe = Recipe.getRecipeById(slug, recipeId);
        } catch (SQLException | SystemConnectorException e) {
            e.printStackTrace();
            return Response.serverError().entity(
                new RequestResponse("ERROR", "Upload recipe FAILED")
            ).build();
        }
        try {
            Recipe.ensureStorageForSlug(slug);
        } catch (IOException | SystemConnectorException  e) {
            e.printStackTrace();
            return Response.serverError().entity(
                new RequestResponse("ERROR", "Upload recipe FAILED")
            ).build();
        }
        String recipeFilename;
        try {
            recipeFilename = Recipe.saveRecipeForSlug(
                slug, recipeBinary, recipeName
            );
        } catch (IOException | SystemConnectorException  e) {
            e.printStackTrace();
            return Response.serverError().entity(
                new RequestResponse("ERROR", "Upload recipe FAILED")
            ).build();
        }
        recipe.setExecutablePath(recipeFilename);
        try {
            recipe.save(slug);
        } catch (SQLException | SystemConnectorException e) {
            e.printStackTrace();
            return Response.serverError().entity(
                new RequestResponse("ERROR", "Upload recipe FAILED")
            ).build();
        }
        return Response.ok(
                new RequestResponse("OK", "")
        ).build();
    }
@ PUT @ Path ( "{slug}/{recipeId}/{filename}" ) @ Consumes ( MediaType . APPLICATION_OCTET_STREAM ) @ Produces ( MediaType . APPLICATION_JSON ) public Response upload ( @ PathParam ( "slug" ) String slug , @ PathParam ( "recipeId" ) int recipeId , @ PathParam ( "filename" ) String recipeName , InputStream recipeBinary ) { Recipe recipe ; try { recipe = Recipe . getRecipeById ( slug , recipeId ) ; } catch ( SQLException | SystemConnectorException e ) { e . printStackTrace ( ) ; return Response . serverError ( ) . entity ( new RequestResponse ( "ERROR" , "Upload recipe FAILED" ) ) . build ( ) ; } try { Recipe . ensureStorageForSlug ( slug ) ; } catch ( IOException | SystemConnectorException e ) { e . printStackTrace ( ) ; return Response . serverError ( ) . entity ( new RequestResponse ( "ERROR" , "Upload recipe FAILED" ) ) . build ( ) ; } String recipeFilename ; try { recipeFilename = Recipe . saveRecipeForSlug ( slug , recipeBinary , recipeName ) ; } catch ( IOException | SystemConnectorException e ) { e . printStackTrace ( ) ; return Response . serverError ( ) . entity ( new RequestResponse ( "ERROR" , "Upload recipe FAILED" ) ) . build ( ) ; } recipe . setExecutablePath ( recipeFilename ) ; try { recipe . save ( slug ) ; } catch ( SQLException | SystemConnectorException e ) { e . printStackTrace ( ) ; return Response . serverError ( ) . entity ( new RequestResponse ( "ERROR" , "Upload recipe FAILED" ) ) . build ( ) ; } return Response . ok ( new RequestResponse ( "OK" , "" ) ) . build ( ) ; }
Uploads a binary for the specified recipe id, SCN.
Uploads a binary for the specified recipe id SCN .
// Ensure a `Recipe` object with the given `id` exists for the specified SCN. // Ensure the storage location for the specified SCN exists. // Save the binary file to the specified location. // Update the `Recipe` object.