Search in sources :

Example 11 with LastModifiedMessage

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

the class v2ClientPerMessageCacheTest method testRecordThenActivityCache.

@Test
public void testRecordThenActivityCache() throws LockedRecordException, DeprecatedRecordException {
    // get it once
    Date date = new Date();
    date.setYear(1900);
    BaseMessage message1 = new LastModifiedMessage("0000-0000-0000-0000", date);
    Record r = orcid20ApiClient.fetchPublicRecord(message1);
    assertEquals("http://orcid.org/0000-0000-0000-0000", r.getOrcidIdentifier().getPath());
    // get it twice, if no error, then it's the cached version
    when(mock_response.getEntity(Record.class)).thenThrow(new RuntimeException("called twice!"));
    ActivitiesSummary s = orcid20ApiClient.fetchPublicActivities(message1);
    assertEquals(s.getWorks().getWorkGroup().get(0).getWorkSummary().get(0).getTitle().getTitle().getContent(), "blah");
    // get it with a different message, should return fresh
    BaseMessage message2 = new LastModifiedMessage("0000-0000-0000-0000", new Date());
    try {
        s = orcid20ApiClient.fetchPublicActivities(message2);
        fail("returned cached when it should get fresh");
    } catch (RuntimeException e) {
        if (e.getMessage() != "called twice!")
            fail("something weird");
    }
}
Also used : BaseMessage(org.orcid.utils.listener.BaseMessage) LastModifiedMessage(org.orcid.utils.listener.LastModifiedMessage) Record(org.orcid.jaxb.model.record_v2.Record) Date(java.util.Date) ActivitiesSummary(org.orcid.jaxb.model.record.summary_v2.ActivitiesSummary) Test(org.junit.Test)

Example 12 with LastModifiedMessage

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

the class UpdatedOrcidWorker method onRemoval.

/**
 * Fires when the queue evicts after an inactivity period.
 * Populates the Amazon S3 buckets and updates solr index
 */
public void onRemoval(RemovalNotification<String, LastModifiedMessage> removal) {
    if (removal.wasEvicted()) {
        LastModifiedMessage m = removal.getValue();
        LOG.info("Removing " + removal.getKey() + " from UpdatedOrcidCacheQueue '" + m.getLastUpdated() + "' Removal cause " + removal.getCause());
        s3Processor.accept(m);
        solrProcessor.accept(m);
        mongoProcessor.accept(m);
    }
}
Also used : LastModifiedMessage(org.orcid.utils.listener.LastModifiedMessage)

Example 13 with LastModifiedMessage

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

the class ReIndexListener method processMessage.

/**
 * Processes messages on receipt.
 *
 * @param map
 * @throws JsonProcessingException
 * @throws JAXBException
 * @throws AmazonClientException
 */
@JmsListener(destination = MessageConstants.Queues.REINDEX)
public void processMessage(final Map<String, String> map) throws JsonProcessingException, AmazonClientException, JAXBException {
    LastModifiedMessage message = new LastModifiedMessage(map);
    String orcid = message.getOrcid();
    LOG.info("Recieved " + MessageConstants.Queues.REINDEX + " message for orcid " + orcid + " " + message.getLastUpdated());
    s3Processor.accept(message);
    solrProcessor.accept(message);
    mongoProcessor.accept(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