[Policy-17] Removed the sql scripts from sdk app
[policy/engine.git] / POLICY-SDK-APP / src / main / java / org / openecomp / policy / controller / PolicyController.java
index 42e4483..f896874 100644 (file)
@@ -72,9 +72,10 @@ import org.openecomp.policy.common.logging.flexlogger.Logger;
 @Controller
 @RequestMapping("/")
 public class PolicyController extends RestrictedBaseController {
-       private static final Logger     LOGGER  = FlexLogger.getLogger(PolicyController.class);
+       private static final Logger     policyLogger    = FlexLogger.getLogger(PolicyController.class);
 
        private static CommonClassDao commonClassDao;
+       
        // Our authorization object
        //
        XacmlAdminAuthorization authorizer = new XacmlAdminAuthorization();
@@ -83,8 +84,8 @@ public class PolicyController extends RestrictedBaseController {
        //
        private static PAPPolicyEngine papEngine;
 
-       public static String logTableLimit;
-       public static String systemAlertTableLimit;
+       private static String logTableLimit;
+       private static String systemAlertTableLimit;
        protected static Map<String, String> dropDownMap = new HashMap<>();
        public static Map<String, String> getDropDownMap() {
                return dropDownMap;
@@ -102,42 +103,47 @@ public class PolicyController extends RestrictedBaseController {
        private static Map<Datatype, List<FunctionDefinition>> mapDatatype2Function = null;
        private static Map<String, FunctionDefinition> mapID2Function = null;
 
-
+       //Constant variables used across Policy-sdk
+       private static final String policyData = "policyData";
+       private static final String characterEncoding = "UTF-8";
+       private static final String contentType = "application/json";
+       private static final String file = "file";
+       
        //Smtp Java Mail Properties
-       public static String smtpHost = null;
-       public static String smtpPort = null;
-       public static String smtpUsername = null;
-       public static String smtpPassword = null;
-       public static String smtpApplicationName = null;
-       public static String smtpEmailExtension = null;
+       private static String smtpHost = null;
+       private static String smtpPort = null;
+       private static String smtpUsername = null;
+       private static String smtpPassword = null;
+       private static String smtpApplicationName = null;
+       private static String smtpEmailExtension = null;
        //log db Properties
-       public static String logdbDriver = null;
-       public static String logdbUrl = null;
-       public static String logdbUserName = null;
-       public static String logdbPassword = null;
-       public static String logdbDialect = null;
+       private static String logdbDriver = null;
+       private static String logdbUrl = null;
+       private static String logdbUserName = null;
+       private static String logdbPassword = null;
+       private static String logdbDialect = null;
        //Xacml db properties
-       public static String xacmldbUrl = null;
-       public static String xacmldbUserName = null;
-       public static String xacmldbPassword = null;
+       private static String xacmldbUrl = null;
+       private static String xacmldbUserName = null;
+       private static String xacmldbPassword = null;
 
        //AutoPush feature. 
-       public static String autoPushAvailable;
-       public static String autoPushDSClosedLoop;
-       public static String autoPushDSFirewall;
-       public static String autoPushDSMicroservice;
-       public static String autoPushPDPGroup;
+       private static String autoPushAvailable;
+       private static String autoPushDSClosedLoop;
+       private static String autoPushDSFirewall;
+       private static String autoPushDSMicroservice;
+       private static String autoPushPDPGroup;
        
        //papURL
-       public static String papUrl;
+       private static String papUrl;
        
        //MicroService Model Properties
-       public static String msEcompName;
-       public static String msPolicyName;
+       private static String msEcompName;
+       private static String msPolicyName;
        
        //WebApp directories
-       public static String configHome;
-       public static String actionHome;
+       private static String configHome;
+       private static String actionHome;
 
        @Autowired
        private PolicyController(CommonClassDao commonClassDao){
@@ -156,54 +162,54 @@ public class PolicyController extends RestrictedBaseController {
                        // load a properties file
                        prop.load(input);
                        //pap url
-                       papUrl = prop.getProperty("xacml.rest.pap.url"); 
+                       setPapUrl(prop.getProperty("xacml.rest.pap.url")); 
                        // get the property values
-                       smtpHost = prop.getProperty("ecomp.smtp.host");
-                       smtpPort = prop.getProperty("ecomp.smtp.port");
-                       smtpUsername = prop.getProperty("ecomp.smtp.userName");
-                       smtpPassword = prop.getProperty("ecomp.smtp.password");
-                       smtpApplicationName = prop.getProperty("ecomp.application.name");
-                       smtpEmailExtension = prop.getProperty("ecomp.smtp.emailExtension");
+                       setSmtpHost(prop.getProperty("ecomp.smtp.host"));
+                       setSmtpPort(prop.getProperty("ecomp.smtp.port"));
+                       setSmtpUsername(prop.getProperty("ecomp.smtp.userName"));
+                       setSmtpPassword(prop.getProperty("ecomp.smtp.password"));
+                       setSmtpApplicationName(prop.getProperty("ecomp.application.name"));
+                       setSmtpEmailExtension(prop.getProperty("ecomp.smtp.emailExtension"));
                        //Log Database Properties
-                       logdbDriver = prop.getProperty("xacml.log.db.driver");
-                       logdbUrl = prop.getProperty("xacml.log.db.url");
-                       logdbUserName = prop.getProperty("xacml.log.db.user");
-                       logdbPassword = prop.getProperty("xacml.log.db.password");
-                       logdbDialect = prop.getProperty("ecomp.dialect");
+                       setLogdbDriver(prop.getProperty("xacml.log.db.driver"));
+                       setLogdbUrl(prop.getProperty("xacml.log.db.url"));
+                       setLogdbUserName(prop.getProperty("xacml.log.db.user"));
+                       setLogdbPassword(prop.getProperty("xacml.log.db.password"));
+                       setLogdbDialect(prop.getProperty("ecomp.dialect"));
                        //Xacml Database Properties
-                       xacmldbUrl = prop.getProperty("javax.persistence.jdbc.url");
-                       xacmldbUserName = prop.getProperty("javax.persistence.jdbc.user");
-                       xacmldbPassword = prop.getProperty("javax.persistence.jdbc.password");
+                       setXacmldbUrl(prop.getProperty("javax.persistence.jdbc.url"));
+                       setXacmldbUserName(prop.getProperty("javax.persistence.jdbc.user"));
+                       setXacmldbPassword(prop.getProperty("javax.persistence.jdbc.password"));
                        //AutoPuh
-                       autoPushAvailable=prop.getProperty("xacml.automatic.push");
-                       autoPushDSClosedLoop=prop.getProperty("xacml.autopush.closedloop");
-                       autoPushDSFirewall=prop.getProperty("xacml.autopush.firewall");
-                       autoPushDSMicroservice=prop.getProperty("xacml.autopush.microservice");
-                       autoPushPDPGroup=prop.getProperty("xacml.autopush.pdpGroup");
+                       setAutoPushAvailable(prop.getProperty("xacml.automatic.push"));
+                       setAutoPushDSClosedLoop(prop.getProperty("xacml.autopush.closedloop"));
+                       setAutoPushDSFirewall(prop.getProperty("xacml.autopush.firewall"));
+                       setAutoPushDSMicroservice(prop.getProperty("xacml.autopush.microservice"));
+                       setAutoPushPDPGroup(prop.getProperty("xacml.autopush.pdpGroup"));
                        //Micro Service Properties
-                       msEcompName=prop.getProperty("xacml.policy.msEcompName");
-                       msPolicyName=prop.getProperty("xacml.policy.msPolicyName");
+                       setMsEcompName(prop.getProperty("xacml.policy.msEcompName"));
+                       setMsPolicyName(prop.getProperty("xacml.policy.msPolicyName"));
                        //WebApp directories
-                       configHome = prop.getProperty("xacml.rest.config.webapps") + "Config";
-                       actionHome = prop.getProperty("xacml.rest.config.webapps") + "Action";
+                       setConfigHome(prop.getProperty("xacml.rest.config.webapps") + "Config");
+                       setActionHome(prop.getProperty("xacml.rest.config.webapps") + "Action");
                        //Get the Property Values for Dashboard tab Limit 
                        try{
-                               logTableLimit = prop.getProperty("xacml.ecomp.dashboard.logTableLimit");
-                               systemAlertTableLimit = prop.getProperty("xacml.ecomp.dashboard.systemAlertTableLimit");
+                               setLogTableLimit(prop.getProperty("xacml.ecomp.dashboard.logTableLimit"));
+                               setSystemAlertTableLimit(prop.getProperty("xacml.ecomp.dashboard.systemAlertTableLimit"));
                        }catch(Exception e){
-                               LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE+"Dashboard tab Property fields are missing" +e);
-                               logTableLimit = "5000";
-                               systemAlertTableLimit = "2000";
+                               policyLogger.error(XACMLErrorConstants.ERROR_DATA_ISSUE+"Dashboard tab Property fields are missing" +e);
+                               setLogTableLimit("5000");
+                               setSystemAlertTableLimit("2000");
                        }
                        System.setProperty(XACMLProperties.XACML_PROPERTIES_NAME, "xacml.admin.properties");
                } catch (IOException ex) {
-                       LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE+"Exception Occured while reading the Smtp properties from xacml.admin.properties file" +ex);
+                       policyLogger.error(XACMLErrorConstants.ERROR_DATA_ISSUE+"Exception Occured while reading the Smtp properties from xacml.admin.properties file" +ex);
                } finally {
                        if (input != null) {
                                try {
                                        input.close();
                                } catch (IOException e) {
-                                       LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE+"Exception Occured while Closing the xacml.admin.properties file" +e);
+                                       policyLogger.error(XACMLErrorConstants.ERROR_DATA_ISSUE+"Exception Occured while Closing the xacml.admin.properties file" +e);
                                }
                        }
                }
@@ -211,7 +217,7 @@ public class PolicyController extends RestrictedBaseController {
                //Initialize the FunctionDefinition table at Server Start up 
                Map<Datatype, List<FunctionDefinition>> functionMap = getFunctionDatatypeMap();
                for (Datatype id : functionMap.keySet()) {
-                       List<FunctionDefinition> functionDefinations = (List<FunctionDefinition>) functionMap.get(id);
+                       List<FunctionDefinition> functionDefinations = functionMap.get(id);
                        for (FunctionDefinition functionDef : functionDefinations) {
                                dropDownMap.put(functionDef.getShortname(),functionDef.getXacmlid());
                        }
@@ -244,7 +250,7 @@ public class PolicyController extends RestrictedBaseController {
                for (int i = 0; i < functiondefinitions.size(); i ++) {
                        FunctionDefinition value = (FunctionDefinition) functiondefinitions.get(i);
                        mapID2Function.put(value.getXacmlid(), value);
-                       if (mapDatatype2Function.containsKey(value.getDatatypeBean()) == false) {
+                       if (!mapDatatype2Function.containsKey(value.getDatatypeBean())) {
                                mapDatatype2Function.put(value.getDatatypeBean(), new ArrayList<FunctionDefinition>());
                        }
                        mapDatatype2Function.get(value.getDatatypeBean()).add(value);
@@ -262,21 +268,20 @@ public class PolicyController extends RestrictedBaseController {
                        response.getWriter().write(j.toString());
                }
                catch (Exception e){
-                       LOGGER.equals(XACMLErrorConstants.ERROR_DATA_ISSUE +"Error while retriving the Function Definition data"+e);
+                       policyLogger.error(XACMLErrorConstants.ERROR_DATA_ISSUE +"Error while retriving the Function Definition data"+e);
                }
        }
        
        public PolicyEntity getPolicyEntityData(String scope, String policyName){
                String key = scope + ":" + policyName;
                List<Object> data = commonClassDao.getDataById(PolicyEntity.class, "scope:policyName", key);
-               PolicyEntity entity = (PolicyEntity) data.get(0);
-               return entity;
+               return (PolicyEntity) data.get(0);
        }
 
        public static Map<String, Roles> getUserRoles(String userId) {
                Map<String, Roles> scopes = new HashMap<>();
                List<Object> roles = commonClassDao.getDataById(Roles.class, "loginId", userId);
-               if (roles != null && roles.size() > 0) {
+               if (roles != null && !roles.isEmpty()) {
                        for (Object role : roles) {
                                scopes.put(((Roles) role).getScope(), (Roles) role);
                        }
@@ -284,8 +289,8 @@ public class PolicyController extends RestrictedBaseController {
                return scopes;
        }
 
-       public static  List<String> getRolesOfUser(String userId) {
-               List<String> rolesList = new ArrayList<String>();
+       public List<String> getRolesOfUser(String userId) {
+               List<String> rolesList = new ArrayList<>();
                List<Object> roles = commonClassDao.getDataById(Roles.class, "loginId", userId);
                for (Object role: roles) {
                        rolesList.add(((Roles) role).getRole());
@@ -293,7 +298,7 @@ public class PolicyController extends RestrictedBaseController {
                return rolesList;
        }
 
-       public static List<Object> getRoles(String userId) {
+       public List<Object> getRoles(String userId) {
                return commonClassDao.getDataById(Roles.class, "loginId", userId);
        }
 
@@ -310,7 +315,7 @@ public class PolicyController extends RestrictedBaseController {
                        response.getWriter().write(j.toString());
                }
                catch (Exception e){
-                       LOGGER.error("Exception Occured"+e);
+                       policyLogger.error("Exception Occured"+e);
                }
        }
 
@@ -325,13 +330,13 @@ public class PolicyController extends RestrictedBaseController {
                        setPapEngine((PAPPolicyEngine) new RESTfulPAPEngine(myRequestURL));
                        new PDPGroupContainer((PAPPolicyEngine) new RESTfulPAPEngine(myRequestURL));
                } catch (Exception e) {
-                       LOGGER.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR+"Exception Occured while loading PAP"+e);
+                       policyLogger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR+"Exception Occured while loading PAP"+e);
                }       
                Map<String, Object> model = new HashMap<>();
                return new ModelAndView("policy_Editor","model", model);
        }
 
-       public static PAPPolicyEngine getPapEngine() {
+       public PAPPolicyEngine getPapEngine() {
                return papEngine;
        }
 
@@ -374,8 +379,7 @@ public class PolicyController extends RestrictedBaseController {
        }
 
        public PolicyVersion getPolicyEntityFromPolicyVersion(String query){
-               PolicyVersion policyVersionEntity = (PolicyVersion) commonClassDao.getEntityItem(PolicyVersion.class, "policyName", query);
-               return policyVersionEntity;     
+               return (PolicyVersion) commonClassDao.getEntityItem(PolicyVersion.class, "policyName", query);
        }
 
        public List<Object> getDataByQuery(String query){
@@ -394,7 +398,7 @@ public class PolicyController extends RestrictedBaseController {
                try {
                        email.sendMail(entity, policyName, mode, commonClassDao);
                } catch (MessagingException e) {
-                       LOGGER.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Excepton Occured while Renaming/Deleting a Policy or Scope" + e);
+                       policyLogger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Excepton Occured while Renaming/Deleting a Policy or Scope" + e);
                }
        }
 
@@ -428,5 +432,265 @@ public class PolicyController extends RestrictedBaseController {
                el.put("highestVersion", entity.getHigherVersion());
                return el;
        }
+
+       public static String getLogTableLimit() {
+               return logTableLimit;
+       }
+
+       public static void setLogTableLimit(String logTableLimit) {
+               PolicyController.logTableLimit = logTableLimit;
+       }
+
+       public static String getSystemAlertTableLimit() {
+               return systemAlertTableLimit;
+       }
+
+       public static void setSystemAlertTableLimit(String systemAlertTableLimit) {
+               PolicyController.systemAlertTableLimit = systemAlertTableLimit;
+       }
+       
+       public static CommonClassDao getCommonClassDao() {
+               return commonClassDao;
+       }
+
+       public static void setCommonClassDao(CommonClassDao commonClassDao) {
+               PolicyController.commonClassDao = commonClassDao;
+       }
+
+       public XacmlAdminAuthorization getAuthorizer() {
+               return authorizer;
+       }
+
+       public void setAuthorizer(XacmlAdminAuthorization authorizer) {
+               this.authorizer = authorizer;
+       }
+
+       public static Map<Datatype, List<FunctionDefinition>> getMapDatatype2Function() {
+               return mapDatatype2Function;
+       }
+
+       public static void setMapDatatype2Function(Map<Datatype, List<FunctionDefinition>> mapDatatype2Function) {
+               PolicyController.mapDatatype2Function = mapDatatype2Function;
+       }
+
+       public static Map<String, FunctionDefinition> getMapID2Function() {
+               return mapID2Function;
+       }
+
+       public static void setMapID2Function(Map<String, FunctionDefinition> mapID2Function) {
+               PolicyController.mapID2Function = mapID2Function;
+       }
+
+       public static String getSmtpHost() {
+               return smtpHost;
+       }
+
+       public static void setSmtpHost(String smtpHost) {
+               PolicyController.smtpHost = smtpHost;
+       }
+
+       public static String getSmtpPort() {
+               return smtpPort;
+       }
+
+       public static void setSmtpPort(String smtpPort) {
+               PolicyController.smtpPort = smtpPort;
+       }
+
+       public static String getSmtpUsername() {
+               return smtpUsername;
+       }
+
+       public static void setSmtpUsername(String smtpUsername) {
+               PolicyController.smtpUsername = smtpUsername;
+       }
+
+       public static String getSmtpPassword() {
+               return smtpPassword;
+       }
+
+       public static void setSmtpPassword(String smtpPassword) {
+               PolicyController.smtpPassword = smtpPassword;
+       }
+
+       public static String getSmtpApplicationName() {
+               return smtpApplicationName;
+       }
+
+       public static void setSmtpApplicationName(String smtpApplicationName) {
+               PolicyController.smtpApplicationName = smtpApplicationName;
+       }
+
+       public static String getSmtpEmailExtension() {
+               return smtpEmailExtension;
+       }
+
+       public static void setSmtpEmailExtension(String smtpEmailExtension) {
+               PolicyController.smtpEmailExtension = smtpEmailExtension;
+       }
+
+       public static String getLogdbDriver() {
+               return logdbDriver;
+       }
+
+       public static void setLogdbDriver(String logdbDriver) {
+               PolicyController.logdbDriver = logdbDriver;
+       }
+
+       public static String getLogdbUrl() {
+               return logdbUrl;
+       }
+
+       public static void setLogdbUrl(String logdbUrl) {
+               PolicyController.logdbUrl = logdbUrl;
+       }
+
+       public static String getLogdbUserName() {
+               return logdbUserName;
+       }
+
+       public static void setLogdbUserName(String logdbUserName) {
+               PolicyController.logdbUserName = logdbUserName;
+       }
+
+       public static String getLogdbPassword() {
+               return logdbPassword;
+       }
+
+       public static void setLogdbPassword(String logdbPassword) {
+               PolicyController.logdbPassword = logdbPassword;
+       }
+
+       public static String getLogdbDialect() {
+               return logdbDialect;
+       }
+
+       public static void setLogdbDialect(String logdbDialect) {
+               PolicyController.logdbDialect = logdbDialect;
+       }
+
+       public static String getXacmldbUrl() {
+               return xacmldbUrl;
+       }
+
+       public static void setXacmldbUrl(String xacmldbUrl) {
+               PolicyController.xacmldbUrl = xacmldbUrl;
+       }
+
+       public static String getXacmldbUserName() {
+               return xacmldbUserName;
+       }
+
+       public static void setXacmldbUserName(String xacmldbUserName) {
+               PolicyController.xacmldbUserName = xacmldbUserName;
+       }
+
+       public static String getXacmldbPassword() {
+               return xacmldbPassword;
+       }
+
+       public static void setXacmldbPassword(String xacmldbPassword) {
+               PolicyController.xacmldbPassword = xacmldbPassword;
+       }
+
+       public static String getAutoPushAvailable() {
+               return autoPushAvailable;
+       }
+
+       public static void setAutoPushAvailable(String autoPushAvailable) {
+               PolicyController.autoPushAvailable = autoPushAvailable;
+       }
+
+       public static String getAutoPushDSClosedLoop() {
+               return autoPushDSClosedLoop;
+       }
+
+       public static void setAutoPushDSClosedLoop(String autoPushDSClosedLoop) {
+               PolicyController.autoPushDSClosedLoop = autoPushDSClosedLoop;
+       }
+
+       public static String getAutoPushDSFirewall() {
+               return autoPushDSFirewall;
+       }
+
+       public static void setAutoPushDSFirewall(String autoPushDSFirewall) {
+               PolicyController.autoPushDSFirewall = autoPushDSFirewall;
+       }
+
+       public static String getAutoPushDSMicroservice() {
+               return autoPushDSMicroservice;
+       }
+
+       public static void setAutoPushDSMicroservice(String autoPushDSMicroservice) {
+               PolicyController.autoPushDSMicroservice = autoPushDSMicroservice;
+       }
+
+       public static String getAutoPushPDPGroup() {
+               return autoPushPDPGroup;
+       }
+
+       public static void setAutoPushPDPGroup(String autoPushPDPGroup) {
+               PolicyController.autoPushPDPGroup = autoPushPDPGroup;
+       }
+
+       public static String getPapUrl() {
+               return papUrl;
+       }
+
+       public static void setPapUrl(String papUrl) {
+               PolicyController.papUrl = papUrl;
+       }
+
+       public static String getMsEcompName() {
+               return msEcompName;
+       }
+
+       public static void setMsEcompName(String msEcompName) {
+               PolicyController.msEcompName = msEcompName;
+       }
+
+       public static String getMsPolicyName() {
+               return msPolicyName;
+       }
+
+       public static void setMsPolicyName(String msPolicyName) {
+               PolicyController.msPolicyName = msPolicyName;
+       }
+
+       public static String getConfigHome() {
+               return configHome;
+       }
+
+       public static void setConfigHome(String configHome) {
+               PolicyController.configHome = configHome;
+       }
+
+       public static String getActionHome() {
+               return actionHome;
+       }
+
+       public static void setActionHome(String actionHome) {
+               PolicyController.actionHome = actionHome;
+       }
+
+       public static Object getMapaccess() {
+               return mapAccess;
+       }
+
+       public static String getPolicydata() {
+               return policyData;
+       }
+
+       public static String getCharacterencoding() {
+               return characterEncoding;
+       }
+
+       public static String getContenttype() {
+               return contentType;
+       }
+
+       public static String getFile() {
+               return file;
+       }
 }