Search in sources :

Example 1 with ParameterType

use of uk.gov.justice.services.adapter.rest.parameter.ParameterType in project microservice_framework by CJSCommonPlatform.

the class JaxRsImplementationGenerator method putAllQueryParamsInCollectionBuilder.

/**
 * Generate code to add all query parameters to the params map.
 *
 * @param parameters the params to add to the map
 * @return the {@link CodeBlock} that represents the generated code
 */
private CodeBlock putAllQueryParamsInCollectionBuilder(final Map<String, QueryParameter> parameters) {
    final CodeBlock.Builder builder = CodeBlock.builder();
    parameters.entrySet().forEach(paramEntry -> {
        final String name = paramEntry.getKey();
        final ParameterType parameterType = ParameterType.valueOfQueryType(paramEntry.getValue().getType().name());
        if (paramEntry.getValue().isRequired()) {
            builder.addStatement(PARAMS_PUT_REQUIRED_STATEMENT_FORMAT, VALID_PARAMETER_COLLECTION_BUILDER_VARIABLE, name, name, ParameterType.class, parameterType.name());
        } else {
            builder.addStatement(PARAMS_PUT_OPTIONAL_STATEMENT_FORMAT, VALID_PARAMETER_COLLECTION_BUILDER_VARIABLE, name, name, ParameterType.class, parameterType.name());
        }
    });
    return builder.build();
}
Also used : ParameterType(uk.gov.justice.services.adapter.rest.parameter.ParameterType) CodeBlock(com.squareup.javapoet.CodeBlock)

Aggregations

CodeBlock (com.squareup.javapoet.CodeBlock)1 ParameterType (uk.gov.justice.services.adapter.rest.parameter.ParameterType)1