
package edu.wustl.query.action;

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

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import edu.common.dynamicextensions.domain.Entity;
import edu.wustl.cab2b.server.cache.EntityCache;
import edu.wustl.query.actionForm.CategorySearchForm;
import edu.wustl.query.htmlprovider.GenerateHTMLDetails;
import edu.wustl.query.htmlprovider.HtmlProvider;
import edu.wustl.query.util.global.Constants;

/**
 * When the Link representing the searched entity is clicked, the UI for Add Limits section is generated with help of
 * GenerateHtmlForAddLimitsBizLogic. The entity is taken from a map of user searched entities is already strored in session. 
 * @author deepti_shelar
 *
 */
public class LoadDefineSearchRulesAction extends Action
{

	/**
	 * This method loads the html for addlimits section.This html is the replaced with the div data with the help of Ajax script.
	 * @param mapping mapping
	 * @param form form
	 * @param request request
	 * @param response response
	 * @throws Exception Exception
	 * @return ActionForward actionForward
	 */
	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) throws Exception
	{
		CategorySearchForm searchForm = (CategorySearchForm) form;
		String entityName = searchForm.getEntityName();

		GenerateHTMLDetails generateHTMLDetails = new GenerateHTMLDetails();
		generateHTMLDetails.setSearchString(searchForm.getTextField());
		generateHTMLDetails.setAttributeChecked(Boolean.valueOf(searchForm.getAttributeChecked()));
		generateHTMLDetails.setPermissibleValuesChecked(Boolean.valueOf(searchForm
				.getPermissibleValuesChecked()));

		HtmlProvider addLimitsBizLogic = new HtmlProvider(
				generateHTMLDetails);

		String html = "";
		/*	Map searchedEntitiesMap = (Map) request.getSession().getAttribute(Constants.SEARCHED_ENTITIES_MAP);
			if (searchedEntitiesMap != null)
			{
		*/Entity entity = (Entity) EntityCache.getCache().getEntityById(Long.valueOf((entityName)));
		if (entity != null)
		{
			html = addLimitsBizLogic.generateHTML(entity, null);
		}
		//	}
		response.setContentType(Constants.CONTENT_TYPE_TEXT);
		response.getWriter().write(html);
		return null;
	}

}

@@ -1945,33 +1945,28 @@
 rovider 
-addLimitsBizLogic
+htmlProvider
  = new H
@@ -1977,22 +1977,16 @@
 rovider(
-%0D%0A%09%09%09%09
 generate
@@ -2268,16 +2268,20 @@
 me)));%0D%0A
+%09%09%0D%0A
 %09%09if (en
@@ -2314,25 +2314,20 @@
 l = 
-addLimitsBizLogic
+htmlProvider
 .gen
@@ -2352,23 +2352,233 @@
 null
-);%0D%0A%09%09%7D%0D%0A%09%09//%09%7D
+,generateHTMLDetails);%0D%0A%09%09%7D%0D%0A%09%09//%09%7D%0D%0A%09%09request.getSession().setAttribute(Constants.ENUMRATED_ATTRIBUTE, generateHTMLDetails.getEnumratedAttributeMap());%0D%0A%09%09request.getSession().setAttribute(Constants.ENTITY_NAME, entityName);
 %0D%0A%09%09

Set few attributes in session for Vocabulary Interface