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

License:Open Source License

/**
 * Validate put request Json object for StaticIpRoute API.
 * /*  w  ww  .  j a v  a2 s.c om*/
 * @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 StaticIpRouteResourceValidator#validatePut()");
    boolean isValid = false;

    setInvalidParameter(VtnServiceJsonConsts.STATIC_IPROUTE);

    if (requestBody.has(VtnServiceJsonConsts.STATIC_IPROUTE)
            && requestBody.get(VtnServiceJsonConsts.STATIC_IPROUTE).isJsonObject()) {
        final JsonObject staticIp = requestBody.getAsJsonObject(VtnServiceJsonConsts.STATIC_IPROUTE);
        // validation for key: nexthopaddress (mandatory)
        setInvalidParameter(VtnServiceJsonConsts.NEXTHOPADDR);
        if (staticIp.has(VtnServiceJsonConsts.NEXTHOPADDR)
                && staticIp.getAsJsonPrimitive(VtnServiceJsonConsts.NEXTHOPADDR).getAsString() != null) {
            isValid = validator
                    .isValidIpV4(staticIp.getAsJsonPrimitive(VtnServiceJsonConsts.NEXTHOPADDR).getAsString());
        }
    }
    LOG.trace("Complete StaticIpRouteResourceValidator#validatePut()");
    return isValid;
}

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

License:Open Source License

/**
 * Validate post request Json object for UnifiedNetworks API
 * //from w  ww .  jav  a2  s  .c om
 * @param requestBody
 *            the request Json object
 * @return true, if successful
 */
