MCPcopy Index your code
hub / github.com/OpenTSDB/opentsdb / parseTreeV1

Method parseTreeV1

src/tsd/HttpJsonSerializer.java:350–402  ·  view source on GitHub ↗

Parses a single Tree object Note: Incoming data is a hash map of strings instead of directly deserializing to a tree. We do it this way because we don't want users messing with the timestamp fields. @return A parsed Tree @throws JSONException if parsing failed @throws BadRequestException if t

()

Source from the content-addressed store, hash-verified

348 * @throws BadRequestException if the content was missing or parsing failed
349 */
350 public Tree parseTreeV1() {
351 final String json = query.getContent();
352 if (json == null || json.isEmpty()) {
353 throw new BadRequestException(HttpResponseStatus.BAD_REQUEST,
354 "Missing message content",
355 "Supply valid JSON formatted data in the body of your request");
356 }
357 try {
358 final HashMap<String, String> properties =
359 JSON.parseToObject(json, TR_HASH_MAP);
360
361 final Tree tree = new Tree();
362 for (Map.Entry<String, String> entry : properties.entrySet()) {
363 // skip nulls, empty is fine, but nulls are not welcome here
364 if (entry.getValue() == null) {
365 continue;
366 }
367
368 if (entry.getKey().toLowerCase().equals("treeid")) {
369 tree.setTreeId(Integer.parseInt(entry.getValue()));
370 } else if (entry.getKey().toLowerCase().equals("name")) {
371 tree.setName(entry.getValue());
372 } else if (entry.getKey().toLowerCase().equals("description")) {
373 tree.setDescription(entry.getValue());
374 } else if (entry.getKey().toLowerCase().equals("notes")) {
375 tree.setNotes(entry.getValue());
376 } else if (entry.getKey().toLowerCase().equals("enabled")) {
377 if (entry.getValue().toLowerCase().equals("true")) {
378 tree.setEnabled(true);
379 } else {
380 tree.setEnabled(false);
381 }
382 } else if (entry.getKey().toLowerCase().equals("strictmatch")) {
383 if (entry.getValue().toLowerCase().equals("true")) {
384 tree.setStrictMatch(true);
385 } else {
386 tree.setStrictMatch(false);
387 }
388 } else if (entry.getKey().toLowerCase().equals("storefailures")) {
389 if (entry.getValue().toLowerCase().equals("true")) {
390 tree.setStoreFailures(true);
391 } else {
392 tree.setStoreFailures(false);
393 }
394 }
395 }
396 return tree;
397 } catch (NumberFormatException nfe) {
398 throw new BadRequestException("Unable to parse 'tree' value");
399 } catch (IllegalArgumentException iae) {
400 throw new BadRequestException("Unable to parse the given JSON", iae);
401 }
402 }
403
404 /**
405 * Parses a single TreeRule object

Callers

nothing calls this directly

Calls 13

parseToObjectMethod · 0.95
setTreeIdMethod · 0.95
setNameMethod · 0.95
setDescriptionMethod · 0.95
setNotesMethod · 0.95
setEnabledMethod · 0.95
setStrictMatchMethod · 0.95
setStoreFailuresMethod · 0.95
isEmptyMethod · 0.80
getContentMethod · 0.45
getValueMethod · 0.45
equalsMethod · 0.45

Tested by

no test coverage detected