<%#
 Copyright 2013-2022 the original author or authors from the JHipster project.

 This file is part of the JHipster project, see https://www.jhipster.tech/
 for more information.

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

      https://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
-%>
package <%= packageName %>.web.rest.errors;

import org.nentangso.core.service.errors.NtsNotFoundException;
import org.nentangso.core.service.errors.NtsValidationException;
import org.nentangso.core.service.utils.NtsValidationUtils;
<%_ if (!databaseTypeNo && !databaseTypeCassandra) { _%>
import org.springframework.dao.ConcurrencyFailureException;
<%_ } _%>
import org.springframework.http.HttpStatus;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;

@RestController
@RequestMapping("/api/exception-translator-test")
public class ExceptionTranslatorTestController {
<%_ if (!databaseTypeNo && !databaseTypeCassandra) { _%>

    @GetMapping("/concurrency-failure")
    public void concurrencyFailure() {
        throw new ConcurrencyFailureException("test concurrency failure");
    }
<%_ } _%>

    @PostMapping("/method-argument")
    public void methodArgument(@Valid @RequestBody Test<%= dtoSuffix %> test<%= dtoSuffix %>) {
    }

    @GetMapping("/missing-servlet-request-part")
    public void missingServletRequestPartException(@RequestPart String part) {
    }

    @GetMapping("/missing-servlet-request-parameter")
    public void missingServletRequestParameterException(@RequestParam String param) {
    }

    @GetMapping("/access-denied")
    public void accessdenied() {
        throw new AccessDeniedException("test access denied!");
    }

    @GetMapping("/unauthorized")
    public void unauthorized() {
        throw new BadCredentialsException("test authentication failed!");
    }

    @GetMapping("/response-status")
    public void exceptionWithResponseStatus() {
        throw new TestResponseStatusException();
    }

    @GetMapping("/internal-server-error")
    public void internalServerError() {
        throw new RuntimeException();
    }

    @GetMapping("/nts-not-found")
    public void ntsNotFound() {
        throw new NtsNotFoundException();
    }

    @PostMapping("/nts-validate-object")
    public void ntsValidateObject(@RequestBody TestDTO testDTO) {
        NtsValidationUtils.validateObject(testDTO);
    }

    @PutMapping("/nts-validation-error")
    public void ntsValidationError() {
        throw new NtsValidationException("test", "must not be null");
    }

    public static class Test<%= dtoSuffix %> {

        @NotNull<% if (reactive) { %>(message = "must not be null")<% } %>
        private String test;

        public String getTest() {
            return test;
        }

        public void setTest(String test) {
            this.test = test;
        }
    }

    @ResponseStatus(value = HttpStatus.BAD_REQUEST, reason = "test response status")
    @SuppressWarnings("serial")
    public static class TestResponseStatusException extends RuntimeException {
    }

}
