Search in sources :

Example 91 with ApplicationContext

use of org.springframework.context.ApplicationContext in project cas by apereo.

the class PrincipalAttributeRegisteredServiceUsernameProvider method getPrincipalAttributes.

/**
     * Gets principal attributes. Will attempt to locate the principal
     * attribute repository from the context if one is defined to use
     * that instance to locate attributes. If none is available,
     * will use the default principal attributes.
     *
     * @param p       the principal
     * @param service the service
     * @return the principal attributes
     */
protected Map<String, Object> getPrincipalAttributes(final Principal p, final Service service) {
    final ApplicationContext context = ApplicationContextProvider.getApplicationContext();
    if (context != null) {
        LOGGER.debug("Located application context to locate the service registry entry");
        final ServicesManager servicesManager = context.getBean(ServicesManager.class);
        if (servicesManager != null) {
            final RegisteredService registeredService = servicesManager.findServiceBy(service);
            if (registeredService != null && registeredService.getAccessStrategy().isServiceAccessAllowed()) {
                LOGGER.debug("Located service [{}] in the registry. Attempting to resolve attributes for [{}]", registeredService, p.getId());
                if (registeredService.getAttributeReleasePolicy() == null) {
                    LOGGER.debug("No attribute release policy is defined for [{}]. Returning default principal attributes", service.getId());
                    return p.getAttributes();
                }
                return registeredService.getAttributeReleasePolicy().getAttributes(p, registeredService);
            }
        }
        LOGGER.debug("Could not locate service [{}] in the registry.", service.getId());
        throw new UnauthorizedServiceException(UnauthorizedServiceException.CODE_UNAUTHZ_SERVICE);
    }
    LOGGER.warn("No application context could be detected. Returning default principal attributes");
    return p.getAttributes();
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext)

Example 92 with ApplicationContext

use of org.springframework.context.ApplicationContext in project head by mifos.

the class DashboardServiceFacadeWebTier method getCustomerHeaders.

@Override
public String[] getCustomerHeaders() {
    String[] headers = new String[5];
    Locale locale = getLocale();
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    Locale prefferedLocale = Localization.getInstance().getLocaleById(user.getPreferredLocaleId());
    if (prefferedLocale != null) {
        locale = prefferedLocale;
    }
    ApplicationContext context = ApplicationContextHolder.getApplicationContext();
    headers[0] = context.getMessage("DashboardDetail.GlobalNumber", null, locale);
    headers[1] = context.getMessage("DashboardDetail.ClientName", null, locale);
    headers[2] = context.getMessage("DashboardDetail.State", null, locale);
    headers[3] = context.getMessage("DashboardDetail.LoanOfficer", null, locale);
    headers[4] = context.getMessage("DashboardDetail.LoanBalance", null, locale);
    return headers;
}
Also used : Locale(java.util.Locale) ApplicationContext(org.springframework.context.ApplicationContext) MifosUser(org.mifos.security.MifosUser)

Example 93 with ApplicationContext

use of org.springframework.context.ApplicationContext in project head by mifos.

the class PPITestDataGenerator method loadTestDataFiles.

public void loadTestDataFiles(String[] args) throws IOException, TaskSystemException, PersistenceException, ConfigurationException, FinancialException {
    parseOptions(args);
    ApplicationContext applicationContext = initializeSpring();
    customerDao = applicationContext.getBean(CustomerDaoHibernate.class);
    questionnaireServiceFacade = applicationContext.getBean(QuestionnaireServiceFacade.class);
    if (testDataDirectoryName != null) {
        File directory = new File(testDataDirectoryName);
        File[] listOfFiles = directory.listFiles();
        if (listOfFiles != null) {
            int totalFilesToLoad = countFilesToUpgrade(listOfFiles);
            int filesLoaded = 0;
            for (File listOfFile : listOfFiles) {
                String currentFilename = listOfFile.getName();
                if (listOfFile.isFile() && currentFilename.endsWith("Testing.properties")) {
                    String dataFileName = testDataDirectoryName + File.separator + currentFilename;
                    loadData(dataFileName, applicationContext);
                    filesLoaded++;
                    System.out.println("Finished " + filesLoaded + "/" + totalFilesToLoad);
                }
            }
        } else {
            fail("No files found in directory: " + testDataDirectoryName);
        }
    } else {
        loadData(dataSetName, applicationContext);
    }
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) QuestionnaireServiceFacade(org.mifos.platform.questionnaire.service.QuestionnaireServiceFacade) File(java.io.File) CustomerDaoHibernate(org.mifos.customers.persistence.CustomerDaoHibernate)

