All Downloads are FREE. Search and download functionalities are using the official Maven repository.

mplates.1.2.source-code.ModelViewService.ftl Maven / Gradle / Ivy

<#include "license.ftl">
<@license/>
package ${doc.all.package}.service;

import redora.util.JSONWriter;

/**
* @author Redora (www.redora.net)
*/
public class ModelViewService {

    public static void getModelNames(JSONWriter writer) {
        writer.print('[');
        char comma = ' ';
        for (String object : Upgrade.objects) {
            writer.print(comma); comma = ',';
            writer.print('{');
            writer.quoted("objectName", object);
            writer.print('}');
        }
        writer.print(']');
    }

    public static void getModelFields(String modelName, JSONWriter writer){
        writer.print('{');
        writer.key("field");
        writer.print('[');
<#list doc["/all/object"] as model>
        if (modelName.equalsIgnoreCase("${model.@name}")) {
    <#assign n = 0 />
        <#list model.attributes?children as att>
            <#if att?node_type == "element">
                <#if att?node_name == "long" && att.@parentClass[0]??>
                <#else>
                    <#assign n = n+1 />
                    <#if n gt 1>
            writer.print(',');
                    
            //add field_name
            writer.print('{');
            writer.key("field_name");
                    <#if att?node_name != "set" && att?node_name != "object">
            writer.quoteValue("${att.@name[0]!att.@class?uncap_first}");
                    <#elseif att?node_name == "set">
            writer.quoteValue("${att.@plural}");
                    <#elseif att?node_name == "object">
            writer.quoteValue("${att.@name[0]!att.@class?uncap_first}");
                    
            writer.print(',');

            //add field_type 	
            writer.quoted("field_type", "${att?node_name}");
            writer.print(',');

            //add not_null attribute	
            writer.kvp("not_null", "${att.@notnull!"false"}");
            writer.print(',');

            //add default attribute
                <#if att.@default[0]??>
            writer.kvp("default","${att.@default}");
            writer.print(',');
                

            //add regexp attribute
                <#if att.@regexp[0]??>
            writer.kvp("regexp", "${att.@regexp}");
            writer.print(',');
                

            //add maxlength attribute				
                <#if att.@maxlength[0]??>
            writer.kvp("maxlength", "${att.@maxlength}");
            writer.print(',');
                

            //add finder attribute
            writer.kvp("finder", "<#if att.finder[0]??>true<#else>false");
            writer.print(',');

            //add lazy attribute
            writer.kvp("lazy", "${att.@lazy!"false"}");
            writer.print(',');

            //add list attribute
            writer.kvp("list", "${att.@list!"false"}");
            writer.print('}');
            
        
        
            }
    
        writer.print("],");

        writer.key("businessRule");
        writer.print('[');
    <#list doc["/all/object"] as model>
        if(modelName.equalsIgnoreCase("${model.@name}")){
        <#if model.businessRules[0]??>
            <#list model.businessRules.businessRule as att>
            writer.print('{');
            writer.kvp("number", "${att.@number}");
            writer.print(',');
            writer.kvp("javadoc", "${att.@javadoc}");
            writer.print(',');
            writer.key("attributes");
                <#if att.@attributes[0]??>
            writer.quoteValue("${att.@attributes}");
                <#else>
            writer.nullOut();
                
            writer.print('}');
                <#if att_has_next>
            writer.print(',');
                
            
        
        }
    
        writer.print("]}");
    }

    public static void getFindFields(String modelName, JSONWriter writer){
    //TODO check this where it is used
        writer.print('[');
<#list doc["/all/object"] as model>
        if (modelName.equalsIgnoreCase("${model.@name}")) {
    <#assign n = 0 />
    <#list model.attributes?children as att>
        <#if att.finder[0]??>
            <#assign n = n+1 />
            <#if n gt 1>
            writer.print(',');
        
            writer.print('{');
            writer.kvp("finder_field_name", "${att.@fieldName}");
            writer.print(',');
            writer.kvp("finder_field_method", "findBy${att.@fieldName?cap_first}");
            writer.print('}');
        
    
        }

        writer.print(']');
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy