
JavaSpring.apiDelegate.mustache Maven / Gradle / Ivy
package {{package}};
{{#imports}}import {{import}};
{{/imports}}
{{#jdk8}}
import io.starter.ignite.model.DataModelObject;
import io.starter.ignite.generator.IgniteException;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.core.type.TypeReference;
{{/jdk8}}
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import org.json.*;
{{#jdk8}}
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
{{/jdk8}}
import org.springframework.http.ResponseEntity;
import org.springframework.web.multipart.MultipartFile;
{{#jdk8}}
import java.io.IOException;
{{/jdk8}}
{{#jdk8}}
import javax.servlet.http.HttpServletRequest;
{{/jdk8}}
import java.util.List;
{{#jdk8}}
{{/jdk8}}
{{^jdk8}}
{{#useOptional}}
import java.util.Optional;
{{/useOptional}}
{{/jdk8}}
{{#async}}
import java.util.concurrent.{{^jdk8}}Callable{{/jdk8}}{{#jdk8}}CompletableFuture{{/jdk8}};
{{/async}}
{{#operations}}
/**
* A delegate to be called by the {@link {{classname}}Controller}}.
* Implement this interface with a {@link org.springframework.stereotype.Service} annotated class.
*
{{#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/apiDelegate.mustache
############################## DO NOT EDIT: GENERATED FILE ##############################
*/
{{>generatedAnnotation}}
@EnableWebMvc
public interface {{classname}}Delegate {
{{#jdk8}}
Logger log = LoggerFactory.getLogger({{classname}}Delegate.class);
ObjectMapper getObjectMapper();
HttpServletRequest getHttpServletRequest();
String getAcceptHeader();
// Starter StackGen Persistence methods
public void setId(Long idVal);
public int insert();
public int update();
public int delete();
public String toJSON();
public void setDelegate(Object o);
public Object getDelegate();
public List<{{classname}}Delegate> list();
public {{classname}}Delegate load();
// End Starter StackGen Persistence methods
{{/jdk8}}
{{#operation}}
/**
* Dispatch the request to the delegate data object method and handle response
*
* @see {{classname}}#{{operationId}}
*/
{{#jdk8}}default {{/jdk8}}{{#responseWrapper}}{{.}}<{{/responseWrapper}}ResponseEntity<{{>returnTypes}}>{{#responseWrapper}}>{{/responseWrapper}} {{operationId}}({{#allParams}}{{^isFile}} {{>optionalDataType}} {{/isFile}}{{#isFile}}MultipartFile{{/isFile}} {{paramName}}{{#hasMore}},
{{/hasMore}}{{/allParams}}){{^jdk8}};{{/jdk8}}{{#jdk8}} {
if(getObjectMapper() != null && getAcceptHeader() != null) {
// {{operationId}}({{paramName}}); -{{>optionalDataType}} {{baseName}}
try {
Object ret = callMethod("{{operationId}}"{{#allParams}}, {{paramName}}{{#hasMore}} {{/hasMore}}{{/allParams}});
if (ret != null) {
if (ret instanceof List) {
return {{#async}}CompletableFuture.completedFuture({{/async}}
(ResponseEntity<{{>returnTypes}}>) getResponse((List>) ret){{#async}}){{/async}};
} else {
return {{#async}}CompletableFuture.completedFuture({{/async}}
(ResponseEntity<{{>returnTypes}}>) getResponse(this){{#async}}){{/async}};
}
} else {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
} catch (Exception e) {
log.error("Failure running method {{classname}}.{{operationId}}: "
+ e);
return new ResponseEntity<>(HttpStatus. INTERNAL_SERVER_ERROR);
}
{{#examples}}
// TODO: implement examples
{{/examples}}
} else {
log.warn("ObjectMapper or HttpServletRequest not configured in default {{classname}} interface so no example is generated");
}
return {{#async}}CompletableFuture.completedFuture({{/async}}new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED){{#async}}){{/async}};
}{{/jdk8}}
{{/operation}}
/**
* Handle calling the data method on the Starter StackGen Delegate
*/
default Object callMethod(String string, Object... args)
throws Exception {
if ("update".equals(string) && args.length == 2) {
this.setDelegate(args[1]);
}
// hande id
try {
Long id = Long.parseLong(args[0].toString());
// TODO: copy vals
setId(id);
// TODO: implement ModelCache
} catch (Exception e) {
// other type NP
setDelegate(args[0]);
}
Method method = this.getClass().getDeclaredMethod(string);
Object rx = method.invoke(this);
List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy