Review Board 1.7.22


Abraham Elmahrek got review request #12821!

SQOOP-1145 Sqoop2: Use JSON object for serializing MAP input type

Review Request #12821 - Created July 23, 2013 and submitted

Abraham Elmahrek
SQOOP-1145
Reviewers
Sqoop
hshreedharan, jarcec
sqoop-trunk
commit 1b2cb874b7ddd2d58b95cd1edfc1125f09892977
Author: Abraham Elmahrek <abraham@elmahrek.com>
Date:   Mon Jul 22 16:53:45 2013 -0700

    SQOOP-1145 Sqoop2: Use JSON object for serializing MAP input type

:100644 100644 98768d6... 50836b6... M  common/src/main/java/org/apache/sqoop/json/util/FormSerialization.java
:000000 100644 0000000... bbae9a0... A  common/src/main/java/org/apache/sqoop/json/util/SerializationError.java
:100644 100644 27db8af... e0c7977... M  common/src/main/java/org/apache/sqoop/model/FormUtils.java
:100644 100644 98a70f1... bbfd33d... M  common/src/test/java/org/apache/sqoop/json/util/TestFormSerialization.java
Ran sqoop tests
common/src/main/java/org/apache/sqoop/json/util/FormSerialization.java
Revision 98768d6cd0db3a7b5b1ac42fce557f52375461ab New Change
[20] 15 lines
[+20]
16
 * limitations under the License.
16
 * limitations under the License.
17
 */
17
 */
18
package org.apache.sqoop.json.util;
18
package org.apache.sqoop.json.util;
19

    
   
19

   
20
import org.apache.commons.lang.StringUtils;
20
import org.apache.commons.lang.StringUtils;

    
   
21
import org.apache.sqoop.common.SqoopException;
21
import org.apache.sqoop.model.MBooleanInput;
22
import org.apache.sqoop.model.MBooleanInput;
22
import org.apache.sqoop.model.MEnumInput;
23
import org.apache.sqoop.model.MEnumInput;
23
import org.apache.sqoop.model.MForm;
24
import org.apache.sqoop.model.MForm;
24
import org.apache.sqoop.model.MFormType;
25
import org.apache.sqoop.model.MFormType;
25
import org.apache.sqoop.model.MInput;
26
import org.apache.sqoop.model.MInput;
[+20] [20] 4 lines
[+20]
30
import org.json.simple.JSONArray;
31
import org.json.simple.JSONArray;
31
import org.json.simple.JSONObject;
32
import org.json.simple.JSONObject;
32

    
   
33

   
33
import java.util.ArrayList;
34
import java.util.ArrayList;
34
import java.util.List;
35
import java.util.List;

    
   
36
import java.util.Map;
35

    
   
37

   
36
/**
38
/**
37
 * Convenient static methods for serializing forms.
39
 * Convenient static methods for serializing forms.
38
 */
40
 */
39
public final class FormSerialization {
41
public final class FormSerialization {
[+20] [20] 71 lines
[+20] [+] public static JSONObject extractForm(MForm mForm, boolean skipSensitive) {
111
      }
113
      }
112

    
   
114

   
113
      // Serialize value if is there
115
      // Serialize value if is there
114
      // Skip if sensitive
116
      // Skip if sensitive
115
      if (!mInput.isEmpty() && !(skipSensitive && mInput.isSensitive())) {
117
      if (!mInput.isEmpty() && !(skipSensitive && mInput.isSensitive())) {

    
   
118
        if (mInput.getType() == MInputType.MAP) {

    
   
119
          input.put(FORM_INPUT_VALUE, mInput.getValue());

    
   
120
        } else {
116
        input.put(FORM_INPUT_VALUE, mInput.getUrlSafeValueString());
121
          input.put(FORM_INPUT_VALUE, mInput.getUrlSafeValueString());
117
      }
122
        }

    
   
123
      }
118

    
   
124

   
119
      mInputs.add(input);
125
      mInputs.add(input);
120
    }
126
    }
121

    
   
127

   
122
    return form;
128
    return form;
[+20] [20] 60 lines
[+20] [+] public static MForm restoreForm(JSONObject form) {
183
      // Propagate form ID
189
      // Propagate form ID
184
      mInput.setPersistenceId((Long)input.get(ID));
190
      mInput.setPersistenceId((Long)input.get(ID));
185

    
   
191

   
186
      // Propagate form optional value
192
      // Propagate form optional value
187
      if(input.containsKey(FORM_INPUT_VALUE)) {
193
      if(input.containsKey(FORM_INPUT_VALUE)) {

    
   
194
        switch (type) {

    
   
195
        case MAP:

    
   
196
          try {

    
   
197
            mInput.setValue((Map<String, String>)input.get(FORM_INPUT_VALUE));

    
   
198
          } catch (ClassCastException e) {

    
   
199
            throw new SqoopException(SerializationError.SERIALIZATION_001, name + " requires a 'map' value.");

    
   
200
          }

    
   
201
          break;

    
   
202
        default:
188
        mInput.restoreFromUrlSafeValueString(
203
          mInput.restoreFromUrlSafeValueString(
189
          (String) input.get(FORM_INPUT_VALUE));
204
              (String) input.get(FORM_INPUT_VALUE));

    
   
205
          break;

    
   
206
        }
190
      }
207
      }
191
      mInputs.add(mInput);
208
      mInputs.add(mInput);
192
    }
209
    }
193

    
   
210

   
194
    MForm mForm = new MForm((String) form.get(FORM_NAME), mInputs);
211
    MForm mForm = new MForm((String) form.get(FORM_NAME), mInputs);
195
    mForm.setPersistenceId((Long) form.get(ID));
212
    mForm.setPersistenceId((Long) form.get(ID));
196
    return mForm;
213
    return mForm;
197
  }
214
  }
198

    
   
215

   
199
  private FormSerialization() {
216
  private FormSerialization() {
200
    // Do not instantiate
217
    // Do not instantiate
201
  }
218
  }
202
}
219
}
common/src/main/java/org/apache/sqoop/json/util/SerializationError.java
New File
 
common/src/main/java/org/apache/sqoop/model/FormUtils.java
Revision 27db8af30f8cd9098ad54d0984b428e0b2dff0ce New Change
 
common/src/test/java/org/apache/sqoop/json/util/TestFormSerialization.java
Revision 98a70f1dc2f99e60c2919893beef0a5b21d761f8 New Change
 
  1. common/src/main/java/org/apache/sqoop/json/util/FormSerialization.java: Loading...
  2. common/src/main/java/org/apache/sqoop/json/util/SerializationError.java: Loading...
  3. common/src/main/java/org/apache/sqoop/model/FormUtils.java: Loading...
  4. common/src/test/java/org/apache/sqoop/json/util/TestFormSerialization.java: Loading...