*/
public class ParseJsonObjects {
private static Logger log = Logger.getLogger(ParseJsonObjects.class.getName());
public static Alert parseAlertJson(JSONObject jsonAlert, String id, String accountName) throws JSONException {
BasicAlert parsedAlert = null;
/*
* {"alertWarningValue":15,"alertDelay":5,"alertType":null,"alertErrorValue":12,"alertActivated":true,"alertName":"Test"}
*/
if (jsonAlert.has("alert")) {
parsedAlert = new BasicAlert();
JSONObject alert = jsonAlert.getJSONObject("alert");
if (id == null || id.length() == 0) {
parsedAlert.setAlertName(parseStringFromJson(alert, "id"));
} else {
parsedAlert.setAlertName(id);
}
parsedAlert.setWarningValue(parseDoubleFromJson(alert, "alertWarningValue"));
parsedAlert.setErrorValue(parseDoubleFromJson(alert, "alertErrorValue"));
parsedAlert.setGuiPath(parseStringFromJson(alert, "alertSource"));
Integer alertDelay = parseIntegerFromJson(alert, "alertDelay");
if (alertDelay == null) { alertDelay = 0; }
parsedAlert.setAlertDelay(alertDelay.longValue());
parsedAlert.setActivated(parseBooleanFromJson(alert, "alertActivated"));
parsedAlert.setSelectedAlertType(AlertType.fromValue(parseStringFromJson(alert, "alertType")));
parsedAlert.setSelectedEmailSenderList(getStringArrayFromJson(alert, "alertNotifications"));
parsedAlert.setSelectedAlertPluginList(getStringArrayFromJson(alert, "alertPlugins"));
parsedAlert.setAccountName(accountName);
}
log.info("alertName: " + parsedAlert.getAlertName() + " account: " + parsedAlert.getAccountName());
return parsedAlert;
}