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

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

<#assign object = doc.object>
package ${object.@package}.businessrules;

import redora.service.BusinessRuleViolation;
import ${object.@package}.businessrules.base.${object.@name}BusinessRulesBase;

/**
* Custom business rule implementations go here. For a business rule you must first define it
* in the object model (see the manual).
* This will look something like this.

    <businessRules>
        <businessRule number="1" javadoc="Only updates at night are allowed." attributes="myNaughtyField">
            <message language="en">You are too early, come back at {0}</message>
        </businessRule>
    </businessRules>

* The generator will generate a ruleId handle on ${object.@name}BusinessRulesBase that you can use like:
* 
* ${object.@name}BusinessRules.BR_[number]
* 
* This can be used to add a new BusinessRuleViolation. For example like this:
* 
  new BusinessRuleViolation(${object.@name}
        , ${object.@name}Fields.myNaughtyField
        , ${object.@name}BusinessRules.BR_1
        , BusinessRuleViolation.Action.Update));
* 
* As you can see the BusinessRuleViolation object makes it possible to pinpoint the
* violated rule to the end user. In the object model you can set messages (with parameters)
* in any of the languages you want to support. The ruleId handle, ${object.@name}BusinessRules.BR_1
* in this example will point to the message you have define in the model. The generator also has
* created a message object for each language you have defined in the model.
* You can use ${object.@name}BusinessRules by invoking the static check() method. This method will check * business rule violations on ${object.@name} and any related parents and children. You can also use * the onXXX methods to check the violations on only this ${object.@name}. * @see BusinessRuleViolation * @author Redora (www.redora.net) */ public class ${object.@name}BusinessRules extends ${object.@name}BusinessRulesBase { /* * Example @NotNull public static Set onUpdate(@NotNull ${object.@name} pojo) throws BusinessRuleViolationException { Set retVal = ${object.@name}BusinessRulesBase.onUpdate(pojo); //for example check if the updateDate is newer then the last updateDate if (pojo.dirty.containsKey(${object.@name}Fields.updateDate) { if (pojo.dirty.get(${object.@name}Fields.updateDate) != null && pojo.dirty.get(${object.@name}Fields.updateDate).compareTo(pojo.getUpdateDate() > 0) { retVal.add(new BusinessRuleViolation( ${object.@name}, ${object.@name}Fields.updateDate, BR_1, Action.Update)); } } return retVal; } */ }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy