incubator-cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mc...@apache.org
Subject git commit: Revert "Guard null pointer exceptions."
Date Wed, 19 Dec 2012 19:25:06 GMT
Updated Branches:
  refs/heads/api_refactoring 1d729578d -> e397f23f6


Revert "Guard null pointer exceptions."

This reverts commit fc56e29a3ec22035c744e276538e8a20e5923996.

Conflicts:
	server/src/com/cloud/api/ApiResponseHelper.java

Signed-off-by: Min Chen <min.chen@citrix.com>


Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/e397f23f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/e397f23f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/e397f23f

Branch: refs/heads/api_refactoring
Commit: e397f23f6b5d6ba34ad42eca95ae9d9ee43ac6a8
Parents: 1d72957
Author: Min Chen <min.chen@citrix.com>
Authored: Wed Dec 19 11:23:09 2012 -0800
Committer: Min Chen <min.chen@citrix.com>
Committed: Wed Dec 19 11:23:09 2012 -0800

----------------------------------------------------------------------
 server/src/com/cloud/api/ApiResponseHelper.java |  235 ++++++------------
 1 files changed, 71 insertions(+), 164 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/e397f23f/server/src/com/cloud/api/ApiResponseHelper.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/ApiResponseHelper.java b/server/src/com/cloud/api/ApiResponseHelper.java
index 44d3693..c602577 100755
--- a/server/src/com/cloud/api/ApiResponseHelper.java
+++ b/server/src/com/cloud/api/ApiResponseHelper.java
@@ -151,7 +151,6 @@ import com.cloud.event.Event;
 import com.cloud.host.Host;
 import com.cloud.host.HostStats;
 import com.cloud.host.HostVO;
-import com.cloud.hypervisor.Hypervisor.HypervisorType;
 import com.cloud.hypervisor.HypervisorCapabilities;
 import com.cloud.network.IPAddressVO;
 import com.cloud.network.IpAddress;
@@ -284,9 +283,7 @@ public class ApiResponseHelper implements ResponseGenerator {
             accountResponse.setDomainId(domain.getUuid());
             accountResponse.setDomainName(domain.getName());
         }
