<commit_before>#   Copyright 2013 <NAME>
#
#   Licensed under the Apache License, Version 2.0 (the "License");
#   you may not use this file except in compliance with the License.
#   You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
#   Unless required by applicable law or agreed to in writing, software
#   distributed under the License is distributed on an "AS IS" BASIS,
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#   See the License for the specific language governing permissions and
#   limitations under the License.
soap = require 'soap'
MongoClient = require('mongodb').MongoClient
mongoUrl = "mongodb://127.0.0.1:27017/galegis-api-dev"

sessionSvcUri = "./wsdl/Sessions.svc.xml"

persistSession = (session, callback) ->
  sessionInstance =
    name: session.Description,
    current: (session.IsDefault.toLowerCase() == "true"),
    library: session.Library

  MongoClient.connect mongoUrl, (err, db) ->
    if err
      callback(err)
      return

    db.collection("sessions").update
      assemblyId: Number(session.Id)
    ,
      "$set": sessionInstance
    ,
      safe: true,
      upsert: true
    , (err, doc) ->
      db.close()

      if err
        console.err err
        callback(err)
        return

      callback()

module.exports = (jobs) ->
  jobs.process 'import sessions', (job, done) ->
    soap.createClient sessionSvcUri, (err, client) ->
      if err
        console.error(err)
        done(err)
        return

      client.SessionService.BasicHttpBinding_SessionFinder.GetSessions (err, result, raw) ->
        if err
          console.error(err)
          done(err)
          return

        sessions = result.GetSessionsResult.Session

        persistSession(session, done) for session in sessions<commit_msg>Rewrite sessions import with ifSuccessful helper.<commit_after>#   Copyright 2013 <NAME>
#
#   Licensed under the Apache License, Version 2.0 (the "License");
#   you may not use this file except in compliance with the License.
#   You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
#   Unless required by applicable law or agreed to in writing, software
#   distributed under the License is distributed on an "AS IS" BASIS,
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#   See the License for the specific language governing permissions and
#   limitations under the License.
helpers = require '../util/helpers'
ifSuccessful = helpers.ifSuccessful

soap = require 'soap'
MongoClient = require('mongodb').MongoClient
mongoUrl = "mongodb://127.0.0.1:27017/galegis-api-dev"

sessionSvcUri = "./wsdl/Sessions.svc.xml"

persistSession = (session, callback) ->
  sessionInstance =
    name: session.Description,
    current: (session.IsDefault.toLowerCase() == "true"),
    library: session.Library

  MongoClient.connect mongoUrl, (err, db) -> ifSuccessful err, callback, ->
    db.collection("sessions").update
      assemblyId: Number(session.Id)
    ,
      "$set": sessionInstance
    ,
      safe: true,
      upsert: true
    , (err, doc) ->
      db.close()

      ifSuccessful err, callback, ->
        callback()

module.exports = (jobs) ->
  jobs.process 'import sessions', (job, callback) ->
    soap.createClient sessionSvcUri, (err, client) -> ifSuccessful err, callback, ->
      client.SessionService.BasicHttpBinding_SessionFinder.GetSessions (err, result, raw) ->
        ifSuccessful err, callback, ->
          sessions = result.GetSessionsResult.Session
          persistSession(session, callback) for session in sessions
{'fraction_non_alphanumeric': 0.10472787245739418, 'fraction_numerical': 0.010445299615173173, 'mean_word_length': 3.0795964125560538, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2238120', 'n_tokens_mistral': 1066, 'n_tokens_neox': 1044, 'n_words': 325}