// Path: src/main/java/com/aemreunal/exception/beacon/BeaconAlreadyExistsException.java
// public class BeaconAlreadyExistsException extends IllegalArgumentException {
// 
//     public BeaconAlreadyExistsException(Beacon beacon) {
//         super("Beacon with UUID:'" + beacon.getUuid() + "', Major:'" + beacon.getMajor() + "', Minor:'" + beacon.getMinor() + "' already exists!");
//     }
// }
// 
// Path: src/main/java/com/aemreunal/exception/beacon/BeaconNotFoundException.java
// public class BeaconNotFoundException extends NullPointerException {
//     public BeaconNotFoundException() {
//         super("The requested Beacon can not be found!");
//     }
// 
//     public BeaconNotFoundException(Long beaconId) {
//         super("The requested Beacon with ID " + beaconId + " can not be found!");
//     }
// }
// 
// Path: src/main/java/com/aemreunal/exception/connection/ConnectionNotPossibleException.java
// public class ConnectionNotPossibleException extends Exception {
//     public ConnectionNotPossibleException(Long beaconId) {
//         super("Unable to create connection, beacon " + beaconId + " is not a designated beacon!");
//     }
// 
//     public ConnectionNotPossibleException() {
//         super("Unable to create connection, a beacon can't be connected to itself!");
//     }
// }
// 
// Path: src/main/java/com/aemreunal/exception/connection/ConnectionExistsException.java
// public class ConnectionExistsException extends Exception {
//     public ConnectionExistsException(Long beaconOneId, Long beaconTwoId) {
//         super("There already is a connection between Beacon " + beaconOneId + " and Beacon " + beaconTwoId + "!");
//     }
// }
// 
// Path: src/main/java/com/aemreunal/exception/connection/ConnectionNotFoundException.java
// public class ConnectionNotFoundException extends Exception {
//     public ConnectionNotFoundException() {
//         super("The requested connection can not be found.");
//     }
// }
// 
// 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 com.aemreunal.exception.beacon.BeaconAlreadyExistsException;
import com.aemreunal.exception.beacon.BeaconNotFoundException;
import com.aemreunal.exception.connection.ConnectionNotPossibleException;
import com.aemreunal.exception.connection.ConnectionExistsException;
import com.aemreunal.exception.connection.ConnectionNotFoundException;
import com.aemreunal.helper.json.JsonBuilderFactory;
package com.aemreunal.controller.beacon;

/*
 * *********************** *
 * 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 BeaconControllerAdvice {
    @ExceptionHandler(BeaconNotFoundException.class)
    public ResponseEntity<JSONObject> beaconNotFoundExceptionHandler(BeaconNotFoundException ex) {
        return getResponse(ex, "beacon", HttpStatus.NOT_FOUND);
    }

    @ExceptionHandler(BeaconAlreadyExistsException.class)
    public ResponseEntity<JSONObject> beaconAlreadyExistsExceptionHandler(BeaconAlreadyExistsException ex) {
        return getResponse(ex, "beacon", HttpStatus.BAD_REQUEST);
    }

    @ExceptionHandler(ConnectionExistsException.class)
// Path: src/main/java/com/aemreunal/exception/beacon/BeaconAlreadyExistsException.java
// public class BeaconAlreadyExistsException extends IllegalArgumentException {
// 
//     public BeaconAlreadyExistsException(Beacon beacon) {
//         super("Beacon with UUID:'" + beacon.getUuid() + "', Major:'" + beacon.getMajor() + "', Minor:'" + beacon.getMinor() + "' already exists!");
//     }
// }
// 
// Path: src/main/java/com/aemreunal/exception/beacon/BeaconNotFoundException.java
// public class BeaconNotFoundException extends NullPointerException {
//     public BeaconNotFoundException() {
//         super("The requested Beacon can not be found!");
//     }
// 
//     public BeaconNotFoundException(Long beaconId) {
//         super("The requested Beacon with ID " + beaconId + " can not be found!");
//     }
// }
// 
// Path: src/main/java/com/aemreunal/exception/connection/ConnectionNotPossibleException.java
// public class ConnectionNotPossibleException extends Exception {
//     public ConnectionNotPossibleException(Long beaconId) {
//         super("Unable to create connection, beacon " + beaconId + " is not a designated beacon!");
//     }
// 
//     public ConnectionNotPossibleException() {
//         super("Unable to create connection, a beacon can't be connected to itself!");
//     }
// }
// 
// Path: src/main/java/com/aemreunal/exception/connection/ConnectionExistsException.java
// public class ConnectionExistsException extends Exception {
//     public ConnectionExistsException(Long beaconOneId, Long beaconTwoId) {
//         super("There already is a connection between Beacon " + beaconOneId + " and Beacon " + beaconTwoId + "!");
//     }
// }
// 
// Path: src/main/java/com/aemreunal/exception/connection/ConnectionNotFoundException.java
// public class ConnectionNotFoundException extends Exception {
//     public ConnectionNotFoundException() {
//         super("The requested connection can not be found.");
//     }
// }
// 
// 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/beacon/BeaconControllerAdvice.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 com.aemreunal.exception.beacon.BeaconAlreadyExistsException;
import com.aemreunal.exception.beacon.BeaconNotFoundException;
import com.aemreunal.exception.connection.ConnectionNotPossibleException;
import com.aemreunal.exception.connection.ConnectionExistsException;
import com.aemreunal.exception.connection.ConnectionNotFoundException;
import com.aemreunal.helper.json.JsonBuilderFactory;

package com.aemreunal.controller.beacon;

/*
 * *********************** *
 * 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 BeaconControllerAdvice {
    @ExceptionHandler(BeaconNotFoundException.class)
    public ResponseEntity<JSONObject> beaconNotFoundExceptionHandler(BeaconNotFoundException ex) {
        return getResponse(ex, "beacon", HttpStatus.NOT_FOUND);
    }

    @ExceptionHandler(BeaconAlreadyExistsException.class)
    public ResponseEntity<JSONObject> beaconAlreadyExistsExceptionHandler(BeaconAlreadyExistsException ex) {
        return getResponse(ex, "beacon", HttpStatus.BAD_REQUEST);
    }

    @ExceptionHandler(ConnectionExistsException.class)
    public ResponseEntity<JSONObject> connectionExistsExceptionHandler(ConnectionExistsException ex) {