private boolean validatePost(final JsonObject requestBody) {
    LOG.trace("Start UnifiedNetworkResourceValidator#validatePost()");

    boolean isValid = false;
    setInvalidParameter(VtnServiceJsonConsts.UNIFIED_NW);
    if (requestBody.has(VtnServiceJsonConsts.UNIFIED_NW)
            && requestBody.get(VtnServiceJsonConsts.UNIFIED_NW).isJsonObject()) {

        final JsonObject unifiedNw = requestBody.getAsJsonObject(VtnServiceJsonConsts.UNIFIED_NW);

        setInvalidParameter(VtnServiceJsonConsts.UNIFIED_NW_NAME);
        // validation for mandatory key: unified_network_name
        if (unifiedNw.has(VtnServiceJsonConsts.UNIFIED_NW_NAME)
                && unifiedNw.get(VtnServiceJsonConsts.UNIFIED_NW_NAME).isJsonPrimitive() && !unifiedNw
                        .getAsJsonPrimitive(VtnServiceJsonConsts.UNIFIED_NW_NAME).getAsString().isEmpty()) {

            isValid = validator.isValidMaxLengthAlphaNum(
                    unifiedNw.getAsJsonPrimitive(VtnServiceJsonConsts.UNIFIED_NW_NAME).getAsString(),
                    VtnServiceJsonConsts.LEN_31);
        }

        if (isValid) {
            // validation for mandatory key: routing_type
            setInvalidParameter(VtnServiceJsonConsts.ROUTING_TYPE);
            if (unifiedNw.has(VtnServiceJsonConsts.ROUTING_TYPE)
                    && unifiedNw.get(VtnServiceJsonConsts.ROUTING_TYPE).isJsonPrimitive() && !unifiedNw
                            .getAsJsonPrimitive(VtnServiceJsonConsts.ROUTING_TYPE).getAsString().isEmpty()) {

                isValid = VtnServiceJsonConsts.ONE
                        .equals(unifiedNw.getAsJsonPrimitive(VtnServiceJsonConsts.ROUTING_TYPE).getAsString());
            } else {
                isValid = false;
            }
        }
    }

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

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

License:Open Source License

/**
 * validate post request Json object for VbridgeFlowFilterEntry,
 * VbridgeInetrfaceFlowFilterEntry and VrouterInterfaceFlowFilterEntry 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 validatePost(final JsonObject requestBody) {
    LOG.trace("Start VBridgeFlowFilterEntriesResourceValidator#validatePost()");
    boolean isValid = false;
    setInvalidParameter(VtnServiceJsonConsts.FLOWFILTERENTRY);
    if (requestBody.has(VtnServiceJsonConsts.FLOWFILTERENTRY)
            && requestBody.get(VtnServiceJsonConsts.FLOWFILTERENTRY).isJsonObject()) {
        final JsonObject ffEntry = requestBody.getAsJsonObject(VtnServiceJsonConsts.FLOWFILTERENTRY);
        // validation for key: seqnum(mandatory)
        setInvalidParameter(VtnServiceJsonConsts.SEQNUM);
        if (ffEntry.has(VtnServiceJsonConsts.SEQNUM)
                && ffEntry.getAsJsonPrimitive(VtnServiceJsonConsts.SEQNUM).getAsString() != null) {
            isValid = validator.isValidRange(
                    ffEntry.getAsJsonPrimitive(VtnServiceJsonConsts.SEQNUM).getAsString(),
                    VtnServiceJsonConsts.VAL_1, VtnServiceJsonConsts.VAL_65535);
        }
        if (isValid) {
            isValid = validator.isValidFlowFilterEntry(requestBody);
        }
        if (isValid) {
            // validation for redirectdst
            isValid = validator.isValidRedirectDst(isValid, ffEntry);
        }
    }
    LOG.trace("Complete VBridgeFlowFilterEntriesResourceValidator#validatePost()");
    return isValid;
}

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

License:Open Source License

/**
 * validate get request Json object for VbridgeFlowFilterEntry,
 * VbridgeInetrfaceFlowFilterEntry and VrouterInterfaceFlowFilterEntry API.
 * /*from   ww  w .  j a  v a 2s.c  o m*/
 * @param requestBody
 *            the request Json object
 * @return true, if successful
 */
private boolean validateGet(final JsonObject requestBody) {
    LOG.trace("Start VBridgeFlowFilterEntryResourceValidator#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);
    // }

    // validation for key: targetdb(optional)
    // if (isValid) {
    setInvalidParameter(VtnServiceJsonConsts.TARGETDB);
    isValid = validator.isValidRequestDB(requestBody);
    // }

    // validation for key: op(optinal)
    if (isValid) {
        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.DETAIL);
        } else {
            requestBody.remove(VtnServiceJsonConsts.OP);
            requestBody.addProperty(VtnServiceJsonConsts.OP, VtnServiceJsonConsts.NORMAL);
        }
    }

    LOG.trace("Complete VBridgeFlowFilterEntryResourceValidator#validateGet()");
    return isValid;
}

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

License:Open Source License

/**
 * Checks if is valid get request./*w w w  .  java  2  s  . c  o m*/
 * 
 * @param requestBody
 *            the request Json object
 * @return true, if is valid get
 */
public final boolean validateGet(final JsonObject requestBody) {
    LOG.trace("Start VBridgePolicingMapResourceValidator#validateGet()");
    boolean isValid = true;
    setInvalidParameter(VtnServiceJsonConsts.TARGETDB);
    isValid = validator.isValidRequestDB(requestBody);
    if (isValid) {
        setInvalidParameter(VtnServiceJsonConsts.OP);
        if (requestBody.has(VtnServiceJsonConsts.OP)
                && requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.OP).getAsString() != null
                && !requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.OP).getAsString().isEmpty()) {
            final String operation = requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.OP).getAsString();
            isValid = operation.equalsIgnoreCase(VtnServiceJsonConsts.DETAIL);
        } else {
            requestBody.remove(VtnServiceJsonConsts.OP);
            requestBody.addProperty(VtnServiceJsonConsts.OP, VtnServiceJsonConsts.NORMAL);
        }
    }
    LOG.trace("Complete VBridgePolicingMapResourceValidator#validateGet()");
    return isValid;
}

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

License:Open Source License

