Example usage for com.google.gson JsonObject remove

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

Introduction

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

Prototype

public JsonElement remove(String property) 

Source Link

Document

Removes the property from this JsonObject .

Usage

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

License:Open Source License

/**
 * Checks if is valid get request./*w  w  w.ja  v a2 s.c  om*/
 * 
 * @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.VBridgePolicingMapResourceValidator.java

License:Open Source License

/**
 * Checks if is valid get request.//w  w w.j  a v a  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);
        // 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.VLanMapResourceValidator.java

License:Open Source License

/**
 * Validate get request Json object for VLanMap API
 * //from w  w 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, final boolean opFlag) {

    LOG.trace("Start VLanMapValiadtor#isValidGet");
    boolean isValid = true;
    // validation for key: targetdb
    if (isValid) {
        setInvalidParameter(VtnServiceJsonConsts.TARGETDB);
        isValid = validator.isValidRequestDB(requestBody);
    }
    if (!opFlag) {
        if (requestBody.has(VtnServiceJsonConsts.OP)) {
            requestBody.remove(VtnServiceJsonConsts.OP);
        } else {
            LOG.debug("No need to remove -op ");
        }
        if (requestBody.has(VtnServiceJsonConsts.INDEX)) {
            requestBody.remove(VtnServiceJsonConsts.INDEX);
        } else {
            LOG.debug("No need to remove - index");
        }
        if (requestBody.has(VtnServiceJsonConsts.MAX)) {
            requestBody.remove(VtnServiceJsonConsts.MAX);
        } else {
            LOG.debug("No need to remove-max count");
        }
    } else {
        // validation for key: op
        if (isValid) {
            setInvalidParameter(VtnServiceJsonConsts.OP);
            isValid = validator.isValidOperation(requestBody);
        }
        // validation for key: index
        if (isValid) {
            setInvalidParameter(VtnServiceJsonConsts.INDEX);
            if (requestBody.has(VtnServiceJsonConsts.INDEX)
                    && requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.INDEX).getAsString() != null) {

                final String vlamMapId = requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.INDEX)
                        .getAsString();
                isValid = isValidVLanMapId(vlamMapId);
            }
        }
        // validation for key: max_repitition
        if (isValid) {
            setInvalidParameter(VtnServiceJsonConsts.MAX);
            isValid = validator.isValidMaxRepetition(requestBody);
        }
    }
    LOG.trace("Complete VLanMapValidator#isValidGet");
    return isValid;
}

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

License:Open Source License

/**
 * @param requestBody/*from w  w  w  .  j  a  v  a  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 GET request JSON object for VTN PolcingMap API.
 * //from w ww  .  j  ava  2 s  . 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.VtnStationsResourceValidator.java

License:Open Source License

/**
 * Validate get request Json object for VtnStations API.
 * //from w  ww .  j a  v  a 2  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.physical.BoundaryResourceValidator.java

License:Open Source License

/**
 * Validate request json for get method of Boundary API
 * //ww  w  .j  a v a  2s. c o  m
 * @param requestBody
 *            the request Json object
 * @return true, if successful
 * @throws VtnServiceException
 */
