Skip to content

Commit

Permalink
clean no more ecoportal old code
Browse files Browse the repository at this point in the history
  • Loading branch information
syphax-bouazzouni committed Jun 2, 2024
1 parent b369660 commit 574a045
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 203 deletions.
1 change: 0 additions & 1 deletion lib/ontologies_api_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
require 'multi_json'
require 'spawnling'

require_relative 'ontologies_api_client/utils'
require_relative 'ontologies_api_client/config'
require_relative 'ontologies_api_client/http'
require_relative 'ontologies_api_client/link_explorer'
Expand Down
17 changes: 6 additions & 11 deletions lib/ontologies_api_client/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,12 @@ def self.map_classes
end

def initialize(options = {})
begin
values = options[:values]
if values.is_a?(Hash) && !values.empty?
create_attributes(values.keys)
populate_attributes(values)
end
create_attributes(self.class.attrs_always_present || [])
rescue => e
LOGGER.debug("\n\n ECCEZIONE! RUBY API - base.rb - initialize(options): #{e.message}\n#{e.backtrace.join("\n")}")
raise e
values = options[:values]
if values.is_a?(Hash) && !values.empty?
create_attributes(values.keys)
populate_attributes(values)
end
create_attributes(self.class.attrs_always_present || [])
end

def id
Expand Down Expand Up @@ -157,4 +152,4 @@ def populate_attributes(hash)

end
end
end
end
12 changes: 0 additions & 12 deletions lib/ontologies_api_client/models/creator.rb

This file was deleted.

12 changes: 0 additions & 12 deletions lib/ontologies_api_client/models/creator_identifier.rb

This file was deleted.

85 changes: 19 additions & 66 deletions lib/ontologies_api_client/read_write.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require 'active_support/core_ext/hash'
require_relative 'utils'

module LinkedData
module Client
Expand Down Expand Up @@ -63,75 +62,29 @@ def cache_refresh(options = {})
end

def equivalent?(current_value, new_value)
# LOGGER.debug("\n\n----------------------\nONTOLOGIES_API_RUBY_CLIENT: LinkedData::Client::ReadWrite -> equivalent:\n\n > current_value=#{current_value.inspect}\n\n > new_value=#{new_value.inspect}")
begin
# If we're comparing an existing embedded object
# then use the id for comparison
if current_value.is_a?(LinkedData::Client::Base)
#LOGGER.debug(" > current_value is a LinkedData::Client::Base \n > current_value= #{current_value}\n > new_value=#{new_value}")
result_equivalent = current_value.id.eql?(new_value)
#LOGGER.debug(" > > equivalent RESULT =#{result_equivalent}")
return result_equivalent
end

# Otherwise, do some complex comparing
case new_value
when String
#LOGGER.debug(" > new_value is a String\n > current_value= #{current_value}\n > new_value=#{new_value}")
result_equivalent = current_value.to_s.eql?(new_value)
#LOGGER.debug(" > > equivalent RESULT =#{result_equivalent}")
return result_equivalent
when Array, Hash
new_value = nil if new_value.is_a?(Array) && new_value.empty? && current_value.nil?
if new_value.is_a?(Hash) || (new_value.is_a?(Array) && (new_value.first.is_a?(Hash) || new_value.first.is_a?(OpenStruct)))
#LOGGER.debug(" > new_value is an Array && new_value.first is an Hash or OpenStruct")

ordered_current = LinkedData::Client::Utils.order_inner_array_elements(current_value, true, [:id, :type, :links, :context, :created])
# LOGGER.debug(" > > ordered_current=#{ordered_current}")
# If we're comparing an existing embedded object
# then use the id for comparison
if current_value.is_a?(LinkedData::Client::Base)
return current_value.id.eql?(new_value)
end

clean_current = LinkedData::Client::Utils.recursive_symbolize_keys(ordered_current, true, [:id, :type, :links, :context, :created])
# LOGGER.debug(" > > clean_current=#{clean_current}")

# LOGGER.debug(" > > BEFORE elaboration PROVE: new_value=#{new_value}")
# LOGGER.debug(" > > BEFORE elaboration PROVE: new_value.inspect= #{new_value.inspect}")
# LOGGER.debug(" > > BEFORE elaboration PROVE: new_value_symbolized: #{LinkedData::Client::Utils.recursive_symbolize_keys(new_value)}")
#new_value.map{|e| LOGGER.debug("new_value.map: \n e = #{e}\n e.to_h = #{e.to_h}")}

#new_value[0].each{ |k,v| LOGGER.debug("new_value[0].each [k,v] = [#{k},#{v}] => #{new_value[0]}")}

clean_new_to_order = LinkedData::Client::Utils.recursive_symbolize_keys(new_value, true, [:id, :type, :links, :context, :created])
# LOGGER.debug(" > > clean_new_to_order=#{clean_new_to_order}")

clean_new = LinkedData::Client::Utils.order_inner_array_elements(clean_new_to_order, true, [:id, :type, :links, :context, :created])
#LOGGER.debug(" > > clean_new=#{clean_new}")

result_equivalent = clean_current.eql?(clean_new) rescue clean_current == clean_new
# LOGGER.debug(" > > equivalent RESULT =#{result_equivalent}")
return result_equivalent
else
#LOGGER.debug(" > new_value is an Array OR Hash:\n > current_value= #{current_value}\n > new_value=#{new_value}")
result_equivalent = current_value.sort.eql?(new_value.sort) rescue current_value == new_value
#LOGGER.debug(" > > equivalent RESULT =#{result_equivalent}")
return result_equivalent
end
# Otherwise, do some complex comparing
case new_value
when String
return current_value.to_s.eql?(new_value)
when Array, Hash
new_value = nil if new_value.is_a?(Array) && new_value.empty? && current_value.nil?
if new_value.is_a?(Array) && new_value.first.is_a?(Hash)
clean_current = current_value.map {|e| e.to_h.symbolize_keys.delete_if {|k,v| v.nil?}}.sort_by {|e| e.is_a?(Hash) ? e.values.sort : e}
clean_new = new_value.map {|e| e.symbolize_keys.delete_if {|k,v| v.nil?}}.sort_by {|e| e.is_a?(Hash) ? e.values.sort : e}
return clean_current.eql?(clean_new) rescue clean_current == clean_new
else
return current_value.sort.eql?(new_value.sort) rescue current_value == new_value
end
#LOGGER.debug(" > OTHERWISE CASE > current_value= #{current_value}\n > new_value=#{new_value}")
result_equivalent = current_value.sort.eql?(new_value.sort) rescue current_value == new_value
#LOGGER.debug(" > > equivalent RESULT =#{result_equivalent}")
return result_equivalent
rescue => e
LOGGER.debug("\n\n ECCEZIONE! ONTOLOGIES_API_RUBY_CLIENT: LinkedData::Client::equivalent: #{e.message}\n#{e.backtrace.join("\n")}")
raise e
end
return current_value.eql?(new_value) rescue current_value == new_value
end

# NEW method Ecoportal
# clean an annidate hash (hash with array, hash or array of hash)
def clean_annidate_hash(obj)

end


def invalidate_cache(cache_refresh_all = true)
self.class.all(invalidate_cache: true) if cache_refresh_all
HTTP.get(self.id, invalidate_cache: true) if self.id
Expand All @@ -151,4 +104,4 @@ def refresh_cache

end
end
end
end
101 changes: 0 additions & 101 deletions lib/ontologies_api_client/utils.rb

This file was deleted.

0 comments on commit 574a045

Please sign in to comment.