Example usage for com.google.gson JsonObject getAsJsonPrimitive

List of usage examples for com.google.gson JsonObject getAsJsonPrimitive

Introduction

In this page you can find the example usage for com.google.gson JsonObject getAsJsonPrimitive.

Prototype

public JsonPrimitive getAsJsonPrimitive(String memberName) 

Source Link

Document

Convenience method to get the specified member as a JsonPrimitive element.

Usage

From source file:org.opendaylight.vtn.javaapi.validation.logical.VLinkResourceValidator.java

License:Open Source License

/**
 * Common validation for description, admin_status and boundary for put and
 * post APIs.//ww  w.  jav  a 2 s.  com
 * 
 * @param vlinkResourceEntry
 *            the vlink resource entry
 * @return true, if successful
 */
private boolean commonValidation(final JsonObject vlinkResourceEntry, boolean isPost) {
    LOG.trace("Start VLinkResourceValidator#commonValidation()");
    boolean isValid = true;
    boolean isBoundaryValid = false;
    // validation for key: description(optional)
    setInvalidParameter(VtnServiceJsonConsts.DESCRIPTION);
    if (vlinkResourceEntry.has(VtnServiceJsonConsts.DESCRIPTION)
            && vlinkResourceEntry.getAsJsonPrimitive(VtnServiceJsonConsts.DESCRIPTION).getAsString() != null) {
        isValid = validator.isValidMaxLength(
                vlinkResourceEntry.getAsJsonPrimitive(VtnServiceJsonConsts.DESCRIPTION).getAsString(),
                VtnServiceJsonConsts.LEN_127)
                || vlinkResourceEntry.getAsJsonPrimitive(VtnServiceJsonConsts.DESCRIPTION).getAsString()
                        .isEmpty();
    }
    // validation for key: adminstatus(optional)
    if (isValid) {
        setInvalidParameter(VtnServiceJsonConsts.ADMINSTATUS);
        if (vlinkResourceEntry.has(VtnServiceJsonConsts.ADMINSTATUS) && vlinkResourceEntry
                .getAsJsonPrimitive(VtnServiceJsonConsts.ADMINSTATUS).getAsString() != null) {
            final String adminstatus = vlinkResourceEntry.getAsJsonPrimitive(VtnServiceJsonConsts.ADMINSTATUS)
                    .getAsString();
            isValid = adminstatus.equalsIgnoreCase(VtnServiceJsonConsts.ENABLE)
                    || adminstatus.equalsIgnoreCase(VtnServiceJsonConsts.DISABLE);
        }
    }
    if (isValid) {
        setInvalidParameter(VtnServiceJsonConsts.BOUNDARYMAP);
        if (vlinkResourceEntry.has(VtnServiceJsonConsts.BOUNDARYMAP)
                && vlinkResourceEntry.get(VtnServiceJsonConsts.BOUNDARYMAP).isJsonObject()) {
            final JsonObject boundary = vlinkResourceEntry.getAsJsonObject(VtnServiceJsonConsts.BOUNDARYMAP);

            //check the boundary_id
            setInvalidParameter(VtnServiceJsonConsts.BOUNDARYID);
            if (boundary.has(VtnServiceJsonConsts.BOUNDARYID)
                    && boundary.getAsJsonPrimitive(VtnServiceJsonConsts.BOUNDARYID).getAsString() != null) {
                if (!boundary.getAsJsonPrimitive(VtnServiceJsonConsts.BOUNDARYID).getAsString().isEmpty()) {
                    if (!validator.isValidMaxLengthAlphaNum(
                            boundary.getAsJsonPrimitive(VtnServiceJsonConsts.BOUNDARYID).getAsString(),
                            VtnServiceJsonConsts.LEN_31)) {
                        //if boundary_id is invalid in post or put, no need to check the vlan_id or no_vlan_id
                        LOG.trace("Complete VLinkResourceValidator#commonValidation() 2 ");
                        return false;
                    } else {
                        isBoundaryValid = true;
                    }
                }
            }

            // either vlan_id or no_vlan_id should be there
            setInvalidParameter(
                    VtnServiceJsonConsts.VLANID + VtnServiceJsonConsts.SLASH + VtnServiceJsonConsts.NO_VLAN_ID);
            if (boundary.has(VtnServiceJsonConsts.VLANID) && boundary.has(VtnServiceJsonConsts.NO_VLAN_ID)) {
                isValid = false;
            } else if (boundary.has(VtnServiceJsonConsts.VLANID)) {
                setInvalidParameter(VtnServiceJsonConsts.VLANID);
                if (boundary.getAsJsonPrimitive(VtnServiceJsonConsts.VLANID).getAsString() != null && !boundary
                        .getAsJsonPrimitive(VtnServiceJsonConsts.VLANID).getAsString().trim().isEmpty()) {
                    isValid = validator.isValidRange(
                            boundary.getAsJsonPrimitive(VtnServiceJsonConsts.VLANID).getAsString(),
                            VtnServiceJsonConsts.VAL_1, VtnServiceJsonConsts.VAL_4095);
                } else {
                    isValid = false;
                }
            } else if (boundary.has(VtnServiceJsonConsts.NO_VLAN_ID)) {
                setInvalidParameter(VtnServiceJsonConsts.NO_VLAN_ID);
                if (boundary.getAsJsonPrimitive(VtnServiceJsonConsts.NO_VLAN_ID).getAsString() != null
                        && !boundary.getAsJsonPrimitive(VtnServiceJsonConsts.NO_VLAN_ID).getAsString()
                                .isEmpty()) {
                    isValid = boundary.getAsJsonPrimitive(VtnServiceJsonConsts.NO_VLAN_ID).getAsString()
                            .equalsIgnoreCase(VtnServiceJsonConsts.TRUE);
                } else {
                    isValid = false;
                }
            } else {
                if (isPost && isBoundaryValid) {
                    isValid = false;
                }
            }
        }
    }
    LOG.trace("Complete VLinkResourceValidator#commonValidation()");
    return isValid;
}

