use of uk.gov.justice.services.generators.commons.mapping.ActionMappingParser 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();
}
Aggregations