resty-generators 0.5.3 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. data/features/generators.feature +67 -0
  2. data/features/step_definitions/simple_steps.rb +1 -0
  3. data/lib/generators/resty/base.rb +15 -3
  4. data/lib/generators/resty/model/model_generator.rb +33 -3
  5. data/lib/generators/resty/scaffold/scaffold_generator.rb +30 -15
  6. data/lib/generators/resty/setup/setup_generator.rb +2 -2
  7. data/lib/generators/resty/setup/setup_generator.rb~ +31 -0
  8. data/lib/generators/resty/setup/templates/ActivityFactory.java~ +7 -0
  9. data/lib/generators/resty/setup/templates/ActivityPlace.java +5 -0
  10. data/lib/generators/resty/setup/templates/ActivityPlace.java~ +8 -0
  11. data/lib/generators/resty/setup/templates/BreadCrumbsPanel.java +3 -2
  12. data/lib/generators/resty/setup/templates/BreadCrumbsPanel.java~ +79 -0
  13. data/lib/generators/resty/setup/templates/GinModule.java~ +7 -0
  14. data/lib/generators/resty/setup/templates/LoginActivity.java~ +58 -0
  15. data/lib/generators/resty/setup/templates/LoginPlace.java~ +20 -0
  16. data/lib/generators/resty/setup/templates/LoginViewImpl.java~ +21 -0
  17. data/lib/generators/resty/setup/templates/Mavenfile +5 -5
  18. data/lib/generators/resty/setup/templates/Mavenfile~ +15 -0
  19. data/lib/generators/resty/setup/templates/MenuPanel.java~ +12 -0
  20. data/lib/generators/resty/setup/templates/PLaceHistoryMapper.java~ +7 -0
  21. data/lib/generators/resty/setup/templates/RestfulPlace.java~ +22 -0
  22. data/lib/generators/resty/setup/templates/SessionActivityPlaceActivityMapper.java~ +71 -0
  23. data/lib/generators/resty/setup/templates/SessionRestService.java~ +23 -0
  24. data/lib/generators/resty/setup/templates/User.java +34 -4
  25. data/lib/generators/resty/setup/templates/authentication.rb +2 -1
  26. data/lib/generators/resty/setup/templates/authentication.rb~ +4 -0
  27. data/lib/generators/resty/setup/templates/empty.css~ +1 -0
  28. data/lib/generators/resty/setup/templates/gwt.css +45 -0
  29. data/lib/generators/resty/setup/templates/initializer.rb~ +1 -0
  30. data/lib/generators/resty/setup/templates/monkey_patch.rb~ +27 -0
  31. data/lib/generators/resty/setup/templates/page.html~ +0 -0
  32. data/lib/generators/resty/setup/templates/session.rb +18 -36
  33. data/lib/generators/resty/setup/templates/session.rb~ +45 -0
  34. data/lib/generators/resty/setup/templates/sessions_controller.rb +27 -8
  35. data/lib/generators/resty/setup/templates/sessions_controller.rb~ +27 -0
  36. data/lib/generators/resty/setup/templates/user.rb +38 -6
  37. data/lib/generators/resty/setup/templates/user.rb~ +27 -0
  38. data/lib/generators/resty/templates/Activity.java +78 -39
  39. data/lib/generators/resty/templates/Activity.java~ +67 -0
  40. data/lib/generators/resty/templates/ActivityPlace.java~ +11 -0
  41. data/lib/generators/resty/templates/ColumnDefinitionsImpl.java~ +24 -0
  42. data/lib/generators/resty/templates/ColumnDefintionsImpl.java~ +34 -0
  43. data/lib/generators/resty/templates/Controller.java~ +49 -0
  44. data/lib/generators/resty/templates/Editor.java +123 -0
  45. data/lib/generators/resty/templates/Editor.java~ +84 -0
  46. data/lib/generators/resty/templates/Editor.ui.xml +41 -0
  47. data/lib/generators/resty/templates/Editor.ui.xml~ +37 -0
  48. data/lib/generators/resty/templates/Event.java +30 -0
  49. data/lib/generators/resty/templates/Event.java~ +31 -0
  50. data/lib/generators/resty/templates/EventHandler.java +8 -0
  51. data/lib/generators/resty/templates/EventHandler.java~ +30 -0
  52. data/lib/generators/resty/templates/Model.java +144 -15
  53. data/lib/generators/resty/templates/Model.java~ +23 -0
  54. data/lib/generators/resty/templates/Place.java +1 -1
  55. data/lib/generators/resty/templates/Place.java~ +21 -0
  56. data/lib/generators/resty/templates/PlaceTokenizer.java +1 -1
  57. data/lib/generators/resty/templates/PlaceTokenizer.java~ +19 -0
  58. data/lib/generators/resty/templates/RestService.java~ +51 -0
  59. data/lib/generators/resty/templates/View.java +15 -4
  60. data/lib/generators/resty/templates/View.java~ +23 -0
  61. data/lib/generators/resty/templates/View.ui.xml +22 -38
  62. data/lib/generators/resty/templates/View.ui.xml~ +17 -0
  63. data/lib/generators/resty/templates/ViewImpl.java +88 -103
  64. data/lib/generators/resty/templates/ViewImpl.java~ +153 -0
  65. data/lib/resty/abstract_session.rb~ +59 -0
  66. data/lib/resty/child_path.rb~ +18 -0
  67. data/lib/resty/session.rb~ +6 -0
  68. metadata +56 -11
