mirror of
https://github.com/apache/sqoop.git
synced 2025-05-11 22:41:50 +08:00
SQOOP-1688: Sqoop2: Fix the Validation Response JSON for configs
(Veena Basavaraj via Abraham Elmahrek)
This commit is contained in:
parent
f9b53acf52
commit
a4ade07f8b
@ -33,10 +33,10 @@
|
|||||||
*/
|
*/
|
||||||
public class ValidationResultBean implements JsonBean {
|
public class ValidationResultBean implements JsonBean {
|
||||||
|
|
||||||
private static final String ROOT = "ROOT";
|
private static final String VALIDATION_RESULT = "validation-result";
|
||||||
private static final String ID = "ID";
|
private static final String ID = "id";
|
||||||
private static final String STATUS = "STATUS";
|
private static final String STATUS = "status";
|
||||||
private static final String TEXT = "TEXT";
|
private static final String MESSAGE = "message";
|
||||||
|
|
||||||
private ConfigValidationResult[] results;
|
private ConfigValidationResult[] results;
|
||||||
private Long id;
|
private Long id;
|
||||||
@ -61,6 +61,7 @@ public Long getId() {
|
|||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public JSONObject extract(boolean skipSensitive) {
|
public JSONObject extract(boolean skipSensitive) {
|
||||||
JSONArray array = new JSONArray();
|
JSONArray array = new JSONArray();
|
||||||
@ -71,16 +72,16 @@ public JSONObject extract(boolean skipSensitive) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
JSONObject object = new JSONObject();
|
JSONObject object = new JSONObject();
|
||||||
object.put(ROOT, array);
|
object.put(VALIDATION_RESULT, array);
|
||||||
if(id != null) {
|
if(id != null) {
|
||||||
object.put(ID, id);
|
object.put(ID, id);
|
||||||
}
|
}
|
||||||
return object;
|
return object;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
private JSONObject extractValidationResult(ConfigValidationResult result) {
|
private JSONObject extractValidationResult(ConfigValidationResult result) {
|
||||||
JSONObject ret = new JSONObject();
|
JSONObject ret = new JSONObject();
|
||||||
|
|
||||||
for(Map.Entry<String, List<Message>> entry : result.getMessages().entrySet()) {
|
for(Map.Entry<String, List<Message>> entry : result.getMessages().entrySet()) {
|
||||||
ret.put(entry.getKey(), extractMessageList(entry.getValue()));
|
ret.put(entry.getKey(), extractMessageList(entry.getValue()));
|
||||||
}
|
}
|
||||||
@ -88,6 +89,7 @@ private JSONObject extractValidationResult(ConfigValidationResult result) {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
private Object extractMessageList(List<Message> messages) {
|
private Object extractMessageList(List<Message> messages) {
|
||||||
JSONArray array = new JSONArray();
|
JSONArray array = new JSONArray();
|
||||||
|
|
||||||
@ -98,34 +100,32 @@ private Object extractMessageList(List<Message> messages) {
|
|||||||
return array;
|
return array;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
private Object extractMessage(Message message) {
|
private Object extractMessage(Message message) {
|
||||||
JSONObject ret = new JSONObject();
|
JSONObject ret = new JSONObject();
|
||||||
|
|
||||||
ret.put(STATUS, message.getStatus().toString());
|
ret.put(STATUS, message.getStatus().toString());
|
||||||
ret.put(TEXT, message.getMessage());
|
ret.put(MESSAGE, message.getMessage());
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void restore(JSONObject jsonObject) {
|
public void restore(JSONObject jsonObject) {
|
||||||
JSONArray array = (JSONArray) jsonObject.get(ROOT);
|
JSONArray array = (JSONArray) jsonObject.get(VALIDATION_RESULT);
|
||||||
results = new ConfigValidationResult[array.size()];
|
results = new ConfigValidationResult[array.size()];
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for(Object item : array) {
|
for(Object item : array) {
|
||||||
results[i++] = restoreValidationResult((JSONObject) item);
|
results[i++] = restoreValidationResult((JSONObject) item);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(jsonObject.containsKey(ID)) {
|
if(jsonObject.containsKey(ID)) {
|
||||||
id = (Long) jsonObject.get(ID);
|
id = (Long) jsonObject.get(ID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
private ConfigValidationResult restoreValidationResult(JSONObject item) {
|
private ConfigValidationResult restoreValidationResult(JSONObject item) {
|
||||||
ConfigValidationResult result = new ConfigValidationResult();
|
ConfigValidationResult result = new ConfigValidationResult();
|
||||||
Set<Map.Entry<String, JSONArray>> entrySet = item.entrySet();
|
Set<Map.Entry<String, JSONArray>> entrySet = item.entrySet();
|
||||||
|
|
||||||
for(Map.Entry<String, JSONArray> entry : entrySet) {
|
for(Map.Entry<String, JSONArray> entry : entrySet) {
|
||||||
result.addMessages(entry.getKey(), restoreMessageList(entry.getValue()));
|
result.addMessages(entry.getKey(), restoreMessageList(entry.getValue()));
|
||||||
}
|
}
|
||||||
@ -136,18 +136,16 @@ private ConfigValidationResult restoreValidationResult(JSONObject item) {
|
|||||||
|
|
||||||
private List<Message> restoreMessageList(JSONArray array) {
|
private List<Message> restoreMessageList(JSONArray array) {
|
||||||
List<Message> messages = new LinkedList<Message>();
|
List<Message> messages = new LinkedList<Message>();
|
||||||
|
|
||||||
for(Object item : array) {
|
for(Object item : array) {
|
||||||
messages.add(restoreMessage((JSONObject)item));
|
messages.add(restoreMessage((JSONObject)item));
|
||||||
}
|
}
|
||||||
|
|
||||||
return messages;
|
return messages;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Message restoreMessage(JSONObject item) {
|
private Message restoreMessage(JSONObject item) {
|
||||||
return new Message(
|
return new Message(
|
||||||
Status.valueOf((String) item.get(STATUS)),
|
Status.valueOf((String) item.get(STATUS)),
|
||||||
(String) item.get(TEXT)
|
(String) item.get(MESSAGE)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user