dgrid 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +15 -0
- data/lib/dgrid.rb +1 -0
- data/lib/dgrid/api.rb +20 -0
- data/lib/dgrid/api/connection.rb +444 -0
- data/lib/dgrid/api/entity.rb +89 -0
- data/lib/dgrid/api/get_test_login_info.rb +19 -0
- data/lib/dgrid/api/gps_coordinates.rb +14 -0
- data/lib/dgrid/api/incident.rb +78 -0
- data/lib/dgrid/api/item.rb +60 -0
- data/lib/dgrid/api/keyword.rb +38 -0
- data/lib/dgrid/api/lens.rb +38 -0
- data/lib/dgrid/api/link.rb +40 -0
- data/lib/dgrid/api/named_entity.rb +20 -0
- data/lib/dgrid/api/organization.rb +28 -0
- data/lib/dgrid/api/person.rb +39 -0
- data/lib/dgrid/api/place.rb +47 -0
- data/lib/dgrid/api/workspace.rb +567 -0
- data/lib/dgrid/argument_validation.rb +17 -0
- data/lib/dgrid/set_members_from_hash.rb +41 -0
- metadata +90 -0
@@ -0,0 +1,89 @@
|
|
1
|
+
module Dgrid
|
2
|
+
module API
|
3
|
+
class Entity
|
4
|
+
include ::Dgrid::ArgumentValidation
|
5
|
+
include ::Dgrid::SetMembersFromHash
|
6
|
+
|
7
|
+
attr_accessor :id, :description
|
8
|
+
|
9
|
+
option :id, String
|
10
|
+
option :description, String, :default => ''
|
11
|
+
def initialize(options)
|
12
|
+
@id = nil
|
13
|
+
set_members_from_hash(options)
|
14
|
+
|
15
|
+
# FIXME Remove this when ArgumentValidation::option is implemented
|
16
|
+
@description ||= ''
|
17
|
+
|
18
|
+
@workspaces = {}
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.type
|
22
|
+
self.name.split('::').last
|
23
|
+
end
|
24
|
+
|
25
|
+
def type
|
26
|
+
self.class.type
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.singular
|
30
|
+
name.split('::').last.downcase
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
argument :other, Entity
|
35
|
+
option :link_type, String, :required
|
36
|
+
def link_to(other, options = {})
|
37
|
+
raise UnimplementedFunctionality
|
38
|
+
self
|
39
|
+
end
|
40
|
+
|
41
|
+
def in_workspace?(workspace)
|
42
|
+
return @workspaces.include?(workspace.id)
|
43
|
+
end
|
44
|
+
|
45
|
+
def add_workspace(workspace)
|
46
|
+
@workspaces[workspace.id] = workspace
|
47
|
+
self
|
48
|
+
end
|
49
|
+
|
50
|
+
def to_hash
|
51
|
+
{ :description => description }
|
52
|
+
end
|
53
|
+
|
54
|
+
def new_record?
|
55
|
+
@id.nil?
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.pluralized
|
59
|
+
'entities'
|
60
|
+
end
|
61
|
+
|
62
|
+
def add_entity(entity)
|
63
|
+
workspaces.each do |workspace_id,workspace|
|
64
|
+
# STDERR.puts "adding #{entity.type} #{entity} to #{self.type} #{self} in workspace #{workspace}"
|
65
|
+
if entity.in_workspace?(workspace)
|
66
|
+
workspace.subordinate_entity_to_other_entity(entity, self)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def attach(filename)
|
72
|
+
conn = connection
|
73
|
+
# TODO Adapt this to a workspace-independent model when available in the server
|
74
|
+
conn.attach_file_to_entity_in_workspace(self,filename,first_workspace.id)
|
75
|
+
end
|
76
|
+
|
77
|
+
def connection
|
78
|
+
first_workspace.connection
|
79
|
+
end
|
80
|
+
|
81
|
+
def first_workspace
|
82
|
+
workspaces.values.first
|
83
|
+
end
|
84
|
+
|
85
|
+
attr_accessor :workspaces
|
86
|
+
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
require 'io/console'
|
4
|
+
|
5
|
+
def get_test_login_info(default_username = 'test', default_password='11111111')
|
6
|
+
STDERR.print "Enter username (#{default_username}): "
|
7
|
+
username = gets.chomp
|
8
|
+
if username.length == 0
|
9
|
+
username = default_username
|
10
|
+
password = default_password
|
11
|
+
else
|
12
|
+
STDERR.print "Password: "
|
13
|
+
password = STDIN.noecho(&:gets).chomp
|
14
|
+
STDERR.puts ""
|
15
|
+
|
16
|
+
end
|
17
|
+
return username, password
|
18
|
+
end
|
19
|
+
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Dgrid
|
2
|
+
module API
|
3
|
+
class GPSCoordinates
|
4
|
+
|
5
|
+
attr_accessor :lat, :long, :elevation
|
6
|
+
|
7
|
+
def initialize(lat,long,elevation = 0)
|
8
|
+
raise "invalid latitude \"#{lat}\"" unless lat.to_f <= 90.0 && lat.to_f >= -90.0
|
9
|
+
raise "invalid longitude \"#{long}\"" unless long.to_f <= 180.0 && long.to_f >= -180.0
|
10
|
+
@lat,@long,@elevation = lat.to_f,long.to_f,elevation.to_f
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
module Dgrid
|
2
|
+
module API
|
3
|
+
class Incident < NamedEntity
|
4
|
+
attr_accessor :body, :time, :end_time
|
5
|
+
|
6
|
+
option :name, String, :required # unique for this workspace
|
7
|
+
option :description, String
|
8
|
+
option :body, String
|
9
|
+
option :time, DateTime
|
10
|
+
option :end_time, DateTime
|
11
|
+
|
12
|
+
# alternative way to specify times from server
|
13
|
+
option :time_date, String
|
14
|
+
option :time_time, String
|
15
|
+
option :end_time_date, String
|
16
|
+
option :end_time_time, String
|
17
|
+
def initialize(options)
|
18
|
+
parent_opts, my_opts = split_hash(options,[:name, :description])
|
19
|
+
super(parent_opts)
|
20
|
+
member_opts = fix_time_opts(my_opts)
|
21
|
+
set_members_from_hash(member_opts)
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.db_fields
|
25
|
+
%w(id name body time end_time)
|
26
|
+
end
|
27
|
+
|
28
|
+
def add_time_to_hash(h, t,prefix)
|
29
|
+
h["#{prefix}_time".to_sym] = t.strftime("%H:%M")
|
30
|
+
h["#{prefix}_date".to_sym] = t.strftime("%Y-%m-%d")
|
31
|
+
h
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.pluralized
|
35
|
+
'incidents'
|
36
|
+
end
|
37
|
+
|
38
|
+
def to_hash
|
39
|
+
h = { :name => name,
|
40
|
+
:body => body
|
41
|
+
}
|
42
|
+
add_time_to_hash(h,time,'time') unless time.nil?
|
43
|
+
add_time_to_hash(h,end_time,'end_time') unless end_time.nil?
|
44
|
+
h
|
45
|
+
end
|
46
|
+
|
47
|
+
argument :person, Dgrid::API::Person
|
48
|
+
def add_person(person)
|
49
|
+
add_entity(person)
|
50
|
+
end
|
51
|
+
|
52
|
+
argument :place, Dgrid::API::Place
|
53
|
+
def add_place(place)
|
54
|
+
add_entity(place)
|
55
|
+
end
|
56
|
+
|
57
|
+
argument :organization, Dgrid::API::Organization
|
58
|
+
def add_organization(organization)
|
59
|
+
add_entity(organization)
|
60
|
+
end
|
61
|
+
|
62
|
+
protected
|
63
|
+
def fix_time_opts(orig_opts)
|
64
|
+
split_time_opts, normal_opts = split_hash(orig_opts,[:time_time,:time_date,:end_time_time, :end_time_date])
|
65
|
+
[:time, :end_time].each do |member|
|
66
|
+
date_part = (member.to_s + "_date").to_sym
|
67
|
+
time_part = (member.to_s + "_time").to_sym
|
68
|
+
if (split_time_opts.include?(date_part))
|
69
|
+
normal_opts[member] = split_time_opts[date_part] + " " + split_time_opts[time_part]
|
70
|
+
end
|
71
|
+
end
|
72
|
+
normal_opts[:time] = DateTime::parse( normal_opts[:time]) if normal_opts[:time].is_a?(String)
|
73
|
+
normal_opts[:end_time] = DateTime::parse( normal_opts[:end_time]) if normal_opts[:end_time].is_a?(String)
|
74
|
+
normal_opts
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module Dgrid
|
2
|
+
module API
|
3
|
+
class Item < NamedEntity
|
4
|
+
include ArgumentValidation
|
5
|
+
attr_accessor :body
|
6
|
+
|
7
|
+
option :name, String, :required # unique for this workspace
|
8
|
+
option :body, String
|
9
|
+
option :source, String
|
10
|
+
def initialize(options)
|
11
|
+
parent_opts, my_opts = split_hash(options,[:name, :description])
|
12
|
+
super(parent_opts)
|
13
|
+
set_members_from_hash(my_opts)
|
14
|
+
@body ||= ''
|
15
|
+
@incidents = nil
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.db_fields
|
19
|
+
%w(id name body source)
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.pluralized
|
23
|
+
'items'
|
24
|
+
end
|
25
|
+
|
26
|
+
def to_hash
|
27
|
+
{ :name => name,
|
28
|
+
:body => body
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
32
|
+
def workspace
|
33
|
+
workspace = workspaces.values.first # FIXME: assumes one workspace per item
|
34
|
+
end
|
35
|
+
|
36
|
+
def incident_ids
|
37
|
+
workspace.incident_ids_in_item(self)
|
38
|
+
end
|
39
|
+
|
40
|
+
def incidents
|
41
|
+
incident_list = workspace.incidents
|
42
|
+
incident_hash = {}
|
43
|
+
incident_list.each { |incident| incident_hash[incident.id] = incident}
|
44
|
+
return incident_ids.map { |id| incident_hash[id]}
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
def create_incident(options = {}, &block)
|
49
|
+
incident = Dgrid::API::Incident.new(options)
|
50
|
+
workspaces.each do |workspace_id, workspace|
|
51
|
+
returned_incident = workspace.add_incident(incident)
|
52
|
+
incident = returned_incident if incident.new_record?
|
53
|
+
workspace.subordinate_entity_to_other_entity(incident,self)
|
54
|
+
end
|
55
|
+
yield incident if block_given?
|
56
|
+
incident
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Dgrid
|
2
|
+
module API
|
3
|
+
class Keyword < NamedEntity
|
4
|
+
attr_accessor :synonyms
|
5
|
+
attr_accessor :triggers_alert
|
6
|
+
|
7
|
+
option :name, String, :required # unique for this workspace
|
8
|
+
option :id, String
|
9
|
+
option :synonyms, String
|
10
|
+
option :triggers_alert, String # really Boolean but no such class exists!
|
11
|
+
def initialize(options)
|
12
|
+
parent_opts, my_opts = split_hash(options,[:id, :name])
|
13
|
+
super(parent_opts)
|
14
|
+
set_members_from_hash(my_opts)
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.db_fields
|
19
|
+
%w(id name synonyms triggers_alert)
|
20
|
+
end
|
21
|
+
|
22
|
+
def to_hash
|
23
|
+
h = super
|
24
|
+
h.delete(:description)
|
25
|
+
h.merge!( { :synonyms => synonyms,
|
26
|
+
:triggers_alert => triggers_alert
|
27
|
+
})
|
28
|
+
h
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.pluralized
|
32
|
+
'keywords'
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Dgrid
|
2
|
+
module API
|
3
|
+
class Lens < NamedEntity
|
4
|
+
include ArgumentValidation
|
5
|
+
|
6
|
+
option :name, String, :required # unique for this workspace
|
7
|
+
option :id, String
|
8
|
+
def initialize(options)
|
9
|
+
super(options)
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.db_fields
|
13
|
+
%w(id name)
|
14
|
+
end
|
15
|
+
|
16
|
+
def to_hash
|
17
|
+
{ :name => name }
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
argument :item, Item
|
22
|
+
def add_item(item)
|
23
|
+
add_entity(item)
|
24
|
+
end
|
25
|
+
|
26
|
+
def item_ids
|
27
|
+
workspace = workspaces.values.first # FIXME: assumes one workspace per item
|
28
|
+
workspace.item_ids_in_lens(self)
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.pluralized
|
32
|
+
'lenses'
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Dgrid
|
2
|
+
module API
|
3
|
+
class Link < Entity
|
4
|
+
|
5
|
+
attr_accessor :left_type, :left_guid, :right_type, :right_guid, :descriptoion
|
6
|
+
attr_reader :auto_linked
|
7
|
+
|
8
|
+
option :left_type, String, :required
|
9
|
+
option :left_guid, String, :required
|
10
|
+
option :right_type, String, :required
|
11
|
+
option :right_guid, String, :required
|
12
|
+
option :auto_linked, String # really Boolean but no such class exists!
|
13
|
+
option :left_id, String
|
14
|
+
option :right_id, String
|
15
|
+
def initialize(options)
|
16
|
+
parent_opts, my_opts = split_hash(options,[:id, :description])
|
17
|
+
super(parent_opts)
|
18
|
+
@auto_linked = false
|
19
|
+
set_members_from_hash(options)
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.db_fields
|
23
|
+
%w(id description auto_linked left_type left_guid left_id right_type right_guid right_id)
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.pluralized
|
27
|
+
'links'
|
28
|
+
end
|
29
|
+
|
30
|
+
def to_hash
|
31
|
+
h = { :description => description,
|
32
|
+
:left_type => left_type,
|
33
|
+
:left_guid => left_guid,
|
34
|
+
:right_type => right_type,
|
35
|
+
:right_guid => right_guid
|
36
|
+
}
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Dgrid
|
2
|
+
module API
|
3
|
+
class NamedEntity < Entity
|
4
|
+
|
5
|
+
attr_accessor :name
|
6
|
+
|
7
|
+
option :name, String, :required
|
8
|
+
def initialize(options)
|
9
|
+
parent_opts, my_opts = split_hash(options,[:id, :description])
|
10
|
+
super(parent_opts)
|
11
|
+
set_members_from_hash(my_opts)
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_hash
|
15
|
+
{ :name => name, :description => description }
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Dgrid
|
2
|
+
module API
|
3
|
+
class Organization < NamedEntity
|
4
|
+
include ArgumentValidation
|
5
|
+
|
6
|
+
option :name, String, :required # unique for this workspace
|
7
|
+
option :description, String # typically an address
|
8
|
+
def initialize(options)
|
9
|
+
super(options)
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.db_fields
|
13
|
+
%w(id name description)
|
14
|
+
end
|
15
|
+
|
16
|
+
argument :person, Person
|
17
|
+
def add_person(person)
|
18
|
+
add_entity(person)
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.pluralized
|
22
|
+
'organizations'
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Dgrid
|
2
|
+
module API
|
3
|
+
class Person < NamedEntity
|
4
|
+
attr_accessor :gender, :birth_date, :death_date, :ext_id
|
5
|
+
|
6
|
+
option :name, String, :required
|
7
|
+
option :description, String
|
8
|
+
option :gender, :must_be_m_or_f
|
9
|
+
option :birth_date, DateTime
|
10
|
+
option :death_date, DateTime
|
11
|
+
option :ext_id, String
|
12
|
+
def initialize(options)
|
13
|
+
parent_opts, my_opts = split_hash(options,[:id, :name, :description])
|
14
|
+
super(parent_opts)
|
15
|
+
set_members_from_hash(my_opts)
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.db_fields
|
19
|
+
%w(id name description gender birth_date death_date)
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
def self.pluralized
|
24
|
+
'people'
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
def to_hash
|
29
|
+
h = super
|
30
|
+
|
31
|
+
h.merge({ :gender => gender,
|
32
|
+
:birth_date => birth_date,
|
33
|
+
:death_date => death_date,
|
34
|
+
:ext_id => ext_id })
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|