Search in sources :

Example 1 with StringCriteriaField

use of org.jaffa.components.finder.StringCriteriaField in project jaffa-framework by jaffa-projects.

the class GraphCriteriaFlexFieldsTest method testCriteriaClauseDomainMapped.

public void testCriteriaClauseDomainMapped() throws FrameworkException, ApplicationExceptions {
    UserCriteria userCriteria = new UserCriteria();
    StaticContext.initialize(userCriteria);
    assertNotNull(userCriteria.getFlexCriteriaBean());
    Criteria c = userCriteria.buildQueryCriteria();
    assertNull(c.getCriteriaEntries());
    userCriteria.getFlexCriteriaBean().set("remarks", new StringCriteriaField("Equals", "nice guy"));
    c = userCriteria.buildQueryCriteria();
    assertNotNull(c.getCriteriaEntries());
    assertEquals(1, c.getCriteriaEntries().size());
    List<Criteria.CriteriaEntry> criteriaEntries = new ArrayList<>(c.getCriteriaEntries());
    assertEquals("nice guy", criteriaEntries.get(0).getValue());
    assertEquals("UserRef15", criteriaEntries.get(0).getName());
}
Also used : UserCriteria(org.jaffa.rules.testmodels.UserCriteria) ArrayList(java.util.ArrayList) Criteria(org.jaffa.persistence.Criteria) UserCriteria(org.jaffa.rules.testmodels.UserCriteria) StringCriteriaField(org.jaffa.components.finder.StringCriteriaField)

Example 2 with StringCriteriaField

use of org.jaffa.components.finder.StringCriteriaField in project jaffa-framework by jaffa-projects.

the class MessageViewerTx method buildBusinessEventLogDto.

/**
 * Obtains the related business event logs.
 */
private void buildBusinessEventLogDto(MessageViewerInDto input, MessageViewerOutDto output, Message message) throws FrameworkException, ApplicationExceptions, JMSException {
    BusinessEventLogFinderInDto inputDto = new BusinessEventLogFinderInDto();
    inputDto.setMessageId(message.getStringProperty(JmsBrowser.HEADER_ORIGINAL_MESSAGE_ID) != null ? new StringCriteriaField(CriteriaField.RELATIONAL_EQUALS, message.getStringProperty(JmsBrowser.HEADER_ORIGINAL_MESSAGE_ID)) : new StringCriteriaField(CriteriaField.RELATIONAL_EQUALS, message.getJMSMessageID()));
    inputDto.setMaxRecords(new Integer(10));
    inputDto.setOrderByFields(new OrderByField[] { new OrderByField(BusinessEventLogMeta.LOGGED_ON, Boolean.FALSE) });
    BusinessEventLogFinderOutDto businessEventLogFinderOutDto = new BusinessEventLogFinderTx().find(inputDto);
    output.setBusinessEventLog(businessEventLogFinderOutDto);
}
Also used : BusinessEventLogFinderTx(org.jaffa.modules.messaging.components.businesseventlogfinder.tx.BusinessEventLogFinderTx) OrderByField(org.jaffa.components.finder.OrderByField) BusinessEventLogFinderOutDto(org.jaffa.modules.messaging.components.businesseventlogfinder.dto.BusinessEventLogFinderOutDto) BusinessEventLogFinderInDto(org.jaffa.modules.messaging.components.businesseventlogfinder.dto.BusinessEventLogFinderInDto) StringCriteriaField(org.jaffa.components.finder.StringCriteriaField)

Example 3 with StringCriteriaField

use of org.jaffa.components.finder.StringCriteriaField in project jaffa-framework by jaffa-projects.

the class JaffaTransactionMessageService method getTransactionByFieldsAndBeginsWithFields.

/**
 * Gets the Transaction that has the specified fields-values and also fields that begin with
 * the specified values.  If multiple beginsWith values are defined for a field, the field will be checked against
 * them all.
 *
 * @param fields     the field name/value pairs
 * @param beginsWith the field name/begins-with values
 * @return the Transaction that contains the specified fields with the input values
 * @throws FrameworkException
 */
