Skip to content

Commit

Permalink
Merge pull request #210 from fgonzal/master
Browse files Browse the repository at this point in the history
Status: add method overloads that accept the status group name as argument.
  • Loading branch information
ar authored Mar 26, 2021
2 parents 4a041e5 + cbec6ca commit b583f1f
Showing 1 changed file with 42 additions and 3 deletions.
45 changes: 42 additions & 3 deletions modules/status/src/main/java/org/jpos/ee/status/StatusManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -141,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 (" ");
Expand All @@ -154,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;
Expand Down

0 comments on commit b583f1f

Please # to comment.