<commit_before>/**
 * Copyright (c) 2012-2013, 2016 University of Stuttgart.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * and the Apache License 2.0 which both accompany this distribution,
 * and are available at http://www.eclipse.org/legal/epl-v10.html
 * and http://www.apache.org/licenses/LICENSE-2.0
 *
 * Contributors:
 *     <NAME> - initial API and implementation
 *     <NAME> - refined tag suport
 *******************************************************************************/
package org.eclipse.winery.repository.resources.tags;

import java.util.List;

import javax.ws.rs.Consumes;
import javax.ws.rs.FormParam;
import javax.ws.rs.POST;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import org.eclipse.winery.model.tosca.TTag;
import org.eclipse.winery.repository.resources._support.IPersistable;
import org.eclipse.winery.repository.resources._support.collections.CollectionsHelper;
import org.eclipse.winery.repository.resources._support.collections.withoutid.EntityWithoutIdCollectionResource;

import com.sun.jersey.api.view.Viewable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


public class TagsResource extends EntityWithoutIdCollectionResource<TagResource, TTag> {

	private static final Logger LOGGER = LoggerFactory.getLogger(TagsResource.class);

	public TagsResource(IPersistable res, List<TTag> list) {
		super(TagResource.class, TTag.class, list, res);
	}

	public Viewable getHTML() {
		return new Viewable("/jsp/tags/tags.jsp", this);
	}


	/**
	 * Adds an element using form-encoding
	 *
	 * This is necessary as TRequirementRef contains an IDREF and the XML
	 * snippet itself does not contain the target id
	 * @param name the optional name of the requirement
	 * @param value the reference to a requirement in the topology
	 */
	@POST
	@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
	public Response addNewElement(@FormParam("id") String id, @FormParam("name") String name,
			@FormParam("value") String value) {

		TTag tag = new TTag();

		tag.setName(name);
		tag.setValue(value);

		this.list.add(tag);
		return CollectionsHelper.persist(this.res, this, tag);
	}

}<commit_msg>Refine method comment<commit_after>/**
 * Copyright (c) 2012-2013, 2016 University of Stuttgart.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * and the Apache License 2.0 which both accompany this distribution,
 * and are available at http://www.eclipse.org/legal/epl-v10.html
 * and http://www.apache.org/licenses/LICENSE-2.0
 *
 * Contributors:
 *     <NAME> - initial API and implementation
 *     <NAME> - refined tag suport
 *******************************************************************************/
package org.eclipse.winery.repository.resources.tags;

import java.util.List;

import javax.ws.rs.Consumes;
import javax.ws.rs.FormParam;
import javax.ws.rs.POST;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import org.eclipse.winery.model.tosca.TTag;
import org.eclipse.winery.repository.resources._support.IPersistable;
import org.eclipse.winery.repository.resources._support.collections.CollectionsHelper;
import org.eclipse.winery.repository.resources._support.collections.withoutid.EntityWithoutIdCollectionResource;

import com.sun.jersey.api.view.Viewable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


public class TagsResource extends EntityWithoutIdCollectionResource<TagResource, TTag> {

	private static final Logger LOGGER = LoggerFactory.getLogger(TagsResource.class);

	public TagsResource(IPersistable res, List<TTag> list) {
		super(TagResource.class, TTag.class, list, res);
	}

	public Viewable getHTML() {
		return new Viewable("/jsp/tags/tags.jsp", this);
	}


	/**
	 * Adds an element using form-encoding
	 *
	 * FIXME: This is necessary as TRequirementRef contains an IDREF and the XML snippet itself does not contain the target id
	 *
	 * TODO: Why can't just addNewElement be used? Why do we need form-based updates?
	 *
	 * @param id ignored (TODO - see above - addNewElement?)
	 * @param name the  name of the tag
	 * @param value the value of the tag
	 */
	@POST
	@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
	public Response addNewElement(
			@FormParam("id") String id,
			@FormParam("name") String name,
			@FormParam("value") String value) {

		TTag tag = new TTag();

		tag.setName(name);
		tag.setValue(value);

		this.list.add(tag);
		return CollectionsHelper.persist(this.res, this, tag);
	}

}
{'fraction_non_alphanumeric': 0.13570658036677455, 'fraction_numerical': 0.009492988133764833, 'mean_word_length': 4.70935960591133, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '2567759', 'n_tokens_mistral': 1455, 'n_tokens_neox': 1361, 'n_words': 376}