001/* 002 * Copyright 2011 The Kuali Foundation. 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.ole.select.batch.service.impl; 017 018import org.kuali.ole.module.purap.document.service.OlePurapService; 019import org.kuali.ole.select.batch.service.VendorToOleExtractService; 020import org.kuali.ole.sys.OLEConstants; 021import org.kuali.ole.sys.context.SpringContext; 022import org.kuali.rice.core.api.config.property.ConfigurationService; 023 024import java.io.File; 025 026public class VendorToOleExtractServiceImpl implements VendorToOleExtractService { 027 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(VendorToOleExtractServiceImpl.class); 028 protected OlePurapService olePurapService; 029 030 public OlePurapService getOlePurapService() { 031 if (olePurapService == null) { 032 olePurapService = SpringContext.getBean(OlePurapService.class); 033 } 034 return olePurapService; 035 } 036 037 public boolean loadVendorToOleEtl() { 038 039 try { 040 ConfigurationService kualiConfigurationService = SpringContext.getBean(ConfigurationService.class); 041 String directory = kualiConfigurationService.getPropertyValueAsString(OLEConstants.STAGING_DIRECTORY_KEY); 042 String sourcePath = directory + getOlePurapService().getParameter(OLEConstants.SOURCE_FOLDER); 043 String logPath = directory + getOlePurapService().getParameter(OLEConstants.LOG_FOLDER); 044 String destinationPath = directory + getOlePurapService().getParameter(OLEConstants.DESTINATION_FOLDER); 045 String backupFolder = directory + getOlePurapService().getParameter(OLEConstants.BACKUP_FOLDER); 046 String filePath = getClass().getClassLoader().getResource("KualiETLConfig.xml").toString(); 047 if (LOG.isDebugEnabled()) { 048 LOG.debug("-------filePath -------------------" + filePath); 049 LOG.debug("-----------------ETL Configuration Paths---------------"); 050 LOG.debug("-----sourcePath------" + sourcePath); 051 LOG.debug("-----logPath------" + logPath); 052 LOG.debug("-----destinationPath------" + destinationPath); 053 LOG.debug("-----backUpFolderPath------" + backupFolder); 054 } 055 File file = new File(sourcePath); 056 057 int position = filePath.indexOf("/"); 058 String newFilePath = ""; 059 if (directory.contains("local")) { 060 newFilePath = filePath.substring(position + 1); 061 } else { 062 newFilePath = "/" + filePath.substring(position + 1); 063 } 064 if (LOG.isDebugEnabled()) { 065 LOG.debug("-------newFilePath -------------------" + newFilePath); 066 } 067 String[] args = {"--context_param COMMAND_LINE_CONFIG_FILE_NAME=" + newFilePath, "--context_param COMMAND_LINE_SOUCE_FILE_PATH=" + sourcePath, "--context_param COMMAND_LINE_LOG_FILE_PATH=" + logPath, "--context_param COMMAND_LINE_DESTINATION_FILE_PATH=" + destinationPath, "--context_param COMMAND_LINE_BACKUP_FOLDER_PATH=" + backupFolder}; 068 LOG.debug("-------ETL Job Started-------------"); 069 // kuali.kualimainjob_0_1.KualiMainJob kualiMainJob = new kuali.kualimainjob_0_1.KualiMainJob(); 070 // kualiMainJob.runJobInTOS(args); 071 LOG.debug("-------ETL Job Completed-----------"); 072 } catch (Exception e) { 073 LOG.error("VendorToOleExtractServiceImpl.loadVendorToOleEtl():", e); 074 throw new RuntimeException(e); 075 } 076 077 return true; 078 } 079 080}