Search in sources :

Example 1 with LastModifiedMessage

use of org.orcid.utils.listener.LastModifiedMessage in project ORCID-Source by ORCID.

the class JmsMessagingSendReceiveReplyTest method testMessagBrokerWorking.

@Test
public void testMessagBrokerWorking() throws InterruptedException {
    Date now = new Date();
    LastModifiedMessage mess = new LastModifiedMessage(orcid, now);
    jmsTemplate.convertAndSend(MessageConstants.Queues.TEST, mess.map);
    Thread.sleep(1000);
    assertEquals(EchoTestMessageListener.message.getOrcid(), orcid);
    assertEquals(EchoTestMessageListener.message.getLastUpdated(), now);
}
Also used : LastModifiedMessage(org.orcid.utils.listener.LastModifiedMessage) Date(java.util.Date) Test(org.junit.Test)

Example 2 with LastModifiedMessage

use of org.orcid.utils.listener.LastModifiedMessage in project ORCID-Source by ORCID.

the class LastModifiedMessageProcessorTest method execute.

private void execute(String orcid) {
    Map<String, String> map = new HashMap<String, String>();
    String date = String.valueOf(System.currentTimeMillis());
    map.put(MessageConstants.ORCID.value, orcid);
    map.put(MessageConstants.DATE.value, date);
    map.put(MessageConstants.TYPE.value, MessageConstants.TYPE_LAST_UPDATED.value);
    LastModifiedMessage message = new LastModifiedMessage(map);
    processor.accept(message);
}
Also used : HashMap(java.util.HashMap) LastModifiedMessage(org.orcid.utils.listener.LastModifiedMessage) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString)

Example 3 with LastModifiedMessage

use of org.orcid.utils.listener.LastModifiedMessage in project ORCID-Source by ORCID.

the class MongoMessageProcessorTest method testLocked.

@Test
public void testLocked() throws LockedRecordException, DeprecatedRecordException {
    when(mock_orcid20ApiClient.fetchPublicRecord(Matchers.any())).thenThrow(new LockedRecordException(new OrcidError()));
    LastModifiedMessage m = new LastModifiedMessage(this.orcid, new Date());
    mongo.accept(m);
    // test db has entry for locked record
    Document d = new Document();
    d.put("_id", this.orcid);
    assertEquals(col.count(d), 1);
    FindIterable<Document> it = col.find(d);
    assertEquals(it.first().get("status"), "locked");
}
Also used : LockedRecordException(org.orcid.listener.exception.LockedRecordException) OrcidError(org.orcid.jaxb.model.error_v2.OrcidError) LastModifiedMessage(org.orcid.utils.listener.LastModifiedMessage) Document(org.bson.Document) Date(java.util.Date) DeactivationDate(org.orcid.jaxb.model.record_v2.DeactivationDate) Test(org.junit.Test)

Example 4 with LastModifiedMessage

use of org.orcid.utils.listener.LastModifiedMessage in project ORCID-Source by ORCID.

the class MongoMessageProcessorTest method testInsertAndUpsert.

