private @Nullable DNSZone toZone(@Nonnull ProviderContext ctx, @Nullable JSONObject json) throws CloudException, InternalException { if (json == null) { return null; } try { String zoneId = (json.has("id") ? json.getString("id") : null); if (zoneId == null) { return null; } String name = (json.has("name") ? json.getString("name") : null); if (name == null) { return null; } String description = (json.has("comment") ? json.getString("comment") : null); if (description == null) { description = name; } JSONArray nameservers = (json.has("nameservers") ? json.getJSONArray("nameservers") : null); DNSZone zone = new DNSZone(); zone.setDescription(description); zone.setDomainName(name); zone.setName(name); zone.setProviderDnsZoneId(zoneId); zone.setProviderOwnerId(getTenantId()); if (nameservers != null) { String[] ns = new String[nameservers.length()]; for (int i = 0; i < nameservers.length(); i++) { JSONObject ob = nameservers.getJSONObject(i); if (ob.has("name")) { ns[i] = ob.getString("name"); } } zone.setNameservers(ns); } else { zone.setNameservers(new String[0]); } return zone; } catch (JSONException e) { throw new CloudException(e); } }
private void listSubdomains( @Nonnull ProviderContext ctx, @Nonnull List<DNSZone> intoList, @Nonnull DNSZone parent, @Nonnull JSONArray subdomains) throws CloudException, InternalException { try { for (int i = 0; i < subdomains.length(); i++) { DNSZone z = toZone(ctx, subdomains.getJSONObject(i)); if (z != null) { z.setNameservers(parent.getNameservers()); intoList.add(z); } } } catch (JSONException e) { throw new CloudException(e); } }