<commit_before>/*
 * Copyright (C) 2015 <NAME>, <EMAIL>
 *
 * This file is part of the Application Intrusion Detection project.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package de.dominikschadow.duke.encounters.controllers;

import de.dominikschadow.duke.encounters.domain.Encounter;
import de.dominikschadow.duke.encounters.domain.SearchFilter;
import de.dominikschadow.duke.encounters.services.EncounterService;
import de.dominikschadow.duke.encounters.services.ValidationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

import static org.springframework.web.bind.annotation.RequestMethod.GET;
import static org.springframework.web.bind.annotation.RequestMethod.POST;

/**
 * Controller to handle all encounter related requests.
 */
@Controller
public class EncountersController {
    private EncounterService encounterService;
    private ValidationService validationService;

    @Autowired
    public EncountersController(EncounterService encounterService, ValidationService validationService) {
        this.encounterService = encounterService;
        this.validationService = validationService;
    }

    @RequestMapping(value = "/encounters", method = GET)
    public String allEncounters(Model model) {
        List<Encounter> encounters = encounterService.getAllEncounters();
        model.addAttribute("encounters", encounters);

        return "encounters";
    }

    @RequestMapping(value = "/encounters", method = POST)
    public String searchEncounters(@ModelAttribute(value="searchFilter") SearchFilter searchFilter, Model model) {
        validationService.validateSearchFilter(searchFilter);
        // TODO react on validation error
        List<Encounter> encounters = encounterService.getEncounters(searchFilter);
        model.addAttribute("encounters", encounters);

        return "encounters";
    }

    @RequestMapping(value = "/encounters/{id}", method = GET)
    public String encounterById(@PathVariable("id") long id, Model model) {
        validationService.validateEncounterId(id);
        // TODO react on validation error

        Encounter encounter = encounterService.getEncounterById(id);
        model.addAttribute("encounter", encounter);

        return "user/encounterDetails";
    }
}
<commit_msg>Added methods to manipulate encounters<commit_after>/*
 * Copyright (C) 2015 <NAME>, <EMAIL>
 *
 * This file is part of the Application Intrusion Detection project.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package de.dominikschadow.duke.encounters.controllers;

import de.dominikschadow.duke.encounters.domain.Encounter;
import de.dominikschadow.duke.encounters.domain.SearchFilter;
import de.dominikschadow.duke.encounters.services.EncounterService;
import de.dominikschadow.duke.encounters.services.ValidationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

import static org.springframework.web.bind.annotation.RequestMethod.GET;
import static org.springframework.web.bind.annotation.RequestMethod.POST;

/**
 * Controller to handle all encounter related requests.
 */
@Controller
public class EncountersController {
    private EncounterService encounterService;
    private ValidationService validationService;

    @Autowired
    public EncountersController(EncounterService encounterService, ValidationService validationService) {
        this.encounterService = encounterService;
        this.validationService = validationService;
    }

    @RequestMapping(value = "/encounters", method = GET)
    public String allEncounters(Model model) {
        List<Encounter> encounters = encounterService.getAllEncounters();
        model.addAttribute("encounters", encounters);

        return "encounters";
    }

    @RequestMapping(value = "/encounters", method = POST)
    public String searchEncounters(@ModelAttribute(value="searchFilter") SearchFilter searchFilter, Model model) {
        validationService.validateSearchFilter(searchFilter);
        // TODO react on validation error
        List<Encounter> encounters = encounterService.getEncounters(searchFilter);
        model.addAttribute("encounters", encounters);

        return "encounters";
    }

    @RequestMapping(value = "/encounters/new", method = GET)
    public String newEncounter(Model model) {
        model.addAttribute("encounter", new Encounter());

        return "user/newEncounter";
    }

    @RequestMapping(value = "/encounters/delete", method = POST)
    public String deleteEncounter(Model model) {
        model.addAttribute("encounter", new Encounter());

        return "user/account";
    }

    @RequestMapping(value = "/encounters/{id}", method = GET)
    public String encounterById(@PathVariable("id") long id, Model model) {
        validationService.validateEncounterId(id);
        // TODO react on validation error

        Encounter encounter = encounterService.getEncounterById(id);
        model.addAttribute("encounter", encounter);

        return "user/encounterDetails";
    }
}

{'fraction_non_alphanumeric': 0.09073037955542114, 'fraction_numerical': 0.0024194767881445638, 'mean_word_length': 4.3554655870445345, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '265043', 'n_tokens_mistral': 1684, 'n_tokens_neox': 1688, 'n_words': 458}