(CommandLine cli)
| 93 | } |
| 94 | |
| 95 | @Override |
| 96 | public void runImpl(CommandLine cli) throws Exception { |
| 97 | String solrUrl = CLIUtils.normalizeSolrUrl(cli); |
| 98 | String action = cli.getOptionValue(ACTION_OPTION, "set-property"); |
| 99 | String collection = cli.getOptionValue(COLLECTION_NAME_OPTION); |
| 100 | String property = cli.getOptionValue(PROPERTY_OPTION); |
| 101 | String value = cli.getOptionValue(VALUE_OPTION); |
| 102 | |
| 103 | // value is required unless the property is one of the "unset-" type. |
| 104 | if (!action.contains("unset-") && value == null) { |
| 105 | throw new MissingArgumentException("'value' is a required option."); |
| 106 | } |
| 107 | Map<String, Object> jsonObj = new HashMap<>(); |
| 108 | if (value != null) { |
| 109 | Map<String, String> setMap = new HashMap<>(); |
| 110 | setMap.put(property, value); |
| 111 | jsonObj.put(action, setMap); |
| 112 | } else { |
| 113 | jsonObj.put(action, property); |
| 114 | } |
| 115 | |
| 116 | CharArr arr = new CharArr(); |
| 117 | (new JSONWriter(arr, 0)).write(jsonObj); |
| 118 | String jsonBody = arr.toString(); |
| 119 | |
| 120 | String updatePath = "/" + collection + "/config"; |
| 121 | |
| 122 | echo("\nPOSTing request to Config API: " + solrUrl + updatePath); |
| 123 | echoIfVerbose(jsonBody); |
| 124 | |
| 125 | try (SolrClient solrClient = |
| 126 | CLIUtils.getSolrClient(solrUrl, cli.getOptionValue(CommonCLIOptions.CREDENTIALS_OPTION))) { |
| 127 | NamedList<Object> result = SolrCLI.postJsonToSolr(solrClient, updatePath, jsonBody); |
| 128 | Integer statusCode = (Integer) result._get(List.of("responseHeader", "status"), null); |
| 129 | if (statusCode == 0) { |
| 130 | if (value != null) { |
| 131 | echo("Successfully " + action + " " + property + " to " + value); |
| 132 | } else { |
| 133 | echo("Successfully " + action + " " + property); |
| 134 | } |
| 135 | } else { |
| 136 | throw new Exception("Failed to " + action + " property due to:\n" + result); |
| 137 | } |
| 138 | } |
| 139 | } |
| 140 | } |
nothing calls this directly
no test coverage detected