Review Board 1.7.22


SQOOP-613: Add support for integer type to metadata model

Review Request #7371 - Created Oct. 1, 2012 and submitted

Jarek Cecho
SQOOP-613
Reviewers
Sqoop
sqoop-sqoop2
Pretty straightforward implementation of new metadata data type.
No new unit tests introduced, just "by hand" testing at the moment.
client/src/main/java/org/apache/sqoop/client/utils/FormFiller.java
Revision af3ff8a New Change
[20] 17 lines
[+20]
18
package org.apache.sqoop.client.utils;
18
package org.apache.sqoop.client.utils;
19

    
   
19

   
20
import jline.ConsoleReader;
20
import jline.ConsoleReader;
21
import org.apache.sqoop.model.MForm;
21
import org.apache.sqoop.model.MForm;
22
import org.apache.sqoop.model.MInput;
22
import org.apache.sqoop.model.MInput;

    
   
23
import org.apache.sqoop.model.MIntegerInput;
23
import org.apache.sqoop.model.MStringInput;
24
import org.apache.sqoop.model.MStringInput;
24
import org.codehaus.groovy.tools.shell.IO;
25
import org.codehaus.groovy.tools.shell.IO;
25

    
   
26

   
26
import java.io.IOException;
27
import java.io.IOException;
27
import java.util.List;
28
import java.util.List;
28
import java.util.ResourceBundle;
29
import java.util.ResourceBundle;
29

    
   
30

   
30
/**
31
/**
31
 *
32
 *
32
 */
33
 */
