<commit_before>package gov.va.escreening.dto.template;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonSubTypes.Type;

@JsonInclude(Include.NON_NULL)
@JsonTypeInfo(use=JsonTypeInfo.Id.NAME, include=JsonTypeInfo.As.PROPERTY, property="type")
@JsonSubTypes({ @Type(value = TemplateTextContent.class, name = "text"), 
	@Type(value = TemplateVariableContent.class, name = "var")
	})
@JsonIgnoreProperties(ignoreUnknown = true)
public abstract class TemplateBaseContent {
	
	public static String translate(String operand, TemplateBaseContent inLeft, TemplateBaseContent right)
	{
		
		
		if (inLeft instanceof TemplateTextContent)
		{
			try
			{
				Double.parseDouble(((TemplateTextContent)inLeft).getContent());
				return ((TemplateTextContent)inLeft).getContent();
			}
			catch(Exception e)
			{}
			return "\""+((TemplateTextContent)inLeft).getContent()+"\"";
		}
		
		TemplateVariableContent leftContent = (TemplateVariableContent) inLeft;
		
		TemplateAssessmentVariableDTO left = leftContent.getContent();
		
		String inStr = "var" + left.getId();
		
		String translatedVar = inStr;
		
		if (operand == null)
		{
			if (left.getTypeId()!=null && left.getTypeId() == 1 && (left.getMeasureTypeId() == 1 || left.getMeasureTypeId() == 2 || left.getMeasureTypeId() == 3))
				
			{
				if (right instanceof TemplateTextContent)
				{
					try
					{
						Double.parseDouble(((TemplateTextContent)right).getContent());
						translatedVar = "asNumber(getResponse("+inStr+", "+left.getMeasureTypeId()+"))";
					}
					catch(Exception e)
					{
						// right is not a number;
						translatedVar = "getResponse("+inStr+", "+left.getMeasureTypeId()+")";
					}
				}
				else
				{
					translatedVar = "getResponse("+inStr+", "+left.getMeasureTypeId()+")";
				}
				
				
			}
			else if (left.getTypeId()!=null && left.getTypeId() == 4 )
			{
				translatedVar =  "getFormulaValue("+inStr+")";
			}
			else if (left.getTypeId()!=null && left.getTypeId() == 3)
			{
				translatedVar =  "getCustomValue("+inStr+")";
			}
		}
		else if ("eq".equals(operand) || "neq".equals(operand) || 
				"lt".equals(operand) || "gt".equals(operand) || "lte".equals(operand) 
				|| "gte".equals(operand))
		{
			if (left.getMeasureId()!=null && left.getMeasureTypeId() == 1)			
			{
				if (right instanceof TemplateTextContent)
				{
					try
					{
						Double.parseDouble(((TemplateTextContent)right).getContent());
						translatedVar = "asNumber("+inStr+", "+left.getMeasureTypeId()+") != \"notset\" && asNumber("+inStr+", "+left.getMeasureTypeId()+")";
					}
					catch(Exception e)
					{
						// right is not a number;<commit_msg>t660: fix one var ftl generation problem.<commit_after>package gov.va.escreening.dto.template;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonSubTypes.Type;

@JsonInclude(Include.NON_NULL)
@JsonTypeInfo(use=JsonTypeInfo.Id.NAME, include=JsonTypeInfo.As.PROPERTY, property="type")
@JsonSubTypes({ @Type(value = TemplateTextContent.class, name = "text"), 
	@Type(value = TemplateVariableContent.class, name = "var")
	})
@JsonIgnoreProperties(ignoreUnknown = true)
public abstract class TemplateBaseContent {
	
	public static String translate(String operand, TemplateBaseContent inLeft, TemplateBaseContent right)
	{
		
		
		if (inLeft instanceof TemplateTextContent)
		{
			try
			{
				Double.parseDouble(((TemplateTextContent)inLeft).getContent());
				return ((TemplateTextContent)inLeft).getContent();
			}
			catch(Exception e)
			{}
			return "\""+((TemplateTextContent)inLeft).getContent()+"\"";
		}
		
		TemplateVariableContent leftContent = (TemplateVariableContent) inLeft;
		
		TemplateAssessmentVariableDTO left = leftContent.getContent();
		
		String inStr = "var" + left.getId();
		
		String translatedVar = inStr;
		
		if (operand == null)
		{
			if (left.getTypeId()!=null && left.getTypeId() == 1 && (left.getMeasureTypeId() == 1 || left.getMeasureTypeId() == 2 || left.getMeasureTypeId() == 3))
				
			{
				
				translatedVar = "getResponse("+inStr+", "+left.getMeasureTypeId()+")";
				
			}
			else if (left.getTypeId()!=null && left.getTypeId() == 4 )
			{
				translatedVar =  "getFormulaValue("+inStr+")";
			}
			else if (left.getTypeId()!=null && left.getTypeId() == 3)
			{
				translatedVar =  "getCustomValue("+inStr+")";
			}
		}
		else if ("eq".equals(operand) || "neq".equals(operand) || 
				"lt".equals(operand) || "gt".equals(operand) || "lte".equals(operand) 
				|| "gte".equals(operand))
		{
			if (left.getMeasureId()!=null && left.getMeasureTypeId() == 1)			
			{
				if (right instanceof TemplateTextContent)
				{
					try
					{
						Double.parseDouble(((TemplateTextContent)right).getContent());
						translatedVar = "asNumber("+inStr+", "+left.getMeasureTypeId()+") != \"notset\" && asNumber("+inStr+", "+left.getMeasureTypeId()+")";
					}
					catch(Exception e)
					{
						// right is not a number;
{'fraction_non_alphanumeric': 0.15661764705882353, 'fraction_numerical': 0.003125, 'mean_word_length': 4.162239089184061, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 12}, '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': '4631801', 'n_tokens_mistral': 2080, 'n_tokens_neox': 1693, 'n_words': 283}