Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Status: add method overloads that accept the status group name as argument. #210

Merged
merged 2 commits into from
Mar 26, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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