List of usage examples for com.google.gson JsonObject getAsJsonPrimitive
public JsonPrimitive getAsJsonPrimitive(String memberName)
From source file:org.opendaylight.vtn.javaapi.validation.logical.VTunnelResourceValidator.java
License:Open Source License
/** * Validate post request Json object for VTunnel API * /*from w w w . j ava 2s. 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 VTunnelResourceValidator#validatePost()"); boolean isValid = false; setInvalidParameter(VtnServiceJsonConsts.VTUNNEL); if (requestBody.has(VtnServiceJsonConsts.VTUNNEL) && requestBody.get(VtnServiceJsonConsts.VTUNNEL).isJsonObject()) { final JsonObject vTunnel = requestBody.getAsJsonObject(VtnServiceJsonConsts.VTUNNEL); // validation for key: vtunnel_name(mandatory) setInvalidParameter(VtnServiceJsonConsts.VTUNNELNAME); if (vTunnel.has(VtnServiceJsonConsts.VTUNNELNAME) && vTunnel.getAsJsonPrimitive(VtnServiceJsonConsts.VTUNNELNAME).getAsString() != null) { isValid = validator.isValidMaxLengthAlphaNum( vTunnel.getAsJsonPrimitive(VtnServiceJsonConsts.VTUNNELNAME).getAsString(), VtnServiceJsonConsts.LEN_31); } // validation for key: controller_id(mandatory) if (isValid) { setInvalidParameter(VtnServiceJsonConsts.CONTROLLERID); if (vTunnel.has(VtnServiceJsonConsts.CONTROLLERID) && vTunnel.getAsJsonPrimitive(VtnServiceJsonConsts.CONTROLLERID).getAsString() != null) { isValid = validator.isValidMaxLengthAlphaNum( vTunnel.getAsJsonPrimitive(VtnServiceJsonConsts.CONTROLLERID).getAsString(), VtnServiceJsonConsts.LEN_31); } else { isValid = false; } } // validation for key: label(mandatory) setInvalidParameter(VtnServiceJsonConsts.LABEL); if (isValid && vTunnel.has(VtnServiceJsonConsts.LABEL) && vTunnel.getAsJsonPrimitive(VtnServiceJsonConsts.LABEL).getAsString() != null) { isValid = validator.isValidRange( vTunnel.getAsJsonPrimitive(VtnServiceJsonConsts.LABEL).getAsString(), VtnServiceJsonConsts.LONG_VAL_0, VtnServiceJsonConsts.LONG_VAL_4294967295); } else { isValid = false; } // validation for key: DomainId(mandatory) setInvalidParameter(VtnServiceJsonConsts.DOMAINID); if (isValid && vTunnel.has(VtnServiceJsonConsts.DOMAINID) && vTunnel.getAsJsonPrimitive(VtnServiceJsonConsts.DOMAINID).getAsString() != null) { isValid = validator.isValidDomainId( vTunnel.getAsJsonPrimitive(VtnServiceJsonConsts.DOMAINID).getAsString(), VtnServiceJsonConsts.LEN_31); } else { isValid = false; } if (isValid) { // validation for key: description(optional), // vtn_name(optional), vtepgroup_name(optional) isValid = commonValidations(isValid, vTunnel); } } LOG.trace("complete VTunnelResourceValidator#validatePost()"); return isValid; }
From source file:org.opendaylight.vtn.javaapi.validation.logical.VTunnelResourceValidator.java
License:Open Source License
/** * @param isValid/*from w ww . j av a 2s . c o m*/ * @param vTunnel * @return */ private boolean commonValidations(boolean isValid, final JsonObject vTunnel) { LOG.trace("Start VTunnelResourceValidator#commonValidations()"); // validation for key: description(optional) setInvalidParameter(VtnServiceJsonConsts.DESCRIPTION); if (vTunnel.has(VtnServiceJsonConsts.DESCRIPTION) && vTunnel.getAsJsonPrimitive(VtnServiceJsonConsts.DESCRIPTION).getAsString() != null) { isValid = validator.isValidMaxLength( vTunnel.getAsJsonPrimitive(VtnServiceJsonConsts.DESCRIPTION).getAsString(), VtnServiceJsonConsts.LEN_127) || vTunnel.getAsJsonPrimitive(VtnServiceJsonConsts.DESCRIPTION).getAsString().isEmpty(); } // validation for key: vtn_name(optional) if (isValid) { setInvalidParameter(VtnServiceJsonConsts.VTNNAME); if (vTunnel.has(VtnServiceJsonConsts.VTNNAME) && vTunnel.getAsJsonPrimitive(VtnServiceJsonConsts.VTNNAME).getAsString() != null) { isValid = validator.isValidMaxLengthAlphaNum( vTunnel.getAsJsonPrimitive(VtnServiceJsonConsts.VTNNAME).getAsString(), VtnServiceJsonConsts.LEN_31) || vTunnel.getAsJsonPrimitive(VtnServiceJsonConsts.VTNNAME).getAsString().isEmpty(); } } // validation for key: vtepgroup_name(optional) if (isValid) { setInvalidParameter(VtnServiceJsonConsts.VTEPGROUPNAME); if (vTunnel.has(VtnServiceJsonConsts.VTEPGROUPNAME) && vTunnel.getAsJsonPrimitive(VtnServiceJsonConsts.VTEPGROUPNAME).getAsString() != null) { isValid = validator.isValidMaxLengthAlphaNum( vTunnel.getAsJsonPrimitive(VtnServiceJsonConsts.VTEPGROUPNAME).getAsString(), VtnServiceJsonConsts.LEN_31) || vTunnel.getAsJsonPrimitive(VtnServiceJsonConsts.VTEPGROUPNAME).getAsString().isEmpty(); } } LOG.trace("complete VTunnelResourceValidator#commonValidations()"); return isValid; }
From source file:org.opendaylight.vtn.javaapi.validation.physical.AlarmResourceValidator.java
License:Open Source License
/** * Validate put request json for Clear Alarms API. * // w ww . ja v a 2s. c om * @param requestBody * the request Json object * * @return true, if successful */ private boolean validatePut(final JsonObject requestBody) { LOG.trace("Start AlarmResourceValidator#validatePut()"); boolean isValid = false; // validation for key: alarm_no(mandatory) setInvalidParameter(VtnServiceJsonConsts.ALARMNO); if (requestBody.has(VtnServiceJsonConsts.ALARMNO) && requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.ALARMNO).getAsString() != null && !requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.ALARMNO).getAsString().isEmpty()) { isValid = validator.isValidBigIntegerRangeString( new BigInteger(requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.ALARMNO).getAsString()), VtnServiceJsonConsts.BIG_VAL0, VtnServiceJsonConsts.BIG_VAL_9999999999999999999); } else { isValid = false; } LOG.trace("Complete AlarmResourceValidator#validatePut()"); 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 * //from 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 post request json for create Boundary API * //from www . j a v a2 s . c om * @param requestBody * the request Json object * @return true, if successful * @throws VtnServiceException */ private boolean validatePost(final JsonObject requestBody) throws VtnServiceException { LOG.trace("Start BoundaryResourceValidator#validatePost()"); boolean isValid = false; setInvalidParameter(VtnServiceJsonConsts.BOUNDARY); if (requestBody.has(VtnServiceJsonConsts.BOUNDARY) && requestBody.get(VtnServiceJsonConsts.BOUNDARY).isJsonObject()) { final JsonObject boundary = requestBody.getAsJsonObject(VtnServiceJsonConsts.BOUNDARY); // validation for mandatory key: boundary_name(mandatory) setInvalidParameter(VtnServiceJsonConsts.BOUNDARYID); if (boundary.has(VtnServiceJsonConsts.BOUNDARYID) && boundary.getAsJsonPrimitive(VtnServiceJsonConsts.BOUNDARYID).getAsString() != null) { isValid = validator.isValidMaxLengthAlphaNum( boundary.getAsJsonPrimitive(VtnServiceJsonConsts.BOUNDARYID).getAsString(), VtnServiceJsonConsts.LEN_31); } if (isValid) { // validation for key: description 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) { setInvalidParameter(VtnServiceJsonConsts.LINK); if (isValid && boundary.has(VtnServiceJsonConsts.LINK)) { final JsonObject link = boundary.getAsJsonObject(VtnServiceJsonConsts.LINK); // validation for key: controller1id (mandatory) setInvalidParameter(VtnServiceJsonConsts.CONTROLLER1ID); if (link.has(VtnServiceJsonConsts.CONTROLLER1ID) && link.getAsJsonPrimitive(VtnServiceJsonConsts.CONTROLLER1ID).getAsString() != null) { isValid = validator.isValidMaxLengthAlphaNum( link.getAsJsonPrimitive(VtnServiceJsonConsts.CONTROLLER1ID).getAsString(), VtnServiceJsonConsts.LEN_31); } else { isValid = false; } if (isValid) { // validation for key: domain1_id (mandatory) setInvalidParameter(VtnServiceJsonConsts.DOMAIN1_ID); if (link.has(VtnServiceJsonConsts.DOMAIN1_ID) && link.getAsJsonPrimitive(VtnServiceJsonConsts.DOMAIN1_ID).getAsString() != null) { isValid = validator.isValidDomainId( link.getAsJsonPrimitive(VtnServiceJsonConsts.DOMAIN1_ID).getAsString(), VtnServiceJsonConsts.LEN_31); } else { isValid = false; } } if (isValid) { // validation for key: logical_port1_id (optional) setInvalidParameter(VtnServiceJsonConsts.LOGICAL_PORT1_ID); if (link.has(VtnServiceJsonConsts.LOGICAL_PORT1_ID) && link.getAsJsonPrimitive(VtnServiceJsonConsts.LOGICAL_PORT1_ID) .getAsString() != null && !link.getAsJsonPrimitive(VtnServiceJsonConsts.LOGICAL_PORT1_ID).getAsString() .isEmpty()) { isValid = validator.isValidMaxLength( link.getAsJsonPrimitive(VtnServiceJsonConsts.LOGICAL_PORT1_ID).getAsString(), VtnServiceJsonConsts.LEN_319); } } if (isValid) { // validation for key: controller2_id (mandatory) setInvalidParameter(VtnServiceJsonConsts.CONTROLLER2ID); if (link.has(VtnServiceJsonConsts.CONTROLLER2ID) && link .getAsJsonPrimitive(VtnServiceJsonConsts.CONTROLLER2ID).getAsString() != null) { isValid = validator.isValidMaxLengthAlphaNum( link.getAsJsonPrimitive(VtnServiceJsonConsts.CONTROLLER2ID).getAsString(), VtnServiceJsonConsts.LEN_31); } else { isValid = false; } } if (isValid) { // validation for key: domain2_id (mandatory) setInvalidParameter(VtnServiceJsonConsts.DOMAIN2_ID); if (link.has(VtnServiceJsonConsts.DOMAIN2_ID) && link.getAsJsonPrimitive(VtnServiceJsonConsts.DOMAIN2_ID).getAsString() != null) { isValid = validator.isValidDomainId( link.getAsJsonPrimitive(VtnServiceJsonConsts.DOMAIN2_ID).getAsString(), VtnServiceJsonConsts.LEN_31); } else { isValid = false; } } if (isValid) { // validation for key: logical_port2_id (optional) setInvalidParameter(VtnServiceJsonConsts.LOGICAL_PORT2_ID); if (link.has(VtnServiceJsonConsts.LOGICAL_PORT2_ID) && link.getAsJsonPrimitive(VtnServiceJsonConsts.LOGICAL_PORT2_ID) .getAsString() != null && !link.getAsJsonPrimitive(VtnServiceJsonConsts.LOGICAL_PORT2_ID).getAsString() .isEmpty()) { isValid = validator.isValidMaxLength( link.getAsJsonPrimitive(VtnServiceJsonConsts.LOGICAL_PORT2_ID).getAsString(), VtnServiceJsonConsts.LEN_319); } } } else { isValid = false; } } } else { isValid = false; } LOG.trace("Complete BoundaryResourceValidator#validatePost()"); 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 * /* w ww. j a v a 2 s .co 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.ControllerDataFlowResourceValidator.java
License:Open Source License
/** * Validate request json for get method of Controller Data Flow API * //w w w . j a va 2s. c o m * @param requestBody * the request Json object * @return true, if successful * @throws VtnServiceException * @param opFlag * , operation type */ private boolean isValidateGet(final JsonObject requestBody, final boolean opFlag) { LOG.trace("Start ControllerDataFlowResourceValidator#isValidateGet()"); boolean isValid = true; setInvalidParameter(VtnServiceJsonConsts.URI + VtnServiceJsonConsts.CONTROLLERID); if (resource instanceof ControllerDataFlowResource && ((ControllerDataFlowResource) resource).getControllerId() != null && !((ControllerDataFlowResource) resource).getControllerId().isEmpty()) { isValid = validator.isValidMaxLengthAlphaNum(((ControllerDataFlowResource) resource).getControllerId(), VtnServiceJsonConsts.LEN_31); setListOpFlag(true); } 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); } setInvalidParameter(VtnServiceJsonConsts.FLOW_ID); if (requestBody.has(VtnServiceJsonConsts.FLOW_ID) && requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.FLOW_ID).getAsString() != null) { isValid = validator.isValidBigIntegerRangeString( new BigInteger(requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.FLOW_ID).getAsString()), VtnServiceJsonConsts.BIG_VAL0, VtnServiceJsonConsts.BIG_VAL_18446744073709551615); } else { isValid = false; } LOG.trace("Complete ControllerDataFlowResourceValidator#isValidateGet"); 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 * /*from w w w. j a v a 2s.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.ControllerResourceValidator.java
License:Open Source License
/** * Validate request json for post method of controller API * /*w w w . j av a 2 s . co m*/ * @param requestBody * the request Json object * * @return true, if successful */ private boolean validatePost(final JsonObject requestBody) { LOG.trace("Start ControllerResourceValidator#validatePost()"); boolean isValid = false; setInvalidParameter(VtnServiceJsonConsts.CONTROLLER); if (requestBody.has(VtnServiceJsonConsts.CONTROLLER) && requestBody.get(VtnServiceJsonConsts.CONTROLLER).isJsonObject()) { final JsonObject controller = requestBody.getAsJsonObject(VtnServiceJsonConsts.CONTROLLER); // validation for mandatory key: controllerId(mandatory) setInvalidParameter(VtnServiceJsonConsts.CONTROLLERID); if (controller.has(VtnServiceJsonConsts.CONTROLLERID) && controller.getAsJsonPrimitive(VtnServiceJsonConsts.CONTROLLERID).getAsString() != null) { isValid = validator.isValidMaxLengthAlphaNum( controller.getAsJsonPrimitive(VtnServiceJsonConsts.CONTROLLERID).getAsString(), VtnServiceJsonConsts.LEN_31); } if (isValid) { // validation for key: type(mandatory) setInvalidParameter(VtnServiceJsonConsts.TYPE); if (controller.has(VtnServiceJsonConsts.TYPE) && controller.getAsJsonPrimitive(VtnServiceJsonConsts.TYPE).getAsString() != null) { isValid = validator .isValidType(controller.getAsJsonPrimitive(VtnServiceJsonConsts.TYPE).getAsString()); } else { isValid = false; } } if (isValid) { // validation for key: version(mandatory) setInvalidParameter(VtnServiceJsonConsts.VERSION); if (controller.has(VtnServiceJsonConsts.VERSION) && controller.getAsJsonPrimitive(VtnServiceJsonConsts.VERSION).getAsString() != null) { isValid = validator.isValidVersion( controller.getAsJsonPrimitive(VtnServiceJsonConsts.VERSION).getAsString(), VtnServiceJsonConsts.LEN_31); } else { isValid = false; } } if (isValid) { isValid = validateField(isValid, controller); } } LOG.trace("Complete ControllerResourceValidator#validatePost()"); return isValid; }