details:   https://code.openbravo.com/erp/devel/pi/rev/3111a27e8c29
changeset: 32663:3111a27e8c29
user:      Carlos Aristu <carlos.aristu <at> openbravo.com>
date:      Mon Sep 11 12:05:17 2017 +0200
summary:   related to bug 36763: Update attachment last update when metadata 
also changes

diffstat:

 
modules/org.openbravo.client.application/src/org/openbravo/client/application/attachment/AttachmentUtils.java
 |  21 ++++++++-
 1 files changed, 18 insertions(+), 3 deletions(-)

diffs (52 lines):

diff -r 44c43a10b62a -r 3111a27e8c29 
modules/org.openbravo.client.application/src/org/openbravo/client/application/attachment/AttachmentUtils.java
--- 
a/modules/org.openbravo.client.application/src/org/openbravo/client/application/attachment/AttachmentUtils.java
     Fri Sep 08 12:30:00 2017 +0200
+++ 
b/modules/org.openbravo.client.application/src/org/openbravo/client/application/attachment/AttachmentUtils.java
     Mon Sep 11 12:05:17 2017 +0200
@@ -11,7 +11,7 @@
  * under the License.
  * The Original Code is Openbravo ERP.
  * The Initial Developer of the Original Code is Openbravo SLU
- * All portions are Copyright (C) 2015-2016 Openbravo SLU
+ * All portions are Copyright (C) 2015-2017 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -169,7 +169,7 @@
     OBCriteria<Attachment> attachmentFiles = 
OBDao.getFilteredCriteria(Attachment.class,
         Restrictions.eq("table.id", tableId), Restrictions.in("record", 
recordIds));
     attachmentFiles.addOrderBy("creationDate", false);
-    List<JSONObject> attachments = new ArrayList<JSONObject>();
+    List<JSONObject> attachments = new ArrayList<>();
     // do not filter by the attachment's organization
     // if the user has access to the record where the file its attached, it 
has access to all its
     // attachments
@@ -179,7 +179,8 @@
       try {
         attachmentobj.put("id", attachment.getId());
         attachmentobj.put("name", attachment.getName());
-        attachmentobj.put("age", (new Date().getTime() - 
attachment.getUpdated().getTime()));
+        attachmentobj.put("age", (new Date().getTime() - 
getLastUpdateOfAttachment(attachment)
+            .getTime()));
         attachmentobj.put("updatedby", attachment.getUpdatedBy().getName());
         String attachmentMethod = DEFAULT_METHOD_ID;
         if (attachment.getAttachmentConf() != null) {
@@ -195,6 +196,20 @@
     return attachments;
   }
 
+  private static Date getLastUpdateOfAttachment(Attachment attachment) {
+    final StringBuilder hql = new StringBuilder();
+    hql.append("SELECT MAX(pv.updated) FROM OBUIAPP_ParameterValue pv");
+    hql.append(" WHERE pv.file.id =:fileId");
+    final Query query = 
OBDal.getInstance().getSession().createQuery(hql.toString());
+    query.setParameter("fileId", attachment.getId());
+    query.setMaxResults(1);
+    Date metadataLastUpdate = (Date) query.uniqueResult();
+    if (metadataLastUpdate == null || 
attachment.getUpdated().after(metadataLastUpdate)) {
+      return attachment.getUpdated();
+    }
+    return metadataLastUpdate;
+  }
+
   /**
    * Get the String value of a parameter with a property path
    * 

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to