List of usage examples for com.google.gson JsonObject remove
public JsonElement remove(String property)
From source file:org.opendaylight.vtn.javaapi.resources.logical.VLinkResource.java
License:Open Source License
/** * Implementation of Put method of VLink Resource API * // ww w. jav a 2s. c o m * @param requestBody * the request Json object * * @return Error code * @throws VtnServiceException */ @Override public final int put(final JsonObject requestBody) throws VtnServiceException { LOG.trace("Start VLinkResource#put()"); ClientSession session = null; IpcRequestProcessor requestProcessor = null; int status = ClientSession.RESP_FATAL; try { LOG.debug("Start Ipc framework call"); session = getConnPool().getSession(UncUPLLEnums.UPLL_IPC_CHANNEL_NAME, UncUPLLEnums.UPLL_IPC_SERVICE_NAME, UncUPLLEnums.ServiceID.UPLL_EDIT_SVC_ID.ordinal(), getExceptionHandler()); LOG.debug("Session created successfully"); requestProcessor = new IpcRequestProcessor(session, getSessionID(), getConfigID(), getExceptionHandler()); //removal of unused parameter in request body. JsonObject vLink = requestBody.getAsJsonObject(VtnServiceJsonConsts.VLINK); if (vLink.has(VtnServiceJsonConsts.VNODE1NAME)) { vLink.remove(VtnServiceJsonConsts.VNODE1NAME); } if (vLink.has(VtnServiceJsonConsts.IF1NAME)) { vLink.remove(VtnServiceJsonConsts.IF1NAME); } if (vLink.has(VtnServiceJsonConsts.VNODE2NAME)) { vLink.remove(VtnServiceJsonConsts.VNODE2NAME); } if (vLink.has(VtnServiceJsonConsts.IF2NAME)) { vLink.remove(VtnServiceJsonConsts.IF2NAME); } requestProcessor.createIpcRequestPacket(IpcRequestPacketEnum.KT_VLINK_UPDATE, requestBody, getUriParameters()); LOG.debug("Request packet created successfully"); status = requestProcessor.processIpcRequest(); LOG.debug("Request packet processed with status" + status); LOG.debug("Complete Ipc framework call"); } catch (final VtnServiceException e) { getExceptionHandler().raise( Thread.currentThread().getStackTrace()[1].getClassName() + VtnServiceConsts.HYPHEN + Thread.currentThread().getStackTrace()[1].getMethodName(), UncJavaAPIErrorCode.IPC_SERVER_ERROR.getErrorCode(), UncJavaAPIErrorCode.IPC_SERVER_ERROR.getErrorMessage(), e); throw e; } finally { if (status == ClientSession.RESP_FATAL) { if (null != requestProcessor.getErrorJson()) { setInfo(requestProcessor.getErrorJson()); } else { createErrorInfo(UncCommonEnum.UncResultCode.UNC_SERVER_ERROR.getValue()); } status = UncResultCode.UNC_SERVER_ERROR.getValue(); } getConnPool().destroySession(session); } LOG.trace("Completed VLinkResource#put()"); return status; }
From source file:org.opendaylight.vtn.javaapi.resources.logical.VRouterResource.java
License:Open Source License
/** * Implementation of Put method of VRouter * /* ww w . j ava2 s. com*/ * @param requestBody * the request Json object * * @return Error code * @throws VtnServiceException */ @Override public final int put(final JsonObject requestBody) throws VtnServiceException { LOG.trace("Start VRouterResource#put()"); ClientSession session = null; IpcRequestProcessor requestProcessor = null; int status = ClientSession.RESP_FATAL; try { LOG.debug("Start Ipc framework call"); session = getConnPool().getSession(UncUPLLEnums.UPLL_IPC_CHANNEL_NAME, UncUPLLEnums.UPLL_IPC_SERVICE_NAME, UncUPLLEnums.ServiceID.UPLL_EDIT_SVC_ID.ordinal(), getExceptionHandler()); LOG.debug("Session created successfully"); requestProcessor = new IpcRequestProcessor(session, getSessionID(), getConfigID(), getExceptionHandler()); //removal of unused parameter in request body. JsonObject vRouter = requestBody.getAsJsonObject(VtnServiceJsonConsts.VROUTER); if (vRouter.has(VtnServiceJsonConsts.CONTROLLERID)) { vRouter.remove(VtnServiceJsonConsts.CONTROLLERID); } if (vRouter.has(VtnServiceJsonConsts.DOMAINID)) { vRouter.remove(VtnServiceJsonConsts.DOMAINID); } requestProcessor.createIpcRequestPacket(IpcRequestPacketEnum.KT_VROUTER_UPDATE, requestBody, getUriParameters()); LOG.debug("Request Packet created successfully"); status = requestProcessor.processIpcRequest(); LOG.debug("Request packet processed with status" + status); LOG.debug("Complete Ipc framework call"); } catch (final VtnServiceException e) { getExceptionHandler().raise( Thread.currentThread().getStackTrace()[1].getClassName() + VtnServiceConsts.HYPHEN + Thread.currentThread().getStackTrace()[1].getMethodName(), UncJavaAPIErrorCode.IPC_SERVER_ERROR.getErrorCode(), UncJavaAPIErrorCode.IPC_SERVER_ERROR.getErrorMessage(), e); throw e; } finally { if (status == ClientSession.RESP_FATAL) { if (null != requestProcessor.getErrorJson()) { setInfo(requestProcessor.getErrorJson()); } else { createErrorInfo(UncCommonEnum.UncResultCode.UNC_SERVER_ERROR.getValue()); } status = UncResultCode.UNC_SERVER_ERROR.getValue(); } getConnPool().destroySession(session); } LOG.trace("Complete VRouterResource#put()"); return status; }
From source file:org.opendaylight.vtn.javaapi.util.VtnServiceUtil.java
License:Open Source License
/** * Remove the parameters of given Json which contain empty string * // w ww . j a v a 2s . c o m * @param Json * object that require to be update * @return Updated Json Object */ public static JsonObject removeEmptyParamas(final JsonObject jsonObject) { // extract all the entries in Json Object final Set<Entry<String, JsonElement>> jsonSet = jsonObject.entrySet(); /* * iterate the loop for each entry */ for (final Entry<String, JsonElement> entry : jsonSet) { /* * if entry is type of Json Object */ if (!(entry.getValue() instanceof JsonNull) && entry.getValue().isJsonObject()) { VtnServiceUtil.removeEmptyParamas((JsonObject) entry.getValue()); continue; } else if (!(entry.getValue() instanceof JsonNull) && entry.getValue().isJsonArray()) { final JsonArray array = (JsonArray) entry.getValue(); for (int index = 0; index < array.size(); index++) { VtnServiceUtil.removeEmptyParamas(array.get(index).getAsJsonObject()); continue; } continue; } else if (!(entry.getValue() instanceof JsonNull) && entry.getValue().getAsString().equals(VtnServiceConsts.EMPTY_STRING)) { jsonObject.remove(entry.getKey()); } } return jsonObject; }
From source file:org.opendaylight.vtn.javaapi.validation.CommonValidator.java
License:Open Source License
/** * Checks if is valid get request.//from w ww . j a v a 2s .com * * @param requestBody * the request JSON object * @return true, if is valid get */ public final boolean isValidGet(final JsonObject requestBody, final boolean opFlag) { LOG.trace("Start CommonValidator#isValidGet"); boolean isValid = true; // validation for key: targetdb 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) { invalidParameter = VtnServiceJsonConsts.INDEX; if (requestBody.has(VtnServiceJsonConsts.INDEX) && requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.INDEX).getAsString() != null && !requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.INDEX).getAsString().isEmpty()) { isValid = isValidMaxLengthAlphaNum( requestBody.getAsJsonPrimitive(VtnServiceJsonConsts.INDEX).getAsString(), VtnServiceJsonConsts.LEN_31); } } // validation for key: max_repitition if (isValid) { invalidParameter = VtnServiceJsonConsts.MAX; isValid = isValidMaxRepetition(requestBody); } } LOG.trace("Complete CommonValidator#isValidGet"); return isValid; }
From source file:org.opendaylight.vtn.javaapi.validation.CommonValidator.java
License:Open Source License
/** * Checks if is valid get for integer index. * /*from w ww .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./*www .j a v a 2 s . 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. * //from ww w . j a v a2 s . co 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. * /*from www .ja va 2s .c o 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. * /*from ww w . ja va2s. com*/ * @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./*from ww w . j a va 2 s . c om*/ * * @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; }