dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #08682
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2139: Cleaning Code in Manpower Module, work in progress
------------------------------------------------------------
revno: 2139
committer: Bharath <chbharathk@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2010-11-22 19:30:26 +0530
message:
Cleaning Code in Manpower Module, work in progress
modified:
dhis-2/dhis-web/dhis-web-commons/src/main/resources/i18n_global.properties
local/bd/dhis-web-linelisting-manpower/src/main/resources/org/hisp/dhis/ll/i18n_module.properties
local/bd/dhis-web-linelisting-manpower/src/main/webapp/dhis-web-linelisting-mp/addLineListGroupForm.vm
local/bd/dhis-web-linelisting-manpower/src/main/webapp/dhis-web-linelisting-mp/form.vm
local/bd/dhis-web-linelisting-manpower/src/main/webapp/dhis-web-linelisting-mp/lineListElements.vm
local/bd/dhis-web-linelisting-manpower/src/main/webapp/dhis-web-linelisting-mp/lineListGroup.vm
local/bd/dhis-web-linelisting-manpower/src/main/webapp/dhis-web-linelisting-mp/menu.vm
local/bd/dhis-web-linelisting-manpower/src/main/webapp/dhis-web-linelisting-mp/menuForLLDataEntry.vm
local/bd/dhis-web-linelisting-manpower/src/main/webapp/dhis-web-linelisting-mp/select.vm
local/bd/dhis-web-linelisting-manpower/src/main/webapp/dhis-web-linelisting-mp/updateLineListGroupForm.vm
local/in/dhis-in-services/dhis-in-service-dbmanager/src/main/java/org/hisp/dhis/dbmanager/mysql/MySQLDataBaseManager.java
--
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 'dhis-2/dhis-web/dhis-web-commons/src/main/resources/i18n_global.properties'
--- dhis-2/dhis-web/dhis-web-commons/src/main/resources/i18n_global.properties 2010-11-20 08:23:34 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/resources/i18n_global.properties 2010-11-22 14:00:26 +0000
@@ -71,6 +71,7 @@
dhis-web-mobile = Mobiles
dhis-web-maintenance-in = Configuration
dhis-web-excelimport = Excel Import
+dhis-web-linelisting-mp = Manpower
patient_attribute_group = Beneficiary Attribute Group
patient_attribute_group_management = Beneficiary Attribute Group Management
=== modified file 'local/bd/dhis-web-linelisting-manpower/src/main/resources/org/hisp/dhis/ll/i18n_module.properties'
--- local/bd/dhis-web-linelisting-manpower/src/main/resources/org/hisp/dhis/ll/i18n_module.properties 2010-10-30 10:08:37 +0000
+++ local/bd/dhis-web-linelisting-manpower/src/main/resources/org/hisp/dhis/ll/i18n_module.properties 2010-11-22 14:00:26 +0000
@@ -377,4 +377,13 @@
contact_no = Contact Number
emer_cont_no = Emergency Contact Number
pdsCode_in_use = This PDS Code is already in use
-reporting_date = Reporting Date
\ No newline at end of file
+reporting_date = Reporting Date
+
+department_management = Department Management
+create_new_department = Create New Department
+edit_department = Update Department
+define_deparment_associations = Define Department Associations
+confirm_delete_department = Are you sure you want to delete this department?
+adding_department_failed = Adding the department failed with the following message
+saving_department_failed = Saving the department failed with the following message
+no_post_selected = No Post Selected
\ No newline at end of file
=== modified file 'local/bd/dhis-web-linelisting-manpower/src/main/webapp/dhis-web-linelisting-mp/addLineListGroupForm.vm'
--- local/bd/dhis-web-linelisting-manpower/src/main/webapp/dhis-web-linelisting-mp/addLineListGroupForm.vm 2010-11-03 13:40:15 +0000
+++ local/bd/dhis-web-linelisting-manpower/src/main/webapp/dhis-web-linelisting-mp/addLineListGroupForm.vm 2010-11-22 14:00:26 +0000
@@ -1,5 +1,5 @@
-<h3>$i18n.getString( "create_new_line_list_group" )</h3>
+<h3>$i18n.getString( "create_new_department" )</h3>
<form id="addLineListGroupElementForm" action="addLineListGroup.action" method="post" onsubmit="return validateAddLineListGroup()">
=== modified file 'local/bd/dhis-web-linelisting-manpower/src/main/webapp/dhis-web-linelisting-mp/form.vm'
--- local/bd/dhis-web-linelisting-manpower/src/main/webapp/dhis-web-linelisting-mp/form.vm 2010-11-19 12:52:40 +0000
+++ local/bd/dhis-web-linelisting-manpower/src/main/webapp/dhis-web-linelisting-mp/form.vm 2010-11-22 14:00:26 +0000
@@ -13,61 +13,61 @@
<form id="LineListDataEntryForm" action="saveValueAction.action" method="post" onsubmit="return calMaxRecords()">
-#set( $count1 = 1 )
-<table width="70%" align="center">
- <tr align="center">
- <th width="10%">Sr.No.</th>
- <th width="40%">DataElement</th>
- <th width="20%">Entry</th>
-
- </tr>
- #set( $dataValueMapKeys = $dataelementMap.keySet() )
- #foreach( $dataValueMapKey in $dataValueMapKeys )
- #set( $dataElementName = $dataelementMap.get( $dataValueMapKey ) )
- #set( $dataValue = $dataValueMap.get( $dataValueMapKey ) )
- <tr>
- <td align="center">$count1</td>
- <td>$dataElementName</td>
- <td align="center"><input type="text" id="$dataValueMapKey" name="$dataValueMapKey" value="$!dataValue.value" onchange="setSancPost(this.value)"/>
- <script>sancPos='$!dataValue.value'; dataValueMapKey='$dataValueMapKey';</script>
- #if( $sactionedPostdataelement == $dataValueMapKey)
- <input type="button" value="Add" onclick="validatePostVacant( '$dataValueMapKey' )">
- #end
- </td>
- <tr>
- #set( $count1 = $count1 + 1 )
- #end
-
-</table>
-
-<table class="listTable" id="listTable" align="centre">
-
-
- <col>
- <col width="20">
- <col width="20">
- <tr>
- <td>$i18n.getString( "filter_by_name" ) : <form style="display:inline" action="none" onsubmit="return false"><div style="inline"><input type="text" onkeyup="filterValues( this.value )"></div></form></td>
- <td></td><td></td>
- </tr>
- <tr>
- <th>$i18n.getString( "name" ) - $i18n.getString( "pdscode" )</th>
- <th colspan="2">$i18n.getString( "operations" )</th>
- </tr>
- <tbody id="list">
- #set( $mark = false )
- #foreach( $employee in $employeeList )
- <tr id="tr${employee.pdsCode}">
- <td#alternate( $mark )>$encoder.htmlEncode( $employee.name ) - $encoder.htmlEncode( $employee.pdsCode )</td>
- <td style="text-align:center"#alternate( $mark )><a href="javascript:showUpdateEmployeePostForm( '$employee.pdsCode' )" title="$i18n.getString( "edit" )"><img src="../images/edit.png" alt="$i18n.getString( "edit" )"></a></td>
- #end
-
- <tbody>
-</table>
+ #set( $count1 = 1 )
+ <table width="70%" align="center">
+ <tr align="center">
+ <th width="10%">Sr.No.</th>
+ <th width="40%">DataElement</th>
+ <th width="20%">Entry</th>
+ </tr>
+ #set( $dataValueMapKeys = $dataelementMap.keySet() )
+ #foreach( $dataValueMapKey in $dataValueMapKeys )
+ #set( $dataElementName = $dataelementMap.get( $dataValueMapKey ) )
+ #set( $dataValue = $dataValueMap.get( $dataValueMapKey ) )
+ <tr>
+ <td align="center">$count1</td>
+ <td>$dataElementName</td>
+ <td align="center"><input type="text" id="$dataValueMapKey" name="$dataValueMapKey" value="$!dataValue.value" onchange="setSancPost(this.value)"/>
+ <script>sancPos='$!dataValue.value'; dataValueMapKey='$dataValueMapKey';</script>
+ #if( $sactionedPostdataelement == $dataValueMapKey)
+ <input type="button" value="Add" onclick="validatePostVacant( '$dataValueMapKey' )">
+ #end
+ </td>
+ <tr>
+ #set( $count1 = $count1 + 1 )
+ #end
+ </table>
+
+ <table class="listTable" id="listTable" align="centre">
+ <col>
+ <col width="20">
+ <col width="20">
+ <tr>
+ <td>$i18n.getString( "filter_by_name" ) : <form style="display:inline" action="none" onsubmit="return false"><div style="inline"><input type="text" onkeyup="filterValues( this.value )"></div></form></td>
+ <td></td><td></td>
+ </tr>
+ <tr>
+ <th>$i18n.getString( "name" ) - $i18n.getString( "pdscode" )</th>
+ <th colspan="2">$i18n.getString( "operations" )</th>
+ </tr>
+ <tbody id="list">
+ #set( $mark = false )
+ #foreach( $employee in $employeeList )
+ <tr id="tr${employee.pdsCode}">
+ <td#alternate( $mark )>$encoder.htmlEncode( $employee.name ) - $encoder.htmlEncode( $employee.pdsCode )</td>
+ <td style="text-align:center"#alternate( $mark )>
+ <a href="javascript:showUpdateEmployeePostForm( '$employee.pdsCode' )" title="$i18n.getString( "edit" )">
+ <img src="../images/edit.png" alt="$i18n.getString( "edit" )" />
+ </a>
+ </td>
+ </tr>
+ #end
+ </tbody>
+ </table>
</form>
+
<script type="text/javascript">
- $calInfo
var counter=0;
var lastRow =0;
var curRow=0;
=== modified file 'local/bd/dhis-web-linelisting-manpower/src/main/webapp/dhis-web-linelisting-mp/lineListElements.vm'
--- local/bd/dhis-web-linelisting-manpower/src/main/webapp/dhis-web-linelisting-mp/lineListElements.vm 2010-10-20 06:14:25 +0000
+++ local/bd/dhis-web-linelisting-manpower/src/main/webapp/dhis-web-linelisting-mp/lineListElements.vm 2010-11-22 14:00:26 +0000
@@ -15,9 +15,6 @@
<tr>
<td>$i18n.getString( "filter_by_name" ): <form style="display:inline" action="none" onsubmit="return false"><div style="inline"><input type="text" onkeyup="filterValues( this.value )"></div></form></td>
<td colspan="5" style="text-align:right">
-<!--
- <input type="button" value="$i18n.getString( "sort" )" onclick="window.location.href='showSortDataSetForm.action'" style="width:80px">
--->
<input type="button" value="$i18n.getString( "add_new" )" onclick="window.location.href='addLineListElementForm.action'" style="width:80px">
</td>
</tr>
=== modified file 'local/bd/dhis-web-linelisting-manpower/src/main/webapp/dhis-web-linelisting-mp/lineListGroup.vm'
--- local/bd/dhis-web-linelisting-manpower/src/main/webapp/dhis-web-linelisting-mp/lineListGroup.vm 2010-10-20 06:14:25 +0000
+++ local/bd/dhis-web-linelisting-manpower/src/main/webapp/dhis-web-linelisting-mp/lineListGroup.vm 2010-11-22 14:00:26 +0000
@@ -1,5 +1,5 @@
-<h3>$i18n.getString( "line_list_group_management" )</h3>
+<h3>$i18n.getString( "department_management" )</h3>
<table class="mainPageTable">
<tr>
@@ -11,8 +11,6 @@
<col width="20">
<col width="20">
<col width="20">
- <col width="20">
- <col width="20">
<tr>
<td>$i18n.getString( "filter_by_name" ): <form style="display:inline" action="none" onsubmit="return false"><div style="inline"><input type="text" onkeyup="filterValues( this.value )"></div></form></td>
<td colspan="6" style="text-align:right"><input type="button" value="$i18n.getString( "add_new" )" onclick="window.location.href='addLineListGroupElementForm.action'" style="width:80px"></td>
@@ -33,12 +31,6 @@
<a href="showUpdateLineListGroupForm.action?id=$lineListGroup.id" title="$i18n.getString( "edit" )"><img src="../images/edit.png" alt="$i18n.getString( "edit" )"></a>
</td>
<td style="text-align:center"#alternate( $mark )>
- <a href="$i18n.getString( "translation_translate" )" title="$i18n.getString( "translation_translate" )" onclick="this.href='javascript:location.href= \'../dhis-web-commons/i18n.action?className=LineListGroup&objectId=$lineListGroup.id&returnUrl=\' + location.href'"><img src="../images/i18n.png" alt="$i18n.getString( "translation_translate" )"></a>
- </td>
- <td style="text-align:center"#alternate( $mark )>
- <a href="javascript:viewDataEntryForm( '$dataSet.id' )" title="$i18n.getString( "design_data_entry_form" )"><img src="../images/edit_layout.png" alt="$i18n.getString( "design_data_entry_form" )"></a>
- </td>
- <td style="text-align:center"#alternate( $mark )>
<a href="javascript:removeLineListGroup( $lineListGroup.id, '$encoder.jsEncode( $lineListGroup.name )' )" title="$i18n.getString( "remove" )"><img src="../images/delete.png" alt="$i18n.getString( "remove" )"></a>
</td>
<td style="text-align:center"#alternate( $mark )>
@@ -75,7 +67,7 @@
<script type="text/javascript">
var none = '$encoder.jsEscape( $i18n.getString( "none" ) , "'" )';
- var i18n_confirm_delete = '$encoder.jsEscape( $i18n.getString( "confirm_delete_line_list_group" ) , "'")';
- var i18n_adding_line_list_group_failed = '$encoder.jsEscape( $i18n.getString( "adding_line_list_group_failed" ) , "'")';
- var i18n_saving_line_list_group_failed = '$encoder.jsEscape( $i18n.getString( "saving_line_list_group_failed" ) , "'")';
+ var i18n_confirm_delete = '$encoder.jsEscape( $i18n.getString( "confirm_delete_department" ) , "'")';
+ var i18n_adding_line_list_group_failed = '$encoder.jsEscape( $i18n.getString( "adding_department_failed" ) , "'")';
+ var i18n_saving_line_list_group_failed = '$encoder.jsEscape( $i18n.getString( "saving_department_failed" ) , "'")';
</script>
=== modified file 'local/bd/dhis-web-linelisting-manpower/src/main/webapp/dhis-web-linelisting-mp/menu.vm'
--- local/bd/dhis-web-linelisting-manpower/src/main/webapp/dhis-web-linelisting-mp/menu.vm 2010-11-22 07:28:23 +0000
+++ local/bd/dhis-web-linelisting-manpower/src/main/webapp/dhis-web-linelisting-mp/menu.vm 2010-11-22 14:00:26 +0000
@@ -1,10 +1,10 @@
<h2>Linelisting Meta Data</h2>
- <ul>
- <li><a href="getLineListOptions.action">Linelist Option</a></li>
- <li><a href="lineListElements.action">Linelist Element</a></li>
- <li><a href="getLineListGroups.action">Linelist Group</a></li>
- <li><a href="getEmployeeList.action">Employee Management</a></li>
- </ul>
+ <ul>
+ <li><a href="getLineListOptions.action">Linelist Option</a></li>
+ <li><a href="lineListElements.action">Linelist Element</a></li>
+ <li><a href="getLineListGroups.action">Department Management</a></li>
+ <li><a href="getEmployeeList.action">Employee Management</a></li>
+ </ul>
<h2>Linelisting DataEntry</h2>
<ul>
<li><a href="select.action">DataEntry</a></li>
=== modified file 'local/bd/dhis-web-linelisting-manpower/src/main/webapp/dhis-web-linelisting-mp/menuForLLDataEntry.vm'
--- local/bd/dhis-web-linelisting-manpower/src/main/webapp/dhis-web-linelisting-mp/menuForLLDataEntry.vm 2010-10-20 06:14:25 +0000
+++ local/bd/dhis-web-linelisting-manpower/src/main/webapp/dhis-web-linelisting-mp/menuForLLDataEntry.vm 2010-11-22 14:00:26 +0000
@@ -9,4 +9,5 @@
<img src="images/goback.png" width="36" height="30" alt="$i18n.getString( "go_back" )"></a>
</div>
+<br/>
#parse( "/dhis-web-commons/ouwt/orgunittree.vm" )
=== modified file 'local/bd/dhis-web-linelisting-manpower/src/main/webapp/dhis-web-linelisting-mp/select.vm'
--- local/bd/dhis-web-linelisting-manpower/src/main/webapp/dhis-web-linelisting-mp/select.vm 2010-11-20 12:16:50 +0000
+++ local/bd/dhis-web-linelisting-manpower/src/main/webapp/dhis-web-linelisting-mp/select.vm 2010-11-22 14:00:26 +0000
@@ -1,18 +1,11 @@
<div id="currentSelection">
#if ( $organisationUnit ) $encoder.htmlEncode( $organisationUnit.name )#else $i18n.getString("no_organisationunit_selected") #end -
#if ( $selectedLineListGroup ) $encoder.htmlEncode( $selectedLineListGroup.name )#else $i18n.getString("no_linelistgroup_selected") #end -
- #set( $period = $selectedStateManager.getSelectedPeriod() )
- #if ( $period ) $format.formatPeriod( $period ) #else $i18n.getString("no_period_selected") #end <br>
+ #if ( $selectedStateManager.getSelectedLineListOption() ) $encoder.htmlEncode( $selectedStateManager.getSelectedLineListOption().name ) #else $i18n.getString("no_post_selected") #end <br>
</div>
<form id="selectForm" name="selectForm" method="post" action="select.action">
-<!--
-<div id="actions" style="width:200px text-align:right">
- <br><br><br>
- <input type="button" value="Save Aggregated Data" onclick="saveLineListingAggData()" #if( $isLineListing.equals("no") ) disabled="disabled" #end disabled>
-</div>
--->
<table>
<tr>
<td><label>$i18n.getString( "organisation_unit" )</label></td>
@@ -61,8 +54,7 @@
<tr #if( !$selectedLineListGroup.getPeriodType().getName().equalsIgnoreCase( "OnChange" ) ) style="display:none" #end>
<td><label for="reportingDate">$i18n.getString( "reporting_date" )</label></td>
<td>
- <input type="text" id="reportingDate" name="reportingDate" value="$curDate" style="width:200px" onchange="setReportedDate()" >
- <img src="../images/calendar_icon.gif" width="16" height="16" id="getReportingDate" cursor: pointer;" title="$i18n.getString( "date_selector" )" onmouseover="this.style.background='orange';" onmouseout="this.style.background=''">
+ <input type="text" id="reportingDate" name="reportingDate" value="$curDate" style="width:200px" >
</td>
</tr>
@@ -73,10 +65,5 @@
<hr style="clear:both;">
<script type="text/javascript">
-
- Calendar.setup({
- inputField : "reportingDate", // id of the input field
- ifFormat : "$i18n.getString("format.date.label")", // format of the input field
- button : "getReportingDate" // trigger for the calendar (button ID)
- });
+ datePickerValid( 'reportingDate', false );
</script>
=== modified file 'local/bd/dhis-web-linelisting-manpower/src/main/webapp/dhis-web-linelisting-mp/updateLineListGroupForm.vm'
--- local/bd/dhis-web-linelisting-manpower/src/main/webapp/dhis-web-linelisting-mp/updateLineListGroupForm.vm 2010-11-03 13:40:15 +0000
+++ local/bd/dhis-web-linelisting-manpower/src/main/webapp/dhis-web-linelisting-mp/updateLineListGroupForm.vm 2010-11-22 14:00:26 +0000
@@ -1,5 +1,5 @@
-<h3>$i18n.getString( "edit_line_list_group" )</h3>
+<h3>$i18n.getString( "edit_department" )</h3>
<form id="showUpdateLineListGroupForm" action="updateLineListGroup.action" method="post" onsubmit="return validateUpdateLineListGroup()">
=== modified file 'local/in/dhis-in-services/dhis-in-service-dbmanager/src/main/java/org/hisp/dhis/dbmanager/mysql/MySQLDataBaseManager.java'
--- local/in/dhis-in-services/dhis-in-service-dbmanager/src/main/java/org/hisp/dhis/dbmanager/mysql/MySQLDataBaseManager.java 2010-11-22 07:28:23 +0000
+++ local/in/dhis-in-services/dhis-in-service-dbmanager/src/main/java/org/hisp/dhis/dbmanager/mysql/MySQLDataBaseManager.java 2010-11-22 14:00:26 +0000
@@ -15,8 +15,6 @@
import java.util.Map;
import java.util.Set;
-import javax.swing.JOptionPane;
-
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hisp.dhis.dbmanager.DataBaseManagerInterface;
@@ -222,17 +220,16 @@
}
return maxRecordNumber;
}
-
-// function for row count
+
+ // -------------------------------------------------------------------------
+ // Get Row Count from Department table
+ // -------------------------------------------------------------------------
public int rowCount( String tableName )
{
int noOfRows = 0;
try
{
- //String rowCount = null;
- //Connection connection = jdbcTemplate.getDataSource().getConnection();
String query = "SELECT COUNT(*) FROM " + tableName;
- // String query = "select * from " + tableName + " ;";
SqlRowSet rs = jdbcTemplate.queryForRowSet( query );
if( rs.next() )
@@ -246,7 +243,10 @@
}
return noOfRows;
}
-
+
+ // -------------------------------------------------------------------------
+ // Update Department table
+ // -------------------------------------------------------------------------
public boolean updateTable( String tableName, List<LineListElement> removeList, List<LineListElement> addList )
{
String columnDefinition = "";
@@ -296,36 +296,33 @@
}
System.out.println( removeList.size() );
- if ( removeList != null )
+ if ( removeList != null && !( removeList.isEmpty() ) )
{
- if ( !( removeList.isEmpty() ) )
+ int j = 1;
+ int size = removeList.size();
+
+ Iterator<LineListElement> removeListItr = removeList.iterator();
+ while ( removeListItr.hasNext() )
{
-
- int j = 1;
- Iterator<LineListElement> removeListItr = removeList.iterator();
- int size = removeList.size();
-
- while ( removeListItr.hasNext() )
- {
- LineListElement element = (LineListElement) removeListItr.next();
- if ( columnAdded )
- {
- columnDefinition += " , drop column " + element.getShortName();
- columnAdded = false;
- } else
- {
- columnDefinition += " drop column " + element.getShortName();
- }
- System.out.println( " element = " + element.getShortName() );
- if ( j < size )
- {
- columnDefinition += " ,";
- j++;
- }
- }
-
- System.out.println( " columnDefinition = " + columnDefinition );
+ LineListElement element = (LineListElement) removeListItr.next();
+ if ( columnAdded )
+ {
+ columnDefinition += " , drop column " + element.getShortName();
+ columnAdded = false;
+ }
+ else
+ {
+ columnDefinition += " drop column " + element.getShortName();
+ }
+ System.out.println( " element = " + element.getShortName() );
+ if ( j < size )
+ {
+ columnDefinition += " ,";
+ j++;
+ }
}
+
+ System.out.println( " columnDefinition = " + columnDefinition );
}
System.out.println( columnDefinition );
@@ -341,9 +338,9 @@
rowUpdated = true;
statement.close();
- } catch ( SQLException e )
+ }
+ catch ( SQLException e )
{
-
rowUpdated = false;
e.printStackTrace();
}
@@ -351,34 +348,32 @@
return rowUpdated;
}
+ // -------------------------------------------------------------------------
+ // Get LineListDataValues from Department table by source and period
+ // -------------------------------------------------------------------------
public List<LineListDataValue> getFromLLTable( String tableName, Source source, Period period )
{
String columnDefinition = "";
- //Statement statement = null;
-
- // creating map of element and its values
+
Map<String, String> llElementValuesMap = new HashMap<String, String>();
-
+
List<LineListDataValue> llDataValues = new ArrayList<LineListDataValue>();
- // LineListDataValue llDataValue = new LineListDataValue();
+
if ( period != null && source != null )
{
- columnDefinition += "select * from " + tableName + " where periodid = " + period.getId() + " and sourceid = " + source.getId() + " order by recordnumber";
+ columnDefinition += "SELECT * FROM " + tableName + " WHERE periodid = " + period.getId() + " AND sourceid = " + source.getId() + " ORDER BY recordnumber";
Collection<LineListElement> elementsCollection = new ArrayList<LineListElement>();
elementsCollection = lineListService.getLineListGroupByShortName( tableName ).getLineListElements();
LineListElement element;
+
String name = "";
try
{
- //Connection connection = jdbcTemplate.getDataSource().getConnection();
- //statement = connection.createStatement( ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE );
- //ResultSet result = statement.executeQuery( columnDefinition );
SqlRowSet result = jdbcTemplate.queryForRowSet( columnDefinition );
- System.out.println( columnDefinition );
if ( result != null )
{
@@ -388,28 +383,24 @@
{
LineListDataValue llDataValue = new LineListDataValue();
llDataValue.setRecordNumber( result.getInt( "recordnumber" ) );
- Iterator it1 = elementsCollection.iterator();
+ Iterator<LineListElement> it1 = elementsCollection.iterator();
while ( it1.hasNext() )
{
element = (LineListElement) it1.next();
name = element.getShortName() + ":" + result.getInt( "recordnumber" );
+
if ( element.getDataType().equalsIgnoreCase( "string" ) )
{
llElementValuesMap.put( name, result.getString( element.getShortName() ) );
- } else
- {
- if ( element.getDataType().equalsIgnoreCase( "date" ) )
- {
- llElementValuesMap.put( name, result.getDate( element.getShortName() ).toString() );
- } else
- {
- if ( element.getDataType().equalsIgnoreCase( "int" ) )
- {
- llElementValuesMap.put( name, Integer.toString( result.getInt( element.getShortName() ) ) );
- }
- }
+ }
+ else if ( element.getDataType().equalsIgnoreCase( "date" ) )
+ {
+ llElementValuesMap.put( name, result.getDate( element.getShortName() ).toString() );
+ }
+ else if ( element.getDataType().equalsIgnoreCase( "int" ) )
+ {
+ llElementValuesMap.put( name, Integer.toString( result.getInt( element.getShortName() ) ) );
}
- //System.out.println("Key = "+name+ "Value = "+llElementValuesMap.get(name));
}
llDataValue.setLineListValues( llElementValuesMap );
@@ -417,11 +408,9 @@
llDataValue.setSource( source );
llDataValues.add( llDataValue );
}
-
}
- //statement.close();
-
- } catch ( Exception e )
+ }
+ catch ( Exception e )
{
e.printStackTrace();
}
@@ -429,19 +418,20 @@
return llDataValues;
}
+ // -------------------------------------------------------------------------
+ // Get LineListDataValues from Department table by source and period and linelist element
+ // -------------------------------------------------------------------------
public List<LineListDataValue> getLLValuesByLLElementValue( String tableName, String llElementName, String llElementValue, Source source, Period period )
{
String columnDefinition = "";
- //Statement statement = null;
- // creating map of element and its values
Map<String, String> llElementValuesMap = new HashMap<String, String>();
List<LineListDataValue> llDataValues = new ArrayList<LineListDataValue>();
- // LineListDataValue llDataValue = new LineListDataValue();
+
if ( period != null && source != null )
{
- columnDefinition += "select * from " + tableName + " where periodid = " + period.getId() + " and sourceid = " + source.getId() + " and " + llElementName + " LIKE '" + llElementValue + "' order by recordnumber";
+ columnDefinition += "SELECT * FROM " + tableName + " WHERE periodid = " + period.getId() + " AND sourceid = " + source.getId() + " AND " + llElementName + " LIKE '" + llElementValue + "' ORDER BY recordnumber";
System.out.println( columnDefinition );
@@ -450,14 +440,12 @@
elementsCollection = lineListService.getLineListGroupByShortName( tableName ).getLineListElements();
LineListElement element;
+
String name = "";
try
{
- //Connection connection = jdbcTemplate.getDataSource().getConnection();
- // statement = connection.createStatement( ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE );
- //ResultSet result = statement.executeQuery( columnDefinition );
- SqlRowSet result = jdbcTemplate.queryForRowSet( columnDefinition );
+ SqlRowSet result = jdbcTemplate.queryForRowSet( columnDefinition );
if ( result != null )
{
@@ -467,7 +455,8 @@
{
LineListDataValue llDataValue = new LineListDataValue();
llDataValue.setRecordNumber( result.getInt( "recordnumber" ) );
- Iterator it1 = elementsCollection.iterator();
+
+ Iterator<LineListElement> it1 = elementsCollection.iterator();
while ( it1.hasNext() )
{
element = (LineListElement) it1.next();
@@ -480,30 +469,26 @@
tempString = "";
}
llElementValuesMap.put( name, tempString );
- } else
- {
- if ( element.getDataType().equalsIgnoreCase( "date" ) )
- {
- Date tempDate = result.getDate( element.getShortName() );
- String tempStr = "";
- if ( tempDate != null )
- {
- tempStr = tempDate.toString();
- }
- llElementValuesMap.put( name, tempStr );
- } else
- {
- if ( element.getDataType().equalsIgnoreCase( "int" ) )
- {
- String tempStr = "";
- Integer tempInt = result.getInt( element.getShortName() );
- if ( tempInt != null )
- {
- tempStr = Integer.toString( tempInt );
- }
- llElementValuesMap.put( name, tempStr );
- }
- }
+ }
+ else if ( element.getDataType().equalsIgnoreCase( "date" ) )
+ {
+ Date tempDate = result.getDate( element.getShortName() );
+ String tempStr = "";
+ if ( tempDate != null )
+ {
+ tempStr = tempDate.toString();
+ }
+ llElementValuesMap.put( name, tempStr );
+ }
+ else if ( element.getDataType().equalsIgnoreCase( "int" ) )
+ {
+ String tempStr = "";
+ Integer tempInt = result.getInt( element.getShortName() );
+ if ( tempInt != null )
+ {
+ tempStr = Integer.toString( tempInt );
+ }
+ llElementValuesMap.put( name, tempStr );
}
}
@@ -512,35 +497,31 @@
llDataValue.setSource( source );
llDataValues.add( llDataValue );
}
-
}
- //statement.close();
-
- } catch ( Exception e )
+ }
+ catch ( Exception e )
{
e.printStackTrace();
}
}
return llDataValues;
-
}
+ // -------------------------------------------------------------------------
+ // Get LineListDataValues from Department table filter by source and period and list of linelist elements
+ // -------------------------------------------------------------------------
public List<LineListDataValue> getLLValuesFilterByLLElements( String tableName, Map<String, String> llElementValueMap, Source source, Period period )
{
String columnDefinition = "";
- //Statement statement = null;
-
- // creating map of element and its values
- //Map<String, String> llElementValuesMap = new HashMap<String, String>();
-
List<LineListDataValue> llDataValues = new ArrayList<LineListDataValue>();
- // LineListDataValue llDataValue = new LineListDataValue();
+
if ( period != null && source != null )
{
- columnDefinition += "select * from " + tableName + " where periodid = " + period.getId() + " and sourceid = " + source.getId();
+ columnDefinition += "SELECT * FROM " + tableName + " WHERE periodid = " + period.getId() + " AND sourceid = " + source.getId();
List<String> llElementNames = new ArrayList<String>( llElementValueMap.keySet() );
+
Iterator<String> llENamesIterator = llElementNames.iterator();
while ( llENamesIterator.hasNext() )
{
@@ -548,23 +529,21 @@
String lleValue = llElementValueMap.get( lleName );
- if ( lleValue.equalsIgnoreCase( "notnull" ) )
+ if( lleValue.equalsIgnoreCase( "notnull" ) )
{
columnDefinition += " and " + lleName + " IS NOT NULL";
- } else
- {
- if ( lleValue.equalsIgnoreCase( "null" ) )
- {
- columnDefinition += " and " + lleName + " IS NULL";
- } else
- {
- columnDefinition += " and " + lleName + " LIKE '" + lleValue + "'";
- }
+ }
+ else if( lleValue.equalsIgnoreCase( "null" ) )
+ {
+ columnDefinition += " and " + lleName + " IS NULL";
+ }
+ else
+ {
+ columnDefinition += " and " + lleName + " LIKE '" + lleValue + "'";
}
}
-
- columnDefinition += " order by recordnumber";
+ columnDefinition += " ORDER BY recordnumber";
System.out.println( columnDefinition );
@@ -573,15 +552,12 @@
elementsCollection = lineListService.getLineListGroupByShortName( tableName ).getLineListElements();
LineListElement element;
+
String name = "";
try
{
- //Connection connection = jdbcTemplate.getDataSource().getConnection();
- //statement = connection.createStatement( ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE );
- //ResultSet result = statement.executeQuery( columnDefinition );
SqlRowSet result = jdbcTemplate.queryForRowSet( columnDefinition );
- //System.out.println(columnDefinition);
if ( result != null )
{
@@ -592,11 +568,10 @@
LineListDataValue llDataValue = new LineListDataValue();
Map<String, String> llElementValuesMap = new HashMap<String, String>();
llDataValue.setRecordNumber( result.getInt( "recordnumber" ) );
- Iterator it1 = elementsCollection.iterator();
+ Iterator<LineListElement> it1 = elementsCollection.iterator();
while ( it1.hasNext() )
{
element = (LineListElement) it1.next();
- //name = element.getShortName() + ":" + result.getInt( "recordnumber" );
name = element.getShortName();
if ( element.getDataType().equalsIgnoreCase( "string" ) )
{
@@ -606,30 +581,26 @@
tempString = "";
}
llElementValuesMap.put( name, tempString );
- } else
- {
- if ( element.getDataType().equalsIgnoreCase( "date" ) )
- {
- Date tempDate = result.getDate( element.getShortName() );
- String tempStr = "";
- if ( tempDate != null )
- {
- tempStr = tempDate.toString();
- }
- llElementValuesMap.put( name, tempStr );
- } else
- {
- if ( element.getDataType().equalsIgnoreCase( "int" ) )
- {
- String tempStr = "";
- Integer tempInt = result.getInt( element.getShortName() );
- if ( tempInt != null )
- {
- tempStr = Integer.toString( tempInt );
- }
- llElementValuesMap.put( name, tempStr );
- }
- }
+ }
+ else if ( element.getDataType().equalsIgnoreCase( "date" ) )
+ {
+ Date tempDate = result.getDate( element.getShortName() );
+ String tempStr = "";
+ if ( tempDate != null )
+ {
+ tempStr = tempDate.toString();
+ }
+ llElementValuesMap.put( name, tempStr );
+ }
+ else if ( element.getDataType().equalsIgnoreCase( "int" ) )
+ {
+ String tempStr = "";
+ Integer tempInt = result.getInt( element.getShortName() );
+ if ( tempInt != null )
+ {
+ tempStr = Integer.toString( tempInt );
+ }
+ llElementValuesMap.put( name, tempStr );
}
}
@@ -638,32 +609,28 @@
llDataValue.setSource( source );
llDataValues.add( llDataValue );
}
-
}
-
- } catch ( Exception e )
+ }
+ catch ( Exception e )
{
e.printStackTrace();
}
}
return llDataValues;
-
}
+ // -------------------------------------------------------------------------
+ // Get LineListDataValues from Department table filter by source and list of linelist elements
+ // -------------------------------------------------------------------------
public List<LineListDataValue> getLLValuesFilterByLLElements( String tableName, Map<String, String> llElementValueMap, Source source )
{
String columnDefinition = "";
- //Statement statement = null;
-
- // creating map of element and its values
- //Map<String, String> llElementValuesMap = new HashMap<String, String>();
-
List<LineListDataValue> llDataValues = new ArrayList<LineListDataValue>();
- // LineListDataValue llDataValue = new LineListDataValue();
+
if ( source != null )
{
- columnDefinition += "select * from " + tableName + " where sourceid = " + source.getId();
+ columnDefinition += "SELECT * FROM " + tableName + " WHERE sourceid = " + source.getId();
List<String> llElementNames = new ArrayList<String>( llElementValueMap.keySet() );
Iterator<String> llENamesIterator = llElementNames.iterator();
@@ -676,20 +643,18 @@
if ( lleValue.equalsIgnoreCase( "notnull" ) )
{
columnDefinition += " and " + lleName + " IS NOT NULL";
- } else
- {
- if ( lleValue.equalsIgnoreCase( "null" ) )
- {
- columnDefinition += " and " + lleName + " IS NULL";
- } else
- {
- columnDefinition += " and " + lleName + " LIKE '" + lleValue + "'";
- }
+ }
+ else if ( lleValue.equalsIgnoreCase( "null" ) )
+ {
+ columnDefinition += " and " + lleName + " IS NULL";
+ }
+ else
+ {
+ columnDefinition += " and " + lleName + " LIKE '" + lleValue + "'";
}
}
-
- columnDefinition += " order by recordnumber";
+ columnDefinition += " ORDER BY recordnumber";
System.out.println( columnDefinition );
@@ -698,15 +663,12 @@
elementsCollection = lineListService.getLineListGroupByShortName( tableName ).getLineListElements();
LineListElement element;
+
String name = "";
try
{
- //Connection connection = jdbcTemplate.getDataSource().getConnection();
- //statement = connection.createStatement( ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE );
- //ResultSet result = statement.executeQuery( columnDefinition );
SqlRowSet result = jdbcTemplate.queryForRowSet( columnDefinition );
- //System.out.println(columnDefinition);
if ( result != null )
{
@@ -717,11 +679,10 @@
LineListDataValue llDataValue = new LineListDataValue();
Map<String, String> llElementValuesMap = new HashMap<String, String>();
llDataValue.setRecordNumber( result.getInt( "recordnumber" ) );
- Iterator it1 = elementsCollection.iterator();
+ Iterator<LineListElement> it1 = elementsCollection.iterator();
while ( it1.hasNext() )
{
element = (LineListElement) it1.next();
- //name = element.getShortName() + ":" + result.getInt( "recordnumber" );
name = element.getShortName();
if ( element.getDataType().equalsIgnoreCase( "string" ) )
{
@@ -731,30 +692,26 @@
tempString = "";
}
llElementValuesMap.put( name, tempString );
- } else
- {
- if ( element.getDataType().equalsIgnoreCase( "date" ) )
- {
- Date tempDate = result.getDate( element.getShortName() );
- String tempStr = "";
- if ( tempDate != null )
- {
- tempStr = tempDate.toString();
- }
- llElementValuesMap.put( name, tempStr );
- } else
- {
- if ( element.getDataType().equalsIgnoreCase( "int" ) )
- {
- String tempStr = "";
- Integer tempInt = result.getInt( element.getShortName() );
- if ( tempInt != null )
- {
- tempStr = Integer.toString( tempInt );
- }
- llElementValuesMap.put( name, tempStr );
- }
- }
+ }
+ else if ( element.getDataType().equalsIgnoreCase( "date" ) )
+ {
+ Date tempDate = result.getDate( element.getShortName() );
+ String tempStr = "";
+ if ( tempDate != null )
+ {
+ tempStr = tempDate.toString();
+ }
+ llElementValuesMap.put( name, tempStr );
+ }
+ else if ( element.getDataType().equalsIgnoreCase( "int" ) )
+ {
+ String tempStr = "";
+ Integer tempInt = result.getInt( element.getShortName() );
+ if ( tempInt != null )
+ {
+ tempStr = Integer.toString( tempInt );
+ }
+ llElementValuesMap.put( name, tempStr );
}
}
@@ -762,25 +719,26 @@
llDataValue.setSource( source );
llDataValues.add( llDataValue );
}
-
}
-
- } catch ( Exception e )
+ }
+ catch ( Exception e )
{
e.printStackTrace();
}
}
+
return llDataValues;
-
}
+ // -------------------------------------------------------------------------
+ // Get LineListDataValueCount from Department table filter by source and list of linelist elements
+ // -------------------------------------------------------------------------
public int getLLValueCountByLLElements( String tableName, Map<String, String> llElementValueMap, Source source )
{
String columnDefinition = "";
int noOfRows = 0;
if ( source != null )
{
- //columnDefinition += "SELECT COUNT(*) FROM " + tableName + " WHERE periodid = " + period.getId() + " AND sourceid = " + source.getId();
columnDefinition += "SELECT COUNT(*) FROM " + tableName + " WHERE sourceid = " + source.getId();
List<String> llElementNames = new ArrayList<String>( llElementValueMap.keySet() );
@@ -794,18 +752,18 @@
if ( lleValue.equalsIgnoreCase( "notnull" ) )
{
columnDefinition += " AND " + lleName + " IS NOT NULL";
- } else
- {
- if ( lleValue.equalsIgnoreCase( "null" ) )
- {
- columnDefinition += " AND " + lleName + " IS NULL";
- } else
- {
- columnDefinition += " AND " + lleName + " LIKE '" + lleValue + "'";
- }
+ }
+ else if ( lleValue.equalsIgnoreCase( "null" ) )
+ {
+ columnDefinition += " AND " + lleName + " IS NULL";
+ }
+ else
+ {
+ columnDefinition += " AND " + lleName + " LIKE '" + lleValue + "'";
}
}
- columnDefinition += " order by recordnumber";
+
+ columnDefinition += " ORDER BY recordnumber";
System.out.println( columnDefinition );
try
@@ -825,22 +783,20 @@
return noOfRows;
}
-
-
-
+ // -------------------------------------------------------------------------
+ // Get LineListDataValues from Department table sort by line list element
+ // -------------------------------------------------------------------------
public List<LineListDataValue> getLLValuesSortBy( String tableName, String sortBy, Source source, Period period )
{
String columnDefinition = "";
- //Statement statement = null;
- // creating map of element and its values
Map<String, String> llElementValuesMap = new HashMap<String, String>();
List<LineListDataValue> llDataValues = new ArrayList<LineListDataValue>();
- // LineListDataValue llDataValue = new LineListDataValue();
+
if ( period != null && source != null )
{
- columnDefinition += "select * from " + tableName + " where periodid = " + period.getId() + " and sourceid = " + source.getId() + " order by " + sortBy;
+ columnDefinition += "SELECT * FROM " + tableName + " WHERE periodid = " + period.getId() + " AND sourceid = " + source.getId() + " ORDER by " + sortBy;
System.out.println( columnDefinition );
@@ -849,22 +805,16 @@
elementsCollection = lineListService.getLineListGroupByShortName( tableName ).getLineListElements();
LineListElement element;
+
String name = "";
try
{
- //Connection connection = jdbcTemplate.getDataSource().getConnection();
-
- //statement = connection.createStatement( ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE );
-
SqlRowSet sqlResultSet = jdbcTemplate.queryForRowSet( columnDefinition );
- //ResultSet result = statement.executeQuery( columnDefinition );
- //System.out.println(columnDefinition);
-
if ( sqlResultSet != null )
{
- sqlResultSet.beforeFirst();
+ sqlResultSet.beforeFirst();
while ( sqlResultSet.next() )
{
@@ -913,10 +863,7 @@
llDataValue.setSource( source );
llDataValues.add( llDataValue );
}
-
}// while loop end
- //result.close();
- //statement.close();
}// Try block end
catch ( Exception e )
{
@@ -926,7 +873,9 @@
return llDataValues;
}
-
+ // -------------------------------------------------------------------------
+ // Insert single LineListDataValue into Department table
+ // -------------------------------------------------------------------------
public boolean insertSingleLLValueIntoDb( LineListDataValue llDataValue, String tableName )
{
boolean updateLLValue = false;
@@ -1007,7 +956,10 @@
return updateLLValue;
}
-
+
+ // -------------------------------------------------------------------------
+ // Insert List of LineListDataValues into Department table
+ // -------------------------------------------------------------------------
public boolean insertLLValueIntoDb( List<LineListDataValue> llDataValuesList, String tableName )
{
boolean updateLLValue = false;
@@ -1016,16 +968,12 @@
for ( LineListDataValue llDataValue : llDataValuesList )
{
-
- columnDefinition = "insert into " + tableName + " (periodid,sourceid,storedby,lastupdated,";
- // get periodid from llDataValue
+ columnDefinition = "INSERT INTO " + tableName + " (periodid,sourceid,storedby,lastupdated,";
Period period = llDataValue.getPeriod();
Source source = llDataValue.getSource();
- // System.out.println(period.getId() + " " + source.getId());
-
Map<String, String> elementValues = llDataValue.getLineListValues();
Set<String> elements = elementValues.keySet();
@@ -1037,17 +985,16 @@
{
Date d = new Date();
t = d.getTime();
- } else
+ }
+ else
{
t = today.getTime();
}
java.sql.Date date = new java.sql.Date( t );
- String values = " values (" + period.getId() + "," + source.getId() + ",'" + llDataValue.getStoredBy() + "','" + date + "',";
+ String values = " VALUES (" + period.getId() + "," + source.getId() + ",'" + llDataValue.getStoredBy() + "','" + date + "',";
for ( String elementName : elements )
{
-
- // String name = elementName.replaceAll(" ", "_");
LineListElement lineListElement = lineListService.getLineListElementByShortName( elementName );
if ( i == size )
{
@@ -1061,7 +1008,8 @@
{
values += "'" + elementValues.get( elementName ) + "'";
}
- } else
+ }
+ else
{
columnDefinition += elementName + ",";
if ( lineListElement.getDataType().equalsIgnoreCase( "int" ) )
@@ -1080,42 +1028,35 @@
try
{
- //Connection connection = jdbcTemplate.getDataSource().getConnection();
- //preparedStatement = connection.prepareStatement( columnDefinition );
- //updateLLValue = preparedStatement.execute();
int sqlResult = jdbcTemplate.update( columnDefinition );
updateLLValue = true;
columnDefinition = "";
- } catch ( Exception e )
+ }
+ catch ( Exception e )
{
e.printStackTrace();
updateLLValue = false;
}
-
}
return updateLLValue;
-
}
+ // -------------------------------------------------------------------------
+ // Remove single LineListDataValue from Department table by record number
+ // -------------------------------------------------------------------------
public boolean removeLLRecord( int recordId, String tableName )
{
boolean valueDeleted = false;
- String columnDefinition = " delete from " + tableName + " where recordnumber = " + recordId;
-
- PreparedStatement preparedStatement = null;
+ String columnDefinition = "DELETE FROM " + tableName + " WHERE recordnumber = " + recordId;
try
{
- //Connection connection = jdbcTemplate.getDataSource().getConnection();
- //preparedStatement = connection.prepareStatement( columnDefinition );
- // valueDeleted = preparedStatement.execute();
int sqlResult = jdbcTemplate.update( columnDefinition );
valueDeleted = true;
- columnDefinition = "";
- //preparedStatement.close();
- } catch ( Exception e )
+ }
+ catch ( Exception e )
{
e.printStackTrace();
valueDeleted = false;
@@ -1124,40 +1065,45 @@
return valueDeleted;
}
+ // -------------------------------------------------------------------------
+ // Update LineListDataValue List for Department table
+ // -------------------------------------------------------------------------
public boolean updateLLValue( List<LineListDataValue> llDataValuesList, String tableName )
{
boolean valueUpdated = false;
String columnDefinition = "";
- PreparedStatement preparedStatement = null;
-
for ( LineListDataValue llDataValue : llDataValuesList )
{
-
- // UPDATE table_name SET column1=value, column2=value2,... WHERE
- // some_column=some_value
- columnDefinition = "update " + tableName + " set ";
- // get periodid from llDataValue
+ columnDefinition = "UPDATE " + tableName + " SET ";
Map<String, String> elementValues = llDataValue.getLineListValues();
- // System.out.println("size of map = "+elementValues.size());
+
Set<String> elements = elementValues.keySet();
- System.out.println("In Update recordnumber = " + llDataValue.getRecordNumber());
+
int size = elements.size();
- //System.out.println("size = "+size);
int i = 1;
java.util.Date today = llDataValue.getTimestamp();
- long t = today.getTime();
+ long t;
+ if ( today == null )
+ {
+ Date d = new Date();
+ t = d.getTime();
+ }
+ else
+ {
+ t = today.getTime();
+ }
+
java.sql.Date date = new java.sql.Date( t );
- String whereClause = " where recordnumber = " + llDataValue.getRecordNumber();
+
+ String whereClause = " WHERE recordnumber = " + llDataValue.getRecordNumber();
for ( String elementName : elements )
{
- //System.out.println( "elementName = " + elementName );
LineListElement lineListElement = lineListService.getLineListElementByShortName( elementName );
if ( i == size )
{
-
if ( lineListElement.getDataType().equalsIgnoreCase( "int" ) )
{
try
@@ -1165,34 +1111,37 @@
columnDefinition += elementName + " = " + Integer.parseInt( elementValues.get( elementName ) ) + ",";
llDataValue.getSource().getId();
columnDefinition += "periodid = '" + llDataValue.getPeriod().getId() + "', sourceid = '" + llDataValue.getSource().getId() + "', storedby = '" + llDataValue.getStoredBy() + "', lastupdated = '" + date + "' ";
-
- } catch ( Exception e )
+ }
+ catch ( Exception e )
{
- JOptionPane.showMessageDialog( null, elementName + " cannot be null" );
+ System.out.println( "Exception:"+e.getMessage() );
}
- } else
+ }
+ else
{
columnDefinition += elementName + " = '" + elementValues.get( elementName ) + "'" + ",";
columnDefinition += "periodid = '" + llDataValue.getPeriod().getId() + "', sourceid = '" + llDataValue.getSource().getId() + "', storedby = '" + llDataValue.getStoredBy() + "', lastupdated = '" + date + "' ";
}
- } else
+ }
+ else
{
if ( lineListElement.getDataType().equalsIgnoreCase( "int" ) )
{
try
{
columnDefinition += elementName + " = " + Integer.parseInt( elementValues.get( elementName ) ) + ",";
- } catch ( Exception e )
+ }
+ catch ( Exception e )
{
- JOptionPane.showMessageDialog( null, elementName + " cannot be null " );
+ System.out.println( "Exception:"+e.getMessage() );
}
- } else
+ }
+ else
{
columnDefinition += elementName + " = '" + elementValues.get( elementName ) + "'" + ",";
}
i++;
}
-
}
columnDefinition += whereClause;
@@ -1200,26 +1149,23 @@
try
{
- //Connection connection = jdbcTemplate.getDataSource().getConnection();
-
- //preparedStatement = connection.prepareStatement( columnDefinition );
int sqlResult = jdbcTemplate.update( columnDefinition );
valueUpdated = true;
- //valueUpdated = preparedStatement.execute();
columnDefinition = "";
- //preparedStatement.close();
- } catch ( Exception e )
+ }
+ catch ( Exception e )
{
e.printStackTrace();
valueUpdated = false;
}
-
}
return valueUpdated;
}
-
+ // -------------------------------------------------------------------------
+ // Update LineListDataValue List for Department table
+ // -------------------------------------------------------------------------
public boolean updateSingleLLValue( LineListDataValue llDataValue, String tableName )
{
boolean valueUpdated = false;
@@ -1234,8 +1180,19 @@
System.out.println("In Update recordnumber = " + llDataValue.getRecordNumber());
int size = elements.size();
int i = 1;
+
java.util.Date today = llDataValue.getTimestamp();
- long t = today.getTime();
+ long t;
+ if ( today == null )
+ {
+ Date d = new Date();
+ t = d.getTime();
+ }
+ else
+ {
+ t = today.getTime();
+ }
+
java.sql.Date date = new java.sql.Date( t );
String whereClause = " WHERE recordnumber = " + llDataValue.getRecordNumber();
for ( String elementName : elements )
@@ -1250,7 +1207,6 @@
columnDefinition += elementName + " = " + Integer.parseInt( elementValues.get( elementName ) ) + ",";
llDataValue.getSource().getId();
columnDefinition += "periodid = '" + llDataValue.getPeriod().getId() + "', sourceid = '" + llDataValue.getSource().getId() + "', storedby = '" + llDataValue.getStoredBy() + "', lastupdated = '" + date + "' ";
-
}
catch ( Exception e )
{
@@ -1275,7 +1231,8 @@
{
System.out.println( "Exception: "+ e.getMessage() );
}
- } else
+ }
+ else
{
columnDefinition += elementName + " = '" + elementValues.get( elementName ) + "'" + ",";
}
@@ -1302,13 +1259,14 @@
return valueUpdated;
}
-
+
+ // -------------------------------------------------------------------------
+ // Get Recent Period from Department table for onChange period type
+ // -------------------------------------------------------------------------
public Period getRecentPeriodForOnChangeData( String tableName, String llElementName, String llElementValue, Source source )
{
String columnDefinition = "";
- //Statement statement = null;
-
List<Period> periodList = new ArrayList<Period>();
if ( source != null )
@@ -1319,17 +1277,11 @@
try
{
- //Connection connection = jdbcTemplate.getDataSource().getConnection();
-
- //statement = connection.createStatement( ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE );
-
- //ResultSet result = statement.executeQuery( columnDefinition );
-
SqlRowSet sqlResultSet = jdbcTemplate.queryForRowSet( columnDefinition );
if ( sqlResultSet != null )
{
- sqlResultSet.beforeFirst();
+ sqlResultSet.beforeFirst();
while ( sqlResultSet.next() )
{
@@ -1337,13 +1289,9 @@
Period tempPeriod = periodService.getPeriod( tempPeriodId );
periodList.add( tempPeriod );
}
-
}
-
- //result.close();
-
- //statement.close();
- } catch ( Exception e )
+ }
+ catch ( Exception e )
{
e.printStackTrace();
}
@@ -1354,111 +1302,108 @@
if ( periodList != null && periodList.size() > 0 )
{
return periodList.get( 0 );
- } else
+ }
+ else
{
return periodService.getPeriod( 0 );
}
}
+ // -------------------------------------------------------------------------
+ // Get Linelist Values from Department table by record number
+ // -------------------------------------------------------------------------
public LineListDataValue getLLValuesByRecordNumber( String tableName, int recordId )
{
String columnDefinition = "";
- //Statement statement = null;
- // creating map of element and its values
Map<String, String> llElementValuesMap = new HashMap<String, String>();
LineListDataValue llDataValue = new LineListDataValue();
- // LineListDataValue llDataValue = new LineListDataValue();
-
- columnDefinition += "select * from " + tableName + "where recordnumber = "+recordId;
-
- System.out.println( columnDefinition );
-
- Collection<LineListElement> elementsCollection = new ArrayList<LineListElement>();
-
- elementsCollection = lineListService.getLineListGroupByShortName( tableName ).getLineListElements();
-
- LineListElement element;
- String name = "";
-
- try
+
+ columnDefinition += "select * from " + tableName + "where recordnumber = "+recordId;
+
+ System.out.println( columnDefinition );
+
+ Collection<LineListElement> elementsCollection = new ArrayList<LineListElement>();
+
+ elementsCollection = lineListService.getLineListGroupByShortName( tableName ).getLineListElements();
+
+ LineListElement element;
+
+ String name = "";
+
+ try
+ {
+ SqlRowSet result = jdbcTemplate.queryForRowSet( columnDefinition );
+ if ( result != null )
{
- // Connection connection = jdbcTemplate.getDataSource().getConnection();
- //statement = connection.createStatement( ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE );
- //ResultSet result = statement.executeQuery( columnDefinition );
- SqlRowSet result = jdbcTemplate.queryForRowSet( columnDefinition );
- if ( result != null )
+ result.beforeFirst();
+
+ while ( result.next() )
{
- result.beforeFirst();
-
- while ( result.next() )
+ llDataValue.setRecordNumber( result.getInt( "recordnumber" ) );
+ Iterator<LineListElement> it1 = elementsCollection.iterator();
+ while ( it1.hasNext() )
{
- llDataValue.setRecordNumber( result.getInt( "recordnumber" ) );
- Iterator it1 = elementsCollection.iterator();
- while ( it1.hasNext() )
- {
- element = (LineListElement) it1.next();
- name = element.getShortName() + ":" + result.getInt( "recordnumber" );
- if ( element.getDataType().equalsIgnoreCase( "string" ) )
- {
- String tempString = result.getString( element.getShortName() );
- if ( tempString == null )
- {
- tempString = "";
- }
- llElementValuesMap.put( name, tempString );
- } else
- {
- if ( element.getDataType().equalsIgnoreCase( "date" ) )
- {
- Date tempDate = result.getDate( element.getShortName() );
- String tempStr = "";
- if ( tempDate != null )
- {
- tempStr = tempDate.toString();
- }
- llElementValuesMap.put( name, tempStr );
- } else
- {
- if ( element.getDataType().equalsIgnoreCase( "int" ) )
- {
- String tempStr = "";
- Integer tempInt = result.getInt( element.getShortName() );
- if ( tempInt != null )
- {
- tempStr = Integer.toString( tempInt );
- }
- llElementValuesMap.put( name, tempStr );
- }
- }
- }
+ element = (LineListElement) it1.next();
+ name = element.getShortName() + ":" + result.getInt( "recordnumber" );
+
+ if ( element.getDataType().equalsIgnoreCase( "string" ) )
+ {
+ String tempString = result.getString( element.getShortName() );
+ if ( tempString == null )
+ {
+ tempString = "";
+ }
+ llElementValuesMap.put( name, tempString );
+ }
+ else if ( element.getDataType().equalsIgnoreCase( "date" ) )
+ {
+ Date tempDate = result.getDate( element.getShortName() );
+ String tempStr = "";
+ if ( tempDate != null )
+ {
+ tempStr = tempDate.toString();
+ }
+ llElementValuesMap.put( name, tempStr );
+ }
+ else if ( element.getDataType().equalsIgnoreCase( "int" ) )
+ {
+ String tempStr = "";
+ Integer tempInt = result.getInt( element.getShortName() );
+ if ( tempInt != null )
+ {
+ tempStr = Integer.toString( tempInt );
+ }
+ llElementValuesMap.put( name, tempStr );
}
-
- llDataValue.setLineListValues( llElementValuesMap );
- llDataValue.setPeriod( periodService.getPeriod( result.getInt( "periodid" )) );
- llDataValue.setSource( organisationUnitService.getOrganisationUnit( result.getInt( "sourceid" )) );
}
-
+
+ llDataValue.setLineListValues( llElementValuesMap );
+ llDataValue.setPeriod( periodService.getPeriod( result.getInt( "periodid" )) );
+ llDataValue.setSource( organisationUnitService.getOrganisationUnit( result.getInt( "sourceid" )) );
}
- //statement.close();
- } catch ( Exception e )
- {
- e.printStackTrace();
}
-
+ }
+ catch ( Exception e )
+ {
+ e.printStackTrace();
+ }
+
return llDataValue;
-
}
+ // -------------------------------------------------------------------------
+ // Get Period from Department table by record number
+ // -------------------------------------------------------------------------
public Period getPeriodByRecordNumber( String tableName, int recordId )
{
String columnDefinition = "";
columnDefinition += "select periodid from " + tableName + " where recordnumber = "+recordId;
- System.out.println( columnDefinition );
Period tempPeriod = new Period();
+
try
{
SqlRowSet result = jdbcTemplate.queryForRowSet( columnDefinition );