// Path: ngsi2-client/src/main/java/com/orange/ngsi2/exception/UnsupportedOperationException.java
// public class UnsupportedOperationException extends Ngsi2Exception {
// 
//     private final static String message = "this operation '%s' is not implemented";
// 
//     public UnsupportedOperationException(String operationName) {
//         super("501", String.format(message, operationName), null);
//     }
// }


import javax.servlet.http.HttpServletRequest;
import java.util.*;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.orange.ngsi2.exception.*;
import com.orange.ngsi2.exception.UnsupportedOperationException;
import com.orange.ngsi2.model.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
     * @param bulkQueryRequest defines the list of entities, attributes and scopes to match registrations
     * @param offset an optional offset (0 for none)
     * @param limit an optional limit (0 for none)
     * @param options an optional list of options separated by comma. Possible value for option: count.
     *        If count is present then the total number of registrations is returned in the response as a HTTP header named `X-Total-Count`.
     * @return a paginated list of registration
     */
    @RequestMapping(method = RequestMethod.POST, value = {"/op/discover"}, consumes = MediaType.APPLICATION_JSON_VALUE)
    final public ResponseEntity<List<Registration>> bulkDiscoverEndpoint(@RequestBody BulkQueryRequest bulkQueryRequest, @RequestParam Optional<Integer> limit,
                                                                @RequestParam Optional<Integer> offset,
                                                                @RequestParam Optional<Set<String>> options) {

        validateSyntax(bulkQueryRequest);
        boolean count = false;
        if (options.isPresent()) {
            Set<String> optionsSet = options.get();
            count = optionsSet.contains("count");
        }
        Paginated<Registration> paginatedRegistration = bulkDiscover(bulkQueryRequest, limit.orElse(0), offset.orElse(0), count);
        if (count) {
            return new ResponseEntity<>(paginatedRegistration.getItems(), xTotalCountHeader(paginatedRegistration.getTotal()), HttpStatus.OK);
        } else {
            return new ResponseEntity<>(paginatedRegistration.getItems(), HttpStatus.OK);
        }
    }

    /*
     * Exception handling
     */

// Path: ngsi2-client/src/main/java/com/orange/ngsi2/exception/UnsupportedOperationException.java
// public class UnsupportedOperationException extends Ngsi2Exception {
// 
//     private final static String message = "this operation '%s' is not implemented";
// 
//     public UnsupportedOperationException(String operationName) {
//         super("501", String.format(message, operationName), null);
//     }
// }


// Path: ngsi2-server/src/main/java/com/orange/ngsi2/server/Ngsi2BaseController.java
import javax.servlet.http.HttpServletRequest;
import java.util.*;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.orange.ngsi2.exception.*;
import com.orange.ngsi2.exception.UnsupportedOperationException;
import com.orange.ngsi2.model.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

     * @param bulkQueryRequest defines the list of entities, attributes and scopes to match registrations
     * @param offset an optional offset (0 for none)
     * @param limit an optional limit (0 for none)
     * @param options an optional list of options separated by comma. Possible value for option: count.
     *        If count is present then the total number of registrations is returned in the response as a HTTP header named `X-Total-Count`.
     * @return a paginated list of registration
     */
    @RequestMapping(method = RequestMethod.POST, value = {"/op/discover"}, consumes = MediaType.APPLICATION_JSON_VALUE)
    final public ResponseEntity<List<Registration>> bulkDiscoverEndpoint(@RequestBody BulkQueryRequest bulkQueryRequest, @RequestParam Optional<Integer> limit,
                                                                @RequestParam Optional<Integer> offset,
                                                                @RequestParam Optional<Set<String>> options) {

        validateSyntax(bulkQueryRequest);
        boolean count = false;
        if (options.isPresent()) {
            Set<String> optionsSet = options.get();
            count = optionsSet.contains("count");
        }
        Paginated<Registration> paginatedRegistration = bulkDiscover(bulkQueryRequest, limit.orElse(0), offset.orElse(0), count);
        if (count) {
            return new ResponseEntity<>(paginatedRegistration.getItems(), xTotalCountHeader(paginatedRegistration.getTotal()), HttpStatus.OK);
        } else {
            return new ResponseEntity<>(paginatedRegistration.getItems(), HttpStatus.OK);
        }
    }

    /*
     * Exception handling
     */

    @ExceptionHandler({UnsupportedOperationException.class})