List of usage examples for com.google.gson JsonObject remove
public JsonElement remove(String property)
From source file:org.opendaylight.vtn.javaapi.validation.CommonValidator.java
License:Open Source License
/** * Checks if is operation is detail.//w w w.j av a 2 s. com * * @param operation * the value of operation in the request JSON object * @return true, if is valid operation */ public final boolean isValidOperationForDetail(final JsonObject requestBody) { LOG.trace("Start CommonValidator#isValidOperationForDetail"); boolean isValid = true; 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 CommonValidator#isValidOperationForDetail"); return isValid; }
From source file:org.opendaylight.vtn.javaapi.validation.CommonValidator.java
License:Open Source License
/** * Checks if is valid max repetition count. * /* ww w . j a va 2 s. c o m*/ * @param operation * the value of max repetition count in the request JSON object * @return true, if is valid operation */ public final boolean isValidMaxRepetition(final JsonObject requestBody) { LOG.trace("Start CommonValidator#isValidMaxRepetition"); boolean isValid = true; if (requestBody.has(VtnServiceJsonConsts.MAX) && requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.MAX).getAsString() != null && !requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.MAX).getAsString().isEmpty()) { final String max = requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.MAX).getAsString(); isValid = isValidRange(max, VtnServiceJsonConsts.LONG_VAL_1, VtnServiceJsonConsts.LONG_VAL_4294967295); } else { final VtnServiceConfiguration configuration = VtnServiceInitManager.getConfigurationMap(); requestBody.remove(VtnServiceJsonConsts.MAX); requestBody.addProperty(VtnServiceJsonConsts.MAX, configuration.getConfigValue(VtnServiceConsts.MAX_REP_DEFAULT)); } LOG.trace("Complete CommonValidator#isValidMaxRepetition"); return isValid; }
From source file:org.opendaylight.vtn.javaapi.validation.CommonValidator.java
License:Open Source License
/** * Checks if is valid tagetdb db./*from w w w . j a va 2 s. co m*/ * * @param targetdb * the value of targetdb in the request Json object * @return true, if is valid request db */ public final boolean isValidRequestDBState(final JsonObject requestBody) { LOG.trace("Start CommonValidator#isValidRequestDBState"); boolean isValid = true; if (requestBody.has(VtnServiceJsonConsts.TARGETDB) && requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.TARGETDB).getAsString() != null && !requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.TARGETDB).getAsString().isEmpty()) { final String targetdb = requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.TARGETDB).getAsString(); isValid = targetdb.equalsIgnoreCase(VtnServiceJsonConsts.STATE); } else { requestBody.remove(VtnServiceJsonConsts.TARGETDB); requestBody.addProperty(VtnServiceJsonConsts.TARGETDB, VtnServiceJsonConsts.STATE); } LOG.trace("Complete CommonValidator#isValidRequestDBState"); return isValid; }
From source file:org.opendaylight.vtn.javaapi.validation.logical.DhcpRelayServerResourceValidator.java
License:Open Source License
/** * Validate get request json for DhcpRelayServer API. * /* w ww . ja va 2s . co m*/ * @param requestBody * the request Json object * @return true, if successful * @throws JsonParseException * the json parse exception */ private boolean validateGet(final JsonObject requestBody, final boolean opFlag) throws JsonParseException { LOG.trace("Start DhcpRelayServerResourceValidator#validateGet()"); boolean isValid = true; // validation for key: targetdb(optional) 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"); } 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(optional) if (isValid) { setInvalidParameter(VtnServiceJsonConsts.OP); isValid = validator.isValidOperationForCount(requestBody); } // validation for key: index(optional) if (isValid) { setInvalidParameter(VtnServiceJsonConsts.INDEX); if (requestBody.has(VtnServiceJsonConsts.INDEX) && requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.INDEX).getAsString() != null) { isValid = validator .isValidIpV4(requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.INDEX).getAsString()); } } // validation for key: max(optional) if (isValid) { setInvalidParameter(VtnServiceJsonConsts.MAX); isValid = validator.isValidMaxRepetition(requestBody); } } LOG.trace("Complete DhcpRelayServerResourceValidator#validateGet()"); return isValid; }
From source file:org.opendaylight.vtn.javaapi.validation.logical.FlowFilterEntryResourceValidator.java
License:Open Source License
/** * Validate get request Json object for FlowFilterEntry 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) { LOG.trace("Start FlowFilterEntryResourceValidator#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 && !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); } } 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 FlowFilterEntryResourceValidator#validateGet()"); 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. * /*from w w w . ja v a 2s. co 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. * /* w w w . j a va 2s.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.LabelRangeResourceValidator.java
License:Open Source License
/** * Checks if is valid get request.//from www . ja va 2 s .c o m * * @param requestBody * the request JSON object * @return true, if is valid get */ private boolean validGet(final JsonObject requestBody, final boolean opFlag) { LOG.trace("Start LabelRangeResourceValidator#isValidGet"); boolean isValid = true; // validation for key: tagetdb setInvalidParameter(VtnServiceJsonConsts.TARGETDB); isValid = validator.isValidRequestDB(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.isValidOperation(requestBody); } // validation for key: index if (isValid && requestBody.has(VtnServiceJsonConsts.INDEX) && requestBody.get(VtnServiceJsonConsts.INDEX).isJsonPrimitive()) { setInvalidParameter(VtnServiceJsonConsts.INDEX); isValid = isValidRangeId(requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.INDEX).getAsString()); } // validation for key: max_repitition if (isValid) { setInvalidParameter(VtnServiceJsonConsts.MAX); isValid = validator.isValidMaxRepetition(requestBody); } } LOG.trace("Complete LabelRangeResourceValidator#isValidGet"); 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. * //from ww w.j a v a 2 s. com * @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.VBridgeFlowFilterEntryResourceValidator.java
License:Open Source License
/** * validate get request Json object for VbridgeFlowFilterEntry, * VbridgeInetrfaceFlowFilterEntry and VrouterInterfaceFlowFilterEntry API. * //from www.j a va 2 s.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; }