IntegrityUtil integrityUtil = new IntegrityUtil();
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//Structures tab data
JSONArray tabResponse = null;
JSONObject errorContent = null;
IntegrityType[] types = IntegrityType.values();
boolean isThereAnyConflict = false;
for (IntegrityType integrityType : types) {
tabResponse = new JSONArray();
errorContent = new JSONObject();
errorContent.put( "title", LanguageUtil.get( initData.getUser().getLocale(), integrityType.getLabel() ) );//Title of the check
List<Map<String, Object>> results = integrityUtil.getIntegrityConflicts(endpointId, integrityType);
JSONArray columns = new JSONArray();
switch (integrityType) {
case STRUCTURES:
columns.add("velocity_name");
break;
case FOLDERS:
columns.add("folder");
break;
case SCHEMES:
columns.add("name");
break;
}
columns.add("local_inode");
columns.add("remote_inode");
errorContent.put( "columns", columns.toArray() );
if(!results.isEmpty()) {
// the columns names are the keys in the results
isThereAnyConflict = isThereAnyConflict || true;
JSONArray values = new JSONArray();
for (Map<String, Object> result : results) {
JSONObject columnsContent = new JSONObject();
for (String keyName : result.keySet()) {
columnsContent.put(keyName, result.get(keyName));
}
values.put(columnsContent);
}
errorContent.put( "values", values.toArray() );
} else {
errorContent.put( "values", new JSONArray().toArray() );
}
tabResponse.add( errorContent );
//And prepare the response
jsonResponse.put( integrityType.name().toLowerCase(), tabResponse.toArray() );