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.FlowFilterResourceValidator.java

License:Open Source License

/**
 * Validate post request json for FlowFilter API
 * /*w  w w .j a v a2  s  . com*/
 * @param requestBody
 *            the request Json object
 * @return true, if successful
 */
private boolean validatePost(final JsonObject requestBody) {
    LOG.trace("Start FlowFilterResourceValidator#validatePost()");
    boolean isValid = false;
    setInvalidParameter(VtnServiceJsonConsts.FLOWFILTER);
    if (requestBody.has(VtnServiceJsonConsts.FLOWFILTER)
            && requestBody.get(VtnServiceJsonConsts.FLOWFILTER).isJsonObject()) {
        final JsonObject flowFilter = requestBody.getAsJsonObject(VtnServiceJsonConsts.FLOWFILTER);
        setInvalidParameter(VtnServiceJsonConsts.FFTYPE);
        if (flowFilter.has(VtnServiceJsonConsts.FFTYPE)
                && flowFilter.getAsJsonPrimitive(VtnServiceJsonConsts.FFTYPE).getAsString() != null) {
            final String ffType = flowFilter.getAsJsonPrimitive(VtnServiceJsonConsts.FFTYPE).getAsString();
            isValid = ffType.equalsIgnoreCase(VtnServiceJsonConsts.IN)
                    || ffType.equalsIgnoreCase(VtnServiceJsonConsts.OUT);
        }
    }
    LOG.trace("Complete FlowFilterResourceValidator#validatePost()");
    return isValid;
}

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

License:Open Source License

