Search in sources :

Example 46 with UOW

use of org.jaffa.persistence.UOW in project jaffa-framework by jaffa-projects.

the class UserContextWrapper method readUserRoles.

/**
 * Read the roles for the user from the database
 *
 * @param userId the user id.
 * @return the roles for the user.
 * @throws FrameworkException if any internal error occurs.
 */
protected String[] readUserRoles(String userId) throws FrameworkException {
    UOW uow = null;
    List<String> roleList = new ArrayList<String>();
    try {
        uow = new UOW();
        Criteria c = new Criteria();
        c.setTable(UserRoleMeta.getName());
        c.addCriteria(UserRoleMeta.USER_NAME, userId);
        Collection roles = uow.query(c);
        for (Iterator it = roles.iterator(); it.hasNext(); ) {
            UserRole role = (UserRole) it.next();
            roleList.add(role.getRoleName());
        }
    } catch (UOWException e) {
        // Log the error
        log.error("Can't Get The Roles for User - " + userId, e);
    } finally {
        // Attempt to rollback any open transaction
        try {
            if (uow != null) {
                uow.rollback();
            }
        } catch (UOWException e) {
            log.error("Rollback", e);
        }
    }
    return (String[]) roleList.toArray(new String[0]);
}
Also used : UOWException(org.jaffa.persistence.exceptions.UOWException) UserRole(org.jaffa.applications.jaffa.modules.admin.domain.UserRole) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) Collection(java.util.Collection) Criteria(org.jaffa.persistence.Criteria) UOW(org.jaffa.persistence.UOW)

Example 47 with UOW

use of org.jaffa.persistence.UOW in project jaffa-framework by jaffa-projects.

the class JaffaTransactionMessageService method getTransactionPayloadByTransactionId.

/**
 * Gets the TransactionPayload of the Transaction with the input ID.
 *
 * @param transactionId the ID of the Transaction to return the TransactionPayload of
 * @return the TransactionPayload of the Transaction with the input ID
 * @throws FrameworkException
 */
@Override
public TransactionPayload getTransactionPayloadByTransactionId(String transactionId) throws FrameworkException {
    UOW uow = null;
    TransactionPayload result = null;
    try {
        uow = new UOW();
        Criteria criteria = new Criteria();
        criteria.setTable(TransactionPayloadMeta.getName());
        criteria.addCriteria(TransactionPayloadMeta.ID, transactionId);
        Iterator itr = uow.query(criteria).iterator();
        if (itr.hasNext()) {
            result = (TransactionPayload) itr.next();
        }
    } finally {
        if (uow != null) {
            uow.close();
        }
    }
    return result;
}
Also used : Iterator(java.util.Iterator) Criteria(org.jaffa.persistence.Criteria) TransactionFieldCriteria(org.jaffa.transaction.apis.data.TransactionFieldCriteria) AtomicCriteria(org.jaffa.persistence.AtomicCriteria) TransactionCriteria(org.jaffa.transaction.apis.data.TransactionCriteria) UOW(org.jaffa.persistence.UOW) TransactionPayload(org.jaffa.transaction.domain.TransactionPayload)

Example 48 with UOW

use of org.jaffa.persistence.UOW in project jaffa-framework by jaffa-projects.

the class JaffaTransactionMessageService method getOpenOutboundByTypeOrderByCreatedOnDesc.

/**
 * Gets a list of all open inbound Transactions of the input type, ordered descending by the createdOn parameter.
 *
 * @param type the type of Transactions to return
 * @return all open inbound Transactions of the input type, ordered by the createdOn parameter
 * @throws FrameworkException
 */
@Override
public List<Transaction> getOpenOutboundByTypeOrderByCreatedOnDesc(String type) throws FrameworkException {
    UOW uow = null;
    List<Transaction> transactions = new ArrayList<Transaction>();
    try {
        uow = new UOW();
        Criteria criteria = new Criteria();
        criteria.setTable(TransactionMeta.getName());
        criteria.addCriteria(TransactionMeta.DIRECTION, Transaction.Direction.OUT.toString());
        criteria.addCriteria(TransactionMeta.TYPE, type);
        criteria.addCriteria(TransactionMeta.STATUS, Transaction.Status.O.toString());
        criteria.addOrderBy(TransactionMeta.CREATED_ON);
        for (Object result : uow.query(criteria)) {
            if (!(result instanceof Transaction)) {
                continue;
            }
            transactions.add((Transaction) result);
        }
    } finally {
        if (uow != null) {
            uow.close();
        }
    }
    return transactions;
}
Also used : Transaction(org.jaffa.transaction.domain.Transaction) ArrayList(java.util.ArrayList) Criteria(org.jaffa.persistence.Criteria) TransactionFieldCriteria(org.jaffa.transaction.apis.data.TransactionFieldCriteria) AtomicCriteria(org.jaffa.persistence.AtomicCriteria) TransactionCriteria(org.jaffa.transaction.apis.data.TransactionCriteria) UOW(org.jaffa.persistence.UOW)

Example 49 with UOW

use of org.jaffa.persistence.UOW in project jaffa-framework by jaffa-projects.

the class JaffaTransactionMessageService method getTransactionField.

