Fixed issue 17880. Attachments 'age' will be calculated in the server to prevent clock synchronization issues
authorAntonio Moreno <antonio.moreno@openbravo.com>
Fri, 29 Jul 2011 11:29:14 +0200
changeset 13347 2d138204577c
parent 13346 11de85d32280
child 13348 1b2e5c4bae72
Fixed issue 17880. Attachments 'age' will be calculated in the server to prevent clock synchronization issues
modules/org.openbravo.client.application/src/org/openbravo/client/application/window/AttachmentsAH.java
modules/org.openbravo.client.application/src/org/openbravo/client/application/window/FormInitializationComponent.java
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/ob-view-form-attachments.js
--- a/modules/org.openbravo.client.application/src/org/openbravo/client/application/window/AttachmentsAH.java	Fri Jul 29 11:27:42 2011 +0200
+++ b/modules/org.openbravo.client.application/src/org/openbravo/client/application/window/AttachmentsAH.java	Fri Jul 29 11:29:14 2011 +0200
@@ -19,8 +19,8 @@
 package org.openbravo.client.application.window;
 
 import java.io.File;
-import java.text.SimpleDateFormat;
 import java.util.ArrayList;
+import java.util.Date;
 import java.util.List;
 import java.util.Map;
 
@@ -104,19 +104,15 @@
     String tableId = (String) DalUtil.getId(tab.getTable());
     OBCriteria<Attachment> attachmentFiles = OBDao.getFilteredCriteria(Attachment.class,
         Restrictions.eq("table.id", tableId), Restrictions.in("record", recordIds.split(",")));
+    attachmentFiles.addOrderBy("creationDate", false);
     List<JSONObject> attachments = new ArrayList<JSONObject>();
     for (Attachment attachment : attachmentFiles.list()) {
       JSONObject attachmentobj = new JSONObject();
       try {
         attachmentobj.put("id", attachment.getId());
         attachmentobj.put("name", attachment.getName());
-        final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZZZZZ");
-        dateFormat.setLenient(true);
-        String date = dateFormat.format(attachment.getCreationDate());
-        String d1 = date.substring(0, date.length() - 2);
-        String d2 = date.substring(date.length() - 2, date.length());
-        attachmentobj.put("creationDate", d1 + ":" + d2);
-        attachmentobj.put("createdby", attachment.getCreatedBy().getName());
+        attachmentobj.put("age", (new Date().getTime() - attachment.getUpdated().getTime()));
+        attachmentobj.put("createdby", attachment.getUpdatedBy().getName());
       } catch (Exception e) {
         throw new OBException("Error while reading attachments:", e);
       }
--- a/modules/org.openbravo.client.application/src/org/openbravo/client/application/window/FormInitializationComponent.java	Fri Jul 29 11:27:42 2011 +0200
+++ b/modules/org.openbravo.client.application/src/org/openbravo/client/application/window/FormInitializationComponent.java	Fri Jul 29 11:29:14 2011 +0200
@@ -22,8 +22,8 @@
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
-import java.text.SimpleDateFormat;
 import java.util.ArrayList;
+import java.util.Date;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
@@ -292,18 +292,14 @@
       attachments = OBDao.getFilteredCriteria(Attachment.class,
           Restrictions.eq("table.id", tableId), Restrictions.in("record", multipleRowIds));
     }
+    attachments.addOrderBy("creationDate", false);
     for (Attachment attachment : attachments.list()) {
       JSONObject obj = new JSONObject();
       try {
         obj.put("name", attachment.getName());
         obj.put("id", attachment.getId());
-        final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZZZZZ");
-        dateFormat.setLenient(true);
-        String date = dateFormat.format(attachment.getCreationDate());
-        String d1 = date.substring(0, date.length() - 2);
-        String d2 = date.substring(date.length() - 2, date.length());
-        obj.put("creationDate", d1 + ":" + d2);
-        obj.put("createdby", attachment.getCreatedBy().getName());
+        obj.put("age", (new Date().getTime() - attachment.getUpdated().getTime()));
+        obj.put("createdby", attachment.getUpdatedBy().getName());
       } catch (JSONException e) {
         log.error("Error while reading attachments", e);
       }
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/ob-view-form-attachments.js	Fri Jul 29 11:27:42 2011 +0200
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/ob-view-form-attachments.js	Fri Jul 29 11:29:14 2011 +0200
@@ -392,7 +392,7 @@
         height: 20,
         wrap: false
       });
-      var creationDate = OB.Utilities.getTimePassed(isc.Date.parseSchemaDate(attachment.creationDate));
+      var creationDate = OB.Utilities.getTimePassedInterval(attachment.age);
       var attachmentBy = isc.Label.create({
         height:  1,
         className: 'OBNoteListGridAuthor',