dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #08215
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 1954: Added Functionality to clear temporary files from output folder and mi folder; Added Option to do...
------------------------------------------------------------
revno: 1954
committer: Bharath <chbharathk@xxxxxxxxx>
branch nick: trunk
timestamp: Mon 2010-10-25 18:34:36 +0530
message:
Added Functionality to clear temporary files from output folder and mi folder; Added Option to download reports folder and mi folder
added:
local/in/dhis-web-maintenance-in/src/main/java/org/hisp/dhis/config/action/ClearFolderAction.java
local/in/dhis-web-maintenance-in/src/main/webapp/dhis-web-maintenance-in/javascript/
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/maintenanceForm.vm
local/in/dhis-web-maintenance-in/src/main/webapp/dhis-web-maintenance-in/responseStatus.vm
modified:
local/in/dhis-in-api/src/main/java/org/hisp/dhis/config/ConfigurationService.java
local/in/dhis-in-services/dhis-in-service-configuration/src/main/java/org/hisp/dhis/config/DefaultConfigurationService.java
local/in/dhis-web-maintenance-in/src/main/resources/META-INF/dhis/beans.xml
local/in/dhis-web-maintenance-in/src/main/resources/struts.xml
local/in/dhis-web-maintenance-in/src/main/webapp/dhis-web-maintenance-in/menu.vm
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== 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<files.length; i++)
+ {
+ in = new BufferedInputStream( new FileInputStream( inFolder.getPath() + "/" + files[i] ), 1024 );
+ out.putNextEntry( new ZipEntry(files[i]) );
+ int count;
+ while( (count = in.read(data,0,1024)) != -1 )
+ {
+ out.write(data, 0, count);
+ }
+ out.closeEntry();
+ }
+ */
+
+ return zipFilePath;
+ }
+ catch(Exception e)
+ {
+ System.out.println( e.getMessage() );
+
+ return "INPUT";
+ }
+ finally
+ {
+ try
+ {
+ out.flush();
+ out.close();
+ }
+ catch( Exception e )
+ {
+ System.out.println( e.getMessage() );
+ }
+ }
+ }
+
+ public void addDirectoryForCompressing( File dirObj, ZipOutputStream out )
+ {
+ try
+ {
+ File[] files = dirObj.listFiles();
+ byte[] tmpBuf = new byte[1024];
+
+ for( int i = 0; i < files.length; i++ )
+ {
+ if (files[i].isDirectory())
+ {
+ addDirectoryForCompressing(files[i], out);
+ continue;
+ }
+
+ FileInputStream in = new FileInputStream(files[i].getAbsolutePath());
+ out.putNextEntry(new ZipEntry(files[i].getAbsolutePath()));
+ int len;
+ while( (len = in.read(tmpBuf)) > 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">
</bean>
+
+<!-- Maintenance -->
+ <bean id="org.hisp.dhis.config.action.ClearFolderAction"
+ class="org.hisp.dhis.config.action.ClearFolderAction"
+ scope="prototype">
+ <property name="configurationService">
+ <ref bean="org.hisp.dhis.config.ConfigurationService"/>
+ </property>
+ </bean>
+
</beans>
=== 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 @@
<param name="bufferSize">1024</param>
</result>
</action>
+
+<!-- Maintenance -->
+ <action name="maintenance" class="org.hisp.dhis.config.action.NoAction">
+ <result name="success" type="velocity">/main.vm</result>
+ <param name="page">/dhis-web-maintenance-in/maintenanceForm.vm</param>
+ <param name="menu">/dhis-web-maintenance-in/menu.vm</param>
+ <param name="stylesheets">css/StylesForTags.css</param>
+ <param name="javascripts">javascript/config.js</param>
+ <param name="requiredAuthorities">F_MAINTENANCE_FORM</param>
+ </action>
+
+ <action name="clearFolder" class="org.hisp.dhis.config.action.ClearFolderAction">
+ <result name="success" type="velocity-xml">/dhis-web-maintenance-in/responseStatus.vm</result>
+ <result name="download" type="stream">
+ <param name="contentType">application/zip</param>
+ <param name="inputName">inputStream</param>
+ <param name="contentDisposition">filename="${fileName}"</param>
+ <param name="bufferSize">1024</param>
+ </result>
+ </action>
</package>
</struts>
=== 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 @@
+
+<br />
+<form id="maintenanceForm" name="maintenanceForm" action="#">
+ <table align="center">
+ <tr align="center"><th>$i18n.getString( "maintenance" )</th></tr>
+ <tr align="center"><td><input type="button" id="clearoutput" value="Clear Output Folder" onclick="clearFolder( this.id )" style="width: 200px; height:35px; font-family: Arial; font-weight: bold; color: rgb(255, 0, 0);" /><br/><br/></td></tr>
+ <tr align="center"><td><input type="button" id="clearbounced" value="Clear Bounced Folder" onclick="clearFolder( this.id )" style="width: 200px; height:35px; font-family: Arial; font-weight: bold; color: rgb(255, 0, 0);" /><br/><br/></td></tr>
+ <tr align="center"><td><input type="button" id="clearpending" value="Clear Pending Folder" onclick="clearFolder( this.id )" style="width: 200px; height:35px; font-family: Arial; font-weight: bold; color: rgb(255, 0, 0);" /><br/><br/></td></tr>
+ <tr align="center"><td><input type="button" id="clearcompleted" value="Clear Completed Folder" onclick="clearFolder( this.id )" style="width: 200px; height:35px; font-family: Arial; font-weight: bold; color: rgb(255, 0, 0);" /><br/><br/></td></tr>
+ <tr align="center"><td><input type="button" id="clearmi" value="Clear mi Folder" onclick="clearFolder( this.id )" style="width: 200px; height:35px; font-family: Arial; font-weight: bold; color: rgb(255, 0, 0);" /><br/><br/></td></tr>
+ <tr align="center"><td><input type="button" id="downloadmi" value="Download mi Folder" onclick="downloadFolder( this.id )" style="width: 200px; height:35px; font-family: Arial; font-weight: bold; color: rgb(0, 0, 255);" /><br/><br/></td></tr>
+ <tr align="center"><td><input type="button" id="downlaodra" value="Download ra Folder" onclick="downloadFolder( this.id )" style="width: 200px; height:35px; font-family: Arial; font-weight: bold; color: rgb(0, 0, 255);" /><br/><br/></td></tr>
+ </table>
+</form>
+
+<span id="message"></span>
\ 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 @@
<ul>
<li><a href="configForm.action">Configuration</a></li>
<li><a href="takeMysqlBackupResult.action" onclick="showOverlay()">Take MySQL Backup</a></li>
+ <li><a href="maintenance.action">Maintenance</a></li>
</ul>
</ul>
=== 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 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<message>$encoder.xmlEncode( $statusMessage )</message>