/** * Update system. * * @param systemID the system id * @return the system record */ public SystemRecord updateSystem(String systemID) { SystemInfo newSystemInfo = new SystemInfo(systemID); SystemRecord systemRecord = newSystemInfo.getSystemRecord(systemID); if (systemID.equals(SYSTEM_ROOT)) { systemsMap = newSystemInfo.systemsMap; } else { SystemRecord oldSystemRecord = systemsMap.get(systemID); if (oldSystemRecord != null) { systemRecord.setButton(oldSystemRecord.getButton()); } systemsMap.put(systemID, systemRecord); } return (systemRecord); }
public SystemInfo deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException, NullPointerException { SystemInfo systemInfo = new SystemInfo(); JsonArray array = null; int length = 0; if (json.getAsJsonObject().has("systems")) { array = json.getAsJsonObject().get("systems").getAsJsonArray(); length = array.size(); } else if (json.getAsJsonObject().has("system")) { length = 1; } LinkedHashMap<String, SystemRecord> systemsMap = new LinkedHashMap<String, SystemRecord>(length); systemInfo.setSystemsMap(systemsMap); if (length == 0) { return systemInfo; } for (int i = 0; i < length; i++) { SystemRecord systemRecord = new SystemRecord(SystemInfo.SYSTEM_ROOT); JsonObject systemObject = (array != null) ? array.get(i).getAsJsonObject() : json.getAsJsonObject().get("system").getAsJsonObject(); JsonElement element; systemRecord.setID( (element = systemObject.get("systemid")).isJsonNull() ? null : element.getAsString()); systemRecord.setSystemType( (element = systemObject.get("systemtype")).isJsonNull() ? null : element.getAsString()); systemRecord.setName( (element = systemObject.get("name")).isJsonNull() ? null : element.getAsString()); systemRecord.setState( (element = systemObject.get("state")).isJsonNull() ? null : element.getAsString()); systemRecord.setStartDate( (element = systemObject.get("started")).isJsonNull() ? null : element.getAsString()); systemRecord.setLastAccess( (element = systemObject.get("lastaccess")).isJsonNull() ? null : element.getAsString()); systemRecord.setLastBackup( (element = systemObject.get("lastbackup")).isJsonNull() ? null : element.getAsString()); systemRecord.setDBUsername( (element = systemObject.get("dbusername")).isJsonNull() ? null : element.getAsString()); systemRecord.setDBPassword( (element = systemObject.get("dbpassword")).isJsonNull() ? null : element.getAsString()); systemRecord.setRepUsername( (element = systemObject.get("repusername")).isJsonNull() ? null : element.getAsString()); systemRecord.setRepPassword( (element = systemObject.get("reppassword")).isJsonNull() ? null : element.getAsString()); systemRecord.setLastMonitored( ((element = systemObject.get("lastmonitored")).isJsonNull()) ? null : element.getAsString()); MonitorLatest monitorLatest = null; if ((element = systemObject.get("monitorlatest")) != null && !element.isJsonNull()) { monitorLatest = APIrestful.getGson().fromJson(element.toString(), MonitorLatest.class); } systemRecord.setMonitorLatest(monitorLatest); String[] nodes = null; if ((element = systemObject.get("nodes")) != null && !element.isJsonNull()) { JsonArray nodesJson = element.getAsJsonArray(); int nodesCount = nodesJson.size(); nodes = new String[nodesCount]; for (int nodesIndex = 0; nodesIndex < nodesCount; nodesIndex++) { nodes[nodesIndex] = nodesJson.get(nodesIndex).getAsString(); } } systemRecord.setNodes(nodes); LinkedHashMap<String, String> properties = new LinkedHashMap<String, String>(); if ((element = systemObject.get("properties")) != null && !element.isJsonNull()) { JsonObject propertiesJson = element.getAsJsonObject(); if ((element = propertiesJson.get(SystemInfo.PROPERTY_EIP)) != null) { properties.put( SystemInfo.PROPERTY_EIP, element.isJsonNull() ? null : element.getAsString()); } if ((element = propertiesJson.get(SystemInfo.PROPERTY_MONYOG)) != null) { properties.put( SystemInfo.PROPERTY_MONYOG, element.isJsonNull() ? null : element.getAsString()); } if ((element = propertiesJson.get(SystemInfo.PROPERTY_PHPMYADMIN)) != null) { properties.put( SystemInfo.PROPERTY_PHPMYADMIN, element.isJsonNull() ? null : element.getAsString()); } if ((element = propertiesJson.get(SystemInfo.PROPERTY_DEFAULTMONITORINTERVAL)) != null) { properties.put( SystemInfo.PROPERTY_DEFAULTMONITORINTERVAL, element.isJsonNull() ? null : element.getAsString()); } if ((element = propertiesJson.get(SystemInfo.PROPERTY_DEFAULTMAXBACKUPCOUNT)) != null) { properties.put( SystemInfo.PROPERTY_DEFAULTMAXBACKUPCOUNT, element.isJsonNull() ? null : element.getAsString()); } if ((element = propertiesJson.get(SystemInfo.PROPERTY_DEFAULTMAXBACKUPSIZE)) != null) { properties.put( SystemInfo.PROPERTY_DEFAULTMAXBACKUPSIZE, element.isJsonNull() ? null : element.getAsString()); } if ((element = propertiesJson.get(SystemInfo.PROPERTY_VERSION)) != null) { properties.put( SystemInfo.PROPERTY_VERSION, element.isJsonNull() ? null : element.getAsString()); } if ((element = propertiesJson.get(SystemInfo.PROPERTY_SKIPLOGIN)) != null) { properties.put( SystemInfo.PROPERTY_SKIPLOGIN, element.isJsonNull() ? null : element.getAsString()); } } systemRecord.setProperties(properties); systemsMap.put(systemRecord.getID(), systemRecord); } if (array != null) { // create a "ROOT" system record to contain the series of flat systems; in a hierarchical // organization of systems, this might be provided by the API SystemRecord rootRecord = new SystemRecord(null); rootRecord.setID(SystemInfo.SYSTEM_ROOT); rootRecord.setName("Root"); String[] systems = new String[systemsMap.keySet().size()]; int i = 0; for (String systemID : systemsMap.keySet()) { systems[i++] = systemID; } rootRecord.setNodes(systems); systemsMap.put(SystemInfo.SYSTEM_ROOT, rootRecord); } return systemInfo; }