<commit_before>package net.muszytowski.WearableInspectionServer;

import java.util.Date;
import java.util.List;
import java.util.Random;

import net.muszytowski.WearableInspectionServer.items.Attachment;
import net.muszytowski.WearableInspectionServer.items.GenericTask;
import net.muszytowski.WearableInspectionServer.items.InspectionTree;
import net.muszytowski.WearableInspectionServer.items.Status;
import net.muszytowski.WearableInspectionServer.items.Task;
import net.muszytowski.WearableInspectionServer.repositories.InspectionTreeRepository;
import net.muszytowski.WearableInspectionServer.repositories.TaskRepository;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.fasterxml.jackson.databind.ObjectMapper;

@Controller
@Transactional
public class WearableController {
	
	private @Autowired TaskRepository taskRepository;
	private @Autowired InspectionTreeRepository inspectionTreeRepository;
	
	/**
	 * Set InspectionTree
	 * 
	 * @return
	 * @throws  
	 */
	@RequestMapping("/setInspectionTree")
	public @ResponseBody
	InspectionTree setInspectionTree(
			@RequestParam(value = "InspectionTree", required = true) String inspectionTree) throws Exception {
		InspectionTree tree = new ObjectMapper().readValue(inspectionTree.getBytes(), InspectionTree.class);
		return inspectionTreeRepository.save(tree);
	}

	/**
	 * Get the InspectionTree
	 * 
	 * @return
	 */
	@RequestMapping("/generateSampleData")
	public @ResponseBody
	InspectionTree getInspectionTreeSample(@RequestParam(value = "Depth", required = false) Integer depth) {
		InspectionTree sample = SampleGenerator.generateRandomTree((depth == null)? 7 : depth);
		System.out.println(sample);
		return inspectionTreeRepository.save(sample);
	}
	
	@RequestMapping("/getInspectionTree")
	public @ResponseBody
	InspectionTree getInspectionTree() {
		List<InspectionTree> result = inspectionTreeRepository.findRoot();
		return (result.isEmpty())?null : result.get(0);
	}
	
	
	/**
	 * Gets a task (by ID)
	 * @param long
	 * @return
	 */
	@RequestMapping("/getTask")<commit_msg>add possibility for POST requests<commit_after>package net.muszytowski.WearableInspectionServer;

import java.util.List;

import net.muszytowski.WearableInspectionServer.items.Attachment;
import net.muszytowski.WearableInspectionServer.items.GenericTask;
import net.muszytowski.WearableInspectionServer.items.InspectionTree;
import net.muszytowski.WearableInspectionServer.items.Status;
import net.muszytowski.WearableInspectionServer.items.Task;
import net.muszytowski.WearableInspectionServer.repositories.InspectionTreeRepository;
import net.muszytowski.WearableInspectionServer.repositories.TaskRepository;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.fasterxml.jackson.databind.ObjectMapper;

@Controller
@Transactional
public class WearableController {
	
	private @Autowired TaskRepository taskRepository;
	private @Autowired InspectionTreeRepository inspectionTreeRepository;
	
	/**
	 * Set InspectionTree
	 * 
	 * @return
	 * @throws  
	 */
	@RequestMapping(value = "/setInspectionTree",
	         method = RequestMethod.GET)
	public @ResponseBody
	InspectionTree setInspectionTree(
			@RequestParam(value = "InspectionTree", required = true) String inspectionTree) throws Exception {
		InspectionTree tree = new ObjectMapper().readValue(inspectionTree.getBytes(), InspectionTree.class);
		return inspectionTreeRepository.save(tree);
	}
	
	@RequestMapping(value = "/setInspectionTree",
	         method = RequestMethod.POST)
	public @ResponseBody
	InspectionTree setInspectionTreePOST(
			@RequestBody String inspectionTree) throws Exception {
		InspectionTree tree = new ObjectMapper().readValue(inspectionTree.getBytes(), InspectionTree.class);
		return inspectionTreeRepository.save(tree);
	}

	/**
	 * Get the InspectionTree
	 * 
	 * @return
	 */
	@RequestMapping("/generateSampleData")
	public @ResponseBody
	InspectionTree getInspectionTreeSample(@RequestParam(value = "Depth", required = false) Integer depth) {
		InspectionTree sample = SampleGenerator.generateRandomTree((depth == null)? 7 : depth);
		System.out.println(sample);
		return inspectionTreeRepository.save(sample);
	}
	
	@RequestMapping("/getInspectionTree")
	public @ResponseBody
	InspectionTree getInspectionTree() {
		List<InspectionTree> result = inspectionTreeRepository.findRoot();
		return (result.isEmpty())?null : result.get(0);
	}
	
	
	/**
	 * Gets a task (by ID)
	 * @param long
	 * @return
	 */
	@RequestMapping("/getTask")
{'fraction_non_alphanumeric': 0.09814779453885812, 'fraction_numerical': 0.0007637960664502578, 'mean_word_length': 6.325874125874126, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '2500361', 'n_tokens_mistral': 1575, 'n_tokens_neox': 1495, 'n_words': 258}