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

License:Open Source License

/**
 * validate post meterAction Json object for PolicingProfilesEntries
 * /*from   www  .  j  a v a  2s.  c o m*/
 * @param requestBody
 *            the request Json object
 * @return true, if successful
 */
private boolean validateMeter(final JsonObject twoRateThreeColorJson) {
    LOG.trace("Start PolicingProfilesEntriesValidation#validatePost#validateMeter()");
    setInvalidParameter(VtnServiceJsonConsts.METER);
    boolean isValid = true;
    if (twoRateThreeColorJson.has(VtnServiceJsonConsts.METER)) {
        final JsonObject meterJson = twoRateThreeColorJson.getAsJsonObject(VtnServiceJsonConsts.METER);

        // validation for rateunit (optional)
        setInvalidParameter(VtnServiceJsonConsts.RATEUNIT);
        if (meterJson.has(VtnServiceJsonConsts.RATEUNIT)
                && meterJson.getAsJsonPrimitive(VtnServiceJsonConsts.RATEUNIT).getAsString() != null) {
            String rate = meterJson.getAsJsonPrimitive(VtnServiceJsonConsts.RATEUNIT).getAsString();
            isValid = rate.equalsIgnoreCase(VtnServiceJsonConsts.KBPS)
                    || rate.equalsIgnoreCase(VtnServiceJsonConsts.PPS);
        }
        // validation for cbs (optional)
        if (isValid) {
            setInvalidParameter(VtnServiceJsonConsts.CBS);
            if (meterJson.has(VtnServiceJsonConsts.CBS)
                    && meterJson.getAsJsonPrimitive(VtnServiceJsonConsts.CBS).getAsString() != null) {
                isValid = validator.isValidBigIntegerRangeString(
                        new BigInteger(meterJson.getAsJsonPrimitive(VtnServiceJsonConsts.CBS).getAsString()),
                        VtnServiceJsonConsts.BIG_VAL0, VtnServiceJsonConsts.BIG_VAL_4294967295);

            }
        }
        // validation for pir (optional)
        if (isValid) {
            setInvalidParameter(VtnServiceJsonConsts.PIR);
            if (meterJson.has(VtnServiceJsonConsts.PIR)
                    && meterJson.getAsJsonPrimitive(VtnServiceJsonConsts.PIR).getAsString() != null) {
                isValid = validator.isValidBigIntegerRangeString(
                        new BigInteger(meterJson.getAsJsonPrimitive(VtnServiceJsonConsts.PIR).getAsString()),
                        VtnServiceJsonConsts.BIG_VAL0, VtnServiceJsonConsts.BIG_VAL_4294967295);

            }
        }
        // validation for pbs (optional)
        if (isValid) {
            setInvalidParameter(VtnServiceJsonConsts.PBS);
            if (meterJson.has(VtnServiceJsonConsts.PBS)
                    && meterJson.getAsJsonPrimitive(VtnServiceJsonConsts.PBS).getAsString() != null) {
                isValid = validator.isValidBigIntegerRangeString(
                        new BigInteger(meterJson.getAsJsonPrimitive(VtnServiceJsonConsts.PBS).getAsString()),
                        VtnServiceJsonConsts.BIG_VAL0, VtnServiceJsonConsts.BIG_VAL_4294967295);

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

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

License:Open Source License

/**
 * /* validate put request JSON object for PolicingProfilesEntries
 * //from   w  w  w. j a  v  a2 s  . co m
 * @param requestBody
 *            the request JSON object
 * @return true, if successful
 */
private boolean validatePut(JsonObject requestBody) {
    LOG.trace("Start PolicingProfilesEntriesResourceValidator#validatePut()");
    boolean isValid = false;
    setInvalidParameter(VtnServiceJsonConsts.POLICINGPROFILEENTRY);
    if (requestBody.has(VtnServiceJsonConsts.POLICINGPROFILEENTRY)
            && requestBody.get(VtnServiceJsonConsts.POLICINGPROFILEENTRY).isJsonObject()) {
        final JsonObject profileEntryJson = requestBody
                .getAsJsonObject(VtnServiceJsonConsts.POLICINGPROFILEENTRY);
        // validation for key: fl_name
        setInvalidParameter(VtnServiceJsonConsts.FLNAME);
        if (profileEntryJson.has(VtnServiceJsonConsts.FLNAME)
                && profileEntryJson.getAsJsonPrimitive(VtnServiceJsonConsts.FLNAME).getAsString() != null
                && !profileEntryJson.get(VtnServiceJsonConsts.FLNAME).getAsString().isEmpty()) {
            isValid = validator.isValidMaxLengthAlphaNum(
                    profileEntryJson.getAsJsonPrimitive(VtnServiceJsonConsts.FLNAME).getAsString(),
                    VtnServiceJsonConsts.LEN_32);
        }
        // validation for tworatethreecolor (optional)
        if (isValid) {
            setInvalidParameter(VtnServiceJsonConsts.TWORATETHREECOLOR);
            if (profileEntryJson.has(VtnServiceJsonConsts.TWORATETHREECOLOR)) {
                final JsonObject twoRateThreeColorJson = profileEntryJson
                        .getAsJsonObject(VtnServiceJsonConsts.TWORATETHREECOLOR);
                // validation for meter (optional)
                if (isValid) {
                    isValid = validateMeter(twoRateThreeColorJson);
                }
                // validation for green-action (optional)
                if (isValid) {
                    setInvalidParameter(VtnServiceJsonConsts.GREENACTION);
                    if (twoRateThreeColorJson.has(VtnServiceJsonConsts.GREENACTION)) {
                        isValid = validateActionJson(
                                twoRateThreeColorJson.get(VtnServiceJsonConsts.GREENACTION).getAsJsonObject());
                    } else {
                        isValid = false;
                    }
                }
                // validation for yellow-action (optional)
                if (isValid) {
                    setInvalidParameter(VtnServiceJsonConsts.YELLOWACTION);
                    if (twoRateThreeColorJson.has(VtnServiceJsonConsts.YELLOWACTION)) {
                        isValid = validateActionJson(
                                twoRateThreeColorJson.get(VtnServiceJsonConsts.YELLOWACTION).getAsJsonObject());
                    } else {
                        isValid = false;
                    }
                }
                // validation for redaction (optional)
                if (isValid) {
                    setInvalidParameter(VtnServiceJsonConsts.REDACTION);
                    if (twoRateThreeColorJson.has(VtnServiceJsonConsts.REDACTION)) {
                        isValid = validateActionJson(
                                twoRateThreeColorJson.get(VtnServiceJsonConsts.REDACTION).getAsJsonObject());
                    } else {
                        isValid = false;
                    }
                }
            }
        }
    }
    LOG.trace("Complete PolicingProfilesEntriesResourceValidator#validatePut()");
    return isValid;
}

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

License:Open Source License

/**
 * /* validate post request JSON object for PolicingProfilesEntries
 * /*from w w  w. ja 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 PolicingProfilesEntriesResourceValidator#validatePost()");
    boolean isValid = false;
    setInvalidParameter(VtnServiceJsonConsts.POLICINGPROFILEENTRY);
    if (requestBody.has(VtnServiceJsonConsts.POLICINGPROFILEENTRY)
            && requestBody.get(VtnServiceJsonConsts.POLICINGPROFILEENTRY).isJsonObject()) {
        final JsonObject profileEntryJson = requestBody
                .getAsJsonObject(VtnServiceJsonConsts.POLICINGPROFILEENTRY);

        // validation for key: seqnum (mandatory)
        setInvalidParameter(VtnServiceJsonConsts.SEQNUM);
        if (profileEntryJson.has(VtnServiceJsonConsts.SEQNUM)
                && profileEntryJson.getAsJsonPrimitive(VtnServiceJsonConsts.SEQNUM).getAsString() != null) {
            isValid = validator.isValidRange(
                    profileEntryJson.getAsJsonPrimitive(VtnServiceJsonConsts.SEQNUM).getAsString(),
                    VtnServiceJsonConsts.VAL_1, VtnServiceJsonConsts.VAL_255);
        }
        if (isValid) {
            isValid = validatePut(requestBody);
        }
    }
    LOG.trace("Complete PolicingProfilesEntriesResourceValidator#validatePost()");
    return isValid;
}

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

License:Open Source License

/**
 * /* validate post greenAction JSON object for PolicingProfilesEntries
 * /*from   ww  w. ja  v  a  2  s .co  m*/
 * @param requestBody
 *            the request JSON object
 * @return true, if successful
 */
private boolean validateActionJson(final JsonObject actionJson) {
    LOG.trace("Start PolicingProfilesEntriesResourceValidator#validatePost#validateActionJson()");
    boolean isValid = true;
    // validation for green_action (optional)
    setInvalidParameter(VtnServiceJsonConsts.TYPE);
    if (actionJson.has(VtnServiceJsonConsts.TYPE)
            && actionJson.getAsJsonPrimitive(VtnServiceJsonConsts.TYPE).getAsString() != null) {
        String rate = actionJson.getAsJsonPrimitive(VtnServiceJsonConsts.TYPE).getAsString();
        isValid = rate.equalsIgnoreCase(VtnServiceJsonConsts.PASS)
                || rate.equalsIgnoreCase(VtnServiceJsonConsts.DROP)
                || rate.equalsIgnoreCase(VtnServiceJsonConsts.PENALTY);

    }
    // validation for ga_priority (optional)
    if (isValid) {
        setInvalidParameter(VtnServiceJsonConsts.PRIORITY);
        if (actionJson.has(VtnServiceJsonConsts.PRIORITY)
                && actionJson.getAsJsonPrimitive(VtnServiceJsonConsts.PRIORITY).getAsString() != null) {
            isValid = validator.isValidRange(
                    actionJson.getAsJsonPrimitive(VtnServiceJsonConsts.PRIORITY).getAsString(),
                    VtnServiceJsonConsts.VAL_0, VtnServiceJsonConsts.VAL_7);

        }
    }
    // validation for ga_dscp (optional)
    if (isValid) {
        setInvalidParameter(VtnServiceJsonConsts.DSCP);
        if (actionJson.has(VtnServiceJsonConsts.DSCP)
                && actionJson.getAsJsonPrimitive(VtnServiceJsonConsts.DSCP).getAsString() != null) {
            isValid = validator.isValidRange(
                    actionJson.getAsJsonPrimitive(VtnServiceJsonConsts.DSCP).getAsString(),
                    VtnServiceJsonConsts.VAL_0, VtnServiceJsonConsts.VAL_63);

        }
    }
    // validation for ga_drop_precedence (optional)
    if (isValid) {
        setInvalidParameter(VtnServiceJsonConsts.DROPPRECEDENCE);
        if (actionJson.has(VtnServiceJsonConsts.DROPPRECEDENCE)
                && actionJson.getAsJsonPrimitive(VtnServiceJsonConsts.DROPPRECEDENCE).getAsString() != null) {
            isValid = validator.isValidRange(
                    actionJson.getAsJsonPrimitive(VtnServiceJsonConsts.DROPPRECEDENCE).getAsString(),
                    VtnServiceJsonConsts.VAL_1, VtnServiceJsonConsts.VAL_3);

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

}

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

License:Open Source License

/**
 * validate post meterAction JSON object for PolicingProfilesEntries
 * /*from   w  w w . j  av a  2s .  c o m*/
 * @param requestBody
 *            the request JSON object
 * @return true, if successful
 */
private boolean validateMeter(final JsonObject twoRateThreeColorJson) {
    LOG.trace("Start PolicingProfilesEntriesResourceValidator#validatePost#validateMeter()");
    setInvalidParameter(VtnServiceJsonConsts.METER);
    boolean isValid = false;
    if (twoRateThreeColorJson.has(VtnServiceJsonConsts.METER)) {
        isValid = true;
        final JsonObject meterJson = twoRateThreeColorJson.getAsJsonObject(VtnServiceJsonConsts.METER);

        // validation for rateunit (optional)
        setInvalidParameter(VtnServiceJsonConsts.UNIT);
        if (meterJson.has(VtnServiceJsonConsts.UNIT)
                && meterJson.getAsJsonPrimitive(VtnServiceJsonConsts.UNIT).getAsString() != null) {
            String rate = meterJson.getAsJsonPrimitive(VtnServiceJsonConsts.UNIT).getAsString();
            isValid = rate.equalsIgnoreCase(VtnServiceJsonConsts.KBPS)
                    || rate.equalsIgnoreCase(VtnServiceJsonConsts.PPS);
        }
        // validation for cir (optional)
        if (isValid) {
            setInvalidParameter(VtnServiceJsonConsts.CIR);
            if (meterJson.has(VtnServiceJsonConsts.CIR)
                    && meterJson.getAsJsonPrimitive(VtnServiceJsonConsts.CIR).getAsString() != null) {
                isValid = validator.isValidBigIntegerRangeString(
                        new BigInteger(meterJson.getAsJsonPrimitive(VtnServiceJsonConsts.CIR).getAsString()),
                        VtnServiceJsonConsts.BIG_VAL0, VtnServiceJsonConsts.BIG_VAL_4294967295);

            }
        }
        // validation for cbs (optional)
        if (isValid) {
            setInvalidParameter(VtnServiceJsonConsts.CBS);
            if (meterJson.has(VtnServiceJsonConsts.CBS)
                    && meterJson.getAsJsonPrimitive(VtnServiceJsonConsts.CBS).getAsString() != null) {
                isValid = validator.isValidBigIntegerRangeString(
                        new BigInteger(meterJson.getAsJsonPrimitive(VtnServiceJsonConsts.CBS).getAsString()),
                        VtnServiceJsonConsts.BIG_VAL0, VtnServiceJsonConsts.BIG_VAL_4294967295);

            }
        }
        // validation for pir (optional)
        if (isValid) {
            setInvalidParameter(VtnServiceJsonConsts.PIR);
            if (meterJson.has(VtnServiceJsonConsts.PIR)
                    && meterJson.getAsJsonPrimitive(VtnServiceJsonConsts.PIR).getAsString() != null) {
                isValid = validator.isValidBigIntegerRangeString(
                        new BigInteger(meterJson.getAsJsonPrimitive(VtnServiceJsonConsts.PIR).getAsString()),
                        VtnServiceJsonConsts.BIG_VAL0, VtnServiceJsonConsts.BIG_VAL_4294967295);

            }
        }
        // validation for pbs (optional)
        if (isValid) {
            setInvalidParameter(VtnServiceJsonConsts.PBS);
            if (meterJson.has(VtnServiceJsonConsts.PBS)
                    && meterJson.getAsJsonPrimitive(VtnServiceJsonConsts.PBS).getAsString() != null) {
                isValid = validator.isValidBigIntegerRangeString(
                        new BigInteger(meterJson.getAsJsonPrimitive(VtnServiceJsonConsts.PBS).getAsString()),
                        VtnServiceJsonConsts.BIG_VAL0, VtnServiceJsonConsts.BIG_VAL_4294967295);

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

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

License:Open Source License

/**
 * validate put request Json object for PortMap API.
 * //from ww w  .ja 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 PortMapResourceValidator#validatePut()");
    boolean isValid = false;
    setInvalidParameter(VtnServiceJsonConsts.PORTMAP);
    if (requestBody.has(VtnServiceJsonConsts.PORTMAP)
            && requestBody.get(VtnServiceJsonConsts.PORTMAP).isJsonObject()) {
        final JsonObject portMap = requestBody.getAsJsonObject(VtnServiceJsonConsts.PORTMAP);
        // validation for key: switch_id(mandatory)
        setInvalidParameter(VtnServiceJsonConsts.LOGICAL_PORT_ID);
        if (portMap.has(VtnServiceJsonConsts.LOGICAL_PORT_ID)
                && portMap.getAsJsonPrimitive(VtnServiceJsonConsts.LOGICAL_PORT_ID).getAsString() != null
                && !portMap.getAsJsonPrimitive(VtnServiceJsonConsts.LOGICAL_PORT_ID).getAsString().isEmpty()) {
            isValid = validator.isValidMaxLength(
                    portMap.getAsJsonPrimitive(VtnServiceJsonConsts.LOGICAL_PORT_ID).getAsString(),
                    VtnServiceJsonConsts.LEN_319);
        }
        if (isValid) {
            // validation for key: vlan_id
            setInvalidParameter(VtnServiceJsonConsts.VLANID);
            if (portMap.has(VtnServiceJsonConsts.VLANID)
                    && portMap.getAsJsonPrimitive(VtnServiceJsonConsts.VLANID).getAsString() != null) {
                isValid = validator.isValidRange(
                        portMap.getAsJsonPrimitive(VtnServiceJsonConsts.VLANID).getAsString(),
                        VtnServiceJsonConsts.VAL_1, VtnServiceJsonConsts.VAL_4095);
            }
        }
        // validation for key:tagged(optional)
        if (isValid) {
            setInvalidParameter(VtnServiceJsonConsts.TAGGED);
            if (portMap.has(VtnServiceJsonConsts.TAGGED)
                    && portMap.getAsJsonPrimitive(VtnServiceJsonConsts.TAGGED).getAsString() != null) {
                final String portMp = portMap.getAsJsonPrimitive(VtnServiceJsonConsts.TAGGED).getAsString();
                if (VtnServiceConsts.EMPTY_STRING.equals(portMp)) {
                    return true;
                }
                isValid = portMp.equalsIgnoreCase(VtnServiceJsonConsts.TRUE)
                        || portMp.equalsIgnoreCase(VtnServiceJsonConsts.FALSE);
            }
        }
    }
    LOG.trace("Complete PortMapResourceValidator#validatePut()");
    return isValid;
}

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

License:Open Source License

/**
 * validate post request Json object for Spine domain API.
 * //from  w ww. j av 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 SpineDomainResourceValidator#validatePost()");
    boolean isValid = false;
    setInvalidParameter(VtnServiceJsonConsts.SPINE_DOMAIN);
    if (requestBody.has(VtnServiceJsonConsts.SPINE_DOMAIN)
            && requestBody.get(VtnServiceJsonConsts.SPINE_DOMAIN).isJsonObject()) {
        final JsonObject spineDomainResourceEntry = requestBody
                .getAsJsonObject(VtnServiceJsonConsts.SPINE_DOMAIN);
        // validation for key: spine_domain_name(mandatory)
        setInvalidParameter(VtnServiceJsonConsts.SPINE_DOMAIN_NAME);
        if (spineDomainResourceEntry.has(VtnServiceJsonConsts.SPINE_DOMAIN_NAME)
                && spineDomainResourceEntry.get(VtnServiceJsonConsts.SPINE_DOMAIN_NAME).isJsonPrimitive()
                && !spineDomainResourceEntry.getAsJsonPrimitive(VtnServiceJsonConsts.SPINE_DOMAIN_NAME)
                        .getAsString().isEmpty()) {
            isValid = validator.isValidMaxLengthAlphaNum(spineDomainResourceEntry
                    .getAsJsonPrimitive(VtnServiceJsonConsts.SPINE_DOMAIN_NAME).getAsString(),
                    VtnServiceJsonConsts.LEN_31);
        }
        // validation for key: controller_id(mandatory)
        if (isValid) {
            setInvalidParameter(VtnServiceJsonConsts.CONTROLLERID);
            if (spineDomainResourceEntry.has(VtnServiceJsonConsts.CONTROLLERID)
                    && spineDomainResourceEntry.get(VtnServiceJsonConsts.CONTROLLERID).isJsonPrimitive()
                    && !spineDomainResourceEntry.getAsJsonPrimitive(VtnServiceJsonConsts.CONTROLLERID)
                            .getAsString().isEmpty()) {
                isValid = validator.isValidMaxLengthAlphaNum(spineDomainResourceEntry
                        .getAsJsonPrimitive(VtnServiceJsonConsts.CONTROLLERID).getAsString(),
                        VtnServiceJsonConsts.LEN_31);
            } else {
                isValid = false;
            }
        }
        // validation for key: domain_id(mandatory)
        if (isValid) {
            setInvalidParameter(VtnServiceJsonConsts.DOMAINID);
            if (spineDomainResourceEntry.has(VtnServiceJsonConsts.DOMAINID)
                    && spineDomainResourceEntry.get(VtnServiceJsonConsts.DOMAINID).isJsonPrimitive()
                    && !spineDomainResourceEntry.getAsJsonPrimitive(VtnServiceJsonConsts.DOMAINID).getAsString()
                            .isEmpty()) {
                isValid = validator.isValidDomainId(spineDomainResourceEntry
                        .getAsJsonPrimitive(VtnServiceJsonConsts.DOMAINID).getAsString(),
                        VtnServiceJsonConsts.LEN_31);
            } else {
                isValid = false;
            }
        }
        // validation for key: label_name(option)
        if (isValid) {
            if (spineDomainResourceEntry.has(VtnServiceJsonConsts.LABEL_NAME)) {
                setInvalidParameter(VtnServiceJsonConsts.LABEL_NAME);
                if (spineDomainResourceEntry.get(VtnServiceJsonConsts.LABEL_NAME).isJsonPrimitive()) {
                    isValid = validator.isValidMaxLengthAlphaNum(spineDomainResourceEntry
                            .getAsJsonPrimitive(VtnServiceJsonConsts.LABEL_NAME).getAsString(),
                            VtnServiceJsonConsts.LEN_31);
                } else {
                    isValid = false;
                }
            }
        }
    } else {
        isValid = false;
    }
    LOG.trace("Complete SpineDomainResourceValidator#validatePost()");
    return isValid;
}

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

License:Open Source License

/**
 * validate put request Json object for Spine domain API.
 * /*from  w ww .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 validatePut(final JsonObject requestBody) throws VtnServiceException {
    LOG.trace("Start SpineDomainResourceValidator#validatePut()");
    boolean isValid = false;
    setInvalidParameter(VtnServiceJsonConsts.SPINE_DOMAIN);
    if (requestBody.has(VtnServiceJsonConsts.SPINE_DOMAIN)
            && requestBody.get(VtnServiceJsonConsts.SPINE_DOMAIN).isJsonObject()) {
        final JsonObject spineDomainResourceEntry = requestBody
                .getAsJsonObject(VtnServiceJsonConsts.SPINE_DOMAIN);
        isValid = true;
        if (spineDomainResourceEntry.has(VtnServiceJsonConsts.LABEL_NAME)) {
            // validation for key: spine_domain_name(option)
            setInvalidParameter(VtnServiceJsonConsts.LABEL_NAME);
            if (spineDomainResourceEntry.get(VtnServiceJsonConsts.LABEL_NAME).isJsonPrimitive()) {
                isValid = validator.isValidMaxLengthAlphaNum(spineDomainResourceEntry
                        .getAsJsonPrimitive(VtnServiceJsonConsts.LABEL_NAME).getAsString(),
                        VtnServiceJsonConsts.LEN_31);
            } else {
                isValid = false;
            }
        }
    }
    LOG.trace("Complete SpineDomainResourceValidator#validatePut()");
    return isValid;
}

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

License:Open Source License

/**
 * Validate get request Json object for StaticIpRoute API.
 * /*w w w. j  av a  2 s . c  om*/
 * @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 StaticIpRouteResourceValidator#validateGet()");
    boolean isValid = true;
    setInvalidParameter(VtnServiceJsonConsts.TARGETDB);
    if (isValid) {
        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 {
        if (isValid) {
            setInvalidParameter(VtnServiceJsonConsts.OP);
            isValid = validator.isValidOperation(requestBody);
        }
        if (isValid) {
            setInvalidParameter(VtnServiceJsonConsts.INDEX);
            if (requestBody.has(VtnServiceJsonConsts.INDEX)
                    && requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.INDEX).getAsString() != null
                    && !requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.INDEX).getAsString().isEmpty()) {
                final String index = requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.INDEX).getAsString();
                final String[] staticIpRoute = index.split(VtnServiceJsonConsts.HYPHEN);
                isValid = isValidStaticIpRouteId(staticIpRoute);
            }
        }
        if (isValid) {
            setInvalidParameter(VtnServiceJsonConsts.MAX);
            isValid = validator.isValidMaxRepetition(requestBody);
        }
    }
    LOG.trace("Complete StaticIpRouteResourceValidator#validateGet()");
    return isValid;

}

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

License:Open Source License

/**
 * Validate post request Json object for StaticIpRoute API.
 * // w  w w  . jav 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 StaticIpRouteResourceValidator#validatePost()");
    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: ipaddr(mandatory)
        setInvalidParameter(VtnServiceJsonConsts.IPADDR);
        if (staticIp.has(VtnServiceJsonConsts.IPADDR)
                && staticIp.getAsJsonPrimitive(VtnServiceJsonConsts.IPADDR).getAsString() != null) {
            isValid = validator
                    .isValidIpV4(staticIp.getAsJsonPrimitive(VtnServiceJsonConsts.IPADDR).getAsString());
        }

        // validation for key: prefix(mandatory)
        if (isValid) {
            setInvalidParameter(VtnServiceJsonConsts.PREFIX);
            if (staticIp.has(VtnServiceJsonConsts.PREFIX)
                    && staticIp.getAsJsonPrimitive(VtnServiceJsonConsts.PREFIX).getAsString() != null) {
                isValid = validator.isValidRange(
                        staticIp.getAsJsonPrimitive(VtnServiceJsonConsts.PREFIX).getAsString(),
                        VtnServiceJsonConsts.VAL_0, VtnServiceJsonConsts.VAL_32);
            } else {
                isValid = false;
            }
        }
        // validation for key: nmg_name(mandatory)
        // if (isValid) {
        // setInvalidParameter(VtnServiceJsonConsts.NMGNAME);
        // if (staticIp.has(VtnServiceJsonConsts.NMGNAME)
        // && staticIp.getAsJsonPrimitive(
        // VtnServiceJsonConsts.NMGNAME).getAsString() != null
        // && !staticIp
        // .getAsJsonPrimitive(
        // VtnServiceJsonConsts.NMGNAME)
        // .getAsString().isEmpty()) {
        // isValid = validator.isValidMaxLengthAlphaNum(staticIp
        // .getAsJsonPrimitive(VtnServiceJsonConsts.NMGNAME)
        // .getAsString(), VtnServiceJsonConsts.LEN_31);
        // }
        // }
        if (isValid) {
            isValid = validatePut(requestBody);
        }

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