Example 94 with ApplicationContext

use of org.springframework.context.ApplicationContext in project head by mifos.

the class ETLReportDWHelper method execute.

@Override
public void execute(final long timeInMillis) throws BatchJobException {
    new ApplicationContextHolder();
    ArrayList<String> errors = new ArrayList<String>();
    ApplicationContext ach = ApplicationContextHolder.getApplicationContext();
    DriverManagerDataSource ds = (DriverManagerDataSource) ach.getBean("dataSource");
    DriverManagerDataSource dsDW = (DriverManagerDataSource) ach.getBean("dataSourcePentahoDW");
    Pattern pat = Pattern.compile(DATA_WAREHOUSE_DB_NAME_PATTERN);
    Matcher m = pat.matcher(dsDW.getUrl());
    String nameOfDataBase = null;
    if (m.find()) {
        nameOfDataBase = m.group(6);
    }
    if (!nameOfDataBase.equals("")) {
        try {
            dsDW.getConnection();
        } catch (SQLException ex) {
            errors.add("Data Warehouse is not configured");
            throw new BatchJobException("Data warehouse database", errors);
        }
        ConfigurationLocator configurationLocator = new ConfigurationLocator();
        String configPath = configurationLocator.getConfigurationDirectory();
        createPropertiesFileForPentahoDWReports(ds, dsDW);
        String path = configPath + "/ETL/MifosDataWarehouseETL/" + FILENAME;
        String jarPath = configPath + "/ETL/mifos-etl-plugin-1.0-SNAPSHOT.one-jar.jar";
        String javaHome = System.getProperty("java.home") + "/bin/java";
        String pathToLog = configPath + "/ETL/log";
        if (File.separatorChar == '\\') {
            // windows platform
            javaHome = javaHome.replaceAll("/", "\\\\");
            javaHome = '"' + javaHome + '"';
            jarPath = jarPath.replaceAll("/", "\\\\");
            path = path.replaceAll("/", "\\\\");
            pathToLog = pathToLog.replaceAll("/", "\\\\");
        }
        PrintWriter fw = null;
        try {
            boolean hasErrors = false;
            boolean notRun = true;
            ProcessBuilder processBuilder = new ProcessBuilder(javaHome, "-jar", jarPath, path, "false", dsDW.getUsername(), dsDW.getPassword(), dsDW.getUrl());
            processBuilder.redirectErrorStream(true);
            Process p = processBuilder.start();
            BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
            String line = null;
            if (new File(pathToLog).exists()) {
                new File(pathToLog).delete();
            }
            File file = new File(pathToLog);
            fw = new PrintWriter(file);
            while ((line = reader.readLine()) != null) {
                fw.println(line);
                if (line.matches("^ERROR.*")) {
                    hasErrors = true;
                }
                notRun = false;
            }
            if (notRun) {
                errors.add("Data Warehouse is not configured properly");
                throw new BatchJobException("Data warehouse database", errors);
            }
            if (hasErrors) {
                errors.add("ETL error, for more details see log file: " + pathToLog);
                throw new BatchJobException("ETL error", errors);
            }
        } catch (IOException ex) {
            throw new BatchJobException(ex.getCause());
        } finally {
            if (fw != null) {
                fw.close();
            }
        }
    } else {
        errors.add("Data Warehouse is not configured");
        throw new BatchJobException("Data warehouse database", errors);
    }
}
Also used : Pattern(java.util.regex.Pattern) InputStreamReader(java.io.InputStreamReader) Matcher(java.util.regex.Matcher) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ConfigurationLocator(org.mifos.framework.util.ConfigurationLocator) ApplicationContext(org.springframework.context.ApplicationContext) BatchJobException(org.mifos.framework.components.batchjobs.exceptions.BatchJobException) DriverManagerDataSource(org.springframework.jdbc.datasource.DriverManagerDataSource) BufferedReader(java.io.BufferedReader) ApplicationContextHolder(org.mifos.application.servicefacade.ApplicationContextHolder) File(java.io.File) PrintWriter(java.io.PrintWriter)

