Search in sources :

Example 1 with Email

use of org.orcid.jaxb.model.record_rc2.Email in project camel by apache.

the class SimpleMessagingExample method sendMessage.

public void sendMessage() throws Exception {
    DefaultCamelContext context = new DefaultCamelContext();
    final CountDownLatch logonLatch = new CountDownLatch(2);
    final CountDownLatch receivedMessageLatch = new CountDownLatch(1);
    RouteBuilder routes = new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            // Release latch when session logon events are received
            // We expect two events, one for the trader session and one for the market session
            from("quickfix:examples/inprocess.cfg").filter(header(QuickfixjEndpoint.EVENT_CATEGORY_KEY).isEqualTo(QuickfixjEventCategory.SessionLogon)).bean(new CountDownLatchDecrementer("logon", logonLatch));
            // For all received messages, print the JSON-formatted message to stdout
            from("quickfix:examples/inprocess.cfg").filter(PredicateBuilder.or(header(QuickfixjEndpoint.EVENT_CATEGORY_KEY).isEqualTo(QuickfixjEventCategory.AdminMessageReceived), header(QuickfixjEndpoint.EVENT_CATEGORY_KEY).isEqualTo(QuickfixjEventCategory.AppMessageReceived))).bean(new QuickfixjMessageJsonPrinter());
            // If the market session receives an email then release the latch
            from("quickfix:examples/inprocess.cfg?sessionID=FIX.4.2:MARKET->TRADER").filter(header(QuickfixjEndpoint.MESSAGE_TYPE_KEY).isEqualTo(MsgType.EMAIL)).bean(new CountDownLatchDecrementer("message", receivedMessageLatch));
        }
    };
    context.addRoutes(routes);
    LOG.info("Starting Camel context");
    context.start();
    if (!logonLatch.await(5L, TimeUnit.SECONDS)) {
        throw new IllegalStateException("Logon did not succeed");
    }
    String marketUri = "quickfix:examples/inprocess.cfg?sessionID=FIX.4.2:TRADER->MARKET";
    Producer producer = context.getEndpoint(marketUri).createProducer();
    Email email = TestSupport.createEmailMessage("Example");
    Exchange exchange = producer.createExchange(ExchangePattern.InOnly);
    exchange.getIn().setBody(email);
    producer.process(exchange);
    if (!receivedMessageLatch.await(5L, TimeUnit.SECONDS)) {
        throw new IllegalStateException("Message did not reach market");
    }
    LOG.info("Message received, shutting down Camel context");
    context.stop();
    LOG.info("Example complete");
}
Also used : QuickfixjMessageJsonPrinter(org.apache.camel.component.quickfixj.examples.transform.QuickfixjMessageJsonPrinter) Exchange(org.apache.camel.Exchange) Email(quickfix.fix42.Email) RouteBuilder(org.apache.camel.builder.RouteBuilder) Producer(org.apache.camel.Producer) CountDownLatch(java.util.concurrent.CountDownLatch) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) CountDownLatchDecrementer(org.apache.camel.component.quickfixj.examples.util.CountDownLatchDecrementer)

Example 2 with Email

use of org.orcid.jaxb.model.record_rc2.Email in project camel by apache.

the class QuickfixjComponentTest method messagePublication.

