← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 7932: local/in: Added New Format Excel Import and Mail attachment import functionality to dhis-web-exce...

 

------------------------------------------------------------
revno: 7932
committer: Gaurav <gaurav08021@xxxxxxxxxxx>
branch nick: dhis2
timestamp: Sat 2012-08-18 16:45:26 +0530
message:
  local/in: Added New Format Excel Import and Mail attachment import functionality to dhis-web-excelimport Module
added:
  local/in/dhis-web-excelimport/src/main/java/org/hisp/dhis/excelimport/bddataimport/
  local/in/dhis-web-excelimport/src/main/java/org/hisp/dhis/excelimport/bddataimport/action/
  local/in/dhis-web-excelimport/src/main/java/org/hisp/dhis/excelimport/bddataimport/action/BDExcelImportFormAction.java
  local/in/dhis-web-excelimport/src/main/java/org/hisp/dhis/excelimport/bddataimport/action/BDExcelImportResultAction.java
  local/in/dhis-web-excelimport/src/main/java/org/hisp/dhis/excelimport/emaildataimport/
  local/in/dhis-web-excelimport/src/main/java/org/hisp/dhis/excelimport/emaildataimport/importEmailAttachmentData.java
  local/in/dhis-web-excelimport/src/main/java/org/hisp/dhis/excelimport/util/BDImportSheet.java
  local/in/dhis-web-excelimport/src/main/java/org/hisp/dhis/excelimport/util/ExcelImport_OUDeCode.java
  local/in/dhis-web-excelimport/src/main/webapp/dhis-web-excelimport/BDDataImportForm.vm
  local/in/dhis-web-excelimport/src/main/webapp/dhis-web-excelimport/BDDataImportResult.vm
  local/in/dhis-web-excelimport/src/main/webapp/dhis-web-excelimport/images/bangladesh-flag-map.gif
modified:
  local/in/dhis-web-excelimport/pom.xml
  local/in/dhis-web-excelimport/src/main/java/org/hisp/dhis/excelimport/action/ExcelImportFormAction.java
  local/in/dhis-web-excelimport/src/main/resources/META-INF/dhis/beans.xml
  local/in/dhis-web-excelimport/src/main/resources/struts.xml
  local/in/dhis-web-excelimport/src/main/webapp/dhis-web-excelimport/menu.vm
  local/in/dhis-web-excelimport/src/main/webapp/dhis-web-excelimport/portalDataImportForm.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-web-excelimport/pom.xml'
--- local/in/dhis-web-excelimport/pom.xml	2012-08-03 11:22:50 +0000
+++ local/in/dhis-web-excelimport/pom.xml	2012-08-18 11:15:26 +0000
@@ -70,19 +70,25 @@
 			<groupId>commons-fileupload</groupId>
 			<artifactId>commons-fileupload</artifactId>
 		</dependency>
-		
-		<!-- Other -->
-		<!--
-		<dependency>
-		<groupId>org.springframework</groupId>
-		<artifactId>spring-orm</artifactId>
-		</dependency>
-		<dependency>
-		<groupId>mysql</groupId>
-		<artifactId>mysql-connector-java</artifactId>
-		</dependency>
-		
-		-->
-		
+        <dependency>
+            <groupId>org.apache.struts.xwork</groupId>
+            <artifactId>xwork-core</artifactId>
+            <version>2.3.3</version>
+        </dependency>
+
+        <!--JAVA-MAIL-->
+        <dependency>
+            <groupId>javax.mail</groupId>
+            <artifactId>mail</artifactId>
+            <version>1.4</version>
+        </dependency>
+
+        <!--Quartz framework-->
+        <dependency>
+            <groupId>org.quartz-scheduler</groupId>
+            <artifactId>quartz</artifactId>
+            <version>1.8.6</version>
+        </dependency>
+
 	</dependencies>
 </project>

=== modified file 'local/in/dhis-web-excelimport/src/main/java/org/hisp/dhis/excelimport/action/ExcelImportFormAction.java'
--- local/in/dhis-web-excelimport/src/main/java/org/hisp/dhis/excelimport/action/ExcelImportFormAction.java	2011-01-18 12:01:24 +0000
+++ local/in/dhis-web-excelimport/src/main/java/org/hisp/dhis/excelimport/action/ExcelImportFormAction.java	2012-08-18 11:15:26 +0000
@@ -1,16 +1,15 @@
 package org.hisp.dhis.excelimport.action;
 
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Iterator;
-
+import com.opensymphony.xwork2.Action;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
 import org.hisp.dhis.period.Period;
 import org.hisp.dhis.period.PeriodService;
 import org.hisp.dhis.period.PeriodType;
 
-import com.opensymphony.xwork2.Action;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
 
 public class ExcelImportFormAction
     implements Action
