openagent 0.9.0 → 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -19,6 +19,7 @@ module OpenAgent
19
19
  attribute :publish_delete, Array[String]
20
20
  attribute :request, Array[String]
21
21
  attribute :respond, Array[String]
22
+ attribute :conditions, Hash
22
23
 
23
24
  end
24
25
  end
@@ -24,8 +24,41 @@ module OpenAgent
24
24
  )
25
25
  )
26
26
  end
27
+ def condition(cond={})
28
+ SIF::Infra::Common::Condition.new(
29
+ :element => cond['element'],
30
+ :value => cond['value'],
31
+ :operator => cond['operator']
32
+ )
33
+ end
34
+
35
+ def conditions(condition_arr={})
36
+ return false if condition_arr.count == 0
37
+ condition_arr.map do |c|
38
+ # require 'pry' ; binding.pry
39
+ SIF::Infra::Common::Conditions.new(
40
+ :type => c['cond_type'],
41
+ :condition => condition(c)
42
+ )
43
+ end
44
+ end
45
+ def conditions_group(condition_arr={})
46
+ return false if condition_arr.nil? || condition_arr['conditions'].count == 0
47
+ if condition_arr['conditions'].count == 1
48
+ SIF::Infra::Common::ConditionGroup.new(
49
+ :type => 'None',
50
+ :conditions => conditions(condition_arr['conditions'])
51
+ )
52
+ else
53
+ SIF::Infra::Common::ConditionGroup.new(
54
+ :type => condition_arr['group_type'],
55
+ :conditions => conditions(condition_arr['conditions'])
56
+ )
57
+ end
58
+ end
59
+ #Condition_hash should = {:type=>"None", :conditions=>[{:type=>"None", :element=>"@SchoolYear", :value=>"2014", :operator=>"EQ"}]}
27
60
 
28
- def request(object_name, condition_group=nil)
61
+ def request(object_name, condition_arr={})
29
62
  SIF::Infra::Common::Message.new(
30
63
  :version => @agent.msg_version,
31
64
  :xmlns => @agent.msg_xmlns,
@@ -37,7 +70,7 @@ module OpenAgent
37
70
  :query_object => SIF::Infra::Common::QueryObject.new(
38
71
  :object_name => object_name
39
72
  ),
40
- :condition_group => condition_group
73
+ :condition_group => conditions_group(condition_arr)
41
74
  )
42
75
  )
43
76
  )
@@ -1,3 +1,3 @@
1
1
  module OpenAgent
2
- VERSION = '0.9.0' unless defined?(OpenAgent::VERSION)
2
+ VERSION = '0.9.1' unless defined?(OpenAgent::VERSION)
3
3
  end
@@ -12,7 +12,7 @@ module OpenAgent
12
12
  include Virtus.model
13
13
 
14
14
  attribute :uri
15
- attribute :timeout, Float, :default => 60
15
+ attribute :timeout, Float, :default => 120
16
16
  attribute :open_timeout, Float, :default => 30
17
17
  attribute :ssl, SSLConfig
18
18
 
@@ -1,4 +1,4 @@
1
- require_relative 'condition'
1
+ require_relative 'conditions'
2
2
 
3
3
  module SIF
4
4
  module Infra
@@ -7,7 +7,13 @@ module SIF
7
7
  include Virtus.model
8
8
 
9
9
  attribute :type, String
10
- attribute :conditions, Array[Condition]
10
+ attribute :conditions, Array[Conditions]
11
+
12
+ def empty?
13
+ return true if conditions.nil?
14
+ return true if conditions.empty?
15
+ return false
16
+ end
11
17
  end
12
18
  end
13
19
  end
@@ -0,0 +1,13 @@
1
+ module SIF
2
+ module Infra
3
+ module Common
4
+ class Conditions
5
+ include Virtus.model
6
+
7
+ attribute :type, String
8
+ attribute :condition, Array[Condition]
9
+
10
+ end
11
+ end
12
+ end
13
+ end
@@ -34,7 +34,7 @@ module SIF
34
34
  end