/**
 * Validate put request Json object for FlowListEntry API
 * //w  w  w  .  j  a  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 FlowListEntryResourceValidator#validatePut()");
    boolean isValid = false;
    setInvalidParameter(VtnServiceJsonConsts.FLOWLISTENTRY);
    if (requestBody.has(VtnServiceJsonConsts.FLOWLISTENTRY)
            && requestBody.get(VtnServiceJsonConsts.FLOWLISTENTRY).isJsonObject()) {
        isValid = true;
        final JsonObject flowListEntry = requestBody.getAsJsonObject(VtnServiceJsonConsts.FLOWLISTENTRY);
        // validation for key: macdstaddr(optional)
        if (isValid) {
            setInvalidParameter(VtnServiceJsonConsts.MACDSTADDR);
            if (flowListEntry.has(VtnServiceJsonConsts.MACDSTADDR) && flowListEntry
                    .getAsJsonPrimitive(VtnServiceJsonConsts.MACDSTADDR).getAsString() != null) {
                isValid = validator.isValidMacAddress(
                        flowListEntry.getAsJsonPrimitive(VtnServiceJsonConsts.MACDSTADDR).getAsString());
            }
        }
        // validation for key: macsrcaddr
        if (isValid) {
            setInvalidParameter(VtnServiceJsonConsts.MACSRCADDR);
            if (flowListEntry.has(VtnServiceJsonConsts.MACSRCADDR) && flowListEntry
                    .getAsJsonPrimitive(VtnServiceJsonConsts.MACSRCADDR).getAsString() != null) {
                isValid = validator.isValidMacAddress(
                        flowListEntry.getAsJsonPrimitive(VtnServiceJsonConsts.MACSRCADDR).getAsString());
            }
        }
        // validation for key: macethertype
        if (isValid) {
            setInvalidParameter(VtnServiceJsonConsts.MACETHERTYPE);
            if (flowListEntry.has(VtnServiceJsonConsts.MACETHERTYPE) && flowListEntry
                    .getAsJsonPrimitive(VtnServiceJsonConsts.MACETHERTYPE).getAsString() != null) {
                isValid = validator.isValidEtherType(
                        flowListEntry.getAsJsonPrimitive(VtnServiceJsonConsts.MACETHERTYPE).getAsString());
            }
        }
        // validation for key: macvlanpriority
        if (isValid) {
            setInvalidParameter(VtnServiceJsonConsts.MACVLANPRIORITY);
            if (flowListEntry.has(VtnServiceJsonConsts.MACVLANPRIORITY) && flowListEntry
                    .getAsJsonPrimitive(VtnServiceJsonConsts.MACVLANPRIORITY).getAsString() != null) {
                isValid = validator.isValidRange(
                        flowListEntry.getAsJsonPrimitive(VtnServiceJsonConsts.MACVLANPRIORITY).getAsString(),
                        VtnServiceJsonConsts.VAL_0, VtnServiceJsonConsts.VAL_7);
            }
        }
        // validation for key: ipdstaddr
        if (isValid) {
            setInvalidParameter(VtnServiceJsonConsts.IPDSTADDR);
            if (flowListEntry.has(VtnServiceJsonConsts.IPDSTADDR)
                    && flowListEntry.getAsJsonPrimitive(VtnServiceJsonConsts.IPDSTADDR).getAsString() != null) {
                isValid = validator.isValidIpV4(
                        flowListEntry.getAsJsonPrimitive(VtnServiceJsonConsts.IPDSTADDR).getAsString());
            }
        }
        // validation for key: ipdstaddrprefix
        if (isValid) {
            setInvalidParameter(VtnServiceJsonConsts.IPDSTADDRPREFIX);
            if (flowListEntry.has(VtnServiceJsonConsts.IPDSTADDRPREFIX) && flowListEntry
                    .getAsJsonPrimitive(VtnServiceJsonConsts.IPDSTADDRPREFIX).getAsString() != null) {
                isValid = validator.isValidRange(
                        flowListEntry.getAsJsonPrimitive(VtnServiceJsonConsts.IPDSTADDRPREFIX).getAsString(),
                        VtnServiceJsonConsts.VAL_1, VtnServiceJsonConsts.VAL_32);
            }
        }
        // validation for key: ipsrcaddr
        if (isValid) {
            setInvalidParameter(VtnServiceJsonConsts.IPSRCADDR);
            if (flowListEntry.has(VtnServiceJsonConsts.IPSRCADDR)
                    && flowListEntry.getAsJsonPrimitive(VtnServiceJsonConsts.IPSRCADDR).getAsString() != null) {
                isValid = validator.isValidIpV4(
                        flowListEntry.getAsJsonPrimitive(VtnServiceJsonConsts.IPSRCADDR).getAsString());
            }
        }
        // validation for key: ipsrcaddrprefix
        if (isValid) {
            setInvalidParameter(VtnServiceJsonConsts.IPSRCADDRPREFIX);
            if (flowListEntry.has(VtnServiceJsonConsts.IPSRCADDRPREFIX) && flowListEntry
                    .getAsJsonPrimitive(VtnServiceJsonConsts.IPSRCADDRPREFIX).getAsString() != null) {
                isValid = validator.isValidRange(
                        flowListEntry.getAsJsonPrimitive(VtnServiceJsonConsts.IPSRCADDRPREFIX).getAsString(),
                        VtnServiceJsonConsts.VAL_1, VtnServiceJsonConsts.VAL_32);
            }
        }
        // validation for key: ipv6dstaddr"
        if (isValid) {
            setInvalidParameter(VtnServiceJsonConsts.IPV6DSTADDR);
            if (flowListEntry.has(VtnServiceJsonConsts.IPV6DSTADDR) && flowListEntry
                    .getAsJsonPrimitive(VtnServiceJsonConsts.IPV6DSTADDR).getAsString() != null) {
                isValid = validator.isValidIpV6(
                        flowListEntry.getAsJsonPrimitive(VtnServiceJsonConsts.IPV6DSTADDR).getAsString());
            }
        }
        // validation for key: ipv6dstaddrprefix
        if (isValid) {
            setInvalidParameter(VtnServiceJsonConsts.IPV6DSTADDRPREFIX);
            if (flowListEntry.has(VtnServiceJsonConsts.IPV6DSTADDRPREFIX) && flowListEntry
                    .getAsJsonPrimitive(VtnServiceJsonConsts.IPV6DSTADDRPREFIX).getAsString() != null) {
                isValid = validator.isValidRange(
                        flowListEntry.getAsJsonPrimitive(VtnServiceJsonConsts.IPV6DSTADDRPREFIX).getAsString(),
                        VtnServiceJsonConsts.VAL_1, VtnServiceJsonConsts.VAL_128);
            }
        }
        // validation for key: ipv6srcaddr
        if (isValid) {
            setInvalidParameter(VtnServiceJsonConsts.IPV6SRCADDR);
            if (flowListEntry.has(VtnServiceJsonConsts.IPV6SRCADDR) && flowListEntry
                    .getAsJsonPrimitive(VtnServiceJsonConsts.IPV6SRCADDR).getAsString() != null) {
                isValid = validator.isValidIpV6(
                        flowListEntry.getAsJsonPrimitive(VtnServiceJsonConsts.IPV6SRCADDR).getAsString());
            }
        }
        // validation for key: ipv6srcaddrprefix
        if (isValid) {
            setInvalidParameter(VtnServiceJsonConsts.IPV6SRCADDRPREFIX);
            if (flowListEntry.has(VtnServiceJsonConsts.IPV6SRCADDRPREFIX) && flowListEntry
                    .getAsJsonPrimitive(VtnServiceJsonConsts.IPV6SRCADDRPREFIX).getAsString() != null) {
                isValid = validator.isValidRange(
                        flowListEntry.getAsJsonPrimitive(VtnServiceJsonConsts.IPV6SRCADDRPREFIX).getAsString(),
                        VtnServiceJsonConsts.VAL_1, VtnServiceJsonConsts.VAL_128);
            }
        }
        // validation for key: ipproto
        if (isValid) {
            setInvalidParameter(VtnServiceJsonConsts.IPPROTO);
            if (flowListEntry.has(VtnServiceJsonConsts.IPPROTO)
                    && flowListEntry.getAsJsonPrimitive(VtnServiceJsonConsts.IPPROTO).getAsString() != null) {
                isValid = validator.isValidRange(
                        flowListEntry.getAsJsonPrimitive(VtnServiceJsonConsts.IPPROTO).getAsString(),
                        VtnServiceJsonConsts.VAL_1, VtnServiceJsonConsts.VAL_255);
            }
        }
        // validation for key: ipdscp
        if (isValid) {
            setInvalidParameter(VtnServiceJsonConsts.IPDSCP);
            if (flowListEntry.has(VtnServiceJsonConsts.IPDSCP)
                    && flowListEntry.getAsJsonPrimitive(VtnServiceJsonConsts.IPDSCP).getAsString() != null) {
                isValid = validator.isValidRange(
                        flowListEntry.getAsJsonPrimitive(VtnServiceJsonConsts.IPDSCP).getAsString(),
                        VtnServiceJsonConsts.VAL_0, VtnServiceJsonConsts.VAL_63);
            }
        }
        // validation for key: l4dstport
        if (isValid) {
            setInvalidParameter(VtnServiceJsonConsts.L4DSTPORT);
            if (flowListEntry.has(VtnServiceJsonConsts.L4DSTPORT)
                    && flowListEntry.getAsJsonPrimitive(VtnServiceJsonConsts.L4DSTPORT).getAsString() != null) {
                isValid = validator.isValidRange(
                        flowListEntry.getAsJsonPrimitive(VtnServiceJsonConsts.L4DSTPORT).getAsString(),
                        VtnServiceJsonConsts.VAL_0, VtnServiceJsonConsts.VAL_65535);
            }
        }
        // validation for key: l4dstendport
        if (isValid) {
            setInvalidParameter(VtnServiceJsonConsts.L4DSTENDPORT);
            if (flowListEntry.has(VtnServiceJsonConsts.L4DSTENDPORT) && flowListEntry
                    .getAsJsonPrimitive(VtnServiceJsonConsts.L4DSTENDPORT).getAsString() != null) {
                isValid = validator.isValidRange(
                        flowListEntry.getAsJsonPrimitive(VtnServiceJsonConsts.L4DSTENDPORT).getAsString(),
                        VtnServiceJsonConsts.VAL_1, VtnServiceJsonConsts.VAL_65535);
            }
        }
        // validation for key: l4srcport
        if (isValid) {
            setInvalidParameter(VtnServiceJsonConsts.L4SRCPORT);
            if (flowListEntry.has(VtnServiceJsonConsts.L4SRCPORT)
                    && flowListEntry.getAsJsonPrimitive(VtnServiceJsonConsts.L4SRCPORT).getAsString() != null) {
                isValid = validator.isValidRange(
                        flowListEntry.getAsJsonPrimitive(VtnServiceJsonConsts.L4SRCPORT).getAsString(),
                        VtnServiceJsonConsts.VAL_0,

                        VtnServiceJsonConsts.VAL_65535);
            }
        }
        // validation for key: l4srcendport
        if (isValid) {
            setInvalidParameter(VtnServiceJsonConsts.L4SRCENDPORT);
            if (flowListEntry.has(VtnServiceJsonConsts.L4SRCENDPORT) && flowListEntry
                    .getAsJsonPrimitive(VtnServiceJsonConsts.L4SRCENDPORT).getAsString() != null) {
                isValid = validator.isValidRange(
                        flowListEntry.getAsJsonPrimitive(VtnServiceJsonConsts.L4SRCENDPORT).getAsString(),
                        VtnServiceJsonConsts.VAL_1, VtnServiceJsonConsts.VAL_65535);
            }
        }
        // validation for key: icmptypenum
        if (isValid) {
            setInvalidParameter(VtnServiceJsonConsts.ICMPTYPENUM);
            if (flowListEntry.has(VtnServiceJsonConsts.ICMPTYPENUM) && flowListEntry
                    .getAsJsonPrimitive(VtnServiceJsonConsts.ICMPTYPENUM).getAsString() != null) {
                isValid = validator.isValidRange(
                        flowListEntry.getAsJsonPrimitive(VtnServiceJsonConsts.ICMPTYPENUM).getAsString(),
                        VtnServiceJsonConsts.VAL_0, VtnServiceJsonConsts.VAL_255);
            }
        }
        // validation for key: icmpcodenum
        if (isValid) {
            setInvalidParameter(VtnServiceJsonConsts.ICMPCODENUM);
            if (flowListEntry.has(VtnServiceJsonConsts.ICMPCODENUM) && flowListEntry
                    .getAsJsonPrimitive(VtnServiceJsonConsts.ICMPCODENUM).getAsString() != null) {
                isValid = validator.isValidRange(
                        flowListEntry.getAsJsonPrimitive(VtnServiceJsonConsts.ICMPCODENUM).getAsString(),
                        VtnServiceJsonConsts.VAL_0, VtnServiceJsonConsts.VAL_255);
            }
        }
        // validation for key: ipv6icmptypenum
        if (isValid) {
            setInvalidParameter(VtnServiceJsonConsts.IPV6ICMPTYPENUM);
            if (flowListEntry.has(VtnServiceJsonConsts.IPV6ICMPTYPENUM) && flowListEntry
                    .getAsJsonPrimitive(VtnServiceJsonConsts.IPV6ICMPTYPENUM).getAsString() != null) {
                isValid = validator.isValidRange(
                        flowListEntry.getAsJsonPrimitive(VtnServiceJsonConsts.IPV6ICMPTYPENUM).getAsString(),
                        VtnServiceJsonConsts.VAL_0, VtnServiceJsonConsts.VAL_255);
            }
        }
        // validation for key: ipv6icmpcodenum
        if (isValid) {
            setInvalidParameter(VtnServiceJsonConsts.IPV6ICMPCODENUM);
            if (flowListEntry.has(VtnServiceJsonConsts.IPV6ICMPCODENUM) && flowListEntry
                    .getAsJsonPrimitive(VtnServiceJsonConsts.IPV6ICMPCODENUM).getAsString() != null) {
                isValid = validator.isValidRange(
                        flowListEntry.getAsJsonPrimitive(VtnServiceJsonConsts.IPV6ICMPCODENUM).getAsString(),
                        VtnServiceJsonConsts.VAL_0, VtnServiceJsonConsts.VAL_255);
            }
        }
    }
    LOG.trace("Complete FlowListEntryResourceValidator#validatePut()");
    return isValid;
}

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

License:Open Source License

/**
 * Validate post request Json object for FlowListEntryresource
 * /*from   ww  w.j  a v  a  2  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 FlowListEntryResourceValidator#validatePost()");
    boolean isValid = false;
    setInvalidParameter(VtnServiceJsonConsts.FLOWLISTENTRY);
    if (requestBody.has(VtnServiceJsonConsts.FLOWLISTENTRY)
            && requestBody.get(VtnServiceJsonConsts.FLOWLISTENTRY).isJsonObject()) {
        final JsonObject flowListEntry = requestBody.getAsJsonObject(VtnServiceJsonConsts.FLOWLISTENTRY);
        // validation for key: seqnum
        setInvalidParameter(VtnServiceJsonConsts.SEQNUM);
        if (flowListEntry.has(VtnServiceJsonConsts.SEQNUM)
                && flowListEntry.getAsJsonPrimitive(VtnServiceJsonConsts.SEQNUM).getAsString() != null) {
            isValid = validator.isValidRange(
                    flowListEntry.getAsJsonPrimitive(VtnServiceJsonConsts.SEQNUM).getAsString(),
                    VtnServiceJsonConsts.VAL_1, VtnServiceJsonConsts.VAL_65535);
        }
        if (isValid) {
            isValid = validatePut(requestBody);
        }

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

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

License:Open Source License

/**
 * Validate post request Json object for FlowList API.
 * /*  w w w .  j  a va  2 s .c  o  m*/
 * @param requestBody
 *            the request Json object
 * @return true, if successful
 */
