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

ftl.rest.server.method.$$RestControllerProcessorMethodBodyTemplateftl Maven / Gradle / Ivy

There is a newer version: 0.11
Show newest version
final ${REQUEST_CLASS} req = ${REQUEST_READER}.read(pathVariableMapping, request, request.contentExists());
<#if GENERATE_REQUEST_VALIDATORS>
${REQUEST_VALIDATOR}.validate(req);

<#-- --------------------------------------------- Static headers -------------------------------------------------- -->
<#if STATIC_HEADERS?has_content>
<#if STATIC_HEADERS?size == 1>
final HttpHeaders headers = HttpHeaders.of(<#list STATIC_HEADERS as e>"${e.key}", "${e.value}");
<#elseif STATIC_HEADERS?size <= 10>
final HttpHeaders headers = HttpHeaders.of(
    <#list STATIC_HEADERS as e>
        "${e.key}", "${e.value}"<#if e?has_next>,
    
);
<#else>
final HttpHeaders headers = HttpHeaders.of(
    <#list STATIC_HEADERS as e>
        java.util.Map.entry("${e.key}", "${e.value}")<#if e?has_next>,
    
);

<#else>
final HttpHeaders headers = HttpHeaders.of();

<#-- --------------------------------------------------------------------------------------------------------------- -->
<#-- --------------------------------------------------------------------------------------------------------------- -->
<#-- --------------------------------------- JSE CompletableFuture ------------------------------------------------- -->
<#if RETURN.future>
<#-- ------------------------------ JSE CompletableFuture> ------------------------------------------ -->
<#if RETURN.optional>
<#if IS_REQUEST_CLASS_VIRTUAL>
return restController.${METHOD_NAME.simpleName}(<#list VIRTUAL_FIELDS as f>req.${f}<#if f?has_next>, )
        .thenApply(optionalResponse -> optionalResponse
                .map(response -> buildResponse(response, ${STATUS_CODE}, headers))
                .orElse(${METHOD_NAME.uniqueJavaName}NotFoundResponse));
<#else>
return restController.${METHOD_NAME.simpleName}(req)
        .thenApply(optionalResponse -> optionalResponse
                .map(response -> buildResponse(response, ${STATUS_CODE}, headers))
                .orElse(${METHOD_NAME.uniqueJavaName}NotFoundResponse));

<#else>
<#-- ------------------------------------ JSE CompletableFuture ---------------------------------------------- -->
<#if IS_REQUEST_CLASS_VIRTUAL>
return restController.${METHOD_NAME.simpleName}(<#list VIRTUAL_FIELDS as f>req.${f}<#if f?has_next>, )
        .thenApply(response -> buildResponse(response, ${STATUS_CODE}, headers));
<#else>
return restController.${METHOD_NAME.simpleName}(req)
        .thenApply(response -> buildResponse(response, ${STATUS_CODE}, headers));


<#-- -------------------------------------- Spring Reactor Mono ---------------------------------------------- -->
<#elseif RETURN.mono>
<#if IS_REQUEST_CLASS_VIRTUAL>
return restController.${METHOD_NAME.simpleName}(<#list VIRTUAL_FIELDS as f>req.${f}<#if f?has_next>, )
        .map(response -> buildResponse(response, ${STATUS_CODE}, headers))
        .defaultIfEmpty(${METHOD_NAME.uniqueJavaName}NotFoundResponse)
        .toFuture();
<#else>
return restController.${METHOD_NAME.simpleName}(req)
        .map(response -> buildResponse(response, ${STATUS_CODE}, headers))
        .defaultIfEmpty(${METHOD_NAME.uniqueJavaName}NotFoundResponse)
        .toFuture();

<#-- ---------------------------------------- RxJava Single -------------------------------------------------- -->
<#elseif RETURN.single>
<#if IS_REQUEST_CLASS_VIRTUAL>
return restController.${METHOD_NAME.simpleName}(<#list VIRTUAL_FIELDS as f>req.${f}<#if f?has_next>, )
        .map(response -> buildResponse(response, ${STATUS_CODE}, headers))
        .toCompletionStage();
<#else>
return restController.${METHOD_NAME.simpleName}(req)
        .map(response -> buildResponse(response, ${STATUS_CODE}, headers))
        .toCompletionStage();

<#-- ----------------------------------------- RxJava Maybe -------------------------------------------------- -->
<#elseif RETURN.maybe>
<#if IS_REQUEST_CLASS_VIRTUAL>
return restController.${METHOD_NAME.simpleName}(<#list VIRTUAL_FIELDS as f>req.${f}<#if f?has_next>, )
        .map(response -> buildResponse(response, ${STATUS_CODE}, headers))
        .defaultIfEmpty(${METHOD_NAME.uniqueJavaName}NotFoundResponse)
        .toCompletionStage();
<#else>
return restController.${METHOD_NAME.simpleName}(req)
        .map(response -> buildResponse(response, ${STATUS_CODE}, headers))
        .defaultIfEmpty(${METHOD_NAME.uniqueJavaName}NotFoundResponse)
        .toCompletionStage();

<#-- --------------------------------------------------------------------------------------------------------------- -->
<#else>
//"RxMicro does not know how to generate this method";
<#-- --------------------------------------------------------------------------------------------------------------- -->





© 2015 - 2024 Weber Informatics LLC | Privacy Policy