@@ -2,16 +2,22 @@ class SessionsController < ApplicationController
2
2
 
3
3
  skip_before_filter :authorization
4
4
 
5
+ skip_before_filter :check_session, :only => :destroy
6
+
5
7
  prepend_after_filter :reset_session, :only => :destroy
6
8
 
7
9
  public
8
10
 
9
11
  def create
10
- @session = Session.create(params[:authentication] || params)
11
-
12
- if @session
13
- current_user @session.user
14
- @session.permissions = guard.permissions(@session.user.groups.collect {|g| g.name.to_s })
12
+ auth = params[:authentication] || params
13
+ method = Rails.application.config.respond_to?(:remote_sso_url) ? :create_remote : :create
14
+ @session = Session.send(method, auth[:login] || auth[:email],
15
+ auth[:password])
16
+
17
+ if @session.valid?
18
+ current_user(@session.user)
19
+ @session.idle_session_timeout = Rails.application.config.idle_session_timeout
20
+ @session.permissions = guard.permissions(groups_for_current_user)
15
21
 
16
22
  # TODO make html login
17
23
  respond_to do |format|
@@ -20,16 +26,29 @@ class SessionsController < ApplicationController
20
26
  format.json { render :json => @session.to_json }
21
27
  end
22
28
  else
23
- head :not_found
29
+ head :unauthorized
24
30
  end
25
31
  end
26
32
 
27
33
  def reset_password
28
- warn "not implemented"
29
- head :ok
34
+ authentication = params[:authentication] || []
35
+ user = User.reset_password(authentication[:email] || authentication[:login])
36
+
37
+ if user
38
+
39
+ # for the log
40
+ @session = user
41
+
42
+ head :ok
43
+ else
44
+ head :not_found
45
+ end
30
46
  end
31
47
 
32
48
  def destroy
49
+ # for the log
50
+ @session = current_user
51
+
33
52
  # reset session happens in the after filter which allows for
34
53
  # audit log with username which happens in another after filter
35
54
  head :ok
@@ -0,0 +1,27 @@
1
+ class SessionsController < ApplicationController
2
+
3
+ skip_before_filter :authorization
4
+
5
+ prepend_after_filter :reset_session, :only => :destroy
6
+
7
+ public
8
+
9
+ def create
10
+ @session = Session.create(params[:session])
11
+
12
+ if @session
13
+ current_user @session.user
14
+ @session.permissions = guard.permissions(self)
15
+
16
+ render :json => @session.to_json(:excludes => :groups)
17
+ else
18
+ head :not_found
19
+ end
20
+ end
21
+
22
+ def destroy
23
+ # reset session happens in the after filter which allows for
24
+ # audit log with username which happens in another after filter
25
+ head :ok
26
+ end
27
+ end
@@ -15,12 +15,44 @@ class User
15
15
  end