@@ -98,9 +97,9 @@
     public String execute()
         throws Exception
     {
-        //raFolderName = reportService.getRAFolderName();
 
         /* Period Info */
+
         periodTypes = periodService.getAllPeriodTypes();
 
         Iterator<PeriodType> alldeIterator = periodTypes.iterator();

=== added directory 'local/in/dhis-web-excelimport/src/main/java/org/hisp/dhis/excelimport/bddataimport'
=== added directory 'local/in/dhis-web-excelimport/src/main/java/org/hisp/dhis/excelimport/bddataimport/action'
=== added file 'local/in/dhis-web-excelimport/src/main/java/org/hisp/dhis/excelimport/bddataimport/action/BDExcelImportFormAction.java'
--- local/in/dhis-web-excelimport/src/main/java/org/hisp/dhis/excelimport/bddataimport/action/BDExcelImportFormAction.java	1970-01-01 00:00:00 +0000
+++ local/in/dhis-web-excelimport/src/main/java/org/hisp/dhis/excelimport/bddataimport/action/BDExcelImportFormAction.java	2012-08-18 11:15:26 +0000
@@ -0,0 +1,165 @@
+package org.hisp.dhis.excelimport.bddataimport.action;
+
+import com.opensymphony.xwork2.Action;
+import org.hisp.dhis.excelimport.util.BDImportSheet;
+import org.hisp.dhis.excelimport.util.ReportService;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+public class BDExcelImportFormAction implements Action
+{
+
+    // -------------------------------------------------------------------------
+    // Dependencies
+    // -------------------------------------------------------------------------
+
+    private ReportService reportService;
+
+    public void setReportService( ReportService reportService )
+    {
+        this.reportService = reportService;
+    }
+
+    // -------------------------------------------------------------------------
+    // Getter & Setter
+    // -------------------------------------------------------------------------
+    
+    private List<BDImportSheet> excelImportSheetList;
+
+    public List<BDImportSheet> getExcelImportSheetList()
+    {
+        return excelImportSheetList;
+    }
+
+    private String raFolderName;
+
+    // -------------------------------------------------------------------------
+    // Action implementation
+    // -------------------------------------------------------------------------
+    public String execute() throws Exception
+    {
+        raFolderName = reportService.getRAFolderName();
+        
+        excelImportSheetList = new ArrayList<BDImportSheet>();
+        
+        getExcelImportSheetList( "BDDataImportSheetList.xml" );
+        
+        return SUCCESS;
+    }
+    
+    
+    public void getExcelImportSheetList( String reportListFileName )
+    {
+        String fileName = reportListFileName;
+
+        String excelImportFolderName = "excelimport";
+
+        String path = System.getProperty( "user.home" ) + File.separator + "dhis" + raFolderName + File.separator + excelImportFolderName + File.separator + fileName;
+
+        try
+        {
+            String newpath = System.getenv( "DHIS2_HOME" );
+            if ( newpath != null )
+            {
+                path = newpath + File.separator + raFolderName + File.separator + excelImportFolderName + File.separator + fileName;
+            }
+        }
+        catch ( NullPointerException npe )
+        {
+            System.out.println("DHIS2_HOME is not set");
+        }
+
+        String xmlTemplateName;
+        String displayName;
+        String periodicity;
+        String checkerTemplateName;
+        String checkerRangeForHeader;
+        String checkerRangeForData;
+
+        int count = 0;
+
+        try
+        {
+            DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
+            DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
+            Document doc = docBuilder.parse( new File( path ) );
+            if ( doc == null )
+            {
+                System.out.println( "XML File Not Found at DHIS HOME" );
+                return;
+            }
+
+            NodeList listOfReports = doc.getElementsByTagName( "BDImportSheet" );
+            int totalReports = listOfReports.getLength();
+            for ( int s = 0; s < totalReports; s++ )
+            {
+                Node reportNode = listOfReports.item( s );
+                if ( reportNode.getNodeType() == Node.ELEMENT_NODE )
+                {
+                    Element reportElement = (Element) reportNode;
+                    
+                    NodeList nodeList = reportElement.getElementsByTagName( "xmlTemplateName" );
+                    Element element = (Element) nodeList.item( 0 );
+                    nodeList = element.getChildNodes();
+                    xmlTemplateName = ((Node) nodeList.item( 0 )).getNodeValue().trim();
+
+                    nodeList = reportElement.getElementsByTagName( "displayName" );
+                    element = (Element) nodeList.item( 0 );
+                    nodeList = element.getChildNodes();
+                    displayName = ((Node) nodeList.item( 0 )).getNodeValue().trim();
+
+                    nodeList = reportElement.getElementsByTagName( "periodType" );
+                    element = (Element) nodeList.item( 0 );
+                    nodeList = element.getChildNodes();
+                    periodicity = ((Node) nodeList.item( 0 )).getNodeValue().trim();
+
+                    nodeList = reportElement.getElementsByTagName( "checkerTemplateName" );
+                    element = (Element) nodeList.item( 0 );
+                    nodeList = element.getChildNodes();
+                    checkerTemplateName = ((Node) nodeList.item( 0 )).getNodeValue().trim();
+
+                    nodeList = reportElement.getElementsByTagName( "checkerRangeForHeader" );
+                    element = (Element) nodeList.item( 0 );
+                    nodeList = element.getChildNodes();
+                    checkerRangeForHeader = ((Node) nodeList.item( 0 )).getNodeValue().trim();
+
+                    nodeList = reportElement.getElementsByTagName( "checkerRangeForData" );
+                    element = (Element) nodeList.item( 0 );
+                    nodeList = element.getChildNodes();
+                    checkerRangeForData = ((Node) nodeList.item( 0 )).getNodeValue().trim();
+
+                    BDImportSheet bdImportSheet = new BDImportSheet( xmlTemplateName, displayName, periodicity,checkerTemplateName, checkerRangeForHeader, checkerRangeForData);
+                    
+                    excelImportSheetList.add( count, bdImportSheet );
+
+                    count++;
+                }
+            }
+        }
+        catch ( SAXParseException err )
+        {
+            System.out.println( "** Parsing error" + ", line " + err.getLineNumber() + ", uri " + err.getSystemId() );
+            System.out.println( " " + err.getMessage() );
+        }
+        catch ( SAXException e )
+        {
+            Exception x = e.getException();
+            ((x == null) ? e : x).printStackTrace();
+        }
+        catch ( Throwable t )
+        {
+            t.printStackTrace();
+        }
+    }
+
+}

=== added file 'local/in/dhis-web-excelimport/src/main/java/org/hisp/dhis/excelimport/bddataimport/action/BDExcelImportResultAction.java'
--- local/in/dhis-web-excelimport/src/main/java/org/hisp/dhis/excelimport/bddataimport/action/BDExcelImportResultAction.java	1970-01-01 00:00:00 +0000
+++ local/in/dhis-web-excelimport/src/main/java/org/hisp/dhis/excelimport/bddataimport/action/BDExcelImportResultAction.java	2012-08-18 11:15:26 +0000
@@ -0,0 +1,569 @@
+package org.hisp.dhis.excelimport.bddataimport.action;
+
+import com.opensymphony.xwork2.Action;
+import jxl.Sheet;
+import jxl.Workbook;
+import jxl.write.WritableWorkbook;
+import org.hisp.dhis.dataset.DataSetService;
+import org.hisp.dhis.excelimport.util.ExcelImport_OUDeCode;
+import org.hisp.dhis.excelimport.util.ReportService;
+import org.hisp.dhis.i18n.I18nFormat;
+import org.hisp.dhis.organisationunit.OrganisationUnitGroupService;
+import org.hisp.dhis.organisationunit.OrganisationUnitService;
+import org.hisp.dhis.period.Period;
+import org.hisp.dhis.period.PeriodService;
+import org.hisp.dhis.period.PeriodType;
+import org.hisp.dhis.system.database.DatabaseInfo;
+import org.hisp.dhis.system.database.DatabaseInfoProvider;
+import org.hisp.dhis.user.CurrentUserService;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import java.io.File;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.UUID;
+
+public class BDExcelImportResultAction implements Action {
+
+    // -------------------------------------------------------------------------
+    // Dependencies
+    // -------------------------------------------------------------------------
+
+    private ReportService reportService;
+
+    public void setReportService(ReportService reportService) {
+        this.reportService = reportService;
+    }
+
+    private PeriodService periodService;
+
+    public void setPeriodService(PeriodService periodService) {
+        this.periodService = periodService;
+    }
+
+    private JdbcTemplate jdbcTemplate;
+
+    public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
+        this.jdbcTemplate = jdbcTemplate;
+    }
+
+    private OrganisationUnitService organisationUnitService;
+
+    public void setOrganisationUnitService(OrganisationUnitService organisationUnitService) {
+        this.organisationUnitService = organisationUnitService;
+    }
+
+    private OrganisationUnitGroupService organisationUnitGroupService;
+
+    public void setOrganisationUnitGroupService(OrganisationUnitGroupService organisationUnitGroupService) {
+        this.organisationUnitGroupService = organisationUnitGroupService;
+    }
+
+    private CurrentUserService currentUserService;
+
+    public void setCurrentUserService(CurrentUserService currentUserService) {
+        this.currentUserService = currentUserService;
+    }
+
+    private DataSetService dataSetService;
+
+    public void setDataSetService(DataSetService dataSetService) {
+        this.dataSetService = dataSetService;
+    }
+
+    private DatabaseInfoProvider databaseInfoProvider;
+
+    public void setDatabaseInfoProvider( DatabaseInfoProvider databaseInfoProvider )
+    {
+        this.databaseInfoProvider = databaseInfoProvider;
+    }
+
+    private I18nFormat format;
+
+    public void setFormat(I18nFormat format) {
+        this.format = format;
+    }
+
+    // -------------------------------------------------------------------------
+    // Getter & Setter
+    // -------------------------------------------------------------------------
+
+    private String checkTemplateName;
+
+    public void setCheckTemplateName(String checkTemplateName) {
+        this.checkTemplateName = checkTemplateName;
+    }
+
+    private String checkRangeForHeader;
+
+    public void setCheckRangeForHeader(String checkRangeForHeader) {
+        this.checkRangeForHeader = checkRangeForHeader;
+    }
+
+    private String checkRangeForData;
+
+    public void setCheckRangeForData(String checkRangeForData) {
+        this.checkRangeForData = checkRangeForData;
+    }
+
+    private String importSheetId;
+
+    public void setImportSheetId(String importSheetId) {
+        this.importSheetId = importSheetId;
+    }
+
+    private String message = "";
+
+    public String getMessage() {
+        return message;
+    }
+
+    private File output;
+
+    public File getOutput() {
+        return output;
+    }
+
+    private File upload;
+
+    public File getUpload() {
+        return upload;
+    }
+
+    public void setUpload(File upload) {
+        this.upload = upload;
+    }
+
+    private String raFolderName;
+
+    private boolean lockStatus;
+
+    public boolean isLockStatus() {
+        return lockStatus;
+    }
+
+    String selectedPeriodicity;
+
+    public void setSelectedPeriodicity(String selectedPeriodicity) {
+        this.selectedPeriodicity = selectedPeriodicity;
+    }
+
+    // -------------------------------------------------------------------------
+    // Action implementation
+    // -------------------------------------------------------------------------
+
+    public String execute() throws Exception {
+
+        message += "\n<br><font color=blue>Importing StartTime : " + new Date() + "  - By " + currentUserService.getCurrentUsername() + "</font><br>";
+
+        System.out.println(message);
+
+        raFolderName = reportService.getRAFolderName();
+
+        System.out.println("\n==========================================TESTING=============================================");
+
+        System.out.println("TemplateName [" + checkTemplateName + "]");
+
+
+        String excelTemplatePath = System.getenv("DHIS2_HOME") + File.separator + raFolderName + File.separator
+                + "excelimport" + File.separator + "template" + File.separator + checkTemplateName;
+
+        String outputReportPath = System.getenv("DHIS2_HOME") + File.separator + raFolderName + File.separator + "output" + File.separator + UUID.randomUUID().toString() + ".xls";
+
+        Workbook excelImportFile = Workbook.getWorkbook(upload);
+
+        WritableWorkbook writableExcelImportFile = Workbook.createWorkbook(new File(outputReportPath), excelImportFile);
+
+        Workbook excelTemplateFile = Workbook.getWorkbook(new File(excelTemplatePath));
+
+        if (validateReport(excelImportFile, excelTemplateFile)) {
+            System.out.println("Uploaded ExcelSheet is matched with Template file.");
+            importPortalData(writableExcelImportFile);
+
+        } else {
+            message = "The file you are trying to import is not the correct format";
+        }
+
+        try {
+
+        } finally {
+            excelImportFile.close();
+            excelTemplateFile.close();
+            writableExcelImportFile.close();
+        }
+
+        System.out.println("==========================================TESTING=============================================\n");
+
+        System.out.println("Importing has been completed which is started by : " + currentUserService.getCurrentUsername() + " at " + new Date());
+        message += "<br><br><font color=blue>Importing EndTime : " + new Date() + "  - By " + currentUserService.getCurrentUsername() + "</font>";
+
+        return SUCCESS;
+    }
+
+
+
+
+    private void importPortalData(WritableWorkbook importWorkbook) throws Exception {
+
+        List<ExcelImport_OUDeCode> excelImport_ouDeCodeList = new ArrayList<ExcelImport_OUDeCode>();
+
+        final String excelImportFolderName = "excelimport";
+
+        String path = System.getProperty("user.home") + File.separator + "dhis" + File.separator + raFolderName + File.separator + excelImportFolderName + File.separator + importSheetId;
+
+        try
+        {
+            String newPath = System.getenv("DHIS2_HOME");
+
+            if (newPath != null) {
+                path = newPath + File.separator + raFolderName + File.separator + excelImportFolderName + File.separator + importSheetId;
+            }
+        }
+        catch (NullPointerException npe)
+        {
+            System.out.println("DHIS2_HOME is not set");
+        }
+
+        try
+        {
+            DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
+            DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
+            Document doc = docBuilder.parse(new File(path));
+
+            if (doc == null)
+            {
+                System.out.println("There is no DECodes related XML file in the DHIS2 Home");
+            }
+
+            NodeList periodCells = doc.getElementsByTagName("period-info");
+
+            Element periodCell = (Element) periodCells.item(0);
+
+            Integer periodSheetNo = Integer.parseInt(periodCell.getAttribute("sheetno"));
+            Integer periodRowNo = Integer.parseInt(periodCell.getAttribute("rowno"));
+            Integer periodColNo = Integer.parseInt(periodCell.getAttribute("colno"));
+            String periodFormat = periodCell.getAttribute("format");
+
+            System.out.println("PERIOD-INFO ["+periodRowNo+","+periodColNo+","+periodSheetNo+", ("+periodFormat+")]");
+
+            Sheet importFileSheet = importWorkbook.getSheet(periodSheetNo);
+            String cellContent = importFileSheet.getCell(periodColNo, periodRowNo).getContents().trim();
+
+            String periodSplit[] = cellContent.split(" ");
+
+            String sDateString;
+
+            String eDateString;
+
+            Period selectedPeriod = null ;
+
+            if(periodSplit.length<3)
+            {
+                System.out.println("* ERROR: Wrong DATE FORMAT");
+                System.exit(1);
+            }
+            else
+            {
+                sDateString = periodSplit[1].trim();
+                eDateString = periodSplit[3].trim();
+
+                SimpleDateFormat dateFormat = new SimpleDateFormat("dd/mm/yyyy");
+
+                Date convertedStartDate = dateFormat.parse(sDateString);
+                Date convertedEndDate = dateFormat.parse(eDateString);
+
+                PeriodType periodType = periodService.getPeriodTypeByName( selectedPeriodicity );
+
+                selectedPeriod = getSelectedPeriod( convertedStartDate, periodType );
+
+                System.out.println("DATE_EXPRESSIONS ["+convertedStartDate+","+convertedEndDate+"]");
+            }
+
+            NodeList listOfDeCodes = doc.getElementsByTagName("cell-info");
+            int totalDeCodes = listOfDeCodes.getLength();
+
+            for (int s = 0; s < totalDeCodes; s++)
+            {
+                Element deCodeElement = (Element) listOfDeCodes.item(s);
+                NodeList textDeCodeList = deCodeElement.getChildNodes();
+                String deCodeExpression = ((Node) textDeCodeList.item(0)).getNodeValue().trim();
+                Integer sheetNo = Integer.parseInt(deCodeElement.getAttribute("sheetno"));
+                Integer rowNo = Integer.parseInt(deCodeElement.getAttribute("rowno"));
+                Integer colNo = Integer.parseInt(deCodeElement.getAttribute("colno"));
+                String type = deCodeElement.getAttribute("type");
+                Integer ouCode = 0;
+                if (type.equalsIgnoreCase("OU-DE"))
+                {
+                   ouCode = Integer.parseInt(deCodeElement.getAttribute("oucode"));
+                }
+
+                System.out.println("OU-DE-INFO ["+rowNo+","+colNo+","+sheetNo+",("+deCodeExpression+","+ouCode+")]");
+
+                ExcelImport_OUDeCode excelImport_ouDeCode = new ExcelImport_OUDeCode(sheetNo,rowNo,colNo,deCodeExpression,ouCode);
+
+                excelImport_ouDeCodeList.add(excelImport_ouDeCode);
+
+            }
+
+            String checkForEntry = new String();
+            String InsertQuery = new String();
+            String UpdateQuery = new String();
+
+            DatabaseInfo dataBaseInfo = databaseInfoProvider.getDatabaseInfo();
+
+            System.out.println("* INFO IMPORT LIST SIZE ["+excelImport_ouDeCodeList.size()+"]" );
+
+            for (ExcelImport_OUDeCode excelImport_ouDeCode: excelImport_ouDeCodeList)
+            {
+
+                System.out.println("* INFO [EXCEL IMPORT VALUES :"+excelImport_ouDeCode.getExpression()+","+excelImport_ouDeCode.getOuCode()+"]");
+
+                Integer dataElementId = 0 ;
+
+                Integer optionComboId = 0 ;
+
+                Integer ouCode = excelImport_ouDeCode.getOuCode();
+
+                Integer dataCellRowNo = excelImport_ouDeCode.getRowno();
+
+                Integer dataCellCollNo = excelImport_ouDeCode.getColno();
+
+                int selectedPeriodID = selectedPeriod.getId();
+
+
+                if(!excelImport_ouDeCode.getExpression().contains("."))
+                {
+                    System.out.println("* ERROR: WRONG DATAELEMENT EXPRESSION FORMAT ["+excelImport_ouDeCode.getExpression()+"]");
+                    System.exit(1);
+                }
+                else
+                {
+                    System.out.println("* TEST PARSE-INT : "+(excelImport_ouDeCode.getExpression().substring(0,(excelImport_ouDeCode.getExpression().indexOf('.')))));
+                    System.out.println("* TEST PARSE-INT : "+(excelImport_ouDeCode.getExpression().substring((excelImport_ouDeCode.getExpression().indexOf('.')+1),(excelImport_ouDeCode.getExpression().length()))));
+
+                    dataElementId = Integer.parseInt(excelImport_ouDeCode.getExpression().substring(0,(excelImport_ouDeCode.getExpression().indexOf('.'))));
+                    optionComboId = Integer.parseInt(excelImport_ouDeCode.getExpression().substring((excelImport_ouDeCode.getExpression().indexOf('.')+1),(excelImport_ouDeCode.getExpression().length())));
+                }
+
+
+                if ( dataBaseInfo.getType().equalsIgnoreCase( "postgresql" ) )
+                {
+                    checkForEntry = "SELECT COUNT(*) FROM datavalue WHERE dataelementid = "
+                            + dataElementId + " AND categoryoptioncomboid = " + optionComboId + " AND periodid = "
+                            + selectedPeriodID + " AND sourceid = " + ouCode;
+                }
+                else if ( dataBaseInfo.getType().equalsIgnoreCase( "mysql" ) )
+                {
+
+                    checkForEntry = "SELECT COUNT(*) FROM datavalue WHERE dataelementid = "
+                            + dataElementId + " AND categoryoptioncomboid = " + optionComboId + " AND periodid = "
+                            + selectedPeriodID + " AND sourceid = " + ouCode;
+                }
+
+                int preEntryCount = -1;
+
+                preEntryCount = jdbcTemplate.queryForInt(checkForEntry);
+
+                System.out.println("* QUERY CHECK: ["+checkForEntry+" >>> "+preEntryCount+"]");
+
+                double dataValue = Double.parseDouble(importFileSheet.getCell(dataCellCollNo, dataCellRowNo).getContents().trim());;
+
+                System.out.println("* CHECK EXCEL-READ : ["+dataValue+"]");
+
+                int isInserted = 0;
+
+                int isUpdated = 0;
+
+                if(preEntryCount == 0)
+                {
+                    if ( dataBaseInfo.getType().equalsIgnoreCase( "postgresql" ) )
+                    {
+                        InsertQuery = "INSERT INTO datavalue (dataelementid,categoryoptioncomboid,periodid,sourceid) VALUES("
+                                + dataElementId + "," + optionComboId + ","
+                                + selectedPeriodID + "," + ouCode+")";
+                    }
+                    else if ( dataBaseInfo.getType().equalsIgnoreCase( "mysql" ) )
+                    {
+
+                        InsertQuery =  "INSERT INTO datavalue (dataelementid,categoryoptioncomboid,periodid,sourceid) VALUES("
+                                + dataElementId + "," + optionComboId + ","
+                                + selectedPeriodID + "," + ouCode+")";
+                    }
+
+                    isInserted = jdbcTemplate.update(InsertQuery);
+
+                    if(isInserted==0)
+                    {
+                        System.out.println("* WARNING : INSERT Operation FAILED");
+                    }
+                    else
+                    {
+                        System.out.println("* INSERT QUERY CHECK: ["+InsertQuery+" >>> "+isInserted+"]");
+                    }
+
+                }
+                else if(preEntryCount == 1)
+                {
+                    if ( dataBaseInfo.getType().equalsIgnoreCase( "postgresql" ) )
+                    {
+                        UpdateQuery = "UPDATE datavalue SET value="+dataValue+" WHERE dataelementid = "
+                                + dataElementId + " AND categoryoptioncomboid = " + optionComboId + " AND periodid = "
+                                + selectedPeriodID + " AND sourceid = " + ouCode;
+                    }
+                    else if ( dataBaseInfo.getType().equalsIgnoreCase( "mysql" ) )
+                    {
+
+                        UpdateQuery = "UPDATE datavalue SET value="+dataValue+" WHERE dataelementid = "
+                                + dataElementId + " AND categoryoptioncomboid = " + optionComboId + " AND periodid = "
+                                + selectedPeriodID + " AND sourceid = " + ouCode;;
+                    }
+
+                    isUpdated = jdbcTemplate.update(UpdateQuery);
+
+                    if(isUpdated==0)
+                    {
+                        System.out.println("* WARNING : UPDATE Operation FAILED");
+                    }
+                    else
+                    {
+                        System.out.println("* UPADTE QUERY CHECK: ["+UpdateQuery+" >>> "+isUpdated+"]");
+                    }
+                }
+
+
+            }
+
+        } catch (SAXParseException err) {
+            System.out.println("** Parsing error" + ", line " + err.getLineNumber() + ", uri " + err.getSystemId());
+            System.out.println(" " + err.getMessage());
+        } catch (SAXException e) {
+            Exception x = e.getException();
+            ((x == null) ? e : x).printStackTrace();
+        } catch (Throwable t) {
+            t.printStackTrace();
+        }
+
+    }
+
+
+    public boolean validateReport(Workbook excelImportFile, Workbook excelTemplateFile) {
+
+        boolean validator = true;
+
+        final int sheetNumber = 0;
+
+        String headerParts[] = checkRangeForHeader.split("-");
+        int headerStartRow = Integer.parseInt(headerParts[0].split(",")[0]);
+        int headerEndRow = Integer.parseInt(headerParts[1].split(",")[0]);
+        int headerStartCol = Integer.parseInt(headerParts[0].split(",")[1]);
+        int headerEndCol = Integer.parseInt(headerParts[1].split(",")[1]);
+
+        String dataParts[] = checkRangeForData.split("-");
+        int dataStartRow = Integer.parseInt(dataParts[0].split(",")[0]);
+        int dataEndRow = Integer.parseInt(dataParts[1].split(",")[0]);
+        int dataStartCol = Integer.parseInt(dataParts[0].split(",")[1]);
+        int dataEndCol = Integer.parseInt(dataParts[1].split(",")[1]);
+
+        System.out.println("* INFO: VALIDATING IMPORTED FILE ["+excelImportFile.getSheet(sheetNumber).getName()+"]"+"AGAINST TEMPLATE ["+excelTemplateFile.getSheet(sheetNumber).getName()+"]");
+
+        Sheet importFileSheet = excelImportFile.getSheet(sheetNumber);
+        Sheet templateFileSheet = excelTemplateFile.getSheet(sheetNumber);
+
+        if (excelImportFile.getSheet(sheetNumber).getRows() == excelTemplateFile.getSheet(sheetNumber).getRows())
+        {
+
+            //-------------------------------- Checking Header Cells ---------------------------------------------
+
+            for (int c = headerStartCol; c <= headerEndCol; c++) {
+                for (int r = headerStartRow; r <= headerEndRow; r++) {
+
+                    String cellContent = importFileSheet.getCell(c, r).getContents();
+                    String templateContent = templateFileSheet.getCell(c, r).getContents();
+
+                    if (templateContent.equalsIgnoreCase(cellContent) && cellContent.equalsIgnoreCase(templateContent)) {
+                        continue;
+                    }
+                    else
+                    {
+                        System.out.println("["+cellContent+"|"+templateContent+"]");
+                        validator = false;
+                        break;
+                    }
+                }
+            }
+
+            //--------------------------------- Checking Data Cells ----------------------------------------------
+
+            for (int c = dataStartCol; c <= dataEndCol; c++) {
+                for (int r = dataStartRow; r <= dataEndRow; r++) {
+                    String cellContent = importFileSheet.getCell(c, r).getContents();
+                    String templateContent = templateFileSheet.getCell(c, r).getContents();
+
+                    if (templateContent.equalsIgnoreCase(cellContent) && cellContent.equalsIgnoreCase(templateContent)) {
+                        continue;
+                    }
+                    else
+                    {
+                        System.out.println("["+cellContent+"|"+templateContent+"]");
+                        validator = false;
+                        break;
+                    }
+                }
+            }
+        }
+        else
+        {
+            System.out.println("* FAILURE :Validation failed due to unequal count of rows.");
+            validator = false;
+        }
+
+        return validator;
+    }
+
+
+    public Period getSelectedPeriod(Date startDate, PeriodType periodType) throws Exception {
+
+
+
+        List<Period> periods = new ArrayList<Period>(periodService.getPeriodsByPeriodType(periodType));
+        for (Period period : periods) {
+            Date tempDate = period.getStartDate();
+            if (tempDate.equals(startDate)) {
+                return period;
+            }
+        }
+
+        Period period = periodType.createPeriod(startDate);
+        period = reloadPeriodForceAdd(period);
+
+
+        return period;
+    }
+
+    private final Period reloadPeriod(Period period) {
+        return periodService.getPeriod(period.getStartDate(), period.getEndDate(), period.getPeriodType());
+    }
+
+    private final Period reloadPeriodForceAdd(Period period) {
+        Period storedPeriod = reloadPeriod(period);
+
+        if (storedPeriod == null) {
+            periodService.addPeriod(period);
+
+            return period;
+        }
+
+        return storedPeriod;
+    }
+
+}

