Addressing Technical Debt for POLICY-SDK-APP
[policy/engine.git] / POLICY-SDK-APP / src / main / java / org / onap / policy / controller / PolicyController.java
index 35b9b95..46510ba 100644 (file)
@@ -40,7 +40,10 @@ import javax.servlet.http.HttpServletResponse;
 import org.json.JSONObject;
 import org.onap.policy.admin.PolicyNotificationMail;
 import org.onap.policy.admin.RESTfulPAPEngine;
+import org.onap.policy.common.logging.flexlogger.FlexLogger;
+import org.onap.policy.common.logging.flexlogger.Logger;
 import org.onap.policy.model.PDPGroupContainer;
+import org.onap.policy.model.Roles;
 import org.onap.policy.rest.XACMLRestProperties;
 import org.onap.policy.rest.XacmlAdminAuthorization;
 import org.onap.policy.rest.dao.CommonClassDao;
@@ -49,10 +52,11 @@ import org.onap.policy.rest.jpa.FunctionDefinition;
 import org.onap.policy.rest.jpa.PolicyEntity;
 import org.onap.policy.rest.jpa.PolicyVersion;
 import org.onap.policy.rest.jpa.UserInfo;
-import org.openecomp.policy.model.Roles;
-import org.openecomp.portalsdk.core.controller.RestrictedBaseController;
-import org.openecomp.portalsdk.core.web.support.JsonMessage;
-import org.openecomp.portalsdk.core.web.support.UserUtils;
+import org.onap.policy.xacml.api.XACMLErrorConstants;
+import org.onap.policy.xacml.api.pap.PAPPolicyEngine;
+import org.onap.portalsdk.core.controller.RestrictedBaseController;
+import org.onap.portalsdk.core.web.support.JsonMessage;
+import org.onap.portalsdk.core.web.support.UserUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.MediaType;
 import org.springframework.stereotype.Controller;
@@ -60,15 +64,9 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.servlet.ModelAndView;
 
-import org.onap.policy.xacml.api.XACMLErrorConstants;
-import org.onap.policy.xacml.api.pap.PAPPolicyEngine;
-
 import com.att.research.xacml.util.XACMLProperties;
 import com.fasterxml.jackson.databind.ObjectMapper;
 
-import org.onap.policy.common.logging.flexlogger.FlexLogger;
-import org.onap.policy.common.logging.flexlogger.Logger;
-
 
 @Controller
 @RequestMapping("/")
@@ -145,6 +143,20 @@ public class PolicyController extends RestrictedBaseController {
        //WebApp directories
        private static String configHome;
        private static String actionHome;
+       
+       //File upload size
+       private static long fileSizeLimit;
+       
+       private static boolean jUnit = false;
+       
+
+       public static boolean isjUnit() {
+               return jUnit;
+       }
+
+       public static void setjUnit(boolean jUnit) {
+               PolicyController.jUnit = jUnit;
+       }
 
        @Autowired
        private PolicyController(CommonClassDao commonClassDao){
@@ -159,9 +171,16 @@ public class PolicyController extends RestrictedBaseController {
                Properties prop = new Properties();
                InputStream input = null;
                try {
-                       input = new FileInputStream("xacml.admin.properties");
+                       if(jUnit){
+                               File file = new File(new File(".").getCanonicalPath() + File.separator + "src"+ File.separator + "test" + File.separator + "resources" + File.separator + "JSONConfig.json");
+                               input = new FileInputStream(file);
+                       }else{
+                               input = new FileInputStream("xacml.admin.properties");
+                       }
                        // load a properties file
                        prop.load(input);
+                       //file upload size limit property
+                       setFileSizeLimit(prop.getProperty("file.size.limit"));
                        //pap url
                        setPapUrl(prop.getProperty("xacml.rest.pap.url"));
                        // get the property values
@@ -189,7 +208,12 @@ public class PolicyController extends RestrictedBaseController {
                        setAutoPushPDPGroup(prop.getProperty("xacml.autopush.pdpGroup"));
                        //Micro Service Properties
                        setMsOnapName(prop.getProperty("xacml.policy.msOnapName"));
+                       if(getMsOnapName() == null){
+                               setMsOnapName(prop.getProperty("xacml.policy.msEcompName"));
+                       }
+                       policyLogger.info("getMsOnapName => " + getMsOnapName());
                        setMsPolicyName(prop.getProperty("xacml.policy.msPolicyName"));
+                       policyLogger.info("setMsPolicyName => " + getMsPolicyName());
                        //WebApp directories
                        setConfigHome(prop.getProperty("xacml.rest.config.webapps") + "Config");
                        setActionHome(prop.getProperty("xacml.rest.config.webapps") + "Action");
@@ -321,7 +345,7 @@ public class PolicyController extends RestrictedBaseController {
        }
 
        //Policy tabs Model and View
-       @RequestMapping(value= {"/policy", "/policy/Editor" } , method = RequestMethod.GET)
+    @RequestMapping(value= {"/policy", "/policy/Editor" } , method = RequestMethod.GET)
        public ModelAndView view(HttpServletRequest request){
                String myRequestURL = request.getRequestURL().toString();
                try {
@@ -341,7 +365,7 @@ public class PolicyController extends RestrictedBaseController {
                return papEngine;
        }
 
-       public void setPapEngine(PAPPolicyEngine papEngine) {
+       public static void setPapEngine(PAPPolicyEngine papEngine) {
                PolicyController.papEngine = papEngine;
        }
 
@@ -352,7 +376,7 @@ public class PolicyController extends RestrictedBaseController {
        }
 
        public static boolean getActivePolicy(String query) {
-               if(commonClassDao.getDataByQuery(query, new SimpleBindings()).size() > 0){
+               if(!commonClassDao.getDataByQuery(query, new SimpleBindings()).isEmpty()){
                        return true;
                }else{
                        return false;
@@ -423,7 +447,7 @@ public class PolicyController extends RestrictedBaseController {
                for(Object entity : policyEntity){
                        PolicyEntity pEntity = (PolicyEntity) entity;
                        String removeExtension = pEntity.getPolicyName().replace(".xml", "");
-                       String version = removeExtension.substring(removeExtension.lastIndexOf(".")+1);
+                       String version = removeExtension.substring(removeExtension.lastIndexOf('.')+1);
                        av.add(version);
                }
                if(policyName.contains("/")){
@@ -696,4 +720,25 @@ public class PolicyController extends RestrictedBaseController {
        public static String getFile() {
                return file;
        }
+       
+       public static void setFileSizeLimit(String uploadSize) {
+               //Default size limit is 30MB
+               if (uploadSize == null || uploadSize.isEmpty()) {
+                       fileSizeLimit = 30000000;
+               }
+               else {
+                       fileSizeLimit = Long.parseLong(uploadSize);
+               }
+       }
+       
+       public static long getFileSizeLimit() {
+               return fileSizeLimit;
+       }
+       public String convertDate(String dateTTL) {
+               String formateDate = null;
+               if(dateTTL.contains("-")){
+                       formateDate = dateTTL.replace("-", "/");
+               }
+               return formateDate;
+       }
 }