5
0
mirror of https://github.com/apache/sqoop.git synced 2025-05-07 13:51:24 +08:00

SQOOP-947: Sqoop2: Introduce the concept of "sensitivity" input to all supported metadata structures

(Abraham Elmahrek via Jarek Jarcec Cecho)
This commit is contained in:
Jarek Jarcec Cecho 2013-03-25 13:33:15 -07:00
parent cc506b9ebf
commit dd61adf66c
24 changed files with 181 additions and 117 deletions

View File

@ -336,8 +336,8 @@ public class Constants {
"formdisplayer.input"; "formdisplayer.input";
public static final String RES_FORMDISPLAYER_TYPE = public static final String RES_FORMDISPLAYER_TYPE =
"formdisplayer.type"; "formdisplayer.type";
public static final String RES_FORMDISPLAYER_MASK = public static final String RES_FORMDISPLAYER_SENSITIVE =
"formdisplayer.mask"; "formdisplayer.sensitive";
public static final String RES_FORMDISPLAYER_SIZE = public static final String RES_FORMDISPLAYER_SIZE =
"formdisplayer.size"; "formdisplayer.size";
public static final String RES_FORMDISPLAYER_POSSIBLE_VALUES = public static final String RES_FORMDISPLAYER_POSSIBLE_VALUES =

View File

@ -101,9 +101,9 @@ public static void displayFormsMetadata(List<MForm> forms,
println(bundle.getString(input.getHelpKey())); println(bundle.getString(input.getHelpKey()));
print(" %s: ", resourceString(Constants.RES_FORMDISPLAYER_TYPE)); print(" %s: ", resourceString(Constants.RES_FORMDISPLAYER_TYPE));
println(input.getType()); println(input.getType());
print(" %s: ", resourceString(Constants.RES_FORMDISPLAYER_SENSITIVE));
println(input.isSensitive());
if (input.getType() == MInputType.STRING) { if (input.getType() == MInputType.STRING) {
print(" %s: ", resourceString(Constants.RES_FORMDISPLAYER_MASK));
println(((MStringInput)input).isMasked());
print(" %s: ", resourceString(Constants.RES_FORMDISPLAYER_SIZE)); print(" %s: ", resourceString(Constants.RES_FORMDISPLAYER_SIZE));
println(((MStringInput)input).getMaxLength()); println(((MStringInput)input).getMaxLength());
} else if(input.getType() == MInputType.ENUM) { } else if(input.getType() == MInputType.ENUM) {
@ -129,23 +129,27 @@ private static void displayForm(MForm form, ResourceBundle bundle) {
print(bundle.getString(input.getLabelKey())); print(bundle.getString(input.getLabelKey()));
print(": "); print(": ");
if(!input.isEmpty()) { if(!input.isEmpty()) {
// Based on the input type, let's perform specific load if (input.isSensitive()) {
switch (input.getType()) { print("(%s)", resourceString(Constants.RES_FORMDISPLAYER_INPUT_SENSITIVE));
case STRING: } else {
displayInputString((MStringInput) input); // Based on the input type, let's perform specific load
break; switch (input.getType()) {
case INTEGER: case STRING:
displayInputInteger((MIntegerInput) input); displayInputString((MStringInput) input);
break; break;
case MAP: case INTEGER:
displayInputMap((MMapInput) input); displayInputInteger((MIntegerInput) input);
break; break;
case ENUM: case MAP:
displayInputEnum((MEnumInput) input); displayInputMap((MMapInput) input);
break; break;
default: case ENUM:
print("\n%s " + input.getType(), resourceString(Constants.RES_FORMDISPLAYER_UNSUPPORTED_DATATYPE)); displayInputEnum((MEnumInput) input);
return; break;
default:
print("\n%s " + input.getType(), resourceString(Constants.RES_FORMDISPLAYER_UNSUPPORTED_DATATYPE));
return;
}
} }
} }
println(""); println("");
@ -158,11 +162,7 @@ private static void displayForm(MForm form, ResourceBundle bundle) {
* @param input String input * @param input String input
*/ */
private static void displayInputString(MStringInput input) { private static void displayInputString(MStringInput input) {
if (input.isMasked()) { print(input.getValue());
print("(%s)", resourceString(Constants.RES_FORMDISPLAYER_INPUT_SENSITIVE));
} else {
print(input.getValue());
}
} }
/** /**

View File

@ -203,7 +203,8 @@ private static boolean fillInputEnum(MEnumInput input,
println(" " + i + " : " + value); println(" " + i + " : " + value);
if(!input.isEmpty() && value.equals(input.getValue())) { // Only show last choice if not sensitive
if(!input.isEmpty() && value.equals(input.getValue()) && !input.isSensitive()) {
lastChoice = i; lastChoice = i;
} }
} }
@ -217,7 +218,12 @@ private static boolean fillInputEnum(MEnumInput input,
} }
reader.flushConsole(); reader.flushConsole();
String userTyped = reader.readLine(); String userTyped;
if(input.isSensitive()) {
userTyped = reader.readLine('*');
} else {
userTyped = reader.readLine();
}
if (userTyped == null) { if (userTyped == null) {
return false; return false;
@ -278,16 +284,23 @@ private static boolean fillInputMap(MMapInput input,
while(true) { while(true) {
// Print all current items in each iteration // Print all current items in each iteration
// However do not printout if this input contains sensitive information.
println("There are currently " + values.size() + " values in the map:"); println("There are currently " + values.size() + " values in the map:");
for(Map.Entry<String, String> entry : values.entrySet()) { if (!input.isSensitive()) {
println(entry.getKey() + " = " + entry.getValue()); for(Map.Entry<String, String> entry : values.entrySet()) {
println(entry.getKey() + " = " + entry.getValue());
}
} }
// Special prompt for Map entry // Special prompt for Map entry
reader.printString("entry# "); reader.printString("entry# ");
reader.flushConsole(); reader.flushConsole();
userTyped = reader.readLine(); if(input.isSensitive()) {
userTyped = reader.readLine('*');
} else {
userTyped = reader.readLine();
}
if(userTyped == null) { if(userTyped == null) {
// Finish loading and return back to Sqoop shell // Finish loading and return back to Sqoop shell
@ -365,11 +378,18 @@ private static boolean fillInputInteger(MIntegerInput input,
generatePrompt(reader, bundle, input); generatePrompt(reader, bundle, input);
// Fill already filled data when available // Fill already filled data when available
if(!input.isEmpty()) { // However do not printout if this input contains sensitive information.
if(!input.isEmpty() && !input.isSensitive()) {
reader.putString(input.getValue().toString()); reader.putString(input.getValue().toString());
} }
String userTyped = reader.readLine(); // Get the data
String userTyped;
if(input.isSensitive()) {
userTyped = reader.readLine('*');
} else {
userTyped = reader.readLine();
}
if (userTyped == null) { if (userTyped == null) {
return false; return false;
@ -408,13 +428,13 @@ public static boolean fillInputString(MStringInput input,
// Fill already filled data when available // Fill already filled data when available
// However do not printout if this input contains sensitive information. // However do not printout if this input contains sensitive information.
if(!input.isEmpty() && !input.isMasked()) { if(!input.isEmpty() && !input.isSensitive()) {
reader.putString(input.getValue()); reader.putString(input.getValue());
} }
// Get the data // Get the data
String userTyped; String userTyped;
if(input.isMasked()) { if(input.isSensitive()) {
userTyped = reader.readLine('*'); userTyped = reader.readLine('*');
} else { } else {
userTyped = reader.readLine(); userTyped = reader.readLine();

View File

@ -182,7 +182,7 @@ formdisplayer.label = Label
formdisplayer.help = Help formdisplayer.help = Help
formdisplayer.input = Input formdisplayer.input = Input
formdisplayer.type = Type formdisplayer.type = Type
formdisplayer.mask = Mask formdisplayer.sensitive = Sensitive
formdisplayer.size = Size formdisplayer.size = Size
formdisplayer.possible_values = Possible values formdisplayer.possible_values = Possible values
formdisplayer.unsupported_datatype = Unsupported data type formdisplayer.unsupported_datatype = Unsupported data type

View File

@ -52,7 +52,7 @@ public final class FormSerialization {
public static final String FORM_INPUTS = "inputs"; public static final String FORM_INPUTS = "inputs";
public static final String FORM_INPUT_NAME = "name"; public static final String FORM_INPUT_NAME = "name";
public static final String FORM_INPUT_TYPE = "type"; public static final String FORM_INPUT_TYPE = "type";
public static final String FORM_INPUT_MASK = "mask"; public static final String FORM_INPUT_SENSITIVE = "sensitive";
public static final String FORM_INPUT_SIZE = "size"; public static final String FORM_INPUT_SIZE = "size";
public static final String FORM_INPUT_VALUE = "value"; public static final String FORM_INPUT_VALUE = "value";
public static final String FORM_INPUT_VALUES = "values"; public static final String FORM_INPUT_VALUES = "values";
@ -95,11 +95,10 @@ public static JSONObject extractForm(MForm mForm, boolean skipSensitive) {
input.put(ID, mInput.getPersistenceId()); input.put(ID, mInput.getPersistenceId());
input.put(FORM_INPUT_NAME, mInput.getName()); input.put(FORM_INPUT_NAME, mInput.getName());
input.put(FORM_INPUT_TYPE, mInput.getType().toString()); input.put(FORM_INPUT_TYPE, mInput.getType().toString());
input.put(FORM_INPUT_SENSITIVE, mInput.isSensitive());
// String specific serialization // String specific serialization
if (mInput.getType() == MInputType.STRING) { if (mInput.getType() == MInputType.STRING) {
input.put(FORM_INPUT_MASK,
((MStringInput)mInput).isMasked());
input.put(FORM_INPUT_SIZE, input.put(FORM_INPUT_SIZE,
((MStringInput)mInput).getMaxLength()); ((MStringInput)mInput).getMaxLength());
} }
@ -112,7 +111,7 @@ public static JSONObject extractForm(MForm mForm, boolean skipSensitive) {
// Serialize value if is there // Serialize value if is there
// Skip if sensitive // Skip if sensitive
if (!mInput.isEmpty() && !(skipSensitive && ((MStringInput)mInput).isMasked())) { if (!mInput.isEmpty() && !(skipSensitive && mInput.isSensitive())) {
input.put(FORM_INPUT_VALUE, mInput.getUrlSafeValueString()); input.put(FORM_INPUT_VALUE, mInput.getUrlSafeValueString());
} }
@ -153,25 +152,25 @@ public static MForm restoreForm(JSONObject form) {
MInputType type = MInputType type =
MInputType.valueOf((String) input.get(FORM_INPUT_TYPE)); MInputType.valueOf((String) input.get(FORM_INPUT_TYPE));
String name = (String) input.get(FORM_INPUT_NAME); String name = (String) input.get(FORM_INPUT_NAME);
Boolean sensitive = (Boolean) input.get(FORM_INPUT_SENSITIVE);
MInput mInput = null; MInput mInput = null;
switch (type) { switch (type) {
case STRING: { case STRING: {
boolean mask = (Boolean) input.get(FORM_INPUT_MASK);
long size = (Long) input.get(FORM_INPUT_SIZE); long size = (Long) input.get(FORM_INPUT_SIZE);
mInput = new MStringInput(name, mask, (short) size); mInput = new MStringInput(name, sensitive.booleanValue(), (short) size);
break; break;
} }
case MAP: { case MAP: {
mInput = new MMapInput(name); mInput = new MMapInput(name, sensitive.booleanValue());
break; break;
} }
case INTEGER: { case INTEGER: {
mInput = new MIntegerInput(name); mInput = new MIntegerInput(name, sensitive.booleanValue());
break; break;
} }
case ENUM: { case ENUM: {
String values = (String) input.get(FORM_INPUT_VALUES); String values = (String) input.get(FORM_INPUT_VALUES);
mInput = new MEnumInput(name, values.split(",")); mInput = new MEnumInput(name, sensitive.booleanValue(), values.split(","));
break; break;
} }
} }

View File

@ -139,11 +139,11 @@ private static MForm toForm(String formName, Class klass, Object object) {
if(type == String.class) { if(type == String.class) {
input = new MStringInput(inputName, sensitive, maxLen); input = new MStringInput(inputName, sensitive, maxLen);
} else if (type.isAssignableFrom(Map.class)) { } else if (type.isAssignableFrom(Map.class)) {
input = new MMapInput(inputName); input = new MMapInput(inputName, sensitive);
} else if(type == Integer.class) { } else if(type == Integer.class) {
input = new MIntegerInput(inputName); input = new MIntegerInput(inputName, sensitive);
} else if(type.isEnum()) { } else if(type.isEnum()) {
input = new MEnumInput(inputName, ClassUtils.getEnumStrings(type)); input = new MEnumInput(inputName, sensitive, ClassUtils.getEnumStrings(type));
} else { } else {
throw new SqoopException(ModelError.MODEL_004, throw new SqoopException(ModelError.MODEL_004,
"Unsupported type " + type.getName() + " for input " + fieldName); "Unsupported type " + type.getName() + " for input " + fieldName);

View File

@ -32,8 +32,8 @@ public class MEnumInput extends MInput<String> {
*/ */
String []values; String []values;
public MEnumInput(String name, String[] values) { public MEnumInput(String name, boolean sensitive, String[] values) {
super(name); super(name, sensitive);
this.values = values; this.values = values;
} }

View File

@ -21,12 +21,16 @@
* Represents a parameter input used by the connector for creating a connection * Represents a parameter input used by the connector for creating a connection
* or a job object. * or a job object.
* @param <T> the value type associated with this parameter * @param <T> the value type associated with this parameter
* @param boolean whether or not the field contains sensitive information
*/ */
public abstract class MInput<T> extends MValidatedElement { public abstract class MInput<T> extends MValidatedElement {
private final boolean sensitive;
private T value; private T value;
protected MInput(String name) { protected MInput(String name, boolean sensitive) {
super(name); super(name);
this.sensitive = sensitive;
} }
/** /**
@ -43,6 +47,13 @@ public T getValue() {
return value; return value;
} }
/**
* @return <tt>true</tt> if this string represents sensitive information
*/
public boolean isSensitive() {
return sensitive;
}
/** /**
* @return a URL-safe string representation of the value * @return a URL-safe string representation of the value
*/ */

View File

@ -24,8 +24,8 @@
*/ */
public class MIntegerInput extends MInput<Integer> { public class MIntegerInput extends MInput<Integer> {
public MIntegerInput(String name) { public MIntegerInput(String name, boolean sensitive) {
super(name); super(name, sensitive);
} }
@Override @Override

View File

@ -24,8 +24,8 @@
public final class MMapInput extends MInput<Map<String, String>> { public final class MMapInput extends MInput<Map<String, String>> {
public MMapInput(String name) { public MMapInput(String name, boolean sensitive) {
super(name); super(name, sensitive);
} }
@Override @Override

View File

@ -20,35 +20,25 @@
import org.apache.sqoop.utils.UrlSafeUtils; import org.apache.sqoop.utils.UrlSafeUtils;
/** /**
* Represents a <tt>String</tt> input. The boolean flag <tt>mask</tt> supplied * Represents a <tt>String</tt> input. The boolean flag <tt>sensitive</tt> supplied
* to its constructor can be used to indicate if the string should be masked * to its constructor can be used to indicate if the string should be masked
* from user-view. This is helpful for creating input strings that represent * from user-view. This is helpful for creating input strings that represent
* sensitive information such as passwords. * sensitive information such as passwords.
*/ */
public final class MStringInput extends MInput<String> { public final class MStringInput extends MInput<String> {
private final boolean mask;
private final short maxLength; private final short maxLength;
/** /**
* @param name the parameter name * @param name the parameter name
* @param mask a flag indicating if the string should be masked * @param sensitive a flag indicating if the string should be masked
* @param maxLength the maximum length of the string * @param maxLength the maximum length of the string
*/ */
public MStringInput(String name, boolean mask, short maxLength) { public MStringInput(String name, boolean sensitive, short maxLength) {
super(name); super(name, sensitive);
this.mask = mask;
this.maxLength = maxLength; this.maxLength = maxLength;
} }
/**
* @return <tt>true</tt> if this string represents sensitive information that
* should be masked
*/
public boolean isMasked() {
return mask;
}
/** /**
* @return the maximum length of this string type * @return the maximum length of this string type
*/ */
@ -78,7 +68,7 @@ public boolean hasExtraInfo() {
@Override @Override
public String getExtraInfoToString() { public String getExtraInfoToString() {
return isMasked() + ":" + getMaxLength(); return Short.toString(getMaxLength());
} }
@Override @Override
@ -93,14 +83,14 @@ public boolean equals(Object other) {
MStringInput msi = (MStringInput) other; MStringInput msi = (MStringInput) other;
return getName().equals(msi.getName()) return getName().equals(msi.getName())
&& (mask == msi.mask) && (isSensitive() == msi.isSensitive())
&& (maxLength == msi.maxLength); && (maxLength == msi.maxLength);
} }
@Override @Override
public int hashCode() { public int hashCode() {
int result = 23 + 31 * getName().hashCode(); int result = 23 + 31 * getName().hashCode();
result = 31 * result + (mask ? 1 : 0); result = 31 * result + (isSensitive() ? 1 : 0);
result = 31 * result + maxLength; result = 31 * result + maxLength;
return result; return result;
} }

View File

@ -19,6 +19,7 @@
import org.apache.sqoop.model.MConnection; import org.apache.sqoop.model.MConnection;
import org.apache.sqoop.model.MStringInput; import org.apache.sqoop.model.MStringInput;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
import org.json.simple.JSONArray; import org.json.simple.JSONArray;
import org.json.simple.JSONValue; import org.json.simple.JSONValue;
@ -52,6 +53,16 @@ public void testSerialization() {
ConnectionBean bean = new ConnectionBean(connection); ConnectionBean bean = new ConnectionBean(connection);
JSONObject json = bean.extract(false); JSONObject json = bean.extract(false);
// Check for sensitivity
JSONArray all = (JSONArray)json.get("all");
JSONObject allItem = (JSONObject)all.get(0);
JSONArray connectors = (JSONArray)allItem.get("connector");
JSONObject connector = (JSONObject)connectors.get(0);
JSONArray inputs = (JSONArray)connector.get("inputs");
for (Object input1 : inputs) {
assertTrue(((JSONObject)input1).containsKey("sensitive"));
}
// "Move" it across network in text form // "Move" it across network in text form
String string = json.toJSONString(); String string = json.toJSONString();

View File

@ -184,9 +184,9 @@ protected List<MForm> getForms() {
// Form C // Form C
inputs = new LinkedList<MInput<?>>(); inputs = new LinkedList<MInput<?>>();
inputs.add(new MIntegerInput("cForm.intValue")); inputs.add(new MIntegerInput("cForm.intValue", false));
inputs.add(new MMapInput("cForm.map")); inputs.add(new MMapInput("cForm.map", false));
inputs.add(new MEnumInput("cForm.enumeration", new String[]{"X", "Y"})); inputs.add(new MEnumInput("cForm.enumeration", false, new String[]{"X", "Y"}));
ret.add(new MForm("cForm", inputs)); ret.add(new MForm("cForm", inputs));
return ret; return ret;

View File

@ -36,7 +36,7 @@ public class TestMAccountableEntity {
@Test @Test
public void testInitialization() { public void testInitialization() {
List<MForm> forms = new ArrayList<MForm>(); List<MForm> forms = new ArrayList<MForm>();
MIntegerInput input = new MIntegerInput("INTEGER-INPUT"); MIntegerInput input = new MIntegerInput("INTEGER-INPUT", false);
List<MInput<?>> list = new ArrayList<MInput<?>>(); List<MInput<?>> list = new ArrayList<MInput<?>>();
list.add(input); list.add(input);
MForm form = new MForm("FORMNAME", list); MForm form = new MForm("FORMNAME", list);

View File

@ -49,7 +49,7 @@ public void testInitialization() {
private MConnectionForms connector1() { private MConnectionForms connector1() {
List<MForm> forms = new ArrayList<MForm>(); List<MForm> forms = new ArrayList<MForm>();
MIntegerInput input = new MIntegerInput("INTEGER-INPUT"); MIntegerInput input = new MIntegerInput("INTEGER-INPUT", false);
List<MInput<?>> list = new ArrayList<MInput<?>>(); List<MInput<?>> list = new ArrayList<MInput<?>>();
list.add(input); list.add(input);
MForm form = new MForm("FORMNAME", list); MForm form = new MForm("FORMNAME", list);
@ -59,7 +59,7 @@ private MConnectionForms connector1() {
private MConnectionForms connector2() { private MConnectionForms connector2() {
List<MForm> forms = new ArrayList<MForm>(); List<MForm> forms = new ArrayList<MForm>();
MMapInput input = new MMapInput("MAP-INPUT"); MMapInput input = new MMapInput("MAP-INPUT", false);
List<MInput<?>> list = new ArrayList<MInput<?>>(); List<MInput<?>> list = new ArrayList<MInput<?>>();
list.add(input); list.add(input);
MForm form = new MForm("form", list); MForm form = new MForm("form", list);

View File

@ -33,19 +33,31 @@ public enum Enumeration { value1, value2}
@Test @Test
public void testInitialization() { public void testInitialization() {
String[] values = { "value1", "value2" }; String[] values = { "value1", "value2" };
MEnumInput input = new MEnumInput("NAME", values); MEnumInput input = new MEnumInput("NAME", false, values);
assertEquals("NAME", input.getName()); assertEquals("NAME", input.getName());
assertArrayEquals(values, input.getValues()); assertArrayEquals(values, input.getValues());
assertEquals(MInputType.ENUM, input.getType()); assertEquals(MInputType.ENUM, input.getType());
MEnumInput input1 = new MEnumInput("NAME", values); MEnumInput input1 = new MEnumInput("NAME", false, values);
assertEquals(input1, input); assertEquals(input1, input);
String[] testVal = { "val", "test" }; String[] testVal = { "val", "test" };
MEnumInput input2 = new MEnumInput("NAME1", testVal); MEnumInput input2 = new MEnumInput("NAME1", false, testVal);
assertFalse(input1.equals(input2)); assertFalse(input1.equals(input2));
MEnumInput input3 = new MEnumInput("NAME", values); MEnumInput input3 = new MEnumInput("NAME", false, values);
input3.setValue(Enumeration.value1); input3.setValue(Enumeration.value1);
assertEquals("value1", input3.getValue()); assertEquals("value1", input3.getValue());
} }
/**
* Test for sensitivity
*/
@Test
public void testSensitivity() {
String[] values = { "value1", "value2" };
MEnumInput input1 = new MEnumInput("NAME", false, values);
MEnumInput input2 = new MEnumInput("NAME", true, values);
assertFalse(input1.isSensitive());
assertTrue(input2.isSensitive());
}
} }

View File

@ -50,15 +50,15 @@ public void testInitialization() {
*/ */
@Test @Test
public void testEquals() { public void testEquals() {
MInput<Integer> input1 = new MIntegerInput("sqoopsqoop1"); MInput<Integer> input1 = new MIntegerInput("sqoopsqoop1", false);
MInput<Integer> input2 = new MIntegerInput("sqoopsqoop2"); MInput<Integer> input2 = new MIntegerInput("sqoopsqoop2", false);
List<MInput<?>> list1 = new ArrayList<MInput<?>>(); List<MInput<?>> list1 = new ArrayList<MInput<?>>();
list1.add(input1); list1.add(input1);
list1.add(input2); list1.add(input2);
MForm mform1 = new MForm("form", list1); MForm mform1 = new MForm("form", list1);
MInput<Integer> input3 = new MIntegerInput("sqoopsqoop1"); MInput<Integer> input3 = new MIntegerInput("sqoopsqoop1", false);
MInput<Integer> input4 = new MIntegerInput("sqoopsqoop2"); MInput<Integer> input4 = new MIntegerInput("sqoopsqoop2", false);
List<MInput<?>> list2 = new ArrayList<MInput<?>>(); List<MInput<?>> list2 = new ArrayList<MInput<?>>();
list2.add(input3); list2.add(input3);
list2.add(input4); list2.add(input4);
@ -68,10 +68,10 @@ public void testEquals() {
@Test @Test
public void testGetInputs() { public void testGetInputs() {
MIntegerInput intInput = new MIntegerInput("Form.A"); MIntegerInput intInput = new MIntegerInput("Form.A", false);
MMapInput mapInput = new MMapInput("Form.B"); MMapInput mapInput = new MMapInput("Form.B", false);
MStringInput stringInput = new MStringInput("Form.C", false, (short)3); MStringInput stringInput = new MStringInput("Form.C", false, (short)3);
MEnumInput enumInput = new MEnumInput("Form.D", new String[] {"I", "V"}); MEnumInput enumInput = new MEnumInput("Form.D", false, new String[] {"I", "V"});
List<MInput<?>> inputs = new ArrayList<MInput<?>>(); List<MInput<?>> inputs = new ArrayList<MInput<?>>();
inputs.add(intInput); inputs.add(intInput);

View File

@ -33,8 +33,8 @@ public class TestMFormList {
public void testGetInputs() { public void testGetInputs() {
List<MForm> forms = new LinkedList<MForm>(); List<MForm> forms = new LinkedList<MForm>();
MIntegerInput intInput = new MIntegerInput("Form1.A"); MIntegerInput intInput = new MIntegerInput("Form1.A", false);
MMapInput mapInput = new MMapInput("Form1.B"); MMapInput mapInput = new MMapInput("Form1.B", false);
List<MInput<?>> inputs = new ArrayList<MInput<?>>(); List<MInput<?>> inputs = new ArrayList<MInput<?>>();
inputs.add(intInput); inputs.add(intInput);
@ -42,7 +42,7 @@ public void testGetInputs() {
forms.add(new MForm("Form1", inputs)); forms.add(new MForm("Form1", inputs));
MStringInput stringInput = new MStringInput("Form2.C", false, (short)3); MStringInput stringInput = new MStringInput("Form2.C", false, (short)3);
MEnumInput enumInput = new MEnumInput("Form2.D", new String[] {"I", "V"}); MEnumInput enumInput = new MEnumInput("Form2.D", false, new String[] {"I", "V"});
inputs = new ArrayList<MInput<?>>(); inputs = new ArrayList<MInput<?>>();
inputs.add(stringInput); inputs.add(stringInput);

View File

@ -33,7 +33,7 @@ public class TestMIntegerInput {
*/ */
@Test @Test
public void testInitialization() { public void testInitialization() {
MIntegerInput input = new MIntegerInput("sqoopsqoop"); MIntegerInput input = new MIntegerInput("sqoopsqoop", false);
assertEquals("sqoopsqoop", input.getName()); assertEquals("sqoopsqoop", input.getName());
assertEquals(MInputType.INTEGER, input.getType()); assertEquals(MInputType.INTEGER, input.getType());
} }
@ -44,13 +44,13 @@ public void testInitialization() {
@Test @Test
public void testEquals() { public void testEquals() {
// Positive test // Positive test
MIntegerInput input1 = new MIntegerInput("sqoopsqoop"); MIntegerInput input1 = new MIntegerInput("sqoopsqoop", false);
MIntegerInput input2 = new MIntegerInput("sqoopsqoop"); MIntegerInput input2 = new MIntegerInput("sqoopsqoop", false);
assertTrue(input1.equals(input2)); assertTrue(input1.equals(input2));
// Negative test // Negative test
MIntegerInput input3 = new MIntegerInput("sqoopsqoop"); MIntegerInput input3 = new MIntegerInput("sqoopsqoop", false);
MIntegerInput input4 = new MIntegerInput("sqoopsqoop1"); MIntegerInput input4 = new MIntegerInput("sqoopsqoop1", false);
assertFalse(input3.equals(input4)); assertFalse(input3.equals(input4));
} }
@ -59,7 +59,7 @@ public void testEquals() {
*/ */
@Test @Test
public void testValue() { public void testValue() {
MIntegerInput input1 = new MIntegerInput("sqoopsqoop"); MIntegerInput input1 = new MIntegerInput("sqoopsqoop", false);
input1.setValue(99); input1.setValue(99);
assertEquals(new Integer(99), input1.getValue()); assertEquals(new Integer(99), input1.getValue());
input1.setEmpty(); input1.setEmpty();
@ -71,7 +71,7 @@ public void testValue() {
*/ */
@Test @Test
public void testUrlSafe() { public void testUrlSafe() {
MIntegerInput input1 = new MIntegerInput("sqoopsqoop"); MIntegerInput input1 = new MIntegerInput("sqoopsqoop", false);
input1.setValue(1001); input1.setValue(1001);
// Getting URL safe string // Getting URL safe string
String tmp = input1.getUrlSafeValueString(); String tmp = input1.getUrlSafeValueString();
@ -89,4 +89,15 @@ public void testNamedElement() {
assertEquals("sqoopsqoop.label", input1.getLabelKey()); assertEquals("sqoopsqoop.label", input1.getLabelKey());
assertEquals("sqoopsqoop.help", input1.getHelpKey()); assertEquals("sqoopsqoop.help", input1.getHelpKey());
} }
/**
* Test for sensitivity
*/
@Test
public void testSensitivity() {
MIntegerInput input1 = new MIntegerInput("NAME", false);
MIntegerInput input2 = new MIntegerInput("NAME", true);
assertFalse(input1.isSensitive());
assertTrue(input2.isSensitive());
}
} }

View File

@ -36,7 +36,7 @@ public class TestMMapInput {
*/ */
@Test @Test
public void testInitialization() { public void testInitialization() {
MMapInput input = new MMapInput("sqoopsqoop"); MMapInput input = new MMapInput("sqoopsqoop", false);
assertEquals("sqoopsqoop", input.getName()); assertEquals("sqoopsqoop", input.getName());
assertEquals(MInputType.MAP, input.getType()); assertEquals(MInputType.MAP, input.getType());
} }
@ -47,13 +47,13 @@ public void testInitialization() {
@Test @Test
public void testEquals() { public void testEquals() {
// Positive test // Positive test
MMapInput input1 = new MMapInput("sqoopsqoop"); MMapInput input1 = new MMapInput("sqoopsqoop", false);
MMapInput input2 = new MMapInput("sqoopsqoop"); MMapInput input2 = new MMapInput("sqoopsqoop", false);
assertTrue(input1.equals(input2)); assertTrue(input1.equals(input2));
// Negative test // Negative test
MMapInput input3 = new MMapInput("sqoopsqoop"); MMapInput input3 = new MMapInput("sqoopsqoop", false);
MMapInput input4 = new MMapInput("sqoopsqoop1"); MMapInput input4 = new MMapInput("sqoopsqoop1", false);
assertFalse(input3.equals(input4)); assertFalse(input3.equals(input4));
} }
@ -62,7 +62,7 @@ public void testEquals() {
*/ */
@Test @Test
public void testValue() { public void testValue() {
MMapInput input1 = new MMapInput("sqoopsqoop"); MMapInput input1 = new MMapInput("sqoopsqoop", false);
Map<String, String> map1 = new HashMap<String, String>(); Map<String, String> map1 = new HashMap<String, String>();
input1.setValue(map1); input1.setValue(map1);
assertEquals(map1, input1.getValue()); assertEquals(map1, input1.getValue());
@ -75,7 +75,7 @@ public void testValue() {
*/ */
@Test @Test
public void testUrlSafe() { public void testUrlSafe() {
MMapInput input1 = new MMapInput("sqoopsqoop"); MMapInput input1 = new MMapInput("sqoopsqoop", false);
Map<String, String> map1 = new HashMap<String, String>(); Map<String, String> map1 = new HashMap<String, String>();
input1.setValue(map1); input1.setValue(map1);
// Getting URL safe string // Getting URL safe string
@ -94,4 +94,15 @@ public void testNamedElement() {
assertEquals("sqoopsqoop.label", input1.getLabelKey()); assertEquals("sqoopsqoop.label", input1.getLabelKey());
assertEquals("sqoopsqoop.help", input1.getHelpKey()); assertEquals("sqoopsqoop.help", input1.getHelpKey());
} }
/**
* Test for sensitivity
*/
@Test
public void testSensitivity() {
MMapInput input1 = new MMapInput("NAME", false);
MMapInput input2 = new MMapInput("NAME", true);
assertFalse(input1.isSensitive());
assertTrue(input2.isSensitive());
}
} }

View File

@ -31,7 +31,7 @@ public class TestMNamedElement {
*/ */
@Test @Test
public void testInitialization() { public void testInitialization() {
MNamedElement named = new MIntegerInput("SQOOP"); MNamedElement named = new MIntegerInput("SQOOP", false);
assertEquals("SQOOP", named.getName()); assertEquals("SQOOP", named.getName());
assertEquals("SQOOP.label", named.getLabelKey()); assertEquals("SQOOP.label", named.getLabelKey());
assertEquals("SQOOP.help", named.getHelpKey()); assertEquals("SQOOP.help", named.getHelpKey());

View File

@ -34,7 +34,7 @@ public void testInitialization() {
short len = 6; short len = 6;
MStringInput input = new MStringInput("sqoopsqoop", true, len); MStringInput input = new MStringInput("sqoopsqoop", true, len);
assertEquals("sqoopsqoop", input.getName()); assertEquals("sqoopsqoop", input.getName());
assertEquals(true, input.isMasked()); assertEquals(true, input.isSensitive());
assertEquals(len, input.getMaxLength()); assertEquals(len, input.getMaxLength());
assertEquals(MInputType.STRING, input.getType()); assertEquals(MInputType.STRING, input.getType());
} }

View File

@ -32,7 +32,7 @@ public class TestMValidatedElement {
*/ */
@Test @Test
public void testInitialization() { public void testInitialization() {
MValidatedElement input = new MIntegerInput("input"); MValidatedElement input = new MIntegerInput("input", false);
assertEquals("input", input.getName()); assertEquals("input", input.getName());
assertEquals(Status.FINE, input.getValidationStatus()); assertEquals(Status.FINE, input.getValidationStatus());
} }
@ -42,7 +42,7 @@ public void testInitialization() {
*/ */
@Test @Test
public void testValidationMessageStatus() { public void testValidationMessageStatus() {
MValidatedElement input = new MIntegerInput("input"); MValidatedElement input = new MIntegerInput("input", false);
// Default status // Default status
assertEquals(Status.FINE, input.getValidationStatus()); assertEquals(Status.FINE, input.getValidationStatus());
// Set status and user message // Set status and user message

View File

@ -1369,13 +1369,12 @@ private void registerFormInputs(long formId, List<MInput<?>> inputs,
baseInputStmt.setLong(2, formId); baseInputStmt.setLong(2, formId);
baseInputStmt.setShort(3, inputIndex++); baseInputStmt.setShort(3, inputIndex++);
baseInputStmt.setString(4, input.getType().name()); baseInputStmt.setString(4, input.getType().name());
baseInputStmt.setBoolean(5, input.isSensitive());
// String specific column(s) // String specific column(s)
if (input.getType().equals(MInputType.STRING)) { if (input.getType().equals(MInputType.STRING)) {
MStringInput strInput = (MStringInput) input; MStringInput strInput = (MStringInput) input;
baseInputStmt.setBoolean(5, strInput.isMasked());
baseInputStmt.setShort(6, strInput.getMaxLength()); baseInputStmt.setShort(6, strInput.getMaxLength());
} else { } else {
baseInputStmt.setNull(5, Types.BOOLEAN);
baseInputStmt.setNull(6, Types.INTEGER); baseInputStmt.setNull(6, Types.INTEGER);
} }
// Enum specific column(s) // Enum specific column(s)
@ -1494,7 +1493,7 @@ public void loadForms(List<MForm> connectionForms,
long inputForm = rsetInput.getLong(3); long inputForm = rsetInput.getLong(3);
short inputIndex = rsetInput.getShort(4); short inputIndex = rsetInput.getShort(4);
String inputType = rsetInput.getString(5); String inputType = rsetInput.getString(5);
boolean inputStrMask = rsetInput.getBoolean(6); boolean inputSensitivity = rsetInput.getBoolean(6);
short inputStrLength = rsetInput.getShort(7); short inputStrLength = rsetInput.getShort(7);
String inputEnumValues = rsetInput.getString(8); String inputEnumValues = rsetInput.getString(8);
String value = rsetInput.getString(9); String value = rsetInput.getString(9);
@ -1504,16 +1503,16 @@ public void loadForms(List<MForm> connectionForms,
MInput input = null; MInput input = null;
switch (mit) { switch (mit) {
case STRING: case STRING:
input = new MStringInput(inputName, inputStrMask, inputStrLength); input = new MStringInput(inputName, inputSensitivity, inputStrLength);
break; break;
case MAP: case MAP:
input = new MMapInput(inputName); input = new MMapInput(inputName, inputSensitivity);
break; break;
case INTEGER: case INTEGER:
input = new MIntegerInput(inputName); input = new MIntegerInput(inputName, inputSensitivity);
break; break;
case ENUM: case ENUM:
input = new MEnumInput(inputName, inputEnumValues.split(",")); input = new MEnumInput(inputName, inputSensitivity, inputEnumValues.split(","));
break; break;
default: default:
throw new SqoopException(DerbyRepoError.DERBYREPO_0006, throw new SqoopException(DerbyRepoError.DERBYREPO_0006,