resty-generators 0.7.0 → 0.7.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/generators/resty/scaffold/scaffold_generator.rb +1 -1
- data/lib/generators/resty/setup/setup_generator.rb +11 -1
- data/lib/generators/resty/setup/templates/MenuPanel.java +1 -1
- data/lib/generators/resty/setup/templates/create_users.rb +13 -0
- data/lib/generators/resty/setup/templates/heartbeat.rb +9 -0
- data/lib/generators/resty/setup/templates/heartbeat.rb~ +8 -0
- data/lib/generators/resty/setup/templates/remote_user.rb +5 -0
- data/lib/generators/resty/setup/templates/remote_user.rb~ +5 -0
- data/lib/generators/resty/setup/templates/seed.rb~ +25 -0
- data/lib/generators/resty/setup/templates/seeds.rb +29 -0
- data/lib/generators/resty/setup/templates/seeds.rb~ +29 -0
- data/lib/generators/resty/setup/templates/session.rb +13 -0
- data/lib/generators/resty/setup/templates/user.rb +16 -3
- data/lib/ixtlan/core/heartbeat.rb +53 -0
- data/lib/ixtlan/core/heartbeat.rb~ +52 -0
- metadata +13 -3
@@ -112,7 +112,7 @@ end
|
|
112
112
|
|
113
113
|
content.sub! /new GinFactoryModuleBuilder\(\)/, "new GinFactoryModuleBuilder()\n .implement(Activity.class, Names.named(\"#{table_name}\"), #{activities_package}.#{class_name}Activity.class)"
|
114
114
|
|
115
|
-
content.sub!
|
115
|
+
content.sub! /^\}/, <<-EOF
|
116
116
|
|
117
117
|
@Singleton
|
118
118
|
public static class #{class_name.pluralize}RestServiceProvider implements Provider<#{restservices_package}.#{class_name.pluralize}RestService> {
|
@@ -13,6 +13,8 @@ module Resty
|
|
13
13
|
|
14
14
|
class_option :menu, :type => :boolean, :default => false
|
15
15
|
|
16
|
+
class_option :remote_users, :type => :boolean, :default => false
|
17
|
+
|
16
18
|
def name
|
17
19
|
gwt_module_name
|
18
20
|
end
|
@@ -26,7 +28,7 @@ module Resty
|
|
26
28
|
unless File.read(".gitignore") =~ /^target/
|
27
29
|
File.open(".gitignore", "a") { |f| f.puts "target/" }
|
28
30
|
end
|
29
|
-
unless File.read(".gitignore") =~
|
31
|
+
unless File.read(".gitignore") =~ /^\*pom/
|
30
32
|
File.open(".gitignore", "a") { |f| f.puts "*pom" }
|
31
33
|
end
|
32
34
|
end
|
@@ -120,6 +122,7 @@ module Resty
|
|
120
122
|
|
121
123
|
if ENV['SSO'] == 'true' || ENV['SSO'] == ''
|
122
124
|
config.remote_sso_url = "http://localhost:3000"
|
125
|
+
config.remote_token = "be happy"
|
123
126
|
end
|
124
127
|
end
|
125
128
|
ENV
|
@@ -170,6 +173,13 @@ SESSION
|
|
170
173
|
template 'group.rb', File.join('app', 'models', "group.rb")
|
171
174
|
template 'session.rb', File.join('app', 'models', "session.rb")
|
172
175
|
template 'user.rb', File.join('app', 'models', "user.rb")
|
176
|
+
if options[:remote_users]
|
177
|
+
template 'remote_user.rb', File.join('app', 'models', "remote_user.rb")
|
178
|
+
template 'create_users.rb', File.join('db', 'migrate', "0_create_users.rb")
|
179
|
+
template 'heartbeat.rb', File.join('lib', 'heartbeat.rb')
|
180
|
+
end
|
181
|
+
FileUtils.mv(File.join('db', 'seeds.rb'), File.join('db', 'seeds-old.rb'))
|
182
|
+
template 'seeds.rb', File.join('db', 'seeds.rb')
|
173
183
|
route <<ROUTE
|
174
184
|
resource :session do
|
175
185
|
member do
|
@@ -22,6 +22,6 @@ public class <%= application_name %>MenuPanel extends MenuPanel<<%= options[:ses
|
|
22
22
|
|
23
23
|
@Inject
|
24
24
|
<%= application_name %>MenuPanel(final PlaceController placeController<% if options[:session] -%>, SessionManager<User> sessionManager<% end %>){
|
25
|
-
super(<% if options[:session] -%>sessionManager<% end
|
25
|
+
super(<% if options[:session] -%>sessionManager<% end -%>, placeController);
|
26
26
|
}
|
27
27
|
}
|
@@ -0,0 +1,5 @@
|
|
1
|
+
class RemoteUser < ActiveResource::Base
|
2
|
+
self.site = Rails.application.config.respond_to?(:remote_sso_url) ? Rails.application.config.remote_sso_url : "http://localhost:3000"
|
3
|
+
self.element_name = "user"
|
4
|
+
self.headers['X-SERVICE-TOKEN'] = Rails.application.config.respond_to?(:remote_service_token) ? Rails.application.config.remote_service_token : 'be happy'
|
5
|
+
end
|
@@ -0,0 +1,5 @@
|
|
1
|
+
class RemoteUser < ActiveResource::Base
|
2
|
+
self.site = Rails.application.config.respond_to?(:remote_sso_url) ? Rails.application.config.remote_sso_url : "http://localhost:3000"
|
3
|
+
self.element_name = "user"
|
4
|
+
self.headers['X-SERVICE-TOKEN'] = Rails.application.config.respond_to?(:remote_token) ? Rails.application.config.remote_token : 'be happy'
|
5
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# This file should contain all the record creation needed to seed the database with its default values.
|
2
|
+
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
|
3
|
+
#
|
4
|
+
# Examples:
|
5
|
+
#
|
6
|
+
# cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }])
|
7
|
+
# Mayor.create(:name => 'Daley', :city => cities.first)
|
8
|
+
u = User.new(:name => "Root", :login => "root")
|
9
|
+
u.id = 0
|
10
|
+
u.save
|
11
|
+
u.modified_by = u
|
12
|
+
u.save
|
13
|
+
|
14
|
+
c = Configuration.instance
|
15
|
+
<% if defined? Ixtlan::Errors -%>
|
16
|
+
c.errors_keep_dumps = 30
|
17
|
+
<% end -%>
|
18
|
+
<% if defined? Ixtlan:Audit -%>
|
19
|
+
c.audit_keep_logs = 90
|
20
|
+
<% end -%>
|
21
|
+
<% if defined? Ixtlan::Session -%>
|
22
|
+
c.idle_session_timeout = 15
|
23
|
+
<% end -%>
|
24
|
+
c.modified_by = u
|
25
|
+
c.save
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# This file should contain all the record creation needed to seed the database with its default values.
|
2
|
+
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
|
3
|
+
#
|
4
|
+
# Examples:
|
5
|
+
#
|
6
|
+
# cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }])
|
7
|
+
# Mayor.create(:name => 'Daley', :city => cities.first)
|
8
|
+
<% if options[:remote_users] -%>
|
9
|
+
u = User.new(:name => "Root", :login => "root")
|
10
|
+
u.id = 0
|
11
|
+
u.save
|
12
|
+
<% end -%>
|
13
|
+
|
14
|
+
c = Configuration.instance
|
15
|
+
if defined? Ixtlan::Errors
|
16
|
+
c.errors_keep_dumps = 30
|
17
|
+
end
|
18
|
+
if defined? Ixtlan::Audit
|
19
|
+
c.audits_keep_logs = 90
|
20
|
+
end
|
21
|
+
if defined? Ixtlan::Sessions
|
22
|
+
c.idle_session_timeout = 15
|
23
|
+
end
|
24
|
+
<% if options[:remote_users] -%>
|
25
|
+
c.modified_by = u
|
26
|
+
<% else -%>
|
27
|
+
# TODO maybe a modified_by= assignment is missing
|
28
|
+
<% end -%>
|
29
|
+
c.save
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# This file should contain all the record creation needed to seed the database with its default values.
|
2
|
+
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
|
3
|
+
#
|
4
|
+
# Examples:
|
5
|
+
#
|
6
|
+
# cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }])
|
7
|
+
# Mayor.create(:name => 'Daley', :city => cities.first)
|
8
|
+
<% if options[:remote_users] -%>
|
9
|
+
u = User.new(:name => "Root", :login => "root")
|
10
|
+
u.id = 0
|
11
|
+
u.save
|
12
|
+
<% end -%>
|
13
|
+
|
14
|
+
c = Configuration.instance
|
15
|
+
if defined? Ixtlan::Errors
|
16
|
+
c.errors_keep_dumps = 30
|
17
|
+
end
|
18
|
+
if defined? Ixtlan:Audit
|
19
|
+
c.audit_keep_logs = 90
|
20
|
+
end
|
21
|
+
if defined? Ixtlan::Session
|
22
|
+
c.idle_session_timeout = 15
|
23
|
+
end
|
24
|
+
<% if options[:remote_users] -%>
|
25
|
+
c.modified_by = u
|
26
|
+
<% else -%>
|
27
|
+
# TODO maybe a modified_by= assignment is missing
|
28
|
+
<% end -%>
|
29
|
+
c.save
|
@@ -1,4 +1,7 @@
|
|
1
1
|
require 'ixtlan/guard/abstract_session'
|
2
|
+
<% if options[:remote_users] -%>
|
3
|
+
require 'ixtlan/core/heartbeat'
|
4
|
+
<% end -%>
|
2
5
|
|
3
6
|
class Session < Ixtlan::Guard::AbstractSession
|
4
7
|
include ActiveModel::Serializers::JSON
|
@@ -11,8 +14,18 @@ class Session < Ixtlan::Guard::AbstractSession
|
|
11
14
|
def self.authenticate_remote(login, password)
|
12
15
|
begin
|
13
16
|
auth = Authentication.create(:login => login, :password => password)
|
17
|
+
<% if options[:remote_users] -%>
|
18
|
+
user = User.find_by_login(auth.login)
|
19
|
+
if user.nil?
|
20
|
+
heart = Heartbeat.new
|
21
|
+
heart.beat User
|
22
|
+
user = User.find_by_login(auth.login)
|
23
|
+
raise "user #{auth.login} not found" unless user
|
24
|
+
end
|
25
|
+
<% else -%>
|
14
26
|
user = User.new
|
15
27
|
user.login = auth.login
|
28
|
+
<% end -%>
|
16
29
|
user.name = auth.name
|
17
30
|
user.groups = auth.groups
|
18
31
|
user
|
@@ -1,4 +1,11 @@
|
|
1
|
-
class User
|
1
|
+
class User<% if options[:remote_users] -%> < ActiveRecord::Base
|
2
|
+
|
3
|
+
attr_accessor :groups
|
4
|
+
|
5
|
+
validates :login, :presence => true
|
6
|
+
|
7
|
+
record_timestamps = false
|
8
|
+
<% else -%>
|
2
9
|
include ActiveModel::Serializers::JSON
|
3
10
|
include ActiveModel::Serializers::Xml
|
4
11
|
|
@@ -13,6 +20,7 @@ class User
|
|
13
20
|
@name = attributes['name']
|
14
21
|
@groups = (attributes['groups'] || []).collect {|g| Group.new g }
|
15
22
|
end
|
23
|
+
<% end -%>
|
16
24
|
|
17
25
|
def self.authenticate(login, password)
|
18
26
|
result = User.new
|
@@ -23,6 +31,9 @@ class User
|
|
23
31
|
elsif password == "behappy"
|
24
32
|
result.login = login
|
25
33
|
result.name = login.humanize
|
34
|
+
<% if options[:remote_users] -%>
|
35
|
+
result.id = 0
|
36
|
+
<% end -%>
|
26
37
|
result.groups = [Group.new('name' => login)]
|
27
38
|
else
|
28
39
|
result.log = "wrong password for login: #{login}"
|
@@ -31,7 +42,7 @@ class User
|
|
31
42
|
end
|
32
43
|
|
33
44
|
def self.reset_password(login)
|
34
|
-
Authentication.post(:reset_password, :login=> login)
|
45
|
+
Authentication.post(:reset_password, :login => login)
|
35
46
|
end
|
36
47
|
|
37
48
|
def log=(msg)
|
@@ -46,7 +57,8 @@ class User
|
|
46
57
|
end
|
47
58
|
end
|
48
59
|
|
49
|
-
|
60
|
+
<% unless options[:remote_users] -%>
|
61
|
+
def valid?(ignore)
|
50
62
|
@log.nil?
|
51
63
|
end
|
52
64
|
|
@@ -54,5 +66,6 @@ class User
|
|
54
66
|
false
|
55
67
|
end
|
56
68
|
alias :destroyed? :new_record?
|
69
|
+
<% end -%>
|
57
70
|
|
58
71
|
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
class Ixtlan::Core::Heartbeat
|
2
|
+
|
3
|
+
class Resource
|
4
|
+
|
5
|
+
attr_reader :local, :remote
|
6
|
+
attr_accessor :count, :failure
|
7
|
+
|
8
|
+
def initialize(local, remote)
|
9
|
+
@count = 0
|
10
|
+
@failures = 0
|
11
|
+
@local = local
|
12
|
+
@remote = remote
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_log
|
16
|
+
"update #{@local} - total: #{@count + @failures} success: #{@count} failures: #{@failures}"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def initialize
|
21
|
+
@count = 0
|
22
|
+
@failures = 0
|
23
|
+
end
|
24
|
+
|
25
|
+
def reg
|
26
|
+
@reg ||= {}
|
27
|
+
end
|
28
|
+
|
29
|
+
def register(local, remote)
|
30
|
+
reg[local] = Resource.new(local, remote)
|
31
|
+
end
|
32
|
+
|
33
|
+
def beat(resource = nil)
|
34
|
+
resources = resource.nil? ? reg.values : [reg[resource]]
|
35
|
+
resources.each do |res|
|
36
|
+
last_update = res.local.maximum(:updated_at) || 2000.years.ago
|
37
|
+
last_update = last_update.strftime('%Y-%m-%d %H:%M:%S.') + ("%06d" % last_update.usec)
|
38
|
+
res.remote.get(:last_changes, :updated_at => last_update).each do |remote|
|
39
|
+
u = res.local.find_by_id(remote.delete('id'))
|
40
|
+
u.update_attributes(res.remote)
|
41
|
+
if u.save
|
42
|
+
res.count = res.count + 1
|
43
|
+
else
|
44
|
+
res.failures = res.failures + 1
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
def to_log
|
50
|
+
reg.collect { |r| r.to_log }.join('\n')
|
51
|
+
end
|
52
|
+
alias :to_s :to_log
|
53
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
class Ixtlan::Core::Heartbeat
|
2
|
+
|
3
|
+
class Resource
|
4
|
+
|
5
|
+
attr_reader :local, :remote
|
6
|
+
attr_accessor :count, :failure
|
7
|
+
|
8
|
+
def initialize(local, remote)
|
9
|
+
@count = 0
|
10
|
+
@failures = 0
|
11
|
+
@local = local
|
12
|
+
@remote = remote
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_log
|
16
|
+
"update #{@local} - total: #{@count + @failures} success: #{@count} failures: #{@failures}"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def initialize
|
21
|
+
@count = 0
|
22
|
+
@failures = 0
|
23
|
+
end
|
24
|
+
|
25
|
+
def reg
|
26
|
+
@reg ||= []
|
27
|
+
end
|
28
|
+
|
29
|
+
def register(local, remote)
|
30
|
+
reg << Resource.new(local, remote)
|
31
|
+
end
|
32
|
+
|
33
|
+
def beat
|
34
|
+
reg.each do |res|
|
35
|
+
last_update = res.local.maximum(:updated_at) || 2000.years.ago
|
36
|
+
last_update = last_update.strftime('%Y-%m-%d %H:%M:%S.') + ("%06d" % last_update.usec)
|
37
|
+
res.remote.get(:last_changes, :updated_at => last_update).each do |remote|
|
38
|
+
u = res.local.find_by_id(remote.delete('id'))
|
39
|
+
u.update_attributes(res.remote)
|
40
|
+
if u.save
|
41
|
+
res.count = res.count + 1
|
42
|
+
else
|
43
|
+
res.failures = res.failures + 1
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
def to_log
|
49
|
+
reg.collect { |r| r.to_log }.join('\n')
|
50
|
+
end
|
51
|
+
alias :to_s :to_log
|
52
|
+
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: resty-generators
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.7.
|
5
|
+
version: 0.7.1
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- mkristian
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-11-
|
13
|
+
date: 2011-11-20 00:00:00 +05:30
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
requirements:
|
22
22
|
- - ~>
|
23
23
|
- !ruby/object:Gem::Version
|
24
|
-
version: 0.1.
|
24
|
+
version: 0.1.4
|
25
25
|
type: :runtime
|
26
26
|
version_requirements: *id001
|
27
27
|
- !ruby/object:Gem::Dependency
|
@@ -107,9 +107,12 @@ files:
|
|
107
107
|
- lib/generators/resty/setup/templates/Mavenfile~
|
108
108
|
- lib/generators/resty/setup/templates/gwt.css
|
109
109
|
- lib/generators/resty/setup/templates/user.rb
|
110
|
+
- lib/generators/resty/setup/templates/seeds.rb
|
111
|
+
- lib/generators/resty/setup/templates/heartbeat.rb~
|
110
112
|
- lib/generators/resty/setup/templates/module.gwt.xml
|
111
113
|
- lib/generators/resty/setup/templates/EntryPoint.java
|
112
114
|
- lib/generators/resty/setup/templates/GinModule.java
|
115
|
+
- lib/generators/resty/setup/templates/seed.rb~
|
113
116
|
- lib/generators/resty/setup/templates/sessions_controller.rb
|
114
117
|
- lib/generators/resty/setup/templates/page.html~
|
115
118
|
- lib/generators/resty/setup/templates/LoginView.ui.xml
|
@@ -124,7 +127,10 @@ files:
|
|
124
127
|
- lib/generators/resty/setup/templates/LoginViewImpl.java~
|
125
128
|
- lib/generators/resty/setup/templates/ActivityPlace.java~
|
126
129
|
- lib/generators/resty/setup/templates/authentication.rb
|
130
|
+
- lib/generators/resty/setup/templates/create_users.rb
|
131
|
+
- lib/generators/resty/setup/templates/remote_user.rb
|
127
132
|
- lib/generators/resty/setup/templates/ActivityFactory.java~
|
133
|
+
- lib/generators/resty/setup/templates/seeds.rb~
|
128
134
|
- lib/generators/resty/setup/templates/session.rb~
|
129
135
|
- lib/generators/resty/setup/templates/LoginActivity.java~
|
130
136
|
- lib/generators/resty/setup/templates/ActivityPlace.java
|
@@ -134,6 +140,8 @@ files:
|
|
134
140
|
- lib/generators/resty/setup/templates/LoginViewImpl.java
|
135
141
|
- lib/generators/resty/setup/templates/LoginPlace.java
|
136
142
|
- lib/generators/resty/setup/templates/session.rb
|
143
|
+
- lib/generators/resty/setup/templates/remote_user.rb~
|
144
|
+
- lib/generators/resty/setup/templates/heartbeat.rb
|
137
145
|
- lib/generators/resty/setup/templates/SessionActivityPlaceActivityMapper.java
|
138
146
|
- lib/generators/resty/setup/templates/ActivityFactory.java
|
139
147
|
- lib/generators/resty/setup/templates/gitignore
|
@@ -179,6 +187,8 @@ files:
|
|
179
187
|
- lib/generators/resty/templates/View.java~
|
180
188
|
- lib/generators/resty/templates/Editor.java~
|
181
189
|
- lib/generators/resty/templates/Activity.java~
|
190
|
+
- lib/ixtlan/core/heartbeat.rb~
|
191
|
+
- lib/ixtlan/core/heartbeat.rb
|
182
192
|
- features/step_definitions/simple_steps.rb
|
183
193
|
- features/generators.feature
|
184
194
|
has_rdoc: true
|