private boolean validatePost(final JsonObject requestBody) {
    LOG.trace("Start FlowListResourceValidator#validatePost()");
    boolean isValid = false;
    setInvalidParameter(VtnServiceJsonConsts.FLOWLIST);
    if (requestBody.has(VtnServiceJsonConsts.FLOWLIST)
            && requestBody.get(VtnServiceJsonConsts.FLOWLIST).isJsonObject()) {
        final JsonObject flowList = requestBody.getAsJsonObject(VtnServiceJsonConsts.FLOWLIST);
        // validation for madatory key: fl_name
        setInvalidParameter(VtnServiceJsonConsts.FLNAME);
        if (flowList.has(VtnServiceJsonConsts.FLNAME)
                && flowList.getAsJsonPrimitive(VtnServiceJsonConsts.FLNAME).getAsString() != null
                && !flowList.getAsJsonPrimitive(VtnServiceJsonConsts.FLNAME).getAsString().isEmpty()) {
            isValid = validator.isValidMaxLengthAlphaNum(
                    flowList.getAsJsonPrimitive(VtnServiceJsonConsts.FLNAME).getAsString(),
                    VtnServiceJsonConsts.LEN_32);
        }
        // validation for key: ip_version(optional)
        if (isValid) {
            setInvalidParameter(VtnServiceJsonConsts.IPVERSION);
            if (flowList.has(VtnServiceJsonConsts.IPVERSION)
                    && flowList.getAsJsonPrimitive(VtnServiceJsonConsts.IPVERSION).getAsString() != null
                    && !flowList.getAsJsonPrimitive(VtnServiceJsonConsts.IPVERSION).getAsString().isEmpty()) {
                final String ipVersion = flowList.getAsJsonPrimitive(VtnServiceJsonConsts.IPVERSION)
                        .getAsString();
                isValid = ipVersion.equalsIgnoreCase(VtnServiceJsonConsts.IP)
                        || ipVersion.equalsIgnoreCase(VtnServiceJsonConsts.IPV6);
            } else {
                flowList.remove(VtnServiceJsonConsts.IPVERSION);
                flowList.addProperty(VtnServiceJsonConsts.IPVERSION, VtnServiceJsonConsts.IP);
                isValid = true;
            }
        }
    }
    LOG.trace("Complete FlowListResourceValidator#validatePost()");
    return isValid;
}

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