/**
 * validate put request JSON object for VBridgeInterfacePolicingMapResource
 * API.//from   w  w  w.j a  va  2 s  .com
 * 
 * @param requestBody
 *            the request JSON object
 * @return true, if successful
 */
private boolean validatePut(final JsonObject requestBody) {
    LOG.trace("Start VBridgeInterfacePolicingMapResourceValidator#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 VBridgeInterfacePolicingMapResourceValidator#validatePut()");
    return isValid;
}

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

License:Open Source License

/**
 * Checks if is valid get request./*from ww  w  .j  av a  2  s  .co  m*/
 * 
 * @param requestBody
 *            the request Json object
 * @return true, if is valid get
 */
public final boolean validateGet(final JsonObject requestBody) {
    LOG.trace("Start VBridgePolicingMapResourceValidator#validateGet()");
    boolean isValid = true;
    setInvalidParameter(VtnServiceJsonConsts.TARGETDB);
    isValid = validator.isValidRequestDB(requestBody);
    if (isValid) {
        setInvalidParameter(VtnServiceJsonConsts.OP);
        // isValid = validator.isValidOperation(requestBody);
        if (requestBody.has(VtnServiceJsonConsts.OP)
                && requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.OP).getAsString() != null
                && !requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.OP).getAsString().isEmpty()) {
            final String operation = requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.OP).getAsString();
            isValid = operation.equalsIgnoreCase(VtnServiceJsonConsts.DETAIL);
        } else {
            requestBody.remove(VtnServiceJsonConsts.OP);
            requestBody.addProperty(VtnServiceJsonConsts.OP, VtnServiceJsonConsts.NORMAL);
        }
    }
    LOG.trace("Complete VBridgePolicingMapResourceValidator#validateGet()");
    return isValid;
}

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

License:Open Source License

/**
 * Validate put request Json object for VBridgePolicingMap API.
 * /*  ww w. j av  a2 s . c o m*/
 * @param requestBody
 *            the request Json object
 * @return true, if successful
 */
private boolean validatePut(final JsonObject requestBody) {
    LOG.trace("Start VBridgePolicingMapResourceValidator#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 VBridgePolicingMapResourceValidator#validatePut()");
    return isValid;
}

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

License:Open Source License

/**
 * Validate post request Json object for VBridgePortMaps API
 * /*  w w  w .ja  va  2s.  c om*/
 * @param requestBody
 *            the request Json object
 * @return true, if successful
 */
