Example usage for com.google.gson JsonObject remove

List of usage examples for com.google.gson JsonObject remove

Introduction

In this page you can find the example usage for com.google.gson JsonObject remove.

Prototype

public JsonElement remove(String property) 

Source Link

Document

Removes the property from this JsonObject .

Usage

From source file:org.onebusaway.admin.service.bundle.impl.BundleBuildingUtil.java

License:Apache License

public static void setBundleId(String metadataFile, String bundleId) {
    if (bundleId == null) {
        return;/*www .  jav  a  2 s .co  m*/
    }
    FileWriter metadataWriter = null;
    try {
        JsonObject metadataJson = new JsonParser().parse(new FileReader(metadataFile)).getAsJsonObject();
        metadataJson.remove("id");
        metadataJson.addProperty("id", bundleId);
        String metadataString = metadataJson.toString();
        metadataWriter = new FileWriter(metadataFile, false);
        metadataWriter.write(metadataString);
    } catch (IOException e) {
        _log.info("Error writing metadata.json: " + e.getMessage());
    } catch (Exception e) {
        _log.error(e.getMessage());
    } finally {
        try {
            if (metadataWriter != null) {
                metadataWriter.close();
            }
        } catch (Exception e) {
            _log.error(e.getMessage());
        }
    }
    return;
}

From source file:org.openbase.bco.registry.agent.core.dbconvert.AgentConfig_0_To_1_DBConverter.java

License:Open Source License

@Override
public JsonObject upgrade(JsonObject agentConfig, final Map<File, JsonObject> dbSnapshot) {
    // remove activation state and use it to set up the enabling state
    if (agentConfig.has("activation_state")) {
        JsonObject activationState = agentConfig.getAsJsonObject("activation_state");
        agentConfig.remove("activation_state");
        JsonObject enablingState = new JsonObject();
        if (activationState.has("value")) {
            EnablingState.State enablingValue = EnablingState.State.ENABLED;
            ActivationState.State activationValue = ActivationState.State
                    .valueOf(activationState.getAsJsonPrimitive("value").getAsString());
            switch (activationValue) {
            case ACTIVE:
                enablingValue = EnablingState.State.ENABLED;
                break;
            case DEACTIVE:
                enablingValue = EnablingState.State.DISABLED;
                break;
            case UNKNOWN:
                enablingValue = EnablingState.State.UNKNOWN;
            }//from  w  w w  . j a v a 2 s .  c om
            enablingState.addProperty("value", enablingValue.toString());
        }
        agentConfig.add("enabling_state", enablingState);
    }

    return agentConfig;
}

From source file:org.openbase.bco.registry.device.core.dbconvert.DeviceConfig_0_To_1_DBConverter.java

License:Open Source License

@Override
public JsonObject upgrade(JsonObject deviceConfig, final Map<File, JsonObject> dbSnapshot) {
    // recover and setup device class id
    JsonObject deviceClass = deviceConfig.get("device_class").getAsJsonObject();
    String deviceClassID = deviceClass.get("id").getAsString();
    deviceConfig.remove("device_class");
    deviceConfig.addProperty("device_class_id", deviceClassID);

    // recover unit config
    JsonArray unitConfigs = deviceConfig.get("unit_config").getAsJsonArray();
    for (JsonElement unitConfigElement : unitConfigs) {
        JsonObject unitConfig = unitConfigElement.getAsJsonObject();

        // remove service config
        unitConfig.remove("service_config");

        // reconstruct unit type and remove template
        String unitType = unitConfig.get("template").getAsJsonObject().get("type").getAsString();
        unitConfig.remove("template");
        unitConfig.addProperty("type", unitType);
    }/*ww  w. j  a  va 2 s. com*/
    return deviceConfig;
}

From source file:org.openbase.bco.registry.device.core.dbconvert.DeviceConfig_1_To_2_DBConverter.java

License:Open Source License

@Override
public JsonObject upgrade(JsonObject deviceConfig, final Map<File, JsonObject> dbSnapshot) {
    // remove the outdated owner(PersonType) from the inventory state
    JsonObject inventoryState = deviceConfig.get("inventory_state").getAsJsonObject();
    deviceConfig.remove("inventory_state");
    inventoryState.remove("owner");
    inventoryState.addProperty("owner_id", "");
    deviceConfig.add("inventory_state", inventoryState);

    return deviceConfig;
}