From source file:org.opendaylight.vtn.javaapi.validation.logical.VRouterInterfaceResourceValidator.java

License:Open Source License

/**
 * validates post request Json object for VrouterInterface API.
 * /* w w w. j  ava2s  . 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 VRouterInterfaceResourceValidator#validatePost()");
    boolean isValid = false;
    setInvalidParameter(VtnServiceJsonConsts.INTERFACE);
    if (requestBody.has(VtnServiceJsonConsts.INTERFACE)
            && requestBody.get(VtnServiceJsonConsts.INTERFACE).isJsonObject()) {
        final JsonObject vRouterInterface = requestBody.getAsJsonObject(VtnServiceJsonConsts.INTERFACE);
        // validation for key: if_name(mandatory)
        setInvalidParameter(VtnServiceJsonConsts.IFNAME);
        if (vRouterInterface.has(VtnServiceJsonConsts.IFNAME)
                && vRouterInterface.getAsJsonPrimitive(VtnServiceJsonConsts.IFNAME).getAsString() != null) {
            isValid = validator.isValidMaxLengthAlphaNum(
                    vRouterInterface.getAsJsonPrimitive(VtnServiceJsonConsts.IFNAME).getAsString(),
                    VtnServiceJsonConsts.LEN_31);
        }
        if (isValid) {
            isValid = validatePut(requestBody);
        }

    }
    LOG.trace("Complete VRouterInterfaceResourceValidator#validatePost()");
    return isValid;
}

From source file:org.opendaylight.vtn.javaapi.validation.logical.VRouterInterfaceResourceValidator.java

License:Open Source License

/**
 * Validate put request Json object for VrouterInterface API.
 * /* w  ww .j  a v 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 VRouterInterfaceResourceValidator#validatePost()");
    boolean isValid = false;
    setInvalidParameter(VtnServiceJsonConsts.INTERFACE);
    if (requestBody.has(VtnServiceJsonConsts.INTERFACE)
            && requestBody.get(VtnServiceJsonConsts.INTERFACE).isJsonObject()) {
        isValid = true;
        final JsonObject vRouterInterface = requestBody.getAsJsonObject(VtnServiceJsonConsts.INTERFACE);
        // validation for key: description(optional)
        if (isValid) {
            setInvalidParameter(VtnServiceJsonConsts.DESCRIPTION);
            if (vRouterInterface.has(VtnServiceJsonConsts.DESCRIPTION) && vRouterInterface
                    .getAsJsonPrimitive(VtnServiceJsonConsts.DESCRIPTION).getAsString() != null) {
                isValid = validator
                        .isValidMaxLength(vRouterInterface.getAsJsonPrimitive(VtnServiceJsonConsts.DESCRIPTION)
                                .getAsString(), VtnServiceJsonConsts.LEN_127)
                        || vRouterInterface.getAsJsonPrimitive(VtnServiceJsonConsts.DESCRIPTION).getAsString()
                                .isEmpty();
            }
        }
        // validation for key: adminstatus(optional)
        if (isValid) {
            setInvalidParameter(VtnServiceJsonConsts.ADMINSTATUS);
            if (vRouterInterface.has(VtnServiceJsonConsts.ADMINSTATUS) && vRouterInterface
                    .getAsJsonPrimitive(VtnServiceJsonConsts.ADMINSTATUS).getAsString() != null) {
                final String adminStatus = vRouterInterface.getAsJsonPrimitive(VtnServiceJsonConsts.ADMINSTATUS)
                        .getAsString();
                isValid = adminStatus.equalsIgnoreCase(VtnServiceJsonConsts.ENABLE)
                        || adminStatus.equalsIgnoreCase(VtnServiceJsonConsts.DISABLE);
            }
        }
        // validation for key: ipaddr(optional)
        if (isValid) {
            setInvalidParameter(VtnServiceJsonConsts.IPADDR);
            if (vRouterInterface.has(VtnServiceJsonConsts.IPADDR)
                    && vRouterInterface.getAsJsonPrimitive(VtnServiceJsonConsts.IPADDR).getAsString() != null) {
                isValid = validator.isValidIpV4(
                        vRouterInterface.getAsJsonPrimitive(VtnServiceJsonConsts.IPADDR).getAsString());
            }
        }
        // validation for key: netmask(optional)
        if (isValid) {
            setInvalidParameter(VtnServiceJsonConsts.PREFIX);
            if (vRouterInterface.has(VtnServiceJsonConsts.PREFIX)) {
                isValid = validator.isValidRange(
                        vRouterInterface.getAsJsonPrimitive(VtnServiceJsonConsts.PREFIX).getAsString(),
                        VtnServiceJsonConsts.VAL_1, VtnServiceJsonConsts.VAL_30);
            }
        }
        // validation for key: macaddr(optional)
        if (isValid) {
            setInvalidParameter(VtnServiceJsonConsts.MACADDR);
            if (vRouterInterface.has(VtnServiceJsonConsts.MACADDR) && vRouterInterface
                    .getAsJsonPrimitive(VtnServiceJsonConsts.MACADDR).getAsString() != null) {
                isValid = validator.isValidMacAddress(
                        vRouterInterface.getAsJsonPrimitive(VtnServiceJsonConsts.MACADDR).getAsString());
            }
        }
    }
    LOG.trace("Complete VRouterInterfaceResourceValidator#validatePost()");
    return isValid;
}

From source file:org.opendaylight.vtn.javaapi.validation.logical.VRouterResourceValidator.java

License:Open Source License

/**
 * Validate post request Json object of Vrouter API.
 * /* w  w w  . j  a va2  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 VRouterResourceValidator#validatePost()");
    boolean isValid = false;
    setInvalidParameter(VtnServiceJsonConsts.VROUTER);
    if (requestBody.has(VtnServiceJsonConsts.VROUTER)
            && requestBody.get(VtnServiceJsonConsts.VROUTER).isJsonObject()) {
        final JsonObject vRouter = requestBody.getAsJsonObject(VtnServiceJsonConsts.VROUTER);
        // validation for key: vrt_name(mandatory)
        setInvalidParameter(VtnServiceJsonConsts.VRTNAME);
        if (vRouter.has(VtnServiceJsonConsts.VRTNAME)
                && vRouter.getAsJsonPrimitive(VtnServiceJsonConsts.VRTNAME).getAsString() != null) {
            isValid = validator.isValidMaxLengthAlphaNum(
                    vRouter.getAsJsonPrimitive(VtnServiceJsonConsts.VRTNAME).getAsString(),
                    VtnServiceJsonConsts.LEN_31);
        }
        // validation for key: controller_id(mandatory)
        if (isValid) {
            setInvalidParameter(VtnServiceJsonConsts.CONTROLLERID);
            if (vRouter.has(VtnServiceJsonConsts.CONTROLLERID)
                    && vRouter.getAsJsonPrimitive(VtnServiceJsonConsts.CONTROLLERID).getAsString() != null) {
                isValid = validator.isValidMaxLengthAlphaNum(
                        vRouter.getAsJsonPrimitive(VtnServiceJsonConsts.CONTROLLERID).getAsString(),
                        VtnServiceJsonConsts.LEN_31);
            } else {
                isValid = false;
            }
        }
        // validation for key: description(optional)
        if (isValid) {
            setInvalidParameter(VtnServiceJsonConsts.DESCRIPTION);
            if (vRouter.has(VtnServiceJsonConsts.DESCRIPTION)
                    && vRouter.getAsJsonPrimitive(VtnServiceJsonConsts.DESCRIPTION).getAsString() != null) {
                isValid = validator.isValidMaxLength(
                        vRouter.getAsJsonPrimitive(VtnServiceJsonConsts.DESCRIPTION).getAsString(),
                        VtnServiceJsonConsts.LEN_127)
                        || vRouter.getAsJsonPrimitive(VtnServiceJsonConsts.DESCRIPTION).getAsString().isEmpty();
            }
        }

        if (isValid) {
            setInvalidParameter(VtnServiceJsonConsts.DOMAINID);
            if (vRouter.has(VtnServiceJsonConsts.DOMAINID)
                    && vRouter.getAsJsonPrimitive(VtnServiceJsonConsts.DOMAINID).getAsString() != null) {
                isValid = validator.isValidDomainId(
                        vRouter.getAsJsonPrimitive(VtnServiceJsonConsts.DOMAINID).getAsString(),
                        VtnServiceJsonConsts.LEN_31);
            } else {
                isValid = false;
            }
        }
    }
    LOG.trace("Complete VRouterResourceValidator#validatePost()");
    return isValid;
}

From source file:org.opendaylight.vtn.javaapi.validation.logical.VRouterResourceValidator.java

License:Open Source License

/**
 * Validate put request Json object for Vrouter API.
 * //from ww w  . j  a v  a  2  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 VRouterResourceValidator#validatePut()");
    boolean isValid = false;
    setInvalidParameter(VtnServiceJsonConsts.VROUTER);
    if (requestBody.has(VtnServiceJsonConsts.VROUTER)
            && requestBody.get(VtnServiceJsonConsts.VROUTER).isJsonObject()) {
        isValid = true;
        final JsonObject vRouter = requestBody.getAsJsonObject(VtnServiceJsonConsts.VROUTER);
        // validation for key: description(optional)
        if (isValid) {
            setInvalidParameter(VtnServiceJsonConsts.DESCRIPTION);
            if (vRouter.has(VtnServiceJsonConsts.DESCRIPTION)
                    && vRouter.getAsJsonPrimitive(VtnServiceJsonConsts.DESCRIPTION).getAsString() != null) {
                isValid = validator.isValidMaxLength(
                        vRouter.getAsJsonPrimitive(VtnServiceJsonConsts.DESCRIPTION).getAsString(),
                        VtnServiceJsonConsts.LEN_127)
                        || vRouter.getAsJsonPrimitive(VtnServiceJsonConsts.DESCRIPTION).getAsString().isEmpty();
            }
        }
    }
    LOG.trace("Complete VRouterResourceValidator#validatePut()");
    return isValid;
}

From source file:org.opendaylight.vtn.javaapi.validation.logical.VTepGroupResourceValidator.java

License:Open Source License

/**
 * validate post request Json object for VTepGroupresource
 * //from  w  ww .  j  a  v  a  2  s.  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 VTepGroupResourceValidator#validatePost()");
    boolean isValid = false;
    setInvalidParameter(VtnServiceJsonConsts.VTEPGROUP);
    if (requestBody.has(VtnServiceJsonConsts.VTEPGROUP)
            && requestBody.get(VtnServiceJsonConsts.VTEPGROUP).isJsonObject()) {
        final JsonObject vTep = requestBody.getAsJsonObject(VtnServiceJsonConsts.VTEPGROUP);
        // validation for key: vtepgroup_name(mandatory)
        setInvalidParameter(VtnServiceJsonConsts.VTEPGROUPNAME);
        if (vTep.has(VtnServiceJsonConsts.VTEPGROUPNAME)
                && vTep.getAsJsonPrimitive(VtnServiceJsonConsts.VTEPGROUPNAME).getAsString() != null) {
            isValid = validator.isValidMaxLengthAlphaNum(
                    vTep.getAsJsonPrimitive(VtnServiceJsonConsts.VTEPGROUPNAME).getAsString(),
                    VtnServiceJsonConsts.LEN_31);
        }
        // validation for key: controller_id(mandatory)
        if (isValid) {
            setInvalidParameter(VtnServiceJsonConsts.CONTROLLERID);
            if (vTep.has(VtnServiceJsonConsts.CONTROLLERID)
                    && vTep.getAsJsonPrimitive(VtnServiceJsonConsts.CONTROLLERID).getAsString() != null) {
                isValid = validator.isValidMaxLengthAlphaNum(
                        vTep.getAsJsonPrimitive(VtnServiceJsonConsts.CONTROLLERID).getAsString(),
                        VtnServiceJsonConsts.LEN_31);
            } else {
                isValid = false;
            }
        }
        // validation for key: description (optional)
        if (isValid) {
            setInvalidParameter(VtnServiceJsonConsts.DESCRIPTION);
            if (vTep.has(VtnServiceJsonConsts.DESCRIPTION)
                    && vTep.getAsJsonPrimitive(VtnServiceJsonConsts.DESCRIPTION).getAsString() != null
                    && !vTep.getAsJsonPrimitive(VtnServiceJsonConsts.DESCRIPTION).getAsString().isEmpty()) {
                isValid = validator.isValidMaxLength(
                        vTep.getAsJsonPrimitive(VtnServiceJsonConsts.DESCRIPTION).getAsString(),
                        VtnServiceJsonConsts.LEN_127);
            }
        }
        if (isValid) {
            isValid = validatePut(requestBody);
        }
    }
    LOG.trace("Complete VTepGroupResourceValidator#validatePost()");
    return isValid;
}

From source file:org.opendaylight.vtn.javaapi.validation.logical.VTepGroupResourceValidator.java

License:Open Source License

/**
 * validate put request Json object for VTepGroup API.
 * /* w  w w. j  av  a 2s. c o  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 VTepGroupResourceValidator#validatePut()");
    boolean isValid = false;
    setInvalidParameter(VtnServiceJsonConsts.VTEPGROUP);
    if (requestBody.has(VtnServiceJsonConsts.VTEPGROUP)
            && requestBody.get(VtnServiceJsonConsts.VTEPGROUP).isJsonObject()) {
        isValid = true;
        final JsonObject vTep = requestBody.getAsJsonObject(VtnServiceJsonConsts.VTEPGROUP);
        setInvalidParameter(VtnServiceJsonConsts.MEMBERVTEPS);
        if (vTep.has(VtnServiceJsonConsts.MEMBERVTEPS)
                && vTep.get(VtnServiceJsonConsts.MEMBERVTEPS).isJsonArray()) {
            final JsonArray memberVtep = vTep.getAsJsonArray(VtnServiceJsonConsts.MEMBERVTEPS);
            final Iterator<JsonElement> vtep = memberVtep.iterator();
            while (vtep.hasNext()) {
                if (isValid) {
                    setInvalidParameter(VtnServiceJsonConsts.VTEPNAME);
                    final JsonObject vtepName = (JsonObject) vtep.next();
                    // validation for key: vtep_name(optinal)
                    if (vtepName.has(VtnServiceJsonConsts.VTEPNAME)
                            && vtepName.getAsJsonPrimitive(VtnServiceJsonConsts.VTEPNAME).getAsString() != null
                            && !vtepName.getAsJsonPrimitive(VtnServiceJsonConsts.VTEPNAME).getAsString()
                                    .isEmpty()) {
                        isValid = validator.isValidMaxLengthAlphaNum(
                                vtepName.getAsJsonPrimitive(VtnServiceJsonConsts.VTEPNAME).getAsString(),
                                VtnServiceJsonConsts.LEN_31);
                    }
                }
            }
        }
    }
    LOG.trace("Complete VTepGroupResourceValidator#validatePut()");
    return isValid;
}

From source file:org.opendaylight.vtn.javaapi.validation.logical.VTepResourceValidator.java

License:Open Source License

/**
 * validate post request Json object for VTep API.
 * /*  w w w  . j  av a 2  s. 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 VTepResourceValidator#validatePost()");
    boolean isValid = false;
    setInvalidParameter(VtnServiceJsonConsts.VTEP);
    if (requestBody.has(VtnServiceJsonConsts.VTEP)
            && requestBody.get(VtnServiceJsonConsts.VTEP).isJsonObject()) {
        final JsonObject vTep = requestBody.getAsJsonObject(VtnServiceJsonConsts.VTEP);
        // validation for key: vtep_name(mandatory)
        setInvalidParameter(VtnServiceJsonConsts.VTEPNAME);
        if (vTep.has(VtnServiceJsonConsts.VTEPNAME)
                && vTep.getAsJsonPrimitive(VtnServiceJsonConsts.VTEPNAME).getAsString() != null) {
            isValid = validator.isValidMaxLengthAlphaNum(
                    vTep.getAsJsonPrimitive(VtnServiceJsonConsts.VTEPNAME).getAsString(),
                    VtnServiceJsonConsts.LEN_31);
        }
        // validation for key: controller_id(mandatory)
        if (isValid) {
            setInvalidParameter(VtnServiceJsonConsts.CONTROLLERID);
            if (vTep.has(VtnServiceJsonConsts.CONTROLLERID)
                    && vTep.getAsJsonPrimitive(VtnServiceJsonConsts.CONTROLLERID).getAsString() != null) {
                isValid = validator.isValidMaxLengthAlphaNum(
                        vTep.getAsJsonPrimitive(VtnServiceJsonConsts.CONTROLLERID).getAsString(),
                        VtnServiceJsonConsts.LEN_31);
            } else {
                isValid = false;
            }
        }
        // validation for key: description(optional)
        if (isValid) {
            setInvalidParameter(VtnServiceJsonConsts.DESCRIPTION);
            if (vTep.has(VtnServiceJsonConsts.DESCRIPTION)
                    && vTep.getAsJsonPrimitive(VtnServiceJsonConsts.DESCRIPTION).getAsString() != null
                    && !vTep.getAsJsonPrimitive(VtnServiceJsonConsts.DESCRIPTION).getAsString().isEmpty()) {
                isValid = validator.isValidMaxLength(
                        vTep.getAsJsonPrimitive(VtnServiceJsonConsts.DESCRIPTION).getAsString(),
                        VtnServiceJsonConsts.LEN_127);
            }
        }
        // validation for key: DomainID(mandatory)
        if (isValid) {
            setInvalidParameter(VtnServiceJsonConsts.DOMAINID);
            if (vTep.has(VtnServiceJsonConsts.DOMAINID)
                    && vTep.getAsJsonPrimitive(VtnServiceJsonConsts.DOMAINID).getAsString() != null) {
                isValid = validator.isValidDomainId(
                        vTep.getAsJsonPrimitive(VtnServiceJsonConsts.DOMAINID).getAsString(),
                        VtnServiceJsonConsts.LEN_31);
            } else {
                isValid = false;
            }
        }
    }
    LOG.trace("Complete VTepResourceValidator#validatePost()");
    return isValid;
}

From source file:org.opendaylight.vtn.javaapi.validation.logical.VTepResourceValidator.java

License:Open Source License

/**
 * validate put request Json object for VTep API.
 * //  ww  w. jav  a  2 s . co m
 * @param requestBody
 *            the request Json object
 * @return true, if successful
 */
