Class: GenTJ::Crosscheck

Inherits:
Object
  • Object
show all
Defined in:
lib/gen-tj/crosscheck.rb

Class Method Summary collapse

Class Method Details

.run(title) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/gen-tj/crosscheck.rb', line 22

def Crosscheck.run title

  DataMapper::Logger.new($stdout, :debug)
  keeper = DataMapper.setup(:default, :adapter   => 'keeper',
   :url  => 'https://keeper.novell.com/sxkeeper')
  require 'keeper/feature'
  require 'keeper/relationtree'
  require 'keeper/relation'
  DataMapper.finalize

  # Get all features with a matching title

  features = {}
  Feature.all(:title.like => title).each do |f|
	features[f.id] = f
  end

  unless features.size>0
	STDERR.puts "No features matching '#{title}' found" 
	return
  end

  # Get the corresponding relationtree
  relationtree = Relationtree.first(:title.like => title)

  unless relationtree
	STDERR.puts "No relationtree matching '#{title}' found" 
	return
  end

  # Now iterate through the relationtree and remove matching features

  size_of_relation_tree = 0
  relationtree.relations.each do |relation|
	target = relation.target
	size_of_relation_tree += 1
	t_id = target.to_i
	if features.delete(t_id).nil?
	  puts "Target #{t_id} has a bad title"
	end
  end

  if size_of_relation_tree == 0
	STDERR.puts "Relationtree '#{title}' has no features"
	return
  end

  # Print out left over features

  features.each do |id,f|
	puts "Missing in relation tree - #{id}:'#{f.title}'"
  end
end