@Test
public void messagePublication() throws Exception {
    setUpComponent();
    // Create settings file with both acceptor and initiator
    SessionSettings settings = new SessionSettings();
    settings.setString(Acceptor.SETTING_SOCKET_ACCEPT_PROTOCOL, ProtocolFactory.getTypeString(ProtocolFactory.VM_PIPE));
    settings.setString(Initiator.SETTING_SOCKET_CONNECT_PROTOCOL, ProtocolFactory.getTypeString(ProtocolFactory.VM_PIPE));
    settings.setBool(Session.SETTING_USE_DATA_DICTIONARY, false);
    SessionID acceptorSessionID = new SessionID(FixVersions.BEGINSTRING_FIX44, "ACCEPTOR", "INITIATOR");
    settings.setString(acceptorSessionID, SessionFactory.SETTING_CONNECTION_TYPE, SessionFactory.ACCEPTOR_CONNECTION_TYPE);
    settings.setLong(acceptorSessionID, Acceptor.SETTING_SOCKET_ACCEPT_PORT, 1234);
    setSessionID(settings, acceptorSessionID);
    SessionID initiatorSessionID = new SessionID(FixVersions.BEGINSTRING_FIX44, "INITIATOR", "ACCEPTOR");
    settings.setString(initiatorSessionID, SessionFactory.SETTING_CONNECTION_TYPE, SessionFactory.INITIATOR_CONNECTION_TYPE);
    settings.setLong(initiatorSessionID, Initiator.SETTING_SOCKET_CONNECT_PORT, 1234);
    settings.setLong(initiatorSessionID, Initiator.SETTING_RECONNECT_INTERVAL, 1);
    setSessionID(settings, initiatorSessionID);
    writeSettings(settings, true);
    Endpoint endpoint = component.createEndpoint(getEndpointUri(settingsFile.getName(), null));
    // Start the component and wait for the FIX sessions to be logged on
    final CountDownLatch logonLatch = new CountDownLatch(2);
    final CountDownLatch messageLatch = new CountDownLatch(2);
    Consumer consumer = endpoint.createConsumer(new Processor() {

        @Override
        public void process(Exchange exchange) throws Exception {
            QuickfixjEventCategory eventCategory = (QuickfixjEventCategory) exchange.getIn().getHeader(QuickfixjEndpoint.EVENT_CATEGORY_KEY);
            if (eventCategory == QuickfixjEventCategory.SessionLogon) {
                logonLatch.countDown();
            } else if (eventCategory == QuickfixjEventCategory.AppMessageReceived) {
                messageLatch.countDown();
            }
        }
    });
    ServiceHelper.startService(consumer);
    // will start the component
    camelContext.start();
    assertTrue("Session not created", logonLatch.await(5000, TimeUnit.MILLISECONDS));
    Endpoint producerEndpoint = component.createEndpoint(getEndpointUri(settingsFile.getName(), acceptorSessionID));
    Producer producer = producerEndpoint.createProducer();
    // FIX message to send
    Email email = new Email(new EmailThreadID("ID"), new EmailType(EmailType.NEW), new Subject("Test"));
    Exchange exchange = producer.createExchange(ExchangePattern.InOnly);
    exchange.getIn().setBody(email);
    producer.process(exchange);
    // Produce with no session ID specified, session ID must be in message
    Producer producer2 = endpoint.createProducer();
    email.getHeader().setString(SenderCompID.FIELD, acceptorSessionID.getSenderCompID());
    email.getHeader().setString(TargetCompID.FIELD, acceptorSessionID.getTargetCompID());
    producer2.process(exchange);
    assertTrue("Messages not received", messageLatch.await(5000, TimeUnit.MILLISECONDS));
}
Also used : Processor(org.apache.camel.Processor) Email(quickfix.fix44.Email) EmailType(quickfix.field.EmailType) EmailThreadID(quickfix.field.EmailThreadID) CountDownLatch(java.util.concurrent.CountDownLatch) SessionSettings(quickfix.SessionSettings) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) Subject(quickfix.field.Subject) Exchange(org.apache.camel.Exchange) Endpoint(org.apache.camel.Endpoint) Consumer(org.apache.camel.Consumer) Producer(org.apache.camel.Producer) SessionID(quickfix.SessionID) Test(org.junit.Test)

Example 3 with Email

use of org.orcid.jaxb.model.record_rc2.Email in project camel by apache.

the class QuickfixjProducerTest method processInOutExchangeSendUnsuccessful.

@Test
public void processInOutExchangeSendUnsuccessful() throws Exception {
    Mockito.when(mockExchange.getPattern()).thenReturn(ExchangePattern.InOut);
    Mockito.when(mockExchange.getProperty(QuickfixjProducer.CORRELATION_CRITERIA_KEY)).thenReturn(new MessagePredicate(sessionID, MsgType.EMAIL));
    Mockito.when(mockExchange.getProperty(QuickfixjProducer.CORRELATION_TIMEOUT_KEY, 1000L, Long.class)).thenReturn(5000L);
    org.apache.camel.Message mockOutboundCamelMessage = Mockito.mock(org.apache.camel.Message.class);
    Mockito.when(mockExchange.getOut()).thenReturn(mockOutboundCamelMessage);
    final Message outboundFixMessage = new Email();
    outboundFixMessage.getHeader().setString(SenderCompID.FIELD, "TARGET");
    outboundFixMessage.getHeader().setString(TargetCompID.FIELD, "SENDER");
    Session mockSession = Mockito.spy(TestSupport.createSession(sessionID));
    Mockito.doReturn(mockSession).when(producer).getSession(MessageUtils.getSessionID(inboundFixMessage));
    Mockito.doAnswer(new Answer<Boolean>() {

        @Override
        public Boolean answer(InvocationOnMock invocation) throws Throwable {
            new Timer().schedule(new TimerTask() {

                @Override
                public void run() {
                    try {
                        quickfixjEngine.getMessageCorrelator().onEvent(QuickfixjEventCategory.AppMessageReceived, sessionID, outboundFixMessage);
                    } catch (Exception e) {
                        throw new RuntimeException(e);
                    }
                }
            }, 10);
            return false;
        }
    }).when(mockSession).send(Matchers.isA(Message.class));
    producer.process(mockExchange);
    Mockito.verify(mockOutboundCamelMessage, Mockito.never()).setBody(Matchers.isA(Message.class));
    Mockito.verify(mockSession).send(inboundFixMessage);
    Mockito.verify(mockExchange).setException(Matchers.isA(CannotSendException.class));
}
Also used : Email(quickfix.fix42.Email) Message(quickfix.Message) IOException(java.io.IOException) JMException(javax.management.JMException) Timer(java.util.Timer) TimerTask(java.util.TimerTask) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Session(quickfix.Session) Test(org.junit.Test)

Example 4 with Email

use of org.orcid.jaxb.model.record_rc2.Email in project ORCID-Source by ORCID.

the class EmailManagerReadOnlyImpl method getEmails.

private Emails getEmails(String orcid, Visibility visibility) {
    List<EmailEntity> entities = new ArrayList<EmailEntity>();
    if (visibility == null) {
        entities = emailDao.findByOrcid(orcid);
    } else {
        entities = emailDao.findByOrcid(orcid, Visibility.PUBLIC);
    }
    List<org.orcid.jaxb.model.record_v2.Email> emailList = jpaJaxbEmailAdapter.toEmailList(entities);
    Emails emails = new Emails();
    emails.setEmails(emailList);
    return emails;
}
Also used : Email(org.orcid.jaxb.model.record_v2.Email) ArrayList(java.util.ArrayList) EmailEntity(org.orcid.persistence.jpa.entities.EmailEntity) Emails(org.orcid.jaxb.model.record_v2.Emails)

Example 5 with Email

use of org.orcid.jaxb.model.record_rc2.Email in project ORCID-Source by ORCID.

the class PersonDetailsManagerReadOnlyImpl method getPersonDetails.

@Override
public Person getPersonDetails(String orcid) {
    long lastModifiedTime = getLastModified(orcid);
    Person person = new Person();
    person.setName(recordNameManager.getRecordName(orcid, lastModifiedTime));
    person.setBiography(biographyManager.getBiography(orcid, lastModifiedTime));
    Addresses addresses = addressManager.getAddresses(orcid, lastModifiedTime);
    if (addresses.getAddress() != null) {
        Addresses filteredAddresses = new Addresses();
        filteredAddresses.setAddress(new ArrayList<Address>(addresses.getAddress()));
        person.setAddresses(filteredAddresses);
    }
    PersonExternalIdentifiers extIds = externalIdentifierManager.getExternalIdentifiers(orcid, lastModifiedTime);
    if (extIds.getExternalIdentifiers() != null) {
        PersonExternalIdentifiers filteredExtIds = new PersonExternalIdentifiers();
        filteredExtIds.setExternalIdentifiers(new ArrayList<PersonExternalIdentifier>(extIds.getExternalIdentifiers()));
        person.setExternalIdentifiers(filteredExtIds);
    }
    Keywords keywords = profileKeywordManager.getKeywords(orcid, lastModifiedTime);
    if (keywords.getKeywords() != null) {
        Keywords filteredKeywords = new Keywords();
        filteredKeywords.setKeywords(new ArrayList<Keyword>(keywords.getKeywords()));
        person.setKeywords(filteredKeywords);
    }
    OtherNames otherNames = otherNameManager.getOtherNames(orcid, lastModifiedTime);
    if (otherNames.getOtherNames() != null) {
        OtherNames filteredOtherNames = new OtherNames();
        filteredOtherNames.setOtherNames(new ArrayList<OtherName>(otherNames.getOtherNames()));
        person.setOtherNames(filteredOtherNames);
    }
    ResearcherUrls rUrls = researcherUrlManager.getResearcherUrls(orcid, lastModifiedTime);
    if (rUrls.getResearcherUrls() != null) {
        ResearcherUrls filteredRUrls = new ResearcherUrls();
        filteredRUrls.setResearcherUrls(new ArrayList<ResearcherUrl>(rUrls.getResearcherUrls()));
        person.setResearcherUrls(filteredRUrls);
    }
    Emails emails = emailManager.getEmails(orcid, lastModifiedTime);
    if (emails.getEmails() != null) {
        Emails filteredEmails = new Emails();
        filteredEmails.setEmails(new ArrayList<Email>(emails.getEmails()));
        person.setEmails(filteredEmails);
    }
    return person;
}
Also used : Keywords(org.orcid.jaxb.model.record_v2.Keywords) Email(org.orcid.jaxb.model.record_v2.Email) Address(org.orcid.jaxb.model.record_v2.Address) Keyword(org.orcid.jaxb.model.record_v2.Keyword) OtherNames(org.orcid.jaxb.model.record_v2.OtherNames) OtherName(org.orcid.jaxb.model.record_v2.OtherName) PersonExternalIdentifier(org.orcid.jaxb.model.record_v2.PersonExternalIdentifier) Addresses(org.orcid.jaxb.model.record_v2.Addresses) PersonExternalIdentifiers(org.orcid.jaxb.model.record_v2.PersonExternalIdentifiers) ResearcherUrls(org.orcid.jaxb.model.record_v2.ResearcherUrls) ResearcherUrl(org.orcid.jaxb.model.record_v2.ResearcherUrl) Emails(org.orcid.jaxb.model.record_v2.Emails) Person(org.orcid.jaxb.model.record_v2.Person)

Aggregations

Email (org.orcid.jaxb.model.record_v2.Email)82 Test (org.junit.Test)79 Emails (org.orcid.jaxb.model.record_v2.Emails)49 Address (org.orcid.jaxb.model.record_v2.Address)41 Keyword (org.orcid.jaxb.model.record_v2.Keyword)41 PersonExternalIdentifier (org.orcid.jaxb.model.record_v2.PersonExternalIdentifier)41 ResearcherUrl (org.orcid.jaxb.model.record_v2.ResearcherUrl)41 OtherName (org.orcid.jaxb.model.record_v2.OtherName)39 Person (org.orcid.jaxb.model.record_v2.Person)35 Biography (org.orcid.jaxb.model.record_v2.Biography)34 OtherNames (org.orcid.jaxb.model.record_v2.OtherNames)33 Addresses (org.orcid.jaxb.model.record_v2.Addresses)31 Keywords (org.orcid.jaxb.model.record_v2.Keywords)31 PersonExternalIdentifiers (org.orcid.jaxb.model.record_v2.PersonExternalIdentifiers)31 ResearcherUrls (org.orcid.jaxb.model.record_v2.ResearcherUrls)31 Name (org.orcid.jaxb.model.record_v2.Name)30 Record (org.orcid.jaxb.model.record_v2.Record)19 ArrayList (java.util.ArrayList)18 EducationSummary (org.orcid.jaxb.model.record.summary_v2.EducationSummary)18 EmploymentSummary (org.orcid.jaxb.model.record.summary_v2.EmploymentSummary)18