resty-generators 0.7.2 → 0.7.3

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.
Files changed (34) hide show
  1. data/features/generators.feature +10 -10
  2. data/lib/generators/resty/model/model_generator.rb +7 -1
  3. data/lib/generators/resty/scaffold/scaffold_generator.rb +1 -1
  4. data/lib/generators/resty/setup/setup_generator.rb +61 -46
  5. data/lib/generators/resty/setup/templates/ActivityPlaceActivityMapper.java +1 -1
  6. data/lib/generators/resty/setup/templates/Application.java +31 -0
  7. data/lib/generators/resty/setup/templates/Application.java~ +95 -0
  8. data/lib/generators/resty/setup/templates/ApplicationLinksPanel.java +29 -0
  9. data/lib/generators/resty/setup/templates/ApplicationLinksPanel.java~ +29 -0
  10. data/lib/generators/resty/setup/templates/BreadCrumbsPanel.java +2 -2
  11. data/lib/generators/resty/setup/templates/EntryPoint.java +14 -4
  12. data/lib/generators/resty/setup/templates/LoginActivity.java +2 -2
  13. data/lib/generators/resty/setup/templates/Mavenfile +10 -2
  14. data/lib/generators/resty/setup/templates/SessionActivityPlaceActivityMapper.java +3 -3
  15. data/lib/generators/resty/setup/templates/User.java +14 -1
  16. data/lib/generators/resty/setup/templates/application.rb +15 -0
  17. data/lib/generators/resty/setup/templates/authentication.rb +2 -2
  18. data/lib/generators/resty/setup/templates/gwt.css +13 -1
  19. data/lib/generators/resty/setup/templates/remote_user.rb +1 -1
  20. data/lib/generators/resty/setup/templates/remote_user.rb~ +1 -1
  21. data/lib/generators/resty/setup/templates/session.rb +7 -0
  22. data/lib/generators/resty/setup/templates/sessions_controller.rb +2 -2
  23. data/lib/generators/resty/setup/templates/user.rb +23 -5
  24. data/lib/generators/resty/templates/Activity.java +22 -5
  25. data/lib/generators/resty/templates/Editor.java +1 -0
  26. data/lib/generators/resty/templates/Model.java +8 -2
  27. data/lib/generators/resty/templates/RestService.java +0 -1
  28. data/lib/ixtlan/core/heartbeat.rb~ +8 -2
  29. data/lib/rails_gwt/dsl.rb +210 -0
  30. data/lib/rails_gwt/dsl.rb~ +210 -0
  31. data/lib/rails_gwt/user_config.rb +80 -0
  32. data/lib/rails_gwt/user_config.rb~ +76 -0
  33. metadata +11 -3
  34. data/lib/ixtlan/core/heartbeat.rb +0 -59