=== added directory 'local/in/dhis-web-excelimport/src/main/java/org/hisp/dhis/excelimport/emaildataimport'
=== added file 'local/in/dhis-web-excelimport/src/main/java/org/hisp/dhis/excelimport/emaildataimport/importEmailAttachmentData.java'
--- local/in/dhis-web-excelimport/src/main/java/org/hisp/dhis/excelimport/emaildataimport/importEmailAttachmentData.java	1970-01-01 00:00:00 +0000
+++ local/in/dhis-web-excelimport/src/main/java/org/hisp/dhis/excelimport/emaildataimport/importEmailAttachmentData.java	2012-08-18 11:15:26 +0000
@@ -0,0 +1,699 @@
+package org.hisp.dhis.excelimport.emaildataimport;
+
+import jxl.Sheet;
+import jxl.Workbook;
+import jxl.write.WritableWorkbook;
+import jxl.write.WriteException;
+import org.hisp.dhis.excelimport.util.BDImportSheet;
+import org.hisp.dhis.excelimport.util.ExcelImport_OUDeCode;
+import org.hisp.dhis.excelimport.util.ReportService;
+import org.hisp.dhis.period.Period;
+import org.hisp.dhis.period.PeriodService;
+import org.hisp.dhis.period.PeriodType;
+import org.hisp.dhis.system.database.DatabaseInfo;
+import org.hisp.dhis.system.database.DatabaseInfoProvider;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+
+import javax.mail.*;
+import javax.mail.internet.InternetAddress;
+import javax.mail.search.FlagTerm;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import java.io.*;
+import java.text.SimpleDateFormat;
+import java.util.*;
+
+public class importEmailAttachmentData {
+
+    //------------------------------------------------------------------------------------------------------
+    //                             EMAIL IMPORT SETTINGS
+    //------------------------------------------------------------------------------------------------------
+
+    public static final String DATABANK_STORE = System.getenv("DHIS2_HOME") + File.separator + "HISPDATABANK";
+
+    public static final String FILTER_TEXT = "IMPORT";
+
+    public static final String EMAIL_PROTOCOL = "imaps";
+
+    public static final String HOST_SERVER =  "imap.gmail.com";
+
+    public static final String USERNAME =  "hispdatabank";
+
+    public static final String PASSWORD =  "Hispindia7";
+
+    public static final String SERVER_FOLDER_NAME = "Inbox";
+
+
+    //------------------------------------------------------------------------------------------------------
+    //                                DEPENDENCIES
+    //------------------------------------------------------------------------------------------------------
+
+    private ReportService reportService;
+
+    public void setReportService(ReportService reportService) {
+        this.reportService = reportService;
+    }
+
+    private PeriodService periodService;
+
+    public void setPeriodService(PeriodService periodService) {
+        this.periodService = periodService;
+    }
+
+    private JdbcTemplate jdbcTemplate;
+
+    public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
+        this.jdbcTemplate = jdbcTemplate;
+    }
+
+    private DatabaseInfoProvider databaseInfoProvider;
+
+    public void setDatabaseInfoProvider(DatabaseInfoProvider databaseInfoProvider) {
+        this.databaseInfoProvider = databaseInfoProvider;
+    }
+
+    private String raFolderName;
+
+    private List<BDImportSheet> excelImportSheetList;
+
+    public static int importCount = 0;
+
+    //------------------------------------------------------------------------------------------------------
+    //                                IMPLEMENTATION
+    //------------------------------------------------------------------------------------------------------
+
+
+    public void saveFile(String filename, InputStream is) throws Exception, WriteException {
+
+        File dataBankFolder = new File(DATABANK_STORE);
+
+        if (!dataBankFolder.exists()) {
+            dataBankFolder.mkdir();
+        }
+
+        String attachmentPath = DATABANK_STORE + File.separator + filename;
+
+        File extractedFile = new File(attachmentPath);
+
+        if (!extractedFile.exists()) {
+
+            FileOutputStream fos = null;
+
+            try {
+                fos = new FileOutputStream(extractedFile);
+            } catch (FileNotFoundException e) {
+                e.printStackTrace();
+            }
+            byte[] buf = new byte[4096];
+
+            int bytesRead;
+
+            try {
+                while ((bytesRead = is.read(buf)) != -1) {
+                    try {
+                        fos.write(buf, 0, bytesRead);
+
+                    } catch (IOException e) {
+                        e.printStackTrace();
+                    }
+                }
+            } catch (IOException e) {
+
+                e.printStackTrace();
+            }
+
+        } else {
+            System.out.println("* INFO   : Attachment already extracted. Skipping!!");
+        }
+
+        importData(extractedFile);
+
+        extractedFile.delete();
+
+    }
+
+    public void getExcelImportSheetList(String reportListFileName) {
+
+        String fileName = reportListFileName;
+
+        String excelImportFolderName = "excelimport";
+
+        String path = System.getProperty("user.home") + File.separator + "dhis" + raFolderName + File.separator + excelImportFolderName + File.separator + fileName;
+
+        try
+        {
+            String newpath = System.getenv("DHIS2_HOME");
+
+            if (newpath != null) {
+                path = newpath + File.separator + raFolderName + File.separator + excelImportFolderName + File.separator + fileName;
+            }
+        }
+        catch (NullPointerException npe)
+        {
+            System.out.println("DHIS2_HOME is not set");
+        }
+
+        String xmlTemplateName;
+        String displayName;
+        String periodicity;
+        String checkerTemplateName;
+        String checkerRangeForHeader;
+        String checkerRangeForData;
+
+        int count = 0;
+
+        try {
+            DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
+            DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
+            Document doc = docBuilder.parse(new File(path));
+            if (doc == null) {
+                System.out.println("XML File Not Found at DHIS HOME");
+                return;
+            }
+
+            NodeList listOfReports = doc.getElementsByTagName("BDImportSheet");
+            int totalReports = listOfReports.getLength();
+            for (int s = 0; s < totalReports; s++) {
+                Node reportNode = listOfReports.item(s);
+                if (reportNode.getNodeType() == Node.ELEMENT_NODE) {
+                    Element reportElement = (Element) reportNode;
+
+                    NodeList nodeList = reportElement.getElementsByTagName("xmlTemplateName");
+                    Element element = (Element) nodeList.item(0);
+                    nodeList = element.getChildNodes();
+                    xmlTemplateName = ((Node) nodeList.item(0)).getNodeValue().trim();
+
+                    nodeList = reportElement.getElementsByTagName("displayName");
+                    element = (Element) nodeList.item(0);
+                    nodeList = element.getChildNodes();
+                    displayName = ((Node) nodeList.item(0)).getNodeValue().trim();
+
+                    nodeList = reportElement.getElementsByTagName("periodType");
+                    element = (Element) nodeList.item(0);
+                    nodeList = element.getChildNodes();
+                    periodicity = ((Node) nodeList.item(0)).getNodeValue().trim();
+
+                    nodeList = reportElement.getElementsByTagName("checkerTemplateName");
+                    element = (Element) nodeList.item(0);
+                    nodeList = element.getChildNodes();
+                    checkerTemplateName = ((Node) nodeList.item(0)).getNodeValue().trim();
+
+                    nodeList = reportElement.getElementsByTagName("checkerRangeForHeader");
+                    element = (Element) nodeList.item(0);
+                    nodeList = element.getChildNodes();
+                    checkerRangeForHeader = ((Node) nodeList.item(0)).getNodeValue().trim();
+
+                    nodeList = reportElement.getElementsByTagName("checkerRangeForData");
+                    element = (Element) nodeList.item(0);
+                    nodeList = element.getChildNodes();
+                    checkerRangeForData = ((Node) nodeList.item(0)).getNodeValue().trim();
+
+                    BDImportSheet bdImportSheet = new BDImportSheet(xmlTemplateName, displayName, periodicity, checkerTemplateName, checkerRangeForHeader, checkerRangeForData);
+
+                    excelImportSheetList.add(count, bdImportSheet);
+
+                    count++;
+                }
+            }
+        } catch (SAXParseException err) {
+            System.out.println("** Parsing error" + ", line " + err.getLineNumber() + ", uri " + err.getSystemId());
+            System.out.println(" " + err.getMessage());
+        } catch (SAXException e) {
+            Exception x = e.getException();
+            ((x == null) ? e : x).printStackTrace();
+        } catch (Throwable t) {
+            t.printStackTrace();
+        }
+    }
+
+
+    private void importPortalData(WritableWorkbook importWorkbook, String templateName) throws Exception {
+
+        for (BDImportSheet importSheet : excelImportSheetList) {
+
+            if (importSheet.getCheckTemplateName().equals(templateName)) {
+
+                List<ExcelImport_OUDeCode> excelImport_ouDeCodeList = new ArrayList<ExcelImport_OUDeCode>();
+
+                String importSheetId = importSheet.getXmlTemplateName();
+
+                String selectedPeriodicity = importSheet.getPeriodicity();
+
+                final String excelImportFolderName = "excelimport";
+
+                String path = System.getProperty("user.home") + File.separator + "dhis" + File.separator + raFolderName + File.separator + excelImportFolderName + File.separator + importSheetId;
+
+                try {
+                    String newPath = System.getenv("DHIS2_HOME");
+
+                    if (newPath != null) {
+
+                        path = newPath + File.separator + raFolderName + File.separator + excelImportFolderName + File.separator + importSheetId;
+                    }
+                } catch (NullPointerException npe) {
+                    System.out.println("DHIS2_HOME is not set");
+                }
+
+                try {
+                    DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
+                    DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
+                    Document doc = docBuilder.parse(new File(path));
+
+                    if (doc == null) {
+                        System.out.println("There is no DECodes related XML file in the DHIS2 Home");
+                    }
+
+                    NodeList periodCells = doc.getElementsByTagName("period-info");
+
+                    Element periodCell = (Element) periodCells.item(0);
+
+                    Integer periodSheetNo = Integer.parseInt(periodCell.getAttribute("sheetno"));
+                    Integer periodRowNo = Integer.parseInt(periodCell.getAttribute("rowno"));
+                    Integer periodColNo = Integer.parseInt(periodCell.getAttribute("colno"));
+                    String periodFormat = periodCell.getAttribute("format");
+
+                    Sheet importFileSheet = importWorkbook.getSheet(periodSheetNo);
+
+                    String cellContent = importFileSheet.getCell(periodColNo, periodRowNo).getContents().trim();
+
+                    String periodSplit[] = cellContent.split(" ");
+
+                    String sDateString;
+
+                    String eDateString;
+
+                    Period selectedPeriod = null;
+
+                    if (periodSplit.length < 3)
+                    {
+                        System.out.println("* ERROR: Wrong DATE FORMAT");
+                        System.exit(1);
+                    }
+                    else
+                    {
+                        sDateString = periodSplit[1].trim();
+                        eDateString = periodSplit[3].trim();
+
+                        SimpleDateFormat dateFormat = new SimpleDateFormat("dd/mm/yyyy");
+
+                        Date convertedStartDate = dateFormat.parse(sDateString);
+                        Date convertedEndDate = dateFormat.parse(eDateString);
+
+                        PeriodType periodType = periodService.getPeriodTypeByName(selectedPeriodicity);
+
+                        selectedPeriod = getSelectedPeriod(convertedStartDate, periodType);
+                    }
+
+                    NodeList listOfDeCodes = doc.getElementsByTagName("cell-info");
+                    int totalDeCodes = listOfDeCodes.getLength();
+
+                    for (int s = 0; s < totalDeCodes; s++) {
+                        Element deCodeElement = (Element) listOfDeCodes.item(s);
+                        NodeList textDeCodeList = deCodeElement.getChildNodes();
+                        String deCodeExpression = ((Node) textDeCodeList.item(0)).getNodeValue().trim();
+                        Integer sheetNo = Integer.parseInt(deCodeElement.getAttribute("sheetno"));
+                        Integer rowNo = Integer.parseInt(deCodeElement.getAttribute("rowno"));
+                        Integer colNo = Integer.parseInt(deCodeElement.getAttribute("colno"));
+                        String type = deCodeElement.getAttribute("type");
+                        Integer ouCode = 0;
+                        if (type.equalsIgnoreCase("OU-DE")) {
+                            ouCode = Integer.parseInt(deCodeElement.getAttribute("oucode"));
+                        }
+
+                        ExcelImport_OUDeCode excelImport_ouDeCode = new ExcelImport_OUDeCode(sheetNo, rowNo, colNo, deCodeExpression, ouCode);
+
+                        excelImport_ouDeCodeList.add(excelImport_ouDeCode);
+
+                    }
+
+                    String checkForEntry = new String();
+                    String InsertQuery = new String();
+                    String UpdateQuery = new String();
+
+                    DatabaseInfo dataBaseInfo = databaseInfoProvider.getDatabaseInfo();
+
+                    System.out.println("* INFO IMPORT LIST SIZE [" + excelImport_ouDeCodeList.size() + "]");
+
+                    for (ExcelImport_OUDeCode excelImport_ouDeCode : excelImport_ouDeCodeList) {
+
+                        Integer dataElementId = 0;
+
+                        Integer optionComboId = 0;
+
+                        Integer ouCode = excelImport_ouDeCode.getOuCode();
+
+                        Integer dataCellRowNo = excelImport_ouDeCode.getRowno();
+
+                        Integer dataCellCollNo = excelImport_ouDeCode.getColno();
+
+                        int selectedPeriodID = selectedPeriod.getId();
+
+
+                        if (!excelImport_ouDeCode.getExpression().contains("."))
+                        {
+                            System.out.println("* ERROR: WRONG DATAELEMENT EXPRESSION FORMAT [" + excelImport_ouDeCode.getExpression() + "]");
+                            System.exit(1);
+                        }
+                        else
+                        {
+                            dataElementId = Integer.parseInt(excelImport_ouDeCode.getExpression().substring(0, (excelImport_ouDeCode.getExpression().indexOf('.'))));
+                            optionComboId = Integer.parseInt(excelImport_ouDeCode.getExpression().substring((excelImport_ouDeCode.getExpression().indexOf('.') + 1), (excelImport_ouDeCode.getExpression().length())));
+                        }
+
+
+                        if (dataBaseInfo.getType().equalsIgnoreCase("postgresql")) {
+                            checkForEntry = "SELECT COUNT(*) FROM datavalue WHERE dataelementid = "
+                                    + dataElementId + " AND categoryoptioncomboid = " + optionComboId + " AND periodid = "
+                                    + selectedPeriodID + " AND sourceid = " + ouCode;
+                        } else if (dataBaseInfo.getType().equalsIgnoreCase("mysql")) {
+
+                            checkForEntry = "SELECT COUNT(*) FROM datavalue WHERE dataelementid = "
+                                    + dataElementId + " AND categoryoptioncomboid = " + optionComboId + " AND periodid = "
+                                    + selectedPeriodID + " AND sourceid = " + ouCode;
+                        }
+
+                        int preEntryCount = -1;
+
+                        preEntryCount = jdbcTemplate.queryForInt(checkForEntry);
+
+
+                        double dataValue = Double.parseDouble(importFileSheet.getCell(dataCellCollNo, dataCellRowNo).getContents().trim());
+
+                        int isInserted = 0;
+
+                        int isUpdated = 0;
+
+                        if (preEntryCount == 0) {
+                            if (dataBaseInfo.getType().equalsIgnoreCase("postgresql")) {
+                                InsertQuery = "INSERT INTO datavalue (dataelementid,categoryoptioncomboid,periodid,sourceid) VALUES("
+                                        + dataElementId + "," + optionComboId + ","
+                                        + selectedPeriodID + "," + ouCode + ")";
+                            } else if (dataBaseInfo.getType().equalsIgnoreCase("mysql")) {
+
+                                InsertQuery = "INSERT INTO datavalue (dataelementid,categoryoptioncomboid,periodid,sourceid) VALUES("
+                                        + dataElementId + "," + optionComboId + ","
+                                        + selectedPeriodID + "," + ouCode + ")";
+                            }
+
+                            isInserted = jdbcTemplate.update(InsertQuery);
+
+                            if (isInserted == 0) {
+                                System.out.println("* WARNING : INSERT Operation FAILED");
+                            }
+
+                        }
+                        else if (preEntryCount == 1) {
+                            if (dataBaseInfo.getType().equalsIgnoreCase("postgresql")) {
+                                UpdateQuery = "UPDATE datavalue SET value=" + dataValue + " WHERE dataelementid = "
+                                        + dataElementId + " AND categoryoptioncomboid = " + optionComboId + " AND periodid = "
+                                        + selectedPeriodID + " AND sourceid = " + ouCode;
+                            } else if (dataBaseInfo.getType().equalsIgnoreCase("mysql")) {
+
+                                UpdateQuery = "UPDATE datavalue SET value=" + dataValue + " WHERE dataelementid = "
+                                        + dataElementId + " AND categoryoptioncomboid = " + optionComboId + " AND periodid = "
+                                        + selectedPeriodID + " AND sourceid = " + ouCode;
+
+                            }
+
+                            isUpdated = jdbcTemplate.update(UpdateQuery);
+
+                            if (isUpdated == 0) {
+                                System.out.println("* WARNING : UPDATE Operation FAILED");
+                            }
+                        }
+
+
+                    }
+
+                } catch (SAXParseException err) {
+                    System.out.println("** Parsing error" + ", line " + err.getLineNumber() + ", uri " + err.getSystemId());
+                    System.out.println(" " + err.getMessage());
+                } catch (SAXException e) {
+                    Exception x = e.getException();
+                    ((x == null) ? e : x).printStackTrace();
+                } catch (Throwable t) {
+                    t.printStackTrace();
+                }
+            }
+        }
+
+    }
+
+
+    public boolean validateReport(Workbook excelImportFile, Workbook excelTemplateFile, String templateName) {
+
+        boolean validator = true;
+
+        final int sheetNumber = 0;
+
+        for (BDImportSheet importSheet : excelImportSheetList) {
+
+            if (importSheet.getCheckTemplateName().equals(templateName)) {
+
+                String checkRangeForHeader = importSheet.getCheckRangeForHeader();
+
+                String checkRangeForData = importSheet.getCheckRangeForHeader();
+
+                String headerParts[] = checkRangeForHeader.split("-");
+                int headerStartRow = Integer.parseInt(headerParts[0].split(",")[0]);
+                int headerEndRow = Integer.parseInt(headerParts[1].split(",")[0]);
+                int headerStartCol = Integer.parseInt(headerParts[0].split(",")[1]);
+                int headerEndCol = Integer.parseInt(headerParts[1].split(",")[1]);
+
+                String dataParts[] = checkRangeForData.split("-");
+                int dataStartRow = Integer.parseInt(dataParts[0].split(",")[0]);
+                int dataEndRow = Integer.parseInt(dataParts[1].split(",")[0]);
+                int dataStartCol = Integer.parseInt(dataParts[0].split(",")[1]);
+                int dataEndCol = Integer.parseInt(dataParts[1].split(",")[1]);
+
+                System.out.println("* INFO: VALIDATING IMPORTED FILE [" + excelImportFile.getSheet(sheetNumber).getName() + "]" + "AGAINST TEMPLATE [" + excelTemplateFile.getSheet(sheetNumber).getName() + "]");
+
+                Sheet importFileSheet = excelImportFile.getSheet(sheetNumber);
+                Sheet templateFileSheet = excelTemplateFile.getSheet(sheetNumber);
+
+                if (excelImportFile.getSheet(sheetNumber).getRows() == excelTemplateFile.getSheet(sheetNumber).getRows()) {
+
+                    //-------------------------------- Checking Header Cells ---------------------------------------------
+
+                    for (int c = headerStartCol; c <= headerEndCol; c++) {
+                        for (int r = headerStartRow; r <= headerEndRow; r++) {
+
+                            String cellContent = importFileSheet.getCell(c, r).getContents();
+                            String templateContent = templateFileSheet.getCell(c, r).getContents();
+
+                            if (templateContent.equalsIgnoreCase(cellContent) && cellContent.equalsIgnoreCase(templateContent)) {
+                                continue;
+                            } else {
+                                System.out.println("[" + cellContent + "|" + templateContent + "]");
+                                validator = false;
+                                break;
+                            }
+                        }
+                    }
+
+                    //--------------------------------- Checking Data Cells ----------------------------------------------
+
+                    for (int c = dataStartCol; c <= dataEndCol; c++) {
+                        for (int r = dataStartRow; r <= dataEndRow; r++) {
+                            String cellContent = importFileSheet.getCell(c, r).getContents();
+                            String templateContent = templateFileSheet.getCell(c, r).getContents();
+
+                            if (templateContent.equalsIgnoreCase(cellContent) && cellContent.equalsIgnoreCase(templateContent)) {
+                                continue;
+                            } else {
+                                System.out.println("[" + cellContent + "|" + templateContent + "]");
+                                validator = false;
+                                break;
+                            }
+                        }
+                    }
+                } else {
+                    System.out.println("* FAILURE :Validation failed due to unequal count of rows.");
+                    validator = false;
+                }
+
+            }
+
+        }
+
+        return validator;
+    }
+
+
+    public Period getSelectedPeriod(Date startDate, PeriodType periodType) throws Exception {
+
+
+        List<Period> periods = new ArrayList<Period>(periodService.getPeriodsByPeriodType(periodType));
+
+        for (Period period : periods)
+        {
+            Date tempDate = period.getStartDate();
+            if (tempDate.equals(startDate))
+            {
+                return period;
+            }
+        }
+
+        Period period = periodType.createPeriod(startDate);
+        period = reloadPeriodForceAdd(period);
+
+        return period;
+    }
+
+    private final Period reloadPeriod(Period period) {
+        return periodService.getPeriod(period.getStartDate(), period.getEndDate(), period.getPeriodType());
+    }
+
+    private final Period reloadPeriodForceAdd(Period period) {
+        Period storedPeriod = reloadPeriod(period);
+
+        if (storedPeriod == null) {
+
+            periodService.addPeriod(period);
+
+            return period;
+        }
+
+        return storedPeriod;
+    }
+
+    public void importData(File fileToImport) throws Exception, IOException, WriteException {
+
+        raFolderName = reportService.getRAFolderName();
+
+        excelImportSheetList = new ArrayList<BDImportSheet>();
+
+        getExcelImportSheetList("BDDataImportSheetList.xml");
+
+
+        System.out.println("\n========================================== EMAIL IMPORT TESTING=============================================");
+
+        System.out.println("* INFO: TemplateName [" + fileToImport.getName() + "]");
+
+
+        String excelTemplatePath = System.getenv("DHIS2_HOME") + File.separator + raFolderName + File.separator
+                + "excelimport" + File.separator + "template" + File.separator + fileToImport.getName();
+
+        String outputReportPath = System.getenv("DHIS2_HOME") + File.separator + raFolderName + File.separator + "output" + File.separator + UUID.randomUUID().toString() + ".xls";
+
+
+        Workbook excelImportFile = Workbook.getWorkbook(fileToImport);
+
+        WritableWorkbook writableExcelImportFile = Workbook.createWorkbook(new File(outputReportPath), excelImportFile);
+
+        Workbook excelTemplateFile = Workbook.getWorkbook(new File(excelTemplatePath));
+
+        if (validateReport(excelImportFile, excelTemplateFile, fileToImport.getName())) {
+
+            System.out.println("* INFO: Uploaded ExcelSheet is matched with Template file.");
+
+            importPortalData(writableExcelImportFile, fileToImport.getName());
+
+        } else {
+
+            System.out.println("* WARNING: The file you are trying to import is not the correct format");
+        }
+
+        try {
+
+        } finally {
+            excelImportFile.close();
+            excelTemplateFile.close();
+            writableExcelImportFile.close();
+        }
+
+        System.out.println("==========================================DONE-TESTING=============================================\n");
+
+    }
+
+
+    public void extractXLSToImport() {
+
+
+        Properties props = System.getProperties();
+
+
+        props.setProperty("mail.store.protocol", "imaps");
+
+        try {
+
+            Session session = Session.getDefaultInstance(props, null);
+
+            Store store = session.getStore(EMAIL_PROTOCOL);
+
+            store.connect(HOST_SERVER,USERNAME,PASSWORD);
+
+            System.out.println("* INFO: EMAIL IMPORT SERVICE STARTED FOR STORE ["+store+"] AT " + new Date().toString());
+
+            Folder inbox = store.getFolder(SERVER_FOLDER_NAME);
+
+            inbox.open(Folder.READ_WRITE);
+
+            Message messages[] = inbox.search(new FlagTerm(new Flags(Flags.Flag.SEEN), false));;
+
+            int j = 0;
+
+            for (Message message : messages) {
+
+                Multipart multipart = (Multipart) message.getContent();
+
+                inbox.setFlags(new Message[]{message}, new Flags(Flags.Flag.SEEN), true);
+
+                for (int i = 0, n = multipart.getCount(); i < n; i++) {
+
+                    Part part = multipart.getBodyPart(i);
+
+                    if (Part.ATTACHMENT.equalsIgnoreCase(part.getDisposition()) && message.getSubject().contains(FILTER_TEXT) && part.getFileName().endsWith(".xls"))  {
+                        ++j;
+
+                        System.out.println("\n--------------------------(" + j + ")---------------------------");
+                        System.out.println("* SUBJECT: " + message.getSubject() + "[1]");
+                        System.out.println("* FROM   : " + ((InternetAddress)message.getFrom()[0]).getAddress());
+                        System.out.println("* DATE   : " + message.getReceivedDate().toString());
+                        System.out.println("* INFO   : Attachment File Found [" + part.getFileName() + "]");
+                        System.out.println("* INFO   : File Details [" + part.getContentType() + " , [" + (int) ((((float) part.getSize()) / 1024.0) + 0.5) + "] KB ]");
+
+                        try
+                        {
+                            saveFile(part.getFileName(), part.getInputStream());
+
+                            ++importCount;
+
+                        }
+
+                        catch (Exception e)
+                        {
+                            e.printStackTrace();
+                        }
+                    }
+                }
+            }
+
+
+            System.out.println("* INFO: EMAIL OPERATION FINISHED WITH TOTAL [ "+importCount+" ] ATTACHMENT IMPORTS.");
+            System.out.println();
+
+            inbox.close(true);
+
+            store.close();
+
+
+        } catch (NoSuchProviderException e) {
+            e.printStackTrace();
+            System.exit(1);
+        } catch (MessagingException e) {
+            e.printStackTrace();
+            System.exit(2);
+        } catch (IOException e) {
+            e.printStackTrace();
+            System.exit(2);
+        }
+    }
+
+}

