Module: Es::Helpers

Defined in:
lib/es.rb

Constant Summary collapse

TEMPLATE_DIR =
"./lib/templates"

Class Method Summary collapse

Class Method Details

.destination_file(entity, options = {}) ⇒ Object



961
962
963
964
965
966
967
968
969
970
# File 'lib/es.rb', line 961

def self.destination_file(entity, options={})
  with_date = options[:with_date]
  deleted = options[:deleted]
  source = entity.file
  filename = File.basename(source)
  base =  File.basename(source, '.*')
  ext = File.extname(filename)
  base = deleted ? "#{base}_deleted" : base
  with_date ? base + '_' + DateTime.now.strftime("%Y-%M-%d_%H:%M:%S") + ext : base + ext
end

.extract_destination_dir(pid, entity) ⇒ Object



957
958
959
# File 'lib/es.rb', line 957

def self.extract_destination_dir(pid, entity)
  "out_#{pid}_#{entity.name}"
end

.get_historyid_settings(json) ⇒ Object



1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
# File 'lib/es.rb', line 1044

def self.get_historyid_settings(json)
    entity_fields =  Array.new
    entity_name = ""
    connected_through = ""
    json.map do |inner_part|
        if (inner_part[:type] == "entity") 
            entity_name = inner_part[:data]
            inner_part[:ops].map do |fields|
                entity_fields << fields[:data]
            end
        elsif (inner_part[:type] == "stream") 
          connected_through = inner_part[:data]
        end 
    end
    {
        :entity => entity_name,
        :fields => entity_fields,
        :through => connected_through
    }
end

.has_more_lines?(path) ⇒ Boolean

Returns:

  • (Boolean)


924
925
926
927
928
929
930
931
932
933
# File 'lib/es.rb', line 924

def self.has_more_lines?(path)
  counter = 0
  File.open(path, "r") do |infile|
    while (line = infile.gets)
      counter += 1
      break if counter > 2
    end
  end
  counter > 1
end

.load_config(filename, validate = true) ⇒ Object



935
936
937
938
939
940
941
942
943
# File 'lib/es.rb', line 935

def self.load_config(filename, validate=true)
    json = File.new(filename, 'r')
      parser = Yajl::Parser.new(:symbolize_keys => true)
    begin
      doc = parser.parse(json)
    rescue Yajl::ParseError => e
      fail Yajl::ParseError.new("Failed during parsing file #{filename}\n" + e.message)
    end
end

.load_destination_dir(pid, entity) ⇒ Object



953
954
955
# File 'lib/es.rb', line 953

def self.load_destination_dir(pid, entity)
  "#{pid}"
end

.type_to_generator_load_type(type) ⇒ Object



1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
# File 'lib/es.rb', line 1025

def self.type_to_generator_load_type(type)
  types = {
    Es::Field::RECORDID_TYPE        => "recordid",
    Es::Field::TIMESTAMP_TYPE       => "timestamp",
    Es::Field::ATTRIBUTE_TYPE       => "attribute",
    Es::Field::FACT_TYPE            => "fact",
    Es::Field::TIME_TYPE            => "time",
    Es::Field::DATE_TYPE            => "date",
    Es::Field::IS_DELETED_TYPE      => "isDeleted",
    Es::Field::TIMEATTRIBUTE_TYPE   => "time"
  }
  if types.has_key?(type) then
    types[type]
  else
    fail "Type #{type} not found."
  end
end

.type_to_load_type(type) ⇒ Object



972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
# File 'lib/es.rb', line 972

def self.type_to_load_type(type)
  types = {
    Es::Field::RECORDID_TYPE        => "recordid",
    Es::Field::TIMESTAMP_TYPE       => "timestamp",
    Es::Field::ATTRIBUTE_TYPE       => "attribute",
    Es::Field::FACT_TYPE            => "fact",
    Es::Field::TIME_TYPE            => "timeAttribute",
    Es::Field::DATE_TYPE            => "timeAttribute",
    Es::Field::IS_DELETED_TYPE      => "isDeleted",
    Es::Field::TIMEATTRIBUTE_TYPE   => "timeAttribute"
  }
  if types.has_key?(type) then
    types[type]
  else
    fail "Type #{type} not found."
  end
end

.type_to_operation(type) ⇒ Object



1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
# File 'lib/es.rb', line 1008

def self.type_to_operation(type)
  types = {
    Es::Field::RECORDID_TYPE      => "value",
    Es::Field::ATTRIBUTE_TYPE     => "value",
    Es::Field::FACT_TYPE          => "number",
    Es::Field::SNAPSHOT_TYPE      => "snapshot",
    Es::Field::TIME_TYPE          => "key",
    Es::Field::DATE_TYPE          => "date",
    Es::Field::TIMEATTRIBUTE_TYPE => "key"
  }
  if types.has_key?(type) then
    types[type]
  else
    fail "Type #{type} not found."
  end
end

.type_to_type(type) ⇒ Object



991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
# File 'lib/es.rb', line 991

def self.type_to_type(type)
  types = {
    Es::Field::RECORDID_TYPE        => "recordid",
    Es::Field::ATTRIBUTE_TYPE       => "stream",
    Es::Field::FACT_TYPE            => "stream",
    Es::Field::SNAPSHOT_TYPE        => "snapshot",
    Es::Field::TIME_TYPE            => "stream",
    Es::Field::DATE_TYPE            => "stream",
    Es::Field::TIMEATTRIBUTE_TYPE   => "stream"
  }
  if types.has_key?(type) then
    types[type]
  else
    fail "Type #{type} not found."
  end
end

.web_dav_extract_destination_dir(pid, entity) ⇒ Object



949
950
951
# File 'lib/es.rb', line 949

def self.web_dav_extract_destination_dir(pid, entity)
  "/out_#{pid}_#{entity.name}"
end

.web_dav_load_destination_dir(pid, entity) ⇒ Object



945
946
947
# File 'lib/es.rb', line 945

def self.web_dav_load_destination_dir(pid, entity)
  "/uploads/#{pid}"
end