Search in sources :

Example 6 with Message

use of io.tbd.tbdex.protocol.core.Message in project tbdex-protocol by TBD54566975.

the class OfferAcceptProcessor method process.

@Override
public Message process(Message message) {
    String messageId = UUID.randomUUID().toString();
    // TODO: send real schema
    SettlementRequest settlementRequest = new SettlementRequest("schema");
    return new Message.Builder(messageId, message.threadID(), message.to(), message.from()).build(settlementRequest);
}
Also used : Message(io.tbd.tbdex.protocol.core.Message) SettlementRequest(io.tbd.tbdex.protocol.messages.SettlementRequest)

Example 7 with Message

use of io.tbd.tbdex.protocol.core.Message in project tbdex-protocol by TBD54566975.

the class HibernateMessageThreadStore method getThread.

@SuppressWarnings("unchecked")
@Override
public MessageThread getThread(String threadToken) {
    Session session = HibernateUtil.getSession();
    Transaction tx = session.getTransaction();
    tx.begin();
    Query query = session.createQuery(// TODO: add a message order field, using created_at is just temporary
    "from DbMessage where thread_token=:t order by created_at asc").setParameter("t", threadToken);
    LinkedList<Message> messages = (LinkedList<Message>) query.list().stream().map(m -> ((DbMessage) m).getMessage()).collect(Collectors.toCollection(LinkedList::new));
    tx.commit();
    session.close();
    return new MessageThread(messages);
}
Also used : Transaction(org.hibernate.Transaction) Query(org.hibernate.query.Query) Message(io.tbd.tbdex.protocol.core.Message) MessageThread(io.tbd.tbdex.protocol.core.MessageThread) LinkedList(java.util.LinkedList) Session(org.hibernate.Session)

Aggregations

Message (io.tbd.tbdex.protocol.core.Message)7 Ask (io.tbd.tbdex.protocol.messages.Ask)4 DisplayName (org.junit.jupiter.api.DisplayName)3 Test (org.junit.jupiter.api.Test)3 MessageThread (io.tbd.tbdex.protocol.core.MessageThread)2 SettlementDetails (io.tbd.tbdex.protocol.messages.SettlementDetails)2 PaymentProcessorRequest (com.squareup.protos.tbd.pfi.PaymentProcessorRequest)1 ConditionalOffer (io.tbd.tbdex.protocol.messages.ConditionalOffer)1 SettlementReceipt (io.tbd.tbdex.protocol.messages.SettlementReceipt)1 SettlementRequest (io.tbd.tbdex.protocol.messages.SettlementRequest)1 LinkedList (java.util.LinkedList)1 Session (org.hibernate.Session)1 Transaction (org.hibernate.Transaction)1 Query (org.hibernate.query.Query)1