CreateFirewallController.commonClassDao = commonClassDao;
}
- public CreateFirewallController(){}
+ public CreateFirewallController(){
+ // Empty constructor
+ }
private List<String> termCollectorList;
public PolicyRestAdapter setDataToPolicyRestAdapter(PolicyRestAdapter policyData){
- String jsonBody="";
+ String jsonBody;
termCollectorList = new ArrayList <>();
tagCollectorList = new ArrayList <>();
- if(policyData.getAttributes().size() > 0){
+ if(! policyData.getAttributes().isEmpty()){
for(Object attribute : policyData.getAttributes()){
if(attribute instanceof LinkedHashMap<?, ?>){
String key = ((LinkedHashMap<?, ?>) attribute).get("key").toString();
}
}
jsonBody = constructJson(policyData);
- if (jsonBody != null && !jsonBody.equalsIgnoreCase("")) {
+ if (jsonBody != null && ! "".equalsIgnoreCase(jsonBody)) {
policyData.setJsonBody(jsonBody);
} else {
policyData.setJsonBody("{}");
}
private List<String> mapping(String expandableList) {
- String value = null;
- String desc = null;
+ String value;
+ String desc;
List <String> valueDesc= new ArrayList<>();
List<Object> prefixListData = commonClassDao.getData(PrefixList.class);
for (int i = 0; i< prefixListData.size(); i++) {
TermCollector tc1=null;
try {
//Json conversion.
- String data=null;
+ String data;
SecurityZone jpaSecurityZone;
data = entity.getConfigurationData().getConfigBody();
tc1 = mapper.readValue(data, TermCollector.class);
policyLogger.error("Exception Caused while Retriving the JSON body data" +e);
}
- Map<String, String> termTagMap=null;
+ Map<String, String> termTagMap;
if(tc1 != null){
for(int i=0;i<tc1.getFirewallRuleList().size();i++){
termTagMap = new HashMap <>();
if (("guard").equals(attributeId)){
policyAdapter.setGuard(value);
}
- if (attributeId.equals("TTLDate") && !value.contains("NA")){
+ if ("TTLDate".equals(attributeId) && !value.contains("NA")){
PolicyController controller = new PolicyController();
String newDate = controller.convertDate(value);
policyAdapter.setTtlDate(newDate);
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
JsonNode root = mapper.readTree(request.getReader());
PolicyRestAdapter policyData = mapper.readValue(root.get("policyData").toString(), PolicyRestAdapter.class);
- if(policyData.getAttributes().size() > 0){
+ if(! policyData.getAttributes().isEmpty()){
for(Object attribute : policyData.getAttributes()){
if(attribute instanceof LinkedHashMap<?, ?>){
String key = ((LinkedHashMap<?, ?>) attribute).get("key").toString();
}
}
TermList jpaTermList;
- String ruleSrcList=null;
- String ruleDestList=null;
- String ruleSrcPort=null;
- String ruleDestPort=null;
- String ruleAction=null;
- List <String> valueDesc= new ArrayList<>();
- StringBuffer displayString = new StringBuffer();
+ String ruleSrcList;
+ String ruleDestList;
+ String ruleSrcPort;
+ String ruleDestPort;
+ String ruleAction;
+ List <String> valueDesc;
+ StringBuilder displayString = new StringBuilder();
for (String id : termCollectorList) {
List<Object> tmList = commonClassDao.getDataById(TermList.class, "termName", id);
jpaTermList = (TermList) tmList.get(0);
if(srcList.startsWith(GROUP)){
AddressGroup ag;
ag= mappingAddressGroup(srcList);
- displayString.append("\n\t"+"Group has :"+ag.getPrefixList()+"\n");
- for(String groupItems:ag.getPrefixList().split(",")){
- valueDesc=mapping(groupItems);
- displayString.append("\n\t"+"Name: "+groupItems);
- if(!valueDesc.isEmpty()){
- displayString.append("\n\t"+"Description: "+valueDesc.get(1));
- displayString.append("\n\t"+"Value: "+valueDesc.get(0));
+ displayString.append("\n\t"+"Group has :"+(ag != null ? ag.getPrefixList() : "") +"\n");
+ if (ag != null) {
+ for(String groupItems:ag.getPrefixList().split(",")){
+ valueDesc=mapping(groupItems);
+ displayString.append("\n\t"+"Name: "+groupItems);
+ if(!valueDesc.isEmpty()){
+ displayString.append("\n\t"+"Description: "+valueDesc.get(1));
+ displayString.append("\n\t"+"Value: "+valueDesc.get(0));
+ }
+ displayString.append("\n");
}
- displayString.append("\n");
}
}else{
if(!srcList.equals(ANY)){
displayString.append("\n");
}
ruleDestList= jpaTermList.getDestIPList();
- if ( ruleDestList!= null && (!ruleDestList.isEmpty())&& !ruleDestList.equals("null")){
+ if ( ruleDestList!= null && (!ruleDestList.isEmpty())&& ! "null".equals(ruleDestList)){
displayString.append("Destination IP List: " + jpaTermList.getDestIPList());
displayString.append(" ; \t\n");
for(String destList:ruleDestList.split(",")){
if(destList.startsWith(GROUP)){
AddressGroup ag;
ag= mappingAddressGroup(destList);
- displayString.append("\n\t"+"Group has :"+ag.getPrefixList()+"\n");
- for(String groupItems:ag.getPrefixList().split(",")){
- valueDesc=mapping(groupItems);
- displayString.append("\n\t"+"Name: "+groupItems);
- displayString.append("\n\t"+"Description: "+valueDesc.get(1));
- displayString.append("\n\t"+"Value: "+valueDesc.get(0));
- displayString.append("\n\t");
+ displayString.append("\n\t"+"Group has :"+ (ag != null ? ag.getPrefixList() : "") +"\n");
+ if (ag != null) {
+ for(String groupItems:ag.getPrefixList().split(",")){
+ valueDesc=mapping(groupItems);
+ displayString.append("\n\t"+"Name: "+groupItems);
+ displayString.append("\n\t"+"Description: "+valueDesc.get(1));
+ displayString.append("\n\t"+"Value: "+valueDesc.get(0));
+ displayString.append("\n\t");
+ }
}
}else{
if(!destList.equals(ANY)){
}
ruleSrcPort=jpaTermList.getSrcPortList();
- if ( ruleSrcPort!= null && (!ruleSrcPort.isEmpty())&& !ruleSrcPort.equals("null")) {
+ if ( ruleSrcPort!= null && (!ruleSrcPort.isEmpty())&& !"null".equals(ruleSrcPort)) {
displayString.append("\n"+"Source Port List:"
+ ruleSrcPort);
displayString.append(" ; \t\n");
}
ruleDestPort= jpaTermList.getDestPortList();
- if (ruleDestPort != null && (!ruleDestPort.isEmpty())&& !ruleDestPort.equals("null")) {
+ if (ruleDestPort != null && (!ruleDestPort.isEmpty())&& !"null".equals(ruleDestPort)) {
displayString.append("\n"+"Destination Port List:"
+ ruleDestPort);
displayString.append(" ; \t\n");
if(destServices.startsWith(GROUP)){
GroupServiceList sg;
sg= mappingServiceGroup(destServices);
- displayString.append("\n\t"+"Service Group has :"+sg.getServiceList()+"\n");
- for(String groupItems:sg.getServiceList().split(",")){
- ServiceList sl;
- sl= mappingServiceList(groupItems);
- displayString.append("\n\t"+"Name: "+
- sl.getServiceName());
- displayString.append("\n\t"+"Description: "+
- sl.getServiceDescription());
- displayString.append("\n\t"+"Transport-Protocol: "+
- sl.getServiceTransProtocol());
- displayString.append("\n\t"+"Ports: "+
- sl.getServicePorts());
- displayString.append("\n");
+ displayString.append("\n\t"+"Service Group has :"+ (sg != null ? sg.getServiceList() : "") +"\n");
+ if (sg != null) {
+ for(String groupItems:sg.getServiceList().split(",")){
+ ServiceList sl;
+ sl= mappingServiceList(groupItems);
+ displayString.append("\n\t"+"Name: "+
+ sl.getServiceName());
+ displayString.append("\n\t"+"Description: "+
+ sl.getServiceDescription());
+ displayString.append("\n\t"+"Transport-Protocol: "+
+ sl.getServiceTransProtocol());
+ displayString.append("\n\t"+"Ports: "+
+ sl.getServicePorts());
+ displayString.append("\n");
+ }
}
}
else{
}
//ExpandableServicesList
if((srcPort_map!=null) && (destPort_map!=null)){
- String servicesCollateString = (srcPort_map.get(tl) + "," + destPort_map.get(tl));
+ String servicesCollateString = srcPort_map.get(tl) + "," + destPort_map.get(tl);
expandableServicesList.add(servicesCollateString);
}else if (srcPort_map!=null){
expandableServicesList.add(srcPort_map.get(tl));
//ExpandablePrefixIPList
if ((srcIP_map!=null) && (destIP_map!=null))
{
- String collateString = (srcIP_map.get(tl) + "," + destIP_map
- .get(tl));
+ String collateString = srcIP_map.get(tl) + "," + destIP_map
+ .get(tl);
expandablePrefixIPList.add(collateString);
}
else if(srcIP_map!=null){
Set<AddressGroupJson> addrGroupArray= new HashSet<>();
Set<AddressMembers> addrArray= new HashSet<> ();
- ServiceGroupJson targetSg= null;
- AddressGroupJson addressSg=null;
- ServiceListJson targetAny= null;
- ServiceListJson targetAnyTcp=null;
- ServiceListJson targetAnyUdp=null;
+ ServiceGroupJson targetSg;
+ AddressGroupJson addressSg;
+ ServiceListJson targetAny;
+ ServiceListJson targetAnyTcp;
+ ServiceListJson targetAnyUdp;
for(String serviceList:expandableServicesList){
for(String t: serviceList.split(",")){
- if((!t.startsWith(GROUP))){
+ if(!t.startsWith(GROUP)){
if(!t.equals(ANY)){
ServiceList sl;
targetSl= new ServiceListJson();
Set<PrefixIPList> prefixIPList = new HashSet<>();
for(String prefixList:expandablePrefixIPList){
for(String prefixIP: prefixList.split(",")){
- if((!prefixIP.startsWith(GROUP))){
+ if(!prefixIP.startsWith(GROUP)){
if(!prefixIP.equals(ANY)){
List<AddressMembers> addMembersList= new ArrayList<>();
List<String> valueDesc;