Example 95 with ApplicationContext

use of org.springframework.context.ApplicationContext in project head by mifos.

the class ApplicationInitializer method init.

public void init(ServletContextEvent servletContextEvent) {
    ServletContext servletContext = servletContextEvent.getServletContext();
    try {
        // prevent ehcache "phone home"
        System.setProperty("net.sf.ehcache.skipUpdateCheck", "true");
        // prevent quartz "phone home"
        System.setProperty("org.terracotta.quartz.skipUpdateCheck", "true");
        synchronized (ApplicationInitializer.class) {
            ApplicationContext applicationContext = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
            if (servletContext != null) {
                dbUpgrade(applicationContext);
            }
            initJNDIforPentaho(applicationContext);
            setAttributesOnContext(servletContext);
            copyResources(servletContext);
            copyLogo(servletContext);
        }
    } catch (Exception e) {
        String errMsgStart = "unable to start Mifos web application";
        if (null == logger) {
            System.err.println(errMsgStart + " and logger is not available!");
            e.printStackTrace();
        } else {
            logger.error(errMsgStart, e);
        }
        throw new Error(e);
    }
    logger.info("Mifos is ready.");
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) ServletContext(javax.servlet.ServletContext) SystemException(org.mifos.framework.exceptions.SystemException) TaskSystemException(org.mifos.framework.components.batchjobs.exceptions.TaskSystemException) XMLReaderException(org.mifos.framework.exceptions.XMLReaderException) HibernateProcessException(org.mifos.framework.exceptions.HibernateProcessException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) ConfigurationException(org.mifos.config.exceptions.ConfigurationException) AppNotConfiguredException(org.mifos.framework.exceptions.AppNotConfiguredException) AccountException(org.mifos.accounts.exceptions.AccountException) FinancialException(org.mifos.accounts.financial.exceptions.FinancialException) NameAlreadyBoundException(javax.naming.NameAlreadyBoundException) IOException(java.io.IOException) HibernateStartUpException(org.mifos.framework.exceptions.HibernateStartUpException) ApplicationException(org.mifos.framework.exceptions.ApplicationException)

Aggregations

ApplicationContext (org.springframework.context.ApplicationContext)578 Test (org.junit.Test)262 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)179 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)44 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)37 ConfigurableMessenger (org.springframework.scripting.ConfigurableMessenger)28 File (java.io.File)25 DataSource (javax.sql.DataSource)24 Messenger (org.springframework.scripting.Messenger)24 GenericWebApplicationContext (org.springframework.web.context.support.GenericWebApplicationContext)21 Refreshable (org.springframework.aop.target.dynamic.Refreshable)20 StubCloudConnectorTest (org.springframework.cloud.StubCloudConnectorTest)17 HashMap (java.util.HashMap)16 SchedulerException (org.quartz.SchedulerException)16 ArrayList (java.util.ArrayList)14 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)14 WebApplicationContext (org.springframework.web.context.WebApplicationContext)14 MovieMapper (com.mapper.MovieMapper)13 Map (java.util.Map)13 AnnotationConfigWebApplicationContext (org.springframework.web.context.support.AnnotationConfigWebApplicationContext)13