/** * Validate uri parameters for Vtn Mapping API. * * @return true, if successful */ @Override public final boolean validateUri() { LOG.trace("Start VtnMappingResourceValidator#validateUri()"); boolean isValid = false; setInvalidParameter(VtnServiceJsonConsts.URI + VtnServiceJsonConsts.VTNNAME); if (resource instanceof VtnMappingsResource && ((VtnMappingsResource) resource).getVtnName() != null && !((VtnMappingsResource) resource).getVtnName().isEmpty()) { isValid = validator.isValidMaxLengthAlphaNum( ((VtnMappingsResource) resource).getVtnName(), VtnServiceJsonConsts.LEN_31); setListOpFlag(true); } else if (resource instanceof VtnMappingResource && ((VtnMappingResource) resource).getVtnName() != null && !((VtnMappingResource) resource).getVtnName().isEmpty()) { isValid = validator.isValidMaxLengthAlphaNum( ((VtnMappingResource) resource).getVtnName(), VtnServiceJsonConsts.LEN_31); if (isValid) { setInvalidParameter(VtnServiceJsonConsts.URI + VtnServiceJsonConsts.MAPPINGID); if (((VtnMappingResource) resource).getMappingId() != null && !((VtnMappingResource) resource).getMappingId().isEmpty()) { final String[] mappingId = ((VtnMappingResource) resource).getMappingId().split(VtnServiceJsonConsts.HYPHEN); isValid = validator.isValidMappingId(mappingId); } else { isValid = false; } } setListOpFlag(false); } LOG.trace("Completed VtnMappingResourceValidator#validateUri()"); return isValid; }
/** * @param requestBody , 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; }