private boolean validatePut(final JsonObject requestBody) {
    LOG.trace("Start VTepResourceValidator#validatePut()");
    boolean isValid = false;
    setInvalidParameter(VtnServiceJsonConsts.VTEP);
    if (requestBody.has(VtnServiceJsonConsts.VTEP)
            && requestBody.get(VtnServiceJsonConsts.VTEP).isJsonObject()) {
        isValid = true;
        final JsonObject vTep = requestBody.getAsJsonObject(VtnServiceJsonConsts.VTEP);
        // validation for key: controller_id
        setInvalidParameter(VtnServiceJsonConsts.CONTROLLERID);
        if (vTep.has(VtnServiceJsonConsts.CONTROLLERID)) {
            isValid = false;
        }
        // validation for key: description(optional)
        if (isValid) {
            setInvalidParameter(VtnServiceJsonConsts.DESCRIPTION);
            if (isValid && vTep.has(VtnServiceJsonConsts.DESCRIPTION)
                    && vTep.getAsJsonPrimitive(VtnServiceJsonConsts.DESCRIPTION).getAsString() != null
                    && !vTep.getAsJsonPrimitive(VtnServiceJsonConsts.DESCRIPTION).getAsString().isEmpty()) {
                isValid = validator.isValidMaxLength(
                        vTep.getAsJsonPrimitive(VtnServiceJsonConsts.DESCRIPTION).getAsString(),
                        VtnServiceJsonConsts.LEN_127);
            }
        }
        // validation for key: DomainID
        if (isValid) {
            setInvalidParameter(VtnServiceJsonConsts.DOMAINID);
            if (vTep.has(VtnServiceJsonConsts.DOMAINID)) {
                isValid = false;
            }
        }
    }
    LOG.trace("Complete VTepResourceValidator#validatePut()");
    return isValid;
}

