CLOUDSTACK-9245 - Formatting NetworkACLServiceImpl class
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/1571e019 Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/1571e019 Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/1571e019 Branch: refs/heads/4.7 Commit: 1571e01994a7d459aa1b123d90cc1418e0ab2037 Parents: 84e89a5 Author: Wilder Rodrigues <wrodrig...@schubergphilis.com> Authored: Thu Jan 21 15:52:53 2016 +0100 Committer: Wilder Rodrigues <wrodrig...@schubergphilis.com> Committed: Fri Jan 22 10:03:14 2016 +0100 ---------------------------------------------------------------------- .../network/vpc/NetworkACLServiceImpl.java | 250 +++++++++---------- 1 file changed, 125 insertions(+), 125 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/1571e019/server/src/com/cloud/network/vpc/NetworkACLServiceImpl.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/network/vpc/NetworkACLServiceImpl.java b/server/src/com/cloud/network/vpc/NetworkACLServiceImpl.java index 60f5d7b..f308b1d 100644 --- a/server/src/com/cloud/network/vpc/NetworkACLServiceImpl.java +++ b/server/src/com/cloud/network/vpc/NetworkACLServiceImpl.java @@ -22,16 +22,15 @@ import java.util.Map; import javax.inject.Inject; -import org.apache.commons.lang.StringUtils; -import org.apache.log4j.Logger; -import org.springframework.stereotype.Component; - import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.api.command.user.network.CreateNetworkACLCmd; import org.apache.cloudstack.api.command.user.network.ListNetworkACLListsCmd; import org.apache.cloudstack.api.command.user.network.ListNetworkACLsCmd; import org.apache.cloudstack.context.CallContext; +import org.apache.commons.lang.StringUtils; +import org.apache.log4j.Logger; +import org.springframework.stereotype.Component; import com.cloud.event.ActionEvent; import com.cloud.event.EventTypes; @@ -95,9 +94,9 @@ public class NetworkACLServiceImpl extends ManagerBase implements NetworkACLServ VpcService _vpcSvc; @Override - public NetworkACL createNetworkACL(String name, String description, long vpcId, Boolean forDisplay) { - Account caller = CallContext.current().getCallingAccount(); - Vpc vpc = _entityMgr.findById(Vpc.class, vpcId); + public NetworkACL createNetworkACL(final String name, final String description, final long vpcId, final Boolean forDisplay) { + final Account caller = CallContext.current().getCallingAccount(); + final Vpc vpc = _entityMgr.findById(Vpc.class, vpcId); if (vpc == null) { throw new InvalidParameterValueException("Unable to find VPC"); } @@ -107,37 +106,37 @@ public class NetworkACLServiceImpl extends ManagerBase implements NetworkACLServ @Override @ActionEvent(eventType = EventTypes.EVENT_NETWORK_ACL_CREATE, eventDescription = "creating network acl list", async = true) - public NetworkACL getNetworkACL(long id) { + public NetworkACL getNetworkACL(final long id) { return _networkAclMgr.getNetworkACL(id); } @Override - public Pair<List<? extends NetworkACL>, Integer> listNetworkACLs(ListNetworkACLListsCmd cmd) { - Long id = cmd.getId(); - String name = cmd.getName(); - Long networkId = cmd.getNetworkId(); - Long vpcId = cmd.getVpcId(); - String keyword = cmd.getKeyword(); - Boolean display = cmd.getDisplay(); - - SearchBuilder<NetworkACLVO> sb = _networkACLDao.createSearchBuilder(); + public Pair<List<? extends NetworkACL>, Integer> listNetworkACLs(final ListNetworkACLListsCmd cmd) { + final Long id = cmd.getId(); + final String name = cmd.getName(); + final Long networkId = cmd.getNetworkId(); + final Long vpcId = cmd.getVpcId(); + final String keyword = cmd.getKeyword(); + final Boolean display = cmd.getDisplay(); + + final SearchBuilder<NetworkACLVO> sb = _networkACLDao.createSearchBuilder(); sb.and("id", sb.entity().getId(), Op.EQ); sb.and("name", sb.entity().getName(), Op.EQ); sb.and("vpcId", sb.entity().getVpcId(), Op.IN); sb.and("display", sb.entity().isDisplay(), Op.EQ); - Account caller = CallContext.current().getCallingAccount(); + final Account caller = CallContext.current().getCallingAccount(); if (networkId != null) { - SearchBuilder<NetworkVO> network = _networkDao.createSearchBuilder(); + final SearchBuilder<NetworkVO> network = _networkDao.createSearchBuilder(); network.and("networkId", network.entity().getId(), Op.EQ); sb.join("networkJoin", network, sb.entity().getId(), network.entity().getNetworkACLId(), JoinBuilder.JoinType.INNER); } - SearchCriteria<NetworkACLVO> sc = sb.create(); + final SearchCriteria<NetworkACLVO> sc = sb.create(); if (keyword != null) { - SearchCriteria<NetworkACLVO> ssc = _networkACLDao.createSearchCriteria(); + final SearchCriteria<NetworkACLVO> ssc = _networkACLDao.createSearchCriteria(); ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%"); ssc.addOr("description", SearchCriteria.Op.LIKE, "%" + keyword + "%"); sc.addAnd("name", SearchCriteria.Op.SC, ssc); @@ -156,7 +155,7 @@ public class NetworkACLServiceImpl extends ManagerBase implements NetworkACLServ } if (vpcId != null) { - Vpc vpc = _entityMgr.findById(Vpc.class, vpcId); + final Vpc vpc = _entityMgr.findById(Vpc.class, vpcId); if (vpc == null) { throw new InvalidParameterValueException("Unable to find VPC"); } @@ -168,26 +167,26 @@ public class NetworkACLServiceImpl extends ManagerBase implements NetworkACLServ // VpcId is not specified. Find permitted VPCs for the caller // and list ACLs belonging to the permitted VPCs - List<Long> permittedAccounts = new ArrayList<Long>(); + final List<Long> permittedAccounts = new ArrayList<Long>(); Long domainId = cmd.getDomainId(); boolean isRecursive = cmd.isRecursive(); - String accountName = cmd.getAccountName(); - Long projectId = cmd.getProjectId(); - boolean listAll = cmd.listAll(); - Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject = new Ternary<Long, Boolean, + final String accountName = cmd.getAccountName(); + final Long projectId = cmd.getProjectId(); + final boolean listAll = cmd.listAll(); + final Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject = new Ternary<Long, Boolean, ListProjectResourcesCriteria>(domainId, isRecursive, null); _accountMgr.buildACLSearchParameters(caller, id, accountName, projectId, permittedAccounts, domainIdRecursiveListProject, listAll, false); domainId = domainIdRecursiveListProject.first(); isRecursive = domainIdRecursiveListProject.second(); - ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject.third(); - SearchBuilder<VpcVO> sbVpc = _vpcDao.createSearchBuilder(); + final ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject.third(); + final SearchBuilder<VpcVO> sbVpc = _vpcDao.createSearchBuilder(); _accountMgr.buildACLSearchBuilder(sbVpc, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria); - SearchCriteria<VpcVO> scVpc = sbVpc.create(); + final SearchCriteria<VpcVO> scVpc = sbVpc.create(); _accountMgr.buildACLSearchCriteria(scVpc, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria); - List<VpcVO> vpcs = _vpcDao.search(scVpc, null); - List<Long> vpcIds = new ArrayList<Long>(); - for (VpcVO vpc : vpcs) { + final List<VpcVO> vpcs = _vpcDao.search(scVpc, null); + final List<Long> vpcIds = new ArrayList<Long>(); + for (final VpcVO vpc : vpcs) { vpcIds.add(vpc.getId()); } //Add vpc_id 0 to list default ACLs @@ -199,16 +198,16 @@ public class NetworkACLServiceImpl extends ManagerBase implements NetworkACLServ sc.setJoinParameters("networkJoin", "networkId", networkId); } - Filter filter = new Filter(NetworkACLVO.class, "id", false, null, null); - Pair<List<NetworkACLVO>, Integer> acls = _networkACLDao.searchAndCount(sc, filter); + final Filter filter = new Filter(NetworkACLVO.class, "id", false, null, null); + final Pair<List<NetworkACLVO>, Integer> acls = _networkACLDao.searchAndCount(sc, filter); return new Pair<List<? extends NetworkACL>, Integer>(acls.first(), acls.second()); } @Override @ActionEvent(eventType = EventTypes.EVENT_NETWORK_ACL_DELETE, eventDescription = "Deleting Network ACL List", async = true) - public boolean deleteNetworkACL(long id) { - Account caller = CallContext.current().getCallingAccount(); - NetworkACL acl = _networkACLDao.findById(id); + public boolean deleteNetworkACL(final long id) { + final Account caller = CallContext.current().getCallingAccount(); + final NetworkACL acl = _networkACLDao.findById(id); if (acl == null) { throw new InvalidParameterValueException("Unable to find specified ACL"); } @@ -218,7 +217,7 @@ public class NetworkACLServiceImpl extends ManagerBase implements NetworkACLServ throw new InvalidParameterValueException("Default ACL cannot be removed"); } - Vpc vpc = _entityMgr.findById(Vpc.class, acl.getVpcId()); + final Vpc vpc = _entityMgr.findById(Vpc.class, acl.getVpcId()); if (vpc == null) { throw new InvalidParameterValueException("Unable to find specified VPC associated with the ACL"); } @@ -227,19 +226,19 @@ public class NetworkACLServiceImpl extends ManagerBase implements NetworkACLServ } @Override - public boolean replaceNetworkACLonPrivateGw(long aclId, long privateGatewayId) throws ResourceUnavailableException { - Account caller = CallContext.current().getCallingAccount(); - VpcGateway gateway = _vpcGatewayDao.findById(privateGatewayId); + public boolean replaceNetworkACLonPrivateGw(final long aclId, final long privateGatewayId) throws ResourceUnavailableException { + final Account caller = CallContext.current().getCallingAccount(); + final VpcGateway gateway = _vpcGatewayDao.findById(privateGatewayId); if (gateway == null) { throw new InvalidParameterValueException("Unable to find specified private gateway"); } - VpcGatewayVO vo = _vpcGatewayDao.findById(privateGatewayId); + final VpcGatewayVO vo = _vpcGatewayDao.findById(privateGatewayId); if (vo.getState() != VpcGateway.State.Ready) { throw new InvalidParameterValueException("Gateway is not in Ready state"); } - NetworkACL acl = _networkACLDao.findById(aclId); + final NetworkACL acl = _networkACLDao.findById(aclId); if (acl == null) { throw new InvalidParameterValueException("Unable to find specified NetworkACL"); } @@ -249,7 +248,7 @@ public class NetworkACLServiceImpl extends ManagerBase implements NetworkACLServ } if (aclId != NetworkACL.DEFAULT_DENY && aclId != NetworkACL.DEFAULT_ALLOW) { - Vpc vpc = _entityMgr.findById(Vpc.class, acl.getVpcId()); + final Vpc vpc = _entityMgr.findById(Vpc.class, acl.getVpcId()); if (vpc == null) { throw new InvalidParameterValueException("Unable to find Vpc associated with the NetworkACL"); } @@ -259,7 +258,7 @@ public class NetworkACLServiceImpl extends ManagerBase implements NetworkACLServ } } - PrivateGateway privateGateway = _vpcSvc.getVpcPrivateGateway(gateway.getId()); + final PrivateGateway privateGateway = _vpcSvc.getVpcPrivateGateway(gateway.getId()); _accountMgr.checkAccess(caller, null, true, privateGateway); return _networkAclMgr.replaceNetworkACLForPrivateGw(acl, privateGateway); @@ -267,15 +266,15 @@ public class NetworkACLServiceImpl extends ManagerBase implements NetworkACLServ } @Override - public boolean replaceNetworkACL(long aclId, long networkId) throws ResourceUnavailableException { - Account caller = CallContext.current().getCallingAccount(); + public boolean replaceNetworkACL(final long aclId, final long networkId) throws ResourceUnavailableException { + final Account caller = CallContext.current().getCallingAccount(); - NetworkVO network = _networkDao.findById(networkId); + final NetworkVO network = _networkDao.findById(networkId); if (network == null) { throw new InvalidParameterValueException("Unable to find specified Network"); } - NetworkACL acl = _networkACLDao.findById(aclId); + final NetworkACL acl = _networkACLDao.findById(aclId); if (acl == null) { throw new InvalidParameterValueException("Unable to find specified NetworkACL"); } @@ -291,7 +290,7 @@ public class NetworkACLServiceImpl extends ManagerBase implements NetworkACLServ if (aclId != NetworkACL.DEFAULT_DENY && aclId != NetworkACL.DEFAULT_ALLOW) { //ACL is not default DENY/ALLOW // ACL should be associated with a VPC - Vpc vpc = _entityMgr.findById(Vpc.class, acl.getVpcId()); + final Vpc vpc = _entityMgr.findById(Vpc.class, acl.getVpcId()); if (vpc == null) { throw new InvalidParameterValueException("Unable to find Vpc associated with the NetworkACL"); } @@ -306,15 +305,15 @@ public class NetworkACLServiceImpl extends ManagerBase implements NetworkACLServ } @Override - public NetworkACLItem createNetworkACLItem(CreateNetworkACLCmd aclItemCmd) { - Account caller = CallContext.current().getCallingAccount(); + public NetworkACLItem createNetworkACLItem(final CreateNetworkACLCmd aclItemCmd) { + final Account caller = CallContext.current().getCallingAccount(); Long aclId = aclItemCmd.getACLId(); if (aclId == null) { //ACL id is not specified. Get the ACL details from network if (aclItemCmd.getNetworkId() == null) { throw new InvalidParameterValueException("Cannot create Network ACL Item. ACL Id or network Id is required"); } - Network network = _networkMgr.getNetwork(aclItemCmd.getNetworkId()); + final Network network = _networkMgr.getNetwork(aclItemCmd.getNetworkId()); if (network.getVpcId() == null) { throw new InvalidParameterValueException("Network: " + network.getUuid() + " does not belong to VPC"); } @@ -329,15 +328,15 @@ public class NetworkACLServiceImpl extends ManagerBase implements NetworkACLServ throw new InvalidParameterValueException("Network Offering does not support NetworkACL service"); } - Vpc vpc = _entityMgr.findById(Vpc.class, network.getVpcId()); + final Vpc vpc = _entityMgr.findById(Vpc.class, network.getVpcId()); if (vpc == null) { throw new InvalidParameterValueException("Unable to find Vpc associated with the Network"); } //Create new ACL - String aclName = "VPC_" + vpc.getName() + "_Tier_" + network.getName() + "_ACL_" + network.getUuid(); - String description = "ACL for " + aclName; - NetworkACL acl = _networkAclMgr.createNetworkACL(aclName, description, network.getVpcId(), aclItemCmd.getDisplay()); + final String aclName = "VPC_" + vpc.getName() + "_Tier_" + network.getName() + "_ACL_" + network.getUuid(); + final String description = "ACL for " + aclName; + final NetworkACL acl = _networkAclMgr.createNetworkACL(aclName, description, network.getVpcId(), aclItemCmd.getDisplay()); if (acl == null) { throw new CloudRuntimeException("Error while create ACL before adding ACL Item for network " + network.getId()); } @@ -349,22 +348,22 @@ public class NetworkACLServiceImpl extends ManagerBase implements NetworkACLServ throw new CloudRuntimeException("Unable to apply auto created ACL to network " + network.getId()); } s_logger.debug("Created ACL is applied to network " + network.getId()); - } catch (ResourceUnavailableException e) { + } catch (final ResourceUnavailableException e) { throw new CloudRuntimeException("Unable to apply auto created ACL to network " + network.getId(), e); } } } - NetworkACL acl = _networkAclMgr.getNetworkACL(aclId); + final NetworkACL acl = _networkAclMgr.getNetworkACL(aclId); if (acl == null) { throw new InvalidParameterValueException("Unable to find specified ACL"); } - if ((aclId == NetworkACL.DEFAULT_DENY) || (aclId == NetworkACL.DEFAULT_ALLOW)) { + if (aclId == NetworkACL.DEFAULT_DENY || aclId == NetworkACL.DEFAULT_ALLOW) { throw new InvalidParameterValueException("Default ACL cannot be modified"); } - Vpc vpc = _entityMgr.findById(Vpc.class, acl.getVpcId()); + final Vpc vpc = _entityMgr.findById(Vpc.class, acl.getVpcId()); if (vpc == null) { throw new InvalidParameterValueException("Unable to find Vpc associated with the NetworkACL"); } @@ -378,15 +377,15 @@ public class NetworkACLServiceImpl extends ManagerBase implements NetworkACLServ } validateNetworkACLItem(aclItemCmd.getSourcePortStart(), aclItemCmd.getSourcePortEnd(), aclItemCmd.getSourceCidrList(), aclItemCmd.getProtocol(), - aclItemCmd.getIcmpCode(), aclItemCmd.getIcmpType(), aclItemCmd.getAction(), aclItemCmd.getNumber()); + aclItemCmd.getIcmpCode(), aclItemCmd.getIcmpType(), aclItemCmd.getAction(), aclItemCmd.getNumber()); return _networkAclMgr.createNetworkACLItem(aclItemCmd.getSourcePortStart(), aclItemCmd.getSourcePortEnd(), aclItemCmd.getProtocol(), - aclItemCmd.getSourceCidrList(), aclItemCmd.getIcmpCode(), aclItemCmd.getIcmpType(), aclItemCmd.getTrafficType(), aclId, aclItemCmd.getAction(), - aclItemCmd.getNumber(), aclItemCmd.getDisplay()); + aclItemCmd.getSourceCidrList(), aclItemCmd.getIcmpCode(), aclItemCmd.getIcmpType(), aclItemCmd.getTrafficType(), aclId, aclItemCmd.getAction(), + aclItemCmd.getNumber(), aclItemCmd.getDisplay()); } - private void validateNetworkACLItem(Integer portStart, Integer portEnd, List<String> sourceCidrList, String protocol, Integer icmpCode, Integer icmpType, - String action, Integer number) { + private void validateNetworkACLItem(final Integer portStart, final Integer portEnd, final List<String> sourceCidrList, final String protocol, final Integer icmpCode, final Integer icmpType, + final String action, final Integer number) { if (portStart != null && !NetUtils.isValidPort(portStart)) { throw new InvalidParameterValueException("publicPort is an invalid value: " + portStart); @@ -401,11 +400,12 @@ public class NetworkACLServiceImpl extends ManagerBase implements NetworkACLServ } // start port and end port must be null for protocol = 'all' - if ((portStart != null || portEnd != null) && protocol != null && protocol.equalsIgnoreCase("all")) + if ((portStart != null || portEnd != null) && protocol != null && protocol.equalsIgnoreCase("all")) { throw new InvalidParameterValueException("start port and end port must be null if protocol = 'all'"); + } if (sourceCidrList != null) { - for (String cidr : sourceCidrList) { + for (final String cidr : sourceCidrList) { if (!NetUtils.isValidCIDR(cidr)) { throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Source cidrs formatting error " + cidr); } @@ -416,14 +416,14 @@ public class NetworkACLServiceImpl extends ManagerBase implements NetworkACLServ if (protocol != null) { //Check if protocol is a number if (StringUtils.isNumeric(protocol)) { - int protoNumber = Integer.parseInt(protocol); + final int protoNumber = Integer.parseInt(protocol); if (protoNumber < 0 || protoNumber > 255) { throw new InvalidParameterValueException("Invalid protocol number: " + protoNumber); } } else { //Protocol is not number //Check for valid protocol strings - String supportedProtocols = "tcp,udp,icmp,all"; + final String supportedProtocols = "tcp,udp,icmp,all"; if (!supportedProtocols.contains(protocol.toLowerCase())) { throw new InvalidParameterValueException("Invalid protocol: " + protocol); } @@ -447,7 +447,7 @@ public class NetworkACLServiceImpl extends ManagerBase implements NetworkACLServ if (icmpCode != null) { if (icmpCode.longValue() != -1 && !NetUtils.validateIcmpCode(icmpCode.longValue())) { throw new InvalidParameterValueException("Invalid icmp code; should belong to [0-15] range and can" - + " be defined when icmpType belongs to [0-40] range"); + + " be defined when icmpType belongs to [0-40] range"); } } } @@ -466,29 +466,29 @@ public class NetworkACLServiceImpl extends ManagerBase implements NetworkACLServ } @Override - public NetworkACLItem getNetworkACLItem(long ruleId) { + public NetworkACLItem getNetworkACLItem(final long ruleId) { return _networkAclMgr.getNetworkACLItem(ruleId); } @Override @ActionEvent(eventType = EventTypes.EVENT_NETWORK_ACL_ITEM_CREATE, eventDescription = "Applying Network ACL Item", async = true) - public boolean applyNetworkACL(long aclId) throws ResourceUnavailableException { + public boolean applyNetworkACL(final long aclId) throws ResourceUnavailableException { return _networkAclMgr.applyNetworkACL(aclId); } @Override - public Pair<List<? extends NetworkACLItem>, Integer> listNetworkACLItems(ListNetworkACLsCmd cmd) { - Long networkId = cmd.getNetworkId(); - Long id = cmd.getId(); + public Pair<List<? extends NetworkACLItem>, Integer> listNetworkACLItems(final ListNetworkACLsCmd cmd) { + final Long networkId = cmd.getNetworkId(); + final Long id = cmd.getId(); Long aclId = cmd.getAclId(); - String trafficType = cmd.getTrafficType(); - String protocol = cmd.getProtocol(); - String action = cmd.getAction(); - Map<String, String> tags = cmd.getTags(); - Account caller = CallContext.current().getCallingAccount(); + final String trafficType = cmd.getTrafficType(); + final String protocol = cmd.getProtocol(); + final String action = cmd.getAction(); + final Map<String, String> tags = cmd.getTags(); + final Account caller = CallContext.current().getCallingAccount(); - Filter filter = new Filter(NetworkACLItemVO.class, "id", false, cmd.getStartIndex(), cmd.getPageSizeVal()); - SearchBuilder<NetworkACLItemVO> sb = _networkACLItemDao.createSearchBuilder(); + final Filter filter = new Filter(NetworkACLItemVO.class, "id", false, cmd.getStartIndex(), cmd.getPageSizeVal()); + final SearchBuilder<NetworkACLItemVO> sb = _networkACLItemDao.createSearchBuilder(); sb.and("id", sb.entity().getId(), Op.EQ); sb.and("aclId", sb.entity().getAclId(), Op.EQ); @@ -497,7 +497,7 @@ public class NetworkACLServiceImpl extends ManagerBase implements NetworkACLServ sb.and("action", sb.entity().getAction(), Op.EQ); if (tags != null && !tags.isEmpty()) { - SearchBuilder<ResourceTagVO> tagSearch = _resourceTagDao.createSearchBuilder(); + final SearchBuilder<ResourceTagVO> tagSearch = _resourceTagDao.createSearchBuilder(); for (int count = 0; count < tags.size(); count++) { tagSearch.or().op("key" + String.valueOf(count), tagSearch.entity().getKey(), Op.EQ); tagSearch.and("value" + String.valueOf(count), tagSearch.entity().getValue(), Op.EQ); @@ -510,19 +510,19 @@ public class NetworkACLServiceImpl extends ManagerBase implements NetworkACLServ if (aclId == null) { //Join with network_acl table when aclId is not specified to list acl_items within permitted VPCs - SearchBuilder<NetworkACLVO> vpcSearch = _networkACLDao.createSearchBuilder(); + final SearchBuilder<NetworkACLVO> vpcSearch = _networkACLDao.createSearchBuilder(); vpcSearch.and("vpcId", vpcSearch.entity().getVpcId(), Op.IN); sb.join("vpcSearch", vpcSearch, sb.entity().getAclId(), vpcSearch.entity().getId(), JoinBuilder.JoinType.INNER); } - SearchCriteria<NetworkACLItemVO> sc = sb.create(); + final SearchCriteria<NetworkACLItemVO> sc = sb.create(); if (id != null) { sc.setParameters("id", id); } if (networkId != null) { - Network network = _networkDao.findById(networkId); + final Network network = _networkDao.findById(networkId); aclId = network.getNetworkACLId(); if( aclId == null){ // No aclId associated with the network. @@ -537,9 +537,9 @@ public class NetworkACLServiceImpl extends ManagerBase implements NetworkACLServ if (aclId != null) { // Get VPC and check access - NetworkACL acl = _networkACLDao.findById(aclId); + final NetworkACL acl = _networkACLDao.findById(aclId); if (acl.getVpcId() != 0) { - Vpc vpc = _vpcDao.findById(acl.getVpcId()); + final Vpc vpc = _vpcDao.findById(acl.getVpcId()); if (vpc == null) { throw new InvalidParameterValueException("Unable to find VPC associated with acl"); } @@ -552,26 +552,26 @@ public class NetworkACLServiceImpl extends ManagerBase implements NetworkACLServ // aclId is not specified // List permitted VPCs and filter aclItems - List<Long> permittedAccounts = new ArrayList<Long>(); + final List<Long> permittedAccounts = new ArrayList<Long>(); Long domainId = cmd.getDomainId(); boolean isRecursive = cmd.isRecursive(); - String accountName = cmd.getAccountName(); - Long projectId = cmd.getProjectId(); - boolean listAll = cmd.listAll(); - Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject = new Ternary<Long, Boolean, + final String accountName = cmd.getAccountName(); + final Long projectId = cmd.getProjectId(); + final boolean listAll = cmd.listAll(); + final Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject = new Ternary<Long, Boolean, ListProjectResourcesCriteria>(domainId, isRecursive, null); _accountMgr.buildACLSearchParameters(caller, id, accountName, projectId, permittedAccounts, domainIdRecursiveListProject, listAll, false); domainId = domainIdRecursiveListProject.first(); isRecursive = domainIdRecursiveListProject.second(); - ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject.third(); - SearchBuilder<VpcVO> sbVpc = _vpcDao.createSearchBuilder(); + final ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject.third(); + final SearchBuilder<VpcVO> sbVpc = _vpcDao.createSearchBuilder(); _accountMgr.buildACLSearchBuilder(sbVpc, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria); - SearchCriteria<VpcVO> scVpc = sbVpc.create(); + final SearchCriteria<VpcVO> scVpc = sbVpc.create(); _accountMgr.buildACLSearchCriteria(scVpc, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria); - List<VpcVO> vpcs = _vpcDao.search(scVpc, null); - List<Long> vpcIds = new ArrayList<Long>(); - for (VpcVO vpc : vpcs) { + final List<VpcVO> vpcs = _vpcDao.search(scVpc, null); + final List<Long> vpcIds = new ArrayList<Long>(); + for (final VpcVO vpc : vpcs) { vpcIds.add(vpc.getId()); } //Add vpc_id 0 to list acl_items in default ACL @@ -590,16 +590,16 @@ public class NetworkACLServiceImpl extends ManagerBase implements NetworkACLServ if (tags != null && !tags.isEmpty()) { int count = 0; sc.setJoinParameters("tagSearch", "resourceType", ResourceObjectType.NetworkACL.toString()); - for (String key : tags.keySet()) { + for (final String key : tags.keySet()) { sc.setJoinParameters("tagSearch", "key" + String.valueOf(count), key); sc.setJoinParameters("tagSearch", "value" + String.valueOf(count), tags.get(key)); count++; } } - Pair<List<NetworkACLItemVO>, Integer> result = _networkACLItemDao.searchAndCount(sc, filter); - List<NetworkACLItemVO> aclItemVOs = result.first(); - for (NetworkACLItemVO item: aclItemVOs) { + final Pair<List<NetworkACLItemVO>, Integer> result = _networkACLItemDao.searchAndCount(sc, filter); + final List<NetworkACLItemVO> aclItemVOs = result.first(); + for (final NetworkACLItemVO item: aclItemVOs) { _networkACLItemDao.loadCidrs(item); } return new Pair<List<? extends NetworkACLItem>, Integer>(aclItemVOs, result.second()); @@ -607,18 +607,18 @@ public class NetworkACLServiceImpl extends ManagerBase implements NetworkACLServ @Override @ActionEvent(eventType = EventTypes.EVENT_NETWORK_ACL_ITEM_DELETE, eventDescription = "Deleting Network ACL Item", async = true) - public boolean revokeNetworkACLItem(long ruleId) { - NetworkACLItemVO aclItem = _networkACLItemDao.findById(ruleId); + public boolean revokeNetworkACLItem(final long ruleId) { + final NetworkACLItemVO aclItem = _networkACLItemDao.findById(ruleId); if(aclItem != null){ - NetworkACL acl = _networkAclMgr.getNetworkACL(aclItem.getAclId()); + final NetworkACL acl = _networkAclMgr.getNetworkACL(aclItem.getAclId()); - Vpc vpc = _entityMgr.findById(Vpc.class, acl.getVpcId()); + final Vpc vpc = _entityMgr.findById(Vpc.class, acl.getVpcId()); - if((aclItem.getAclId() == NetworkACL.DEFAULT_ALLOW) || (aclItem.getAclId() == NetworkACL.DEFAULT_DENY)){ + if(aclItem.getAclId() == NetworkACL.DEFAULT_ALLOW || aclItem.getAclId() == NetworkACL.DEFAULT_DENY){ throw new InvalidParameterValueException("ACL Items in default ACL cannot be deleted"); } - Account caller = CallContext.current().getCallingAccount(); + final Account caller = CallContext.current().getCallingAccount(); _accountMgr.checkAccess(caller, null, true, vpc); @@ -628,9 +628,9 @@ public class NetworkACLServiceImpl extends ManagerBase implements NetworkACLServ @Override @ActionEvent(eventType = EventTypes.EVENT_NETWORK_ACL_ITEM_UPDATE, eventDescription = "Updating Network ACL Item", async = true) - public NetworkACLItem updateNetworkACLItem(Long id, String protocol, List<String> sourceCidrList, NetworkACLItem.TrafficType trafficType, String action, - Integer number, Integer sourcePortStart, Integer sourcePortEnd, Integer icmpCode, Integer icmpType, String newUUID, Boolean forDisplay) throws ResourceUnavailableException { - NetworkACLItemVO aclItem = _networkACLItemDao.findById(id); + public NetworkACLItem updateNetworkACLItem(final Long id, final String protocol, final List<String> sourceCidrList, final NetworkACLItem.TrafficType trafficType, final String action, + final Integer number, final Integer sourcePortStart, final Integer sourcePortEnd, final Integer icmpCode, final Integer icmpType, final String newUUID, final Boolean forDisplay) throws ResourceUnavailableException { + final NetworkACLItemVO aclItem = _networkACLItemDao.findById(id); if (aclItem == null) { throw new InvalidParameterValueException("Unable to find ACL Item cannot be found"); } @@ -639,34 +639,34 @@ public class NetworkACLServiceImpl extends ManagerBase implements NetworkACLServ throw new InvalidParameterValueException("Default ACL Items cannot be updated"); } - NetworkACL acl = _networkAclMgr.getNetworkACL(aclItem.getAclId()); + final NetworkACL acl = _networkAclMgr.getNetworkACL(aclItem.getAclId()); - Vpc vpc = _entityMgr.findById(Vpc.class, acl.getVpcId()); + final Vpc vpc = _entityMgr.findById(Vpc.class, acl.getVpcId()); - Account caller = CallContext.current().getCallingAccount(); + final Account caller = CallContext.current().getCallingAccount(); _accountMgr.checkAccess(caller, null, true, vpc); if (number != null) { //Check if ACL Item with specified number already exists - NetworkACLItemVO aclNumber = _networkACLItemDao.findByAclAndNumber(acl.getId(), number); - if ((aclNumber != null) && (aclNumber.getId() != id)) { + final NetworkACLItemVO aclNumber = _networkACLItemDao.findByAclAndNumber(acl.getId(), number); + if (aclNumber != null && aclNumber.getId() != id) { throw new InvalidParameterValueException("ACL item with number " + number + " already exists in ACL: " + acl.getUuid()); } } - validateNetworkACLItem((sourcePortStart == null) ? aclItem.getSourcePortStart() : sourcePortStart, (sourcePortEnd == null) ? aclItem.getSourcePortEnd() - : sourcePortEnd, sourceCidrList, protocol, icmpCode, (icmpType == null) ? aclItem.getIcmpType() : icmpType, action, number); + validateNetworkACLItem(sourcePortStart == null ? aclItem.getSourcePortStart() : sourcePortStart, sourcePortEnd == null ? aclItem.getSourcePortEnd() + : sourcePortEnd, sourceCidrList, protocol, icmpCode, icmpType == null ? aclItem.getIcmpType() : icmpType, action, number); return _networkAclMgr.updateNetworkACLItem(id, protocol, sourceCidrList, trafficType, action, number, sourcePortStart, sourcePortEnd, icmpCode, icmpType, newUUID, forDisplay); } @Override @ActionEvent(eventType = EventTypes.EVENT_NETWORK_ACL_UPDATE, eventDescription = "updating network acl", async = true) - public NetworkACL updateNetworkACL(Long id, String customId, Boolean forDisplay) { - NetworkACLVO acl = _networkACLDao.findById(id); - Vpc vpc = _entityMgr.findById(Vpc.class, acl.getVpcId()); - Account caller = CallContext.current().getCallingAccount(); + public NetworkACL updateNetworkACL(final Long id, final String customId, final Boolean forDisplay) { + final NetworkACLVO acl = _networkACLDao.findById(id); + final Vpc vpc = _entityMgr.findById(Vpc.class, acl.getVpcId()); + final Account caller = CallContext.current().getCallingAccount(); _accountMgr.checkAccess(caller, null, true, vpc); if (customId != null) {