License:Open Source License

/**
 * Validate get request Json object for FlowList API.
 * // ww  w  .java2 s .c o m
 * @param requestBody
 *            the request Json object
 * @param opFlag
 *            the op flag
 * @return true, if successful
 */

private boolean validateGet(final JsonObject requestBody, final boolean opFlag) {
    LOG.trace("Start FlowListResourceValidator#validateGet()");
    boolean isValid = true;
    // validation for key: targetdb
    setInvalidParameter(VtnServiceJsonConsts.TARGETDB);
    isValid = validator.isValidRequestDB(requestBody);
    // validation for key: ip_version(optional)
    if (isValid) {
        setInvalidParameter(VtnServiceJsonConsts.IPVERSION);
        if (requestBody.has(VtnServiceJsonConsts.IPVERSION)
                && requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.IPVERSION).getAsString() != null
                && !requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.IPVERSION).getAsString().isEmpty()) {
            final String ipVersion = requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.IPVERSION)
                    .getAsString();
            isValid = ipVersion.equalsIgnoreCase(VtnServiceJsonConsts.IP)
                    || ipVersion.equalsIgnoreCase(VtnServiceJsonConsts.IPV6);
        } else {
            requestBody.remove(VtnServiceJsonConsts.IPVERSION);
            requestBody.addProperty(VtnServiceJsonConsts.IPVERSION, VtnServiceJsonConsts.IP);
            isValid = true;
        }
    }
    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) {
            setInvalidParameter(VtnServiceJsonConsts.INDEX);
            if (requestBody.has(VtnServiceJsonConsts.INDEX)
                    && requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.INDEX).getAsString() != null
                    && !requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.INDEX).getAsString().isEmpty()) {
                isValid = validator.isValidMaxLengthAlphaNum(
                        requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.INDEX).getAsString(),
                        VtnServiceJsonConsts.LEN_32);
            }
        }
        // validation for key: max_repitition
        if (isValid) {
            setInvalidParameter(VtnServiceJsonConsts.MAX);
            isValid = validator.isValidMaxRepetition(requestBody);
        }
    }
    LOG.trace("Complete FlowListResourceValidator#validateGet()");
    return isValid;
}

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