From source file:org.opendaylight.vtn.javaapi.validation.logical.VTerminalInterfacePolicingMapResourceValidator.java

License:Open Source License

/**
 * validate put request JSON object for PolcingMap API.
 * /*from   w  w w.j a va 2 s.co  m*/
 * @param requestBody
 *            the request JSON object
 * @return true, if successful
 */
private boolean validatePut(final JsonObject requestBody) {
    LOG.trace("Start VTerminalInterfacePolicingMapResourceValidator#validatePut()");
    boolean isValid = false;
    setInvalidParameter(VtnServiceJsonConsts.POLICINGMAP);
    if (requestBody.has(VtnServiceJsonConsts.POLICINGMAP)
            && requestBody.get(VtnServiceJsonConsts.POLICINGMAP).isJsonObject()) {
        final JsonObject policing = requestBody.getAsJsonObject(VtnServiceJsonConsts.POLICINGMAP);

        // validation for mandatory key: prf_name
        if (policing.has(VtnServiceJsonConsts.PROFILE_NAME)
                && policing.getAsJsonPrimitive(VtnServiceJsonConsts.PROFILE_NAME).getAsString() != null) {
            isValid = validator.isValidMaxLengthAlphaNum(
                    policing.getAsJsonPrimitive(VtnServiceJsonConsts.PROFILE_NAME).getAsString(),
                    VtnServiceJsonConsts.LEN_32);
        }

    }
    LOG.trace("Complete VTerminalInterfacePolicingMapResourceValidator#validatePut()");
    return isValid;
}