use of org.sagebionetworks.repo.model.message.ChangeMessage in project Synapse-Repository-Services by Sage-Bionetworks.
the class MessageUtils method createMessage.
/**
* Create an Amazon message from a ChangeMessage. This is used for testing.
* @param message
* @return
*/
public static Message createMessage(ChangeMessage message, String messageId, String receiptHandle) {
if (message == null)
throw new IllegalArgumentException("Message cannot be null");
try {
Message result = new Message().withMessageId(messageId).withReceiptHandle(receiptHandle);
result.setBody(EntityFactory.createJSONStringForEntity(message));
return result;
} catch (JSONObjectAdapterException e) {
throw new RuntimeException(e);
}
}
use of org.sagebionetworks.repo.model.message.ChangeMessage in project Synapse-Repository-Services by Sage-Bionetworks.
the class MessageUtils method extractMessageBody.
/**
* Extract a ChangeMessage from an Amazon Message
* @param message
* @return
*/
public static ChangeMessage extractMessageBody(Message message) {
if (message == null)
throw new IllegalArgumentException("Message cannot be null");
try {
JSONObject object = new JSONObject(message.getBody());
if (object.has("objectId")) {
// This is a message pushed directly to a queue
JSONObjectAdapterImpl adapter = new JSONObjectAdapterImpl(object);
return new ChangeMessage(adapter);
}
if (object.has("TopicArn") && object.has("Message")) {
// This is a message that was pushed to a topic then forwarded to a queue.
JSONObject innerObject = new JSONObject(object.getString("Message"));
JSONObjectAdapterImpl adapter = new JSONObjectAdapterImpl(innerObject);
return new ChangeMessage(adapter);
} else {
throw new IllegalArgumentException("Unknown message type: " + message.getBody());
}
} catch (JSONException e) {
throw new RuntimeException(e);
} catch (JSONObjectAdapterException e) {
throw new RuntimeException(e);
}
}
use of org.sagebionetworks.repo.model.message.ChangeMessage in project Synapse-Repository-Services by Sage-Bionetworks.
the class TagMessengerImpl method generateEtagAndSendMessage.
@Override
public void generateEtagAndSendMessage(ObservableEntity observable, ChangeType changeType) {
// Send a message that an entity was created
String newEtag = eTagGenerator.generateETag(observable);
observable.seteTag(newEtag);
// Create the message
ChangeMessage message = new ChangeMessage();
message.setChangeType(changeType);
message.setObjectType(observable.getObjectType());
message.setObjectId(observable.getIdString());
message.setParentId(observable.getParentIdString());
message.setObjectEtag(observable.geteTag());
transactionalMessanger.sendMessageAfterCommit(message);
}
use of org.sagebionetworks.repo.model.message.ChangeMessage in project Synapse-Repository-Services by Sage-Bionetworks.
the class SearchQueueWorker method call.
@Override
public List<Message> call() throws Exception {
// Process each message
for (Message message : messagesToProcess) {
// Extract the ChangeMessage
ChangeMessage change = MessageUtils.extractMessageBody(message);
// We only care about entity messages as this time
if (ObjectType.ENTITY == change.getObjectType()) {
// Is this a create or update
if (ChangeType.CREATE == change.getChangeType() || ChangeType.UPDATE == change.getChangeType()) {
addCreateOrUpdateEntity(change);
} else if (ChangeType.DELETE == change.getChangeType()) {
addDeleteEntity(change);
} else {
throw new IllegalArgumentException("Unknown change type: " + change.getChangeType() + " for messageID =" + message.getMessageId());
}
}
}
processCreateUpdateBatch();
processDeleteBatch();
return messagesToProcess;
}
use of org.sagebionetworks.repo.model.message.ChangeMessage in project Synapse-Repository-Services by Sage-Bionetworks.
the class SearchQueueWorker method processCreateUpdateBatch.
/**
* Send the documents to search.
* @throws DatastoreException
* @throws NotFoundException
* @throws ClientProtocolException
* @throws IOException
* @throws HttpClientHelperException
*/
private void processCreateUpdateBatch() throws DatastoreException, NotFoundException, ClientProtocolException, IOException, HttpClientHelperException {
if (createOrUpdateMessages != null) {
log.debug("Processing " + createOrUpdateMessages.size() + " create/update messages");
// Prepare a batch of documents
List<Document> batch = new LinkedList<Document>();
for (ChangeMessage message : createOrUpdateMessages) {
// We want to ignore this message if a document with this ID and Etag already exists in the search index.
if (!searchDao.doesDocumentExist(message.getObjectId(), message.getObjectEtag())) {
// We want to ignore this message if a document with this ID and Etag are not in the repository as it is an old message.
if (documentProvider.doesDocumentExist(message.getObjectId(), message.getObjectEtag())) {
// Create a document for this
Document newDoc = documentProvider.formulateSearchDocument(message.getObjectId());
batch.add(newDoc);
}
}
}
if (!batch.isEmpty()) {
searchDao.createOrUpdateSearchDocument(batch);
}
}
}
Aggregations