use of org.mifos.framework.util.ConfigurationLocator in project head by mifos.
the class BirtReportsUploadAction method getUploadStorageDirectory.
public static String getUploadStorageDirectory() {
ConfigurationLocator configurationLocator = new ConfigurationLocator();
String reportPath = configurationLocator.getConfigurationDirectory() + "/uploads";
String uploadsDir = reportPath;
if (File.separatorChar == '\\') {
// windows platform
uploadsDir = uploadsDir.replaceAll("/", "\\\\");
}
return uploadsDir;
}
use of org.mifos.framework.util.ConfigurationLocator 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);
}
}
use of org.mifos.framework.util.ConfigurationLocator in project head by mifos.
the class PluginManager method initializePluginClassLoader.
/**
* Extend classloader by loading jars from ${MIFOS_CONF}/plugins at runtime
*
* @return pluginClassLoader
*/
private ClassLoader initializePluginClassLoader() {
ConfigurationLocator configurationLocator = new ConfigurationLocator();
String libDir = configurationLocator.getConfigurationDirectory() + "/plugins";
File dependencyDirectory = new File(libDir);
File[] files = dependencyDirectory.listFiles();
ArrayList<URL> urls = new ArrayList<URL>();
if (files != null) {
urls.addAll(getPluginURLs(files));
}
return new URLClassLoader(urls.toArray(new URL[urls.size()]), Thread.currentThread().getContextClassLoader());
}
use of org.mifos.framework.util.ConfigurationLocator in project head by mifos.
the class ImageStorageManager method getStorageLocation.
public static synchronized String getStorageLocation() {
if (location == null) {
String pathConfig = MifosConfigurationManager.getInstance().getString(STORAGE_CONFIG_KEY);
if (StringUtils.isBlank(pathConfig) || pathConfig.equals(ConfigurationLocator.LOCATOR_ENVIRONMENT_PROPERTY_NAME)) {
ConfigurationLocator cl = new ConfigurationLocator();
location = cl.getConfigurationDirectory() + BASE_DIR;
} else {
location = pathConfig + BASE_DIR;
}
checkStoragePermission();
}
return location;
}
use of org.mifos.framework.util.ConfigurationLocator in project head by mifos.
the class ApplicationInitializer method copyResources.
private void copyResources(ServletContext sc) throws IOException {
URL protocol = ETLReportDWHelper.class.getClassLoader().getResource("sql/release-upgrades.txt");
ConfigurationLocator configurationLocator = new ConfigurationLocator();
String configPath = configurationLocator.getConfigurationDirectory();
String destinationDirectoryForJobs = configPath + "/ETL/MifosDataWarehouseETL";
String destinationDirectoryForJar = configPath + "/ETL/mifos-etl-plugin-1.0-SNAPSHOT.one-jar.jar";
String destinationDirectoryForReportJobs = configPath + "/uploads/report";
String pathFromJar = "/WEB-INF/mifos-etl-plugin-1.0-SNAPSHOT.one-jar.jar";
String pathFromJobs = "/WEB-INF/MifosDataWarehouseETL/";
if (File.separatorChar == '\\') {
destinationDirectoryForJobs = destinationDirectoryForJobs.replaceAll("/", "\\\\");
destinationDirectoryForJar = destinationDirectoryForJar.replaceAll("/", "\\\\");
destinationDirectoryForReportJobs = destinationDirectoryForReportJobs.replaceAll("/", "\\\\");
}
File directory = new File(destinationDirectoryForJobs);
directory.mkdirs();
File jarDest = new File(destinationDirectoryForJar);
File reportDirectory = new File(destinationDirectoryForReportJobs);
reportDirectory.mkdirs();
if (protocol.getProtocol().equals("jar")) {
FileUtils.cleanDirectory(directory);
// Mifos WAR
URL fullPath = sc.getResource(pathFromJar);
File f = new File(sc.getResource(pathFromJobs).toString().replace("file:", ""));
for (File fileEntry : f.listFiles()) {
FileUtils.copyFileToDirectory(fileEntry, directory);
logger.info("Copy file: " + fileEntry.getName() + " to: " + directory);
}
FileUtils.copyURLToFile(fullPath, jarDest);
logger.info("Copy file: " + fullPath + " to: " + directory);
String jarPath = "/WEB-INF/lib/mifos-reporting-1.12-SNAPSHOT.jar";
String jarName = sc.getResource(jarPath).toString().replace("file:", "");
JarInputStream jarFileStream = new JarInputStream(new FileInputStream(jarName));
JarEntry jarEntry;
while (true) {
jarEntry = jarFileStream.getNextJarEntry();
if (jarEntry == null) {
break;
}
// Skip irrelevant folders
String jarEntryName = jarEntry.getName();
if (!jarEntryName.startsWith("birt/report") && !jarEntryName.startsWith("pentaho")) {
continue;
}
int lastIndexOfDot = jarEntryName.lastIndexOf('.');
if (lastIndexOfDot != -1 && !jarEntry.isDirectory()) {
String destinationDirectory = destinationDirectoryForReportJobs;
String birtReportFolderName = "birt/report";
if (jarEntryName.startsWith(birtReportFolderName)) {
int indexOfLastSlash = jarEntryName.lastIndexOf('/');
String folderName = jarEntryName.substring(birtReportFolderName.length(), indexOfLastSlash).replaceAll("/", "");
File birtSubFolder = new File(destinationDirectoryForReportJobs + File.separatorChar + folderName);
birtSubFolder.mkdirs();
destinationDirectory = destinationDirectoryForReportJobs + File.separatorChar + folderName;
}
InputStream inputStream = MifosViewerServletContextListener.class.getClassLoader().getResourceAsStream(jarEntryName);
int lastIndexOfSlash = jarEntryName.lastIndexOf('/');
String reportFileName = jarEntryName.substring(lastIndexOfSlash + 1);
File reportFile = new File(destinationDirectory + File.separatorChar + reportFileName);
FileUtils.copyInputStreamToFile(inputStream, reportFile);
logger.info("Copy file: " + jarEntryName + " to: " + reportFile);
}
}
} else {
try {
// Mifos Cloud Foundry WAR
URL fullPath = sc.getResource(pathFromJar);
File f = new File(sc.getRealPath("/") + pathFromJobs);
if (f.listFiles().equals(null)) {
throw new NullPointerException();
}
FileUtils.cleanDirectory(directory);
for (File fileEntry : f.listFiles()) {
FileUtils.copyFileToDirectory(fileEntry, directory);
logger.info("Copy file: " + fileEntry.getName() + " to: " + directory);
}
FileUtils.copyURLToFile(fullPath, jarDest);
logger.info("Copy file: " + fullPath + " to: " + directory);
String sourceBirtReportPath = "/report";
String sourcePentahoReportPath = "/WEB-INF/classes/pentaho";
File birtReports = new File(sc.getRealPath("/") + sourceBirtReportPath);
File pentahoReports = new File(sc.getRealPath("/") + sourcePentahoReportPath);
for (File fileEntry : birtReports.listFiles()) {
if (fileEntry.isDirectory()) {
File destinationDirectory = new File(destinationDirectoryForReportJobs + File.separatorChar + fileEntry.getName());
FileUtils.copyDirectory(fileEntry, destinationDirectory);
logger.info("Copy directory: " + fileEntry.getName() + " to: " + destinationDirectory);
continue;
}
FileUtils.copyFileToDirectory(fileEntry, reportDirectory);
logger.info("Copy file: " + fileEntry.getName() + " to: " + reportDirectory);
}
for (File fileEntry : pentahoReports.listFiles()) {
FileUtils.copyFileToDirectory(fileEntry, reportDirectory);
logger.info("Copy file: " + fileEntry.getName() + " to: " + reportDirectory);
}
} catch (NullPointerException e) {
// Eclipse
logger.info("Could not copy Birt/Pentaho report files to Mifos config directory.");
}
}
}
Aggregations