License:Open Source License

/**
 * Validate put request Json object for HostAddressResource
 * //from www  .  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 HostAddressResourceValidator#validatePut()");
    boolean isValid = false;
    setInvalidParameter(VtnServiceJsonConsts.IPADDRESS);
    if (requestBody.has(VtnServiceJsonConsts.IPADDRESS)
            && requestBody.get(VtnServiceJsonConsts.IPADDRESS).isJsonObject()) {
        final JsonObject ipaddr = requestBody.getAsJsonObject(VtnServiceJsonConsts.IPADDRESS);
        // validation for mandatory keys: ipaddr
        setInvalidParameter(VtnServiceJsonConsts.IPADDR);
        if (ipaddr.has(VtnServiceJsonConsts.IPADDR)
                && ipaddr.getAsJsonPrimitive(VtnServiceJsonConsts.IPADDR).getAsString() != null) {
            isValid = validator
                    .isValidIpV4(ipaddr.getAsJsonPrimitive(VtnServiceJsonConsts.IPADDR).getAsString());
        }
        if (isValid) {
            // validation for mandatory keys: netmask
            setInvalidParameter(VtnServiceJsonConsts.PREFIX);
            if (ipaddr.has(VtnServiceJsonConsts.PREFIX)
                    && ipaddr.getAsJsonPrimitive(VtnServiceJsonConsts.PREFIX).getAsString() != null) {
                isValid = validator.isValidRange(
                        ipaddr.getAsJsonPrimitive(VtnServiceJsonConsts.PREFIX).getAsString(),
                        VtnServiceJsonConsts.VAL_1, VtnServiceJsonConsts.VAL_30);
            } else {
                isValid = false;
            }
        }
    }
    LOG.trace("Complete HostAddressResourceValidator#validatePut()");
    return isValid;
}

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

License:Open Source License

/**
 * Validates op key for DHCP Interface API
 * //from  w w  w .  j av  a 2  s .  c  o  m
 * @param requestBody
 *            the request Json object
 * @param isValid
 *            boolean flag
 * @return true, if successful
 */