@Test
public void testInsertAndUpsert() throws LockedRecordException, DeprecatedRecordException {
    Record record = new Record();
    record.setOrcidIdentifier(new OrcidIdentifier("http://orcid.org/" + this.orcid));
    ActivitiesSummary sum = new ActivitiesSummary();
    Works works = new Works();
    WorkGroup group = new WorkGroup();
    WorkSummary work = new WorkSummary();
    WorkTitle title = new WorkTitle();
    title.setTitle(new Title("blah"));
    work.setTitle(title);
    group.getWorkSummary().add(work);
    works.getWorkGroup().add(group);
    sum.setWorks(works);
    record.setActivitiesSummary(sum);
    when(mock_orcid20ApiClient.fetchPublicRecord(Matchers.any())).thenReturn(record);
    LastModifiedMessage m = new LastModifiedMessage(this.orcid, new Date());
    mongo.accept(m);
    // test record inserted (has work, no name)
    Document d = new Document();
    d.put("_id", this.orcid);
    assertEquals(col.count(d), 1);
    FindIterable<Document> it = col.find(d);
    Document found = it.first();
    assertEquals(found.get("orcid-identifier", Document.class).get("path"), "http://orcid.org/" + this.orcid);
    List<Document> groups = (List<Document>) found.get("activities-summary", Document.class).get("works", Document.class).get("group");
    List<Document> sums = (List<Document>) groups.get(0).get("work-summary");
    assertEquals(sums.get(0).get("title", Document.class).get("title", Document.class).get("value"), "blah");
    record.setPerson(new Person());
    record.getPerson().setName(new Name());
    record.getPerson().getName().setCreditName(new CreditName());
    record.getPerson().getName().getCreditName().setContent("name");
    ;
    LastModifiedMessage m2 = new LastModifiedMessage(this.orcid, new Date());
    mongo.accept(m2);
    it = col.find(d);
    found = it.first();
    assertEquals(found.get("person", Document.class).get("name", Document.class).get("credit-name", Document.class).get("value"), "name");
}
Also used : LastModifiedMessage(org.orcid.utils.listener.LastModifiedMessage) CreditName(org.orcid.jaxb.model.record_v2.CreditName) WorkTitle(org.orcid.jaxb.model.record_v2.WorkTitle) Title(org.orcid.jaxb.model.common_v2.Title) Document(org.bson.Document) Date(java.util.Date) DeactivationDate(org.orcid.jaxb.model.record_v2.DeactivationDate) ActivitiesSummary(org.orcid.jaxb.model.record.summary_v2.ActivitiesSummary) CreditName(org.orcid.jaxb.model.record_v2.CreditName) Name(org.orcid.jaxb.model.record_v2.Name) WorkGroup(org.orcid.jaxb.model.record.summary_v2.WorkGroup) WorkSummary(org.orcid.jaxb.model.record.summary_v2.WorkSummary) WorkTitle(org.orcid.jaxb.model.record_v2.WorkTitle) OrcidIdentifier(org.orcid.jaxb.model.common_v2.OrcidIdentifier) Record(org.orcid.jaxb.model.record_v2.Record) List(java.util.List) Works(org.orcid.jaxb.model.record.summary_v2.Works) Person(org.orcid.jaxb.model.record_v2.Person) Test(org.junit.Test)

Example 5 with LastModifiedMessage

use of org.orcid.utils.listener.LastModifiedMessage in project ORCID-Source by ORCID.

the class UpdatedOrcidListener method processMessage.

/**
 * Queues incoming messages for processing, eventually handled by UpdatedOrcidWorker
 *
 * @param map
 */
@JmsListener(destination = MessageConstants.Queues.UPDATED_ORCIDS)
public void processMessage(final Map<String, String> map) {
    LastModifiedMessage message = new LastModifiedMessage(map);
    LOG.info("Recieved " + MessageConstants.Queues.UPDATED_ORCIDS + " message for orcid " + message.getOrcid() + " " + message.getLastUpdated());
    LastModifiedMessage existingMessage = cacheQueue.getCache().getIfPresent(message.getOrcid());
    if (existingMessage == null || message.getLastUpdated().after(existingMessage.getLastUpdated()))
        cacheQueue.getCache().put(message.getOrcid(), message);
}
Also used : LastModifiedMessage(org.orcid.utils.listener.LastModifiedMessage) JmsListener(org.springframework.jms.annotation.JmsListener)

Aggregations

LastModifiedMessage (org.orcid.utils.listener.LastModifiedMessage)13 Date (java.util.Date)9 Test (org.junit.Test)8 Document (org.bson.Document)4 DeactivationDate (org.orcid.jaxb.model.record_v2.DeactivationDate)4 Record (org.orcid.jaxb.model.record_v2.Record)4 ActivitiesSummary (org.orcid.jaxb.model.record.summary_v2.ActivitiesSummary)3 BaseMessage (org.orcid.utils.listener.BaseMessage)3 OrcidIdentifier (org.orcid.jaxb.model.common_v2.OrcidIdentifier)2 OrcidError (org.orcid.jaxb.model.error_v2.OrcidError)2 JmsListener (org.springframework.jms.annotation.JmsListener)2 ArrayList (java.util.ArrayList)1 GregorianCalendar (java.util.GregorianCalendar)1 HashMap (java.util.HashMap)1 List (java.util.List)1 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)1 Pair (org.apache.commons.lang3.tuple.Pair)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1 Title (org.orcid.jaxb.model.common_v2.Title)1 WorkGroup (org.orcid.jaxb.model.record.summary_v2.WorkGroup)1