<commit_before>	package com.athena.meerkat.controller.web.tomcat;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
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.ResponseBody;

import com.athena.meerkat.controller.MeerkatConstants;
import com.athena.meerkat.controller.web.common.code.CommonCodeHandler;
import com.athena.meerkat.controller.web.common.model.GridJsonResponse;
import com.athena.meerkat.controller.web.common.model.SimpleJsonResponse;
import com.athena.meerkat.controller.web.entities.CommonCode;
import com.athena.meerkat.controller.web.entities.TaskHistory;
import com.athena.meerkat.controller.web.entities.TomcatConfigFile;
import com.athena.meerkat.controller.web.entities.TomcatDomain;
import com.athena.meerkat.controller.web.entities.TomcatInstance;
import com.athena.meerkat.controller.web.tomcat.services.TaskHistoryService;
import com.athena.meerkat.controller.web.tomcat.services.TomcatConfigFileService;
import com.athena.meerkat.controller.web.tomcat.services.TomcatDomainService;
import com.athena.meerkat.controller.web.tomcat.services.TomcatInstanceService;

@Controller
@RequestMapping("/configfile")
public class TomcatConfigFileController {

	@Autowired
	private TomcatDomainService domainService;

	@Autowired
	private CommonCodeHandler commonHandler;

	@Autowired
	private TomcatInstanceService tomcatService;

	@Autowired
	private TomcatConfigFileService tomcatConfigFileService;

	@Autowired
	private TaskHistoryService taskService;

	@RequestMapping(value = "/save", method = RequestMethod.POST)
	public @ResponseBody SimpleJsonResponse saveConfigFile(SimpleJsonResponse json, String content, String confType, String objType, int id, int objId) {
		TomcatDomain td = null;
		TomcatInstance tcinst = null;
		TomcatConfigFile conf = new TomcatConfigFile();

		if (objType.equals(MeerkatConstants.OBJ_TYPE_DOMAIN)) {
			td = domainService.getDomain(objId);
			conf.setTomcatDomain(td);

		} else if (objType.equals(MeerkatConstants.OBJ_TYPE_TOMCAT)) {
			tcinst = tomcatService.findOne(objId);
			conf.setTomcatInstance(tcinst);
			conf.setTomcatDomain(tcinst.getTomcatDomain());//don't delete.
		}

		CommonCode code = commonHandler.getCode(confType);
		if (code != null) {
			conf.setFileTypeCdId(code.getId());
		}

		TomcatConfigFile latestVersion = tomcatConfigFileService.getLatestConfVersion(td, tcinst, conf.getFileTypeCdId());

		if (latestVersion != null) {
			conf.setVersion(latestVersion.getVersion() + 1);
		} else {
			conf.setVersion(1);
		}

		conf.setContent(content);
		if (td != null) {
			conf = tomcatConfigFileService.saveConfigXmlFile(conf, td.getDomainTomcatConfig());
		} else {
			conf = tomcatConfigFileService.saveConfigXmlFile(conf, tcinst.getTomcatDomain().getDomainTomcatConfig());
		}

		// create task
		TaskHistory task = taskService.createConfigXmlUpdateTask(conf.getTomcatDomain().getId(), conf.getFileTypeCdId());

		Map<String, Object> resultMap = new HashMap<String, Object>();
		resultMap.put("configFileId", conf.getId());
		resultMap.put("task", task);

		json.setData(resultMap);

		return json;<commit_msg>fix update context.xml editing on tomcat instance <commit_after>package com.athena.meerkat.controller.web.tomcat;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
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.ResponseBody;

import com.athena.meerkat.controller.MeerkatConstants;
import com.athena.meerkat.controller.web.common.code.CommonCodeHandler;
import com.athena.meerkat.controller.web.common.model.GridJsonResponse;
import com.athena.meerkat.controller.web.common.model.SimpleJsonResponse;
import com.athena.meerkat.controller.web.entities.CommonCode;
import com.athena.meerkat.controller.web.entities.TaskHistory;
import com.athena.meerkat.controller.web.entities.TomcatConfigFile;
import com.athena.meerkat.controller.web.entities.TomcatDomain;
import com.athena.meerkat.controller.web.entities.TomcatInstance;
import com.athena.meerkat.controller.web.provisioning.TomcatProvisioningService;
import com.athena.meerkat.controller.web.tomcat.services.TaskHistoryService;
import com.athena.meerkat.controller.web.tomcat.services.TomcatConfigFileService;
import com.athena.meerkat.controller.web.tomcat.services.TomcatDomainService;
import com.athena.meerkat.controller.web.tomcat.services.TomcatInstanceService;

@Controller
@RequestMapping("/configfile")
public class TomcatConfigFileController {

	@Autowired
	private TomcatDomainService domainService;

	@Autowired
	private CommonCodeHandler commonHandler;

	@Autowired
	private TomcatInstanceService tomcatService;

	@Autowired
	private TomcatConfigFileService tomcatConfigFileService;

	@Autowired
	private TomcatProvisioningService proviService;

	@Autowired
	private TaskHistoryService taskService;

	@RequestMapping(value = "/save", method = RequestMethod.POST)
	public @ResponseBody SimpleJsonResponse saveConfigFile(SimpleJsonResponse json, String content, String confType, String objType, int id, int objId) {
		TomcatDomain td = null;
		TomcatInstance tcinst = null;
		TomcatConfigFile conf = new TomcatConfigFile();

		if (objType.equals(MeerkatConstants.OBJ_TYPE_DOMAIN)) {
			td = domainService.getDomain(objId);
			conf.setTomcatDomain(td);

		} else if (objType.equals(MeerkatConstants.OBJ_TYPE_TOMCAT)) {
			tcinst = tomcatService.findOne(objId);
			conf.setTomcatInstance(tcinst);
			conf.setTomcatDomain(tcinst.getTomcatDomain());//don't delete.
		}

		CommonCode code = commonHandler.getCode(confType);
		if (code != null) {
			conf.setFileTypeCdId(code.getId());
		}

		TomcatConfigFile latestVersion = tomcatConfigFileService.getLatestConfVersion(td, tcinst, conf.getFileTypeCdId());

		if (latestVersion != null) {
			conf.setVersion(latestVersion.getVersion() + 1);
		} else {
			conf.setVersion(1);
		}

		conf.setContent(content);
		if (td != null) {
			conf = tomcatConfigFileService.saveConfigXmlFile(conf, td.getDomainTomcatConfig());
		} else {
			conf = tomcatConfigFileService.saveConfigXmlFile(conf, tcinst.getTomcatDomain().getDomainTomcatConfig());
		}

		// create task
		TaskHistory task = taskService.createConfigXmlUpdateTask(conf.getTomcatDomain().getId(), conf.getFileTypeCdId());
		if (td != null) {
			proviService.updateXml(td.getId(), conf.getId(), task.getId(), td.getTomcatInstances());
		} else if (tcinst != null) {
			proviService.updateXml(tcinst.getId(), conf.getId(), task.getId());
		}
		Map<String, Object> resultMap = new HashMap<String, Object>();
		resultMap.put("configFileId", conf.getId());
		resultMap.put("task", task);
		json.setData(resultMap);

		return json;
{'fraction_non_alphanumeric': 0.109720885466795, 'fraction_numerical': 0.0005499793757734085, 'mean_word_length': 6.230616302186879, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 1}, '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': '5222411', 'n_tokens_mistral': 2374, 'n_tokens_neox': 2290, 'n_words': 355}