private boolean validateOpDhcpInterface(final JsonObject requestBody, boolean isValid) {
    LOG.trace("Start InterfaceResourceValidator#validateOpDhcpInterface()");
    setInvalidParameter(VtnServiceJsonConsts.OP);
    if (requestBody.has(VtnServiceJsonConsts.OP)
            && requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.OP).getAsString() != null
            && !requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.OP).getAsString().isEmpty()) {
        isValid = requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.OP).getAsString()
                .equalsIgnoreCase(VtnServiceJsonConsts.COUNT);
    }
    LOG.trace("Complete InterfaceResourceValidator#validateOpDhcpInterface()");
    return isValid;
}

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

License:Open Source License

/**
 * validate post request Json object for Interface API
 * /* w  w w  .j a v a  2  s. co m*/
 * @param requestBody
 *            the request Json object
 * @return true, if successful
 * @throws VtnServiceException
 */
private boolean validatePost(final JsonObject requestBody) throws VtnServiceException {
    LOG.trace("Start InterfaceResourceValidator#validatePost()");
    boolean isValid = false;
    setInvalidParameter(VtnServiceJsonConsts.INTERFACE);
    if (requestBody.has(VtnServiceJsonConsts.INTERFACE)
            && requestBody.get(VtnServiceJsonConsts.INTERFACE).isJsonObject()) {
        final JsonObject commonInterface = requestBody.getAsJsonObject(VtnServiceJsonConsts.INTERFACE);
        // validation for key: if_name(mandatory)
        setInvalidParameter(VtnServiceJsonConsts.IFNAME);
        if (commonInterface.has(VtnServiceJsonConsts.IFNAME)
                && commonInterface.getAsJsonPrimitive(VtnServiceJsonConsts.IFNAME).getAsString() != null
                && !commonInterface.getAsJsonPrimitive(VtnServiceJsonConsts.IFNAME).getAsString().isEmpty()) {
            isValid = validator.isValidMaxLengthAlphaNum(
                    commonInterface.getAsJsonPrimitive(VtnServiceJsonConsts.IFNAME).getAsString(),
                    VtnServiceJsonConsts.LEN_31);
        }
        if (isValid) {
            isValid = validatePut(requestBody);
        }

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

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

License:Open Source License

/**
 * validate put request Json object for Interface API
 * /*ww w.  jav a  2s . co m*/
 * @param requestBody
 *            the request Json object
 * @return true, if successful
 * @throws VtnServiceException
 */
private boolean validatePut(final JsonObject requestBody) {
    LOG.trace("Start InterfaceResourceValidator#validatePut()");
    boolean isValid = false;
    setInvalidParameter(VtnServiceJsonConsts.INTERFACE);
    if (requestBody.has(VtnServiceJsonConsts.INTERFACE)
            && requestBody.get(VtnServiceJsonConsts.INTERFACE).isJsonObject()) {
        isValid = true;
        final JsonObject commonInterface = requestBody.getAsJsonObject(VtnServiceJsonConsts.INTERFACE);
        // validation for key: description(optional)
        setInvalidParameter(VtnServiceJsonConsts.DESCRIPTION);
        if (commonInterface.has(VtnServiceJsonConsts.DESCRIPTION)
                && commonInterface.getAsJsonPrimitive(VtnServiceJsonConsts.DESCRIPTION).getAsString() != null
                && !commonInterface.getAsJsonPrimitive(VtnServiceJsonConsts.DESCRIPTION).getAsString()
                        .isEmpty()) {
            isValid = validator.isValidMaxLength(
                    commonInterface.getAsJsonPrimitive(VtnServiceJsonConsts.DESCRIPTION).getAsString(),
                    VtnServiceJsonConsts.LEN_127);
        }
        // validation for key: adminstatus(optional)
        if (isValid) {
            setInvalidParameter(VtnServiceJsonConsts.ADMINSTATUS);
            if (commonInterface.has(VtnServiceJsonConsts.ADMINSTATUS) && commonInterface
                    .getAsJsonPrimitive(VtnServiceJsonConsts.ADMINSTATUS).getAsString() != null) {
                final String adminStatus = commonInterface.getAsJsonPrimitive(VtnServiceJsonConsts.ADMINSTATUS)
                        .getAsString();
                isValid = adminStatus.equalsIgnoreCase(VtnServiceJsonConsts.ENABLE)
                        || adminStatus.equalsIgnoreCase(VtnServiceJsonConsts.DISABLE)
                        || adminStatus.equalsIgnoreCase(VtnServiceJsonConsts.EMPTY);
            }
        }
    }
    LOG.trace("Complete InterfaceResourceValidator#validatePut()");
    return isValid;
}

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

License:Open Source License

/**
 * Validate post request Json object for Lanbel Range API
 * // w  w w  .  j  a  v  a 2s  .co  m
 * @param requestBody
 *            the request Json object
 * @return true, if successful
 */
private boolean validatePost(final JsonObject requestBody) {
    LOG.trace("Start LabelRangeResourceValidator#validatePost()");
    boolean isValid = false;
    setInvalidParameter(VtnServiceJsonConsts.RANGE);
    if (requestBody.has(VtnServiceJsonConsts.RANGE)
            && requestBody.get(VtnServiceJsonConsts.RANGE).isJsonObject()) {
        final JsonObject range = requestBody.getAsJsonObject(VtnServiceJsonConsts.RANGE);

        // validation for mandatory key: min
        setInvalidParameter(VtnServiceJsonConsts.RANGE_MIN);
        if (range.has(VtnServiceJsonConsts.RANGE_MIN)
                && range.get(VtnServiceJsonConsts.RANGE_MIN).isJsonPrimitive()) {
            isValid = validator.isValidRange(
                    range.getAsJsonPrimitive(VtnServiceJsonConsts.RANGE_MIN).getAsString(),
                    VtnServiceJsonConsts.VAL_1, VtnServiceJsonConsts.VAL_4000);
        } else {
            isValid = false;
        }

        // validation for mandatory key: max
        if (isValid) {
            setInvalidParameter(VtnServiceJsonConsts.RANGE_MAX);
            if (range.has(VtnServiceJsonConsts.RANGE_MAX)
                    && range.get(VtnServiceJsonConsts.RANGE_MAX).isJsonPrimitive()) {
                isValid = validator.isValidRange(
                        range.getAsJsonPrimitive(VtnServiceJsonConsts.RANGE_MAX).getAsString(),
                        VtnServiceJsonConsts.VAL_1, VtnServiceJsonConsts.VAL_4000);
            } else {
                isValid = false;
            }
        }
    }
    LOG.trace("Complete LabelRangeResourceValidator#validatePost()");
    return isValid;
}