16
16
 
17
17
  def self.authenticate(login, password)
18
- if login.size > 0 && password == "behappy"
19
- u = User.new
20
- u.login = login
21
- u.name = login.humanize
22
- u.groups = [Group.new('name' => login)]
23
- u
18
+ result = User.new
19
+ if password.blank?
20
+ result.log = "no password given with login: #{login}"
21
+ elsif login.blank?
22
+ result.log = "no login given"
23
+ elsif password == "behappy"
24
+ result.login = login
25
+ result.name = login.humanize
26
+ result.groups = [Group.new('name' => login)]
27
+ else
28
+ result.log = "wrong password for login: #{login}"
24
29
  end
30
+ result
25
31
  end
32
+
33
+ def self.reset_password(login)
34
+ Authentication.post(:reset_password, :login=> login)
35
+ end
36
+
37
+ def log=(msg)
38
+ @log = msg
39
+ end
40
+
41
+ def to_log
42
+ if @log
43
+ @log
44
+ else
45
+ "User(#{id})"
46
+ end
47
+ end
48
+
49
+ def valid?
50
+ @log.nil?
51
+ end
52
+
53
+ def new_record?
54
+ false
55
+ end
56
+ alias :destroyed? :new_record?
57
+
26
58
  end
@@ -0,0 +1,27 @@
1
+ class User
2
+ include ActiveModel::Serializers::JSON
3
+
4
+ attr_accessor :login, :name, :groups
5
+
6
+ def attributes
7
+ {'login' => login, 'name' => name, 'groups' => groups.collect { |g| g.attributes } }
8
+ end
9
+
10
+ def initialize(attributes = {})
11
+ @login = attributes['login']
12
+ @name = attributes['name']
13
+ @groups = (attributes['groups'] || []).collect {|g| Group.new g }
14
+ end
15
+
16
+ def self.authenticate(login, password)
17
+ if login =~ /^oldstudent$|^dhammaworker$/ && password == "behappy"
18
+ u = User.new
19
+ u.login = login
20
+ u.name = login.humanize
21
+ u.groups = [Group.new('name' => login)]
22
+ u
23
+ end
24
+ end
25
+ end
26
+ User.include_root_in_json = false
27
+ User
@@ -1,11 +1,22 @@
1
1
  package <%= activities_package %>;
2
- <% unless options[:singleton] -%>
2
+ <% if !options[:singleton] || attributes.detect { |a| a.type == :belongs_to} -%>
3
3
 
4
4
  import java.util.List;
5
5
  <% end -%>
6
6
 
7
+ import <%= events_package %>.<%= class_name %>Event;
8
+ <% for attribute in attributes -%>
9
+ <% if attribute.type == :belongs_to -%>
10
+ import <%= models_package %>.<%= attribute.name.classify %>;
11
+ <% end -%>
12
+ <% end -%>
7
13
  import <%= models_package %>.<%= class_name %>;
8
14
  import <%= places_package %>.<%= class_name %>Place;
15
+ <% for attribute in attributes -%>
16
+ <% if attribute.type == :belongs_to -%>
17
+ import <%= restservices_package %>.<%= attribute.name.classify.to_s.pluralize %>RestService;
18
+ <% end -%>
19
+ <% end -%>
9
20
  import <%= restservices_package %>.<%= class_name.pluralize %>RestService;
10
21
  import <%= views_package %>.<%= class_name %>View;
11
22
 
@@ -21,6 +32,7 @@ import com.google.inject.Inject;
21
32
  import com.google.inject.assistedinject.Assisted;
22
33
 
23
34
  import <%= gwt_rails_package %>.Notice;
35
+ import <%= gwt_rails_package %>.events.ModelEvent.Action;
24
36
  <% unless options[:singleton] -%>
25
37
  import <%= gwt_rails_package %>.places.RestfulActionEnum;
