<commit_before>package com.willhamill;

import com.amazonaws.services.dynamodbv2.document.Item;
import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.RequestHandler;
import com.github.mustachejava.DefaultMustacheFactory;
import com.github.mustachejava.Mustache;

import java.io.IOException;
import java.io.StringWriter;
import java.util.Optional;

public class HelloWorldMicroservice implements RequestHandler<String, String> {

    private Item dynamoDbConfigItem;

    public String handleRequest(String name, Context context) {
        ContextWrapper contextWrapper = new ContextWrapper(context);
        if (dynamoDbConfigItem == null) {
            dynamoDbConfigItem = contextWrapper.getConfigItem();
        }
        String responseLanguage = dynamoDbConfigItem.getString("responseLanguage");

        Mustache mustache = new DefaultMustacheFactory().compile("hellopage.mustache");

        String envVersion = Optional.ofNullable(context.getFunctionVersion()).orElse("no-alias");
        String functionName = Optional.ofNullable(context.getFunctionName()).orElse("default-name");
        String arnName = Optional.ofNullable(context.getInvokedFunctionArn()).orElse("default-arn");

        String response = "Hello " + name + " from version: " + envVersion + " of " + functionName + " with arn: " + arnName;

        HelloResponse responseData = new HelloResponse(responseLanguage, response);
        StringWriter stringWriter = new StringWriter();

        try {
            mustache.execute(stringWriter, responseData).flush();
        } catch (IOException e) {
            stringWriter.append("Failed to execute mustache template and flush output");
        }

        return stringWriter.toString();
    }
<commit_msg>Adding support for environment variable config for language<commit_after>package com.willhamill;

import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.RequestHandler;
import com.github.mustachejava.DefaultMustacheFactory;
import com.github.mustachejava.Mustache;

import java.io.IOException;
import java.io.StringWriter;
import java.util.Optional;

/*
    This class acts as the main function handler for the lambda
 */
public class HelloWorldMicroservice implements RequestHandler<String, String> {

    private static final String DEFAULT_LANGUAGE = "en-GB";

    /*
        This method is the main handler for the hello world function,
        taking a string param and returning a HTML templated response
        containing a language read in from environment variable config
     */
    public String handleRequest(String name, Context context) {
        String responseLanguage = Optional.ofNullable(System.getenv("language")).orElse(DEFAULT_LANGUAGE);

        Mustache mustache = new DefaultMustacheFactory().compile("hellopage.mustache");

        String envVersion = Optional.ofNullable(context.getFunctionVersion()).orElse("no-alias");
        String functionName = Optional.ofNullable(context.getFunctionName()).orElse("default-name");
        String arnName = Optional.ofNullable(context.getInvokedFunctionArn()).orElse("default-arn");

        String response = "Hello " + name + " from version: " + envVersion + " of " + functionName + " with arn: " + arnName;

        HelloResponse responseData = new HelloResponse(responseLanguage, response);
        StringWriter stringWriter = new StringWriter();

        try {
            mustache.execute(stringWriter, responseData).flush();
        } catch (IOException e) {
            stringWriter.append("Failed to execute mustache template and flush output");
        }

        return stringWriter.toString();
    }

{'fraction_non_alphanumeric': 0.09456903539583897, 'fraction_numerical': 0.0002701972439881113, 'mean_word_length': 3.8968253968253967, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6436744', 'n_tokens_mistral': 938, 'n_tokens_neox': 914, 'n_words': 230}