From c99fd8938a81589f0d87442a350883f700b6c5c0 Mon Sep 17 00:00:00 2001 From: Federico Date: Fri, 26 Mar 2021 15:26:11 -0300 Subject: [PATCH 1/2] Add touch() overloads that accepts 'groupName' as argument. --- .../org/jpos/ee/status/StatusManager.java | 32 +++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/modules/status/src/main/java/org/jpos/ee/status/StatusManager.java b/modules/status/src/main/java/org/jpos/ee/status/StatusManager.java index 9159fd542e..a9756bc711 100644 --- a/modules/status/src/main/java/org/jpos/ee/status/StatusManager.java +++ b/modules/status/src/main/java/org/jpos/ee/status/StatusManager.java @@ -19,7 +19,6 @@ package org.jpos.ee.status; import org.hibernate.HibernateException; -import org.hibernate.ObjectNotFoundException; import org.hibernate.Query; import org.hibernate.Transaction; import org.jpos.ee.DB; @@ -69,6 +68,21 @@ public void touch (String id, String state, String detail) db.session().evict (status); } + /** + * @param id status id + * @param state Status.OK, Status.WARN, Status.ERROR or user defined + * @param detail optional detail information + * @param groupName group name + */ + public void touch (String id, String state, String detail, String groupName) + throws HibernateException, SQLException + { + Transaction tx = db.beginTransaction(); + Status status = touch (id, state, detail, tx, groupName); + tx.commit(); + db.session().evict (status); + } + /** * @param id status id * @param state Status.OK, Status.WARN, Status.ERROR or user defined @@ -77,6 +91,19 @@ public void touch (String id, String state, String detail) */ public Status touch (String id, String state, String detail, Transaction tx) throws HibernateException, SQLException + { + return touch(id, state, detail, tx, null); + } + + /** + * @param id status id + * @param state Status.OK, Status.WARN, Status.ERROR or user defined + * @param detail optional detail information + * @param tx transaction + * @param groupName group name + */ + public Status touch (String id, String state, String detail, Transaction tx, String groupName) + throws HibernateException, SQLException { Status status = getStatus (id, true); if (state == null) { @@ -109,9 +136,10 @@ public Status touch (String id, String state, String detail, Transaction tx) status.setLastTick (now); status.setDetail (detail); status.setExpired (false); + status.setGroupName (groupName); return status; } - + /** * @param state * @return syslog severity associated with this state From cbec6ca02edf375952cf3bc2e7b568e62b42ba80 Mon Sep 17 00:00:00 2001 From: Federico Date: Fri, 26 Mar 2021 15:27:15 -0300 Subject: [PATCH 2/2] Add getStatus() overload that accepts the group name as argument. --- .../main/java/org/jpos/ee/status/StatusManager.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/modules/status/src/main/java/org/jpos/ee/status/StatusManager.java b/modules/status/src/main/java/org/jpos/ee/status/StatusManager.java index a9756bc711..cbc3994af9 100644 --- a/modules/status/src/main/java/org/jpos/ee/status/StatusManager.java +++ b/modules/status/src/main/java/org/jpos/ee/status/StatusManager.java @@ -169,6 +169,17 @@ public void touch (String key, String state) */ public Status getStatus (String id, boolean create) throws HibernateException, SQLException + { + return getStatus(id, create, null); + } + + /** + * @param id status id and optional name (used when create=true) + * @param create if true and status doesn't exist, a new status with an optional name would be created. + * @param groupName group name to be used if a new status is created. + */ + public Status getStatus (String id, boolean create, String groupName) + throws HibernateException, SQLException { String name = ""; int sp = id.indexOf (" "); @@ -182,7 +193,7 @@ public Status getStatus (String id, boolean create) s.setId (id); s.setName (name.length() > 0 ? name : id); s.setTimeoutState (Status.OFF); - s.setGroupName ("Unfiled"); + s.setGroupName (groupName != null ? groupName : "Unfiled"); db.save (s); } return s;