List of usage examples for com.google.gson JsonObject getAsJsonPrimitive
public JsonPrimitive getAsJsonPrimitive(String memberName)
From source file:org.opendaylight.vtn.javaapi.validation.CommonValidator.java
License:Open Source License
/** * Checks if is valid get for integer index. * /*from www. j ava 2 s .c o m*/ * @param requestBody * the request JSON object * @return true, if is valid get for int index */ public final boolean isValidGetForIntIndex(final JsonObject requestBody, final boolean opFlag) { LOG.trace("Start CommonValidator#isValidGetForIntIndex"); boolean isValid = true; // validation for key: tagetdb invalidParameter = VtnServiceJsonConsts.TARGETDB; isValid = 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) { invalidParameter = VtnServiceJsonConsts.OP; isValid = isValidOperation(requestBody); } // validation for key: index if (isValid && requestBody.has(VtnServiceJsonConsts.INDEX) && requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.INDEX).getAsString() != null) { invalidParameter = VtnServiceJsonConsts.INDEX; isValid = isValidRange(requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.INDEX).getAsString(), VtnServiceJsonConsts.VAL_1, VtnServiceJsonConsts.VAL_65535); } // validation for key: max_repitition if (isValid) { invalidParameter = VtnServiceJsonConsts.MAX; isValid = isValidMaxRepetition(requestBody); } } LOG.trace("Complete CommonValidator#isValidGetForIntIndex"); return isValid; }
From source file:org.opendaylight.vtn.javaapi.validation.CommonValidator.java
License:Open Source License
/** * Checks if is valid tagetdb db.//from w ww . j av a2s.c om * * @param targetdb * the value of targetdb in the request JSON object * @return true, if is valid request db */ public final boolean isValidRequestDB(final JsonObject requestBody) { LOG.trace("Start CommonValidator#isValidRequestDB"); 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.CANDIDATE) || targetdb.equalsIgnoreCase(VtnServiceJsonConsts.RUNNING) || targetdb.equalsIgnoreCase(VtnServiceJsonConsts.STATE) || targetdb.equalsIgnoreCase(VtnServiceJsonConsts.STARTUP); } else { requestBody.remove(VtnServiceJsonConsts.TARGETDB); requestBody.addProperty(VtnServiceJsonConsts.TARGETDB, VtnServiceJsonConsts.STATE); } LOG.trace("Complete CommonValidator#isValidRequestDB"); return isValid; }
From source file:org.opendaylight.vtn.javaapi.validation.CommonValidator.java
License:Open Source License
/** * Checks if is operation is count or detail. * // www .j a v a 2 s .c o m * @param operation * the value of operation in the request JSON object * @return true, if is valid operation */ public final boolean isValidOperation(final JsonObject requestBody) { LOG.trace("Start CommonValidator#isValidOperation"); boolean isValid = true; 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) || operation.equalsIgnoreCase(VtnServiceJsonConsts.COUNT); } else { requestBody.remove(VtnServiceJsonConsts.OP); requestBody.addProperty(VtnServiceJsonConsts.OP, VtnServiceJsonConsts.NORMAL); } LOG.trace("Complete CommonValidator#isValidOperation"); return isValid; }
From source file:org.opendaylight.vtn.javaapi.validation.CommonValidator.java
License:Open Source License
/** * Checks if is operation is count or detail. * /*ww w .jav a 2s . co m*/ * @param operation * the value of operation in the request JSON object * @return true, if is valid operation */ public final boolean isValidOperationInfo(final JsonObject requestBody) { LOG.trace("Start CommonValidator#isValidOperation"); boolean isValid = true; 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) || operation.equalsIgnoreCase(VtnServiceJsonConsts.COUNT) || operation.equalsIgnoreCase(VtnServiceJsonConsts.INFO); } else { requestBody.remove(VtnServiceJsonConsts.OP); requestBody.addProperty(VtnServiceJsonConsts.OP, VtnServiceJsonConsts.NORMAL); } LOG.trace("Complete CommonValidator#isValidOperation"); return isValid; }
From source file:org.opendaylight.vtn.javaapi.validation.CommonValidator.java
License:Open Source License
/** * Checks if is operation is count or detail. * // w w w .jav a2 s .c o m * @param operation * the value of operation in the request JSON object * @return true, if is valid operation */ public final boolean isValidOperationShow(final JsonObject requestBody) { LOG.trace("Start CommonValidator#isValidOperation"); boolean isValid = true; 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) || operation.equalsIgnoreCase(VtnServiceJsonConsts.COUNT); } else { requestBody.remove(VtnServiceJsonConsts.OP); requestBody.addProperty(VtnServiceJsonConsts.OP, VtnServiceJsonConsts.NORMAL); } LOG.trace("Complete CommonValidator#isValidOperation"); return isValid; }
From source file:org.opendaylight.vtn.javaapi.validation.CommonValidator.java
License:Open Source License
/** * Checks if is operation is count.// www.j ava 2 s . co m * * @param operation * the value of operation in the request JSON object * @return true, if is valid operation */ public boolean isValidOperationForCount(final JsonObject requestBody) { LOG.trace("Start CommonValidator#isValidOperationForCount"); 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.COUNT); } else { requestBody.remove(VtnServiceJsonConsts.OP); requestBody.addProperty(VtnServiceJsonConsts.OP, VtnServiceJsonConsts.NORMAL); } LOG.trace("Complete CommonValidator#isValidOperationForCount"); return isValid; }
From source file:org.opendaylight.vtn.javaapi.validation.CommonValidator.java
License:Open Source License
/** * Checks if is operation is detail.//from www . j a va 2 s . c o m * * @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. * /*from w w w.jav a 2 s.co 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
/** * Validate put request Json object for FlowFilterEntry APIs * /* ww w.ja v a2 s . c o m*/ * @param requestBody * the request Json object * @return true, if successful */ public final boolean isValidFlowFilterEntry(final JsonObject requestBody) { LOG.trace("Start CommonValidator#isValidFlowFilterEntry()"); boolean isValid = false; setInvalidParameter(VtnServiceJsonConsts.FLOWFILTERENTRY); if (requestBody.has(VtnServiceJsonConsts.FLOWFILTERENTRY) && requestBody.get(VtnServiceJsonConsts.FLOWFILTERENTRY).isJsonObject()) { isValid = true; final JsonObject ffEntry = requestBody.getAsJsonObject(VtnServiceJsonConsts.FLOWFILTERENTRY); // validation for key: fl_name setInvalidParameter(VtnServiceJsonConsts.FLNAME); if (ffEntry.has(VtnServiceJsonConsts.FLNAME) && ffEntry.getAsJsonPrimitive(VtnServiceJsonConsts.FLNAME).getAsString() != null && !ffEntry.get(VtnServiceJsonConsts.FLNAME).getAsString().isEmpty()) { isValid = isValidMaxLengthAlphaNum( ffEntry.getAsJsonPrimitive(VtnServiceJsonConsts.FLNAME).getAsString(), VtnServiceJsonConsts.LEN_32); } // validation for key: action_type if (isValid) { setInvalidParameter(VtnServiceJsonConsts.ACTIONTYPE); if (ffEntry.has(VtnServiceJsonConsts.ACTIONTYPE) && ffEntry.getAsJsonPrimitive(VtnServiceJsonConsts.ACTIONTYPE).getAsString() != null) { final String actionType = ffEntry.getAsJsonPrimitive(VtnServiceJsonConsts.ACTIONTYPE) .getAsString(); isValid = actionType.equalsIgnoreCase(VtnServiceJsonConsts.PASS) || actionType.equalsIgnoreCase(VtnServiceJsonConsts.DROP) || actionType.equalsIgnoreCase(VtnServiceJsonConsts.REDIRECT) || actionType.equalsIgnoreCase(VtnServiceJsonConsts.EMPTY); } } // validation for key: nmg_name if (isValid) { setInvalidParameter(VtnServiceJsonConsts.NMGNAME); if (ffEntry.has(VtnServiceJsonConsts.NMGNAME) && ffEntry.getAsJsonPrimitive(VtnServiceJsonConsts.NMGNAME).getAsString() != null && !ffEntry.get(VtnServiceJsonConsts.NMGNAME).getAsString().isEmpty()) { isValid = isValidMaxLengthAlphaNum( ffEntry.getAsJsonPrimitive(VtnServiceJsonConsts.NMGNAME).getAsString(), VtnServiceJsonConsts.LEN_31); } } // validation for key: priority if (isValid) { setInvalidParameter(VtnServiceJsonConsts.PRIORITY); if (ffEntry.has(VtnServiceJsonConsts.PRIORITY) && ffEntry.getAsJsonPrimitive(VtnServiceJsonConsts.PRIORITY).getAsString() != null) { isValid = isValidRange(ffEntry.getAsJsonPrimitive(VtnServiceJsonConsts.PRIORITY).getAsString(), VtnServiceJsonConsts.VAL_0, VtnServiceJsonConsts.VAL_7); } } // validation for key: dscp if (isValid) { setInvalidParameter(VtnServiceJsonConsts.DSCP); if (ffEntry.has(VtnServiceJsonConsts.DSCP) && ffEntry.getAsJsonPrimitive(VtnServiceJsonConsts.DSCP).getAsString() != null) { isValid = isValidRange(ffEntry.getAsJsonPrimitive(VtnServiceJsonConsts.DSCP).getAsString(), VtnServiceJsonConsts.VAL_0, VtnServiceJsonConsts.VAL_63); } } } LOG.trace("Complete CommonValidator#isValidFlowFilterEntry()"); return isValid; }
From source file:org.opendaylight.vtn.javaapi.validation.CommonValidator.java
License:Open Source License
/** * Validate redirectdst Json Object in request Json object for * FlowFilterEntry APIs/*from ww w . ja v a2 s.co m*/ * * @param ffEntry * the request Json object to be validated * @return true, if successful */ public final boolean isValidRedirectDst(boolean isValid, final JsonObject ffEntry) { LOG.trace("Start CommonValidator#isValidRedirectDst()"); setInvalidParameter(VtnServiceJsonConsts.REDIRECTDST); if (ffEntry.has(VtnServiceJsonConsts.REDIRECTDST)) { final JsonObject dest = ffEntry.getAsJsonObject(VtnServiceJsonConsts.REDIRECTDST); // validation for key: vnode_name (optional) if (isValid) { setInvalidParameter(VtnServiceJsonConsts.VNODENAME); if (dest.has(VtnServiceJsonConsts.VNODENAME) && dest.getAsJsonPrimitive(VtnServiceJsonConsts.VNODENAME).getAsString() != null) { isValid = isValidMaxLengthAlphaNum( dest.getAsJsonPrimitive(VtnServiceJsonConsts.VNODENAME).getAsString(), VtnServiceJsonConsts.LEN_31) || dest.getAsJsonPrimitive(VtnServiceJsonConsts.VNODENAME).getAsString().isEmpty(); } } // validation for key: if_name (optional) if (isValid) { setInvalidParameter(VtnServiceJsonConsts.IFNAME); if (dest.has(VtnServiceJsonConsts.IFNAME) && dest.getAsJsonPrimitive(VtnServiceJsonConsts.IFNAME).getAsString() != null) { isValid = isValidMaxLengthAlphaNum( dest.getAsJsonPrimitive(VtnServiceJsonConsts.IFNAME).getAsString(), VtnServiceJsonConsts.LEN_31) || dest.getAsJsonPrimitive(VtnServiceJsonConsts.IFNAME).getAsString().isEmpty(); } } // validation for key: Direction (optional) if (isValid) { setInvalidParameter(VtnServiceJsonConsts.DIRECTION); if (dest.has(VtnServiceJsonConsts.DIRECTION) && dest.getAsJsonPrimitive(VtnServiceJsonConsts.DIRECTION).getAsString() != null) { isValid = VtnServiceJsonConsts.IN.equalsIgnoreCase( dest.getAsJsonPrimitive(VtnServiceJsonConsts.DIRECTION).getAsString().trim()) || VtnServiceJsonConsts.OUT.equalsIgnoreCase( dest.getAsJsonPrimitive(VtnServiceJsonConsts.DIRECTION).getAsString().trim()) || VtnServiceJsonConsts.EMPTY.equalsIgnoreCase( dest.getAsJsonPrimitive(VtnServiceJsonConsts.DIRECTION).getAsString().trim()); } } // validation for key: macdstaddr (optional) if (isValid) { setInvalidParameter(VtnServiceJsonConsts.MACDSTADDR); if (dest.has(VtnServiceJsonConsts.MACDSTADDR) && dest.getAsJsonPrimitive(VtnServiceJsonConsts.MACDSTADDR).getAsString() != null) { isValid = isValidMacAddress( dest.getAsJsonPrimitive(VtnServiceJsonConsts.MACDSTADDR).getAsString()); } } // validation for key: macsrcaddr (optional) if (isValid) { setInvalidParameter(VtnServiceJsonConsts.MACSRCADDR); if (isValid && dest.has(VtnServiceJsonConsts.MACSRCADDR) && dest.getAsJsonPrimitive(VtnServiceJsonConsts.MACSRCADDR).getAsString() != null) { isValid = isValidMacAddress( dest.getAsJsonPrimitive(VtnServiceJsonConsts.MACSRCADDR).getAsString()); } } } LOG.trace("Complete CommonValidator#isValidRedirectDst()"); return isValid; }