/**
 * Gets the TransactionField with the input Transaction ID and field name.
 *
 * @param transactionId the ID of the Transaction the TransactionField is part of
 * @param fieldName     the field name of the TransactionField to return
 * @return the TransactionField with the input Transaction ID and field name
 * @throws FrameworkException
 */
@Override
public TransactionField getTransactionField(String transactionId, String fieldName) throws FrameworkException {
    UOW uow = null;
    TransactionField field = null;
    try {
        uow = new UOW();
        Criteria criteria = new Criteria();
        criteria.setTable(TransactionFieldMeta.getName());
        criteria.addCriteria(TransactionFieldMeta.TRANSACTION_ID, transactionId);
        criteria.addCriteria(TransactionFieldMeta.FIELD_NAME, fieldName);
        for (Object result : uow.query(criteria)) {
            if (result instanceof TransactionField) {
                field = (TransactionField) result;
                break;
            }
        }
    } finally {
        if (uow != null) {
            uow.close();
        }
    }
    return field;
}
Also used : TransactionField(org.jaffa.transaction.domain.TransactionField) Criteria(org.jaffa.persistence.Criteria) TransactionFieldCriteria(org.jaffa.transaction.apis.data.TransactionFieldCriteria) AtomicCriteria(org.jaffa.persistence.AtomicCriteria) TransactionCriteria(org.jaffa.transaction.apis.data.TransactionCriteria) UOW(org.jaffa.persistence.UOW)

Example 50 with UOW

use of org.jaffa.persistence.UOW in project jaffa-framework by jaffa-projects.

the class JaffaTransactionMessageService method getCountOpenInProgress.

/**
 * Gets the count of all Transactions with the specified field-value that are in the Open or InProgress state.
 *
 * @param field the field to check the value of
 * @param value the input value of the field we are looking for
 * @return the count of all Transactions with the specified field-value that are in the Open or InProgress state
 * @throws FrameworkException
 */
@Override
public long getCountOpenInProgress(String field, String value) throws FrameworkException {
    UOW uow = null;
    long transactionCount = 0;
    try {
        uow = new UOW();
        Criteria criteria = new Criteria();
        criteria.setTable(TransactionMeta.getName());
        AtomicCriteria ac0 = new AtomicCriteria();
        ac0.addCriteria(TransactionMeta.STATUS, Transaction.Status.O.toString());
        ac0.addOrCriteria(TransactionMeta.STATUS, Transaction.Status.I.toString());
        criteria.addAtomic(ac0);
        Criteria transactionFieldCriteria = new Criteria();
        transactionFieldCriteria.setTable(TransactionFieldMeta.getName());
        transactionFieldCriteria.addInnerCriteria(TransactionFieldMeta.TRANSACTION_ID, TransactionMeta.ID);
        criteria.addAggregate(transactionFieldCriteria);
        AtomicCriteria ac = new AtomicCriteria();
        ac.addCriteria(TransactionFieldMeta.FIELD_NAME, field);
        ac.addCriteria(TransactionFieldMeta.VALUE, value);
        transactionFieldCriteria.addAtomic(ac);
        // return the count, or zero
        for (Object result : uow.query(criteria)) {
            if (!(result instanceof Transaction)) {
                continue;
            }
            transactionCount++;
        }
    } finally {
        if (uow != null) {
            uow.close();
        }
    }
    return transactionCount;
}
Also used : Transaction(org.jaffa.transaction.domain.Transaction) AtomicCriteria(org.jaffa.persistence.AtomicCriteria) Criteria(org.jaffa.persistence.Criteria) TransactionFieldCriteria(org.jaffa.transaction.apis.data.TransactionFieldCriteria) AtomicCriteria(org.jaffa.persistence.AtomicCriteria) TransactionCriteria(org.jaffa.transaction.apis.data.TransactionCriteria) UOW(org.jaffa.persistence.UOW)

Aggregations

UOW (org.jaffa.persistence.UOW)260 Criteria (org.jaffa.persistence.Criteria)139 FrameworkException (org.jaffa.exceptions.FrameworkException)99 ApplicationException (org.jaffa.exceptions.ApplicationException)88 AtomicCriteria (org.jaffa.persistence.AtomicCriteria)87 ApplicationExceptions (org.jaffa.exceptions.ApplicationExceptions)82 Iterator (java.util.Iterator)47 TransactionCriteria (org.jaffa.transaction.apis.data.TransactionCriteria)33 TransactionFieldCriteria (org.jaffa.transaction.apis.data.TransactionFieldCriteria)33 ArrayList (java.util.ArrayList)19 Transaction (org.jaffa.transaction.domain.Transaction)19 Map (java.util.Map)16 LinkedHashMap (java.util.LinkedHashMap)13 HashMap (java.util.HashMap)12 DateTime (org.jaffa.datatypes.DateTime)11 FormTemplate (org.jaffa.modules.printing.domain.FormTemplate)10 IPersistent (org.jaffa.persistence.IPersistent)10 Method (java.lang.reflect.Method)9 Collection (java.util.Collection)8 DomainObjectNotFoundException (org.jaffa.exceptions.DomainObjectNotFoundException)8