<commit_before>package cloudstack.reporting

import org.springframework.dao.DataIntegrityViolationException
import org.apache.commons.logging.LogFactory
import org.hibernate.criterion.CriteriaSpecification
import org.hibernate.type.Type
import org.hibernate.criterion.Projections
import org.hibernate.Hibernate
import org.hibernate.criterion.Restrictions
import grails.converters.JSON

class TemplateController {
    private static final log = LogFactory.getLog(this)

    static allowedMethods = [save: "POST", update: "POST", delete: "POST"]

    def index() {
        redirect(action: "list", params: params)
    }


    def validTemplateAJAX() {
        def found
        if (params.templateText == null || Template.findByName(params.templateText) != null) {
            found = "true"
        } else {
            found = "false"
        }
        render found
    }
    
    def templateListAJAX() {
        def templates = Template.findAllByIspublicAndReadyAndNameLike(true, true, "%${params.term}%")

        render templates.collect { it.name } as JSON
    }
     
    def list(Integer max) {
        params.max = Math.min(max ?: 10, 100)
        def sortTok = params.sort ?: "name"
        def orderTok = params.order ?: "asc"

        def latestReportRun = ReportRun.withCriteria {
            geAll("dateCreated", {
                      projections {
                          property "dateCreated"
                      }
                      eq("completed", true)
                  })
        }[0]

        def templateInstanceTotal = Template.count()
        log.warn("latestReportRun.dateCreated: ${latestReportRun.dateCreated}")

        def rawTemplateList = Template.withCriteria() { 
            getInstance().createAlias("instances", "i", CriteriaSpecification.LEFT_JOIN, Restrictions.and(
                                          Restrictions.ge("i.lastUpdated", latestReportRun.dateCreated),
                                          Restrictions.ne("i.state", "Destroyed")))<commit_msg>Spit out template validation ajax as json, for sure<commit_after>package cloudstack.reporting

import org.springframework.dao.DataIntegrityViolationException
import org.apache.commons.logging.LogFactory
import org.hibernate.criterion.CriteriaSpecification
import org.hibernate.type.Type
import org.hibernate.criterion.Projections
import org.hibernate.Hibernate
import org.hibernate.criterion.Restrictions
import grails.converters.JSON

class TemplateController {
    private static final log = LogFactory.getLog(this)

    static allowedMethods = [save: "POST", update: "POST", delete: "POST"]

    def index() {
        redirect(action: "list", params: params)
    }


    def validTemplateAJAX() {
        def found
        if (params.templateText == null || Template.findByName(params.templateText) != null) {
            found = "true"
        } else {
            found = "false"
        }
        response.setContentType("text/json;charset=UTF-8");

        render found  
    }
    
    def templateListAJAX() {
        def templates = Template.findAllByIspublicAndReadyAndNameLike(true, true, "%${params.term}%")

        render templates.collect { it.name } as JSON
    }
     
    def list(Integer max) {
        params.max = Math.min(max ?: 10, 100)
        def sortTok = params.sort ?: "name"
        def orderTok = params.order ?: "asc"

        def latestReportRun = ReportRun.withCriteria {
            geAll("dateCreated", {
                      projections {
                          property "dateCreated"
                      }
                      eq("completed", true)
                  })
        }[0]

        def templateInstanceTotal = Template.count()
        log.warn("latestReportRun.dateCreated: ${latestReportRun.dateCreated}")

        def rawTemplateList = Template.withCriteria() { 
            getInstance().createAlias("instances", "i", CriteriaSpecification.LEFT_JOIN, Restrictions.and(
                                          Restrictions.ge("i.lastUpdated", latestReportRun.dateCreated),
                                          Restrictions.ne("i.state", "Destroyed")))
{'fraction_non_alphanumeric': 0.10196173407604747, 'fraction_numerical': 0.0031484620973601355, 'mean_word_length': 2.2570977917981074, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7392690', 'n_tokens_mistral': 1123, 'n_tokens_neox': 1055, 'n_words': 224}