From source file:org.openbase.bco.registry.location.core.dbconvert.LocationConfig_0_To_1_DBConverter.java

License:Open Source License

@Override
public JsonObject upgrade(final JsonObject locationConfig, final Map<File, JsonObject> dbSnapshot) {

    // check if child element exists otherwise we are finish
    JsonElement childElement = locationConfig.get("child");
    if (childElement == null) {
        return locationConfig;
    }/* w  w w  .  j  a v a 2  s.  c o m*/

    // recover child ids
    JsonArray childConfigs = childElement.getAsJsonArray();
    List<String> childList = new ArrayList<>();
    for (JsonElement childConfigElement : childConfigs) {
        childList.add(childConfigElement.getAsJsonObject().get("id").getAsString());
    }
    // remove outdated child collection
    locationConfig.remove("child");

    // add new entries
    JsonArray child_id_array = new JsonArray();
    for (String child_id : childList) {
        child_id_array.add(child_id);
    }
    locationConfig.add("child_id", child_id_array);

    return locationConfig;
}

From source file:org.openbase.bco.registry.location.core.dbconvert.LocationConfig_2_To_3_DBConverter.java

License:Open Source License

@Override
public JsonObject upgrade(JsonObject locationConfig, final Map<File, JsonObject> dbSnapshot) {
    String oldId = locationConfig.getAsJsonPrimitive("id").getAsString();
    String newId = UUID.randomUUID().toString();

    locationConfig.remove("id");
    locationConfig.add("id", new JsonPrimitive(newId));

    for (JsonObject location : dbSnapshot.values()) {
        if (location.getAsJsonPrimitive("id").getAsString().equals(oldId)) {
            // set new id here?
            continue;
        }//from ww  w.  j ava  2s .  c  o m

        // change parent_id in all location if needed to the new id
        if (location.getAsJsonPrimitive("parent_id") != null
                && location.getAsJsonPrimitive("parent_id").getAsString().equals(oldId)) {
            location.remove("parent_id");
            location.add("parent_id", new JsonPrimitive(newId));
        }

        // adjust the child ids if needed
        if (location.getAsJsonArray("child_id") == null) {
            continue;
        }
        JsonArray childIdArray = new JsonArray();
        for (JsonElement childId : location.getAsJsonArray("child_id")) {
            if (childId.getAsJsonPrimitive().getAsString().equals(oldId)) {
                childIdArray.add(newId);
            } else {
                childIdArray.add(childId.getAsJsonPrimitive().getAsString());
            }
        }
        location.remove("child_id");
        location.add("child_id", childIdArray);
    }

    return locationConfig;
}

From source file:org.openbase.bco.registry.location.core.dbconvert.LocationConfig_3_To_4_DBConverter.java

License:Open Source License

@Override
public JsonObject upgrade(JsonObject locationConfig, final Map<File, JsonObject> dbSnapshot) {
    // remove position
    if (locationConfig.getAsJsonObject("position") != null) {
        locationConfig.remove("position");
    }//  w w  w .j  a va  2  s  .c  o  m

    if (locationConfig.getAsJsonPrimitive("parent_id") == null) {
        return locationConfig;
    }

    String parentId = locationConfig.getAsJsonPrimitive("parent_id").getAsString();
    JsonObject placement;
    if (locationConfig.getAsJsonObject("placement_config") == null) {
        placement = new JsonObject();
    } else {
        placement = locationConfig.getAsJsonObject("placement_config");
    }

    for (JsonObject location : dbSnapshot.values()) {
        if (location.getAsJsonPrimitive("id").getAsString().equals(parentId)) {
            //parent exists
            placement.remove("location_id");
            placement.add("location_id", new JsonPrimitive(parentId));
        }
    }
    locationConfig.remove("parent_id");
    locationConfig.remove("placement_config");
    locationConfig.add("placement_config", placement);

    return locationConfig;
}

From source file:org.opendaylight.vtn.javaapi.ipc.conversion.IpcLogicalResponseFactory.java

