<commit_before>package codeine.servlets.api_servlets.angular;

import java.util.Map;

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

import org.apache.log4j.Logger;

import codeine.api.MonitorStatusInfo;
import codeine.api.NodeGetter;
import codeine.api.NodeInfo;
import codeine.api.NodeWithMonitorsInfo;
import codeine.configuration.IConfigurationManager;
import codeine.jsons.peer_status.PeerStatusJsonV2;
import codeine.jsons.peer_status.PeerStatusString;
import codeine.jsons.peer_status.ProjectStatus;
import codeine.jsons.project.ProjectJson;
import codeine.model.Constants;
import codeine.permissions.UserPermissionsGetter;
import codeine.servlet.AbstractApiServlet;

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

public class NodeStatusApiServlet extends AbstractApiServlet {

	private static final Logger log = Logger
			.getLogger(NodeStatusApiServlet.class);
	private static final long serialVersionUID = 1L;
	@Inject	private NodeGetter nodesGetter;
	@Inject	private IConfigurationManager configurationManager;
	@Inject	private UserPermissionsGetter userPermissionsGetter;
	
	@Override
	protected boolean checkPermissions(HttpServletRequest request) {
		return canReadProject(request);
	}
	
	@Override
	protected void myGet(HttpServletRequest request, HttpServletResponse response) {
		String projectName = request.getParameter(Constants.UrlParameters.PROJECT_NAME);
		String nodeName = request.getParameter(Constants.UrlParameters.NODE);
		NodeWithMonitorsInfo nodeByNameOrNull = nodesGetter.getNodeByNameOrNull(projectName, nodeName);
		NodeWithMonitorsInfoApi node = null;
		if (nodeByNameOrNull != null) {
			boolean can_command = (userPermissionsGetter.user(request).canCommand(projectName, nodeByNameOrNull.alias()));
			node = new NodeWithMonitorsInfoApi(nodeByNameOrNull, can_command);
		}
		else {
			ProjectJson projectJson = configurationManager.getProjectForName(projectName);
			for (NodeInfo nodeInfo : projectJson.nodes_info()) {
				Map<String, MonitorStatusInfo> monitors = Maps.newHashMap();
				ProjectStatus projectStatus = new ProjectStatus();
				PeerStatusJsonV2 peer = new PeerStatusJsonV2("", projectStatus);
				peer.status(PeerStatusString.Offline);
				NodeWithMonitorsInfoApi nodeStatusInfo = new NodeWithMonitorsInfoApi(new NodeWithMonitorsInfo(
						peer, nodeInfo.name(), nodeInfo.alias(), projectJson.name(), monitors), false);
				log.info("offline node " + nodeStatusInfo);
				node = nodeStatusInfo;
				break;
			}
		}
		if (null == node){
			throw new IllegalArgumentException("node not found " + nodeName);
		}
		writeResponseGzipJson(response, node);
	}

}<commit_msg>fixed wrong node<commit_after>package codeine.servlets.api_servlets.angular;

import java.util.Map;

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

import org.apache.log4j.Logger;

import codeine.api.MonitorStatusInfo;
import codeine.api.NodeGetter;
import codeine.api.NodeInfo;
import codeine.api.NodeWithMonitorsInfo;
import codeine.configuration.IConfigurationManager;
import codeine.jsons.peer_status.PeerStatusJsonV2;
import codeine.jsons.peer_status.PeerStatusString;
import codeine.jsons.peer_status.ProjectStatus;
import codeine.jsons.project.ProjectJson;
import codeine.model.Constants;
import codeine.permissions.UserPermissionsGetter;
import codeine.servlet.AbstractApiServlet;

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

public class NodeStatusApiServlet extends AbstractApiServlet {

	private static final Logger log = Logger
			.getLogger(NodeStatusApiServlet.class);
	private static final long serialVersionUID = 1L;
	@Inject	private NodeGetter nodesGetter;
	@Inject	private IConfigurationManager configurationManager;
	@Inject	private UserPermissionsGetter userPermissionsGetter;
	
	@Override
	protected boolean checkPermissions(HttpServletRequest request) {
		return canReadProject(request);
	}
	
	@Override
	protected void myGet(HttpServletRequest request, HttpServletResponse response) {
		String projectName = request.getParameter(Constants.UrlParameters.PROJECT_NAME);
		String nodeName = request.getParameter(Constants.UrlParameters.NODE);
		NodeWithMonitorsInfo nodeByNameOrNull = nodesGetter.getNodeByNameOrNull(projectName, nodeName);
		NodeWithMonitorsInfoApi node = null;
		if (nodeByNameOrNull != null) {
			boolean can_command = (userPermissionsGetter.user(request).canCommand(projectName, nodeByNameOrNull.alias()));
			node = new NodeWithMonitorsInfoApi(nodeByNameOrNull, can_command);
		}
		else {
			node = getNodeFromConfiguration(projectName, nodeName);
		}
		if (null == node){
			
		}
		writeResponseGzipJson(response, node);
	}

	private NodeWithMonitorsInfoApi getNodeFromConfiguration(String projectName, String nodeName) {
		ProjectJson projectJson = configurationManager.getProjectForName(projectName);
		for (NodeInfo nodeInfo : projectJson.nodes_info()) {
			if (nodeName.equals(nodeInfo.name())) {
				Map<String, MonitorStatusInfo> monitors = Maps.newHashMap();
				ProjectStatus projectStatus = new ProjectStatus();
				PeerStatusJsonV2 peer = new PeerStatusJsonV2("", projectStatus);
				peer.status(PeerStatusString.Offline);
				NodeWithMonitorsInfoApi nodeStatusInfo = new NodeWithMonitorsInfoApi(new NodeWithMonitorsInfo(
						peer, nodeInfo.name(), nodeInfo.alias(), projectJson.name(), monitors), false);
				log.info("offline node " + nodeStatusInfo);
				return nodeStatusInfo;
			}
		}
		throw new IllegalArgumentException("node not found " + nodeName);
	}

}
{'fraction_non_alphanumeric': 0.08661417322834646, 'fraction_numerical': 0.0017895490336435219, 'mean_word_length': 6.383091149273448, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1119201', 'n_tokens_mistral': 1677, 'n_tokens_neox': 1598, 'n_words': 324}