26
38
  <% end -%>
@@ -32,18 +44,38 @@ public class <%= class_name %>Activity extends AbstractActivity implements <%= c
32
44
  private final Notice notice;
33
45
  private final PlaceController placeController;
34
46
  private final <%= class_name %>View view;
47
+ private EventBus eventBus;
35
48
 
36
49
  @Inject
37
- public <%= class_name %>Activity(@Assisted <%= class_name %>Place place, Notice notice, <%= class_name %>View view,
38
- <%= class_name.pluralize %>RestService service, PlaceController placeController) {
50
+ public <%= class_name %>Activity(@Assisted <%= class_name %>Place place, final Notice notice, final <%= class_name %>View view,
51
+ <%= class_name.pluralize %>RestService service, PlaceController placeController<% for attribute in attributes -%>
52
+ <% if attribute.type == :belongs_to -%>
53
+ , <%= attribute.name.classify.to_s.pluralize %>RestService <%= attribute.name %>RestService<% end -%><% end -%>) {
39
54
  this.place = place;
40
55
  this.notice = notice;
41
56
  this.view = view;
42
57
  this.service = service;
43
58
  this.placeController = placeController;
59
+ <% for attribute in attributes -%>
60
+ <% if attribute.type == :belongs_to -%>
61
+
62
+ view.reset<%= attribute.name.classify.to_s.pluralize %>(null);
63
+ <%= attribute.name %>RestService.index(new MethodCallback<List<<%= attribute.name.classify %>>>() {
64
+
65
+ public void onSuccess(Method method, List<<%= attribute.name.classify %>> response) {
66
+ view.reset<%= attribute.name.classify.to_s.pluralize %>(response);
67
+ }
68
+
69
+ public void onFailure(Method method, Throwable exception) {
70
+ notice.setText("failed to load <%= attribute.name.pluralize %>");
71
+ }
72
+ });
73
+ <% end -%>
74
+ <% end -%>
44
75
  }
45
76
 
46
77
  public void start(AcceptsOneWidget display, EventBus eventBus) {
78
+ this.eventBus = eventBus;
47
79
  display.setWidget(view.asWidget());
48
80
  view.setPresenter(this);
49
81
  <% if options[:singleton] -%>
@@ -52,11 +84,11 @@ public class <%= class_name %>Activity extends AbstractActivity implements <%= c
52
84
  switch(RestfulActionEnum.valueOf(place.action.name())){
53
85
  case EDIT:
54
86
  case SHOW:
55
- load(place.model == null ? place.id : place.model.id);
87
+ load(place.model == null ? place.id : place.model.getId());
56
88
  break;
57
89
  case NEW:
58
90
  notice.setText(null);
59
- view.reset(new <%= class_name %>());
91
+ view.edit(new <%= class_name %>());
60
92
  break;
61
93
  case INDEX:
62
94
  default:
@@ -83,8 +115,9 @@ public class <%= class_name %>Activity extends AbstractActivity implements <%= c
83
115
  }
84
116
 
85
117
  public void onSuccess(Method method, List<<%= class_name %>> response) {
86
- view.reset(response);
118
+ eventBus.fireEvent(new <%= class_name %>Event(response, Action.LOAD));
87
119
  notice.setText(null);
120
+ view.reset(response);
88
121
  view.reset(place.action);
89
122
  }
90
123
  });
@@ -93,6 +126,29 @@ public class <%= class_name %>Activity extends AbstractActivity implements <%= c
93
126
  }
94
127
  }
95
128
  <% end -%>