33
public class FormFiller {
34
public class FormFiller {
34

    
   
35

   
35

    
   

   
36
  public static boolean fillForms(IO io,
36
  public static boolean fillForms(IO io,
37
                                  List<MForm> forms,
37
                                  List<MForm> forms,
38
                                  ConsoleReader reader,
38
                                  ConsoleReader reader,
39
                                  ResourceBundle bundle)
39
                                  ResourceBundle bundle)
40
    throws IOException {
40
    throws IOException {
[+20] [20] 27 lines
[+20] [+] public static boolean fillInput(IO io,
68
                                  ResourceBundle bundle) throws IOException {
68
                                  ResourceBundle bundle) throws IOException {
69
    // Print out warning or error message in case some validations were already
69
    // Print out warning or error message in case some validations were already
70
    // performed.
70
    // performed.
71
    switch (input.getValidationSeverity()) {
71
    switch (input.getValidationSeverity()) {
72
      case ERROR:
72
      case ERROR:
73
        io.out.println("Error message: @|red "
73
        errorMessage(io, input.getValidationMessage());
74
          + input.getValidationMessage() + " |@");

   
75
        break;
74
        break;
76
      case WARNING:
75
      case WARNING:
77
        io.out.println("Warning message: @|yellow "
76
        warningMessage(io, input.getValidationMessage());
78
          + input.getValidationMessage() + " |@");

   
79
        break;
77
        break;
80
      default:
78
      default:
81
        // Simply ignore all other states for the moment
79
        // Simply ignore all other states for the moment
82
        break;
80
        break;
83
    }
81
    }
84

    
   
82

   
85
    // Based on the input type, let's perform specific load
83
    // Based on the input type, let's perform specific load
86
    switch (input.getType()) {
84
    switch (input.getType()) {
87
      case STRING:
85
      case STRING:
88
        return fillInputString(io, (MStringInput) input, reader, bundle);
86
        return fillInputString(io, (MStringInput) input, reader, bundle);

    
   
87
      case INTEGER:

    
   
88
        return fillInputInteger(io, (MIntegerInput) input, reader, bundle);
89
      //TODO(jarcec): Support MAP
89
      //TODO(jarcec): Support MAP
90
      default:
90
      default:
91
        io.out.println("Unsupported data type " + input.getType());
91
        io.out.println("Unsupported data type " + input.getType());
92
        return true;
92
        return true;
93
    }
93
    }
94
  }
94
  }
95

    
   
95

   

    
   
96
  private static boolean fillInputInteger(IO io,

    
   
97
                                          MIntegerInput input,

    
   
98
                                          ConsoleReader reader,

    
   
99
                                          ResourceBundle bundle)

    
   
100
                                          throws IOException {

    
   
101
    generatePrompt(reader, bundle, input);

    
   
102

   

    
   
103
    // Fill already filled data when available

    
   
104
    if(!input.isEmpty()) {

    
   
105
      reader.putString(input.getValue().toString());

    
   
106
    }

    
   
107

   

    
   
108
    String userTyped = reader.readLine();

    
   
109

   

    
   
110
    if (userTyped == null) {

    
   
111
      return false;

    
   
112
    } else if (userTyped.isEmpty()) {

    
   
113
      input.setEmpty();

    
   
114
    } else {

    
   
115
      Integer value;

    
   
116
      try {

    
   
117
        value = Integer.valueOf(userTyped);

    
   
118
        input.setValue(value);

    
   
119
      } catch (NumberFormatException ex) {

    
   
120
        errorMessage(io, "Input is not valid integer number");

    
   
121
        return fillInputInteger(io, input, reader, bundle);

    
   
122
      }

    
   
123

   

    
   
124
      input.setValue(Integer.valueOf(userTyped));

    
   
125
    }

    
   
126

   

    
   
127
    return true;

    
   
128
  }

    
   
129

   
96
  public static boolean fillInputString(IO io,
130
  public static boolean fillInputString(IO io,
97
                                        MStringInput input,
131
                                        MStringInput input,
98
                                        ConsoleReader reader,
132
                                        ConsoleReader reader,
99
                                        ResourceBundle bundle)
133
                                        ResourceBundle bundle)
100
                                        throws IOException {
134
                                        throws IOException {
101
    // Print prompt
135
    generatePrompt(reader, bundle, input);
102
    reader.printString(bundle.getString(input.getLabelKey()) + ": ");
Moved to 166

   
103
    reader.flushConsole();
Moved to 167

   
104

    
   
136

   
105
    // Fill already filled data when available
137
    // Fill already filled data when available
106
    if(!input.isEmpty()) {
138
    // However do not printout if this input contains sensitive information.

    
   
139
    if(!input.isEmpty() && !input.isMasked()) {
107
      reader.putString(input.getValue());
140
      reader.putString(input.getValue());
108
    }
141
    }
109

    
   
142

   
110
    // Get the data
143
    // Get the data
111
    String userTyped;
144
    String userTyped;
[+20] [20] 12 lines
[+20] public static boolean fillInputString(IO io,
124
    }
157
    }
125

    
   
158

   
126
    return true;
159
    return true;
127
  }
160
  }
128

    
   
161

   

    
   
162
  public static void generatePrompt(ConsoleReader reader,

    
   
163
                                    ResourceBundle bundle,

    
   
164
                                    MInput input)

    
   
165
                                    throws IOException {
Moved from 102

    
   
166
    reader.printString(bundle.getString(input.getLabelKey()) + ": ");
Moved from 103

    
   
167
    reader.flushConsole();

    
   
168
  }

    
   
169

   

    
   
170
  public static void errorMessage(IO io, String message) {

    
   
171
    io.out.println("Error message: @|red " + message + " |@");

    
   
172
  }

    
   
173

   

    
   
174
  public static void warningMessage(IO io, String message) {

    
   
175
    io.out.println("Warning message: @|yellow " + message + " |@");

    
   
176
  }

    
   
177

   
129
  private FormFiller() {
178
  private FormFiller() {
130
    // Do not instantiate
179
    // Do not instantiate
131
  }
180
  }
132
}
181
}
common/src/main/java/org/apache/sqoop/json/util/FormSerialization.java
Revision 6b7332a New Change
 
common/src/main/java/org/apache/sqoop/model/MInputType.java
Revision 7acdbca New Change
 
common/src/main/java/org/apache/sqoop/model/MIntegerInput.java
New File
 
core/src/main/java/org/apache/sqoop/framework/FrameworkManager.java
Revision 657eab2 New Change
 
repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbyRepositoryHandler.java
Revision c44270e New Change
 
  1. client/src/main/java/org/apache/sqoop/client/utils/FormFiller.java: Loading...
  2. common/src/main/java/org/apache/sqoop/json/util/FormSerialization.java: Loading...
  3. common/src/main/java/org/apache/sqoop/model/MInputType.java: Loading...
  4. common/src/main/java/org/apache/sqoop/model/MIntegerInput.java: Loading...
  5. core/src/main/java/org/apache/sqoop/framework/FrameworkManager.java: Loading...
  6. repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbyRepositoryHandler.java: Loading...