@@ -33,7 +33,7 @@ public class BreadCrumbsPanel extends FlowPanel {
33
33
  sessionManager.addSessionHandler(new SessionHandler<User>() {
34
34
 
35
35
  public void timeout() {
36
- notice.setText("timeout");
36
+ notice.info("timeout");
37
37
  logout();
38
38
  }
39
39
 
@@ -52,7 +52,7 @@ public class BreadCrumbsPanel extends FlowPanel {
52
52
  }
53
53
 
54
54
  public void accessDenied() {
55
- notice.setText("access denied");
55
+ notice.error("access denied");
56
56
  }
57
57
  });
58
58
  logout = new Button("logout");
@@ -39,6 +39,9 @@ public class <%= application_name %>EntryPoint implements EntryPoint {
39
39
  <% end -%>
40
40
  <% if options[:menu] -%>
41
41
  private final <%= application_name %>MenuPanel menu;
42
+ <% end -%>
43
+ <% if options[:remote_users] -%>
44
+ private final ApplicationLinksPanel links;
42
45
  <% end -%>
43
46
  private RootPanel root;
44
47
 
@@ -50,18 +53,22 @@ public class <%= application_name %>EntryPoint implements EntryPoint {
50
53
  <% if options[:menu] -%>
51
54
  final <%= application_name %>MenuPanel menu,
52
55
  <% end -%>
53
- final ActivityManager activityManager){
56
+ final ActivityManager activityManager<% if options[:remote_users] -%>,
57
+ final ApplicationLinksPanel links<% end -%>){
54
58
  super(activityManager);
55
59
  this.notice = notice;
56
60
  <% if options[:session] -%>
57
61
  this.breadCrumbs = breadCrumbs;
58
62
  <% end -%>
59
63
  <% if options[:menu] -%>
60
- this.menu = menu;
64
+ this.menu = menu;
65
+ <% end -%>
66
+ <% if options[:remote_users] -%>
67
+ this.links = links;
61
68
  <% end -%>
62
69
  }
63
70
 
64
- protected Panel getApplicationPanel(){
71
+ protected void initApplicationPanel(Panel panel) {
65
72
  if (this.root == null) {
66
73
  this.root = RootPanel.get();
67
74
  this.root.add(notice);
@@ -70,9 +77,12 @@ public class <%= application_name %>EntryPoint implements EntryPoint {
70
77
  <% end -%>
71
78
  <% if options[:menu] -%>
72
79
  this.root.add(menu);
80
+ <% end -%>
81
+ this.root.add(panel);
82
+ <% if options[:remote_users] -%>
83
+ this.root.add(links);
73
84
  <% end -%>
74
85
  }
75
- return this.root;
76
86
  }
77
87
  }
78
88
 
@@ -66,11 +66,11 @@ public class LoginActivity extends AbstractActivity implements LoginView.Present
66
66
  service.resetPassword(authentication, new MethodCallback<Void>() {
67
67
 
68
68
  public void onSuccess(Method method, Void result) {
69
- notice.setText("new password was sent to your email address");
69
+ notice.info("new password was sent to your email address");
70
70
  }
71
71
 
72
72
  public void onFailure(Method method, Throwable exception) {
73
- notice.setText("could not reset password - username/email unknown");
73
+ notice.error("could not reset password - username/email unknown");
74
74
  }
75
75
  });
76
76
  }
@@ -1,7 +1,7 @@
1
1
  #-*- mode: ruby -*-
2
2
  GWT_VERSION = '2.4.0'
3
- jar('de.mkristian.gwt:rails-gwt', '0.7.0').scope :provided
4
- jar('org.fusesource.restygwt:restygwt', '1.2').scope :provided
3
+ jar('de.mkristian.gwt:rails-gwt', '0.7.1-SNAPSHOT').scope :provided
4
+ jar('org.fusesource.restygwt:restygwt', '1.3-SNAPSHOT').scope :provided
5
5
  jar('javax.ws.rs:jsr311-api', '1.1').scope :provided
6
6
  jar('com.google.gwt:gwt-user', GWT_VERSION).scope :provided
7
7
  jar('com.google.gwt.inject:gin', '1.5.0').scope :provided
@@ -30,4 +30,12 @@ profile("mac") do |mac|
30
30
  mac.activation.os.family "mac"
31
31
  mac.plugin('org.codehaus.mojo:gwt-maven-plugin').with(:extraJvmArgs => "-d32 -XstartOnFirstThread -Xmx512m")
32
32
  end
33
+
34
+ # to get the restygwt and rails-gwt snapshots
35
+ repository("snapshots") do |snapshot|
36
+ snapshots.url "http://"
37
+ snapshots.releases(:enabled => false)
38
+ snapshots.snapshots(:enabled => true)
39
+ end
40
+
33
41
  # vim: syntax=Ruby
@@ -37,11 +37,11 @@ public class SessionActivityPlaceActivityMapper extends ActivityPlaceActivityMap
37
37
  if (!(place instanceof NoAuthorization)) {
38
38
  if(manager.hasSession()){
39
39
  if(!manager.isAllowed((RestfulPlace<?,?>)place)){
40
- notice.setText("nothing to see");
40
+ notice.warn("nothing to see");
41
41
  return null;
42
42
  }
43
43
  //TODO move into a dispatch filter or callback filter
44
- manager.resetTimer();
44
+ manager.resetCountDown();
45
45
  }
46
46
  else {
47
47
  return LoginPlace.LOGIN.create(factory);
@@ -58,7 +58,7 @@ public class SessionActivityPlaceActivityMapper extends ActivityPlaceActivityMap
58
58
  if (place instanceof NeedsAuthorization) {
59
59
  if(manager.hasSession()){
60
60
  if(!manager.isAllowed((RestfulPlace<?,?>)place)){
61
- notice.setText("nothing to see");
61
+ notice.warn("nothing to see");
62
62
  return null;
63
63
  }
64
64
  }
@@ -1,4 +1,9 @@
1
1
  package <%= models_package %>;
2
+ <% if options[:remote_users] -%>
3
+
4
+ import java.util.Collections;
5
+ import java.util.List;
6
+ <% end -%>
2
7
 
3
8
  import org.codehaus.jackson.annotate.JsonCreator;
4
9
  import org.codehaus.jackson.annotate.JsonProperty;
@@ -14,12 +19,20 @@ public class User implements IsUser {
14
19
  private String login;
15
20
 
16
21
  private String name;
22
+ <% if options[:remote_users] -%>
23
+
24
+ public final List<Application> applications;
25
+ <% end -%>
17
26
 
18
27
  @JsonCreator
19
28
  public User(@JsonProperty("login") String login,
20
- @JsonProperty("name") String name){
29
+ @JsonProperty("name") String name<% if options[:remote_users] -%>,
30
+ @JsonProperty("applications") List<Application> applications<% end -%>){
21
31
  this.login = login;
22
32
  this.name = name;
33
+ <% if options[:remote_users] -%>
34
+ this.applications = applications == null ? null : Collections.unmodifiableList(applications);
35
+ <% end -%>
23
36
  }
24
37
 
25
38
  public String getLogin(){
@@ -0,0 +1,15 @@
1
+ class Application
2
+ include ActiveModel::Serializers::JSON
3
+ include ActiveModel::Serializers::Xml
4
+
5
+ attr_accessor :name, :url
6
+
7
+ def initialize(attributes = {})
8
+ @name = attributes['name']
9
+ @url = attributes['url']
10
+ end
11
+
12
+ def attributes
13
+ { 'name' => name, 'url' => url }
14
+ end
15
+ end
@@ -1,4 +1,4 @@
1
1
  class Authentication < ActiveResource::Base
2
- self.site = Rails.application.config.respond_to?(:remote_sso_url) ? Rails.application.config.remote_sso_url : "http://localhost:3000"
3
- self.headers['X-SERVICE-TOKEN'] = Rails.application.config.respond_to?(:remote_sso_token) ? Rails.application.config.remote_sso_token : 'be happy'
2
+ self.site = Rails.application.config.respond_to?(:remote_service_url) ? Rails.application.config.remote_service_url : "http://localhost:3000"
3
+ self.headers['X-SERVICE-TOKEN'] = Rails.application.config.respond_to?(:remote_service_token) ? Rails.application.config.remote_service_token : 'be happy'
4
4
  end
@@ -59,4 +59,16 @@
59
59
  .gwt-rails-model-fields .gwt-TextArea
60
60
  {
61
61
  height: 6em;
62
- }
62
+ }
63
+
64
+ .gwt-rails-application-links > div
65
+ {
66
+ display: inline;
67
+ border-left: solid darkblue 1px;
68
+ border-right: solid darkblue 1px;
69
+ padding-left: 0.5em;
70
+ padding-right: 0.5em;
71
+ margin: 0;
72
+ margin-left: -1px;
73
+ font-size: 0.9em;
74
+ }
@@ -1,5 +1,5 @@
1
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"
2
+ self.site = Rails.application.config.respond_to?(:remote_service_url) ? Rails.application.config.remote_service_url : "http://localhost:3000"
3
3
  self.element_name = "user"
4
4
  self.headers['X-SERVICE-TOKEN'] = Rails.application.config.respond_to?(:remote_service_token) ? Rails.application.config.remote_service_token : 'be happy'
5
5
  end
@@ -1,5 +1,5 @@
1
1
  class RemoteUser < ActiveResource::Base
2
2
  self.site = Rails.application.config.respond_to?(:remote_sso_url) ? Rails.application.config.remote_sso_url : "http://localhost:3000"
3
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'
4
+ self.headers['X-SERVICE-TOKEN'] = Rails.application.config.respond_to?(:remote_service_token) ? Rails.application.config.remote_service_token : 'be happy'
5
5
  end
@@ -28,11 +28,18 @@ class Session < Ixtlan::Guard::AbstractSession
28
28
  <% end -%>
29
29
  user.name = auth.name
30
30
  user.groups = auth.groups
31
+ <% if options[:remote_users] -%>
32
+ user.applications = auth.applications
33
+ <% end -%>
31
34
  user
32
35
  rescue ActiveResource::ResourceNotFound
33
36
  result = User.new
34
37
  result.log = "access denied #{login}" # error message
35
38
  result
39
+ rescue ActiveResource::UnauthorizedAccess
40
+ result = User.new
41
+ result.log = "access denied #{login}" # error message
42
+ result
36
43
  end
37
44
  end
38
45
  end
@@ -1,6 +1,6 @@
1
1
  class SessionsController < ApplicationController
2
2
 
3
- skip_before_filter :authorization
3
+ skip_before_filter :authorize
4
4
 
5
5
  skip_before_filter :check_session, :only => :destroy
6
6
 
@@ -10,7 +10,7 @@ class SessionsController < ApplicationController
10
10
 
11
11
  def create
12
12
  auth = params[:authentication] || params
13
- method = Rails.application.config.respond_to?(:remote_sso_url) ? :create_remote : :create
13
+ method = Rails.application.config.respond_to?(:remote_service_url) ? :create_remote : :create
14
14
  @session = Session.send(method, auth[:login] || auth[:email],
15
15
  auth[:password])
16
16
 
@@ -1,11 +1,12 @@
1
1
  class User<% if options[:remote_users] -%> < ActiveRecord::Base
2
2
 
3
- attr_accessor :groups
4
-
3
+ attr_accessor :groups, :applications
4
+
5
5
  validates :login, :presence => true
6
6
 
7
7
  record_timestamps = false
8
8
  <% else -%>
9
+
9
10
  include ActiveModel::Serializers::JSON
10
11
  include ActiveModel::Serializers::Xml
11
12
 
@@ -35,6 +36,9 @@ class User<% if options[:remote_users] -%> < ActiveRecord::Base
35
36
  result.id = 0
36
37
  <% end -%>
37
38
  result.groups = [Group.new('name' => login)]
39
+ <% if options[:remote_users] -%>
40
+ result.applications = []
41
+ <% end -%>
38
42
  else
39
43
  result.log = "wrong password for login: #{login}"
40
44
  end
@@ -42,7 +46,13 @@ class User<% if options[:remote_users] -%> < ActiveRecord::Base
42
46
  end
43
47
 
44
48
  def self.reset_password(login)
45
- Authentication.post(:reset_password, :login => login)
49
+ result = User.new(:login => login)
50
+ begin
51
+ Authentication.post(:reset_password, :login => login)
52
+ rescue ActiveResource::ResourceNotFound
53
+ result.log = "User(#{login}) not found"
54
+ end
55
+ result
46
56
  end
47
57
 
48
58
  def log=(msg)
@@ -53,11 +63,19 @@ class User<% if options[:remote_users] -%> < ActiveRecord::Base
53
63
  if @log
54
64
  @log
55
65
  else
56
- "User(#{id})"
66
+ "User(#{id ? (id.to_s + ':') : ''}#{login})"
57
67
  end
58
68
  end
59
69
 
60
- <% unless options[:remote_users] -%>
70
+ <% if options[:remote_users] -%>
71
+ unless respond_to? :old_as_json
72
+ alias :old_as_json :as_json
73
+ def as_json(options = nil)
74
+ options = { :methods => [ :applications ] } unless options
75
+ old_as_json(options)
76
+ end
77
+ end
78
+ <% else -%>
61
79
  def valid?(ignore)
62
80
  @log.nil?
63
81
  end
@@ -11,6 +11,7 @@ import <%= events_package %>.<%= class_name %>EventHandler;
11
11
  <% if !options[:singleton] && !options[:read_only] -%>
12
12
  import <%= caches_package %>.<%= class_name.pluralize %>Cache;
13
13
  <% end -%>
14
+
14
15
  <% for attribute in attributes -%>
15
16
  <% if attribute.type == :belongs_to -%>
16
17
  import <%= models_package %>.<%= attribute.name.classify %>;
@@ -39,6 +40,7 @@ import com.google.gwt.user.client.ui.AcceptsOneWidget;
39
40
  import com.google.inject.Inject;
40
41
  import com.google.inject.assistedinject.Assisted;
41
42
 
43
+ import <%= gwt_rails_package %>.DisplayErrors;
42
44
  import <%= gwt_rails_package %>.Notice;
43
45
  <% if !options[:singleton] && !options[:read_only] -%>
44
46
  import <%= gwt_rails_package %>.events.ModelEvent;
@@ -55,6 +57,7 @@ public class <%= class_name %>Activity extends AbstractActivity implements <%= c
55
57
  <% end -%>
56
58
  private final <%= class_name.pluralize %>RestService service;
57
59
  private final Notice notice;
60
+ private final DisplayErrors errors;
58
61
  private final PlaceController placeController;
59
62
  private final <%= class_name %>View view;
60
63
  <% if !options[:singleton] && !options[:read_only] -%>
@@ -66,8 +69,8 @@ public class <%= class_name %>Activity extends AbstractActivity implements <%= c
66
69
  private EventBus eventBus;
67
70
 
68
71
  @Inject
69
- public <%= class_name %>Activity(@Assisted <%= class_name %>Place place, final Notice notice, final <%= class_name %>View view,
70
- <%= class_name.pluralize %>RestService service, PlaceController placeController<% if !options[:singleton] && !options[:read_only] -%>,
72
+ public <%= class_name %>Activity(@Assisted <%= class_name %>Place place, final Notice notice, DisplayErrors errors,
73
+ final <%= class_name %>View view, <%= class_name.pluralize %>RestService service, PlaceController placeController<% if !options[:singleton] && !options[:read_only] -%>,
71
74
  <%= class_name.pluralize %>Cache cache<% for attribute in attributes -%>
72
75
  <% end -%>
73
76
  <% if attribute.type == :belongs_to -%>
@@ -76,6 +79,7 @@ public class <%= class_name %>Activity extends AbstractActivity implements <%= c
76
79
  this.place = place;
77
80
  <% end -%>
78
81
  this.notice = notice;
82
+ this.errors = errors;
79
83
  this.view = view;
80
84
  this.service = service;
81
85
  this.placeController = placeController;
@@ -202,7 +206,10 @@ public class <%= class_name %>Activity extends AbstractActivity implements <%= c
202
206
 
203
207
  public void onFailure(Method method, Throwable exception) {
204
208
  notice.finishLoading();
205
- notice.error("error creating <%= class_name.underscore.humanize %>", exception);
209
+ switch (errors.showMessages(method, exception)) {
210
+ case GENERAL:
211
+ notice.error("error creating <%= class_name.underscore.humanize %>", exception);
212
+ }
206
213
  }
207
214
 
208
215
  public void onSuccess(Method method, <%= class_name %> response) {
@@ -254,7 +261,12 @@ public class <%= class_name %>Activity extends AbstractActivity implements <%= c
254
261
 
255
262
  public void onFailure(Method method, Throwable exception) {
256
263
  notice.finishLoading();
257
- notice.error("error saving <%= class_name.underscore.humanize %>", exception);
264
+ switch (errors.showMessages(method, exception)) {
265
+ case CONFLICT:
266
+ //TODO
267
+ case GENERAL:
268
+ notice.error("error saving <%= class_name.underscore.humanize %>", exception);
269
+ }
258
270
  }
259
271
 
260
272
  public void onSuccess(Method method, <%= class_name %> response) {
@@ -272,7 +284,12 @@ public class <%= class_name %>Activity extends AbstractActivity implements <%= c
272
284
 
273
285
  public void onFailure(Method method, Throwable exception) {
274
286
  notice.finishLoading();
275
- notice.error("error deleting <%= class_name.underscore.humanize %>", exception);
287
+ switch (errors.showMessages(method, exception)) {
288
+ case CONFLICT:
289
+ //TODO
290
+ case GENERAL:
291
+ notice.error("error deleting <%= class_name.underscore.humanize %>", exception);
292
+ }
276
293
  }
277
294
 
278
295
  public void onSuccess(Method method, Void response) {
@@ -85,6 +85,7 @@ public class <%= class_name %>Editor extends Composite implements Editor<<%= cla
85
85
  <% elsif attribute.type == :text && options[:read_only] -%>
86
86
  @UiField Label <%= attribute.name.camelcase.sub(/^(.)/){ $1.downcase } %>;
87
87
  <% else -%>
88
+ <% raise "unknown widget for type #{attribute.type}" unless type_widget_map[attribute.type] -%>
88
89
  @UiField <%= type_widget_map[attribute.type][2..-1] %> <%= attribute.name.camelcase.sub(/^(.)/){ $1.downcase } %>;
89
90
  <% end -%>
90
91
 
@@ -47,7 +47,7 @@ public class <%= class_name %> implements HasToDisplay<% unless options[:singlet
47
47
  <% if attribute.type == :has_one || attribute.type == :belongs_to -%>
48
48
  private <%= attribute.name.classify %> <%= name %>;
49
49
  <% elsif attribute.type == :has_many -%>
50
- private java.util.List<<%= attribute.name.classify %>> <%= name %>;
50
+ private java.util.List<<%= attribute.name.singularize.classify %>> <%= name %>;
51
51
  <% else -%>
52
52
  private <%= type_map[attribute.type] || attribute.type.to_s.classify %> <%= name %>;
53
53
  <% end -%>
@@ -128,7 +128,13 @@ public class <%= class_name %> implements HasToDisplay<% unless options[:singlet
128
128
  }
129
129
  <% end -%>
130
130
  <% elsif attribute.type == :has_many -%>
131
- //TODO private java.util.List<<%= attribute.name.classify %>> <%= name %>;
131
+ public java.util.List<<%= attribute.name.singularize.classify %>> get<%= attribute.name.pluralize.camelcase %>(){
132
+ return <%= name %>;
133
+ }
134
+
135
+ public void set<%= attribute.name.pluralize.camelcase %>(java.util.List<<%= attribute.name.singularize.classify %>> value){
136
+ <%= name %> = value;
137
+ }
132
138
  <% else -%>
133
139
  public <%= type_map[attribute.type] || attribute.type.to_s.classify %> get<%= name.camelcase %>(){
134
140
  return <%= name %>;
@@ -21,7 +21,6 @@ import org.fusesource.restygwt.client.RestService;
21
21
 
22
22
  <% if name -%>
23
23
  import <%= models_package %>.<%= class_name %>;
24
- import <%= models_package %>.*;
25
24
  <% end -%>
26
25
 
27
26
  <% if options[:singleton] -%>@Path("/<%= singular_table_name %>")
@@ -36,8 +36,14 @@ class Ixtlan::Core::Heartbeat
36
36
  last_update = res.local.maximum(:updated_at) || 2000.years.ago
37
37
  last_update = last_update.strftime('%Y-%m-%d %H:%M:%S.') + ("%06d" % last_update.usec)
38
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)
39
+ id = remote.delete('id')
40
+ u = res.local.find_by_id(id)
41
+ if u
42
+ u.update_attributes(remote)
43
+ else
44
+ u = res.local.new(remote)
45
+ u.id = id
46
+ end
41
47
  if u.save
42
48
  res.count = res.count + 1
43
49
  else