-        if (account.getState() != null) {
-            accountResponse.setState(account.getState().toString());
-        }
+        accountResponse.setState(account.getState().toString());
         accountResponse.setNetworkDomain(account.getNetworkDomain());
         DataCenter dc = ApiDBUtils.findZoneById(account.getDefaultZoneId());
         if (dc != null) {
@@ -443,17 +440,16 @@ public class ApiResponseHelper implements ResponseGenerator {
         domainResponse.setId(domain.getUuid());
         domainResponse.setLevel(domain.getLevel());
         domainResponse.setNetworkDomain(domain.getNetworkDomain());
-        if (domain.getParent() != null) {
-            Domain parentDomain = ApiDBUtils.findDomainById(domain.getParent());
-            if (parentDomain != null) {
-                domainResponse.setParentDomainId(parentDomain.getUuid());
-                domainResponse.setParentDomainName(parentDomain.getName());
-            }
+        Domain parentDomain = ApiDBUtils.findDomainById(domain.getParent());
+        if (parentDomain != null) {
+            domainResponse.setParentDomainId(parentDomain.getUuid());
         }
         StringBuilder domainPath = new StringBuilder("ROOT");
         (domainPath.append(domain.getPath())).deleteCharAt(domainPath.length() - 1);
         domainResponse.setPath(domainPath.toString());
-
+        if (domain.getParent() != null) {
+            domainResponse.setParentDomainName(ApiDBUtils.findDomainById(domain.getParent()).getName());
+        }
         if (domain.getChildCount() > 0) {
             domainResponse.setHasChild(true);
         }
@@ -493,9 +489,7 @@ public class ApiResponseHelper implements ResponseGenerator {
             populateAccount(resourceLimitResponse, limit.getOwnerId());
             populateDomain(resourceLimitResponse, accountTemp.getDomainId());
         }
-        if (limit.getType() != null) {
-            resourceLimitResponse.setResourceType(Integer.valueOf(limit.getType().getOrdinal()).toString());
-        }
+        resourceLimitResponse.setResourceType(Integer.valueOf(limit.getType().getOrdinal()).toString());
         resourceLimitResponse.setMax(limit.getMax());
         resourceLimitResponse.setObjectName("resourcelimit");
 
@@ -516,9 +510,7 @@ public class ApiResponseHelper implements ResponseGenerator {
             populateDomain(resourceCountResponse, resourceCount.getOwnerId());
         }
 
-        if (resourceCount.getType() != null) {
-            resourceCountResponse.setResourceType(Integer.valueOf(resourceCount.getType().getOrdinal()).toString());
-        }
+        resourceCountResponse.setResourceType(Integer.valueOf(resourceCount.getType().getOrdinal()).toString());
         resourceCountResponse.setResourceCount(resourceCount.getCount());
         resourceCountResponse.setObjectName("resourcecount");
         return resourceCountResponse;
@@ -674,9 +666,7 @@ public class ApiResponseHelper implements ResponseGenerator {
 
             if (cluster != null) {
                 hostResponse.setClusterName(cluster.getName());
-                if (cluster.getClusterType() != null) {
-                    hostResponse.setClusterType(cluster.getClusterType().toString());
-                }
+                hostResponse.setClusterType(cluster.getClusterType().toString());
             }
         }
 
@@ -752,9 +742,7 @@ public class ApiResponseHelper implements ResponseGenerator {
             }
         }
 
-        if (host.getResourceState() != null) {
-            hostResponse.setResourceState(host.getResourceState().toString());
-        }
+        hostResponse.setResourceState(host.getResourceState().toString());
         hostResponse.setObjectName("host");
 
         return hostResponse;
@@ -833,9 +821,7 @@ public class ApiResponseHelper implements ResponseGenerator {
 
         IPAddressResponse ipResponse = new IPAddressResponse();
         ipResponse.setId(ipAddr.getUuid());
-        if (ipAddr.getAddress() != null) {
-            ipResponse.setIpAddress(ipAddr.getAddress().toString());
-        }
+        ipResponse.setIpAddress(ipAddr.getAddress().toString());
         if (ipAddr.getAllocatedTime() != null) {
             ipResponse.setAllocated(ipAddr.getAllocatedTime());
         }
@@ -901,9 +887,7 @@ public class ApiResponseHelper implements ResponseGenerator {
                 ipResponse.setNetworkId(nw.getUuid());
             }
         }
-        if (ipAddr.getState() != null) {
-            ipResponse.setState(ipAddr.getState().toString());
-        }
+        ipResponse.setState(ipAddr.getState().toString());
 
         if (ipAddr.getPhysicalNetworkId() != null) {
             PhysicalNetworkVO pnw = ApiDBUtils.findPhysicalNetworkById(ipAddr.getPhysicalNetworkId());
@@ -959,13 +943,11 @@ public class ApiResponseHelper implements ResponseGenerator {
         lbResponse.setPrivatePort(Integer.toString(loadBalancer.getDefaultPortStart()));
         lbResponse.setAlgorithm(loadBalancer.getAlgorithm());
         FirewallRule.State state = loadBalancer.getState();
-        if (state != null) {
-            String stateToSet = state.toString();
-            if (state.equals(FirewallRule.State.Revoke)) {
-                stateToSet = "Deleting";
-            }
-            lbResponse.setState(stateToSet);
+        String stateToSet = state.toString();
+        if (state.equals(FirewallRule.State.Revoke)) {
+            stateToSet = "Deleting";
         }
+        lbResponse.setState(stateToSet);
         populateOwner(lbResponse, loadBalancer);
         DataCenter zone = ApiDBUtils.findZoneById(publicIp.getDataCenterId());
         if (zone != null) {
@@ -1006,9 +988,7 @@ public class ApiResponseHelper implements ResponseGenerator {
         podResponse.setStartIp(ipRange[0]);
         podResponse.setEndIp(((ipRange.length > 1) && (ipRange[1] != null)) ?
ipRange[1] : "");
         podResponse.setGateway(pod.getGateway());
-        if (pod.getAllocationState() != null) {
-            podResponse.setAllocationState(pod.getAllocationState().toString());
-        }
+        podResponse.setAllocationState(pod.getAllocationState().toString());
         if (showCapacities != null && showCapacities) {
             List<SummedCapacity> capacities = ApiDBUtils.getCapacityByClusterPodZone(null,
pod.getId(), null);
             Set<CapacityResponse> capacityResponses = new HashSet<CapacityResponse>();
@@ -1106,12 +1086,8 @@ public class ApiResponseHelper implements ResponseGenerator {
             zoneResponse.setDomainName(domain.getName());
         }
 
-        if (dataCenter.getNetworkType() != null) {
-            zoneResponse.setType(dataCenter.getNetworkType().toString());
-        }
-        if (dataCenter.getAllocationState() != null) {
-            zoneResponse.setAllocationState(dataCenter.getAllocationState().toString());
-        }
+        zoneResponse.setType(dataCenter.getNetworkType().toString());
+        zoneResponse.setAllocationState(dataCenter.getAllocationState().toString());
         zoneResponse.setZoneToken(dataCenter.getZoneToken());
         zoneResponse.setDhcpProvider(dataCenter.getDhcpProvider());
         zoneResponse.setObjectName("zone");
@@ -1159,9 +1135,7 @@ public class ApiResponseHelper implements ResponseGenerator {
             volResponse.setZoneName(zone.getName());
         }
 
-        if (volume.getVolumeType() != null) {
-            volResponse.setVolumeType(volume.getVolumeType().toString());
-        }
+        volResponse.setVolumeType(volume.getVolumeType().toString());
         volResponse.setDeviceId(volume.getDeviceId());
 
         Long instanceId = volume.getInstanceId();
@@ -1170,22 +1144,17 @@ public class ApiResponseHelper implements ResponseGenerator {
             if (vm != null) {
                 volResponse.setVirtualMachineId(vm.getUuid());
                 volResponse.setVirtualMachineName(vm.getHostName());
-                if (vm.getState() != null) {
-                    volResponse.setVirtualMachineState(vm.getState().toString());
-                }
-
+                volResponse.setVirtualMachineState(vm.getState().toString());
                 UserVm userVm = ApiDBUtils.findUserVmById(vm.getId());
                 if (userVm != null) {
                     if (userVm.getDisplayName() != null) {
                         volResponse.setVirtualMachineDisplayName(userVm.getDisplayName());
-                    } else {
-                        volResponse.setVirtualMachineDisplayName(userVm.getHostName());
                     }
                 } else {
-                    s_logger.error("User Vm with Id: " + instanceId + " does not exist for
volume " + volume.getId());
+                        s_logger.error("User Vm with Id: " + instanceId + " does not exist
for volume " + volume.getId());
                 }
             } else {
-                s_logger.error("Vm with Id: " + instanceId + " does not exist for volume
" + volume.getId());
+                    s_logger.error("Vm with Id: " + instanceId + " does not exist for volume
" + volume.getId());
             }
         }
 
@@ -1193,9 +1162,7 @@ public class ApiResponseHelper implements ResponseGenerator {
         volResponse.setSize(volume.getSize());
 
         volResponse.setCreated(volume.getCreated());
-        if (volume.getState() != null) {
-            volResponse.setState(volume.getState().toString());
-        }
+        volResponse.setState(volume.getState().toString());
         if(volume.getState() == Volume.State.UploadOp){
             com.cloud.storage.VolumeHostVO volumeHostRef = ApiDBUtils.findVolumeHostRef(volume.getId(),
volume.getDataCenterId());
             volResponse.setSize(volumeHostRef.getSize());
@@ -1260,10 +1227,7 @@ public class ApiResponseHelper implements ResponseGenerator {
         // return hypervisor for ROOT and Resource domain only
         Account caller = UserContext.current().getCaller();
         if ((caller.getType() == Account.ACCOUNT_TYPE_ADMIN || caller.getType() == Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN)
&& volume.getState() != Volume.State.UploadOp) {
-            HypervisorType ht = ApiDBUtils.getVolumeHyperType(volume.getId());
-            if (ht != null) {
-                volResponse.setHypervisor(ht.toString());
-            }
+            volResponse.setHypervisor(ApiDBUtils.getVolumeHyperType(volume.getId()).toString());
         }
 
         volResponse.setAttached(volume.getAttached());
@@ -1361,18 +1325,10 @@ public class ApiResponseHelper implements ResponseGenerator {
             clusterResponse.setZoneId(dc.getUuid());
             clusterResponse.setZoneName(dc.getName());
         }
-        if (cluster.getHypervisorType() != null) {
-            clusterResponse.setHypervisorType(cluster.getHypervisorType().toString());
-        }
-        if (cluster.getClusterType() != null) {
-            clusterResponse.setClusterType(cluster.getClusterType().toString());
-        }
-        if (cluster.getAllocationState() != null) {
-            clusterResponse.setAllocationState(cluster.getAllocationState().toString());
-        }
-        if (cluster.getManagedState() != null) {
-            clusterResponse.setManagedState(cluster.getManagedState().toString());
-        }
+        clusterResponse.setHypervisorType(cluster.getHypervisorType().toString());
+        clusterResponse.setClusterType(cluster.getClusterType().toString());
+        clusterResponse.setAllocationState(cluster.getAllocationState().toString());
+        clusterResponse.setManagedState(cluster.getManagedState().toString());
 
 
         if (showCapacities != null && showCapacities) {
@@ -1439,12 +1395,9 @@ public class ApiResponseHelper implements ResponseGenerator {
             }
         }
         FirewallRule.State state = fwRule.getState();
-        if (state != null) {
-            String stateToSet = state.toString();
-            if (state.equals(FirewallRule.State.Revoke)) {
-                stateToSet = "Deleting";
-            }
-            response.setState(stateToSet);
+        String stateToSet = state.toString();
+        if (state.equals(FirewallRule.State.Revoke)) {
+            stateToSet = "Deleting";
         }
 
         //set tag information
@@ -1455,6 +1408,8 @@ public class ApiResponseHelper implements ResponseGenerator {
             tagResponses.add(tagResponse);
         }
         response.setTags(tagResponses);
+
+        response.setState(stateToSet);
         response.setObjectName("portforwardingrule");
         return response;
     }
@@ -1482,17 +1437,15 @@ public class ApiResponseHelper implements ResponseGenerator {
             }
         }
         FirewallRule.State state = fwRule.getState();
-        if (state != null) {
-            String stateToSet = state.toString();
-            if (state.equals(FirewallRule.State.Revoke)) {
-                stateToSet = "Deleting";
-            }
-            response.setState(stateToSet);
+        String stateToSet = state.toString();
+        if (state.equals(FirewallRule.State.Revoke)) {
+            stateToSet = "Deleting";
         }
 
         response.setStartPort(fwRule.getSourcePortStart());
         response.setEndPort(fwRule.getSourcePortEnd());
         response.setProtocol(fwRule.getProtocol());
+        response.setState(stateToSet);
         response.setObjectName("ipforwardingrule");
         return response;
     }
@@ -1528,9 +1481,7 @@ public class ApiResponseHelper implements ResponseGenerator {
             // SystemVm vm = (SystemVm) systemVM;
             vmResponse.setId(vm.getUuid());
             vmResponse.setObjectId(vm.getId());
-            if (vm.getType() != null) {
-                vmResponse.setSystemVmType(vm.getType().toString().toLowerCase());
-            }
+            vmResponse.setSystemVmType(vm.getType().toString().toLowerCase());
 
             vmResponse.setName(vm.getHostName());
             if ( vm.getPodIdToDeployIn() != null ){
@@ -1656,9 +1607,7 @@ public class ApiResponseHelper implements ResponseGenerator {
 
         populateOwner(vpnResponse, vpn);
 
-        if (vpn.getState() != null) {
-            vpnResponse.setState(vpn.getState().toString());
-        }
+        vpnResponse.setState(vpn.getState().toString());
         vpnResponse.setObjectName("remoteaccessvpn");
 
         return vpnResponse;
@@ -1684,13 +1633,7 @@ public class ApiResponseHelper implements ResponseGenerator {
         if (result.getFormat() == ImageFormat.ISO) { // Templates are always bootable
             response.setBootable(result.isBootable());
         } else {
-            if (result.getHypervisorType() != null) {
-                response.setHypervisor(result.getHypervisorType().toString());// hypervisors
-                                                                              // are
-                                                                              // associated
-                                                                              // with
-                                                                              // templates
-            }
+            response.setHypervisor(result.getHypervisorType().toString());// hypervisors
are associated with templates
         }
 
         // add account ID and name
@@ -1762,9 +1705,7 @@ public class ApiResponseHelper implements ResponseGenerator {
             templateResponse.setTemplateType(template.getTemplateType().toString());
         }
 
-        if (template.getHypervisorType() != null) {
-            templateResponse.setHypervisor(template.getHypervisorType().toString());
-        }
+        templateResponse.setHypervisor(template.getHypervisorType().toString());
 
         GuestOS os = ApiDBUtils.findGuestOSById(template.getGuestOSId());
         if (os != null) {
@@ -1844,9 +1785,7 @@ public class ApiResponseHelper implements ResponseGenerator {
             templateResponse.setTemplateType(template.getTemplateType().toString());
         }
 
-        if (template.getHypervisorType() != null) {
-            templateResponse.setHypervisor(template.getHypervisorType().toString());
-        }
+        templateResponse.setHypervisor(template.getHypervisorType().toString());
         templateResponse.setDetails(template.getDetails());
 
         GuestOS os = ApiDBUtils.findGuestOSById(template.getGuestOSId());
@@ -2158,9 +2097,7 @@ public class ApiResponseHelper implements ResponseGenerator {
         }
         response.setMode(mode);
         response.setUploadId(uploadId);
-        if (uploadInfo.getUploadState() != null) {
-            response.setState(uploadInfo.getUploadState().toString());
-        }
+        response.setState(uploadInfo.getUploadState().toString());
         response.setAccountId(accountId);
         response.setUrl(uploadInfo.getUploadUrl());
         return response;
@@ -2190,9 +2127,7 @@ public class ApiResponseHelper implements ResponseGenerator {
         jobResponse.setJobProcStatus(job.getProcessStatus());
 
         if (job.getInstanceType() != null && job.getInstanceId() != null) {
-            if (job.getInstanceType() != null) {
-                jobResponse.setJobInstanceType(job.getInstanceType().toString());
-            }
+            jobResponse.setJobInstanceType(job.getInstanceType().toString());
             String jobInstanceId = null;
             if (job.getInstanceType() == AsyncJob.Type.Volume) {
                 VolumeVO volume = ApiDBUtils.findVolumeById(job.getInstanceId());
@@ -2512,6 +2447,7 @@ public class ApiResponseHelper implements ResponseGenerator {
             capacityResponse.setCapacityType(summedCapacity.getCapacityType());
             capacityResponse.setCapacityUsed(summedCapacity.getUsedCapacity());
             if (summedCapacity.getPodId() != null) {
+                capacityResponse.setPodId(ApiDBUtils.findPodById(summedCapacity.getPodId()).getUuid());
                 HostPodVO pod = ApiDBUtils.findPodById(summedCapacity.getPodId());
                 if (pod != null) {
                     capacityResponse.setPodId(pod.getUuid());
@@ -2679,16 +2615,12 @@ public class ApiResponseHelper implements ResponseGenerator {
         response.setName(offering.getName());
         response.setDisplayText(offering.getDisplayText());
         response.setTags(offering.getTags());
-        if (offering.getTrafficType() != null) {
-            response.setTrafficType(offering.getTrafficType().toString());
-        }
+        response.setTrafficType(offering.getTrafficType().toString());
         response.setIsDefault(offering.isDefault());
         response.setSpecifyVlan(offering.getSpecifyVlan());
         response.setConserveMode(offering.isConserveMode());
         response.setSpecifyIpRanges(offering.getSpecifyIpRanges());
-        if (offering.getAvailability() != null) {
-            response.setAvailability(offering.getAvailability().toString());
-        }
+        response.setAvailability(offering.getAvailability().toString());
         response.setNetworkRate(ApiDBUtils.getNetworkRate(offering.getId()));
         Long so = null;
         if (offering.getServiceOfferingId() != null) {
@@ -2832,17 +2764,13 @@ public class ApiResponseHelper implements ResponseGenerator {
             response.setNetworkOfferingName(networkOffering.getName());
             response.setNetworkOfferingDisplayText(networkOffering.getDisplayText());
             response.setIsSystem(networkOffering.isSystemOnly());
-            if (networkOffering.getAvailability() != null) {
-                response.setNetworkOfferingAvailability(networkOffering.getAvailability().toString());
-            }
+            response.setNetworkOfferingAvailability(networkOffering.getAvailability().toString());
         }
 
         if (network.getAclType() != null) {
             response.setAclType(network.getAclType().toString());
         }
-        if (network.getState() != null) {
-            response.setState(network.getState().toString());
-        }
+        response.setState(network.getState().toString());
         response.setRestartRequired(network.isRestartRequired());
         NetworkVO nw = ApiDBUtils.findNetworkById(network.getRelated());
         if (nw != null) {
@@ -2973,12 +2901,9 @@ public class ApiResponseHelper implements ResponseGenerator {
         response.setPublicIpAddress(ip.getAddress().addr());
 
         FirewallRule.State state = fwRule.getState();
-        if (state != null) {
-            String stateToSet = state.toString();
-            if (state.equals(FirewallRule.State.Revoke)) {
-                stateToSet = "Deleting";
-            }
-            response.setState(stateToSet);
+        String stateToSet = state.toString();
+        if (state.equals(FirewallRule.State.Revoke)) {
+            stateToSet = "Deleting";
         }
 
         response.setIcmpCode(fwRule.getIcmpCode());
@@ -2993,6 +2918,7 @@ public class ApiResponseHelper implements ResponseGenerator {
         }
         response.setTags(tagResponses);
 
+        response.setState(stateToSet);
         response.setObjectName("firewallrule");
         return response;
     }
@@ -3014,23 +2940,18 @@ public class ApiResponseHelper implements ResponseGenerator {
         List<String> cidrs = ApiDBUtils.findFirewallSourceCidrs(networkACL.getId());
         response.setCidrList(StringUtils.join(cidrs, ","));
 
-        if (networkACL.getTrafficType() != null) {
-            response.setTrafficType(networkACL.getTrafficType().toString());
-        }
+        response.setTrafficType(networkACL.getTrafficType().toString());
 
         FirewallRule.State state = networkACL.getState();
-        if (state != null) {
-            String stateToSet = state.toString();
-            if (state.equals(FirewallRule.State.Revoke)) {
-                stateToSet = "Deleting";
-            }
-            response.setState(stateToSet);
+        String stateToSet = state.toString();
+        if (state.equals(FirewallRule.State.Revoke)) {
+            stateToSet = "Deleting";
         }
 
         response.setIcmpCode(networkACL.getIcmpCode());
         response.setIcmpType(networkACL.getIcmpType());
 
-
+        response.setState(stateToSet);
 
         //set tag information
         List<? extends ResourceTag> tags = ApiDBUtils.listByResourceTypeAndId(TaggedResourceType.NetworkACL,
networkACL.getId());
@@ -3129,9 +3050,7 @@ public class ApiResponseHelper implements ResponseGenerator {
     public SystemVmInstanceResponse createSystemVmInstanceResponse(VirtualMachine vm) {
         SystemVmInstanceResponse vmResponse = new SystemVmInstanceResponse();
         vmResponse.setId(vm.getUuid());
-        if (vm.getType() != null) {
-            vmResponse.setSystemVmType(vm.getType().toString().toLowerCase());
-        }
+        vmResponse.setSystemVmType(vm.getType().toString().toLowerCase());
         vmResponse.setName(vm.getHostName());
         if (vm.getHostId() != null) {
             Host host = ApiDBUtils.findHostById(vm.getHostId());
@@ -3247,9 +3166,7 @@ public class ApiResponseHelper implements ResponseGenerator {
         if (dnw != null) {
             response.setDestinationPhysicalNetworkId(dnw.getUuid());
         }
-        if (result.getState() != null) {
-            response.setState(result.getState().toString());
-        }
+        response.setState(result.getState().toString());
 
         // set enabled services
         List<String> services = new ArrayList<String>();
@@ -3273,6 +3190,7 @@ public class ApiResponseHelper implements ResponseGenerator {
         if (result.getTrafficType() != null) {
             response.setTrafficType(result.getTrafficType().toString());
         }
+
         response.setXenLabel(result.getXenNetworkLabel());
         response.setKvmLabel(result.getKvmNetworkLabel());
         response.setVmwareLabel(result.getVmwareNetworkLabel());
@@ -3522,9 +3440,7 @@ public class ApiResponseHelper implements ResponseGenerator {
 
         populateAccount(response, result.getAccountId());
         populateDomain(response, result.getDomainId());
-        if (result.getState() != null) {
-            response.setState(result.getState().toString());
-        }
+        response.setState(result.getState().toString());
 
         response.setObjectName("privategateway");
 
@@ -3536,9 +3452,7 @@ public class ApiResponseHelper implements ResponseGenerator {
     public CounterResponse createCounterResponse(Counter counter) {
         CounterResponse response = new CounterResponse();
         response.setId(counter.getUuid());
-        if (counter.getSource() != null) {
-            response.setSource(counter.getSource().toString());
-        }
+        response.setSource(counter.getSource().toString());
         response.setName(counter.getName());
         response.setValue(counter.getValue());
         response.setObjectName("counter");
@@ -3552,9 +3466,7 @@ public class ApiResponseHelper implements ResponseGenerator {
         List<CounterResponse> counterResponseList = new ArrayList<CounterResponse>();
         counterResponseList.add(createCounterResponse(ApiDBUtils.getCounter(condition.getCounterid())));
         response.setCounterResponse(counterResponseList);
-        if (condition.getRelationalOperator() != null) {
-            response.setRelationalOperator(condition.getRelationalOperator().toString());
-        }
+        response.setRelationalOperator(condition.getRelationalOperator().toString());
         response.setThreshold(condition.getThreshold());
         response.setObjectName("condition");
         populateOwner(response, condition);
@@ -3669,13 +3581,11 @@ public class ApiResponseHelper implements ResponseGenerator {
         response.setCidr(result.getCidr());
 
         StaticRoute.State state = result.getState();
-        if (state != null) {
-            String stateToSet = state.toString();
-            if (state.equals(FirewallRule.State.Revoke)) {
-                stateToSet = "Deleting";
-            }
-            response.setState(stateToSet);
+        String stateToSet = state.toString();
+        if (state.equals(FirewallRule.State.Revoke)) {
+            stateToSet = "Deleting";
         }
+        response.setState(stateToSet);
         populateAccount(response, result.getAccountId());
         populateDomain(response, result.getDomainId());
 
@@ -3696,10 +3606,7 @@ public class ApiResponseHelper implements ResponseGenerator {
     public Site2SiteVpnGatewayResponse createSite2SiteVpnGatewayResponse(Site2SiteVpnGateway
result) {
         Site2SiteVpnGatewayResponse response = new Site2SiteVpnGatewayResponse();
         response.setId(result.getUuid());
-        IpAddress ip = ApiDBUtils.findIpAddressById(result.getAddrId());
-        if (ip != null && ip.getAddress() != null) {
-            response.setIp(ip.getAddress().toString());
-        }
+        response.setIp(ApiDBUtils.findIpAddressById(result.getAddrId()).getAddress().toString());
         Vpc vpc = ApiDBUtils.findVpcById(result.getVpcId());
         if (vpc != null) {
             response.setVpcId(result.getUuid());


Mime
View raw message