I have following command object with constraints :
@Validateable
class RefundCommand{
private static final Logger log = Logger.getLogger(RefundCommand.class)
Double amount
String order_id
MerchantAccount merchant
OrderReference order
String unique_request_id
public void getDerivedValues() {
this.order = OrderReference.findByOrderIdAndMerchantId(order_id, merchant.merchantId)
}
static constraints = {
amount nullable: false, validator: {amount, cmd->
if(cmd.amount <= 0) {
log.info("Amount must be greater than 0. Given value: ${cmd.amount}")
return ['invalid.amount']
}
}
}
}
Initiating an object in following way inside a controller:
def refund = {RefundCommand cmd->
def String orderId = params.orderId
def String merchantId = params.merchant.merchantId
def Double amount = params.amount.toDouble()
OrderReference orderReference = OrderReference.findByOrderIdAndMerchantId(orderId, merchantId)
MerchantAccount merchantAccount = MerchantAccount.findByMerchantId(merchantId)
cmd.order_id = orderId
cmd.merchant = merchantAccount
cmd.order = orderReference
cmd.amount = amount
cmd.unique_request_id = "rf_" + util.generateUniqueReference()
cmd.clearErrors()
cmd.validate()
log.info(cmd.dump())
if(cmd.hasErrors()) {
.....
return
}
proceedForRefund()
}
When I deploy initially validations are not working, validate() always return true and hasError() return null.
As we are using nginx, if I make any change in RefundCommand file then after auto-compile validation start working.
What could be the reason for that?
we are using grails-2.2.2 with nginx server.