*/
package org.openecomp.policy.controller;
-import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.servlet.ModelAndView;
-import com.fasterxml.jackson.core.JsonGenerationException;
import com.fasterxml.jackson.databind.DeserializationFeature;
-import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectWriter;
@Controller
@RequestMapping("/")
public class CreateFirewallController extends RestrictedBaseController {
- private static Logger logger = FlexLogger.getLogger(CreateFirewallController.class);
+ private static Logger policyLogger = FlexLogger.getLogger(CreateFirewallController.class);
@Autowired
SessionFactory sessionFactory;
public PolicyRestAdapter setDataToPolicyRestAdapter(PolicyRestAdapter policyData){
- termCollectorList = new ArrayList<String>();
- tagCollectorList = new ArrayList<String>();
- if(policyData.getAttributes().size() > 0){
+ termCollectorList = new ArrayList<>();
+ tagCollectorList = new ArrayList<>();
+ if(!policyData.getAttributes().isEmpty()){
for(Object attribute : policyData.getAttributes()){
if(attribute instanceof LinkedHashMap<?, ?>){
String key = ((LinkedHashMap<?, ?>) attribute).get("key").toString();
}
private List<String> mapping(String expandableList) {
- String value = new String();
- String desc = new String();
List <String> valueDesc= new ArrayList<>();
List<Object> prefixListData = commonClassDao.getData(PrefixList.class);
for (int i = 0; i< prefixListData.size(); i++) {
PrefixList prefixList = (PrefixList) prefixListData.get(i);
if (prefixList.getPrefixListName().equals(expandableList)) {
- value = prefixList.getPrefixListValue();
+ String value = prefixList.getPrefixListValue();
valueDesc.add(value);
- desc= prefixList.getDescription();
+ String desc= prefixList.getDescription();
valueDesc.add(desc);
break;
}
// policy name value is the policy name without any prefix and Extensions.
policyAdapter.setOldPolicyFileName(policyAdapter.getPolicyName());
String policyNameValue = policyAdapter.getPolicyName().substring(policyAdapter.getPolicyName().indexOf("FW_") +3);
- if (logger.isDebugEnabled()) {
- logger.debug("Prepopulating form data for Config Policy selected:"+ policyAdapter.getPolicyName());
+ if (policyLogger.isDebugEnabled()) {
+ policyLogger.debug("Prepopulating form data for Config Policy selected:"+ policyAdapter.getPolicyName());
}
policyAdapter.setPolicyName(policyNameValue);
String description = "";
try{
description = policy.getDescription().substring(0, policy.getDescription().indexOf("@CreatedBy:"));
}catch(Exception e){
+ policyLogger.info("General error", e);
description = policy.getDescription();
}
policyAdapter.setPolicyDescription(description);
}
}
catch(Exception e) {
- logger.error("Exception Caused while Retriving the JSON body data" +e);
+ policyLogger.error("Exception Caused while Retriving the JSON body data" +e);
}
Map<String, String> termTagMap=null;
}
@RequestMapping(value={"/policyController/ViewFWPolicyRule.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
- public ModelAndView setFWViewRule(HttpServletRequest request, HttpServletResponse response) throws Exception{
+ public void setFWViewRule(HttpServletRequest request, HttpServletResponse response){
try {
termCollectorList = new ArrayList<>();
ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
JsonNode root = mapper.readTree(request.getReader());
PolicyRestAdapter policyData = (PolicyRestAdapter)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();
}
}
}
- displayString.append("\n");
+ displayString.append("\n");
}
ruleAction=(jpaTermList).getAction();
String responseString = mapper.writeValueAsString(displayString);
JSONObject j = new JSONObject("{policyData: " + responseString + "}");
out.write(j.toString());
- return null;
} catch (Exception e) {
- logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
+ policyLogger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
}
- return null;
}
private String constructJson(PolicyRestAdapter policyData) {
PrefixIPList targetAddressList = new PrefixIPList();
AddressMembers addressMembers= new AddressMembers();
targetAddressList.setName(prefixIP);
- logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "PrefixList value:"+prefixIP);
+ policyLogger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "PrefixList value:"+prefixIP);
valueDesc = mapping(prefixIP);
if(!valueDesc.isEmpty()){
- logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "PrefixList description:"+valueDesc.get(1));
+ policyLogger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "PrefixList description:"+valueDesc.get(1));
targetAddressList.setDescription(valueDesc.get(1));
}
ObjectWriter om = new ObjectMapper().writer();
try {
json = om.writeValueAsString(tc);
- } catch (JsonGenerationException e) {
- logger.error("Exception Occured"+e);
- } catch (JsonMappingException e) {
- logger.error("Exception Occured"+e);
- } catch (IOException e) {
- logger.error("Exception Occured"+e);
+ } catch (Exception e) {
+ policyLogger.error("Exception Occured"+e);
}
}catch (Exception e) {
- logger.error("Exception Occured"+e);
+ policyLogger.error("Exception Occured"+e);
}
return json;