129
+ <% unless options[:singleton] -%>
130
+
131
+ public void create() {
132
+ <%= class_name %> model = view.flush();
133
+ view.setEnabled(false);
134
+ service.create(model<% if attributes.detect{|a| a.type == :belongs_to} -%>.minimalClone()<% end -%>, new MethodCallback<<%= class_name %>>() {
135
+
136
+ public void onFailure(Method method, Throwable exception) {
137
+ notice.setText("error creating <%= class_name.underscore.humanize %>: "
138
+ + exception.getMessage());
139
+ view.reset(place.action);
140
+ }
141
+
142
+ public void onSuccess(Method method, <%= class_name %> response) {
143
+ eventBus.fireEvent(new <%= class_name %>Event(response, Action.CREATE));
144
+ notice.setText(null);
145
+ view.addToList(response);
146
+ goTo(new <%= class_name %>Place(response.getId(), RestfulActionEnum.EDIT));
147
+ }
148
+ });
149
+ notice.setText("creating <%= class_name.underscore.humanize %> . . .");
150
+ }
151
+ <% end -%>
96
152
 
97
153
  public void load(<% unless options[:singleton] -%>int id<% end -%>) {
98
154
  view.setEnabled(false);
@@ -105,8 +161,9 @@ public class <%= class_name %>Activity extends AbstractActivity implements <%= c
105
161
  }
106
162
 
107
163
  public void onSuccess(Method method, <%= class_name %> response) {
164
+ eventBus.fireEvent(new <%= class_name %>Event(response, Action.LOAD));
108
165
  notice.setText(null);
109
- view.reset(response);
166
+ view.edit(response);
110
167
  view.reset(place.action);
111
168
  }
112
169
  });
@@ -114,27 +171,31 @@ public class <%= class_name %>Activity extends AbstractActivity implements <%= c
114
171
  notice.setText("loading <%= class_name.underscore.humanize %> . . .");
115
172
  }
116
173
  }
