/** Output records are not supported/required. */ public boolean execute(InteractionSpec spec, Record input, Record output) throws ResourceException { if (!(spec instanceof MongoInteractionSpec)) { throw EISException.invalidInteractionSpecType(); } if (!(input instanceof MongoRecord) || !(output instanceof MongoRecord)) { throw EISException.invalidRecordType(); } MongoInteractionSpec mongoSpec = (MongoInteractionSpec) spec; MongoRecord record = (MongoRecord) input; MongoRecord translationRecord = (MongoRecord) output; MongoOperation operation = mongoSpec.getOperation(); String collectionName = mongoSpec.getCollection(); if (operation == null) { throw new ResourceException("Mongo operation must be set"); } if (collectionName == null) { throw new ResourceException("DB Collection name must be set"); } try { DBCollection collection = this.connection.getDB().getCollection(collectionName); DBObject object = buildDBObject(record); DBObject translation = buildDBObject(translationRecord); if (operation == MongoOperation.UPDATE) { WriteResult result = collection.update(translation, object, mongoSpec.isUpsert(), mongoSpec.isMulti()); return result.getN() > 0; } else { throw new ResourceException("Invalid operation: " + operation); } } catch (Exception exception) { ResourceException resourceException = new ResourceException(exception.toString()); resourceException.initCause(exception); throw resourceException; } }