<commit_before>package org.intermine.web;

/*
 * Copyright (C) 2002-2005 FlyMine
 *
 * This code may be freely distributed and modified under the
 * terms of the GNU Lesser General Public Licence.  This should
 * be distributed with the code.  See the LICENSE file for more
 * information or http://www.gnu.org/copyleft/lesser.html.
 *
 */

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.intermine.objectstore.query.ConstraintOp;
import org.intermine.objectstore.query.Query;
import org.intermine.objectstore.query.Results;

import org.intermine.metadata.ClassDescriptor;
import org.intermine.metadata.Model;
import org.intermine.model.InterMineObject;
import org.intermine.objectstore.ObjectStore;
import org.intermine.util.TypeUtil;
import org.intermine.web.results.DisplayObject;
import org.intermine.web.results.InlineTemplateTable;

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

import org.apache.log4j.Logger;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.tiles.ComponentContext;
import org.apache.struts.tiles.actions.TilesAction;

/**
 * Controller for an inline table created by running a template on an object details page.
 * @author <NAME>
 */
public class ObjectDetailsTemplateController extends TilesAction
{
    private static final Logger LOG = Logger.getLogger(ObjectDetailsTemplateController.class);

    /**
     * @see TilesAction#execute(ComponentContext context, ActionMapping mapping, ActionForm form,
     *                          HttpServletRequest request, HttpServletResponse response) 
     */
    public ActionForward execute(ComponentContext context,
                                 ActionMapping mapping,
                                 ActionForm form,
                                 HttpServletRequest request,
                                 HttpServletResponse response)
        throws Exception {
        HttpSession session = request.getSession();
        ServletContext servletContext = session.getServletContext();
        ObjectStore os = (ObjectStore) servletContext.getAttribute(Constants.OBJECTSTORE);
        Map webProperties = (Map) servletContext.getAttribute(Constants.WEB_PROPERTIES);

        DisplayObject displayObject = (DisplayObject) context.getAttribute("displayObject");

        if (displayObject == null) {
            return null;
        }
        
        TemplateQuery  templateQuery = (TemplateQuery) context.getAttribute("templateQuery");        
        String templateName = templateQuery.getName();
        
        TemplateQuery template =
            TemplateHelper.findTemplate(session, templateName, TemplateHelper.ALL_TEMPLATE);

        if (template == null) {
            throw new IllegalStateException("Could not find template \"" 
                                            + templateName + "\"");
        }

        TemplateForm templateForm = new TemplateForm();
        int unconstrainedCount = 
            fillTemplateForm(template, displayObject.getObject(), templateForm, os.getModel());
        if (unconstrainedCount == 0) {
            templateForm.parseAttributeValues(template, session, new ActionErrors(), false);
            PathQuery pathQuery = TemplateHelper.templateFormToQuery(templateForm, template);
            try {
                Query query = MainHelper.makeQuery(pathQuery, Collections.EMPTY_MAP);<commit_msg>Checkstyle fix.<commit_after>package org.intermine.web;

/*
 * Copyright (C) 2002-2005 FlyMine
 *
 * This code may be freely distributed and modified under the
 * terms of the GNU Lesser General Public Licence.  This should
 * be distributed with the code.  See the LICENSE file for more
 * information or http://www.gnu.org/copyleft/lesser.html.
 *
 */

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.intermine.objectstore.query.ConstraintOp;
import org.intermine.objectstore.query.Query;
import org.intermine.objectstore.query.Results;

import org.intermine.metadata.ClassDescriptor;
import org.intermine.metadata.Model;
import org.intermine.model.InterMineObject;
import org.intermine.objectstore.ObjectStore;
import org.intermine.util.TypeUtil;
import org.intermine.web.results.DisplayObject;
import org.intermine.web.results.InlineTemplateTable;

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

import org.apache.log4j.Logger;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.tiles.ComponentContext;
import org.apache.struts.tiles.actions.TilesAction;

/**
 * Controller for an inline table created by running a template on an object details page.
 * @author <NAME>
 */
public class ObjectDetailsTemplateController extends TilesAction
{
    private static final Logger LOG = Logger.getLogger(ObjectDetailsTemplateController.class);

    /**
     * @see TilesAction#execute(ComponentContext context, ActionMapping mapping, ActionForm form,
     *                          HttpServletRequest request, HttpServletResponse response) 
     */
    public ActionForward execute(ComponentContext context,
                                 ActionMapping mapping,
                                 ActionForm form,
                                 HttpServletRequest request,
                                 HttpServletResponse response)
        throws Exception {
        HttpSession session = request.getSession();
        ServletContext servletContext = session.getServletContext();
        ObjectStore os = (ObjectStore) servletContext.getAttribute(Constants.OBJECTSTORE);
        Map webProperties = (Map) servletContext.getAttribute(Constants.WEB_PROPERTIES);

        DisplayObject displayObject = (DisplayObject) context.getAttribute("displayObject");

        if (displayObject == null) {
            return null;
        }
        
        TemplateQuery templateQuery = (TemplateQuery) context.getAttribute("templateQuery");        
        String templateName = templateQuery.getName();
        
        TemplateQuery template =
            TemplateHelper.findTemplate(session, templateName, TemplateHelper.ALL_TEMPLATE);

        if (template == null) {
            throw new IllegalStateException("Could not find template \"" 
                                            + templateName + "\"");
        }

        TemplateForm templateForm = new TemplateForm();
        int unconstrainedCount = 
            fillTemplateForm(template, displayObject.getObject(), templateForm, os.getModel());
        if (unconstrainedCount == 0) {
            templateForm.parseAttributeValues(template, session, new ActionErrors(), false);
            PathQuery pathQuery = TemplateHelper.templateFormToQuery(templateForm, template);
            try {
                Query query = MainHelper.makeQuery(pathQuery, Collections.EMPTY_MAP);
{'fraction_non_alphanumeric': 0.0835470373869618, 'fraction_numerical': 0.0026994196247806723, 'mean_word_length': 3.125835189309577, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6819058', 'n_tokens_mistral': 1832, 'n_tokens_neox': 1801, 'n_words': 434}