List of usage examples for com.google.gson JsonObject getAsJsonPrimitive
public JsonPrimitive getAsJsonPrimitive(String memberName)
From source file:org.opendaylight.vtn.javaapi.validation.logical.LabelRangeResourceValidator.java
License:Open Source License
/** * Checks if is valid get request.//from www .ja va2s.c om * * @param requestBody * the request JSON object * @return true, if is valid get */ private boolean validGet(final JsonObject requestBody, final boolean opFlag) { LOG.trace("Start LabelRangeResourceValidator#isValidGet"); boolean isValid = true; // validation for key: tagetdb setInvalidParameter(VtnServiceJsonConsts.TARGETDB); isValid = validator.isValidRequestDB(requestBody); /* * Remove unwanted parameters from request body for Show APIs */ if (!opFlag) { if (requestBody.has(VtnServiceJsonConsts.OP)) { requestBody.remove(VtnServiceJsonConsts.OP); } else { LOG.debug("No need to remove"); } if (requestBody.has(VtnServiceJsonConsts.INDEX)) { requestBody.remove(VtnServiceJsonConsts.INDEX); } else { LOG.debug("No need to remove"); } if (requestBody.has(VtnServiceJsonConsts.MAX)) { requestBody.remove(VtnServiceJsonConsts.MAX); } else { LOG.debug("No need to remove"); } } else { // validation for key: op if (isValid) { setInvalidParameter(VtnServiceJsonConsts.OP); isValid = validator.isValidOperation(requestBody); } // validation for key: index if (isValid && requestBody.has(VtnServiceJsonConsts.INDEX) && requestBody.get(VtnServiceJsonConsts.INDEX).isJsonPrimitive()) { setInvalidParameter(VtnServiceJsonConsts.INDEX); isValid = isValidRangeId(requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.INDEX).getAsString()); } // validation for key: max_repitition if (isValid) { setInvalidParameter(VtnServiceJsonConsts.MAX); isValid = validator.isValidMaxRepetition(requestBody); } } LOG.trace("Complete LabelRangeResourceValidator#isValidGet"); return isValid; }
From source file:org.opendaylight.vtn.javaapi.validation.logical.LabelResourceValidator.java
License:Open Source License
/** * Validate put request Json object for Lable API * /* w ww. ja v a 2 s. c om*/ * @param requestBody * the request Json object * @return true, if successful */ private boolean validatePut(final JsonObject requestBody) { LOG.trace("Start LabelResourceValidator#validatePut()"); boolean isValid = true; setInvalidParameter(VtnServiceJsonConsts.LABEL); if (requestBody.has(VtnServiceJsonConsts.LABEL) && requestBody.get(VtnServiceJsonConsts.LABEL).isJsonObject()) { final JsonObject lable = requestBody.getAsJsonObject(VtnServiceJsonConsts.LABEL); // validation for key: max_count setInvalidParameter(VtnServiceJsonConsts.MAX_COUNT); if (lable.has(VtnServiceJsonConsts.MAX_COUNT)) { if (lable.get(VtnServiceJsonConsts.MAX_COUNT).isJsonPrimitive()) { isValid = validator.isValidRange( lable.getAsJsonPrimitive(VtnServiceJsonConsts.MAX_COUNT).getAsString(), VtnServiceJsonConsts.VAL_1, VtnServiceJsonConsts.VAL_4000); } else { isValid = false; } } // validation for key: raising_threshold if (isValid) { setInvalidParameter(VtnServiceJsonConsts.RISING_THRESHOLD); if (lable.has(VtnServiceJsonConsts.RISING_THRESHOLD)) { if (lable.get(VtnServiceJsonConsts.RISING_THRESHOLD).isJsonPrimitive()) { isValid = validator.isValidRange( lable.getAsJsonPrimitive(VtnServiceJsonConsts.RISING_THRESHOLD).getAsString(), VtnServiceJsonConsts.VAL_1, VtnServiceJsonConsts.VAL_4000); } else { isValid = false; } } } // validation for key: falling_threshold if (isValid) { setInvalidParameter(VtnServiceJsonConsts.FALLING_THRESHOLD); if (lable.has(VtnServiceJsonConsts.FALLING_THRESHOLD)) { if (lable.get(VtnServiceJsonConsts.FALLING_THRESHOLD).isJsonPrimitive()) { isValid = validator.isValidRange( lable.getAsJsonPrimitive(VtnServiceJsonConsts.FALLING_THRESHOLD).getAsString(), VtnServiceJsonConsts.VAL_1, VtnServiceJsonConsts.VAL_4000); } else { isValid = false; } } } } else { isValid = false; } LOG.trace("Complete LabelResourceValidator#validatePut()"); return isValid; }
From source file:org.opendaylight.vtn.javaapi.validation.logical.LabelResourceValidator.java
License:Open Source License
/** * Validate post request Json object for Label API * /*from w w w.j a v a 2 s . c om*/ * @param requestBody * the request Json object * @return true, if successful */ private boolean validatePost(final JsonObject requestBody) { LOG.trace("Start LabelResourceValidator#validatePost()"); boolean isValid = false; setInvalidParameter(VtnServiceJsonConsts.LABEL); if (requestBody.has(VtnServiceJsonConsts.LABEL) && requestBody.get(VtnServiceJsonConsts.LABEL).isJsonObject()) { final JsonObject lable = requestBody.getAsJsonObject(VtnServiceJsonConsts.LABEL); // validation for mandatory key: label_name setInvalidParameter(VtnServiceJsonConsts.LABEL_NAME); if (lable.has(VtnServiceJsonConsts.LABEL_NAME) && lable.get(VtnServiceJsonConsts.LABEL_NAME).isJsonPrimitive()) { String labelName = lable.getAsJsonPrimitive(VtnServiceJsonConsts.LABEL_NAME).getAsString(); if (!labelName.isEmpty()) { isValid = validator.isValidMaxLengthAlphaNum(labelName, VtnServiceJsonConsts.LEN_31); } } if (isValid) { isValid = validatePut(requestBody); } } LOG.trace("Complete LabelResourceValidator#validatePost()"); return isValid; }
From source file:org.opendaylight.vtn.javaapi.validation.logical.MacEntryResourceValidator.java
License:Open Source License
/** * Validate get request Json object for MacEntryResource * // ww w . j av a 2 s . c o m * @param requestBody * the request Json object * @return true, if successful */ private boolean validateGet(final JsonObject requestBody) { LOG.trace("Start MacEntryResourceValidator#validateGet()"); boolean isValid = true; // validation for key: op setInvalidParameter(VtnServiceJsonConsts.OP); isValid = validator.isValidOperationForCount(requestBody); // validation for key: type if (isValid) { setInvalidParameter(VtnServiceJsonConsts.TYPE); if (requestBody.has(VtnServiceJsonConsts.TYPE) && requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.TYPE).getAsString() != null) { final String type = requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.TYPE).getAsString(); isValid = type.equalsIgnoreCase(VtnServiceJsonConsts.STATIC) || type.equalsIgnoreCase(VtnServiceJsonConsts.DYNAMIC); } } LOG.trace("Complete MacEntryResourceValidator#validateGet()"); return isValid; }
From source file:org.opendaylight.vtn.javaapi.validation.logical.PolicingProfileResourceValidator.java
License:Open Source License
/** * Validate post request JSON object for Policing Profile API * /* w w w .j ava 2 s . c om*/ * @param requestBody * the request JSON object * @return true, if successful */ private boolean validatePost(final JsonObject requestBody) { LOG.trace("Start PolicingProfileResourceValidator#validatePost()"); boolean isValid = false; setInvalidParameter(VtnServiceJsonConsts.POLICINGPROFILE); if (requestBody.has(VtnServiceJsonConsts.POLICINGPROFILE) && requestBody.get(VtnServiceJsonConsts.POLICINGPROFILE).isJsonObject()) { final JsonObject policingProfileJsonObject = requestBody .getAsJsonObject(VtnServiceJsonConsts.POLICINGPROFILE); setInvalidParameter(VtnServiceJsonConsts.PROFILE_NAME); // validation for mandatory key: prf_name if (policingProfileJsonObject.has(VtnServiceJsonConsts.PROFILE_NAME) && policingProfileJsonObject .getAsJsonPrimitive(VtnServiceJsonConsts.PROFILE_NAME).getAsString() != null) { isValid = validator.isValidMaxLengthAlphaNum(policingProfileJsonObject .getAsJsonPrimitive(VtnServiceJsonConsts.PROFILE_NAME).getAsString(), VtnServiceJsonConsts.LEN_32); } } LOG.trace("Complete PolicingProfileResourceValidator#validatePost()"); return isValid; }
From source file:org.opendaylight.vtn.javaapi.validation.logical.PolicingProfilesEntriesResourceValidation.java
License:Open Source License
/** * /* validate put request Json object for PolicingProfilesEntries * // ww w . j av a 2s . co m * @param requestBody * the request Json object * @return true, if successful */ private boolean validatePut(JsonObject requestBody) { LOG.trace("Start PolicingProfilesEntriesValidation#validatePut()"); boolean isValid = false; setInvalidParameter(VtnServiceJsonConsts.POLCINGPROFILEENTRY); if (requestBody.has(VtnServiceJsonConsts.POLCINGPROFILEENTRY) && requestBody.get(VtnServiceJsonConsts.POLCINGPROFILEENTRY).isJsonObject()) { final JsonObject profileEntryJson = requestBody .getAsJsonObject(VtnServiceJsonConsts.POLCINGPROFILEENTRY); // validation for key: fl_name setInvalidParameter(VtnServiceJsonConsts.FLNAME); if (profileEntryJson.has(VtnServiceJsonConsts.FLNAME) && profileEntryJson.getAsJsonPrimitive(VtnServiceJsonConsts.FLNAME).getAsString() != null && !profileEntryJson.get(VtnServiceJsonConsts.FLNAME).getAsString().isEmpty()) { isValid = validator.isValidMaxLengthAlphaNum( profileEntryJson.getAsJsonPrimitive(VtnServiceJsonConsts.FLNAME).getAsString(), VtnServiceJsonConsts.LEN_32); } // validation for tworatethreecolor (optional) if (isValid) { setInvalidParameter(VtnServiceJsonConsts.TWORATETHREECOLOR); if (profileEntryJson.has(VtnServiceJsonConsts.TWORATETHREECOLOR)) { final JsonObject twoRateThreeColorJson = profileEntryJson .getAsJsonObject(VtnServiceJsonConsts.TWORATETHREECOLOR); // validation for meter (optional) if (isValid) { isValid = validateMeter(twoRateThreeColorJson); } // validation for greenaction (optional) if (isValid) { isValid = validateGreenAction(twoRateThreeColorJson); } // validation for yellowaction (optional) if (isValid) { isValid = validateYellowAction(twoRateThreeColorJson); } // validation for redaction (optional) if (isValid) { isValid = validateRedAction(twoRateThreeColorJson); } } } } LOG.trace("Complete PolicingProfilesEntriesValidation#validatePut()"); return isValid; }
From source file:org.opendaylight.vtn.javaapi.validation.logical.PolicingProfilesEntriesResourceValidation.java
License:Open Source License
/** * /* validate post request Json object for PolicingProfilesEntries * //w ww. j av a 2s .c o m * @param requestBody * the request Json object * @return true, if successful */ private boolean validatePost(final JsonObject requestBody) { LOG.trace("Start PolicingProfilesEntriesValidation#validatePost()"); boolean isValid = false; setInvalidParameter(VtnServiceJsonConsts.POLCINGPROFILEENTRY); if (requestBody.has(VtnServiceJsonConsts.POLCINGPROFILEENTRY) && requestBody.get(VtnServiceJsonConsts.POLCINGPROFILEENTRY).isJsonObject()) { final JsonObject profileEntryJson = requestBody .getAsJsonObject(VtnServiceJsonConsts.POLCINGPROFILEENTRY); // validation for key: seqnum(mandatory) setInvalidParameter(VtnServiceJsonConsts.SEQNUM); if (profileEntryJson.has(VtnServiceJsonConsts.SEQNUM) && profileEntryJson.getAsJsonPrimitive(VtnServiceJsonConsts.SEQNUM).getAsString() != null) { isValid = validator.isValidRange( profileEntryJson.getAsJsonPrimitive(VtnServiceJsonConsts.SEQNUM).getAsString(), VtnServiceJsonConsts.VAL_1, VtnServiceJsonConsts.VAL_65535); } if (isValid) { isValid = validatePut(requestBody); } } LOG.trace("Complete PolicingProfilesEntriesValidation#validatePost()"); return isValid; }
From source file:org.opendaylight.vtn.javaapi.validation.logical.PolicingProfilesEntriesResourceValidation.java
License:Open Source License
/** * /* validate post redAction Json object for PolicingProfilesEntries * /* ww w . j a v a 2s. c o m*/ * @param requestBody * the request Json object * @return true, if successful */ private boolean validateRedAction(final JsonObject twoRateThreeColorJson) { LOG.trace("Start PolicingProfilesEntriesValidation#validatePost#validateRedAction()"); setInvalidParameter(VtnServiceJsonConsts.REDACTION); boolean isValid = true; if (twoRateThreeColorJson.has(VtnServiceJsonConsts.REDACTION)) { final JsonObject redActionJson = twoRateThreeColorJson.getAsJsonObject(VtnServiceJsonConsts.REDACTION); // validation for yellow_action (optional) setInvalidParameter(VtnServiceJsonConsts.RED_ACTION); if (redActionJson.has(VtnServiceJsonConsts.RED_ACTION) && redActionJson.getAsJsonPrimitive(VtnServiceJsonConsts.RED_ACTION).getAsString() != null) { String rate = redActionJson.getAsJsonPrimitive(VtnServiceJsonConsts.RED_ACTION).getAsString(); isValid = rate.equalsIgnoreCase(VtnServiceJsonConsts.PASS) || rate.equalsIgnoreCase(VtnServiceJsonConsts.DROP) || rate.equalsIgnoreCase(VtnServiceJsonConsts.PENALTY); } // validation for ga_priority (optional) if (isValid) { setInvalidParameter(VtnServiceJsonConsts.RAPRIORITY); if (redActionJson.has(VtnServiceJsonConsts.RAPRIORITY) && redActionJson .getAsJsonPrimitive(VtnServiceJsonConsts.RAPRIORITY).getAsString() != null) { isValid = validator.isValidRange( redActionJson.getAsJsonPrimitive(VtnServiceJsonConsts.RAPRIORITY).getAsString(), VtnServiceJsonConsts.VAL_0, VtnServiceJsonConsts.VAL_7); } } // validation for ga_dscp (optional) if (isValid) { setInvalidParameter(VtnServiceJsonConsts.RADSCP); if (redActionJson.has(VtnServiceJsonConsts.RADSCP) && redActionJson.getAsJsonPrimitive(VtnServiceJsonConsts.RADSCP).getAsString() != null) { isValid = validator.isValidRange( redActionJson.getAsJsonPrimitive(VtnServiceJsonConsts.RADSCP).getAsString(), VtnServiceJsonConsts.VAL_0, VtnServiceJsonConsts.VAL_63); } } // validation for ga_drop_precedence (optional) if (isValid) { setInvalidParameter(VtnServiceJsonConsts.RADROPPRECEDENCE); if (redActionJson.has(VtnServiceJsonConsts.RADROPPRECEDENCE) && redActionJson .getAsJsonPrimitive(VtnServiceJsonConsts.RADROPPRECEDENCE).getAsString() != null) { isValid = validator.isValidRange( redActionJson.getAsJsonPrimitive(VtnServiceJsonConsts.RADROPPRECEDENCE).getAsString(), VtnServiceJsonConsts.VAL_1, VtnServiceJsonConsts.VAL_3); } } } LOG.trace("Complete PolicingProfilesEntriesValidation#validatePost#validateRedAction()"); return isValid; }
From source file:org.opendaylight.vtn.javaapi.validation.logical.PolicingProfilesEntriesResourceValidation.java
License:Open Source License
/** * /* validate post yellowAction Json object for PolicingProfilesEntries * //from ww w .ja v a 2 s. c o m * @param requestBody * the request Json object * @return true, if successful */ private boolean validateYellowAction(final JsonObject twoRateThreeColorJson) { LOG.trace("Start PolicingProfilesEntriesValidation#validatePost#validateYellowAction()"); setInvalidParameter(VtnServiceJsonConsts.YELLOWACTION); boolean isValid = true; if (twoRateThreeColorJson.has(VtnServiceJsonConsts.YELLOWACTION)) { final JsonObject yellowActionJson = twoRateThreeColorJson .getAsJsonObject(VtnServiceJsonConsts.YELLOWACTION); // validation for yellow_action (optional) setInvalidParameter(VtnServiceJsonConsts.YELLOW_ACTION); if (yellowActionJson.has(VtnServiceJsonConsts.YELLOW_ACTION) && yellowActionJson .getAsJsonPrimitive(VtnServiceJsonConsts.YELLOW_ACTION).getAsString() != null) { String rate = yellowActionJson.getAsJsonPrimitive(VtnServiceJsonConsts.YELLOW_ACTION).getAsString(); isValid = rate.equalsIgnoreCase(VtnServiceJsonConsts.PASS) || rate.equalsIgnoreCase(VtnServiceJsonConsts.DROP) || rate.equalsIgnoreCase(VtnServiceJsonConsts.PENALTY); } // validation for ga_priority (optional) if (isValid) { setInvalidParameter(VtnServiceJsonConsts.YAPRIORITY); if (yellowActionJson.has(VtnServiceJsonConsts.YAPRIORITY) && yellowActionJson .getAsJsonPrimitive(VtnServiceJsonConsts.YAPRIORITY).getAsString() != null) { isValid = validator.isValidRange( yellowActionJson.getAsJsonPrimitive(VtnServiceJsonConsts.YAPRIORITY).getAsString(), VtnServiceJsonConsts.VAL_0, VtnServiceJsonConsts.VAL_7); } } // validation for ga_dscp (optional) if (isValid) { setInvalidParameter(VtnServiceJsonConsts.YADSCP); if (yellowActionJson.has(VtnServiceJsonConsts.YADSCP) && yellowActionJson.getAsJsonPrimitive(VtnServiceJsonConsts.YADSCP).getAsString() != null) { isValid = validator.isValidRange( yellowActionJson.getAsJsonPrimitive(VtnServiceJsonConsts.YADSCP).getAsString(), VtnServiceJsonConsts.VAL_0, VtnServiceJsonConsts.VAL_63); } } // validation for ga_drop_precedence (optional) if (isValid) { setInvalidParameter(VtnServiceJsonConsts.YADROPPRECEDENCE); if (yellowActionJson.has(VtnServiceJsonConsts.YADROPPRECEDENCE) && yellowActionJson .getAsJsonPrimitive(VtnServiceJsonConsts.YADROPPRECEDENCE).getAsString() != null) { isValid = validator.isValidRange(yellowActionJson .getAsJsonPrimitive(VtnServiceJsonConsts.YADROPPRECEDENCE).getAsString(), VtnServiceJsonConsts.VAL_1, VtnServiceJsonConsts.VAL_3); } } } LOG.trace("Complete PolicingProfilesEntriesValidation#validatePost#validateYellowAction()"); return isValid; }
From source file:org.opendaylight.vtn.javaapi.validation.logical.PolicingProfilesEntriesResourceValidation.java
License:Open Source License
/** * /* validate post greenAction Json object for PolicingProfilesEntries * //from www . j a v a 2 s . c om * @param requestBody * the request Json object * @return true, if successful */ private boolean validateGreenAction(final JsonObject twoRateThreeColorJson) { LOG.trace("Start PolicingProfilesEntriesValidation#validatePost#validateGreenAction()"); setInvalidParameter(VtnServiceJsonConsts.GREEN_ACTION); boolean isValid = true; if (twoRateThreeColorJson.has(VtnServiceJsonConsts.GREEN_ACTION)) { final JsonObject greenActionJson = twoRateThreeColorJson .getAsJsonObject(VtnServiceJsonConsts.GREEN_ACTION); // validation for green_action (optional) setInvalidParameter(VtnServiceJsonConsts.GREENACTION); if (greenActionJson.has(VtnServiceJsonConsts.GREENACTION) && greenActionJson.getAsJsonPrimitive(VtnServiceJsonConsts.GREENACTION).getAsString() != null) { String rate = greenActionJson.getAsJsonPrimitive(VtnServiceJsonConsts.GREENACTION).getAsString(); isValid = rate.equalsIgnoreCase(VtnServiceJsonConsts.PASS) || rate.equalsIgnoreCase(VtnServiceJsonConsts.DROP) || rate.equalsIgnoreCase(VtnServiceJsonConsts.PENALTY); } // validation for ga_priority (optional) if (isValid) { setInvalidParameter(VtnServiceJsonConsts.GAPRIORITY); if (greenActionJson.has(VtnServiceJsonConsts.GAPRIORITY) && greenActionJson .getAsJsonPrimitive(VtnServiceJsonConsts.GAPRIORITY).getAsString() != null) { isValid = validator.isValidRange( greenActionJson.getAsJsonPrimitive(VtnServiceJsonConsts.GAPRIORITY).getAsString(), VtnServiceJsonConsts.VAL_0, VtnServiceJsonConsts.VAL_7); } } // validation for ga_dscp (optional) if (isValid) { setInvalidParameter(VtnServiceJsonConsts.GADSCP); if (greenActionJson.has(VtnServiceJsonConsts.GADSCP) && greenActionJson.getAsJsonPrimitive(VtnServiceJsonConsts.GADSCP).getAsString() != null) { isValid = validator.isValidRange( greenActionJson.getAsJsonPrimitive(VtnServiceJsonConsts.GADSCP).getAsString(), VtnServiceJsonConsts.VAL_0, VtnServiceJsonConsts.VAL_63); } } // validation for ga_drop_precedence (optional) if (isValid) { setInvalidParameter(VtnServiceJsonConsts.GADROPPRECEDENCE); if (greenActionJson.has(VtnServiceJsonConsts.GADROPPRECEDENCE) && greenActionJson .getAsJsonPrimitive(VtnServiceJsonConsts.GADROPPRECEDENCE).getAsString() != null) { isValid = validator.isValidRange( greenActionJson.getAsJsonPrimitive(VtnServiceJsonConsts.GADROPPRECEDENCE).getAsString(), VtnServiceJsonConsts.VAL_1, VtnServiceJsonConsts.VAL_3); } } } LOG.trace("Complete PolicingProfilesEntriesValidation#validatePost#validateGreenAction()"); return isValid; }