|
|
@@ -34,45 +34,52 @@ module.exports = ReferencesSearchHandler =
|
|
|
owner = project.owner_ref
|
|
|
callback(null, owner.features.references == true)
|
|
|
|
|
|
- # projectId: String, docIds: List[String]|Null
|
|
|
+ indexAll: (projectId, callback=(err, data)->) ->
|
|
|
+ Project.findPopulatedById projectId, (err, project) ->
|
|
|
+ if err
|
|
|
+ logger.err {err, projectId}, "error finding project"
|
|
|
+ return callback(err)
|
|
|
+ logger.log {projectId}, "indexing all bib files in project"
|
|
|
+ docIds = ReferencesSearchHandler._findBibDocIds(project)
|
|
|
+ ReferencesSearchHandler._doIndexOperation(projectId, project, docIds, callback)
|
|
|
+
|
|
|
index: (projectId, docIds, callback=(err, data)->) ->
|
|
|
Project.findPopulatedById projectId, (err, project) ->
|
|
|
if err
|
|
|
logger.err {err, projectId}, "error finding project"
|
|
|
return callback(err)
|
|
|
- if docIds == "ALL"
|
|
|
- logger.log {projectId}, "indexing all bib files in project"
|
|
|
- docIds = ReferencesSearchHandler._findBibDocIds(project)
|
|
|
- ReferencesSearchHandler._isFullIndex project, (err, isFullIndex) ->
|
|
|
- if err
|
|
|
- logger.err {err, projectId}, "error checking whether to do full index"
|
|
|
- return callback(err)
|
|
|
- # TODO: flush documents to mongo
|
|
|
- logger.log {projectId, docIds}, 'flushing docs to mongo before calling references service'
|
|
|
- Async.series(
|
|
|
- docIds.map((docId) -> (cb) -> DocumentUpdaterHandler.flushDocToMongo(projectId, docId, cb)),
|
|
|
- (err) ->
|
|
|
- # continue
|
|
|
+ ReferencesSearchHandler._doIndexOperation(projectId, project, docIds, callback)
|
|
|
+
|
|
|
+ _doIndexOperation: (projectId, project, docIds, callback) ->
|
|
|
+ ReferencesSearchHandler._isFullIndex project, (err, isFullIndex) ->
|
|
|
+ if err
|
|
|
+ logger.err {err, projectId}, "error checking whether to do full index"
|
|
|
+ return callback(err)
|
|
|
+ logger.log {projectId, docIds}, 'flushing docs to mongo before calling references service'
|
|
|
+ Async.series(
|
|
|
+ docIds.map((docId) -> (cb) -> DocumentUpdaterHandler.flushDocToMongo(projectId, docId, cb)),
|
|
|
+ (err) ->
|
|
|
+ # continue
|
|
|
+ if err
|
|
|
+ logger.err {err, projectId, docIds}, "error flushing docs to mongo"
|
|
|
+ return callback(err)
|
|
|
+ bibDocUrls = docIds.map (docId) ->
|
|
|
+ ReferencesSearchHandler._buildDocUrl projectId, docId
|
|
|
+ logger.log {projectId, isFullIndex, docIds, bibDocUrls}, "sending request to references service"
|
|
|
+ request.post {
|
|
|
+ url: "#{settings.apis.references.url}/project/#{projectId}/index"
|
|
|
+ json:
|
|
|
+ docUrls: bibDocUrls
|
|
|
+ fullIndex: isFullIndex
|
|
|
+ }, (err, res, data) ->
|
|
|
if err
|
|
|
- logger.err {err, projectId, docIds}, "error flushing docs to mongo"
|
|
|
+ logger.err {err, projectId}, "error communicating with references api"
|
|
|
+ return callback(err)
|
|
|
+ if 200 <= res.statusCode < 300
|
|
|
+ logger.log {projectId}, "got keys from references api"
|
|
|
+ return callback(null, data)
|
|
|
+ else
|
|
|
+ err = new Error("references api responded with non-success code: #{res.statusCode}")
|
|
|
+ logger.log {err, projectId}, "error updating references"
|
|
|
return callback(err)
|
|
|
- bibDocUrls = docIds.map (docId) ->
|
|
|
- ReferencesSearchHandler._buildDocUrl projectId, docId
|
|
|
- logger.log {projectId, isFullIndex, docIds, bibDocUrls}, "sending request to references service"
|
|
|
- request.post {
|
|
|
- url: "#{settings.apis.references.url}/project/#{projectId}/index"
|
|
|
- json:
|
|
|
- docUrls: bibDocUrls
|
|
|
- fullIndex: isFullIndex
|
|
|
- }, (err, res, data) ->
|
|
|
- if err
|
|
|
- logger.err {err, projectId}, "error communicating with references api"
|
|
|
- return callback(err)
|
|
|
- if 200 <= res.statusCode < 300
|
|
|
- logger.log {projectId}, "got keys from references api"
|
|
|
- return callback(null, data)
|
|
|
- else
|
|
|
- err = new Error("references api responded with non-success code: #{res.statusCode}")
|
|
|
- logger.log {err, projectId}, "error updating references"
|
|
|
- return callback(err)
|
|
|
- )
|
|
|
+ )
|