Search in sources :

Example 1 with ActionMapping

use of uk.gov.justice.services.generators.commons.mapping.ActionMapping in project microservice_framework by CJSCommonPlatform.

the class ActionMappingGenerator method mapperConstructorCodeFor.

private CodeBlock mapperConstructorCodeFor(final Resource resource) {
    final CodeBlock.Builder constructorCode = CodeBlock.builder().addStatement("this.$L = $L", ACTION_MAPPER_HELPER_FIELD, ACTION_MAPPER_HELPER_FIELD);
    // NOTE: there's a bit of ambiguity here: ramlActions (http methods) are not framework actions
    resource.getActions().values().forEach(ramlAction -> {
        final List<ActionMapping> actionMappings = new ActionMappingParser().listOf(ramlAction.getDescription());
        final ActionType actionType = ramlAction.getType();
        if (isSupportedActionType(actionType)) {
            actionMappings.forEach(actionMapping -> {
                final String mediaType = actionMapping.mimeTypeFor(ramlAction.getType());
                constructorCode.addStatement("$L.add($S, $S, $S)", ACTION_MAPPER_HELPER_FIELD, methodNameForAction(ramlAction, actionType, mediaType), mediaType, actionMapping.getName());
            });
        } else {
            throw new IllegalStateException(format("Http Method of type %s is not supported by the Action Mapper", actionType.toString()));
        }
    });
    return constructorCode.build();
}
Also used : ActionMappingParser(uk.gov.justice.services.generators.commons.mapping.ActionMappingParser) ActionMapping(uk.gov.justice.services.generators.commons.mapping.ActionMapping) ActionType(org.raml.model.ActionType) Actions.isSupportedActionType(uk.gov.justice.services.generators.commons.helper.Actions.isSupportedActionType) CodeBlock(com.squareup.javapoet.CodeBlock)

Aggregations

CodeBlock (com.squareup.javapoet.CodeBlock)1 ActionType (org.raml.model.ActionType)1 Actions.isSupportedActionType (uk.gov.justice.services.generators.commons.helper.Actions.isSupportedActionType)1 ActionMapping (uk.gov.justice.services.generators.commons.mapping.ActionMapping)1 ActionMappingParser (uk.gov.justice.services.generators.commons.mapping.ActionMappingParser)1