List of usage examples for com.google.gson JsonObject getAsJsonPrimitive
public JsonPrimitive getAsJsonPrimitive(String memberName)
From source file:org.opendaylight.vtn.javaapi.validation.logical.VBridgePortMapResourceValidator.java
License:Open Source License
/** * logical_port_id, label_type and label should have same valid flag * //from w w w .ja va 2s . c om * @param JsonObject * the request Json object * @return true, if successful */ private boolean validateParameter(JsonObject portMap) { LOG.trace("Start VBridgePortMapResourceValidator#validateParameter()"); boolean isValidPortId = false; boolean isValidVlanId = false; boolean isValidLabel = false; // validation for mandatory key: logical_port_id setInvalidParameter(VtnServiceJsonConsts.LOGICAL_PORT_ID); isValidPortId = validator.isValidMaxLength( portMap.getAsJsonPrimitive(VtnServiceJsonConsts.LOGICAL_PORT_ID).getAsString(), VtnServiceJsonConsts.LEN_319); // validation for mandatory key: label_type if (isValidPortId) { setInvalidParameter(VtnServiceJsonConsts.LABEL_TYPE); if (VtnServiceJsonConsts.VLAN_ID .equals(portMap.getAsJsonPrimitive(VtnServiceJsonConsts.LABEL_TYPE).getAsString())) { isValidVlanId = true; } } // validation for mandatory key: label if (isValidVlanId) { setInvalidParameter(VtnServiceJsonConsts.LABEL); if (VtnServiceJsonConsts.ANY_VLAN_ID .equals(portMap.getAsJsonPrimitive(VtnServiceJsonConsts.LABEL).getAsString())) { isValidLabel = true; } else if (VtnServiceJsonConsts.NO_VLAN_ID .equals(portMap.getAsJsonPrimitive(VtnServiceJsonConsts.LABEL).getAsString())) { isValidLabel = true; } else { isValidLabel = validator.isValidRange( portMap.getAsJsonPrimitive(VtnServiceJsonConsts.LABEL).getAsString(), VtnServiceJsonConsts.VAL_1, VtnServiceJsonConsts.VAL_4095); } } LOG.trace("Complete VBridgePortMapResourceValidator#validateParameter()"); return isValidPortId && isValidVlanId && isValidLabel; }
From source file:org.opendaylight.vtn.javaapi.validation.logical.VBridgeResourceValidator.java
License:Open Source License
/** * Validate put request Json object for VBridge API * /*w w w.ja v a 2 s .c o m*/ * @param requestBody * the request Json object * @return true, if successful */ private boolean validatePut(final JsonObject requestBody) { LOG.trace("Start VBridgeResourceValidator#validatePut()"); boolean isValid = false; setInvalidParameter(VtnServiceJsonConsts.VBRIDGE); if (requestBody.has(VtnServiceJsonConsts.VBRIDGE) && requestBody.get(VtnServiceJsonConsts.VBRIDGE).isJsonObject()) { isValid = true; final JsonObject vBridge = requestBody.getAsJsonObject(VtnServiceJsonConsts.VBRIDGE); // validation for key: description if (isValid) { setInvalidParameter(VtnServiceJsonConsts.DESCRIPTION); if (vBridge.has(VtnServiceJsonConsts.DESCRIPTION) && vBridge.getAsJsonPrimitive(VtnServiceJsonConsts.DESCRIPTION).getAsString() != null && !vBridge.getAsJsonPrimitive(VtnServiceJsonConsts.DESCRIPTION).getAsString().isEmpty()) { isValid = validator.isValidMaxLength( vBridge.getAsJsonPrimitive(VtnServiceJsonConsts.DESCRIPTION).getAsString(), VtnServiceJsonConsts.LEN_127); } } } LOG.trace("Complete VBridgeResourceValidator#validatePut()"); return isValid; }
From source file:org.opendaylight.vtn.javaapi.validation.logical.VBridgeResourceValidator.java
License:Open Source License
/** * Validate post request Json object for VBridge API * // w ww . j ava2 s . c om * @param requestBody * the request Json object * @return true, if successful */ private boolean validatePost(final JsonObject requestBody) { LOG.trace("Start VBridgeResourceValidator#validatePost()"); boolean isValid = false; setInvalidParameter(VtnServiceJsonConsts.VBRIDGE); if (requestBody.has(VtnServiceJsonConsts.VBRIDGE) && requestBody.get(VtnServiceJsonConsts.VBRIDGE).isJsonObject()) { final JsonObject vbridge = requestBody.getAsJsonObject(VtnServiceJsonConsts.VBRIDGE); // validation for mandatory key: vbr_name setInvalidParameter(VtnServiceJsonConsts.VBRNAME); if (vbridge.has(VtnServiceJsonConsts.VBRNAME) && vbridge.getAsJsonPrimitive(VtnServiceJsonConsts.VBRNAME).getAsString() != null) { isValid = validator.isValidMaxLengthAlphaNum( vbridge.getAsJsonPrimitive(VtnServiceJsonConsts.VBRNAME).getAsString(), VtnServiceJsonConsts.LEN_31); } // validation for mandatory key:controller_id if (isValid) { setInvalidParameter(VtnServiceJsonConsts.CONTROLLERID); if (vbridge.has(VtnServiceJsonConsts.CONTROLLERID) && vbridge.getAsJsonPrimitive(VtnServiceJsonConsts.CONTROLLERID).getAsString() != null) { isValid = validator.isValidMaxLengthAlphaNum( vbridge.getAsJsonPrimitive(VtnServiceJsonConsts.CONTROLLERID).getAsString(), VtnServiceJsonConsts.LEN_31); } else { isValid = false; } } // validation for key: description if (isValid) { setInvalidParameter(VtnServiceJsonConsts.DESCRIPTION); if (vbridge.has(VtnServiceJsonConsts.DESCRIPTION) && vbridge.getAsJsonPrimitive(VtnServiceJsonConsts.DESCRIPTION).getAsString() != null && !vbridge.getAsJsonPrimitive(VtnServiceJsonConsts.DESCRIPTION).getAsString().isEmpty()) { isValid = validator.isValidMaxLength( vbridge.getAsJsonPrimitive(VtnServiceJsonConsts.DESCRIPTION).getAsString(), VtnServiceJsonConsts.LEN_127); } } // validation for key: DomainID if (isValid) { setInvalidParameter(VtnServiceJsonConsts.DOMAINID); if (vbridge.has(VtnServiceJsonConsts.DOMAINID) && vbridge.getAsJsonPrimitive(VtnServiceJsonConsts.DOMAINID).getAsString() != null) { isValid = validator.isValidDomainId( vbridge.getAsJsonPrimitive(VtnServiceJsonConsts.DOMAINID).getAsString(), VtnServiceJsonConsts.LEN_31); } else { isValid = false; } } } LOG.trace("Complete VBridgeResourceValidator#validatePost()"); return isValid; }
From source file:org.opendaylight.vtn.javaapi.validation.logical.VBypassResourceValidator.java
License:Open Source License
/** * Validate post request Json object for VBypassResource. * //ww w . j av a2s . c om * @param requestBody * the request Json object * @return true, if successful * @throws VtnServiceException * the vtn service exception */ private boolean validatePost(final JsonObject requestBody) throws VtnServiceException { LOG.trace("Start VBypassResourceValidator#validatePost()"); boolean isValid = false; setInvalidParameter(VtnServiceJsonConsts.VBYPASS); if (requestBody.has(VtnServiceJsonConsts.VBYPASS) && requestBody.get(VtnServiceJsonConsts.VBYPASS).isJsonObject()) { final JsonObject vBypass = requestBody.getAsJsonObject(VtnServiceJsonConsts.VBYPASS); // validation for key: VBYPASS_NAME(mandatory) setInvalidParameter(VtnServiceJsonConsts.VBYPASS_NAME); if (vBypass.has(VtnServiceJsonConsts.VBYPASS_NAME) && vBypass.getAsJsonPrimitive(VtnServiceJsonConsts.VBYPASS_NAME).getAsString() != null) { isValid = validator.isValidMaxLengthAlphaNum( vBypass.getAsJsonPrimitive(VtnServiceJsonConsts.VBYPASS_NAME).getAsString(), VtnServiceJsonConsts.LEN_31); } if (isValid) { isValid = commonValidations(isValid, vBypass); } // validation for key: DOMAINID(mandatory) if (isValid) { setInvalidParameter(VtnServiceJsonConsts.DOMAINID); if (vBypass.has(VtnServiceJsonConsts.DOMAINID) && vBypass.getAsJsonPrimitive(VtnServiceJsonConsts.DOMAINID).getAsString() != null) { isValid = validator.isValidDomainId( vBypass.getAsJsonPrimitive(VtnServiceJsonConsts.DOMAINID).getAsString(), VtnServiceJsonConsts.LEN_31); } else { isValid = false; } } } LOG.trace("Complete VBypassResourceValidator#validatePost()"); return isValid; }
From source file:org.opendaylight.vtn.javaapi.validation.logical.VBypassResourceValidator.java
License:Open Source License
/** * @param isValid//from ww w.j ava2s . c o m * @param vBypass * @return */ private boolean commonValidations(boolean isValid, final JsonObject vBypass) { LOG.trace("Start VBypassResourceValidator#commonValidations()"); // validation for key: description setInvalidParameter(VtnServiceJsonConsts.DESCRIPTION); if (vBypass.has(VtnServiceJsonConsts.DESCRIPTION) && vBypass.getAsJsonPrimitive(VtnServiceJsonConsts.DESCRIPTION).getAsString() != null && !vBypass.getAsJsonPrimitive(VtnServiceJsonConsts.DESCRIPTION).getAsString().isEmpty()) { isValid = validator.isValidMaxLength( vBypass.getAsJsonPrimitive(VtnServiceJsonConsts.DESCRIPTION).getAsString(), VtnServiceJsonConsts.LEN_127); } // validation for key: type if (isValid) { setInvalidParameter(VtnServiceJsonConsts.TYPE); if (vBypass.has(VtnServiceJsonConsts.TYPE) && vBypass.getAsJsonPrimitive(VtnServiceJsonConsts.TYPE).getAsString() != null) { isValid = validType(vBypass.getAsJsonPrimitive(VtnServiceJsonConsts.TYPE).getAsString()); } } LOG.trace("Complete VBypassResourceValidator#commonValidations()"); return isValid; }
From source file:org.opendaylight.vtn.javaapi.validation.logical.VLanMapResourceValidator.java
License:Open Source License
/** * Validate get request Json object for VLanMap API * /* w ww .jav a 2 s .c om*/ * @param requestBody * the request Json object * @return true, if successful */ private boolean validateGet(final JsonObject requestBody, final boolean opFlag) { LOG.trace("Start VLanMapValiadtor#isValidGet"); boolean isValid = true; // validation for key: targetdb if (isValid) { setInvalidParameter(VtnServiceJsonConsts.TARGETDB); isValid = validator.isValidRequestDB(requestBody); } if (!opFlag) { if (requestBody.has(VtnServiceJsonConsts.OP)) { requestBody.remove(VtnServiceJsonConsts.OP); } else { LOG.debug("No need to remove -op "); } if (requestBody.has(VtnServiceJsonConsts.INDEX)) { requestBody.remove(VtnServiceJsonConsts.INDEX); } else { LOG.debug("No need to remove - index"); } if (requestBody.has(VtnServiceJsonConsts.MAX)) { requestBody.remove(VtnServiceJsonConsts.MAX); } else { LOG.debug("No need to remove-max count"); } } else { // validation for key: op if (isValid) { setInvalidParameter(VtnServiceJsonConsts.OP); isValid = validator.isValidOperation(requestBody); } // validation for key: index if (isValid) { setInvalidParameter(VtnServiceJsonConsts.INDEX); if (requestBody.has(VtnServiceJsonConsts.INDEX) && requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.INDEX).getAsString() != null) { final String vlamMapId = requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.INDEX) .getAsString(); isValid = isValidVLanMapId(vlamMapId); } } // validation for key: max_repitition if (isValid) { setInvalidParameter(VtnServiceJsonConsts.MAX); isValid = validator.isValidMaxRepetition(requestBody); } } LOG.trace("Complete VLanMapValidator#isValidGet"); return isValid; }
From source file:org.opendaylight.vtn.javaapi.validation.logical.VLanMapResourceValidator.java
License:Open Source License
/** * Validate post request Json object for VLanMap API. * // w ww . j av a2 s .c o m * @param requestBody * the request Json object * @return true, if successful * @throws VtnServiceException * the vtn service exception */ private boolean validatePost(final JsonObject requestBody) throws VtnServiceException { LOG.trace("Start VLanMapValidator#validatePost()"); boolean isValid = false; setInvalidParameter(VtnServiceJsonConsts.VLANMAP); if (requestBody.has(VtnServiceJsonConsts.VLANMAP) && requestBody.get(VtnServiceJsonConsts.VLANMAP).isJsonObject()) { isValid = true; final JsonObject vLanMap = requestBody.getAsJsonObject(VtnServiceJsonConsts.VLANMAP); // validation for key: logical_port_id(optional) setInvalidParameter(VtnServiceJsonConsts.LOGICAL_PORT_ID); if (vLanMap.has(VtnServiceJsonConsts.LOGICAL_PORT_ID) && vLanMap.getAsJsonPrimitive(VtnServiceJsonConsts.LOGICAL_PORT_ID).getAsString() != null && !vLanMap.getAsJsonPrimitive(VtnServiceJsonConsts.LOGICAL_PORT_ID).getAsString().isEmpty()) { isValid = validator.isValidMaxLength( vLanMap.getAsJsonPrimitive(VtnServiceJsonConsts.LOGICAL_PORT_ID).getAsString(), VtnServiceJsonConsts.LEN_319); } if (isValid) { isValid = validatePut(requestBody); } } LOG.trace("Complete VLanMapValidator#validatePost()"); return isValid; }
From source file:org.opendaylight.vtn.javaapi.validation.logical.VLanMapResourceValidator.java
License:Open Source License
/** * Validate put request Json object for VLanMap API. * /*from w ww . j av a2 s . co m*/ * @param requestBody * the request Json object * @return true, if successful * @throws VtnServiceException * the vtn service exception */ private boolean validatePut(final JsonObject requestBody) throws VtnServiceException { LOG.trace("Start VLanMapResourceValidator#validatePut()"); boolean isValid = false; setInvalidParameter(VtnServiceJsonConsts.VLANMAP); if (requestBody.has(VtnServiceJsonConsts.VLANMAP) && requestBody.get(VtnServiceJsonConsts.VLANMAP).isJsonObject()) { final JsonObject vLanMap = requestBody.getAsJsonObject(VtnServiceJsonConsts.VLANMAP); // only vlan_id or no_vlan_id is allowed setInvalidParameter( VtnServiceJsonConsts.VLANID + VtnServiceJsonConsts.SLASH + VtnServiceJsonConsts.NO_VLAN_ID); if (vLanMap.has(VtnServiceJsonConsts.VLANID) && vLanMap.has(VtnServiceJsonConsts.NO_VLAN_ID)) { isValid = false; } else if (vLanMap.has(VtnServiceJsonConsts.VLANID)) { setInvalidParameter(VtnServiceJsonConsts.VLANID); if (vLanMap.getAsJsonPrimitive(VtnServiceJsonConsts.VLANID).getAsString() != null && !vLanMap.getAsJsonPrimitive(VtnServiceJsonConsts.VLANID).getAsString().isEmpty()) { // validation for key: vlan_id isValid = validator.isValidRange( vLanMap.getAsJsonPrimitive(VtnServiceJsonConsts.VLANID).getAsString(), VtnServiceJsonConsts.VAL_1, VtnServiceJsonConsts.VAL_4095); } else { isValid = false; } } else if (vLanMap.has(VtnServiceJsonConsts.NO_VLAN_ID)) { setInvalidParameter(VtnServiceJsonConsts.NO_VLAN_ID); if (vLanMap.getAsJsonPrimitive(VtnServiceJsonConsts.NO_VLAN_ID).getAsString() != null && !vLanMap.getAsJsonPrimitive(VtnServiceJsonConsts.NO_VLAN_ID).getAsString().isEmpty()) { // validation for key: no_vlan_id final String no_vlan_id = vLanMap.getAsJsonPrimitive(VtnServiceJsonConsts.NO_VLAN_ID) .getAsString(); isValid = no_vlan_id.equalsIgnoreCase(VtnServiceJsonConsts.TRUE); } else { isValid = false; } } else { isValid = false; } } else { isValid = false; } LOG.trace("Complete VLanMapResourceValidator#validatePut()"); return isValid; }
From source file:org.opendaylight.vtn.javaapi.validation.logical.VLinkResourceValidator.java
License:Open Source License
/** * Validate get request Json object for Vlink API. * /*from w w w .j a v a2 s .co m*/ * @param requestBody * the request Json object * @return true, if successful */ private boolean validateGet(final JsonObject requestBody) { boolean isValid = false; isValid = validator.isValidGet(requestBody, isListOpFlag()); setInvalidParameter(validator.getInvalidParameter()); if (isValid) { setInvalidParameter(VtnServiceJsonConsts.VNODE1NAME); if (requestBody.has(VtnServiceJsonConsts.VNODE1NAME) && requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.VNODE1NAME).getAsString() != null) { isValid = validator.isValidMaxLengthAlphaNum( requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.VNODE1NAME).getAsString(), VtnServiceJsonConsts.LEN_31) || requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.VNODE1NAME).getAsString().isEmpty(); } } if (isValid) { setInvalidParameter(VtnServiceJsonConsts.VNODE2NAME); if (requestBody.has(VtnServiceJsonConsts.VNODE2NAME) && requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.VNODE2NAME).getAsString() != null) { isValid = validator.isValidMaxLengthAlphaNum( requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.VNODE2NAME).getAsString(), VtnServiceJsonConsts.LEN_31) || requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.VNODE2NAME).getAsString().isEmpty(); } } return isValid; }
From source file:org.opendaylight.vtn.javaapi.validation.logical.VLinkResourceValidator.java
License:Open Source License
/** * validate post request Json object for Vlink API. * /*from www . ja va2s . co m*/ * @param requestBody * the request Json object * @return true, if successful * @throws VtnServiceException * the vtn service exception */ private boolean validatePost(final JsonObject requestBody) throws VtnServiceException { LOG.trace("Start VLinkResourceValidator#validatePost()"); boolean isValid = false; setInvalidParameter(VtnServiceJsonConsts.VLINK); if (requestBody.has(VtnServiceJsonConsts.VLINK) && requestBody.get(VtnServiceJsonConsts.VLINK).isJsonObject()) { final JsonObject vlinkResourceEntry = requestBody.getAsJsonObject(VtnServiceJsonConsts.VLINK); // validation for key: vlk_name(mandatory) setInvalidParameter(VtnServiceJsonConsts.VLKNAME); if (vlinkResourceEntry.has(VtnServiceJsonConsts.VLKNAME) && vlinkResourceEntry.getAsJsonPrimitive(VtnServiceJsonConsts.VLKNAME).getAsString() != null && !vlinkResourceEntry.getAsJsonPrimitive(VtnServiceJsonConsts.VLKNAME).getAsString() .isEmpty()) { isValid = validator.isValidMaxLengthAlphaNum( vlinkResourceEntry.getAsJsonPrimitive(VtnServiceJsonConsts.VLKNAME).getAsString(), VtnServiceJsonConsts.LEN_31); } // validation for key: vnode1_name(mandatory) if (isValid) { setInvalidParameter(VtnServiceJsonConsts.VNODE1NAME); if (vlinkResourceEntry.has(VtnServiceJsonConsts.VNODE1NAME) && vlinkResourceEntry .getAsJsonPrimitive(VtnServiceJsonConsts.VNODE1NAME).getAsString() != null) { isValid = validator.isValidMaxLengthAlphaNum( vlinkResourceEntry.getAsJsonPrimitive(VtnServiceJsonConsts.VNODE1NAME).getAsString(), VtnServiceJsonConsts.LEN_31); } else { isValid = false; } } // validation for key: if1_name(mandatory) if (isValid) { setInvalidParameter(VtnServiceJsonConsts.IF1NAME); if (vlinkResourceEntry.has(VtnServiceJsonConsts.IF1NAME) && vlinkResourceEntry .getAsJsonPrimitive(VtnServiceJsonConsts.IF1NAME).getAsString() != null) { isValid = validator.isValidMaxLengthAlphaNum( vlinkResourceEntry.getAsJsonPrimitive(VtnServiceJsonConsts.IF1NAME).getAsString(), VtnServiceJsonConsts.LEN_31); } else { isValid = false; } } // validation for key: vnode2_name(mandatory) if (isValid) { setInvalidParameter(VtnServiceJsonConsts.VNODE2NAME); if (vlinkResourceEntry.has(VtnServiceJsonConsts.VNODE2NAME) && vlinkResourceEntry .getAsJsonPrimitive(VtnServiceJsonConsts.VNODE2NAME).getAsString() != null) { isValid = validator.isValidMaxLengthAlphaNum( vlinkResourceEntry.getAsJsonPrimitive(VtnServiceJsonConsts.VNODE2NAME).getAsString(), VtnServiceJsonConsts.LEN_31); } else { isValid = false; } } // validation for key: if2_name(mandatory) if (isValid) { setInvalidParameter(VtnServiceJsonConsts.IF2NAME); if (vlinkResourceEntry.has(VtnServiceJsonConsts.IF2NAME) && vlinkResourceEntry .getAsJsonPrimitive(VtnServiceJsonConsts.IF2NAME).getAsString() != null) { isValid = validator.isValidMaxLengthAlphaNum( vlinkResourceEntry.getAsJsonPrimitive(VtnServiceJsonConsts.IF2NAME).getAsString(), VtnServiceJsonConsts.LEN_31); } else { isValid = false; } if (isValid) { isValid = commonValidation(vlinkResourceEntry, true); } } } else { isValid = false; } LOG.trace("Complete VLinkResourceValidator#validatePost()"); return isValid; }