License:Open Source License

/**
 * Used for Vtnmapping Response/*from  w ww  . j a  v a2  s.  c o  m*/
 * 
 * @param responsePacket
 * @param requestBody
 * @param getType
 * @return JsonObject
 */
public JsonObject getVtnMappingResponse(final IpcDataUnit[] responsePacket, final JsonObject requestBody,
        final String getType) {

    LOG.trace("Start getVtnMappingResponse");
    final JsonObject root = new JsonObject();
    JsonObject vtnMapping = null;
    JsonArray vtnMappingArray = null;
    JsonArray vtnMappingInfosJsonArray = null;

    LOG.debug("getType: " + getType);
    String rootJsonName;
    /*
     * get type (show or list) will be required to resolve root json name
     * here it will be mapping for show and mappings for list
     */
    if (getType.equals(VtnServiceJsonConsts.SHOW)) {
        rootJsonName = VtnServiceJsonConsts.MAPPING;
    } else {
        rootJsonName = VtnServiceJsonConsts.MAPPINGS;
        // json array will be required for list type of cases
        vtnMappingArray = new JsonArray();
    }
    LOG.debug("Json Name :" + rootJsonName);

    String opType = VtnServiceJsonConsts.NORMAL;
    if (requestBody.has(VtnServiceJsonConsts.OP)) {
        opType = requestBody.get(VtnServiceJsonConsts.OP).getAsString();
    }

    for (int index = 0; index < responsePacket.length; index++) {
        vtnMapping = new JsonObject();
        LOG.debug("initial index :" + index);
        // ignore key-type
        index++;
        /*
         * add mandatory informations from key structure
         */
        LOG.debug("domainId index :" + index);
        final IpcStruct keyVtnControllerStruct = (IpcStruct) responsePacket[index++];
        final String controllerId = IpcDataUnitWrapper.getIpcStructUint8ArrayValue(keyVtnControllerStruct,
                VtnServiceIpcConsts.CONTROLLERNAME);
        final String domainId = IpcDataUnitWrapper.getIpcStructUint8ArrayValue(keyVtnControllerStruct,
                VtnServiceIpcConsts.DOMAINID);

        vtnMapping.addProperty(VtnServiceJsonConsts.MAPPINGID,
                controllerId + VtnServiceJsonConsts.HYPHEN + domainId);

        vtnMapping.addProperty(VtnServiceJsonConsts.CONTROLLERID, controllerId);
        vtnMapping.addProperty(VtnServiceJsonConsts.DOMAINID, domainId);
        // get count of value structure
        LOG.debug("count index :" + index);
        final int count = Integer.valueOf(IpcDataUnitWrapper.getIpcDataUnitValue(responsePacket[index++]));

        if (opType.equalsIgnoreCase(VtnServiceJsonConsts.DETAIL)
                || getType.equalsIgnoreCase(VtnServiceJsonConsts.SHOW)) {
            vtnMappingInfosJsonArray = new JsonArray();

            for (int valIndex = 0; valIndex < count; valIndex++) {
                final JsonObject vtnMappingInfojsonObject = new JsonObject();
                /*
                 * this part is always required in Show, but not required in
                 * List + "normal" op type
                 */

                byte validBit;
                /*
                 * add valid informations from value structure
                 */
                LOG.debug("valVtnMappingStruct index :" + index);
                final IpcStruct valVtnMappingStruct = (IpcStruct) responsePacket[index++];
                validBit = valVtnMappingStruct.getByte(VtnServiceIpcConsts.VALID,
                        UncStructIndexEnum.valVtnMappingControllerStIndex.UPLL_IDX_SWITCH_ID_VMCS.ordinal());
                if (validBit != (byte) UncStructIndexEnum.Valid.UNC_VF_INVALID.ordinal()
                        && validBit != (byte) UncStructIndexEnum.Valid.UNC_VF_NOT_SUPPORTED.ordinal()) {
                    setValueToJsonObject(validBit, vtnMappingInfojsonObject, VtnServiceJsonConsts.SWITCHID,
                            IpcDataUnitWrapper.getIpcStructUint8ArrayValue(valVtnMappingStruct,
                                    VtnServiceIpcConsts.SWITCHID));
                }
                validBit = valVtnMappingStruct.getByte(VtnServiceIpcConsts.VALID,
                        UncStructIndexEnum.valVtnMappingControllerStIndex.UPLL_IDX_PORT_NAME_VMCS.ordinal());
                if (validBit != (byte) UncStructIndexEnum.Valid.UNC_VF_INVALID.ordinal()
                        && validBit != (byte) UncStructIndexEnum.Valid.UNC_VF_NOT_SUPPORTED.ordinal()) {
                    setValueToJsonObject(validBit, vtnMappingInfojsonObject, VtnServiceJsonConsts.PORTNAME,
                            IpcDataUnitWrapper.getIpcStructUint8ArrayValue(valVtnMappingStruct,
                                    VtnServiceIpcConsts.PORTNAME));
                }

                validBit = valVtnMappingStruct.getByte(VtnServiceIpcConsts.VALID,
                        UncStructIndexEnum.valVtnMappingControllerStIndex.UPLL_IDX_LOGICAL_PORT_ID_VMCS
                                .ordinal());
                if (validBit != (byte) UncStructIndexEnum.Valid.UNC_VF_INVALID.ordinal()
                        && validBit != (byte) UncStructIndexEnum.Valid.UNC_VF_NOT_SUPPORTED.ordinal()) {
                    setValueToJsonObject(validBit, vtnMappingInfojsonObject,
                            VtnServiceJsonConsts.LOGICAL_PORT_ID,
                            IpcDataUnitWrapper.getIpcStructUint8ArrayValue(valVtnMappingStruct,
                                    VtnServiceIpcConsts.LOGICAL_PORT_ID));
                }

                validBit = valVtnMappingStruct.getByte(VtnServiceIpcConsts.VALID,
                        UncStructIndexEnum.valVtnMappingControllerStIndex.UPLL_IDX_VLAN_ID_VMCS.ordinal());
                if (validBit != (byte) UncStructIndexEnum.Valid.UNC_VF_INVALID.ordinal()
                        && validBit != (byte) UncStructIndexEnum.Valid.UNC_VF_NOT_SUPPORTED.ordinal()) {

                    String vLanIdValue = IpcDataUnitWrapper.getIpcStructUint16Value(valVtnMappingStruct,
                            VtnServiceIpcConsts.VLANID);

                    if (!vLanIdValue.equalsIgnoreCase(VtnServiceJsonConsts.VLAN_ID_65535)) {
                        setValueToJsonObject(validBit, vtnMappingInfojsonObject, VtnServiceJsonConsts.VLANID,
                                vLanIdValue);
                    }
                }
                validBit = valVtnMappingStruct.getByte(VtnServiceIpcConsts.VALID,
                        UncStructIndexEnum.valVtnMappingControllerStIndex.UPLL_IDX_TAGGED_VMCS.ordinal());

                if (validBit != (byte) UncStructIndexEnum.Valid.UNC_VF_INVALID.ordinal()
                        && validBit != (byte) UncStructIndexEnum.Valid.UNC_VF_NOT_SUPPORTED.ordinal()) {
                    if (IpcDataUnitWrapper
                            .getIpcStructUint8Value(valVtnMappingStruct, VtnServiceIpcConsts.TAGGED)
                            .equals(UncStructIndexEnum.vlan_tagged.UPLL_VLAN_TAGGED.getValue())) {
                        setValueToJsonObject(validBit, vtnMappingInfojsonObject, VtnServiceJsonConsts.TAGGED,
                                VtnServiceJsonConsts.TRUE);
                    } else if (IpcDataUnitWrapper
                            .getIpcStructUint8Value(valVtnMappingStruct, VtnServiceIpcConsts.TAGGED)
                            .equals(UncStructIndexEnum.vlan_tagged.UPLL_VLAN_UNTAGGED.getValue())) {
                        setValueToJsonObject(validBit, vtnMappingInfojsonObject, VtnServiceJsonConsts.TAGGED,
                                VtnServiceJsonConsts.FALSE);
                    }
                    LOG.debug("Tagged :" + IpcDataUnitWrapper.getIpcStructUint8Value(valVtnMappingStruct,
                            VtnServiceIpcConsts.TAGGED));
                }

                validBit = valVtnMappingStruct.getByte(VtnServiceIpcConsts.VALID,
                        UncStructIndexEnum.valVtnMappingControllerStIndex.UPLL_IDX_MAP_TYPE_VMCS.ordinal());
                if (validBit != (byte) UncStructIndexEnum.Valid.UNC_VF_INVALID.ordinal()
                        && validBit != (byte) UncStructIndexEnum.Valid.UNC_VF_NOT_SUPPORTED.ordinal()) {

                    if (UncStructIndexEnum.ValVbrIfMapType.UPLL_IF_OFS_MAP.getValue().equals(IpcDataUnitWrapper
                            .getIpcStructUint8Value(valVtnMappingStruct, VtnServiceIpcConsts.MAP_TYPE))) {
                        setValueToJsonObject(validBit, vtnMappingInfojsonObject, VtnServiceJsonConsts.MAPTYPE,
                                VtnServiceJsonConsts.PORTMAP);
                    } else if (UncStructIndexEnum.ValVbrIfMapType.UPLL_IF_VLAN_MAP.getValue()
                            .equals(IpcDataUnitWrapper.getIpcStructUint8Value(valVtnMappingStruct,
                                    VtnServiceIpcConsts.MAP_TYPE))) {
                        setValueToJsonObject(validBit, vtnMappingInfojsonObject, VtnServiceJsonConsts.MAPTYPE,
                                VtnServiceJsonConsts.VLANMAP);
                    } else {
                        LOG.debug("MapType : invalid");
                    }
                    LOG.debug("MapType :" + IpcDataUnitWrapper.getIpcStructUint8Value(valVtnMappingStruct,
                            VtnServiceIpcConsts.MAP_TYPE));

                }
                // for vnode_type parameter
                validBit = valVtnMappingStruct.getByte(VtnServiceIpcConsts.VALID,
                        UncStructIndexEnum.valVtnMappingControllerStIndex.UPLL_IDX_VNODE_TYPE_VMCS.ordinal());
                if (validBit != (byte) UncStructIndexEnum.Valid.UNC_VF_INVALID.ordinal()
                        && validBit != (byte) UncStructIndexEnum.Valid.UNC_VF_NOT_SUPPORTED.ordinal()) {

                    int vnodeVal = Integer.parseInt(IpcDataUnitWrapper
                            .getIpcStructUint8Value(valVtnMappingStruct, VtnServiceIpcConsts.VNODETYPE));
                    String vnodeType = null;
                    if (vnodeVal == UncStructIndexEnum.ValVnodeType.UPLL_VNODE_VBRIDGE.ordinal()) {
                        vnodeType = VtnServiceJsonConsts.VBRIDGE;
                    } else if (vnodeVal == UncStructIndexEnum.ValVnodeType.UPLL_VNODE_VROUTER.ordinal()) {
                        vnodeType = VtnServiceJsonConsts.VROUTER;
                    } else if (vnodeVal == UncStructIndexEnum.ValVnodeType.UPLL_VNODE_VTEP.ordinal()) {
                        vnodeType = VtnServiceJsonConsts.VTEP;
                    } else if (vnodeVal == UncStructIndexEnum.ValVnodeType.UPLL_VNODE_VTERMINAL.ordinal()) {
                        vnodeType = VtnServiceJsonConsts.VTERMINAL;
                    } else if (vnodeVal == UncStructIndexEnum.ValVnodeType.UPLL_VNODE_VTUNNEL.ordinal()) {
                        vnodeType = VtnServiceJsonConsts.VTUNNEL;
                    } else if (vnodeVal == UncStructIndexEnum.ValVnodeType.UPLL_VNODE_VUNKNOWN.ordinal()) {
                        vnodeType = VtnServiceJsonConsts.VBYPASS;
                    }
                    setValueToJsonObject(validBit, vtnMappingInfojsonObject, VtnServiceJsonConsts.VNODETYPE,
                            vnodeType);
                }
                // for vnode_name parameter
                validBit = valVtnMappingStruct.getByte(VtnServiceIpcConsts.VALID,
                        UncStructIndexEnum.valVtnMappingControllerStIndex.UPLL_IDX_VNODE_NAME_VMCS.ordinal());
                if (validBit != (byte) UncStructIndexEnum.Valid.UNC_VF_INVALID.ordinal()
                        && validBit != (byte) UncStructIndexEnum.Valid.UNC_VF_NOT_SUPPORTED.ordinal()) {
                    setValueToJsonObject(validBit, vtnMappingInfojsonObject, VtnServiceJsonConsts.VNODENAME,
                            IpcDataUnitWrapper.getIpcStructUint8ArrayValue(valVtnMappingStruct,
                                    VtnServiceIpcConsts.VNODENAME));
                }

                validBit = valVtnMappingStruct.getByte(VtnServiceIpcConsts.VALID,
                        UncStructIndexEnum.valVtnMappingControllerStIndex.UPLL_IDX_VNODE_IF_NAME_VMCS
                                .ordinal());
                if (validBit != (byte) UncStructIndexEnum.Valid.UNC_VF_INVALID.ordinal()
                        && validBit != (byte) UncStructIndexEnum.Valid.UNC_VF_NOT_SUPPORTED.ordinal()) {
                    setValueToJsonObject(validBit, vtnMappingInfojsonObject, VtnServiceJsonConsts.IFNAME,
                            IpcDataUnitWrapper.getIpcStructUint8ArrayValue(valVtnMappingStruct,
                                    VtnServiceIpcConsts.VNODEIF_NAME));
                }

                vtnMappingInfosJsonArray.add(vtnMappingInfojsonObject);
            }
            vtnMapping.add(VtnServiceJsonConsts.MAPPINGINFOS, vtnMappingInfosJsonArray);
        } else {
            vtnMapping.remove(VtnServiceJsonConsts.CONTROLLERID);
            vtnMapping.remove(VtnServiceJsonConsts.DOMAINID);
            index = index + count;
        }
        if (null != vtnMappingArray) {
            vtnMappingArray.add(vtnMapping);
        }
    }
    /*
     * finally add either array or single object to root json object and
     * return the same.
     */
    if (null != vtnMappingArray) {
        LOG.debug("List VTN Mapping JSON :" + vtnMappingArray);
        root.add(rootJsonName, vtnMappingArray);
    } else {
        LOG.debug("Show VTN Mapping JSON :" + vtnMapping);
        root.add(rootJsonName, vtnMapping);
    }
    LOG.debug("response Json: " + root.toString());
    LOG.trace("Complete getVtnMappingResponse");

    return root;
}

