<commit_before>package com.fns.grivet.service;

import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.stream.messaging.Processor;
import org.springframework.integration.annotation.ServiceActivator;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.messaging.Message;
import org.springframework.util.Assert;

import com.codahale.metrics.MetricRegistry;
import com.fns.grivet.model.Op;

public class PersistenceService {

	private final Logger log = LoggerFactory.getLogger(getClass());

	private final EntityService entityService;
	private final MetricRegistry metricRegistry;

	public PersistenceService(EntityService entityService, MetricRegistry metricRegistry) {
		this.entityService = entityService;
		this.metricRegistry = metricRegistry;
	}

	@ServiceActivator(inputChannel = Processor.INPUT, outputChannel = Processor.OUTPUT)
	public Object store(Message<JSONObject> message) {
		Object result = message;
		Assert.notNull(message.getHeaders(), "No message headers!");
		Assert.notNull(message.getPayload(), "Message must have non-null payload!");
		log.debug("Received message.  Headers - {}.  Payload - {}", message.getHeaders().toString(),
				message.getPayload().toString());

		Op op = message.getHeaders().get("op", Op.class);
		Assert.notNull(op, "Message header must contain an op code!");

		String type = null;
		Long oid = null;
		try {
			switch (op) {
				case CREATE:
					type = message.getHeaders().get("type", String.class);
					Assert.hasText(type, "Message header must contain a type for create requests!");
					entityService.create(type, message.getPayload());
					metricRegistry.counter(MetricRegistry.name("store", "create", type, "count")).inc();
					log.info("Successfully created type [{}]", type);
					result = MessageBuilder.fromMessage(message).setHeader("processed", true);
					break;
				case UPDATE:
					oid = message.getHeaders().get("oid", Long.class);
					Assert.notNull(oid, "Message header must contain an oid for update requests!");
					type = entityService.update(oid, message.getPayload());
					metricRegistry.counter(MetricRegistry.name("store", "update", type, "count")).inc();
					log.info("Successfully updated type [{}]", type);
					result = MessageBuilder.fromMessage(message).setHeader("processed", true);
					break;
				case DELETE:
					oid = message.getHeaders().get("oid", Long.class);
					Assert.notNull(oid, "Message header must contain an oid for delete requests!");
					type = entityService.delete(oid);
					metricRegistry.counter(MetricRegistry.name("store", "delete", type, "count")).inc();
					log.info("Successfully deleted type [{}]", type);
					result = MessageBuilder.fromMessage(message).setHeader("processed", true);
					break;
				default:
					log.error("Bad payload! Op not available.  Headers - {}.  Payload - {}", message.getHeaders().toString(),
							message.getPayload().toString());
					result = MessageBuilder.fromMessage(message).setHeader("processed", false);
			}
		} catch (Exception e) {
			result = MessageBuilder.fromMessage(message)
						.setHeader("processed", false)
						.setHeader("exception", e.getMessage());
		}
		return result;
	}
}
<commit_msg>Fix code booboo<commit_after>package com.fns.grivet.service;

import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.stream.messaging.Processor;
import org.springframework.integration.annotation.ServiceActivator;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.messaging.Message;
import org.springframework.util.Assert;

import com.codahale.metrics.MetricRegistry;
import com.fns.grivet.model.Op;

public class PersistenceService {

	private final Logger log = LoggerFactory.getLogger(getClass());

	private final EntityService entityService;
	private final MetricRegistry metricRegistry;

	public PersistenceService(EntityService entityService, MetricRegistry metricRegistry) {
		this.entityService = entityService;
		this.metricRegistry = metricRegistry;
	}

	@ServiceActivator(inputChannel = Processor.INPUT, outputChannel = Processor.OUTPUT)
	public Object store(Message<JSONObject> message) {
		log.trace("Received message.  Headers - {}.  Payload - {}", message.getHeaders().toString(),
				message.getPayload().toString());
		Object result = message;
		try {
			Assert.notNull(message.getHeaders(), "No message headers!");
			Assert.notNull(message.getPayload(), "Message must have non-null payload!");
	
			Op op = message.getHeaders().get("op", Op.class);
			Assert.notNull(op, "Message header must contain an op code!");
	
			String type = null;
			Long oid = null;
		
			switch (op) {
				case CREATE:
					type = message.getHeaders().get("type", String.class);
					Assert.hasText(type, "Message header must contain a type for create requests!");
					entityService.create(type, message.getPayload());
					metricRegistry.counter(MetricRegistry.name("store", "create", type, "count")).inc();
					log.info("Successfully created type [{}]", type);
					result = MessageBuilder.fromMessage(message).setHeader("processed", true);
					break;
				case UPDATE:
					oid = message.getHeaders().get("oid", Long.class);
					Assert.notNull(oid, "Message header must contain an oid for update requests!");
					type = entityService.update(oid, message.getPayload());
					metricRegistry.counter(MetricRegistry.name("store", "update", type, "count")).inc();
					log.info("Successfully updated type [{}]", type);
					result = MessageBuilder.fromMessage(message).setHeader("processed", true);
					break;
				case DELETE:
					oid = message.getHeaders().get("oid", Long.class);
					Assert.notNull(oid, "Message header must contain an oid for delete requests!");
					type = entityService.delete(oid);
					metricRegistry.counter(MetricRegistry.name("store", "delete", type, "count")).inc();
					log.info("Successfully deleted type [{}]", type);
					result = MessageBuilder.fromMessage(message).setHeader("processed", true);
					break;
				default:
					throw new RuntimeException("Bad message payload!");
			}
		} catch (Exception e) {
			log.error("Op not available.  Headers - {}.  Payload - {}", message.getHeaders().toString(),
					message.getPayload().toString());
			result = MessageBuilder.fromMessage(message)
						.setHeader("processed", false)
						.setHeader("exception", e.getMessage());
		}
		return result;
	}
}

{'fraction_non_alphanumeric': 0.13583282114320835, 'fraction_numerical': 0.0006146281499692685, 'mean_word_length': 4.68471615720524, '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': '4744388', 'n_tokens_mistral': 2106, 'n_tokens_neox': 1780, 'n_words': 416}