<commit_before>package org.zalando.nakadi.enrichment;

import org.zalando.nakadi.domain.BatchItem;
import org.zalando.nakadi.domain.EventType;
import org.zalando.nakadi.exceptions.EnrichmentException;
import org.zalando.nakadi.util.FlowIdUtils;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.json.JSONException;
import org.json.JSONObject;

public class MetadataEnrichmentStrategy implements EnrichmentStrategy {
    @Override
    public void enrich(final BatchItem batchItem, final EventType eventType) throws EnrichmentException {
        try {
            final JSONObject metadata = batchItem.getEvent().getJSONObject("metadata");

            setReceivedAt(metadata);
            setEventTypeName(metadata, eventType);
            setFlowId(metadata);
            setPartition(metadata, batchItem);
            setVersion(metadata, eventType);
        } catch (final JSONException e) {
            throw new EnrichmentException("enrichment error", e);
        }
    }

    private void setVersion(final JSONObject metadata, final EventType eventType) {
        metadata.put("version", eventType.getSchema().getVersion().toString());
    }

    private void setFlowId(final JSONObject metadata) {
        if (metadata.optString("flow_id") == null || "".equals(metadata.optString("flow_id"))) {
            metadata.put("flow_id", FlowIdUtils.peek());
        }
    }

    private void setEventTypeName(final JSONObject metadata, final EventType eventType) {
        metadata.put("event_type", eventType.getName());
    }

    private void setReceivedAt(final JSONObject metadata) {
        final DateTime dateTime = new DateTime(DateTimeZone.UTC);
        metadata.put("received_at", dateTime.toString());
    }

    public void setPartition(final JSONObject metadata, final BatchItem batchItem) {
        metadata.put("partition", batchItem.getPartition());
    }
}<commit_msg>Avoid unecessary check for null<commit_after>package org.zalando.nakadi.enrichment;

import org.zalando.nakadi.domain.BatchItem;
import org.zalando.nakadi.domain.EventType;
import org.zalando.nakadi.exceptions.EnrichmentException;
import org.zalando.nakadi.util.FlowIdUtils;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.json.JSONException;
import org.json.JSONObject;

public class MetadataEnrichmentStrategy implements EnrichmentStrategy {
    @Override
    public void enrich(final BatchItem batchItem, final EventType eventType) throws EnrichmentException {
        try {
            final JSONObject metadata = batchItem.getEvent().getJSONObject("metadata");

            setReceivedAt(metadata);
            setEventTypeName(metadata, eventType);
            setFlowId(metadata);
            setPartition(metadata, batchItem);
            setVersion(metadata, eventType);
        } catch (final JSONException e) {
            throw new EnrichmentException("enrichment error", e);
        }
    }

    private void setVersion(final JSONObject metadata, final EventType eventType) {
        metadata.put("version", eventType.getSchema().getVersion().toString());
    }

    private void setFlowId(final JSONObject metadata) {
        if ("".equals(metadata.optString("flow_id"))) {
            metadata.put("flow_id", FlowIdUtils.peek());
        }
    }

    private void setEventTypeName(final JSONObject metadata, final EventType eventType) {
        metadata.put("event_type", eventType.getName());
    }

    private void setReceivedAt(final JSONObject metadata) {
        final DateTime dateTime = new DateTime(DateTimeZone.UTC);
        metadata.put("received_at", dateTime.toString());
    }

    public void setPartition(final JSONObject metadata, final BatchItem batchItem) {
        metadata.put("partition", batchItem.getPartition());
    }
}
{'fraction_non_alphanumeric': 0.10076295711654827, 'fraction_numerical': 0.0, 'mean_word_length': 3.580722891566265, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6274695', 'n_tokens_mistral': 1042, 'n_tokens_neox': 1023, 'n_words': 220}