35
35
 
36
36
  def teacher
37
- first_schedule_info.first_teacher
37
+ first_schedule_info.first_teacher if first_schedule_info.first_teacher
38
38
  end
39
39
  end
40
40
  end
@@ -5,12 +5,12 @@ module SIF
5
5
  module SISRepresenter
6
6
  include Virtus.model
7
7
 
8
- attribute :extended_elements, Array[MODEL_COMMON::ExtendedElement]
8
+ attribute :extended_elements, Array[MODEL_COMMON::ExtendedElement], :default => []
9
9
  attribute :metadata, String
10
10
  attribute :ref_id, String
11
11
 
12
12
  def find_element(name)
13
- return if extended_elements.nil?
13
+ return nil if extended_elements.nil?
14
14
  el = extended_elements.find{ |e| e.name == name }
15
15
  el ? el.value : nil
16
16
  end
@@ -14,8 +14,8 @@ module SIF
14
14
  attribute :schedule_info_overrides, Array[Common::ScheduleInfoOverride]
15
15
  attribute :credits_attempted, Common::CreditsAttempted
16
16
 
17
- def status(as_of=Date.today)
18
- if as_of >= entry_date && as_of < exit_date
17
+ def status
18
+ if entry_date.past? && exit_date.future?
19
19
  'active'
20
20
  else
21
21
  'deleted'
@@ -9,8 +9,9 @@ module SIF
9
9
  property :type, :as => 'Type', :attribute => true
10
10
 
11
11
  collection :conditions, :as => 'SIF_Conditions',
12
- :class => SIF::Infra::Common::Condition,
13
- :decorator => Condition
12
+ :class => SIF::Infra::Common::Conditions,
13
+ :decorator => Conditions
14
+
14
15
  end
15
16
  end
16
17
  end
@@ -0,0 +1,18 @@
1
+ module SIF
2
+ module Representation
3
+ module Infra
4
+ module Common
5
+ class Conditions < SIF::Represent
6
+
7
+ self.representation_wrap = 'SIF_Conditions'
8
+
9
+ property :type, :as => 'Type', :attribute => true
10
+
11
+ collection :condition, :as => 'SIF_Condition',
12
+ :class => SIF::Infra::Common::Condition,
13
+ :decorator => Condition
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -14,7 +14,8 @@ module SIF
14
14
  :decorator => QueryObject
15
15
  property :condition_group, :as => 'SIF_ConditionGroup',
16
16
  :class => SIF::Infra::Common::ConditionGroup,
17
- :decorator => ConditionGroup
17
+ :decorator => ConditionGroup,
18
+ :if => lambda { !condition_group.empty? }
18
19
 
19
20
  property :example, :as => 'SIF_Example'
20
21
  end
data/lib/sif/sif.rb CHANGED
@@ -13,6 +13,7 @@ module SIF
13
13
  module Common
14
14
  autoload :Application, 'sif/infra/common/application'
15
15
  autoload :Condition, 'sif/infra/common/condition'
16
+ autoload :Conditions, 'sif/infra/common/conditions'
16
17
  autoload :ConditionGroup, 'sif/infra/common/condition_group'
17
18
  autoload :Data, 'sif/infra/common/data'
18
19
  autoload :Error, 'sif/infra/common/error'
@@ -137,6 +138,7 @@ module SIF
137
138
  module Common
138
139
  autoload :Application, 'sif/representations/infra/common/application'
139
140
  autoload :Condition, 'sif/representations/infra/common/condition'
141
+ autoload :Conditions, 'sif/representations/infra/common/conditions'
140
142
  autoload :ConditionGroup, 'sif/representations/infra/common/condition_group'
141
143
  autoload :Data, 'sif/representations/infra/common/data'