=== added file 'local/in/dhis-web-excelimport/src/main/java/org/hisp/dhis/excelimport/util/BDImportSheet.java'
--- local/in/dhis-web-excelimport/src/main/java/org/hisp/dhis/excelimport/util/BDImportSheet.java	1970-01-01 00:00:00 +0000
+++ local/in/dhis-web-excelimport/src/main/java/org/hisp/dhis/excelimport/util/BDImportSheet.java	2012-08-18 11:15:26 +0000
@@ -0,0 +1,98 @@
+package org.hisp.dhis.excelimport.util;
+
+import java.io.Serializable;
+
+public class BDImportSheet implements Serializable
+{
+    private String xmlTemplateName;
+    private String displayName;
+    private String periodicity;
+    private String checkTemplateName;
+    private String checkRangeForHeader;
+    private String checkRangeForData;
+
+
+    // -------------------------------------------------------------------------
+    // Constructors
+    // -------------------------------------------------------------------------
+
+    public BDImportSheet()
+    {
+
+    }
+
+    public BDImportSheet(String xmlTemplateName, String displayName, String periodicity, String checkTemplateName, String checkRangeForHeader, String checkRangeForData)
+    {
+        this.xmlTemplateName = xmlTemplateName;
+        this.displayName = displayName;
+        this.periodicity = periodicity;
+        this.checkTemplateName = checkTemplateName;
+        this.checkRangeForHeader = checkRangeForHeader;
+        this.checkRangeForData = checkRangeForData;
+    }
+
+    // -------------------------------------------------------------------------
+    // Getters and setters
+    // -------------------------------------------------------------------------
+
+    public String getXmlTemplateName()
+    {
+        return xmlTemplateName;
+    }
+
+    public void setXmlTemplateName( String xmlTemplateName )
+    {
+        this.xmlTemplateName = xmlTemplateName;
+    }
+
+    public String getDisplayName()
+    {
+        return displayName;
+    }
+
+    public void setDisplayName( String displayName )
+    {
+        this.displayName = displayName;
+    }
+
+    public String getPeriodicity()
+    {
+        return periodicity;
+    }
+
+    public void setPeriodicity( String periodicity )
+    {
+        this.periodicity = periodicity;
+    }
+
+    public String getCheckTemplateName()
+    {
+        return checkTemplateName;
+    }
+
+    public void setCheckTemplateName(String checkTemplateName)
+    {
+        this.checkTemplateName = checkTemplateName;
+    }
+
+    public String getCheckRangeForHeader()
+    {
+        return checkRangeForHeader;
+    }
+
+    public void setCheckRangeForHeader(String checkRangeForHeader)
+    {
+        this.checkRangeForHeader = checkRangeForHeader;
+    }
+
+    public String getCheckRangeForData()
+    {
+        return checkRangeForData;
+    }
+
+    public void setCheckRangeForData(String checkRangeForData)
+    {
+        this.checkRangeForData = checkRangeForData;
+    }
+
+}

=== added file 'local/in/dhis-web-excelimport/src/main/java/org/hisp/dhis/excelimport/util/ExcelImport_OUDeCode.java'
--- local/in/dhis-web-excelimport/src/main/java/org/hisp/dhis/excelimport/util/ExcelImport_OUDeCode.java	1970-01-01 00:00:00 +0000
+++ local/in/dhis-web-excelimport/src/main/java/org/hisp/dhis/excelimport/util/ExcelImport_OUDeCode.java	2012-08-18 11:15:26 +0000
@@ -0,0 +1,102 @@
+package org.hisp.dhis.excelimport.util;
+
+public class ExcelImport_OUDeCode
+{
+    /**
+     * Sheet number
+     */
+    private int sheetno;
+
+    /**
+     * Row number
+     */
+    private int rowno;
+
+    /**
+     * Column number
+     */
+    private int colno;
+
+    /**
+     * Formula to calculate the values.
+     */
+    private String expression;
+
+    /**
+     * Organisation Unit Code.
+     */
+    private int ouCode;
+
+
+    // -------------------------------------------------------------------------
+    // Constructors
+    // -------------------------------------------------------------------------
+
+    public ExcelImport_OUDeCode()
+    {
+
+    }
+
+    public ExcelImport_OUDeCode(int sheetno, int rowno, int colno, String expression, int ouCode)
+    {
+        this.sheetno = sheetno;
+        this.rowno = rowno;
+        this.colno = colno;
+        this.expression = expression;
+        this.ouCode = ouCode;
+
+    }
+
+    // -------------------------------------------------------------------------
+    // Getters and setters
+    // -------------------------------------------------------------------------
+
+    public int getSheetno()
+    {
+        return sheetno;
+    }
+
+    public void setSheetno( int sheetno )
+    {
+        this.sheetno = sheetno;
+    }
+
+    public int getRowno()
+    {
+        return rowno;
+    }
+
+    public void setRowno( int rowno )
+    {
+        this.rowno = rowno;
+    }
+
+    public int getColno()
+    {
+        return colno;
+    }
+
+    public void setColno( int colno )
+    {
+        this.colno = colno;
+    }
+
+    public String getExpression()
+    {
+        return expression;
+    }
+
+    public void setExpression( String expression )
+    {
+        this.expression = expression;
+    }
+
+    public int getOuCode() {
+        return ouCode;
+    }
+
+    public void setOuCode(int ouCode) {
+        this.ouCode = ouCode;
+    }
+
+}

