All Downloads are FREE. Search and download functionalities are using the official Maven repository.

JavaSpring.apiController.mustache Maven / Gradle / Ivy

There is a newer version: 0.9.25
Show newest version
package {{package}};

{{^jdk8}}
{{#imports}}import {{import}};
{{/imports}}
{{/jdk8}}
{{^isDelegate}}
{{/isDelegate}}
{{^jdk8}}
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import io.swagger.annotations.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
{{/jdk8}}
import org.springframework.stereotype.Controller;
{{^jdk8}}
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.multipart.MultipartFile;

    {{#useBeanValidation}}
import javax.validation.constraints.*;
import javax.validation.Valid;
    {{/useBeanValidation}}
{{/jdk8}}
{{^isDelegate}}
import javax.servlet.http.HttpServletRequest;
    {{#jdk8}}
import java.util.Optional;
    {{/jdk8}}
{{/isDelegate}}
{{^jdk8-no-delegate}}
    {{#useOptional}}
import java.util.Optional;
    {{/useOptional}}
{{/jdk8-no-delegate}}
{{^jdk8}}
    {{^isDelegate}}
import java.io.IOException;
    {{/isDelegate}}
import java.util.List;
    {{#async}}
import java.util.concurrent.Callable;
    {{/async}}
{{/jdk8}}
{{>generatedAnnotation}}
@Controller
{{#operations}}
/**
 {{#description}}{{.}}{{/description}}{{^description}}{{classname}}{{/description}}
 ############################## DO NOT EDIT: GENERATED FILE ##############################

    Generated by Starter StackGen: http://stackgen.io
    Powered by Swagger Codegen: http://swagger.io
    
    Template file: JavaSpring/apiController.mustache

############################## DO NOT EDIT: GENERATED FILE ##############################
 
 StackGen Version: {{ignite.version}}
 
 */
public class {{classname}}Controller implements {{classname}} {

{{#isDelegate}}
    
    @org.springframework.beans.factory.annotation.Autowired
    private {{classname}}Delegate delegate = null;

	/**
	* No-Args Constructor for classloading.
	*/
	public {{classname}}Controller() {
		// do not use
    }
    
    @org.springframework.beans.factory.annotation.Autowired
    public {{classname}}Controller({{classname}}Delegate delegate) {
        this.delegate = delegate;
    }
    {{#jdk8}}

    @Override
    public {{classname}}Delegate getDelegate() {
        return delegate;
    }
    {{/jdk8}}
{{/isDelegate}}
{{^isDelegate}}
    {{^jdk8}}
    private static final Logger log = LoggerFactory.getLogger({{classname}}Controller.class);

    {{/jdk8}}
    @Autowired
    private final ObjectMapper objectMapper;

    private final HttpServletRequest request;

    @org.springframework.beans.factory.annotation.Autowired
    public {{classname}}Controller(ObjectMapper objectMapper, HttpServletRequest request) {
        this.objectMapper = objectMapper;
        this.request = request;
    }
    {{#jdk8}}

    @Override
    public Optional getObjectMapper() {
        return Optional.ofNullable(objectMapper);
    }

    @Override
    public Optional getRequest() {
        return Optional.ofNullable(request);
    }
    {{/jdk8}}

{{/isDelegate}}
{{^jdk8}}
{{#operation}}
    public {{#async}}Callable<{{/async}}ResponseEntity<{{>returnTypes}}>{{#async}}>{{/async}} {{operationId}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{#hasMore}},{{/hasMore}}{{/allParams}}) {
        {{^isDelegate}}
        {{^async}}
        String accept = request.getHeader("Accept");
        {{#examples}}
        if (accept != null && accept.contains("{{{contentType}}}")) {

            {{{contentType}}}Service ret = {{{contentType}}}Service(); // create and load
            ret.load();

            try {
              if(ret.getId() > -1l){
                 return new ResponseEntity<{{>returnTypes}}>(objectMapper.readValue(ret.toString(), {{>exampleReturnTypes}}.class), HttpStatus.NOT_IMPLEMENTED);
              } else {
                return new ResponseEntity<{{>returnTypes}}>(objectMapper.readValue("{{#lambdaRemoveLineBreak}}{{#lambdaEscapeDoubleQuote}}{{{example}}}{{/lambdaEscapeDoubleQuote}}{{/lambdaRemoveLineBreak}}", {{>exampleReturnTypes}}.class), HttpStatus.NOT_IMPLEMENTED);
              }
            } catch (IOException e) {
                log.error("Couldn't serialize response for content type {{{contentType}}}", e);
                return new ResponseEntity<{{>returnTypes}}>(HttpStatus.INTERNAL_SERVER_ERROR);
            }
        }

        {{/examples}}
        return new ResponseEntity<{{>returnTypes}}>(HttpStatus.NOT_IMPLEMENTED);
        {{/async}}
        {{#async}}
        return new CallablereturnTypes}}>>() {
            @Override
            public ResponseEntity<{{>returnTypes}}> call() {
                String accept = request.getHeader("Accept");
                {{#examples}}
                if (accept != null && accept.contains("{{{contentType}}}")) {
                    try {
                        return new ResponseEntity<{{>returnTypes}}>(objectMapper.readValue("{{#lambdaRemoveLineBreak}}{{#lambdaEscapeDoubleQuote}}{{{example}}}{{/lambdaEscapeDoubleQuote}}{{/lambdaRemoveLineBreak}}", {{>exampleReturnTypes}}.class), HttpStatus.NOT_IMPLEMENTED);
                    } catch (IOException e) {
                        log.error("Couldn't serialize response for content type {{{contentType}}}", e);
                        return new ResponseEntity<{{>returnTypes}}>(HttpStatus.INTERNAL_SERVER_ERROR);
                    }
                }

                {{/examples}}
                return new ResponseEntity<{{>returnTypes}}>(HttpStatus.NOT_IMPLEMENTED);
            }
        };
        {{/async}}
        {{/isDelegate}}
        {{#isDelegate}}
        return delegate.{{operationId}}({{#allParams}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}});
        {{/isDelegate}}
    }

{{/operation}}
{{/jdk8}}
}
{{/operations}}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy