Search in sources :

Example 6 with LastModifiedMessage

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

the class OrcidProfileManagerImpl method processProfilesWithFlagAndAddToMessageQueue.

/**
 * Simple method to be called by scheduler. Looks for profiles with REINDEX
 * flag and adds LastModifiedMessages to the REINDEX queue Then sets
 * indexing flag to DONE (although there is no guarantee it will be done!)
 */
private void processProfilesWithFlagAndAddToMessageQueue(IndexingStatus status, JmsDestination destination) {
    LOG.info("processing profiles with " + status.name() + " flag. sending to " + destination.name());
    List<Pair<String, IndexingStatus>> orcidsForIndexing = new ArrayList<>();
    List<IndexingStatus> indexingStatuses = new ArrayList<IndexingStatus>(1);
    indexingStatuses.add(status);
    boolean connectionIssue = false;
    do {
        orcidsForIndexing = profileDaoReadOnly.findOrcidsByIndexingStatus(indexingStatuses, INDEXING_BATCH_SIZE, new ArrayList<String>());
        LOG.info("processing batch of " + orcidsForIndexing.size());
        for (Pair<String, IndexingStatus> p : orcidsForIndexing) {
            String orcid = p.getLeft();
            Date last = profileDaoReadOnly.retrieveLastModifiedDate(orcid);
            LastModifiedMessage mess = new LastModifiedMessage(orcid, last);
            if (messaging.send(mess, destination))
                profileDao.updateIndexingStatus(orcid, IndexingStatus.DONE);
            else
                connectionIssue = true;
        }
    } while (!connectionIssue && !orcidsForIndexing.isEmpty());
    if (connectionIssue)
        LOG.warn("ABORTED processing profiles with " + status.name() + " flag. sending to " + destination.name());
}
Also used : LastModifiedMessage(org.orcid.utils.listener.LastModifiedMessage) ArrayList(java.util.ArrayList) IndexingStatus(org.orcid.persistence.jpa.entities.IndexingStatus) Date(java.util.Date) Pair(org.apache.commons.lang3.tuple.Pair)

Example 7 with LastModifiedMessage

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

the class MongoMessageProcessorTest method testDeactivated.

@Test
public void testDeactivated() throws LockedRecordException, DeprecatedRecordException, DatatypeConfigurationException {
    Record deactivatedRecord = new Record();
    deactivatedRecord.setOrcidIdentifier(new OrcidIdentifier("http://orcid.org/" + this.orcid2));
    History h = new History();
    h.setDeactivationDate(new DeactivationDate());
    GregorianCalendar c = new GregorianCalendar();
    XMLGregorianCalendar date = DatatypeFactory.newInstance().newXMLGregorianCalendar(c);
    h.getDeactivationDate().setValue(date);
    deactivatedRecord.setHistory(h);
    when(mock_orcid20ApiClient.fetchPublicRecord(Matchers.any())).thenReturn(deactivatedRecord);
    LastModifiedMessage m = new LastModifiedMessage(this.orcid2, new Date());
    mongo.accept(m);
    // test db has entry for deactivated record
    Document d = new Document();
    d.put("_id", this.orcid2);
    assertEquals(col.count(d), 1);
    FindIterable<Document> it = col.find(d);
    assertEquals(it.first().get("status"), "deactivated");
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) OrcidIdentifier(org.orcid.jaxb.model.common_v2.OrcidIdentifier) LastModifiedMessage(org.orcid.utils.listener.LastModifiedMessage) GregorianCalendar(java.util.GregorianCalendar) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) Record(org.orcid.jaxb.model.record_v2.Record) History(org.orcid.jaxb.model.record_v2.History) Document(org.bson.Document) DeactivationDate(org.orcid.jaxb.model.record_v2.DeactivationDate) Date(java.util.Date) DeactivationDate(org.orcid.jaxb.model.record_v2.DeactivationDate) Test(org.junit.Test)

Example 8 with LastModifiedMessage

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

the class MongoMessageProcessorTest method testDeprecated.

@Test
public void testDeprecated() throws LockedRecordException, DeprecatedRecordException {
    when(mock_orcid20ApiClient.fetchPublicRecord(Matchers.any())).thenThrow(new DeprecatedRecordException(new OrcidError()));
    LastModifiedMessage m = new LastModifiedMessage(this.orcid, new Date());
    mongo.accept(m);
    // test db has entry for depreciated 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"), "deprecated");
}
Also used : OrcidError(org.orcid.jaxb.model.error_v2.OrcidError) DeprecatedRecordException(org.orcid.listener.exception.DeprecatedRecordException) 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 9 with LastModifiedMessage

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

the class v2ClientPerMessageCacheTest method testActivityCache.

@Test
public void testActivityCache() throws LockedRecordException, DeprecatedRecordException {
    // get it once
    Date date = new Date();
    date.setYear(1900);
    BaseMessage message1 = new LastModifiedMessage("0000-0000-0000-0000", date);
    ActivitiesSummary s = orcid20ApiClient.fetchPublicActivities(message1);
    assertEquals(s.getWorks().getWorkGroup().get(0).getWorkSummary().get(0).getTitle().getTitle().getContent(), "blah");
    // get it twice, if no error, then it's the cached version
    when(mock_response.getEntity(Record.class)).thenThrow(new RuntimeException("called twice!"));
    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) Date(java.util.Date) ActivitiesSummary(org.orcid.jaxb.model.record.summary_v2.ActivitiesSummary) Test(org.junit.Test)

Example 10 with LastModifiedMessage

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

the class v2ClientPerMessageCacheTest method testRecordCache.

@Test
public void testRecordCache() throws LockedRecordException, DeprecatedRecordException {
    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!"));
    r = orcid20ApiClient.fetchPublicRecord(message1);
    assertEquals("http://orcid.org/0000-0000-0000-0000", r.getOrcidIdentifier().getPath());
    // get it with a different message, should return fresh
    BaseMessage message2 = new LastModifiedMessage("0000-0000-0000-0000", new Date());
    try {
        r = orcid20ApiClient.fetchPublicRecord(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) Test(org.junit.Test)

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