private boolean isValidateGet(final JsonObject requestBody, final boolean opFlag) {
    LOG.trace("Start BoundaryResourceValidator#isValidateGet()");
    boolean isValid = true;
    if (isValid) {
        // validation for key: targetdb
        setInvalidParameter(VtnServiceJsonConsts.TARGETDB);
        isValid = validator.isValidRequestDB(requestBody);
    }
    if (!opFlag) {
        if (requestBody.has(VtnServiceJsonConsts.OP)) {
            requestBody.remove(VtnServiceJsonConsts.OP);
        } else {
            LOG.debug("No need to remove -op ");
        }
        if (requestBody.has(VtnServiceJsonConsts.INDEX)) {
            requestBody.remove(VtnServiceJsonConsts.INDEX);
        } else {
            LOG.debug("No need to remove - index");
        }
        if (requestBody.has(VtnServiceJsonConsts.MAX)) {
            requestBody.remove(VtnServiceJsonConsts.MAX);
        } else {
            LOG.debug("No need to remove-max count");
        }
    } else {
        // validation for key: op
        if (isValid) {
            setInvalidParameter(VtnServiceJsonConsts.OP);
            isValid = validator.isValidOperation(requestBody);
        }
        // validation for key: index
        if (isValid) {
            setInvalidParameter(VtnServiceJsonConsts.INDEX);
            if (requestBody.has(VtnServiceJsonConsts.INDEX)
                    && requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.INDEX).getAsString() != null
                    && !requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.INDEX).getAsString().isEmpty()) {
                isValid = validator.isValidMaxLengthAlphaNum(
                        requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.INDEX).getAsString(),
                        VtnServiceJsonConsts.LEN_31);
            }
        }
        // validation for key: max_repitition
        if (isValid) {
            setInvalidParameter(VtnServiceJsonConsts.MAX);
            isValid = validator.isValidMaxRepetition(requestBody);
        }
        // validation for key: controller1_id
        if (isValid) {
            setInvalidParameter(VtnServiceJsonConsts.CONTROLLER1ID);
            if (requestBody.has(VtnServiceJsonConsts.CONTROLLER1ID)
                    && requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.CONTROLLER1ID).getAsString() != null
                    && !requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.CONTROLLER1ID).getAsString()
                            .isEmpty()) {
                isValid = validator.isValidMaxLengthAlphaNum(
                        requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.CONTROLLER1ID).getAsString(),
                        VtnServiceJsonConsts.LEN_31);
            }
        }
        // validation for key: controller2_id
        if (isValid) {
            setInvalidParameter(VtnServiceJsonConsts.CONTROLLER2ID);
            if (requestBody.has(VtnServiceJsonConsts.CONTROLLER2ID)
                    && requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.CONTROLLER2ID).getAsString() != null
                    && !requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.CONTROLLER2ID).getAsString()
                            .isEmpty()) {
                isValid = validator.isValidMaxLengthAlphaNum(
                        requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.CONTROLLER2ID).getAsString(),
                        VtnServiceJsonConsts.LEN_31);
            }
        }
    }
    LOG.trace("Complete BoundaryResourceValidator#isValidateGet");
    return isValid;
}

From source file:org.opendaylight.vtn.javaapi.validation.physical.BoundaryResourceValidator.java

License:Open Source License

/**
 * Validate put request json for update Boundary API
 * //from  ww w.  j ava  2s  .c  o  m
 * @param requestBody
 *            the request Json object
 * 
 * @return true, if successful
 */
private boolean validatePut(final JsonObject requestBody) {
    LOG.trace("Start BoundaryResourceValidator#validatePut()");
    boolean isValid = true;
    setInvalidParameter(VtnServiceJsonConsts.BOUNDARY);
    if (requestBody.has(VtnServiceJsonConsts.BOUNDARY)
            && requestBody.get(VtnServiceJsonConsts.BOUNDARY).isJsonObject()) {
        final JsonObject boundary = requestBody.getAsJsonObject(VtnServiceJsonConsts.BOUNDARY);
        // validation for key: description(optional)
        setInvalidParameter(VtnServiceJsonConsts.DESCRIPTION);
        if (boundary.has(VtnServiceJsonConsts.DESCRIPTION)
                && boundary.getAsJsonPrimitive(VtnServiceJsonConsts.DESCRIPTION).getAsString() != null
                && !boundary.getAsJsonPrimitive(VtnServiceJsonConsts.DESCRIPTION).getAsString().isEmpty()) {
            isValid = validator.isValidMaxLength(
                    boundary.getAsJsonPrimitive(VtnServiceJsonConsts.DESCRIPTION).getAsString(),
                    VtnServiceJsonConsts.LEN_127);
        }
        if (isValid && boundary.has(VtnServiceJsonConsts.LINK)) {
            boundary.remove(VtnServiceJsonConsts.LINK);
        }
    } else {
        isValid = false;
    }
    LOG.trace("Complete BoundaryResourceValidator#validatePut()");
    return isValid;
}

From source file:org.opendaylight.vtn.javaapi.validation.physical.ControllerResourceValidator.java

License:Open Source License

/**
 * Validate request json for get method of controller API
 * /*  w  ww .  ja  v a2  s. c o  m*/
 * @param requestBody
 *            the request Json object
 * 
 * @return true, if is valid get
 */