private boolean validatePost(final JsonObject requestBody) {
    LOG.trace("Start VBridgePortMapResourceValidator#validatePost()");

    boolean isValid = false;
    setInvalidParameter(VtnServiceJsonConsts.PORTMAP);
    if (requestBody.has(VtnServiceJsonConsts.PORTMAP)
            && requestBody.get(VtnServiceJsonConsts.PORTMAP).isJsonObject()) {

        final JsonObject portMap = requestBody.getAsJsonObject(VtnServiceJsonConsts.PORTMAP);

        setInvalidParameter(VtnServiceJsonConsts.PORTMAP_NAME);
        // validation for mandatory key: portmap_name
        if (portMap.has(VtnServiceJsonConsts.PORTMAP_NAME)
                && portMap.get(VtnServiceJsonConsts.PORTMAP_NAME).isJsonPrimitive()
                && !portMap.getAsJsonPrimitive(VtnServiceJsonConsts.PORTMAP_NAME).getAsString().isEmpty()) {
            isValid = validator.isValidMaxLengthAlphaNum(
                    portMap.getAsJsonPrimitive(VtnServiceJsonConsts.PORTMAP_NAME).getAsString(),
                    VtnServiceJsonConsts.LEN_31);
        }

        // validation for mandatory key: controller_id
        if (isValid) {
            setInvalidParameter(VtnServiceJsonConsts.CONTROLLERID);
            if (portMap.has(VtnServiceJsonConsts.CONTROLLERID)
                    && portMap.get(VtnServiceJsonConsts.CONTROLLERID).isJsonPrimitive()
                    && !portMap.getAsJsonPrimitive(VtnServiceJsonConsts.CONTROLLERID).getAsString().isEmpty()) {
                isValid = validator.isValidMaxLengthAlphaNum(
                        portMap.getAsJsonPrimitive(VtnServiceJsonConsts.CONTROLLERID).getAsString(),
                        VtnServiceJsonConsts.LEN_31);
            } else {
                isValid = false;
            }
        }

        // validation for mandatory key: domain_id
        if (isValid) {
            setInvalidParameter(VtnServiceJsonConsts.DOMAINID);
            if (portMap.has(VtnServiceJsonConsts.DOMAINID)
                    && portMap.get(VtnServiceJsonConsts.DOMAINID).isJsonPrimitive()
                    && !portMap.getAsJsonPrimitive(VtnServiceJsonConsts.DOMAINID).getAsString().isEmpty()) {
                isValid = validator.isValidDomainId(
                        portMap.getAsJsonPrimitive(VtnServiceJsonConsts.DOMAINID).getAsString(),
                        VtnServiceJsonConsts.LEN_31);
            } else {
                isValid = false;
            }
        }

        if (isValid) {
            isValid = paramIsSpecifiedTogether(portMap);
        }
    }

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

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

License:Open Source License

/**
 *  Is logical_port_id, label_type and label specified together and have same valid flag
 * /*from   www. j a  v a2s  .c  o m*/
 * @param boolean
 *            the validate result
 * @param JsonObject
 *            the request Json object
 * @return true, if successful
 */
private boolean paramIsSpecifiedTogether(JsonObject portMap) {
    LOG.trace("Start VBridgePortMapResourceValidator#paramIsSpecifiedTogether()");
    boolean isValid = false;
    setInvalidParameter(VtnServiceJsonConsts.LOGICAL_PORT_ID + VtnServiceJsonConsts.SLASH
            + VtnServiceJsonConsts.LABEL_TYPE + VtnServiceJsonConsts.SLASH + VtnServiceJsonConsts.LABEL);
    if (!portMap.has(VtnServiceJsonConsts.LOGICAL_PORT_ID) && !portMap.has(VtnServiceJsonConsts.LABEL_TYPE)
            && !portMap.has(VtnServiceJsonConsts.LABEL)) {

        isValid = true;
    } else if (portMap.has(VtnServiceJsonConsts.LOGICAL_PORT_ID)
            && portMap.get(VtnServiceJsonConsts.LOGICAL_PORT_ID).isJsonPrimitive()
            && portMap.has(VtnServiceJsonConsts.LABEL_TYPE)
            && portMap.get(VtnServiceJsonConsts.LABEL_TYPE).isJsonPrimitive()
            && portMap.has(VtnServiceJsonConsts.LABEL)
            && portMap.get(VtnServiceJsonConsts.LABEL).isJsonPrimitive()) {

        if (portMap.getAsJsonPrimitive(VtnServiceJsonConsts.LOGICAL_PORT_ID).getAsString().isEmpty()
                && portMap.getAsJsonPrimitive(VtnServiceJsonConsts.LABEL_TYPE).getAsString().isEmpty()
                && portMap.getAsJsonPrimitive(VtnServiceJsonConsts.LABEL).getAsString().isEmpty()) {
            isValid = true;
        } else if (!portMap.getAsJsonPrimitive(VtnServiceJsonConsts.LOGICAL_PORT_ID).getAsString().isEmpty()
                && !portMap.getAsJsonPrimitive(VtnServiceJsonConsts.LABEL_TYPE).getAsString().isEmpty()
                && !portMap.getAsJsonPrimitive(VtnServiceJsonConsts.LABEL).getAsString().isEmpty()) {
            isValid = validateParameter(portMap);
        }
    }

    LOG.trace("Complete VBridgePortMapResourceValidator#paramIsSpecifiedTogether()");
    return isValid;
}