dynamicloud 1.0.1 → 1.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 +4 -4
- data/lib/configuration.rb +2 -2
- data/lib/dynamic_api.rb +47 -7
- data/lib/dynamic_criteria.rb +109 -0
- data/lib/dynamicloud/version.rb +1 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 318fe1e2561223c784d9ea4d04ca0171e2e39faa
|
4
|
+
data.tar.gz: 45a07038c7f20182e48589fe8d14c18a45e7529f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 70b9f33d24b1462fcbe8a4db5cf83c2eeeac8435ea5ea258c39b304f2896d93564e64b7f6aa889acabf2fab413f2194c45fbc5528c21b65f9557c5a8ba411397
|
7
|
+
data.tar.gz: 416cecdbeae4f8f98ba13b51b58e4d8363af84259b100a7544d5841dc698a2ce96fd6c8712d99e9a6a6ad7f2cf2361ccad17f95c233b835c348f7da29ed4d331
|
data/lib/configuration.rb
CHANGED
@@ -13,7 +13,7 @@ class Configuration
|
|
13
13
|
# Load the current properties in config.yml.
|
14
14
|
def initialize
|
15
15
|
@config = {
|
16
|
-
:url => 'http://
|
16
|
+
:url => 'http://localhost',
|
17
17
|
# this url must be executed using post method
|
18
18
|
:url_get_records => '/api_models/{csk}/{aci}/get_records/{mid}/{count}/{offset}/',
|
19
19
|
# this url must be executed using post method
|
@@ -42,7 +42,7 @@ class Configuration
|
|
42
42
|
:url_update_selection => '/api_records/{csk}/{aci}/update_using_selection/{mid}',
|
43
43
|
# this url must be executed using post method
|
44
44
|
:url_delete_selection => '/api_records/{csk}/{aci}/delete_using_selection/{mid}',
|
45
|
-
:version => '1.0.
|
45
|
+
:version => '1.0.2'
|
46
46
|
}
|
47
47
|
end
|
48
48
|
|
data/lib/dynamic_api.rb
CHANGED
@@ -31,15 +31,33 @@ module Dynamicloud
|
|
31
31
|
@credentials = nil
|
32
32
|
@order_by = nil
|
33
33
|
@group_by = nil
|
34
|
-
#@projection = nil
|
35
34
|
@offset = -1
|
36
35
|
@count = -1
|
37
36
|
@current_callback = nil
|
38
37
|
@list_was_called = false
|
39
38
|
@conditions = []
|
39
|
+
@joins = []
|
40
|
+
@alias = nil
|
40
41
|
@current_projection = nil
|
41
42
|
end
|
42
43
|
|
44
|
+
# Attaches a alias to this query, the model in this query will use this alias in Join Clauses or whatever situation where alias is needed.
|
45
|
+
#
|
46
|
+
# @param aliass alias to attach
|
47
|
+
# @return this instance of Query
|
48
|
+
def set_alias(aliass)
|
49
|
+
@alias = aliass
|
50
|
+
end
|
51
|
+
|
52
|
+
# Add a join to the list of joins
|
53
|
+
#
|
54
|
+
# @param join_clause join clause
|
55
|
+
# @return this instance of Query
|
56
|
+
def join(join_clause)
|
57
|
+
@joins.push join_clause
|
58
|
+
self
|
59
|
+
end
|
60
|
+
|
43
61
|
# Apply a desc ordering to the current order by object
|
44
62
|
# An IllegalStateException will be thrown if orderBy object is nil
|
45
63
|
#
|
@@ -117,7 +135,8 @@ module Dynamicloud
|
|
117
135
|
# @param projection projection to use in this operation
|
118
136
|
def get_results(projection = nil)
|
119
137
|
selection = Dynamicloud::API::DynamicloudHelper.build_string(get_conditions, get_group_by, get_order_by,
|
120
|
-
(Dynamicloud::API::DynamicloudHelper.build_projection(projection))
|
138
|
+
(Dynamicloud::API::DynamicloudHelper.build_projection(projection)),
|
139
|
+
@alias, @joins)
|
121
140
|
@current_projection = projection
|
122
141
|
|
123
142
|
url = Configuration::PROPERTIES.get_property :url
|
@@ -148,7 +167,7 @@ module Dynamicloud
|
|
148
167
|
# @param attribute attribute by this query will be ordered.
|
149
168
|
# @return this instance of Query
|
150
169
|
def order_by(attribute)
|
151
|
-
@order_by = OrderByClause.asc(attribute)
|
170
|
+
@order_by = Dynamicloud::API::Criteria::OrderByClause.asc(attribute)
|
152
171
|
self
|
153
172
|
end
|
154
173
|
|
@@ -157,7 +176,7 @@ module Dynamicloud
|
|
157
176
|
# @param attribute attribute by this query will group.
|
158
177
|
# @return this instance of Query
|
159
178
|
def group_by(attribute)
|
160
|
-
@group_by = GroupByClause.new(attribute)
|
179
|
+
@group_by = Dynamicloud::API::Criteria::GroupByClause.new(attribute)
|
161
180
|
self
|
162
181
|
end
|
163
182
|
|
@@ -693,8 +712,9 @@ module Dynamicloud
|
|
693
712
|
|
694
713
|
# Builds a compatible String to use in service executions
|
695
714
|
# @return compatible String
|
696
|
-
def self.build_string(conditions, group_by, order_by, projection)
|
697
|
-
built = '{' + (
|
715
|
+
def self.build_string(conditions, group_by, order_by, projection, aliass = nil, joins = [])
|
716
|
+
built = '{' + (aliass == nil ? '' : '"alias": "' + aliass + '", ') + build_join_tag(joins) +
|
717
|
+
((projection.nil? || projection.eql?('') || projection.strip!.eql?('')) ? '' : (', ' + projection)) + ', "where": {'
|
698
718
|
|
699
719
|
if conditions.length > 0
|
700
720
|
global = conditions[0]
|
@@ -734,7 +754,27 @@ module Dynamicloud
|
|
734
754
|
cols = cols + (cols == '' ? '' : ',') + '"' + field + '"'
|
735
755
|
end
|
736
756
|
|
737
|
-
columns + cols + ']
|
757
|
+
columns + cols + ']'
|
758
|
+
end
|
759
|
+
|
760
|
+
# This method builds the tag joins as follows:
|
761
|
+
# i.e: "joins": [ { "type": "full", "alias": "user", "target": "3456789", "on": { "user.id" : "languages.id" } } ]
|
762
|
+
#
|
763
|
+
# @param joins list of join clauses
|
764
|
+
# @return the representation of a join tag.
|
765
|
+
def self.build_join_tag(joins)
|
766
|
+
tag = '"joins": ['
|
767
|
+
|
768
|
+
unless joins.nil?
|
769
|
+
first_time = true
|
770
|
+
joins.each do |clause|
|
771
|
+
tag += (first_time ? '' : ', ') + clause.to_record_string(Dynamicloud::API::Criteria::Condition::ROOT)
|
772
|
+
|
773
|
+
first_time = false
|
774
|
+
end
|
775
|
+
end
|
776
|
+
|
777
|
+
return tag + ']'
|
738
778
|
end
|
739
779
|
|
740
780
|
# This utility will build a RecordResults object
|
data/lib/dynamic_criteria.rb
CHANGED
@@ -19,6 +19,65 @@ module Dynamicloud
|
|
19
19
|
end
|
20
20
|
# End of Condition class
|
21
21
|
|
22
|
+
# This enum represents the different Join types
|
23
|
+
class JoinType
|
24
|
+
attr_accessor :type
|
25
|
+
|
26
|
+
def initialize(type)
|
27
|
+
@type = type
|
28
|
+
end
|
29
|
+
|
30
|
+
LEFT = JoinType.new 1
|
31
|
+
RIGHT = JoinType.new 2
|
32
|
+
INNER = JoinType.new 3
|
33
|
+
LEFT_OUTER = JoinType.new 4
|
34
|
+
RIGHT_OUTER = JoinType.new 5
|
35
|
+
|
36
|
+
# This method returns the text according to this Join Type.
|
37
|
+
#
|
38
|
+
# @return the text according to this Join Type.
|
39
|
+
def to_string
|
40
|
+
case (@type)
|
41
|
+
when LEFT.type
|
42
|
+
return 'left'
|
43
|
+
when RIGHT.type
|
44
|
+
return 'right'
|
45
|
+
when INNER.type
|
46
|
+
return 'inner'
|
47
|
+
when LEFT_OUTER.type
|
48
|
+
return 'left outer'
|
49
|
+
when RIGHT_OUTER.type
|
50
|
+
return 'right outer'
|
51
|
+
else
|
52
|
+
return 'inner'
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
#This class represents a Join clause
|
58
|
+
class JoinClause < Condition
|
59
|
+
# Builds a JoinClause using type, model and compatible condition.
|
60
|
+
#
|
61
|
+
# @param join_type join type
|
62
|
+
# @param model_id target model id
|
63
|
+
# @param aliass alias to use with this target model. You don't need to concatenate the alias in join condition.
|
64
|
+
# @param join_condition compatible join condition
|
65
|
+
def initialize(join_type, model_id, aliass, join_condition)
|
66
|
+
@join_type = join_type
|
67
|
+
@model_id = model_id
|
68
|
+
@join_condition = join_condition
|
69
|
+
@alias = aliass
|
70
|
+
end
|
71
|
+
|
72
|
+
# This method will return a String of this condition
|
73
|
+
# @param parent this is the parent of this condition
|
74
|
+
# @return a json
|
75
|
+
def to_record_string(parent)
|
76
|
+
'{ "type": "' + @join_type.to_string + '", "alias": "' + @alias + '", "target": "' + @model_id.to_s + '", "on": "' + @join_condition + '" }'
|
77
|
+
end
|
78
|
+
end
|
79
|
+
# End of JoinClause class
|
80
|
+
|
22
81
|
class ANDCondition < Condition
|
23
82
|
# Will build an and condition using two part.
|
24
83
|
# @param left left part of this and condition
|
@@ -393,6 +452,56 @@ module Dynamicloud
|
|
393
452
|
inner_equals(left, right, '<')
|
394
453
|
end
|
395
454
|
|
455
|
+
# Builds a left join clause.
|
456
|
+
#
|
457
|
+
# @param model_id target model id of this join
|
458
|
+
# @param aliass attached alias to this target model
|
459
|
+
# @param Condition on condition of this join clause
|
460
|
+
# @return a Join Clause as a condition
|
461
|
+
def self.left_join(model_id, aliass, condition)
|
462
|
+
return JoinClause.new(JoinType::LEFT, model_id, aliass, condition);
|
463
|
+
end
|
464
|
+
|
465
|
+
# Builds a left outer join clause.
|
466
|
+
#
|
467
|
+
# @param model_id target model id of this join
|
468
|
+
# @param aliass attached alias to this target model
|
469
|
+
# @param Condition on condition of this join clause
|
470
|
+
# @return a Join Clause as a condition
|
471
|
+
def self.left_outer_join(model_id, aliass, condition)
|
472
|
+
return JoinClause.new(JoinType::LEFT_OUTER, model_id, aliass, condition);
|
473
|
+
end
|
474
|
+
|
475
|
+
# Builds a right join clause.
|
476
|
+
#
|
477
|
+
# @param model_id target model id of this join
|
478
|
+
# @param aliass attached alias to this target model
|
479
|
+
# @param Condition on condition of this join clause
|
480
|
+
# @return a Join Clause as a condition
|
481
|
+
def self.right_join(model_id, aliass, condition)
|
482
|
+
return JoinClause.new(JoinType::RIGHT, model_id, aliass, condition);
|
483
|
+
end
|
484
|
+
|
485
|
+
# Builds a right outer join clause.
|
486
|
+
#
|
487
|
+
# @param model_id target model id of this join
|
488
|
+
# @param aliass attached alias to this target model
|
489
|
+
# @param Condition on condition of this join clause
|
490
|
+
# @return a Join Clause as a condition
|
491
|
+
def self.right_outer_join(model_id, aliass, condition)
|
492
|
+
return JoinClause.new(JoinType::RIGHT_OUTER, model_id, aliass, condition);
|
493
|
+
end
|
494
|
+
|
495
|
+
# Builds a inner join clause.
|
496
|
+
#
|
497
|
+
# @param model_id target model id of this join
|
498
|
+
# @param aliass attached alias to this target model
|
499
|
+
# @param Condition on condition of this join clause
|
500
|
+
# @return a Join Clause as a condition
|
501
|
+
def self.inner_join(model_id, aliass, condition)
|
502
|
+
return JoinClause.new(JoinType::INNER, model_id, aliass, condition);
|
503
|
+
end
|
504
|
+
|
396
505
|
# This method will build a not equals condition.
|
397
506
|
# @param left value to compare
|
398
507
|
# @param right right part of this condition
|
data/lib/dynamicloud/version.rb
CHANGED