public final boolean validateGet(final JsonObject requestBody, final boolean opFlag) {
    LOG.trace("Start ControllerResourceValidator#isValidGet");
    boolean isValid = true;
    // validation for key: targetdb
    if (isValid) {
        setInvalidParameter(VtnServiceJsonConsts.TARGETDB);
        isValid = validator.isValidRequestDB(requestBody);
    }
    if (!opFlag) {
        if (requestBody.has(VtnServiceJsonConsts.OP)) {
            requestBody.remove(VtnServiceJsonConsts.OP);
        } else {
            LOG.debug("No need to remove");
        }
        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_31);
            }
        }
        // validation for key: max_repitition
        // updated validation for max_repetition_count
        if (isValid) {
            setInvalidParameter(VtnServiceJsonConsts.MAX);
            isValid = validator.isValidMaxRepetition(requestBody);
            return isValid;
        }
    }
    LOG.trace("Complete ControllerResourceValidator#isValidGet");
    return isValid;
}

From source file:org.opendaylight.vtn.javaapi.validation.physical.DomainLogicalPortResourceValidator.java

License:Open Source License

/**
 * Validate get request json for Logical Port API
 * //from w w  w .j  ava  2s . c  o  m
 * @param requestBody
 *            the request Json object
 * @return true, if successful
 */
private boolean validateGet(final JsonObject requestBody, final boolean opFlag) {
    LOG.trace("Start DomainLogicalPortResourceValidator#validateGet()");
    boolean isValid = true;
    // validation for key: targetdb
    setInvalidParameter(VtnServiceJsonConsts.TARGETDB);
    if (requestBody.has(VtnServiceJsonConsts.TARGETDB)
            && requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.TARGETDB).getAsString() != null
            && !requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.TARGETDB).getAsString().isEmpty()) {
        isValid = requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.TARGETDB).getAsString()
                .equalsIgnoreCase(VtnServiceJsonConsts.STATE);
    } else {
        requestBody.remove(VtnServiceJsonConsts.TARGETDB);
        requestBody.addProperty(VtnServiceJsonConsts.TARGETDB, VtnServiceJsonConsts.STATE);
    }
    if (!opFlag) {
        if (requestBody.has(VtnServiceJsonConsts.OP)) {
            requestBody.remove(VtnServiceJsonConsts.OP);
        } else {
            LOG.debug("No need to remove -op ");
        }
        if (requestBody.has(VtnServiceJsonConsts.INDEX)) {
            requestBody.remove(VtnServiceJsonConsts.INDEX);
        } else {
            LOG.debug("No need to remove - index");
        }
        if (requestBody.has(VtnServiceJsonConsts.MAX)) {
            requestBody.remove(VtnServiceJsonConsts.MAX);
        } else {
            LOG.debug("No need to remove-max count");
        }
    } else {
        // validation for key: op
        if (isValid) {
            setInvalidParameter(VtnServiceJsonConsts.OP);
            isValid = validator.isValidOperation(requestBody);
        }
        // validation for key: index
        if (isValid) {
            setInvalidParameter(VtnServiceJsonConsts.INDEX);
            if (requestBody.has(VtnServiceJsonConsts.INDEX)
                    && requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.INDEX).getAsString() != null
                    && !requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.INDEX).getAsString().isEmpty()) {
                isValid = validator.isValidMaxLength(
                        requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.INDEX).getAsString(),
                        VtnServiceJsonConsts.LEN_319);
            }
        }
        // validation for key: max_repitition
        if (isValid) {
            setInvalidParameter(VtnServiceJsonConsts.MAX);
            isValid = validator.isValidMaxRepetition(requestBody);
            /*
             * if (requestBody.has(VtnServiceJsonConsts.MAX) &&
             * requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.MAX)
             * .getAsString() != null) { isValid =
             * validator.isValidMaxLengthNumber(requestBody
             * .getAsJsonPrimitive(VtnServiceJsonConsts.MAX)
             * .getAsString()); }
             */
        }
    }
    if (isValid) {
        setInvalidParameter(VtnServiceJsonConsts.LOGICAL_PORT_ID);
        if (requestBody.has(VtnServiceJsonConsts.LOGICAL_PORT_ID)
                && requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.LOGICAL_PORT_ID).getAsString() != null
                && !requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.LOGICAL_PORT_ID).getAsString()
                        .isEmpty()) {
            isValid = validator.isValidMaxLength(
                    requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.LOGICAL_PORT_ID).getAsString(),
                    VtnServiceJsonConsts.LEN_319);
        }
    }
    LOG.trace("Complete DomainLogicalPortResourceValidator#isValidGet");
    return isValid;
}