From source file:org.opendaylight.vtn.javaapi.resources.logical.VBridgeResource.java

License:Open Source License

/**
 * Implementation of Put method of VBridge API
 * /*  w w  w. java  2  s . 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 VBridgeResource#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 vBridge = requestBody.getAsJsonObject(VtnServiceJsonConsts.VBRIDGE);
        if (vBridge.has(VtnServiceJsonConsts.CONTROLLERID)) {
            vBridge.remove(VtnServiceJsonConsts.CONTROLLERID);
        }
        if (vBridge.has(VtnServiceJsonConsts.DOMAINID)) {
            vBridge.remove(VtnServiceJsonConsts.DOMAINID);
        }
        requestProcessor.createIpcRequestPacket(IpcRequestPacketEnum.KT_VBRIDGE_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 VBridgeResource#put()");
    return status;
}

From source file:org.opendaylight.vtn.javaapi.resources.logical.VBypassResource.java

License:Open Source License

/**
 * Implementation of put method of VBypass
 * //from   ww  w  .j  a  v a 2 s.  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("Starts VBypassResource#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 vBypass = requestBody.getAsJsonObject(VtnServiceJsonConsts.VBYPASS);
        if (vBypass.has(VtnServiceJsonConsts.DOMAINID)) {
            vBypass.remove(VtnServiceJsonConsts.DOMAINID);
        }
        requestProcessor.createIpcRequestPacket(IpcRequestPacketEnum.KT_VUNKNOWN_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 VBypassResource#put()");
    return status;
}