details: /erp/devel/pi/rev/0a78708af7ba
changeset: 9286:0a78708af7ba
user: Antonio Moreno <antonio.moreno <at> openbravo.com>
date: Tue Dec 21 15:40:12 2010 +0100
summary: Fixed small issue with null values in the request
details: /erp/devel/pi/rev/76a9ae67cc68
changeset: 9287:76a9ae67cc68
user: Antonio Moreno <antonio.moreno <at> openbravo.com>
date: Tue Dec 21 18:32:15 2010 +0100
summary: Modified DateUIDefinition so that it orrectly parses both dates
which come from the client (and follow the 'xml' format) and dates which are
formatted through the standard Openbravo.properties format.
details: /erp/devel/pi/rev/cffb019e1744
changeset: 9288:cffb019e1744
user: Antonio Moreno <antonio.moreno <at> openbravo.com>
date: Tue Dec 21 18:34:42 2010 +0100
summary: Force all dates stored in the FIC structures to follow the 'xml'
format. The dates which are passed to callouts through the request will be
transformed to the standard date format defined in the Openbravo.properties. .
Improved runCallouts comments. Reset the request values after a callout is
executed so that values follow the standard format, and therefore UIDefinition
can happen without trouble.
diffstat:
modules/org.openbravo.client.application/src/org/openbravo/client/application/window/FormInitializationComponent.java
| 43 ++++++++-
modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/reference/DateUIDefinition.java
| 26 +++++-
2 files changed, 58 insertions(+), 11 deletions(-)
diffs (152 lines):
diff -r 18eb4167ed6a -r cffb019e1744
modules/org.openbravo.client.application/src/org/openbravo/client/application/window/FormInitializationComponent.java
---
a/modules/org.openbravo.client.application/src/org/openbravo/client/application/window/FormInitializationComponent.java
Tue Dec 21 18:18:40 2010 +0100
+++
b/modules/org.openbravo.client.application/src/org/openbravo/client/application/window/FormInitializationComponent.java
Tue Dec 21 18:34:42 2010 +0100
@@ -23,7 +23,10 @@
import java.lang.reflect.Method;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
import java.util.ArrayList;
+import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -140,7 +143,14 @@
+
Sqlc.TransformaNombreColumna(field.getColumn().getDBColumnName());
try {
if (jsContent.has(inpColName)) {
- RequestContext.get().setRequestParameter(inpColName,
jsContent.getString(inpColName));
+ String value;
+ if (jsContent.get(inpColName) == null
+ || jsContent.get(inpColName).toString().equals("null")) {
+ value = null;
+ } else {
+ value = jsContent.get(inpColName).toString();
+ }
+ RequestContext.get().setRequestParameter(inpColName, value);
}
} catch (Exception e) {
log.error("Couldn't read column value from the request for column
" + inpColName, e);
@@ -423,8 +433,21 @@
Entity entity = obj.getEntity();
Property prop = entity.getPropertyByColumnName(columnName);
Object currentValue = obj.get(prop.getName());
+
if (currentValue != null) {
- if (currentValue instanceof BaseOBObject) {
+ if (prop.isDate()) {
+ SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+ format.setLenient(true);
+ Date date;
+ try {
+ date = format.parse(currentValue.toString());
+ } catch (ParseException e) {
+ throw new OBException("Error while parsing date: " + currentValue,
e);
+ }
+ SimpleDateFormat outFormat = new
SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
+ outFormat.setLenient(true);
+ currentValue = outFormat.format(date);
+ } else if (currentValue instanceof BaseOBObject) {
if (prop.getReferencedProperty() != null) {
currentValue = ((BaseOBObject)
currentValue).get(prop.getReferencedProperty().getName());
} else {
@@ -540,11 +563,11 @@
log.error("Couldn't find method doPost in Callout " +
calloutClassName);
} else {
RequestContext rq = RequestContext.get();
- HashMap<String, JSONObject> formattedColumnValues = new
HashMap<String, JSONObject>(
- columnValues);
- formatColumnValues(formattedColumnValues, fields);
- setRequestContextParameters(fields, columnValues);
+ // We first prepare the data so that it's usable by the callout
+ formatColumnValues(columnValues, fields);
RequestContext.get().setRequestParameter("inpLastFieldChanged",
lastFieldChanged);
+
+ // We then execute the callout
CalloutServletConfig config = new
CalloutServletConfig(calloutClassName, RequestContext
.getServletContext());
Object[] initArgs = { config };
@@ -555,6 +578,11 @@
method.invoke(calloutInstance, arguments);
String calloutResponse = fakeResponse.getOutputFromWriter();
+ // Now we restore the request data so that it's compatible with the
UIDefinition
+ // computation
+ setRequestContextParameters(fields, columnValues);
+ // Now we parse the callout response and modify the stored values of
the columns modified
+ // by the callout
ArrayList<NativeArray> returnedArray = new ArrayList<NativeArray>();
String calloutNameJS = parseCalloutResponse(calloutResponse,
returnedArray);
if (calloutNameJS != null && calloutNameJS != "") {
@@ -655,7 +683,8 @@
String oldValue = obj.has("value") ? obj.getString("value") : null;
String value = oldValue == null || oldValue.equals("") ? oldValue :
uiDef
.formatValueToSQL(oldValue.toString());
- obj.put("value", value);
+ RequestContext.get().setRequestParameter(
+ "inp" +
Sqlc.TransformaNombreColumna(field.getColumn().getDBColumnName()), value);
}
} catch (Exception e) {
log.error("Error while formatting column " +
field.getColumn().getDBColumnName(), e);
diff -r 18eb4167ed6a -r cffb019e1744
modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/reference/DateUIDefinition.java
---
a/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/reference/DateUIDefinition.java
Tue Dec 21 18:18:40 2010 +0100
+++
b/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/reference/DateUIDefinition.java
Tue Dec 21 18:34:42 2010 +0100
@@ -18,11 +18,13 @@
*/
package org.openbravo.client.kernel.reference;
+import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.openbravo.base.exception.OBException;
import org.openbravo.base.model.domaintype.PrimitiveDomainType;
+import org.openbravo.client.kernel.RequestContext;
/**
* Implementation of the date ui definition.
@@ -31,8 +33,8 @@
*/
public class DateUIDefinition extends UIDefinition {
- private static final String PATTERN = "yyyy-MM-dd HH:mm:ss";
- private static final String PATTERN_T = "yyyy-MM-dd'T'HH:mm:ss";
+ private static final String PATTERN = "yyyy-MM-dd'T'HH:mm:ss";
+
private SimpleDateFormat format = null;
public SimpleDateFormat getFormat() {
@@ -61,9 +63,10 @@
}
SimpleDateFormat lformat;
if (value.contains("T")) {
- lformat = new SimpleDateFormat(PATTERN_T);
+ lformat = new SimpleDateFormat(PATTERN);
} else {
- lformat = new SimpleDateFormat(PATTERN);
+ String pattern =
RequestContext.get().getSessionAttribute("#AD_JAVADATEFORMAT").toString();
+ lformat = new SimpleDateFormat(pattern);
}
lformat.setLenient(true);
final Date date = lformat.parse(value);
@@ -82,4 +85,19 @@
+ "return OB.Utilities.Date.JSToOB(value, OB.Format.date);" + "},");
return sb.toString();
}
+
+ public String formatValueToSQL(String value) {
+ SimpleDateFormat lformat = new SimpleDateFormat(PATTERN);
+ lformat.setLenient(true);
+ Date date;
+ try {
+ date = lformat.parse(value);
+ } catch (ParseException e) {
+ throw new OBException("Couldn't parse date: " + value, e);
+ }
+ String pattern =
RequestContext.get().getSessionAttribute("#AD_JAVADATEFORMAT").toString();
+ SimpleDateFormat outFormat = new SimpleDateFormat(pattern);
+ outFormat.setLenient(true);
+ return outFormat.format(date);
+ }
}
------------------------------------------------------------------------------
Forrester recently released a report on the Return on Investment (ROI) of
Google Apps. They found a 300% ROI, 38%-56% cost savings, and break-even
within 7 months. Over 3 million businesses have gone Google with Google Apps:
an online email calendar, and document program that's accessible from your
browser. Read the Forrester report: http://p.sf.net/sfu/googleapps-sfnew
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits