=== modified file 'local/in/dhis-in-api/src/main/java/org/hisp/dhis/config/ConfigurationService.java' --- local/in/dhis-in-api/src/main/java/org/hisp/dhis/config/ConfigurationService.java 2010-06-04 11:50:05 +0000 +++ local/in/dhis-in-api/src/main/java/org/hisp/dhis/config/ConfigurationService.java 2010-10-25 13:04:36 +0000 @@ -45,5 +45,14 @@ Configuration_IN getConfiguration( int id ); Configuration_IN getConfigurationByKey( String ckey ); + + // ------------------------------------------------------------------------- + // + // ------------------------------------------------------------------------- + + boolean clearXfolder( String folderPath ); + + String backupFolder( String folderPath ); + } === modified file 'local/in/dhis-in-services/dhis-in-service-configuration/src/main/java/org/hisp/dhis/config/DefaultConfigurationService.java' --- local/in/dhis-in-services/dhis-in-service-configuration/src/main/java/org/hisp/dhis/config/DefaultConfigurationService.java 2010-06-04 11:50:05 +0000 +++ local/in/dhis-in-services/dhis-in-service-configuration/src/main/java/org/hisp/dhis/config/DefaultConfigurationService.java 2010-10-25 13:04:36 +0000 @@ -1,5 +1,15 @@ package org.hisp.dhis.config; +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Date; +import java.util.zip.ZipEntry; +import java.util.zip.ZipOutputStream; + import org.springframework.transaction.annotation.Transactional; @Transactional @@ -46,4 +56,136 @@ { return configurationStore.getConfigurationByKey( ckey ); } + + // ------------------------------------------------------------------------- + // + // ------------------------------------------------------------------------- + + public boolean clearXfolder( String folderPath ) + { + try + { + File dir = new File( folderPath ); + String[] files = dir.list(); + for ( String file : files ) + { + file = folderPath + File.separator + file; + File tempFile = new File(file); + tempFile.delete(); + } + + return true; + } + catch(Exception e) + { + System.out.println(e.getMessage()); + return false; + } + } + + public String backupFolder( String folderPath ) + { + + Calendar curDateTime = Calendar.getInstance(); + Date curDate = new Date(); + curDateTime.setTime( curDate ); + + SimpleDateFormat simpleDateFormat = new SimpleDateFormat( "ddMMMyyyy-HHmmssSSS" ); + + String tempFolderName = simpleDateFormat.format( curDate ); + + String zipFilePath = getConfigurationByKey( Configuration_IN.KEY_BACKUPDATAPATH ).getValue(); + zipFilePath += tempFolderName; + + File newdir = new File( zipFilePath ); + if( !newdir.exists() ) + newdir.mkdirs(); + + //zipFilePath = zipFilePath.substring( 0, zipFilePath.lastIndexOf( "/" ) ); + + zipFilePath += "/mi.zip"; + + System.out.println("zipFilePath: "+ zipFilePath ); + + ZipOutputStream out = null; + + try + { + File inFolder = new File( folderPath ); + File outFolder = new File( zipFilePath ); + out = new ZipOutputStream( new BufferedOutputStream( new FileOutputStream(outFolder) ) ); + + addDirectoryForCompressing( inFolder, out ); + /* + BufferedInputStream in = null; + byte[] data = new byte[1024]; + String files[] = inFolder.list(); + + for (int i=0; i 0) + { + out.write(tmpBuf, 0, len); + } + out.closeEntry(); + in.close(); + } + } + catch(Exception e) + { + System.out.println( e.getMessage() ); + } + } + } === added file 'local/in/dhis-web-maintenance-in/src/main/java/org/hisp/dhis/config/action/ClearFolderAction.java' --- local/in/dhis-web-maintenance-in/src/main/java/org/hisp/dhis/config/action/ClearFolderAction.java 1970-01-01 00:00:00 +0000 +++ local/in/dhis-web-maintenance-in/src/main/java/org/hisp/dhis/config/action/ClearFolderAction.java 2010-10-25 13:04:36 +0000 @@ -0,0 +1,237 @@ +package org.hisp.dhis.config.action; + +import java.io.BufferedInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.InputStream; + +import org.hisp.dhis.config.ConfigurationService; +import org.hisp.dhis.config.Configuration_IN; + +import com.opensymphony.xwork2.Action; + +public class ClearFolderAction implements Action +{ + + // ------------------------------------------------------------------------- + // Dependencies + // ------------------------------------------------------------------------- + + private ConfigurationService configurationService; + + public void setConfigurationService( ConfigurationService configurationService ) + { + this.configurationService = configurationService; + } + + // ------------------------------------------------------------------------- + // Input and Output Parameters + // ------------------------------------------------------------------------- + + private InputStream inputStream; + + public InputStream getInputStream() + { + return inputStream; + } + + private String fileName; + + public String getFileName() + { + return fileName; + } + + private String selectedButton; + + public void setSelectedButton( String selectedButton ) + { + this.selectedButton = selectedButton; + } + + private String statusMessage; + + public String getStatusMessage() + { + return statusMessage; + } + + // ------------------------------------------------------------------------- + // Action Implementation + // ------------------------------------------------------------------------- + + public String execute() throws Exception + { + String clearFolderPath; + + statusMessage = ""; + + if( selectedButton.equalsIgnoreCase( "clearoutput" ) ) + { + String raFolderName = configurationService.getConfigurationByKey( Configuration_IN.KEY_REPORTFOLDER ).getValue(); + + clearFolderPath = System.getenv( "DHIS2_HOME" ) + File.separator + raFolderName + File.separator + "output"; + + if( configurationService.clearXfolder( clearFolderPath ) ) + { + statusMessage = "Successfully Cleared the Folder : OUTPUT"; + } + else + { + statusMessage = "Problem while clearing OUTPUT folder, please see the log"; + } + } + else if( selectedButton.equalsIgnoreCase( "clearbounced" ) ) + { + clearFolderPath = System.getenv( "DHIS2_HOME" ) + File.separator + "mi" + File.separator + "bounced"; + + String backupStatus = configurationService.backupFolder( System.getenv( "DHIS2_HOME" ) + File.separator + "mi" ); + + if( backupStatus.equalsIgnoreCase( "INPUT" ) ) + { + statusMessage = "Problem while taking backup for mi folder, please see the log"; + } + else + { + if( configurationService.clearXfolder( clearFolderPath ) ) + { + statusMessage = "Successfully Cleared the Folder : BOUNCED"; + } + else + { + statusMessage = "Problem while clearing BOUNCED folder, please see the log"; + } + } + } + else if( selectedButton.equalsIgnoreCase( "clearpending" ) ) + { + clearFolderPath = System.getenv( "DHIS2_HOME" ) + File.separator + "mi" + File.separator + "pending"; + + String backupStatus = configurationService.backupFolder( System.getenv( "DHIS2_HOME" ) + File.separator + "mi" ); + + if( backupStatus.equalsIgnoreCase( "INPUT" ) ) + { + statusMessage = "Problem while taking backup for mi folder, please see the log"; + } + else + { + if( configurationService.clearXfolder( clearFolderPath ) ) + { + statusMessage = "Successfully Cleared the Folder : PENDING"; + } + else + { + statusMessage = "Problem while clearing PENDING folder, please see the log"; + } + } + } + else if( selectedButton.equalsIgnoreCase( "clearcompleted" ) ) + { + clearFolderPath = System.getenv( "DHIS2_HOME" ) + File.separator + "mi" + File.separator + "completed"; + + String backupStatus = configurationService.backupFolder( System.getenv( "DHIS2_HOME" ) + File.separator + "mi" ); + + if( backupStatus.equalsIgnoreCase( "INPUT" ) ) + { + statusMessage = "Problem while taking backup for mi folder, please see the log"; + } + else + { + if( configurationService.clearXfolder( clearFolderPath ) ) + { + statusMessage = "Successfully Cleared the Folder : COMPLETED"; + } + else + { + statusMessage = "Problem while clearing COMPLETED folder, please see the log"; + } + } + } + else if( selectedButton.equalsIgnoreCase( "clearmi" ) ) + { + String backupStatus = configurationService.backupFolder( System.getenv( "DHIS2_HOME" ) + File.separator + "mi" ); + + if( backupStatus.equalsIgnoreCase( "INPUT" ) ) + { + statusMessage = "Problem while taking backup for mi folder, please see the log"; + } + else + { + // Clearing Bounced Folder + clearFolderPath = System.getenv( "DHIS2_HOME" ) + File.separator + "mi" + File.separator + "bounced"; + + if( configurationService.clearXfolder( clearFolderPath ) ) + { + statusMessage += " Successfully Cleared the Folder : BOUNCED;"; + } + else + { + statusMessage += " Problem while clearing BOUNCED folder, please see the log"; + } + + // Clearing Pending Folder + clearFolderPath = System.getenv( "DHIS2_HOME" ) + File.separator + "mi" + File.separator + "pending"; + + if( configurationService.clearXfolder( clearFolderPath ) ) + { + statusMessage += " Successfully Cleared the Folder : PENDING"; + } + else + { + statusMessage += " Problem while clearing PENDING folder, please see the log"; + } + + // Clearing Completed Folder + clearFolderPath = System.getenv( "DHIS2_HOME" ) + File.separator + "mi" + File.separator + "completed"; + + if( configurationService.clearXfolder( clearFolderPath ) ) + { + statusMessage += " Successfully Cleared the Folder : COMPLETED"; + } + else + { + statusMessage += " Problem while clearing COMPLETED folder, please see the log"; + } + } + } + else if( selectedButton.equalsIgnoreCase( "downloadmi" ) ) + { + String backupStatus = configurationService.backupFolder( System.getenv( "DHIS2_HOME" ) + File.separator + "mi" ); + + if( backupStatus.equalsIgnoreCase( "INPUT" ) ) + { + statusMessage = "Problem while taking backup for mi folder, please see the log"; + } + else + { + fileName = "mi.zip"; + + inputStream = new BufferedInputStream( new FileInputStream( backupStatus ), 1024 ); + + return "download"; + } + } + else if( selectedButton.equalsIgnoreCase( "downlaodra" ) ) + { + String raFolderName = configurationService.getConfigurationByKey( Configuration_IN.KEY_REPORTFOLDER ).getValue(); + + String backupStatus = configurationService.backupFolder( System.getenv( "DHIS2_HOME" ) + File.separator + raFolderName ); + + if( backupStatus.equalsIgnoreCase( "INPUT" ) ) + { + statusMessage = "Problem while taking backup for reports folder, please see the log"; + } + else + { + fileName = raFolderName+".zip"; + + inputStream = new BufferedInputStream( new FileInputStream( backupStatus ), 1024 ); + + return "download"; + } + } + + return SUCCESS; + } + +} === modified file 'local/in/dhis-web-maintenance-in/src/main/resources/META-INF/dhis/beans.xml' --- local/in/dhis-web-maintenance-in/src/main/resources/META-INF/dhis/beans.xml 2010-08-30 12:04:09 +0000 +++ local/in/dhis-web-maintenance-in/src/main/resources/META-INF/dhis/beans.xml 2010-10-25 13:04:36 +0000 @@ -39,5 +39,15 @@ class="org.hisp.dhis.config.action.StreamMySqlBackupAction" scope="prototype"> + + + + + + + + === modified file 'local/in/dhis-web-maintenance-in/src/main/resources/struts.xml' --- local/in/dhis-web-maintenance-in/src/main/resources/struts.xml 2010-06-04 11:50:05 +0000 +++ local/in/dhis-web-maintenance-in/src/main/resources/struts.xml 2010-10-25 13:04:36 +0000 @@ -44,6 +44,26 @@ 1024 + + + + /main.vm + /dhis-web-maintenance-in/maintenanceForm.vm + /dhis-web-maintenance-in/menu.vm + css/StylesForTags.css + javascript/config.js + F_MAINTENANCE_FORM + + + + /dhis-web-maintenance-in/responseStatus.vm + + application/zip + inputStream + filename="${fileName}" + 1024 + + === added directory 'local/in/dhis-web-maintenance-in/src/main/webapp/dhis-web-maintenance-in/javascript' === added file 'local/in/dhis-web-maintenance-in/src/main/webapp/dhis-web-maintenance-in/javascript/config.js' --- local/in/dhis-web-maintenance-in/src/main/webapp/dhis-web-maintenance-in/javascript/config.js 1970-01-01 00:00:00 +0000 +++ local/in/dhis-web-maintenance-in/src/main/webapp/dhis-web-maintenance-in/javascript/config.js 2010-10-25 13:04:36 +0000 @@ -0,0 +1,27 @@ + +function clearFolder( folderId ) +{ + var request = new Request(); + request.setResponseTypeXML( 'message' ); + request.setCallbackSuccess( clearFolderRecieved ); + + var requestString = "clearFolder.action"; + var params = 'selectedButton=' + folderId; + + request.sendAsPost( params ); + request.send( requestString ); +} + +function clearFolderRecieved( messageElement ) +{ + var message = messageElement.firstChild.nodeValue; + + document.getElementById( 'message' ).innerHTML = message; + document.getElementById( 'message' ).style.display = 'block'; +} + + +function downloadFolder( folderId ) +{ + window.location.href="clearFolder.action?selectedButton="+folderId; +} \ No newline at end of file === added file 'local/in/dhis-web-maintenance-in/src/main/webapp/dhis-web-maintenance-in/maintenanceForm.vm' --- local/in/dhis-web-maintenance-in/src/main/webapp/dhis-web-maintenance-in/maintenanceForm.vm 1970-01-01 00:00:00 +0000 +++ local/in/dhis-web-maintenance-in/src/main/webapp/dhis-web-maintenance-in/maintenanceForm.vm 2010-10-25 13:04:36 +0000 @@ -0,0 +1,16 @@ + +
+
+ + + + + + + + + +
$i18n.getString( "maintenance" )














+
+ + \ No newline at end of file === modified file 'local/in/dhis-web-maintenance-in/src/main/webapp/dhis-web-maintenance-in/menu.vm' --- local/in/dhis-web-maintenance-in/src/main/webapp/dhis-web-maintenance-in/menu.vm 2010-08-30 12:04:09 +0000 +++ local/in/dhis-web-maintenance-in/src/main/webapp/dhis-web-maintenance-in/menu.vm 2010-10-25 13:04:36 +0000 @@ -28,6 +28,7 @@ === added file 'local/in/dhis-web-maintenance-in/src/main/webapp/dhis-web-maintenance-in/responseStatus.vm' --- local/in/dhis-web-maintenance-in/src/main/webapp/dhis-web-maintenance-in/responseStatus.vm 1970-01-01 00:00:00 +0000 +++ local/in/dhis-web-maintenance-in/src/main/webapp/dhis-web-maintenance-in/responseStatus.vm 2010-10-25 13:04:36 +0000 @@ -0,0 +1,2 @@ + +$encoder.xmlEncode( $statusMessage )