List of usage examples for com.google.gson JsonObject getAsJsonPrimitive
public JsonPrimitive getAsJsonPrimitive(String memberName)
From source file:org.opendaylight.vtn.javaapi.validation.logical.VTerminalResourceValidator.java
License:Open Source License
/** * Validate put request Json object for VTerminal API * //ww w . jav a 2 s .c om * @param requestBody * the request Json object * @return true, if successful */ private boolean validatePut(final JsonObject requestBody) { LOG.trace("Start VTerminalResourceValidator#validatePut()"); boolean isValid = false; setInvalidParameter(VtnServiceJsonConsts.VTERMINAL); if (requestBody.has(VtnServiceJsonConsts.VTERMINAL) && requestBody.get(VtnServiceJsonConsts.VTERMINAL).isJsonObject()) { isValid = true; final JsonObject vTerminal = requestBody.getAsJsonObject(VtnServiceJsonConsts.VTERMINAL); if (vTerminal.has(VtnServiceJsonConsts.CONTROLLERID) || vTerminal.has(VtnServiceJsonConsts.DOMAINID)) { isValid = false; } else { // validation for key: description setInvalidParameter(VtnServiceJsonConsts.DESCRIPTION); if (vTerminal.has(VtnServiceJsonConsts.DESCRIPTION) && vTerminal.getAsJsonPrimitive(VtnServiceJsonConsts.DESCRIPTION).getAsString() != null && !vTerminal.getAsJsonPrimitive(VtnServiceJsonConsts.DESCRIPTION).getAsString() .isEmpty()) { isValid = validator.isValidMaxLength( vTerminal.getAsJsonPrimitive(VtnServiceJsonConsts.DESCRIPTION).getAsString(), VtnServiceJsonConsts.LEN_127); } } } LOG.trace("Complete vTerminalResourceValidator#validatePut()"); return isValid; }
From source file:org.opendaylight.vtn.javaapi.validation.logical.VTerminalResourceValidator.java
License:Open Source License
/** * Validate post request Json object for vTerminal API * /*www . ja va2 s .com*/ * @param requestBody * the request Json object * @return true, if successful */ private boolean validatePost(final JsonObject requestBody) { LOG.trace("Start vTerminalResourceValidator#validatePost()"); boolean isValid = false; setInvalidParameter(VtnServiceJsonConsts.VTERMINAL); if (requestBody.has(VtnServiceJsonConsts.VTERMINAL) && requestBody.get(VtnServiceJsonConsts.VTERMINAL).isJsonObject()) { final JsonObject vterminal = requestBody.getAsJsonObject(VtnServiceJsonConsts.VTERMINAL); // validation for mandatory key: VTERMINAL_NAME setInvalidParameter(VtnServiceJsonConsts.VTERMINAL_NAME); if (vterminal.has(VtnServiceJsonConsts.VTERMINAL_NAME) && vterminal.getAsJsonPrimitive(VtnServiceJsonConsts.VTERMINAL_NAME).getAsString() != null) { isValid = validator.isValidMaxLengthAlphaNum( vterminal.getAsJsonPrimitive(VtnServiceJsonConsts.VTERMINAL_NAME).getAsString(), VtnServiceJsonConsts.LEN_31); } // validation for mandatory key:controller_id if (isValid) { setInvalidParameter(VtnServiceJsonConsts.CONTROLLERID); if (vterminal.has(VtnServiceJsonConsts.CONTROLLERID) && vterminal.getAsJsonPrimitive(VtnServiceJsonConsts.CONTROLLERID).getAsString() != null) { isValid = validator.isValidMaxLengthAlphaNum( vterminal.getAsJsonPrimitive(VtnServiceJsonConsts.CONTROLLERID).getAsString(), VtnServiceJsonConsts.LEN_31); } else { isValid = false; } } // validation for key: DomainID if (isValid) { setInvalidParameter(VtnServiceJsonConsts.DOMAINID); if (vterminal.has(VtnServiceJsonConsts.DOMAINID) && vterminal.getAsJsonPrimitive(VtnServiceJsonConsts.DOMAINID).getAsString() != null) { isValid = validator.isValidDomainId( vterminal.getAsJsonPrimitive(VtnServiceJsonConsts.DOMAINID).getAsString(), VtnServiceJsonConsts.LEN_31); } else { isValid = false; } } // validation for key: description if (isValid) { setInvalidParameter(VtnServiceJsonConsts.DESCRIPTION); if (vterminal.has(VtnServiceJsonConsts.DESCRIPTION) && vterminal.getAsJsonPrimitive(VtnServiceJsonConsts.DESCRIPTION).getAsString() != null && !vterminal.getAsJsonPrimitive(VtnServiceJsonConsts.DESCRIPTION).getAsString() .isEmpty()) { isValid = validator.isValidMaxLength( vterminal.getAsJsonPrimitive(VtnServiceJsonConsts.DESCRIPTION).getAsString(), VtnServiceJsonConsts.LEN_127); } } } LOG.trace("Complete vTerminalResourceValidator#validatePost()"); return isValid; }
From source file:org.opendaylight.vtn.javaapi.validation.logical.VtnDataFlowResourceValidator.java
License:Open Source License
/** * Validate request JSON for get method of VTN Data Flow API. * //from w w w .jav a2s .c o m * @param requestBody * the request Json object * @return true, if successful * @throws VtnServiceException */ private boolean isValidateGet(final JsonObject requestBody) { LOG.trace("Start VtnDataFlowResourceValidator#isValidateGet()"); boolean isValid = true; // validation for key:vnode_name(mandatory) setInvalidParameter(VtnServiceJsonConsts.VNODENAME); if (requestBody.has(VtnServiceJsonConsts.VNODENAME) && requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.VNODENAME).getAsString() != null && !requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.VNODENAME).getAsString().isEmpty()) { isValid = validator.isValidMaxLengthAlphaNum( requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.VNODENAME).getAsString(), VtnServiceJsonConsts.LEN_31); } else { isValid = false; } // validation for key: srcmacaddr(mandatory) if (isValid) { setInvalidParameter(VtnServiceJsonConsts.SRCMACADDR); if (requestBody.has(VtnServiceJsonConsts.SRCMACADDR) && requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.SRCMACADDR).getAsString() != null && !requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.SRCMACADDR).getAsString().isEmpty()) { isValid = validator.isValidMacAddress( requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.SRCMACADDR).getAsString()); } else { isValid = false; } } // validation for key: vlan_id or no_vlan_id(One of them is Mandatory) if (isValid) { // Only vlan_id or no_vlan_id is allowed in request body setInvalidParameter( VtnServiceJsonConsts.VLANID + VtnServiceJsonConsts.SLASH + VtnServiceJsonConsts.NO_VLAN_ID); if (requestBody.has(VtnServiceJsonConsts.VLANID) && requestBody.has(VtnServiceJsonConsts.NO_VLAN_ID)) { isValid = false; } else if (requestBody.has(VtnServiceJsonConsts.VLANID)) { setInvalidParameter(VtnServiceJsonConsts.VLANID); if (requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.VLANID).getAsString() != null && !requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.VLANID).getAsString().isEmpty()) { isValid = validator.isValidRange( requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.VLANID).getAsString(), VtnServiceJsonConsts.VAL_1, VtnServiceJsonConsts.VAL_4095); } else { isValid = false; } } else if (requestBody.has(VtnServiceJsonConsts.NO_VLAN_ID)) { setInvalidParameter(VtnServiceJsonConsts.NO_VLAN_ID); if (requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.NO_VLAN_ID).getAsString() != null && !requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.NO_VLAN_ID).getAsString() .isEmpty()) { isValid = requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.NO_VLAN_ID).getAsString() .equalsIgnoreCase(VtnServiceJsonConsts.TRUE); } else { isValid = false; } } else { isValid = false; } } LOG.trace("Complete VtnDataFlowResourceValidator#isValidateGet"); return isValid; }
From source file:org.opendaylight.vtn.javaapi.validation.logical.VtnMappingResourceValidator.java
License:Open Source License
/** * @param requestBody/*from w ww .java 2 s.c om*/ * , for request * @param opFlag * , for getting option1 type * @return true , if parameter are in correct format values */ public final boolean isValidGetForMappingIdIndex(final JsonObject requestBody, final boolean opFlag) { LOG.trace("Start CommonValidator#isValidGetForMappingIdIndex"); boolean isValid = true; // validation for key: targetdb setInvalidParameter(VtnServiceJsonConsts.TARGETDB); isValid = validator.isValidRequestDBState(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.isValidOperationForDetail(requestBody); } // validation for key: index where index is combination of // controller id and domain id if (isValid) { setInvalidParameter(VtnServiceJsonConsts.INDEX); if (requestBody.has(VtnServiceJsonConsts.INDEX) && requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.INDEX).getAsString() != null) { final String[] mappingId = requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.INDEX) .getAsString().split(VtnServiceJsonConsts.HYPHEN); isValid = validator.isValidMappingId(mappingId); } } // validation for key: max_repitition if (isValid) { setInvalidParameter(VtnServiceJsonConsts.MAX); isValid = validator.isValidMaxRepetition(requestBody); } // validation for key: vnode_type if (isValid) { setInvalidParameter(VtnServiceJsonConsts.VNODETYPE); if (requestBody.has(VtnServiceJsonConsts.VNODETYPE) && requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.VNODETYPE).getAsString() != null) { final String vnodeType = requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.VNODETYPE) .getAsString(); isValid = validator.isValidVnodeType(vnodeType); } } // validation for key: vnode_name if (isValid) { setInvalidParameter(VtnServiceJsonConsts.VNODENAME); if (requestBody.has(VtnServiceJsonConsts.VNODENAME) && requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.VNODENAME).getAsString() != null) { final String vnodeName = requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.VNODENAME) .getAsString(); isValid = validator.isValidMaxLengthAlphaNum(vnodeName, VtnServiceJsonConsts.LEN_31); } } // validation for key: if_name if (isValid) { setInvalidParameter(VtnServiceJsonConsts.VIFNAME); if (requestBody.has(VtnServiceJsonConsts.VIFNAME) && requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.VIFNAME).getAsString() != null) { final String ifName = requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.VIFNAME) .getAsString(); isValid = validator.isValidMaxLengthAlphaNum(ifName, VtnServiceJsonConsts.LEN_31); } } } LOG.trace("Complete CommonValidator#isValidGetForMappingIdIndex"); return isValid; }
From source file:org.opendaylight.vtn.javaapi.validation.logical.VtnPolicingMapResourceValidator.java
License:Open Source License
/** * validate PUT request JSON object for VTN PolcingMap API. * //www .j a va 2s.c o m * @param requestBody * the request JSON object * @return true, if successful */ private boolean validatePut(final JsonObject requestBody) { LOG.trace("Start VtnPolicingMapResourceValidator#validatePut()"); boolean isValid = false; setInvalidParameter(VtnServiceJsonConsts.POLICINGMAP); if (requestBody.has(VtnServiceJsonConsts.POLICINGMAP) && requestBody.get(VtnServiceJsonConsts.POLICINGMAP).isJsonObject()) { final JsonObject policingmap = requestBody.getAsJsonObject(VtnServiceJsonConsts.POLICINGMAP); setInvalidParameter(VtnServiceJsonConsts.PROFILE_NAME); // validation for mandatory key: profile_name if (policingmap.has(VtnServiceJsonConsts.PROFILE_NAME) && policingmap.getAsJsonPrimitive(VtnServiceJsonConsts.PROFILE_NAME).getAsString() != null) { isValid = validator.isValidMaxLengthAlphaNum( policingmap.getAsJsonPrimitive(VtnServiceJsonConsts.PROFILE_NAME).getAsString(), VtnServiceJsonConsts.LEN_32); } } LOG.trace("Complete VtnPolicingMapResourceValidator#validatePut()"); return isValid; }
From source file:org.opendaylight.vtn.javaapi.validation.logical.VtnPolicingMapResourceValidator.java
License:Open Source License
/** * validate GET request JSON object for VTN PolcingMap API. * //w ww. j a v a2s. c o m * @param requestBody * the request JSON object * @return true, if successful */ private boolean validateGet(final JsonObject requestBody) { LOG.trace("Start VtnPolicingMapResourceValidator#validateGet()"); boolean isValid = false; // validation for key: targetdb setInvalidParameter(VtnServiceJsonConsts.TARGETDB); isValid = validator.isValidRequestDB(requestBody); // validation for key: op if (isValid) { setInvalidParameter(VtnServiceJsonConsts.OP); // isValid = validator.isValidOperation(requestBody); if (requestBody.has(VtnServiceJsonConsts.OP) && requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.OP).getAsString() != null) { final String operation = requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.OP).getAsString(); isValid = operation.equalsIgnoreCase(VtnServiceJsonConsts.DETAIL); } else { requestBody.addProperty(VtnServiceJsonConsts.OP, VtnServiceJsonConsts.NORMAL); } } if (isValid) { // validation for key: controller_id(optional) setInvalidParameter(VtnServiceJsonConsts.CONTROLLERID); if (requestBody.has(VtnServiceJsonConsts.CONTROLLERID) && requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.CONTROLLERID).getAsString() != null) { isValid = validator.isValidMaxLengthAlphaNum( requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.CONTROLLERID).getAsString(), VtnServiceJsonConsts.LEN_31); } } if (isValid) { // validation for key: domain_id(optional) setInvalidParameter(VtnServiceJsonConsts.DOMAINID); if (requestBody.has(VtnServiceJsonConsts.DOMAINID) && requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.DOMAINID).getAsString() != null) { isValid = validator.isValidDomainId( requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.DOMAINID).getAsString(), VtnServiceJsonConsts.LEN_31); } } /* * controller_id and domain_id are mandatory for detail case */ if (requestBody.get(VtnServiceJsonConsts.OP).getAsString().equalsIgnoreCase(VtnServiceJsonConsts.DETAIL) && requestBody.get(VtnServiceJsonConsts.TARGETDB).getAsString() .equalsIgnoreCase(VtnServiceJsonConsts.STATE)) { setInvalidParameter( VtnServiceJsonConsts.CONTROLLERID + VtnServiceConsts.HYPHEN + VtnServiceJsonConsts.DOMAINID); if (requestBody.has(VtnServiceJsonConsts.CONTROLLERID) && requestBody.has(VtnServiceJsonConsts.DOMAINID)) { LOG.info("mandatory parameters are provided for detail case"); } else { LOG.error("mandatory parameters are not provided for detail case"); isValid = false; } } // index parameter should not be used in show APIs if (requestBody.has(VtnServiceJsonConsts.INDEX)) { requestBody.remove(VtnServiceJsonConsts.INDEX); } LOG.trace("Complete VtnPolicingMapResourceValidator#validateGet()"); return isValid; }
From source file:org.opendaylight.vtn.javaapi.validation.logical.VtnResourceValidator.java
License:Open Source License
/** * Validate post request Json object for Vtn API * /*ww w .j a v a 2s. c o m*/ * @param requestBody * the request Json object * @return true, if successful */ private boolean validatePost(final JsonObject requestBody) { LOG.trace("Start VtnResourceValidator#validatePost()"); boolean isValid = false; setInvalidParameter(VtnServiceJsonConsts.VTN); if (requestBody.has(VtnServiceJsonConsts.VTN) && requestBody.get(VtnServiceJsonConsts.VTN).isJsonObject()) { final JsonObject vtn = requestBody.getAsJsonObject(VtnServiceJsonConsts.VTN); setInvalidParameter(VtnServiceJsonConsts.VTNNAME); // validation for mandatory key: vtn_name if (vtn.has(VtnServiceJsonConsts.VTNNAME) && vtn.getAsJsonPrimitive(VtnServiceJsonConsts.VTNNAME).getAsString() != null) { isValid = validator.isValidMaxLengthAlphaNum( vtn.getAsJsonPrimitive(VtnServiceJsonConsts.VTNNAME).getAsString(), VtnServiceJsonConsts.LEN_31); } if (isValid) { isValid = validatePut(requestBody); } } LOG.trace("Complete VtnResourceValidator#validatePost()"); return isValid; }
From source file:org.opendaylight.vtn.javaapi.validation.logical.VtnStationsResourceValidator.java
License:Open Source License
/** * Validate get request Json object for VtnStations API. * /* w w w . ja v a2 s . c o m*/ * @param requestBody * the request Json object * @return true, if successful */ private boolean validateGet(final JsonObject requestBody) { LOG.trace("Start VtnStationsResourceValidator#validateGet()"); boolean isValid = false; // validation for key: controller_id(mandatory) setInvalidParameter(VtnServiceJsonConsts.CONTROLLERID); if (requestBody.has(VtnServiceJsonConsts.CONTROLLERID) && requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.CONTROLLERID).getAsString() != null) { isValid = validator.isValidMaxLengthAlphaNum( requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.CONTROLLERID).getAsString(), VtnServiceJsonConsts.LEN_31); } if (isValid) { // only vlan_id or no_vlan_id is allowed setInvalidParameter( VtnServiceJsonConsts.VLANID + VtnServiceJsonConsts.SLASH + VtnServiceJsonConsts.NO_VLAN_ID); if (requestBody.has(VtnServiceJsonConsts.VLANID) && requestBody.has(VtnServiceJsonConsts.NO_VLAN_ID)) { isValid = false; } else if (requestBody.has(VtnServiceJsonConsts.VLANID)) { setInvalidParameter(VtnServiceJsonConsts.VLANID); if (requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.VLANID).getAsString() != null && !requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.VLANID).getAsString().isEmpty()) { // validation for key: vlan_id isValid = validator.isValidRange( requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.VLANID).getAsString(), VtnServiceJsonConsts.VAL_1, VtnServiceJsonConsts.VAL_4095); } else { isValid = false; } } else if (requestBody.has(VtnServiceJsonConsts.NO_VLAN_ID)) { // validation for key: no_vlan_id setInvalidParameter(VtnServiceJsonConsts.NO_VLAN_ID); if (requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.NO_VLAN_ID).getAsString() != null && !requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.NO_VLAN_ID).getAsString() .isEmpty()) { final String no_vlan_id = requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.NO_VLAN_ID) .getAsString(); isValid = no_vlan_id.equalsIgnoreCase(VtnServiceJsonConsts.TRUE); } else { isValid = false; } } } // validation for key: op if (isValid) { setInvalidParameter(VtnServiceJsonConsts.OP); isValid = validator.isValidOperation(requestBody); } // validation for key: macaddr if (isValid) { setInvalidParameter(VtnServiceJsonConsts.MACADDR); if (requestBody.has(VtnServiceJsonConsts.MACADDR) && requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.MACADDR).getAsString() != null) { isValid = validator.isValidMacAddress( requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.MACADDR).getAsString()); } } // validation for key: ipaddr if (isValid) { setInvalidParameter(VtnServiceJsonConsts.IPADDR); if (requestBody.has(VtnServiceJsonConsts.IPADDR) && requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.IPADDR).getAsString() != null) { isValid = validator .isValidIpV4(requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.IPADDR).getAsString()); } } // validation for key: ipv6addr if (isValid) { setInvalidParameter(VtnServiceJsonConsts.IPV6ADDR); if (requestBody.has(VtnServiceJsonConsts.IPV6ADDR) && requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.IPV6ADDR).getAsString() != null) { isValid = validator .isValidIpV6(requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.IPV6ADDR).getAsString()); } } // validation for key: switch_id if (isValid) { setInvalidParameter(VtnServiceJsonConsts.SWITCHID); if (requestBody.has(VtnServiceJsonConsts.SWITCHID) && requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.SWITCHID).getAsString() != null) { isValid = validator.isValidMaxLength( requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.SWITCHID).getAsString(), VtnServiceJsonConsts.LEN_255) || requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.SWITCHID).getAsString().isEmpty(); } } // validation for key: port_name if (isValid) { setInvalidParameter(VtnServiceJsonConsts.PORTNAME); if (requestBody.has(VtnServiceJsonConsts.PORTNAME) && requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.PORTNAME).getAsString() != null) { isValid = validator.isValidMaxLength( requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.PORTNAME).getAsString(), VtnServiceJsonConsts.LEN_31) || requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.PORTNAME).getAsString().isEmpty(); } } // validation for key: vtn_name if (isValid) { setInvalidParameter(VtnServiceJsonConsts.VTNNAME); if (requestBody.has(VtnServiceJsonConsts.VTNNAME) && requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.VTNNAME).getAsString() != null) { isValid = validator.isValidMaxLengthAlphaNum( requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.VTNNAME).getAsString(), VtnServiceJsonConsts.LEN_31) || requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.VTNNAME).getAsString().isEmpty(); } } // validation for key: vnode_type if (isValid) { setInvalidParameter(VtnServiceJsonConsts.VNODETYPE); if (requestBody.has(VtnServiceJsonConsts.VNODETYPE) && requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.VNODETYPE).getAsString() != null) { String vnodeType = requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.VNODETYPE).getAsString(); if (vnodeType.equals(VtnServiceJsonConsts.VBRIDGE) || vnodeType.equals(VtnServiceJsonConsts.VROUTER) || vnodeType.equals(VtnServiceJsonConsts.VTERMINAL) || vnodeType.equals(VtnServiceJsonConsts.VBYPASS) || vnodeType.equals(VtnServiceJsonConsts.VTEP) || vnodeType.equals(VtnServiceJsonConsts.VTUNNEL) || vnodeType.equals(VtnServiceJsonConsts.EMPTY)) { isValid = true; } } } // validation for key: vnode_name if (isValid) { setInvalidParameter(VtnServiceJsonConsts.VNODENAME); if (requestBody.has(VtnServiceJsonConsts.VNODENAME) && requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.VNODENAME).getAsString() != null) { isValid = validator.isValidMaxLengthAlphaNum( requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.VNODENAME).getAsString(), VtnServiceJsonConsts.LEN_31) || requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.VNODENAME).getAsString().isEmpty(); } } // validation for key: if_name if (isValid) { setInvalidParameter(VtnServiceJsonConsts.IFNAME); if (requestBody.has(VtnServiceJsonConsts.IFNAME) && requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.IFNAME).getAsString() != null) { isValid = validator.isValidMaxLengthAlphaNum( requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.IFNAME).getAsString(), VtnServiceJsonConsts.LEN_31) || requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.IFNAME).getAsString().isEmpty(); } } // validation for key: domain_id if (isValid) { setInvalidParameter(VtnServiceJsonConsts.DOMAINID); if (requestBody.has(VtnServiceJsonConsts.DOMAINID) && requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.DOMAINID).getAsString() != null && !requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.DOMAINID).getAsString().isEmpty()) { isValid = validator.isValidDomainId( requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.DOMAINID).getAsString(), VtnServiceJsonConsts.LEN_31); } } if (requestBody.has(VtnServiceJsonConsts.INDEX)) { requestBody.remove(VtnServiceJsonConsts.INDEX); } else { LOG.debug("No need to remove"); } LOG.trace("Complete VtnStationsResourceValidator#validateGet()"); return isValid; }
From source file:org.opendaylight.vtn.javaapi.validation.logical.VTNUnifiedNetworkResourceValidator.java
License:Open Source License
/** * validate post request Json object for VTN Unified Network API. * //from w w w.j a v a 2s . 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 VTNUnifiedNetworkResourceValidator#validatePost()"); boolean isValid = false; setInvalidParameter(VtnServiceJsonConsts.UNIFIED_NW); if (requestBody.has(VtnServiceJsonConsts.UNIFIED_NW) && requestBody.get(VtnServiceJsonConsts.UNIFIED_NW).isJsonObject()) { final JsonObject vtnUnifiedNetworkResourceEntry = requestBody .getAsJsonObject(VtnServiceJsonConsts.UNIFIED_NW); // validation for key: unified_network_name(mandatory) setInvalidParameter(VtnServiceJsonConsts.UNIFIED_NETWORK_NAME); if (vtnUnifiedNetworkResourceEntry.has(VtnServiceJsonConsts.UNIFIED_NETWORK_NAME) && vtnUnifiedNetworkResourceEntry.get(VtnServiceJsonConsts.UNIFIED_NETWORK_NAME) .isJsonPrimitive() && !vtnUnifiedNetworkResourceEntry.getAsJsonPrimitive(VtnServiceJsonConsts.UNIFIED_NETWORK_NAME) .getAsString().isEmpty()) { isValid = validator.isValidMaxLengthAlphaNum(vtnUnifiedNetworkResourceEntry .getAsJsonPrimitive(VtnServiceJsonConsts.UNIFIED_NETWORK_NAME).getAsString(), VtnServiceJsonConsts.LEN_31); } if (isValid && vtnUnifiedNetworkResourceEntry.has(VtnServiceJsonConsts.SPINE_DOMAIN_NAME)) { // validation for key: spine_domain_name(option) setInvalidParameter(VtnServiceJsonConsts.SPINE_DOMAIN_NAME); if (vtnUnifiedNetworkResourceEntry.get(VtnServiceJsonConsts.SPINE_DOMAIN_NAME).isJsonPrimitive()) { isValid = validator.isValidMaxLengthAlphaNum( vtnUnifiedNetworkResourceEntry .getAsJsonPrimitive(VtnServiceJsonConsts.SPINE_DOMAIN_NAME).getAsString(), VtnServiceJsonConsts.LEN_31); } else { isValid = false; } } } LOG.trace("Complete VTNUnifiedNetworkResourceValidator#validatePost()"); return isValid; }
From source file:org.opendaylight.vtn.javaapi.validation.logical.VTNUnifiedNetworkResourceValidator.java
License:Open Source License
/** * validate put request Json object for VTN Unified Network API. * /*ww w.j a va2 s . com*/ * @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 VTNUnifiedNetworkResourceValidator#validatePut()"); boolean isValid = false; setInvalidParameter(VtnServiceJsonConsts.UNIFIED_NW); if (requestBody.has(VtnServiceJsonConsts.UNIFIED_NW) && requestBody.get(VtnServiceJsonConsts.UNIFIED_NW).isJsonObject()) { final JsonObject vtnUnifiedNetworkResourceEntry = requestBody .getAsJsonObject(VtnServiceJsonConsts.UNIFIED_NW); // validation for key: spine_domain_name(option) isValid = true; if (vtnUnifiedNetworkResourceEntry.has(VtnServiceJsonConsts.SPINE_DOMAIN_NAME)) { setInvalidParameter(VtnServiceJsonConsts.SPINE_DOMAIN_NAME); if (vtnUnifiedNetworkResourceEntry.get(VtnServiceJsonConsts.SPINE_DOMAIN_NAME).isJsonPrimitive()) { isValid = validator.isValidMaxLengthAlphaNum( vtnUnifiedNetworkResourceEntry .getAsJsonPrimitive(VtnServiceJsonConsts.SPINE_DOMAIN_NAME).getAsString(), VtnServiceJsonConsts.LEN_31); } else { isValid = false; } } } LOG.trace("Complete VTNUnifiedNetworkResourceValidator#validatePut()"); return isValid; }