<commit_before>/* 
 * Copyright 2014 <NAME>
 *
 * 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 net.objecthunter.larch.controller;

import java.io.IOException;

import net.objecthunter.larch.helpers.AuditRecords;
import net.objecthunter.larch.service.AuditService;
import net.objecthunter.larch.service.EntityService;
import net.objecthunter.larch.service.MessagingService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
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.ResponseStatus;

/**
 * Web controller responsible for interactions on the identifier level
 */
@Controller
public class IdentifierController extends AbstractLarchController {
    @Autowired
    private EntityService entityService;

    @Autowired
    private AuditService auditService;

    @Autowired
    private MessagingService messagingService;

    /**
     * Controller method for adding a new identifier using a HTTP POST
     * 
     * @param id
     *            the id of the Entity to which the identifier is added
     * @param type
     *            the type of the identifier
     * @param value
     *            the value of the identifier
     * @throws IOException
     */
    @RequestMapping(value = "/entity/{id}/identifier", method = RequestMethod.POST)
    @ResponseStatus(HttpStatus.CREATED)
    public void create(@PathVariable("id")
    final String id, @RequestParam("type")
    final String type, @RequestParam("value")
    final String value) throws IOException {
        this.entityService.createIdentifier(id, type, value);
        this.auditService.create(AuditRecords.createIdentifier(id));
        this.messagingService.publishCreateIdentifier(id, type, value);
    }

    /**
     * Controller method for adding a new identifier using a HTTP POST that redirects to an HTML view of the
     * {@link net.objecthunter.larch.model.Entity}
     * 
     * @param id
     *            the id of the Entity to which the identifier is added
     * @param type
     *            the type of the identifier
     * @param value
     *            the value of the identifier
     * @throws IOException
     */
    @RequestMapping(value = "/entity/{id}/identifier", method = RequestMethod.POST, produces = "text/html")
    @ResponseStatus(HttpStatus.OK)
    public String createHtml(@PathVariable("id")
    final String id, @RequestParam("type")
    final String type, @RequestParam("value")
    final String value) throws IOException {
        this.entityService.createIdentifier(id, type, value);
        this.auditService.create(AuditRecords.createIdentifier(id));
        this.messagingService.publishCreateIdentifier(id, type, value);
        return "redirect:/entity/" + id;
    }
}<commit_msg>implement delete identifier<commit_after>/* 
 * Copyright 2014 <NAME>
 *
 * 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 net.objecthunter.larch.controller;

import java.io.IOException;

import net.objecthunter.larch.helpers.AuditRecords;
import net.objecthunter.larch.service.AuditService;
import net.objecthunter.larch.service.EntityService;
import net.objecthunter.larch.service.MessagingService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
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 org.springframework.web.bind.annotation.ResponseStatus;

/**
 * Web controller responsible for interactions on the identifier level
 */
@Controller
public class IdentifierController extends AbstractLarchController {
    @Autowired
    private EntityService entityService;

    @Autowired
    private AuditService auditService;

    @Autowired
    private MessagingService messagingService;

    /**
     * Controller method for adding a new identifier using a HTTP POST
     * 
     * @param entityId
     *            the id of the Entity to which the identifier is added
     * @param type
     *            the type of the identifier
     * @param value
     *            the value of the identifier
     * @throws IOException
     */
    @RequestMapping(value = "/entity/{id}/identifier", method = RequestMethod.POST)
    @ResponseStatus(HttpStatus.CREATED)
    public void create(@PathVariable("id")
    final String entityId, @RequestParam("type")
    final String type, @RequestParam("value")
    final String value) throws IOException {
        this.entityService.createIdentifier(entityId, type, value);
        this.auditService.create(AuditRecords.createIdentifier(entityId));
        this.messagingService.publishCreateIdentifier(entityId, type, value);
    }

    /**
     * Controller method for adding a new identifier using a HTTP POST that redirects to an HTML view of the
     * {@link net.objecthunter.larch.model.Entity}
     * 
     * @param entityId
     *            the id of the Entity to which the identifier is added
     * @param type
     *            the type of the identifier
     * @param value
     *            the value of the identifier
     * @throws IOException
     */
    @RequestMapping(value = "/entity/{id}/identifier", method = RequestMethod.POST, produces = "text/html")
    @ResponseStatus(HttpStatus.OK)
    public String createHtml(@PathVariable("id")
    final String entityId, @RequestParam("type")
    final String type, @RequestParam("value")
    final String value) throws IOException {
        this.entityService.createIdentifier(entityId, type, value);
        this.auditService.create(AuditRecords.createIdentifier(entityId));
        this.messagingService.publishCreateIdentifier(entityId, type, value);
        return "redirect:/entity/" + entityId;
    }

    /**
     * Controller method to delete an identifier
     *
     * @param entityId
     *            the entity's id
     * @param type
     *            the type of the identifier
     * @param value
     *            the value of the identifier
     * @throws IOException
     */
    @RequestMapping(value = "/entity/{id}/identifier/{type}/{value}", method = RequestMethod.DELETE)
    @ResponseStatus(HttpStatus.OK)
    @ResponseBody
    public void delete(@PathVariable("id")
    final String entityId, @PathVariable("type")
    final String type, @PathVariable("value")
    final String value) throws IOException {
        this.entityService.deleteIdentifier(entityId, type, value);
        this.auditService.create(AuditRecords.deleteEntityRecord(entityId));
        this.messagingService.publishDeleteIdentifier(entityId, type, value);
    }

    /**
     * Controller method to delete an identifier
     *
     * @param entityId
     *            the entity's id
     * @param type
     *            the type of the identifier
     * @param value
     *            the value of the identifier
     * @throws IOException
     */
    @RequestMapping(value = "/entity/{id}/identifier/{type}/{value}", method = RequestMethod.DELETE)
    @ResponseStatus(HttpStatus.OK)
    @ResponseBody
    public String deleteHtml(@PathVariable("id")
    final String entityId, @PathVariable("type")
    final String type, @PathVariable("value")
    final String value) throws IOException {
        this.entityService.deleteIdentifier(entityId, type, value);
        this.auditService.create(AuditRecords.deleteEntityRecord(entityId));
        this.messagingService.publishDeleteIdentifier(entityId, type, value);
        return "redirect:/entity/" + entityId;
    }

}
{'fraction_non_alphanumeric': 0.08933909000332116, 'fraction_numerical': 0.001771283073176132, 'mean_word_length': 3.3579353593825374, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '6724579', 'n_tokens_mistral': 2316, 'n_tokens_neox': 2286, 'n_words': 695}