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());
}
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");
}
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");
}
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");
}
}
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");
}
}
Aggregations