@@ -0,0 +1,2738 @@
+package com.aemreunal.controller.scenario;%0A%0A/*%0A ***************************%0A * Copyright (c) 2014      *%0A *                         *%0A * This code belongs to:   *%0A *                         *%0A * @author Ahmet Emre %C3%9Cnal *%0A * S001974                 *%0A *                         *%0A * aemreunal@gmail.com     *%0A * emre.unal@ozu.edu.tr    *%0A *                         *%0A * aemreunal.com           *%0A ***************************%0A */%0A%0Aimport net.minidev.json.JSONArray;%0Aimport net.minidev.json.JSONObject;%0A%0Aimport java.util.HashMap;%0Aimport java.util.Map;%0Aimport java.util.Set;%0Aimport javax.validation.ConstraintViolation;%0Aimport javax.validation.ConstraintViolationException;%0Aimport org.springframework.http.HttpStatus;%0Aimport org.springframework.http.ResponseEntity;%0Aimport org.springframework.web.bind.annotation.ControllerAdvice;%0Aimport org.springframework.web.bind.annotation.ExceptionHandler;%0Aimport com.aemreunal.exception.scenario.ScenarioNotFoundException;%0Aimport com.aemreunal.helper.JsonBuilder;%0A%0A@ControllerAdvice%0Apublic class ScenarioControllerAdvice %7B%0A    @ExceptionHandler(ScenarioNotFoundException.class)%0A    public ResponseEntity%3CJSONObject%3E scenarioNotFoundExceptionHandler(ScenarioNotFoundException ex) %7B%0A        JSONObject responseBody = new JsonBuilder().add(%22reason%22, %22scenario%22)%0A                                                   .add(%22error%22, ex.getLocalizedMessage())%0A                                                   .build();%0A        return new ResponseEntity%3CJSONObject%3E(responseBody, HttpStatus.NOT_FOUND);%0A    %7D%0A%0A    @ExceptionHandler(ConstraintViolationException.class)%0A    public ResponseEntity%3CJSONObject%3E constraintViolationExceptionHandler(ConstraintViolationException ex) %7B%0A        JSONObject responseBody = new JsonBuilder().add(%22reason%22, %22scenario%22)%0A                                                   .add(%22error%22, %22Constraint violation error ocurred! Unable to save scenario.%22)%0A                                                   .add(%22violations%22, formatViolations(ex.getConstraintViolations()))%0A                                                   .build();%0A        return new ResponseEntity%3CJSONObject%3E(responseBody, HttpStatus.BAD_REQUEST);%0A    %7D%0A%0A    private JSONArray formatViolations(Set%3CConstraintViolation%3C?%3E%3E violations) %7B%0A        JSONArray violationDescriptions = new JSONArray();%0A        for (ConstraintViolation%3C?%3E violation : violations) %7B%0A            Map%3CString, String%3E violationDescription = new HashMap%3C%3E();%0A            violationDescription.put(%22property%22, violation.getPropertyPath().toString());%0A            violationDescription.put(%22violation%22, violation.getMessage());%0A            violationDescriptions.add(violationDescription);%0A        %7D%0A        return violationDescriptions;%0A    %7D%0A%7D%0A

Add ScenarioController advice