Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    12.0p serverside Validators, serverObjects and reflection

    Hi Isomorphic,

    we are in the process of converting our repeatedly run jobs (Mail sending, Mail receiving and DB Jobs) from wget-Cronjobs to Quartz.
    This is working fine for Mail sending and DB Jobs, which are not doing many DSRequests.
    Mail receiving, which involves creating entries, has a lot of complex validators. Here we do have problems.

    Validator-Java classes can only have one validate()-method with a given parameter list (constructed with parameters from here), no overloading allowed. This is fine, if it wasn't for the 2nd problem (see after code example).
    Example:
    Code:
    package com.lmscompany.lms.server.worker.validator;
    
    import java.util.Map;
    
    import javax.servlet.http.HttpServletRequest;
    
    import com.isomorphic.datasource.DSRequest;
    import com.isomorphic.datasource.DataSource;
    import com.isomorphic.datasource.ValidationContext;
    import com.isomorphic.datasource.Validator;
    
    
    public class ValidatorSetStringToUppercase {
    
        public boolean condition(Object value, Validator validator, String fieldName, Map<Object, Object> record, DataSource ds,
                DSRequest request, HttpServletRequest httpServletRequest, ValidationContext validationContext) throws Exception {
            validationContext.setResultingValue((String) value != null ? value.toString().toUpperCase() : value);
            return true;
        }
    }
    Here a 2nd
    Code:
        public boolean condition(Object value, Validator validator, String fieldName, Map<Object, Object> record, DataSource ds,
                DSRequest request) throws Exception { ...
    is not allowed. Now in a non-servlet (=Quartz) use case in the 1st case an exception is thrown because the framework does not find data for HttpServletRequest and ValidationContext (as there are none).
    IMHO in this case the method should be called with null for these, perhaps a warning logged, but the method should be called and no Exception thrown.

    My code then has to handle the null (which might be easy for HttpServletRequest, which we only use to cache stuff in queues).
    Also it would be great if ValidationContext would work in the non-servlet case of StandaloneDataSourceUsage).

    The root problem also applies to ServerObject.lookupStyle of factory and
    Code:
    create(DSRequest dsRequest, HttpServletRequest httpServletRequest) throws Exception { ...
    , where the same exception is thrown because of the missing httpServletRequest

    Best regards
    Blama

    #2
    If the HttpServletRequest is not a required parameter, then we would recommend not declaring it as a parameter, and retrieving it instead via DSRequest.getHttpServletRequest().

    Comment


      #3
      Hi Isomorphic,

      yes that works. Although I don't understand why the call is not working. IMHO it should. This might not matter for HttpServletRequest, but it does for ValidationContext, where I can't get it otherwise. Is there a reason that ValidationContext does not work in the non-servlet case of StandaloneDataSourceUsage?

      Best regards
      Blama

      Comment

      Working...
      X