X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=ONAP-PAP-REST%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fpolicy%2Fpap%2Fxacml%2Frest%2FPAPRestConfig.java;h=614ba85df2620058980f84be23858b5e831861e0;hb=8cf5ed300190ab386d95758e6d4be6c38e67123d;hp=7e514ef245f1b9f052b4188ba1636f526cdd3d8b;hpb=240bbdbdc76e0e91af9f18164eadb2708d14c6fb;p=policy%2Fengine.git diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/PAPRestConfig.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/PAPRestConfig.java index 7e514ef24..614ba85df 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/PAPRestConfig.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/PAPRestConfig.java @@ -3,6 +3,7 @@ * ONAP-PAP-REST * ================================================================================ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + * Modified Copyright (C) 2018 Samsung Electronics Co., Ltd. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -47,91 +48,90 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter @EnableTransactionManagement @ComponentScan(basePackages = { "org.onap.*", "com.*" }) public class PAPRestConfig extends WebMvcConfigurerAdapter { - private static final Logger LOGGER = FlexLogger.getLogger(PAPRestConfig.class); - - private static String dbDriver = null; - private static String dbUrl = null; - private static String dbUserName = null; - private static String dbPassword = null; - - @PostConstruct - public void init(){ - Properties prop = new Properties(); - - try(InputStream input = new FileInputStream("xacml.pap.properties")) { - // load a properties file - prop.load(input); - setDbDriver(prop.getProperty("javax.persistence.jdbc.driver")); - setDbUrl(prop.getProperty("javax.persistence.jdbc.url")); - setDbUserName(prop.getProperty("javax.persistence.jdbc.user")); - setDbPassword( CryptoUtils.decryptTxtNoExStr(prop.getProperty("javax.persistence.jdbc.password", ""))); - }catch(Exception e){ - LOGGER.error("Exception Occured while loading properties file"+e); - } - } - - @Bean(name = "dataSource") - public DataSource getDataSource() { - BasicDataSource dataSource = new BasicDataSource(); - dataSource.setDriverClassName(PAPRestConfig.getDbDriver()); - dataSource.setUrl(PAPRestConfig.getDbUrl()); - dataSource.setUsername(PAPRestConfig.getDbUserName()); - dataSource.setPassword(PAPRestConfig.getDbPassword()); - return dataSource; - } - - @Autowired - @Bean(name = "sessionFactory") - public SessionFactory getSessionFactory(DataSource dataSource) { - LocalSessionFactoryBuilder sessionBuilder = new LocalSessionFactoryBuilder(dataSource); - sessionBuilder.scanPackages("org.onap.*", "com.*"); - sessionBuilder.addProperties(getHibernateProperties()); - return sessionBuilder.buildSessionFactory(); - } - - private Properties getHibernateProperties() { - Properties properties = new Properties(); - properties.put("hibernate.show_sql", "true"); - properties.put("hibernate.dialect", "org.hibernate.dialect.MySQLDialect"); - return properties; - } - - @Autowired - @Bean(name = "transactionManager") - public HibernateTransactionManager getTransactionManager(SessionFactory sessionFactory) { - return new HibernateTransactionManager(sessionFactory); - } - - public static String getDbDriver() { - return dbDriver; - } - - public static void setDbDriver(String dbDriver) { - PAPRestConfig.dbDriver = dbDriver; - } - - public static String getDbUrl() { - return dbUrl; - } - - public static void setDbUrl(String dbUrl) { - PAPRestConfig.dbUrl = dbUrl; - } - - public static String getDbUserName() { - return dbUserName; - } - - public static void setDbUserName(String dbUserName) { - PAPRestConfig.dbUserName = dbUserName; - } - - public static String getDbPassword() { - return dbPassword; - } - - public static void setDbPassword(String dbPassword) { - PAPRestConfig.dbPassword = CryptoUtils.decryptTxtNoExStr(dbPassword); - } - + private static final Logger LOGGER = FlexLogger.getLogger(PAPRestConfig.class); + + private static String dbDriver = null; + private static String dbUrl = null; + private static String dbUserName = null; + private static String dbPassword = null; + + @PostConstruct + public void init(){ + Properties prop = new Properties(); + try(InputStream input = new FileInputStream("xacml.pap.properties")) { + // load a properties file + prop.load(input); + setDbDriver(prop.getProperty("javax.persistence.jdbc.driver")); + setDbUrl(prop.getProperty("javax.persistence.jdbc.url")); + setDbUserName(prop.getProperty("javax.persistence.jdbc.user")); + setDbPassword( CryptoUtils.decryptTxtNoExStr(prop.getProperty("javax.persistence.jdbc.password", ""))); + }catch(Exception e){ + LOGGER.error("Exception Occured while loading properties file"+e); + } + } + + @Bean(name = "dataSource") + public DataSource getDataSource() { + BasicDataSource dataSource = new BasicDataSource(); + dataSource.setDriverClassName(PAPRestConfig.getDbDriver()); + dataSource.setUrl(PAPRestConfig.getDbUrl()); + dataSource.setUsername(PAPRestConfig.getDbUserName()); + dataSource.setPassword(PAPRestConfig.getDbPassword()); + return dataSource; + } + + @Autowired + @Bean(name = "sessionFactory") + public SessionFactory getSessionFactory(DataSource dataSource) { + LocalSessionFactoryBuilder sessionBuilder = new LocalSessionFactoryBuilder(dataSource); + sessionBuilder.scanPackages("org.onap.*", "com.*"); + sessionBuilder.addProperties(getHibernateProperties()); + return sessionBuilder.buildSessionFactory(); + } + + private Properties getHibernateProperties() { + Properties properties = new Properties(); + properties.put("hibernate.show_sql", "true"); + properties.put("hibernate.dialect", "org.hibernate.dialect.MySQLDialect"); + return properties; + } + + @Autowired + @Bean(name = "transactionManager") + public HibernateTransactionManager getTransactionManager(SessionFactory sessionFactory) { + return new HibernateTransactionManager(sessionFactory); + } + + public static String getDbDriver() { + return dbDriver; + } + + public static void setDbDriver(String dbDriver) { + PAPRestConfig.dbDriver = dbDriver; + } + + public static String getDbUrl() { + return dbUrl; + } + + public static void setDbUrl(String dbUrl) { + PAPRestConfig.dbUrl = dbUrl; + } + + public static String getDbUserName() { + return dbUserName; + } + + public static void setDbUserName(String dbUserName) { + PAPRestConfig.dbUserName = dbUserName; + } + + public static String getDbPassword() { + return dbPassword; + } + + public static void setDbPassword(String dbPassword) { + PAPRestConfig.dbPassword = CryptoUtils.decryptTxtNoExStr(dbPassword); + } + }