=== modified file 'local/in/dhis-web-excelimport/src/main/resources/META-INF/dhis/beans.xml'
--- local/in/dhis-web-excelimport/src/main/resources/META-INF/dhis/beans.xml	2012-03-19 06:11:45 +0000
+++ local/in/dhis-web-excelimport/src/main/resources/META-INF/dhis/beans.xml	2012-08-18 11:15:26 +0000
@@ -43,8 +43,28 @@
         <property name="organisationUnitService" ref="org.hisp.dhis.organisationunit.OrganisationUnitService" />
         <property name="organisationUnitGroupService" ref="org.hisp.dhis.organisationunit.OrganisationUnitGroupService" />
         <property name="currentUserService" ref="org.hisp.dhis.user.CurrentUserService" />
-        <!--<property name="dataSetLockService" ref="org.hisp.dhis.datalock.DataSetLockService" />-->
-        <property name="dataSetService" ref="org.hisp.dhis.dataset.DataSetService" />
+        <property name="dataSetService" ref="org.hisp.dhis.dataset.DataSetService" />
+    </bean>
+
+    <!-- BD Data Import -->
+
+    <bean id="org.hisp.dhis.excelimport.bddataimport.action.BDExcelImportFormAction"
+          class="org.hisp.dhis.excelimport.bddataimport.action.BDExcelImportFormAction"
+          scope="prototype">
+        <property name="reportService" ref="org.hisp.dhis.excelimport.util.ReportService" />
+    </bean>
+
+    <bean id="org.hisp.dhis.excelimport.bddataimport.action.BDExcelImportResultAction"
+          class="org.hisp.dhis.excelimport.bddataimport.action.BDExcelImportResultAction"
+          scope="prototype">
+        <property name="reportService" ref="org.hisp.dhis.excelimport.util.ReportService" />
+        <property name="periodService" ref="org.hisp.dhis.period.PeriodService" />
+        <property name="jdbcTemplate" ref="jdbcTemplate" />
+        <property name="organisationUnitService" ref="org.hisp.dhis.organisationunit.OrganisationUnitService" />
+        <property name="organisationUnitGroupService" ref="org.hisp.dhis.organisationunit.OrganisationUnitGroupService" />
+        <property name="currentUserService" ref="org.hisp.dhis.user.CurrentUserService" />
+        <property name="dataSetService" ref="org.hisp.dhis.dataset.DataSetService" />
+        <property name="databaseInfoProvider" ref="databaseInfoProvider" />
     </bean>
     
     <!-- TCS Data Import -->
