@Override public synchronized boolean configure(StaplerRequest req, JSONObject formData) throws FormException { // The following codes are bad... // How to bind formData to List<Discriptor> ? if (nexusMap == null) { nexusMap = new HashMap<String, NexusDescriptor>(); } try { JSONObject json = formData.getJSONObject("nexusList"); nexusMap.clear(); NexusDescriptor desc = parse(json); nexusMap.put(desc.getName(), desc); } catch (JSONException e) { try { JSONArray jsons = formData.getJSONArray("nexusList"); nexusMap.clear(); for (Object json : jsons) { NexusDescriptor desc = parse((JSONObject) json); nexusMap.put(desc.getName(), desc); } } catch (JSONException ee) { // exec in this path only if nexusList is empty. } } save(); return super.configure(req, formData); }
public String getSelected() { if (selectedNexus != null) { return selectedNexus.getName(); } else { return "hoge"; } }
public String getTasksAsJson() { Map<String, List<String>> taskNameLists = new HashMap<String, List<String>>(); for (NexusDescriptor desc : nexusMap.values()) { NexusClient client = new NexusJerseyClient(desc.getUrl(), desc.getUser(), desc.getPassword()); client.init(); if (client.ping()) { List<ScheduledServiceListResource> serviceList = client.get("schedules", ScheduledServiceListResourceResponse.class).getData(); if (serviceList != null && serviceList.size() > 0) { List<String> serviceNameList = new ArrayList<String>(); for (ScheduledServiceListResource servise : serviceList) { serviceNameList.add(servise.getName()); } taskNameLists.put(desc.getName(), serviceNameList); } } } return JSONObject.fromObject(taskNameLists).toString(); }