@Override
public Transaction getTransactionByFieldsAndBeginsWithFields(HashMap<String, String> fields, HashMap<String, String> beginsWith) throws FrameworkException {
    UOW uow = null;
    Transaction transaction = null;
    try {
        uow = new UOW();
        TransactionCriteria transactionCriteria = new TransactionCriteria();
        List<TransactionFieldCriteria> tranFieldCriteriaList = new ArrayList<TransactionFieldCriteria>();
        // add all of the field criteria
        for (Map.Entry<String, String> field : fields.entrySet()) {
            TransactionFieldCriteria fieldCriteria = new TransactionFieldCriteria();
            fieldCriteria.setFieldName(field.getKey());
            StringCriteriaField stringCriteria = StringCriteriaField.getStringCriteriaField(StringCriteriaField.RELATIONAL_EQUALS, field.getValue(), null);
            fieldCriteria.setValue(stringCriteria);
            tranFieldCriteriaList.add(fieldCriteria);
        }
        // add all of the begins with criteria
        for (Map.Entry<String, String> beginsWithField : beginsWith.entrySet()) {
            TransactionFieldCriteria beginsWithCriteria = new TransactionFieldCriteria();
            beginsWithCriteria.setFieldName(beginsWithField.getKey());
            StringCriteriaField stringCriteria = StringCriteriaField.getStringCriteriaField(StringCriteriaField.RELATIONAL_BEGINS_WITH, beginsWithField.getValue(), null);
            beginsWithCriteria.setValue(stringCriteria);
            tranFieldCriteriaList.add(beginsWithCriteria);
        }
        // set all of the field criteria on the transaction criteria
        TransactionFieldCriteria[] criteriaArray = new TransactionFieldCriteria[tranFieldCriteriaList.size()];
        criteriaArray = tranFieldCriteriaList.toArray(criteriaArray);
        transactionCriteria.setTransactionFields(criteriaArray);
        // call the transaction service for a response to the query
        TransactionService transactionService = new TransactionService();
        TransactionQueryResponse response = transactionService.query(transactionCriteria);
        // return a transaction from the response
        for (TransactionGraph transactionGraph : response.getGraphs()) {
            if ((transactionGraph != null) && (transactionGraph.getId() != null)) {
                transaction = getTransaction(transactionGraph.getId());
            }
        }
    } finally {
        if (uow != null) {
            uow.close();
        }
    }
    return transaction;
}
Also used : TransactionService(org.jaffa.transaction.apis.TransactionService) TransactionFieldCriteria(org.jaffa.transaction.apis.data.TransactionFieldCriteria) ArrayList(java.util.ArrayList) TransactionQueryResponse(org.jaffa.transaction.apis.data.TransactionQueryResponse) TransactionCriteria(org.jaffa.transaction.apis.data.TransactionCriteria) Transaction(org.jaffa.transaction.domain.Transaction) TransactionGraph(org.jaffa.transaction.apis.data.TransactionGraph) UOW(org.jaffa.persistence.UOW) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) StringCriteriaField(org.jaffa.components.finder.StringCriteriaField)

Example 4 with StringCriteriaField

use of org.jaffa.components.finder.StringCriteriaField in project jaffa-framework by jaffa-projects.

the class JaffaTransactionMessageService method getTransactionsByTypeSubTypeFieldsOrderBy.

/**
 * Gets an ordered list of Transaction that match the input type, subType and fields.
 * If more than one value is defined for a field, that field will be checked against all values to see if it
 * matched any of them (they will be OR-ed).
 *
 * @param type    the type of Transactions to return
 * @param subType the subType of Transactions to return
 * @param fields  the fields to check the Transaction for, if multiple values are defined for a field, the
 *                field will be checked to see if it matches any of the values (they will be OR-ed)
 * @param orderBy the fields to sort the return list by, each field has a boolean value that determines the
 *                direction.  True for ascending and false for descending.
 * @return an ordered list of Transactions that match the input type, subType and fields
 * @throws FrameworkException
 */
