<commit_before>package gov.nih.nci.calab.ui.protocol;

import gov.nih.nci.calab.dto.common.ProtocolFileBean;
import gov.nih.nci.calab.exception.CaNanoLabException;
import gov.nih.nci.calab.exception.CaNanoLabSecurityException;
import gov.nih.nci.calab.exception.ParticleCharacterizationException;
import gov.nih.nci.calab.exception.ProtocolException;
import gov.nih.nci.calab.service.common.LookupService;
import gov.nih.nci.calab.service.particle.NanoparticleCharacterizationService;
import gov.nih.nci.calab.service.protocol.SearchProtocolService;
import gov.nih.nci.calab.service.util.CaNanoLabConstants;

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

import javax.servlet.http.HttpSession;

/**
 * This class sets up session level or servlet context level variables to be
 * used in various actions during the setup of query forms.
 * 
 * @author pansu
 * 
 */
public class InitProtocolSetup {
	private static SearchProtocolService searchProtocolService;

	private InitProtocolSetup() throws CaNanoLabSecurityException {
		searchProtocolService = new SearchProtocolService();
	}

	public static InitProtocolSetup getInstance()
			throws CaNanoLabSecurityException {
		return new InitProtocolSetup();
	}

	public void setAllProtocolTypes(HttpSession session)
			throws CaNanoLabException {
		SortedSet<String> protocolTypes = LookupService
				.getAllLookupTypes("ProtocolType");
		session.setAttribute("protocolTypes", protocolTypes);
	}

	public void setProtocolFilesByCharName(HttpSession session, String charName)
			throws ParticleCharacterizationException,
			CaNanoLabSecurityException, ProtocolException {
		Map<String, String> charNameToCharCategory = null;
		// retrieve from application context if there
		if (session.getServletContext().getAttribute(
				"characterizationCategoryMap") == null) {
			NanoparticleCharacterizationService charService = new NanoparticleCharacterizationService();
			charNameToCharCategory = charService
					.getCharacterizationCategoryMap();
			session.getServletContext().setAttribute(
					"characterizationCategoryMap", charNameToCharCategory);
		} else {
			charNameToCharCategory = new HashMap<String, String>(
					(Map<? extends String, String>) session.getServletContext()
							.getAttribute("characterizationCategoryMap"));
		}
		String protocolType = null;
		String category = charNameToCharCategory.get(charName);
		if (category != null
				&& category
						.equals(CaNanoLabConstants.PHYSICAL_CHARACTERIZATION_CATEGORY)) {
			protocolType = CaNanoLabConstants.PHYSICAL_ASSAY_PROTOCOL;
		} else {
			// get the top level category
			String nextCategory = null;
			while (category != null) {
				nextCategory = category;
				category = charNameToCharCategory.get(nextCategory);
			}
			if (nextCategory
					.equals(CaNanoLabConstants.IN_VITRO_CHARACTERIZATION_CATEGORY)) {
				protocolType = CaNanoLabConstants.INVITRO_ASSAY_PROTOCOL;
			} else {
				protocolType = null; // update if in vivo is implemented
			}
		}<commit_msg>updated to use setProtocolFilesByCharType<commit_after>package gov.nih.nci.calab.ui.protocol;

import gov.nih.nci.calab.domain.nano.characterization.Characterization;
import gov.nih.nci.calab.dto.common.ProtocolFileBean;
import gov.nih.nci.calab.exception.CaNanoLabException;
import gov.nih.nci.calab.exception.CaNanoLabSecurityException;
import gov.nih.nci.calab.exception.ParticleCharacterizationException;
import gov.nih.nci.calab.exception.ProtocolException;
import gov.nih.nci.calab.service.common.LookupService;
import gov.nih.nci.calab.service.protocol.SearchProtocolService;
import gov.nih.nci.calab.service.util.CaNanoLabConstants;

import java.util.List;
import java.util.SortedSet;

import javax.servlet.http.HttpSession;

/**
 * This class sets up session level or servlet context level variables to be
 * used in various actions during the setup of query forms.
 * 
 * @author pansu
 * 
 */
public class InitProtocolSetup {
	private static SearchProtocolService searchProtocolService;

	private InitProtocolSetup() throws CaNanoLabSecurityException {
		searchProtocolService = new SearchProtocolService();
	}

	public static InitProtocolSetup getInstance()
			throws CaNanoLabSecurityException {
		return new InitProtocolSetup();
	}

	public void setAllProtocolTypes(HttpSession session)
			throws CaNanoLabException {
		if (session.getAttribute("protocolTypes") == null
				|| session.getAttribute("newProtocolCreated") != null) {
			SortedSet<String> protocolTypes = LookupService
					.getAllLookupTypes("ProtocolType");
			session.setAttribute("protocolTypes", protocolTypes);
		}
		session.removeAttribute("newProtocolCreated");
	}

	public void setProtocolFilesByCharType(HttpSession session, String charType)
			throws ParticleCharacterizationException,
			CaNanoLabSecurityException, ProtocolException {
		String protocolType = null;
		if (charType != null
				&& charType
						.equalsIgnoreCase(Characterization.PHYSICAL_CHARACTERIZATION)) {
			protocolType = CaNanoLabConstants.PHYSICAL_ASSAY_PROTOCOL;
		} else if (charType != null
				&& charType
						.equalsIgnoreCase(Characterization.INVITRO_CHARACTERIZATION)) {
			protocolType = CaNanoLabConstants.INVITRO_ASSAY_PROTOCOL;
		} else {
			protocolType = null; // update if in vivo is implemented
		}
{'fraction_non_alphanumeric': 0.08609022556390977, 'fraction_numerical': 0.0, 'mean_word_length': 5.426328502415459, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, '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': '4040585', 'n_tokens_mistral': 1730, 'n_tokens_neox': 1549, 'n_words': 310}