@@ -61,7 +81,6 @@
         <property name="jdbcTemplate" ref="jdbcTemplate" />
         <property name="organisationUnitService" ref="org.hisp.dhis.organisationunit.OrganisationUnitService" />
         <property name="currentUserService" ref="org.hisp.dhis.user.CurrentUserService" />
-        <!--<property name="dataSetLockService" ref="org.hisp.dhis.datalock.DataSetLockService" />-->
         <property name="dataSetService" ref="org.hisp.dhis.dataset.DataSetService" />
     </bean>
     
@@ -110,6 +129,48 @@
             <ref bean="org.hisp.dhis.dataset.DataSetService"/>
         </property>
     </bean>
+
+    <bean id="org.hisp.dhis.excelimport.emaildataimport.importEmailAttachmentData"
+          class="org.hisp.dhis.excelimport.emaildataimport.importEmailAttachmentData">
+         <property name="reportService" ref="org.hisp.dhis.excelimport.util.ReportService" />
+         <property name="periodService" ref="org.hisp.dhis.period.PeriodService" />
+         <property name="jdbcTemplate" ref="jdbcTemplate" />
+         <property name="databaseInfoProvider" ref="databaseInfoProvider" />
+    </bean>
+
+    <!-- Task Scheduling -->
+
+    <bean id="schedulerTask"
+          class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
+        <property name="targetObject" ref="org.hisp.dhis.excelimport.emaildataimport.importEmailAttachmentData"/>
+        <property name="targetMethod" value="extractXLSToImport"/>
+    </bean>
+
+
+    <!-- Simple Trigger, run every 60 seconds -->
+
+    <bean id="simpleTrigger"
+          class="org.springframework.scheduling.quartz.SimpleTriggerBean">
+
+        <property name="jobDetail" ref="schedulerTask"/>
+        <property name="repeatInterval" value="60000"/>
+        <property name="startDelay" value="1000"/>
+
+    </bean>
+
+    <bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
+        <property name="jobDetails">
+            <list>
+                <ref bean="schedulerTask"/>
+            </list>
+        </property>
+
+        <property name="triggers">
+            <list>
+                <ref bean="simpleTrigger"/>
+            </list>
+        </property>
+    </bean>
     
     <!-- Report Service -->
     <bean id="org.hisp.dhis.excelimport.util.ReportService"

=== modified file 'local/in/dhis-web-excelimport/src/main/resources/struts.xml'
--- local/in/dhis-web-excelimport/src/main/resources/struts.xml	2011-04-15 11:43:00 +0000
+++ local/in/dhis-web-excelimport/src/main/resources/struts.xml	2012-08-18 11:15:26 +0000
@@ -64,6 +64,23 @@
         <interceptor-ref name="fileUploadStack"/>
     </action>
 
+    <!-- BDExcel Data Import -->
+        <action name="BDDataImportForm"
+                class="org.hisp.dhis.excelimport.bddataimport.action.BDExcelImportFormAction">
+            <result name="success" type="velocity">/main.vm</result>
+            <param name="page">/dhis-web-excelimport/BDDataImportForm.vm</param>
+            <param name="menu">/dhis-web-excelimport/menu.vm</param>
+            <param name="javascripts">javascript/hashtable.js</param>
+            <param name="stylesheets">css/StylesForTags.css</param>
+        </action>
+
+        <action name="BDExcelImportResult" class="org.hisp.dhis.excelimport.bddataimport.action.BDExcelImportResultAction">
+            <result name="success" type="velocity">/main.vm</result>
+            <param name="page">/dhis-web-excelimport/BDDataImportResult.vm</param>
+            <param name="menu">/dhis-web-excelimport/menu.vm</param>
+            <interceptor-ref name="fileUploadStack"/>
+        </action>
+
     <!-- TCS Data Import -->
     <action name="tcsDataImportForm"
         class="org.hisp.dhis.excelimport.tcs.action.TCSXmlImportFormAction">

