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