142
144
  autoload :Error, 'sif/representations/infra/common/error'
@@ -28,4 +28,12 @@ request:
28
28
  - StudentPersonal
29
29
  - StaffPersonal
30
30
  - StudentSectionInfo
31
- respond:
31
+ respond:
32
+ conditions:
33
+ conditions:
34
+ -
35
+ cond_type: None
36
+ element: "@SchoolYear"
37
+ operator: EQ
38
+ value: 2014
39
+ group_type: None
@@ -2,6 +2,7 @@ require_relative 'spec_helper'
2
2
  require "openagent/message_builder"
3
3
  require "openagent/agent"
4
4
  require "openagent/zone"
5
+ require "openagent"
5
6
 
6
7
  describe OpenAgent::MessageBuilder do
7
8
 
@@ -24,7 +25,7 @@ describe OpenAgent::MessageBuilder do
24
25
  end
25
26
 
26
27
  def represent(msg)
27
- SIF::Representation::Infra::Common::Message.new(msg)
28
+ SIF.repr(msg)
28
29
  end
29
30
 
30
31
  it "registers" do
@@ -38,8 +39,15 @@ describe OpenAgent::MessageBuilder do
38
39
  end
39
40
 
40
41
 
41
- it "requests" do
42
- header_checks_out{ builder.request("StudentPersonal", nil) }
42
+ it "requests without conditions" do
43
+ msg = header_checks_out{ builder.request("StudentPersonal", nil) }
44
+ represent(msg).to_xml.should == "<SIF_Message xmlns=\"http://www.sifinfo.org/infrastructure/2.x\" Version=\"2.0r1\">\n <SIF_Request>\n <SIF_Header>\n <SIF_MsgId>GUUID</SIF_MsgId>\n <SIF_Timestamp>TIME</SIF_Timestamp>\n <SIF_SourceId>canvas</SIF_SourceId>\n </SIF_Header>\n <SIF_Version>2.0r1</SIF_Version>\n <SIF_MaxBufferSize>64000</SIF_MaxBufferSize>\n <SIF_Query>\n <SIF_QueryObject ObjectName=\"StudentPersonal\"/>\n </SIF_Query>\n </SIF_Request>\n</SIF_Message>"
45
+ end
46
+
47
+ it "requests with conditions" do
48
+ conditions_arr = agent.conditions
49
+ msg = header_checks_out{ builder.request("StudentPersonal", conditions_arr) }
50
+ represent(msg).to_xml.should == "<SIF_Message xmlns=\"http://www.sifinfo.org/infrastructure/2.x\" Version=\"2.0r1\">\n <SIF_Request>\n <SIF_Header>\n <SIF_MsgId>GUUID</SIF_MsgId>\n <SIF_Timestamp>TIME</SIF_Timestamp>\n <SIF_SourceId>canvas</SIF_SourceId>\n </SIF_Header>\n <SIF_Version>2.0r1</SIF_Version>\n <SIF_MaxBufferSize>64000</SIF_MaxBufferSize>\n <SIF_Query>\n <SIF_QueryObject ObjectName=\"StudentPersonal\"/>\n <SIF_ConditionGroup Type=\"None\">\n <SIF_Conditions Type=\"None\">\n <SIF_Condition>\n <SIF_Element>@SchoolYear</SIF_Element>\n <SIF_Operator>EQ</SIF_Operator>\n <SIF_Value>2014</SIF_Value>\n </SIF_Condition>\n </SIF_Conditions>\n </SIF_ConditionGroup>\n </SIF_Query>\n </SIF_Request>\n</SIF_Message>"
43
51
  end
44
52
 
45
53
  it "pings" do
@@ -73,9 +81,4 @@ describe OpenAgent::MessageBuilder do
73
81
  msg = header_checks_out{builder.provision}
