<commit_before>package codeine.servlets.api_servlets;

import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

import codeine.api.NodeGetter;
import codeine.api.NodeInfo;
import codeine.api.NodeWithMonitorsInfo;
import codeine.configuration.IConfigurationManager;
import codeine.jsons.nodes.NodeDiscoveryStrategy;
import codeine.jsons.project.ProjectJson;
import codeine.model.Constants;
import codeine.servlet.AbstractServlet;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.inject.Inject;

public class ProjectTagsApiServlet extends AbstractServlet {

	private static final long serialVersionUID = 1L;
	private static final Logger log = Logger.getLogger(ProjectTagsApiServlet.class);
	@Inject	private IConfigurationManager configurationManager;
	@Inject	private NodeGetter nodesGetter;
	
	@Override
	protected void myGet(HttpServletRequest request, HttpServletResponse response) {
		String projectName = request.getParameter(Constants.UrlParameters.PROJECT_NAME);
		
		ProjectJson project = configurationManager.getProjectForName(projectName);
		Map<String,Integer> map = Maps.newHashMap();
		
		if (project.node_discovery_startegy() == NodeDiscoveryStrategy.Configuration && !projectName.equals(Constants.CODEINE_NODES_PROJECT_NAME)) {
			log.info("getting static tags");
			for (NodeInfo node : project.nodes_info()) {
				updateMapWithNode(map, node);
			}
		}
		else {
			List<NodeWithMonitorsInfo> nodes = nodesGetter.getNodes(projectName);
			for (NodeWithMonitorsInfo nodeWithMonitorsInfo : nodes) {
				updateMapWithNode(map, nodeWithMonitorsInfo);
			}
		}
		List<NodeTag> list = Lists.newArrayList();
		for (Entry<String, Integer> e : map.entrySet()) {
			list.add(new NodeTag(e.getKey(), e.getValue()));
		}
<<<<<<< HEAD
		
		Comparator<NodeTag> c = new Comparator<NodeTag>() {
			@Override
			public int compare(NodeTag o1, NodeTag o2) {
				return o1.name().compareTo(o2.name());
			}
		};
		Collections.sort(list, c);
		
=======
		Comparator<NodeTag> c = new Comparator<ProjectTagsApiServlet.NodeTag>() {
			@Override
			public int compare(NodeTag o1, NodeTag o2) {
				return o1.name.compareTo(o2.name);
			}
		};
		Collections.sort(list, c);
>>>>>>> 9716273398c7ef5aed402a501e8782b29cff78ce
		writeResponseJson(response, list);
	}


	public void updateMapWithNode(Map<String, Integer> map, NodeInfo node) {
		if (node.tags() == null) {
			return;
		}
		for (String tag : node.tags()) {
			if (!map.containsKey(tag)) {
				map.put(tag, 1);
			} else {<commit_msg>fixed build<commit_after>package codeine.servlets.api_servlets;

import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

import codeine.api.NodeGetter;
import codeine.api.NodeInfo;
import codeine.api.NodeWithMonitorsInfo;
import codeine.configuration.IConfigurationManager;
import codeine.jsons.nodes.NodeDiscoveryStrategy;
import codeine.jsons.project.ProjectJson;
import codeine.model.Constants;
import codeine.servlet.AbstractServlet;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.inject.Inject;

public class ProjectTagsApiServlet extends AbstractServlet {

	private static final long serialVersionUID = 1L;
	private static final Logger log = Logger.getLogger(ProjectTagsApiServlet.class);
	@Inject	private IConfigurationManager configurationManager;
	@Inject	private NodeGetter nodesGetter;
	
	@Override
	protected void myGet(HttpServletRequest request, HttpServletResponse response) {
		String projectName = request.getParameter(Constants.UrlParameters.PROJECT_NAME);
		
		ProjectJson project = configurationManager.getProjectForName(projectName);
		Map<String,Integer> map = Maps.newHashMap();
		
		if (project.node_discovery_startegy() == NodeDiscoveryStrategy.Configuration && !projectName.equals(Constants.CODEINE_NODES_PROJECT_NAME)) {
			log.info("getting static tags");
			for (NodeInfo node : project.nodes_info()) {
				updateMapWithNode(map, node);
			}
		}
		else {
			List<NodeWithMonitorsInfo> nodes = nodesGetter.getNodes(projectName);
			for (NodeWithMonitorsInfo nodeWithMonitorsInfo : nodes) {
				updateMapWithNode(map, nodeWithMonitorsInfo);
			}
		}
		List<NodeTag> list = Lists.newArrayList();
		for (Entry<String, Integer> e : map.entrySet()) {
			list.add(new NodeTag(e.getKey(), e.getValue()));
		}
		
		Comparator<NodeTag> c = new Comparator<NodeTag>() {
			@Override
			public int compare(NodeTag o1, NodeTag o2) {
				return o1.name().compareTo(o2.name());
			}
		};
		Collections.sort(list, c);
	
		writeResponseJson(response, list);
	}


	public void updateMapWithNode(Map<String, Integer> map, NodeInfo node) {
		if (node.tags() == null) {
			return;
		}
		for (String tag : node.tags()) {
			if (!map.containsKey(tag)) {
				map.put(tag, 1);
			} else {
{'fraction_non_alphanumeric': 0.1137065637065637, 'fraction_numerical': 0.008494208494208495, 'mean_word_length': 5.272397094430993, 'pattern_counts': {'":': 0, '<': 26, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '7489129', 'n_tokens_mistral': 1762, 'n_tokens_neox': 1611, 'n_words': 322}