<commit_before>=begin

Copyright 2012-2013 inBloom, Inc. and its affiliates.

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.

=end
require 'open3'
require 'digest/sha1'
require_relative '../../../utils/sli_utils.rb'

$TAR_FILE_NAME = "Final.tar"
LEA_DAYBREAK_ID_VAL2 = '1b223f577827204a1c7e9c851dba06bea6b031fe_id'

Given /^I update the "(.*?)" with ID "(.*?)" field "(.*?)" to "(.*?)" on the sli database$/ do |collection, id, field, boolean|
  conn = Mongo::Connection.new(Property["ingestion_db"], Property["ingestion_db_port"])
  sli = conn.db("sli")

  coll = sli[collection]
  entity = coll.find_one({"_id" => id})
  assert(entity, "cant find #{collection} with id #{id}")
  entry = entity
  subfields = field.split(".")
  last = subfields.pop
  subfields.each { |subfield|
    entry = entry[subfield]
  }
  puts "saving entity: #{entity}"
  entry[last] = boolean=="true"
  coll.save(entity)
end

Given /^I am a valid 'service' user with an authorized long\-lived token "(.*?)"$/ do |token|
  @sessionId=token
end

Given /^I delete the previous tar file if it exists$/ do
  @received_file = Dir.pwd + "/#{$TAR_FILE_NAME}"
  File.delete(@received_file) if File.exists?(@received_file)
end

When /^I make a call to the bulk extract end point "([^"]*)"$/ do |url|

  restTls(url)
end

When /^I make a call to the bulk extract end point "([^"]*)" without a certificate$/ do |url|
  restHttpGet(url)
end

When /^I make a call to the bulk extract end point "(.*?)" using the certificate for app "(.*?)"$/ do |url, app|
  restTls(url, nil, @format, @sessionId, app)
end

When /^I make a call retrieve the header for the bulk extract end point "(.*?)"$/ do |url|
  restHttpHead(url)
end

Given /^in my list of rights I have BULK_EXTRACT$/ do
  #  Explanatory step
end

When /^I make a full bulk extract API call for edorg "(.*?)"$/ do |arg1|
  puts 'waiting 10 minutes for ingestion to finish'
  sleep 600
  restTls("/bulk/extract/#{arg1}")
end

When /^I make a custom bulk extract API call$/ do
  restHttpCustomHeadersGet("/bulk/extract/#{LEA_DAYBREAK_ID_VAL2}", @customHeaders)
end

When /^I make a concurrent ranged bulk extract API call and store the results$/ do
  offset = (@content_length.to_i/2).to_i<commit_msg>i hate sleep(s)<commit_after>=begin

Copyright 2012-2013 inBloom, Inc. and its affiliates.

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.

=end
require 'open3'
require 'digest/sha1'
require_relative '../../../utils/sli_utils.rb'

$TAR_FILE_NAME = "Final.tar"
LEA_DAYBREAK_ID_VAL2 = '1b223f577827204a1c7e9c851dba06bea6b031fe_id'

Given /^I update the "(.*?)" with ID "(.*?)" field "(.*?)" to "(.*?)" on the sli database$/ do |collection, id, field, boolean|
  conn = Mongo::Connection.new(Property["ingestion_db"], Property["ingestion_db_port"])
  sli = conn.db("sli")

  coll = sli[collection]
  entity = coll.find_one({"_id" => id})
  assert(entity, "cant find #{collection} with id #{id}")
  entry = entity
  subfields = field.split(".")
  last = subfields.pop
  subfields.each { |subfield|
    entry = entry[subfield]
  }
  puts "saving entity: #{entity}"
  entry[last] = boolean=="true"
  coll.save(entity)
end

Given /^I am a valid 'service' user with an authorized long\-lived token "(.*?)"$/ do |token|
  @sessionId=token
end

Given /^I delete the previous tar file if it exists$/ do
  @received_file = Dir.pwd + "/#{$TAR_FILE_NAME}"
  File.delete(@received_file) if File.exists?(@received_file)
end

When /^I make a call to the bulk extract end point "([^"]*)"$/ do |url|

  restTls(url)
end

When /^I make a call to the bulk extract end point "([^"]*)" without a certificate$/ do |url|
  restHttpGet(url)
end

When /^I make a call to the bulk extract end point "(.*?)" using the certificate for app "(.*?)"$/ do |url, app|
  restTls(url, nil, @format, @sessionId, app)
end

When /^I make a call retrieve the header for the bulk extract end point "(.*?)"$/ do |url|
  restHttpHead(url)
end

Given /^in my list of rights I have BULK_EXTRACT$/ do
  #  Explanatory step
end

When /^I make a full bulk extract API call for edorg "(.*?)"$/ do |arg1|
  puts 'waiting 3.5 minutes for ingestion to finish'
  sleep 210
  restTls("/bulk/extract/#{arg1}")
end

When /^I make a custom bulk extract API call$/ do
  restHttpCustomHeadersGet("/bulk/extract/#{LEA_DAYBREAK_ID_VAL2}", @customHeaders)
end

When /^I make a concurrent ranged bulk extract API call and store the results$/ do
  offset = (@content_length.to_i/2).to_i
{'fraction_non_alphanumeric': 0.1316620241411328, 'fraction_numerical': 0.01819870009285051, 'mean_word_length': 4.229126213592233, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, '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': '3756565', 'n_tokens_mistral': 1893, 'n_tokens_neox': 1768, 'n_words': 655}