package com.amway.validation; import java.util.*; import org.apache.log4j.Logger; import org.aspectj.lang.*; import org.apache.commons.validator.ValidatorException; import com.amway.model.*; import com.amway.service.*; import com.amway.exception.*; import com.amway.resource.Message; /** * Validate IBO in business service delegate (SOA interface for web services). * * @author David Wong */ public aspect IboValidationAspect { static Logger log = Logger.getLogger("trace"); /** * Validate an IBO before persistent operations on it. * Since the project is for an RIA client, any failed validation checks are considered * an error since they should have been caught by the client validation first. Validation * errors are logged instead of sent to the client. * * Therefore the client and server validations should be kept in sync. * * If there is a change to a HTML based client (where javascript validation can be turned * off) then the logic here should be changed to return validation error messages to the * client. * * @author David Wong */ void around(AgsServiceDelegate del, Ibo ibo) throws AgsException : execution(public * AgsServiceDelegate.*(Ibo)) && !execution(* AgsServiceDelegate+.handle*(..)) && target(del) && args(ibo) { if (ibo == null) { // should really be IllegalArgumentException, except the joinpoint is at the component interface // so we throw a business exception throw new AgsException(Message.message("error.validation.missing")); } log.debug("About validate IBO for " + thisJoinPointStaticPart.getSignature().getName() + " with IBO " + ibo.getIboNumber()); try { // validate the IBO IboValidator validator = new IboValidator(); List errors = new ArrayList(); boolean valid = validator.validate(ibo, errors); if (valid) { proceed(del, ibo); } else { // create error msg String domainDescriptor = Message.message("Ibo.descriptor"); Object[] args = {domainDescriptor}; String msg = Message.message("error.validation.fail", args); // log the validation errors log.error(msg + ":"); for (Iterator iter = errors.iterator(); iter.hasNext(); ) { log.error(iter.next()); } // throw exception to indicate failed validation throw new AgsException(msg); } } catch (ValidatorException ve) { log.error(ve); throw new AgsException(ve); } } }