[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Request Validations

Posted on 2004-10-27
4
Medium Priority
?
217 Views
Last Modified: 2010-04-17
getTest1( String tNo, String tn, String state) //all three required as input

getTest2(String tn, String State) // both data values required
for both of these input needs to be validated to see if it is null and is in the right format ..

I have this fn to test this
public void validateReq(String qualTrackNo, String tn, String state) throws ServicesApplicationException
{
      String fctStr = "ServiceRequestBean::checkReq()";
      
      PatternMatcher re = new Perl5Matcher();

      if (!reInit)
            setupRePatterns();
      
      try
      {
         // EDIT THE TELEPHONE NUMBER
         if ( (tn == null) || (!re.matches(tn, reTn)) )
            throw exception;...                                                                        
         // EDIT THE QUALIFICATION TRACKING NUMBER
         if ( TrackNo == null ||
           (!re.matches(TrackNo, reQualTrackNum)) )
            throw exception...                                                                              
            // EDIT THE STATE
       if ( state == null ||       (!re.matches(state, reState)) )
            throw exception...                                                
      
}
private synchronized void setupRePatterns() throws ServicesApplicationException
{
   try
   {
         TraceLog.write(TraceLog.DEBUG, "Initializing regular patterns...");
      
         if (reInit)
            return;
         reTn = new Perl5Compiler().compile(props.getValue(ServicesConstants.REGEXP_TN_10DIGIT), Perl5Compiler.READ_ONLY_MASK);
         reQualTrackNum = new Perl5Compiler().compile(props.getValue(ServicesConstants.REGEXP_QUAL_TRACK_NO), Perl5Compiler.READ_ONLY_MASK);
         reState = new Perl5Compiler().compile(props.getValue(ServicesConstants.REGEXP_STATE_2CHAR), Perl5Compiler.READ_ONLY_MASK);

         reInit = true;
         return;
   }
        
   catch(Throwable t)
   {
         ServicesError.throwProcessingException(t, "ServiceRequestBean::setupRePatterns()", props);
   }

   return;
}

How do I retain the same fns and test for both getTest1 and getTest2? other than polymorphism?
0
Comment
Question by:skn73
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 5

Expert Comment

by:Hammadian2
ID: 12428352
getTest1( String tn, String state, String tNo = "xxx")

where "xxx" is a valid value for tNo
these way it can be used with 2 or 3 parameters
0
 

Author Comment

by:skn73
ID: 12434061
getTest1(tno, Tn, state) & getTest2(tn, state) needs to call validateReq() to validate the input
I dont want to change getTest1 or getTest2.

as it is written currently ..
if getTest2() calls validateReq("",tn,state) because there is no tracknum ...
it will error out saying tracknum is null or is in iinvalid format..

How can I use validateReq fn to do validations for both getTest1 and getTest2
0
 
LVL 1

Accepted Solution

by:
zcayo earned 2000 total points
ID: 12437298
skn73,

The easiest way is makeup a tracking number that will validate (i.e.- "_VALID") and hardcode it into getTest2() so it will call:

 validateReq("_VALID",tn,state)

you would then have to modify your tn validation rule from

if ( TrackNo == null ||
          (!re.matches(TrackNo, reQualTrackNum)) )

to

if ( TrackNo == null || (!re.matches(TrackNo, reQualTrackNum)) || !TrackNo.equals("_VALID"))

This is more or less what was suggested by Hammadian2, but with a little more detail.

Hope it works for you
0
 

Author Comment

by:skn73
ID: 12444227
Thanks .. this is exactly what I did ...
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Six Sigma Control Plans

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question