Review Board 1.7.22


SQOOP-858 Sqoop2: Add validation messages on form level

Review Request #9279 - Created Feb. 3, 2013 and submitted

Jarek Cecho
SQOOP-858
Reviewers
Sqoop
sqoop-sqoop2
I've extended the system to support validations on form level.
Unit tests seems to be passing and I've tried several scenarios on real cluster.
client/src/main/java/org/apache/sqoop/client/utils/FormFiller.java
Revision 753d78e74a3d632e27cd9a965efa79031de5c7d8 New Change
[20] 24 lines
[+20]
25
import org.apache.sqoop.model.MInput;
25
import org.apache.sqoop.model.MInput;
26
import org.apache.sqoop.model.MIntegerInput;
26
import org.apache.sqoop.model.MIntegerInput;
27
import org.apache.sqoop.model.MMapInput;
27
import org.apache.sqoop.model.MMapInput;
28
import org.apache.sqoop.model.MJob;
28
import org.apache.sqoop.model.MJob;
29
import org.apache.sqoop.model.MStringInput;
29
import org.apache.sqoop.model.MStringInput;

    
   
30
import org.apache.sqoop.model.MValidatedElement;
30
import org.codehaus.groovy.tools.shell.IO;
31
import org.codehaus.groovy.tools.shell.IO;
31

    
   
32

   
32
import java.io.IOException;
33
import java.io.IOException;
33
import java.util.List;
34
import java.util.List;
34
import java.util.Map;
35
import java.util.Map;
[+20] [20] 110 lines
[+20] [+] public static boolean fillForms(IO io,
145
                                 MForm form,
146
                                 MForm form,
146
                                 ConsoleReader reader,
147
                                 ConsoleReader reader,
147
                                 ResourceBundle bundle) throws IOException {
148
                                 ResourceBundle bundle) throws IOException {
148
    io.out.println("");
149
    io.out.println("");
149
    io.out.println(bundle.getString(form.getLabelKey()));
150
    io.out.println(bundle.getString(form.getLabelKey()));

    
   
151

   

    
   
152
    // Print out form validation

    
   
153
    printValidationMessage(io, form);

    
   
154
    io.out.println("");

    
   
155

   
150
    for (MInput input : form.getInputs()) {
156
    for (MInput input : form.getInputs()) {
151
      if(!fillInput(io, input, reader, bundle)) {
157
      if(!fillInput(io, input, reader, bundle)) {
152
        return false;
158
        return false;
153
      }
159
      }
154
    }
160
    }
155

    
   
161

   
156
    return true;
162
    return true;
157
  }
163
  }
158

    
   
164

   
159
  public static boolean fillInput(IO io,
165
  public static boolean fillInput(IO io,
160
                                  MInput input,
166
                                  MInput input,
161
                                  ConsoleReader reader,
167
                                  ConsoleReader reader,
162
                                  ResourceBundle bundle) throws IOException {
168
                                  ResourceBundle bundle) throws IOException {
163
    // Print out warning or error message in case some validations were already
169
    // Print out validation
164
    // performed.
170
    printValidationMessage(io, input);
165
    switch (input.getValidationStatus()) {

   
166
      case UNACCEPTABLE:

   
167
        errorMessage(io, input.getValidationMessage());

   
168
        break;
Moved to 494

   
169
      case ACCEPTABLE:
Moved to 495

   
170
        warningMessage(io, input.getValidationMessage());

   
171
        break;

   
172
      default:

   
173
        // Simply ignore all other states for the moment

   
174
        break;

   
175
    }

   
176

    
   
171

   
177
    // Based on the input type, let's perform specific load
172
    // Based on the input type, let's perform specific load
178
    switch (input.getType()) {
173
    switch (input.getType()) {
179
      case STRING:
174
      case STRING:
180
        return fillInputString(io, (MStringInput) input, reader, bundle);
175
        return fillInputString(io, (MStringInput) input, reader, bundle);
[+20] [20] 303 lines
[+20] [+] public static String getName(IO io, ConsoleReader reader,
484
    fillInputString(io, nameInput, reader, Environment.getResourceBundle());
479
    fillInputString(io, nameInput, reader, Environment.getResourceBundle());
485

    
   
480

   
486
    return nameInput.getValue();
481
    return nameInput.getValue();
487
  }
482
  }
488

    
   
483

   

    
   
484
  /**

    
   
485
   * Print validation message in cases that it's not in state "FINE"

    
   
486
   *

    
   
487
   * @param io IO object to print out the message

    
   
488
   * @param element Validated element

    
   
489
   */

    
   
490
  public static void printValidationMessage(IO io, MValidatedElement element) {

    
   
491
    switch (element.getValidationStatus()) {

    
   
492
      case UNACCEPTABLE:

    
   
493
        errorMessage(io, element.getValidationMessage());
Moved from 168

    
   
494
        break;
Moved from 169

    
   
495
      case ACCEPTABLE:

    
   
496
        warningMessage(io, element.getValidationMessage());

    
   
497
        break;

    
   
498
      default:

    
   
499
        // Simply ignore all other states for the moment

    
   
500
        break;

    
   
501
    }

    
   
502
  }

    
   
503

   
489
  public static void errorMessage(IO io, String message) {
504
  public static void errorMessage(IO io, String message) {
490
    io.out.println("Error message: @|red " + message + " |@");
505
    io.out.println("Error message: @|red " + message + " |@");
491
  }
506
  }
492

    
   
507

   
493
  public static void warningMessage(IO io, String message) {
508
  public static void warningMessage(IO io, String message) {
[+20] [20] 13 lines
common/src/main/java/org/apache/sqoop/model/FormUtils.java
Revision 10e64a3515437aa4f3522b7fa6d58d0e0f8a388d New Change
 
common/src/main/java/org/apache/sqoop/validation/Validation.java
Revision ddc1d9e1f302d09ab94f31f005f5883a1ebd9387 New Change
 
common/src/test/java/org/apache/sqoop/validation/TestValidation.java
Revision 600cfff8c9c982cac9c98a63700bedfed09dfa9a New Change
 
connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcValidator.java
Revision 8980b629982e866949f5f92d9728045722ed156a New Change
 
connector/connector-generic-jdbc/src/main/resources/generic-jdbc-connector-resources.properties
Revision 0372911a139c2a6d62ca8353976a527e55bc078d New Change
 
  1. client/src/main/java/org/apache/sqoop/client/utils/FormFiller.java: Loading...
  2. common/src/main/java/org/apache/sqoop/model/FormUtils.java: Loading...
  3. common/src/main/java/org/apache/sqoop/validation/Validation.java: Loading...
  4. common/src/test/java/org/apache/sqoop/validation/TestValidation.java: Loading...
  5. connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcValidator.java: Loading...
  6. connector/connector-generic-jdbc/src/main/resources/generic-jdbc-connector-resources.properties: Loading...