bda-controller/src/main/java/gr/ntua/ece/cslab/selis/bda/controller/resources/RecipeResource.java
@POST
    @Path("{slug}")
    @Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
    @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
    public Response insert(@PathParam("slug") String slug,
                           Recipe r) {
        String details = "";

        try {

            List<ExecutionEngine> engines = ExecutionEngine.getEngines();

            boolean correctEngine = false;
            for (ExecutionEngine engine : engines) {
                if (engine.getId() == r.getEngineId()) {
                    correctEngine = true;
                }
            }

            List<ExecutionLanguage> languages = ExecutionLanguage.getLanguages();

            boolean correctLanguage = false;
            for (ExecutionLanguage language : languages) {
                if (language.getId() == r.getLanguageId()) {
                    correctLanguage = true;
                }
            }

            if (correctEngine && correctLanguage) {
                r.save(slug);

                details = Integer.toString(r.getId());

            }
            else {
                LOGGER.log(Level.WARNING, "Bad engine id or language id provided!");
                return Response.serverError().entity(
                        new RequestResponse("ERROR", "Could not create Recipe. Invalid json.")
                ).build();
            }
        } catch (Exception e) {
            e.printStackTrace();

            return Response.serverError().entity(
                    new RequestResponse("ERROR", "Could not create Recipe.")
            ).build();
        }

        return Response.ok(
                new RequestResponse("OK", details)
        ).build();
    }
/**
     * Recipe insert method
     * @param r the recipe to insert
     */
Recipe insert method
@param r the recipe to insert
Recipe insert method @param r the recipe to insert
@POST
    @Path("{slug}")
    @Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
    @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
    public Response insert(@PathParam("slug") String slug,
                           Recipe r) {
        String details = "";
        try {
            List<ExecutionEngine> engines = ExecutionEngine.getEngines();
            boolean correctEngine = false;
            for (ExecutionEngine engine : engines) {
                if (engine.getId() == r.getEngineId()) {
                    correctEngine = true;
                }
            }
            List<ExecutionLanguage> languages = ExecutionLanguage.getLanguages();
            boolean correctLanguage = false;
            for (ExecutionLanguage language : languages) {
                if (language.getId() == r.getLanguageId()) {
                    correctLanguage = true;
                }
            }
            if (correctEngine && correctLanguage) {
                r.save(slug);
                details = Integer.toString(r.getId());
            }
            else {
                LOGGER.log(Level.WARNING, "Bad engine id or language id provided!");
                return Response.serverError().entity(
                        new RequestResponse("ERROR", "Could not create Recipe. Invalid json.")
                ).build();
            }
        } catch (Exception e) {
            e.printStackTrace();
            return Response.serverError().entity(
                    new RequestResponse("ERROR", "Could not create Recipe.")
            ).build();
        }
        return Response.ok(
                new RequestResponse("OK", details)
        ).build();
    }
@ POST @ Path ( "{slug}" ) @ Consumes ( { MediaType . APPLICATION_JSON , MediaType . APPLICATION_XML } ) @ Produces ( { MediaType . APPLICATION_JSON , MediaType . APPLICATION_XML } ) public Response insert ( @ PathParam ( "slug" ) String slug , Recipe r ) { String details = "" ; try { List < ExecutionEngine > engines = ExecutionEngine . getEngines ( ) ; boolean correctEngine = false ; for ( ExecutionEngine engine : engines ) { if ( engine . getId ( ) == r . getEngineId ( ) ) { correctEngine = true ; } } List < ExecutionLanguage > languages = ExecutionLanguage . getLanguages ( ) ; boolean correctLanguage = false ; for ( ExecutionLanguage language : languages ) { if ( language . getId ( ) == r . getLanguageId ( ) ) { correctLanguage = true ; } } if ( correctEngine && correctLanguage ) { r . save ( slug ) ; details = Integer . toString ( r . getId ( ) ) ; } else { LOGGER . log ( Level . WARNING , "Bad engine id or language id provided!" ) ; return Response . serverError ( ) . entity ( new RequestResponse ( "ERROR" , "Could not create Recipe. Invalid json." ) ) . build ( ) ; } } catch ( Exception e ) { e . printStackTrace ( ) ; return Response . serverError ( ) . entity ( new RequestResponse ( "ERROR" , "Could not create Recipe." ) ) . build ( ) ; } return Response . ok ( new RequestResponse ( "OK" , details ) ) . build ( ) ; }
Recipe insert method
 @param r the recipe to insert
Recipe insert method @param r the recipe to insert