@Override
public List<Transaction> getTransactionsByTypeSubTypeFieldsOrderBy(String type, String subType, HashMap<String, List<String>> fields, LinkedHashMap<String, Boolean> orderBy) throws FrameworkException {
    List<Transaction> results = new ArrayList<Transaction>();
    UOW uow = null;
    try {
        uow = new UOW();
        Criteria c = new Criteria();
        c.setTable(TransactionMeta.getName());
        // query on type and subType
        StringCriteriaField typeField = StringCriteriaField.getStringCriteriaField(CriteriaField.RELATIONAL_EQUALS, type, null);
        StringCriteriaField subTypeField = StringCriteriaField.getStringCriteriaField(CriteriaField.RELATIONAL_EQUALS, subType, null);
        FinderTx.addCriteria(typeField, TransactionMeta.TYPE, c);
        FinderTx.addCriteria(subTypeField, TransactionMeta.SUB_TYPE, c);
        // add the fields
        for (Map.Entry<String, List<String>> entry : fields.entrySet()) {
            Criteria joinCriteria = new Criteria();
            joinCriteria.setTable(TransactionFieldMeta.getName());
            joinCriteria.addInnerCriteria(TransactionFieldMeta.TRANSACTION_ID, TransactionMeta.ID);
            // the key is the field name
            joinCriteria.addCriteria(TransactionFieldMeta.FIELD_NAME, entry.getKey());
            // the values are OR-ed together
            AtomicCriteria ac = new AtomicCriteria();
            for (String value : entry.getValue()) {
                if (value == null) {
                    if ((ac.getCriteriaEntries() == null) || ac.getCriteriaEntries().isEmpty()) {
                        ac.addCriteria(TransactionFieldMeta.VALUE, Criteria.RELATIONAL_IS_NULL);
                    } else {
                        ac.addOrCriteria(TransactionFieldMeta.VALUE, Criteria.RELATIONAL_IS_NULL);
                    }
                } else {
                    if ((ac.getCriteriaEntries() == null) || ac.getCriteriaEntries().isEmpty()) {
                        ac.addCriteria(TransactionFieldMeta.VALUE, value);
                    } else {
                        ac.addOrCriteria(TransactionFieldMeta.VALUE, value);
                    }
                }
            }
            joinCriteria.addAtomic(ac);
            c.addAggregate(joinCriteria);
        }
        // add the orderBy
        for (Map.Entry<String, Boolean> entry : orderBy.entrySet()) {
            int sort = Criteria.ORDER_BY_ASC;
            if (entry.getValue() != null && !entry.getValue()) {
                sort = Criteria.ORDER_BY_DESC;
            }
            c.addOrderBy(entry.getKey(), sort);
        }
        // add the query results to the return list
        for (Object o : uow.query(c)) {
            results.add((Transaction) o);
        }
    } finally {
        if (uow != null) {
            uow.close();
        }
    }
    return results;
}
Also used : ArrayList(java.util.ArrayList) 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) Transaction(org.jaffa.transaction.domain.Transaction) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) UOW(org.jaffa.persistence.UOW) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) StringCriteriaField(org.jaffa.components.finder.StringCriteriaField)

Example 5 with StringCriteriaField

use of org.jaffa.components.finder.StringCriteriaField in project jaffa-framework by jaffa-projects.

the class AttachmentFinderInDtoTapGenTest method testGetAttachmentType.

/**
 * Test method for {@link org.jaffa.components.attachment.components.attachmentfinder.dto.AttachmentFinderInDto#getAttachmentType()}.
 */
@Test
public void testGetAttachmentType() {
    AttachmentFinderInDto testObject = new AttachmentFinderInDto();
    StringCriteriaField setValue = new StringCriteriaField();
    testObject.setAttachmentType(setValue);
    StringCriteriaField getValue = testObject.getAttachmentType();
    assertEquals(setValue, getValue);
}
Also used : StringCriteriaField(org.jaffa.components.finder.StringCriteriaField) Test(org.junit.Test)

Aggregations

StringCriteriaField (org.jaffa.components.finder.StringCriteriaField)27 Test (org.junit.Test)20 ArrayList (java.util.ArrayList)3 Criteria (org.jaffa.persistence.Criteria)3 Transaction (org.jaffa.transaction.domain.Transaction)3 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 OrderByField (org.jaffa.components.finder.OrderByField)2 BusinessEventLogFinderInDto (org.jaffa.modules.messaging.components.businesseventlogfinder.dto.BusinessEventLogFinderInDto)2 BusinessEventLogFinderTx (org.jaffa.modules.messaging.components.businesseventlogfinder.tx.BusinessEventLogFinderTx)2 UOW (org.jaffa.persistence.UOW)2 TransactionCriteria (org.jaffa.transaction.apis.data.TransactionCriteria)2 TransactionFieldCriteria (org.jaffa.transaction.apis.data.TransactionFieldCriteria)2 LinkedList (java.util.LinkedList)1 List (java.util.List)1 BusinessEventLogFinderOutDto (org.jaffa.modules.messaging.components.businesseventlogfinder.dto.BusinessEventLogFinderOutDto)1 AtomicCriteria (org.jaffa.persistence.AtomicCriteria)1 UserCriteria (org.jaffa.rules.testmodels.UserCriteria)1 GraphCriteria (org.jaffa.soa.graph.GraphCriteria)1