public JSONObject removeNode(String id) { JSONObject result = new JSONObject(); JSONObject targetElement = this.elementCache.get(id); JSONObject parent = this.parentCache.get(id); JSONArray children = parent.getJSONArray("children"); if (children != null && !children.isEmpty()) { int targetIndex = -1; int targetCount = 0; for (int i = 0; i < children.size(); i++) { JSONObject child = (JSONObject) children.get(i); if (child.getString("id").equals(id)) { targetIndex = i; } } if (targetIndex >= 0) { children.remove(targetIndex); this.elementCache.remove(id); this.parentCache.remove(id); } result = result.element("id", id); } else { result = result.element("error", "could not find target element"); } this.saveMappings(); return result; }
private void removeConditionClause(JSONArray clauses, String path) { if (path.length() > 0) { if (path.contains(".")) { String[] parts = path.split("\\.", 2); int index = Integer.parseInt(parts[0]); if (parts[1].length() > 0) { removeConditionClause(clauses.getJSONObject(index), parts[1]); } else { clauses.remove(index); } } else { int index = Integer.parseInt(path); clauses.remove(index); } } }
public void removeMappings(JSONObject target, int index) { JSONArray mappings = target.getJSONArray("mappings"); target.remove("warning"); if (index > -1) { mappings.remove(index); } }
@Override public void syncSharedConnectorSettings( final long apiKeyId, final SharedConnector sharedConnector) { JSONObject jsonSettings = new JSONObject(); if (sharedConnector.filterJson != null) jsonSettings = JSONObject.fromObject(sharedConnector.filterJson); // get calendars, add new configs for new calendars... // we use the data in the connector settings, which have either just been synched (see // UpdateWorker's syncSettings) // or were synched when the connector was last updated; in either cases, we know that the data // is up-to-date final GoogleCalendarConnectorSettings connectorSettings = (GoogleCalendarConnectorSettings) settingsService.getConnectorSettings(apiKeyId); final List<CalendarConfig> calendars = connectorSettings.calendars; JSONArray sharingSettingsCalendars = new JSONArray(); if (jsonSettings.has("calendars")) sharingSettingsCalendars = jsonSettings.getJSONArray("calendars"); there: for (CalendarConfig calendarConfig : calendars) { for (int i = 0; i < sharingSettingsCalendars.size(); i++) { JSONObject sharingSettingsCalendar = sharingSettingsCalendars.getJSONObject(i); if (sharingSettingsCalendar.getString("id").equals(calendarConfig.id)) continue there; } JSONObject sharingConfig = new JSONObject(); sharingConfig.accumulate("id", calendarConfig.id); sharingConfig.accumulate("summary", calendarConfig.summary); sharingConfig.accumulate("description", calendarConfig.description); sharingConfig.accumulate("shared", false); sharingSettingsCalendars.add(sharingConfig); } // and remove configs for deleted notebooks - leave others untouched JSONArray settingsToDelete = new JSONArray(); there: for (int i = 0; i < sharingSettingsCalendars.size(); i++) { JSONObject sharingSettingsCalendar = sharingSettingsCalendars.getJSONObject(i); for (CalendarConfig calendarConfig : calendars) { if (sharingSettingsCalendar.getString("id").equals(calendarConfig.id)) continue there; } settingsToDelete.add(sharingSettingsCalendar); } for (int i = 0; i < settingsToDelete.size(); i++) { JSONObject toDelete = settingsToDelete.getJSONObject(i); for (int j = 0; j < sharingSettingsCalendars.size(); j++) { if (sharingSettingsCalendars .getJSONObject(j) .getString("id") .equals(toDelete.getString("id"))) { sharingSettingsCalendars.remove(j); } } } jsonSettings.put("calendars", sharingSettingsCalendars); String toPersist = jsonSettings.toString(); coachingService.setSharedConnectorFilter(sharedConnector.getId(), toPersist); }