117
- <% unless options[:singleton] -%>
118
- public void create() {
119
- <%= class_name %> model = view.retrieve<%= class_name %>();
174
+
175
+ public void save() {
176
+ <%= class_name %> model = view.flush();
120
177
  view.setEnabled(false);
121
- service.create(model, new MethodCallback<<%= class_name %>>() {
178
+ service.update(model<% if attributes.detect{|a| a.type == :belongs_to} -%>.minimalClone()<% end -%>, new MethodCallback<<%= class_name %>>() {
122
179
 
123
180
  public void onFailure(Method method, Throwable exception) {
124
- notice.setText("error creating <%= class_name.underscore.humanize %>: "
181
+ notice.setText("error saving <%= class_name.underscore.humanize %>: "
125
182
  + exception.getMessage());
126
183
  view.reset(place.action);
127
184
  }
128
185
 
129
186
  public void onSuccess(Method method, <%= class_name %> response) {
187
+ eventBus.fireEvent(new <%= class_name %>Event(response, Action.UPDATE));
130
188
  notice.setText(null);
131
- view.addToList(response);
132
- goTo(new <%= class_name %>Place(response.id,
133
- RestfulActionEnum.EDIT));
189
+ <% unless options[:singleton] -%>
190
+ view.updateInList(response);
191
+ <% end -%>
192
+ view.edit(response);
193
+ view.reset(place.action);
134
194
  }
135
195
  });
136
- notice.setText("creating <%= class_name.underscore.humanize %> . . .");
196
+ notice.setText("saving <%= class_name.underscore.humanize %> . . .");
137
197
  }
198
+ <% unless options[:singleton] -%>
138
199
 
139
200
  public void delete(final <%= class_name %> model){
140
201
  view.setEnabled(false);
@@ -147,6 +208,7 @@ public class <%= class_name %>Activity extends AbstractActivity implements <%= c
147
208
  }
148
209
 
149
210
  public void onSuccess(Method method, Void response) {
211
+ eventBus.fireEvent(new <%= class_name %>Event(model, Action.DESTROY));
150
212
  notice.setText(null);
151
213
  view.removeFromList(model);
152
214
  <%= class_name %>Place next = new <%= class_name %>Place(RestfulActionEnum.INDEX);
@@ -161,27 +223,4 @@ public class <%= class_name %>Activity extends AbstractActivity implements <%= c
161
223
  notice.setText("deleting <%= class_name.underscore.humanize %> . . .");
162
224
  }
163
225
  <% end -%>
164
-
165
- public void save() {
166
- <%= class_name %> model = view.retrieve<%= class_name %>();
167
- view.setEnabled(false);
168
- service.update(model, new MethodCallback<<%= class_name %>>() {
169
-
170
- public void onFailure(Method method, Throwable exception) {
171
- notice.setText("error saving <%= class_name.underscore.humanize %>: "
172
- + exception.getMessage());
173
- view.reset(place.action);
174
- }
175
-
176
- public void onSuccess(Method method, <%= class_name %> response) {
177
- notice.setText(null);
178
- <% unless options[:singleton] -%>
179
- view.updateInList(response);
180
- <% end -%>
181
- view.reset(response);
182
- view.reset(place.action);
183
- }
184
- });
185
- notice.setText("saving <%= class_name.underscore.humanize %> . . .");
186
- }
187
226
  }
@@ -0,0 +1,67 @@
1
+ package <%= activities_package %>;
2
+
3
+ import java.util.List;
4
+
5
+ import <%= models_package %>.<%= class_name %>;
6
+ import <%= places_package %>.<%= class_name %>Place;
7
+ import <%= restservices_package %>.<%= class_name.pluralize %>RestService;
8
+ import <%= views_package %>.<%= class_name %>View;
9
+
10
+ import <%= gwt_rails_package %>.Notice;
11
+
12
+ import org.fusesource.restygwt.client.Method;
13
+ import org.fusesource.restygwt.client.MethodCallback;
14
+
15
+ import com.google.gwt.activity.shared.AbstractActivity;
16
+ import com.google.gwt.event.shared.EventBus;
17
+ import com.google.gwt.place.shared.Place;
18
+ import com.google.gwt.place.shared.PlaceController;
19
+ import com.google.gwt.user.client.Window;
20
+ import com.google.gwt.user.client.ui.AcceptsOneWidget;
21
+ import com.google.inject.Inject;
22
+ import com.google.inject.assistedinject.Assisted;
23
+
24
+ public class <%= class_name %>Activity extends AbstractActivity implements <%= class_name %>View.Presenter{
25
+
26
+ private final <%= class_name %>Place place;
27
+ private final <%= class_name.pluralize %>RestService service;
28
+ private final Notice notice;
29
+ private final PlaceController placeController;
30
+ private final <%= class_name %>View view;
31
+
32
+ @Inject
33
+ public <%= class_name %>Activity(@Assisted <%= class_name %>Place place, Notice notice, <%= class_name %>View view,
34
+ <%= class_name.pluralize %>RestService service, PlaceController placeController) {
35
+ this.place = place;
36
+ this.notice = notice;
37
+ this.view = view;
38
+ this.service = service;
39
+ this.placeController = placeController;
40
+ }
41
+
42
+ public void start(AcceptsOneWidget display, EventBus eventBus) {
43
+ display.setWidget(view.asWidget());
44
+ view.setPresenter(this);
45
+ notice.setText("loading <%= table_name %> . . .");
46
+ service.index(new MethodCallback<List<<%= class_name %>>>() {
47
+
48
+ public void onFailure(Method method, Throwable exception) {
49
+ notice.setText("error loading <%= table_name %>: "
50
+ + exception.getMessage());
51
+ }
52
+
53
+ public void onSuccess(Method method, List<<%= class_name %>> response) {
54
+ notice.setText(null);
55
+ view.reset(response);
56
+ }
57
+ });
58
+ }
59
+
60
+ public void goTo(Place place) {
61
+ placeController.goTo(place);
62
+ }
63
+
64
+ public void onItemClicked(<%= class_name %> model) {
65
+ Window.alert("TODO");
66
+ }
67
+ }
@@ -0,0 +1,11 @@
1
+ package org.dhamma.schedules.client.lib;
2
+
3
+ import org.dhamma.schedules.client.managed.ActivityFactory;
4
+
5
+ import com.google.gwt.activity.shared.Activity;
6
+ import com.google.gwt.place.shared.Place;
7
+
8
+ public abstract class ActivityPlace extends Place {
9
+
10
+ public abstract Activity create(ActivityFactory factory);
11
+ }