74
82
  represent(msg).to_xml.should == "<SIF_Message xmlns=\"http://www.sifinfo.org/infrastructure/2.x\" Version=\"2.0r1\">\n <SIF_Provision>\n <SIF_Header>\n <SIF_MsgId>GUUID</SIF_MsgId>\n <SIF_Timestamp>TIME</SIF_Timestamp>\n <SIF_SourceId>canvas</SIF_SourceId>\n </SIF_Header>\n <SIF_ProvideObjects/>\n <SIF_SubscribeObjects>\n <SIF_Object ObjectName=\"LEAInfo\"/>\n <SIF_Object ObjectName=\"SchoolInfo\"/>\n <SIF_Object ObjectName=\"TermInfo\"/>\n <SIF_Object ObjectName=\"SchoolCourseInfo\"/>\n <SIF_Object ObjectName=\"SectionInfo\"/>\n <SIF_Object ObjectName=\"StudentPersonal\"/>\n <SIF_Object ObjectName=\"StaffPersonal\"/>\n <SIF_Object ObjectName=\"StudentSectionInfo\"/>\n </SIF_SubscribeObjects>\n <SIF_PublishAddObjects/>\n <SIF_PublishChangeObjects/>\n <SIF_PublishDeleteObjects/>\n <SIF_RequestObjects>\n <SIF_Object ObjectName=\"LEAInfo\"/>\n <SIF_Object ObjectName=\"SchoolInfo\"/>\n <SIF_Object ObjectName=\"TermInfo\"/>\n <SIF_Object ObjectName=\"SchoolCourseInfo\"/>\n <SIF_Object ObjectName=\"SectionInfo\"/>\n <SIF_Object ObjectName=\"StudentPersonal\"/>\n <SIF_Object ObjectName=\"StaffPersonal\"/>\n <SIF_Object ObjectName=\"StudentSectionInfo\"/>\n </SIF_RequestObjects>\n <SIF_RespondObjects/>\n </SIF_Provision>\n</SIF_Message>"
75
83
  end
76
-
77
- it "requests" do
78
- msg = header_checks_out{builder.request("StudentPersonal")}
79
- represent(msg).to_xml.should == "<SIF_Message xmlns=\"http://www.sifinfo.org/infrastructure/2.x\" Version=\"2.0r1\">\n <SIF_Request>\n <SIF_Header>\n <SIF_MsgId>GUUID</SIF_MsgId>\n <SIF_Timestamp>TIME</SIF_Timestamp>\n <SIF_SourceId>canvas</SIF_SourceId>\n </SIF_Header>\n <SIF_Version>2.0r1</SIF_Version>\n <SIF_MaxBufferSize>64000</SIF_MaxBufferSize>\n <SIF_Query>\n <SIF_QueryObject ObjectName=\"StudentPersonal\"/>\n </SIF_Query>\n </SIF_Request>\n</SIF_Message>"
80
- end
81
84
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openagent
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.9.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2014-01-22 00:00:00.000000000 Z
14
+ date: 2014-02-06 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rake
@@ -197,6 +197,7 @@ files:
197
197
  - lib/sif/infra/common/application.rb
198
198
  - lib/sif/infra/common/condition.rb
199
199
  - lib/sif/infra/common/condition_group.rb
200
+ - lib/sif/infra/common/conditions.rb
200
201
  - lib/sif/infra/common/data.rb
201
202
  - lib/sif/infra/common/error.rb
202
203
  - lib/sif/infra/common/event.rb
@@ -296,6 +297,7 @@ files:
296
297
  - lib/sif/representations/infra/common/application.rb
297
298
  - lib/sif/representations/infra/common/condition.rb
298
299
  - lib/sif/representations/infra/common/condition_group.rb
300
+ - lib/sif/representations/infra/common/conditions.rb
299
301
  - lib/sif/representations/infra/common/data.rb
300
302
  - lib/sif/representations/infra/common/error.rb
301
303
  - lib/sif/representations/infra/common/event.rb