=== added file 'local/in/dhis-web-excelimport/src/main/webapp/dhis-web-excelimport/BDDataImportForm.vm'
--- local/in/dhis-web-excelimport/src/main/webapp/dhis-web-excelimport/BDDataImportForm.vm	1970-01-01 00:00:00 +0000
+++ local/in/dhis-web-excelimport/src/main/webapp/dhis-web-excelimport/BDDataImportForm.vm	2012-08-18 11:15:26 +0000
@@ -0,0 +1,140 @@
+<style>
+    #overlay {
+        z-index: 9998;
+        position: absolute;
+        top: 0;
+        bottom: 0;
+        left: 0;
+        width: 100%;
+        background: #000;
+        opacity: 0.45;
+        -moz-opacity: 0.45;
+        filter: alpha(opacity = 45);
+        visibility: hidden;
+    }
+
+    #overlayImg {
+        width: 50px;
+        height: 50px;
+        z-index: 9999;
+        position: absolute;
+        left: 50%
+    }
+</style>
+
+<div id="overlay">
+    <div id="overlayImg"><img width="50" height="50" src="images/ajax-loader.gif"/></div>
+</div>
+
+<script>
+
+    //Global Variables
+    var checkTemplateNames = new HashTable();
+    var checkRangeForHeaders = new HashTable();
+    var checkRangeForData = new HashTable();
+    var periodicityTable = new HashTable();
+
+        #foreach ( $excelImportSheet in $excelImportSheetList )
+        var excelImportSheetId = "" + "$excelImportSheet.xmlTemplateName";
+        checkTemplateNames.put(excelImportSheetId, "$excelImportSheet.checkTemplateName");
+        checkRangeForHeaders.put(excelImportSheetId, "$excelImportSheet.checkRangeForHeader");
+        checkRangeForData.put(excelImportSheetId, "$excelImportSheet.checkRangeForData");
+        periodicityTable.put(excelImportSheetId, "$excelImportSheet.periodicity");
+        #end
+
+    function formValidations() {
+        var importSheetList = document.getElementById("importSheetId");
+        var importSheetListSelectedIndex = importSheetList.selectedIndex;
+
+        if (importSheetListSelectedIndex < 0 || importSheetList.options[importSheetListSelectedIndex].text == null) {
+            alert("Please Select Import Sheet");
+            return false;
+        }
+
+        document.dataImportForm.checkTemplateName.value = checkTemplateNames.get(importSheetList.options[importSheetListSelectedIndex].value);
+        document.dataImportForm.checkRangeForHeader.value = checkRangeForHeaders.get(importSheetList.options[importSheetListSelectedIndex].value);
+        document.dataImportForm.checkRangeForData.value = checkRangeForData.get(importSheetList.options[importSheetListSelectedIndex].value);
+        document.dataImportForm.selectedPeriodicity.value = periodicityTable.get(importSheetList.options[importSheetListSelectedIndex].value);
+
+        showOverlay();
+
+        return true;
+    }
+
+    function showOverlay() {
+        var o = document.getElementById('overlay');
+        o.style.visibility = 'visible';
+        jQuery("#overlay").css({
+            "height":jQuery(document).height()
+        });
+        jQuery("#overlayImg").css({
+            "top":jQuery(window).height() / 2
+        });
+    }
+    function hideOverlay() {
+        var o = document.getElementById('overlay');
+        o.style.visibility = 'hidden';
+    }
+
+</script>
+<div>
+    <h3>Bangladesh Data Import Form</h3>
+</div>
+<hr/><br/>
+
+<table align="center" style=" border-collapse: collapse; margin-top: 0;" cellpadding="10" cellspacing="100" border="0">
+    <tr>
+        <td>
+            <img width="200" height="200" src="images/bangladesh-flag-map.gif"/>
+        </td>
+        <td>
+            <form id="dataImportForm" name="dataImportForm" method="post" enctype="multipart/form-data"
+                  action="BDExcelImportResult.action" onsubmit="formValidations()">
+                <table align="center" style=" border-collapse: collapse; margin-top: 0;" cellpadding="0" cellspacing="0"
+                       width="730"
+                       border="0">
+                    <tr>
+                        <td class="NormalB">
+                            Import Sheets :<br/>
+                            <select id="importSheetId" name="importSheetId" style="width:325px"
+                                    class="{validate:{required:true}}">
+
+                                #foreach ( $excelImportSheet in $excelImportSheetList )
+                                    <option value="$excelImportSheet.xmlTemplateName">$excelImportSheet.displayName</option>
+                                #end
+
+                            </select>
+                        </td>
+                    </tr>
+                    <tr>
+                        <td class="NormalB">&nbsp;</td>
+                    </tr>
+                    <tr>
+                        <td class="NormalB">&nbsp;</td>
+                    </tr>
+                    <tr>
+                        <td class="NormalB">
+                            Upload/Import (XLS) File :<br/>
+                            <input type="file" id="upload" name="upload" size="45" class="{validate:{required:true}}"/>
+                        </td>
+                    </tr>
+                    <tr>
+                        <td class="NormalB">&nbsp;</td>
+                    </tr>
+                    <tr>
+                        <td class="NormalB">&nbsp;</td>
+                    </tr>
+                    <tr>
+                        <td class="NormalB">
+                            <input type="submit" name="importReport" value='Import Data' style="width:325px"/>
+                            <input type="hidden" name="checkTemplateName" id="checkTemplateName"/>
+                            <input type="hidden" name="checkRangeForHeader" id="checkRangeForHeader"/>
+                            <input type="hidden" name="checkRangeForData" id="checkRangeForData"/>
+                            <input type="hidden" name="selectedPeriodicity" id="selectedPeriodicity"/>
+                        </td>
+                    </tr>
+                </table>
+            </form>
+        </td>
+    </tr>
+</table>
\ No newline at end of file

=== added file 'local/in/dhis-web-excelimport/src/main/webapp/dhis-web-excelimport/BDDataImportResult.vm'
--- local/in/dhis-web-excelimport/src/main/webapp/dhis-web-excelimport/BDDataImportResult.vm	1970-01-01 00:00:00 +0000
+++ local/in/dhis-web-excelimport/src/main/webapp/dhis-web-excelimport/BDDataImportResult.vm	2012-08-18 11:15:26 +0000
@@ -0,0 +1,4 @@
+
+<input type="button" value="Back" onclick="window.location.href='BDDataImportForm.action'" />
+<br/><br/>
+<span id="message" style="display:block">$message</span>

=== added file 'local/in/dhis-web-excelimport/src/main/webapp/dhis-web-excelimport/images/bangladesh-flag-map.gif'
Binary files local/in/dhis-web-excelimport/src/main/webapp/dhis-web-excelimport/images/bangladesh-flag-map.gif	1970-01-01 00:00:00 +0000 and local/in/dhis-web-excelimport/src/main/webapp/dhis-web-excelimport/images/bangladesh-flag-map.gif	2012-08-18 11:15:26 +0000 differ
=== modified file 'local/in/dhis-web-excelimport/src/main/webapp/dhis-web-excelimport/menu.vm'
--- local/in/dhis-web-excelimport/src/main/webapp/dhis-web-excelimport/menu.vm	2011-04-15 11:43:00 +0000
+++ local/in/dhis-web-excelimport/src/main/webapp/dhis-web-excelimport/menu.vm	2012-08-18 11:15:26 +0000
@@ -12,5 +12,8 @@
         <li>
             <a href = "tcsDataImportForm.action">Import XML From TNHMIS</a>
         </li>
+        <li>
+            <a href = "BDDataImportForm.action">Bangladesh Data Import Form</a>
+        </li>
     </ul>
 </ul>

=== modified file 'local/in/dhis-web-excelimport/src/main/webapp/dhis-web-excelimport/portalDataImportForm.vm'
--- local/in/dhis-web-excelimport/src/main/webapp/dhis-web-excelimport/portalDataImportForm.vm	2012-05-21 11:48:24 +0000
+++ local/in/dhis-web-excelimport/src/main/webapp/dhis-web-excelimport/portalDataImportForm.vm	2012-08-18 11:15:26 +0000
@@ -36,9 +36,9 @@
 	#foreach ( $excelImportSheet in $excelImportSheetList )
 		var excelImportSheetId = ""+"$excelImportSheet.xmlTemplateName";
 		proformas.put( excelImportSheetId, "$excelImportSheet.proforma" );
-		checkerTemplateNames.put( excelImportSheetId, "$excelImportSheet.checkerTemplateName" );
-		checkerRangeForHeaders.put( excelImportSheetId, "$excelImportSheet.checkerRangeForHeader" );
-        checkerRangeForData.put( excelImportSheetId, "$excelImportSheet.checkerRangeForData" );
+		checkerTemplateNames.put( excelImportSheetId, "$excelImportSheet.checkTemplateName" );
+		checkerRangeForHeaders.put( excelImportSheetId, "$excelImportSheet.checkRangeForHeader" );
+        checkerRangeForData.put( excelImportSheetId, "$excelImportSheet.checkRangeForData" );
         datasetIds.put( excelImportSheetId, "$excelImportSheet.datasetId" );
 		orgunitGroupIds.put( excelImportSheetId, "$excelImportSheet.orgunitGroupId" );
 		facilityStarts.put( excelImportSheetId, "$excelImportSheet.facilityStart" );
@@ -122,9 +122,9 @@
             <td class="NormalB">
                 <input type="submit" name="importReport" value='Import Data' style="width:325px" />
                 <input type="hidden" name="proforma" id="proforma" />
-                <input type="hidden" name="checkerTemplateName" id="checkerTemplateName" />
-                <input type="hidden" name="checkerRangeForHeader" id="checkerRangeForHeader" />
-                <input type="hidden" name="checkerRangeForData" id="checkerRangeForData" />
+                <input type="hidden" name="checkTemplateName" id="checkTemplateName" />
+                <input type="hidden" name="checkRangeForHeader" id="checkRangeForHeader" />
+                <input type="hidden" name="checkRangeForData" id="checkRangeForData" />
                 <input type="hidden" name="datasetId" id="datasetId" />
 				<input type="hidden" name="orgunitGroupId" id="orgunitGroupId" />
 				<input type="hidden" name="facilityStart" id="facilityStart" />