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

ftl.rest.client.rest-client-libftl Maven / Gradle / Ivy

The newest version!
<#-- ------------------------------------------------------------------------------------------------ -->
<#-- ----------------- https://freemarker.apache.org/docs/ref_directive_macro.html ------------------ -->
<#-- ------------------------------------------------------------------------------------------------ -->
<#macro validateRequest MODE>
<#-- ------------------------------------------------------------------------------------------------ -->
<#if MODE.name() == 'THROW_EXCEPTION'>
validateRequest(config.isEnableAdditionalValidations(), ${REQUEST_MODEL_CLASS.modelValidatorInstanceName}, ${MODEL});
<#else>
try {
    validateRequest(config.isEnableAdditionalValidations(), ${REQUEST_MODEL_CLASS.modelValidatorInstanceName}, ${MODEL});
} catch (final ValidationException e) {
    <#if RETURN.mono>
    return Mono.error(e);
    <#elseif RETURN.future>
    return CompletableFuture.failedFuture(e);
    <#elseif RETURN.single>
    return Single.error(e);
    <#elseif RETURN.maybe>
    return Maybe.error(e);
    <#elseif RETURN.completable>
    return Completable.error(e);
    <#else>
    //"The RxMicro framework does not know how to generate this method";
    
}

<#-- ------------------------------------------------------------------------------------------------ -->

<#-- ------------------------------------------------------------------------------------------------ -->
<#-- ----------------- https://freemarker.apache.org/docs/ref_directive_macro.html ------------------ -->
<#-- ------------------------------------------------------------------------------------------------ -->
<#macro returnResult>
<#-- ------------------------------------------- Void ----------------------------------------------- -->
<#if RETURN.void>
<#if RETURN.mono>
return Mono.fromFuture(response)
        .then();
<#elseif RETURN.future>
return response
        .thenApply(resp -> null);
<#elseif RETURN.completable>
return Completable.fromCompletionStage(response);
<#else>
//"The RxMicro framework does not know how to generate this method";

<#-- ------------------------------------- Single result -------------------------------------------- -->
<#elseif RETURN.oneItem>
<#if RETURN.mono>
return Mono.fromFuture(response)
        .map(resp -> ${RESPONSE_READER}.readSingle(resp))<#if !GENERATE_RESPONSE_VALIDATORS>;
        <#if GENERATE_RESPONSE_VALIDATORS>
        .doOnSuccess(resp -> validateResponse(${RESPONSE_MODEL_CLASS.modelValidatorInstanceName}, resp));
        
<#elseif RETURN.future>
return response
        .thenApply(resp -> ${RESPONSE_READER}.readSingle(resp))<#if !GENERATE_RESPONSE_VALIDATORS>;
        <#if GENERATE_RESPONSE_VALIDATORS>
        .whenComplete((resp, th) -> validateIfResponseExists(${RESPONSE_MODEL_CLASS.modelValidatorInstanceName}, resp));
        
<#elseif RETURN.single>
return Single.fromCompletionStage(response)
        .map(resp -> ${RESPONSE_READER}.readSingle(resp))<#if !GENERATE_RESPONSE_VALIDATORS>;
        <#if GENERATE_RESPONSE_VALIDATORS>
        .doOnSuccess(resp -> validateResponse(${RESPONSE_MODEL_CLASS.modelValidatorInstanceName}, resp));
        
<#else>
//"The RxMicro framework does not know how to generate this method";

<#-- -------------------------------------- List result -------------------------------------------- -->
<#else>
<#if RETURN.mono>
return Mono.fromFuture(response)
        .map(resp -> ${RESPONSE_READER}.readList(resp))<#if !GENERATE_RESPONSE_VALIDATORS>;
        <#if GENERATE_RESPONSE_VALIDATORS>
        .doOnSuccess(resp -> validateResponse(${RESPONSE_MODEL_CLASS.modelValidatorInstanceName}, resp));
        
<#elseif RETURN.future>
return response
        .thenApply(resp -> ${RESPONSE_READER}.readList(resp))<#if !GENERATE_RESPONSE_VALIDATORS>;
        <#if GENERATE_RESPONSE_VALIDATORS>
        .whenComplete((resp, th) -> validateIfResponseExists(${RESPONSE_MODEL_CLASS.modelValidatorInstanceName}, resp));
        
<#elseif RETURN.single>
return Single.fromCompletionStage(response)
        .map(resp -> ${RESPONSE_READER}.readList(resp))<#if !GENERATE_RESPONSE_VALIDATORS>;
        <#if GENERATE_RESPONSE_VALIDATORS>
        .doOnSuccess(resp -> validateResponse(${RESPONSE_MODEL_CLASS.modelValidatorInstanceName}, resp));
        
<#else>
//"The RxMicro framework does not know how to generate this method";


<#-- ------------------------------------------------------------------------------------------------ -->

<#-- ------------------------------------------------------------------------------------------------ -->
<#-- ----------------- https://freemarker.apache.org/docs/ref_directive_macro.html ------------------ -->
<#-- ------------------------------------------------------------------------------------------------ -->




© 2015 - 2024 Weber Informatics LLC | Privacy Policy