// Path: src/main/java/com/aemreunal/exception/imageStorage/ImageDeleteException.java
// public class ImageDeleteException extends Exception {
//     public ImageDeleteException(Long projectId, Long regionId) {
//         super("Unable to delete the image file of project " + projectId + ", region " + regionId + "!");
//     }
// }
// 
// Path: src/main/java/com/aemreunal/exception/imageStorage/ImageLoadException.java
// public class ImageLoadException extends Exception {
//     public ImageLoadException(Long projectId, Long regionId) {
//         super(getExceptionMessage(projectId, regionId));
//     }
// 
//     private static String getExceptionMessage(Long projectId, Long regionId) {
//         if (regionId == null) {
//             return "Unable to load the image file of project " + projectId + "!";
//         } else {
//             return "Unable to load the image file of project " + projectId + ", region " + regionId + "!";
//         }
//     }
// }
// 
// Path: src/main/java/com/aemreunal/exception/imageStorage/ImageSaveException.java
// public class ImageSaveException extends Exception {
//     public ImageSaveException(Long projectId, Long regionId) {
//         super(createCauseMessage(projectId, regionId));
//     }
// 
//     public static String createCauseMessage(Long projectId, Long regionId) {
//         String message = "Unable to save ";
//         if (regionId != null) {
//             return message + "map image of project " + projectId + ", region " + regionId + "!";
//         } else {
//             return message + "a navigation image of project " + projectId + "!";
//         }
//     }
// }
// 
// Path: src/main/java/com/aemreunal/helper/json/JsonBuilderFactory.java
// public class JsonBuilderFactory {
//     public static JsonObjectBuilder object() {
//         return new JsonObjectBuilder();
//     }
// 
//     public static JsonArrayBuilder array() {
//         return new JsonArrayBuilder();
//     }
// }


import net.minidev.json.JSONObject;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.multipart.MultipartException;
import com.aemreunal.exception.imageStorage.ImageDeleteException;
import com.aemreunal.exception.imageStorage.ImageLoadException;
import com.aemreunal.exception.imageStorage.ImageSaveException;
import com.aemreunal.exception.region.*;
import com.aemreunal.helper.json.JsonBuilderFactory;
package com.aemreunal.controller.region;

/*
 * *********************** *
 * Copyright (c) 2015      *
 *                         *
 * This code belongs to:   *
 *                         *
 * @author Ahmet Emre Ünal *
 * S001974                 *
 *                         *
 * aemreunal@gmail.com     *
 * emre.unal@ozu.edu.tr    *
 *                         *
 * aemreunal.com           *
 * *********************** *
 */



@ControllerAdvice
public class RegionControllerAdvice {

    @ExceptionHandler(RegionNotFoundException.class)
    public ResponseEntity<JSONObject> regionNotFoundExceptionHandler(RegionNotFoundException ex) {
        return new ResponseEntity<JSONObject>(getErrorResponseBody(ex), HttpStatus.NOT_FOUND);
    }

// Path: src/main/java/com/aemreunal/exception/imageStorage/ImageDeleteException.java
// public class ImageDeleteException extends Exception {
//     public ImageDeleteException(Long projectId, Long regionId) {
//         super("Unable to delete the image file of project " + projectId + ", region " + regionId + "!");
//     }
// }
// 
// Path: src/main/java/com/aemreunal/exception/imageStorage/ImageLoadException.java
// public class ImageLoadException extends Exception {
//     public ImageLoadException(Long projectId, Long regionId) {
//         super(getExceptionMessage(projectId, regionId));
//     }
// 
//     private static String getExceptionMessage(Long projectId, Long regionId) {
//         if (regionId == null) {
//             return "Unable to load the image file of project " + projectId + "!";
//         } else {
//             return "Unable to load the image file of project " + projectId + ", region " + regionId + "!";
//         }
//     }
// }
// 
// Path: src/main/java/com/aemreunal/exception/imageStorage/ImageSaveException.java
// public class ImageSaveException extends Exception {
//     public ImageSaveException(Long projectId, Long regionId) {
//         super(createCauseMessage(projectId, regionId));
//     }
// 
//     public static String createCauseMessage(Long projectId, Long regionId) {
//         String message = "Unable to save ";
//         if (regionId != null) {
//             return message + "map image of project " + projectId + ", region " + regionId + "!";
//         } else {
//             return message + "a navigation image of project " + projectId + "!";
//         }
//     }
// }
// 
// Path: src/main/java/com/aemreunal/helper/json/JsonBuilderFactory.java
// public class JsonBuilderFactory {
//     public static JsonObjectBuilder object() {
//         return new JsonObjectBuilder();
//     }
// 
//     public static JsonArrayBuilder array() {
//         return new JsonArrayBuilder();
//     }
// }


// Path: src/main/java/com/aemreunal/controller/region/RegionControllerAdvice.java
import net.minidev.json.JSONObject;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.multipart.MultipartException;
import com.aemreunal.exception.imageStorage.ImageDeleteException;
import com.aemreunal.exception.imageStorage.ImageLoadException;
import com.aemreunal.exception.imageStorage.ImageSaveException;
import com.aemreunal.exception.region.*;
import com.aemreunal.helper.json.JsonBuilderFactory;

package com.aemreunal.controller.region;

/*
 * *********************** *
 * Copyright (c) 2015      *
 *                         *
 * This code belongs to:   *
 *                         *
 * @author Ahmet Emre Ünal *
 * S001974                 *
 *                         *
 * aemreunal@gmail.com     *
 * emre.unal@ozu.edu.tr    *
 *                         *
 * aemreunal.com           *
 * *********************** *
 */



@ControllerAdvice
public class RegionControllerAdvice {

    @ExceptionHandler(RegionNotFoundException.class)
    public ResponseEntity<JSONObject> regionNotFoundExceptionHandler(RegionNotFoundException ex) {
        return new ResponseEntity<JSONObject>(getErrorResponseBody(ex), HttpStatus.NOT_FOUND);
    }

    @ExceptionHandler({ ImageSaveException.class, ImageLoadException.class, ImageDeleteException.class })