use of org.jaffa.components.audit.domain.AuditTransaction in project jaffa-framework by jaffa-projects.
the class AuditTransactionObject method findAuditTransactionObject.
/**
* Finds the related foreign AuditTransaction object.
* If checkExistenceOnly is false, then the foreign object will be fetched and assigned to the corresponding member variable of this class.
* If checkExistenceOnly is true, then a mere existence check is performed for the foreign object, as oppposed to fetching all the values for that object.
*/
private void findAuditTransactionObject(boolean checkExistenceOnly) throws ValidationException, FrameworkException {
UOW uow = getUOW();
boolean localUow = false;
try {
if (m_auditTransactionObject == null && getTransactionId() != null) {
Criteria criteria = new Criteria();
criteria.setTable(AuditTransactionMeta.getName());
criteria.addCriteria(AuditTransactionMeta.TRANSACTION_ID, getTransactionId());
if (checkExistenceOnly)
criteria.addFunction(Criteria.FUNCTION_COUNT, null, Criteria.ID_FUNCTION_COUNT);
Number count = null;
if (uow == null || !uow.isActive()) {
uow = new UOW();
localUow = true;
}
Iterator itr = uow.query(criteria).iterator();
if (itr.hasNext()) {
if (checkExistenceOnly)
count = (Number) ((Map) itr.next()).get(Criteria.ID_FUNCTION_COUNT);
else
m_auditTransactionObject = (AuditTransaction) itr.next();
}
if (m_auditTransactionObject == null && (count == null || count.intValue() <= 0))
throw new InvalidForeignKeyException(AuditTransactionObjectMeta.META_TRANSACTION_ID.getLabelToken(), new Object[] { AuditTransactionMeta.getLabelToken(), AuditTransactionMeta.META_TRANSACTION_ID.getLabelToken() });
}
} finally {
if (localUow && uow != null)
uow.rollback();
}
}
use of org.jaffa.components.audit.domain.AuditTransaction in project jaffa-framework by jaffa-projects.
the class AuditLogger method createAuditTransaction.
/**
* Creates an AuditTransaction instance, if not already created, and adds it to the UOW.
*/
private void createAuditTransaction() throws ApplicationExceptions, FrameworkException {
if (m_transactionId == null) {
try {
AuditTransaction at = new AuditTransaction();
at.generateKey();
at.setProcessName((String) MDC.get(AuditTransactionMeta.PROCESS_NAME));
at.setSubProcessName((String) MDC.get(AuditTransactionMeta.SUB_PROCESS_NAME));
at.setReason((String) MDC.get(AuditTransactionMeta.REASON));
if (SecurityManager.getPrincipal() != null && SecurityManager.getPrincipal().getName() != null)
at.setCreatedBy(SecurityManager.getPrincipal().getName());
at.setCreatedOn(new DateTime());
m_uow.addSpecial(at);
m_transactionId = at.getTransactionId();
if (log.isDebugEnabled())
log.debug("Created AuditTransaction: " + at);
} catch (ValidationException e) {
if (log.isDebugEnabled())
log.debug("Exception thrown during creation of AuditTransaction", e);
throw new ApplicationExceptions(e);
}
}
}
Aggregations