<commit_before>package sk.fiit.dps.team11.resources;

import java.util.Optional;

import javax.inject.Inject;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.codahale.metrics.annotation.Timed;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.kjetland.dropwizard.activemq.ActiveMQSender;
import com.sleepycat.je.DatabaseException;

import sk.fiit.dps.team11.annotations.MQSender;
import sk.fiit.dps.team11.models.Sample;
import sk.fiit.dps.team11.models.SimpleEntry;
import sk.fiit.dps.team11.providers.DatabaseAdapter;

@Path("/sample")
public class SampleResource {

	private static final Logger LOGGER = LoggerFactory.getLogger(SampleResource.class);
	
	@Inject
	DatabaseAdapter db;
	
	@MQSender(topic = "sample")
	ActiveMQSender sender;
	
	@Produces(MediaType.APPLICATION_JSON)
	@GET
	@Timed(name = "sample")
	public Sample justTest(@QueryParam("value") String value) {
		
		if (value != null) {
			LOGGER.info("Putting value {} into sample queue", value);
			sender.send(value);
		}
		
		return new Sample("Hello! The application works.");
	}
	
	@POST
	@Consumes(MediaType.APPLICATION_JSON)
	@Path("put")
	public Response simplePut(SimpleEntry entry) throws DatabaseException {
		boolean success = db.put(entry.getKey().getBytes(), entry.getValue().getBytes());
		
		return success ? Response.ok().build() : Response.serverError().build();
	}
	
	@POST
	@Produces(MediaType.APPLICATION_JSON)
	@Path("get")
	public JsonNode simpleGet(SimpleEntry entry) throws DatabaseException {
		Optional<byte[]> value = db.get(entry.getKey().getBytes());
		
		ObjectNode ret = JsonNodeFactory.instance.objectNode();
		ret.put("present", value.isPresent());
		if (value.isPresent()) {
			ret.put("value", value.get());
		}
		
		return ret;
	}
	
}
<commit_msg>Database example correction<commit_after>package sk.fiit.dps.team11.resources;

import java.util.Optional;

import javax.inject.Inject;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.codahale.metrics.annotation.Timed;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.kjetland.dropwizard.activemq.ActiveMQSender;
import com.sleepycat.je.DatabaseException;

import sk.fiit.dps.team11.annotations.MQSender;
import sk.fiit.dps.team11.models.Sample;
import sk.fiit.dps.team11.models.SimpleEntry;
import sk.fiit.dps.team11.providers.DatabaseAdapter;

@Path("/sample")
public class SampleResource {

	private static final Logger LOGGER = LoggerFactory.getLogger(SampleResource.class);
	
	@Inject
	DatabaseAdapter db;
	
	@MQSender(topic = "sample")
	ActiveMQSender sender;
	
	@Produces(MediaType.APPLICATION_JSON)
	@GET
	@Timed(name = "sample")
	public Sample justTest(@QueryParam("value") String value) {
		
		if (value != null) {
			LOGGER.info("Putting value {} into sample queue", value);
			sender.send(value);
		}
		
		return new Sample("Hello! The application works.");
	}
	
	@POST
	@Consumes(MediaType.APPLICATION_JSON)
	@Path("put")
	public Response simplePut(SimpleEntry entry) throws DatabaseException {
		boolean success = db.put(entry.getKey().getBytes(), entry.getValue().getBytes());
		
		return success ? Response.ok().build() : Response.serverError().build();
	}
	
	@POST
	@Produces(MediaType.APPLICATION_JSON)
	@Path("get")
	public JsonNode simpleGet(SimpleEntry entry) throws DatabaseException {
		Optional<byte[]> value = db.get(entry.getKey().getBytes());
		
		ObjectNode ret = JsonNodeFactory.instance.objectNode();
		ret.put("present", value.isPresent());
		if (value.isPresent()) {
			ret.put("value", new String(value.get()));
		}
		
		return ret;
	}
	
}

{'fraction_non_alphanumeric': 0.1351098644226274, 'fraction_numerical': 0.005610098176718092, 'mean_word_length': 5.147988505747127, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, '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': '7063990', 'n_tokens_mistral': 1520, 'n_tokens_neox': 1403, 'n_words': 259}