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
@@ -0,0 +1,20 @@
1
+ package <%= places_package %>;
2
+
3
+ import org.dhamma.schedules.client.ActivityPlace;
4
+ import org.dhamma.schedules.client.managed.ActivityFactory;
5
+
6
+ import com.google.gwt.activity.shared.Activity;
7
+
8
+ public class LoginPlace extends ActivityPlace {
9
+
10
+ public static final LoginPlace LOGIN = new LoginPlace();
11
+
12
+ private LoginPlace() {
13
+ super(null);
14
+ }
15
+
16
+ @Override
17
+ public Activity create(ActivityFactory factory) {
18
+ return factory.create(this);
19
+ }
20
+ }
@@ -0,0 +1,21 @@
1
+ package <%= views_package %>;
2
+
3
+ import com.google.gwt.core.client.GWT;
4
+ import com.google.gwt.uibinder.client.UiBinder;
5
+ import com.google.gwt.uibinder.client.UiTemplate;
6
+ import com.google.gwt.user.client.ui.Widget;
7
+ import com.google.inject.Singleton;
8
+
9
+ @Singleton
10
+ public class LoginViewImpl extends de.mkristian.gwt.rails.session.LoginViewImpl {
11
+
12
+ @UiTemplate("LoginView.ui.xml")
13
+ interface LoginViewUiBinder extends UiBinder<Widget, de.mkristian.gwt.rails.session.LoginViewImpl> {}
14
+
15
+ private static LoginViewUiBinder uiBinder = GWT.create(LoginViewUiBinder.class);
16
+
17
+ public LoginViewImpl() {
18
+ super(uiBinder);
19
+ }
20
+
21
+ }
@@ -1,10 +1,12 @@
1
1
  #-*- mode: ruby -*-
2
- GWT_VERSION = '2.3.0'
3
- jar('org.fusesource.restygwt:restygwt', '1.2-SNAPSHOT').scope :provided
2
+ GWT_VERSION = '2.4.0'
3
+ jar('de.mkristian.gwt:rails-gwt', '0.6.0').scope :provided
4
+ jar('org.fusesource.restygwt:restygwt', '1.2').scope :provided
4
5
  jar('javax.ws.rs:jsr311-api', '1.1').scope :provided
5
6
  jar('com.google.gwt:gwt-user', GWT_VERSION).scope :provided
6
7
  jar('com.google.gwt.inject:gin', '1.5.0').scope :provided
7
- jar('de.mkristian.rails-gwt:rails-gwt', '0.2.1-SNAPSHOT').scope :provided
8
+ jar('javax.validation:validation-api', '1.0.0.GA').scope :provided
9
+ jar('javax.validation:validation-api', '1.0.0.GA', 'sources').scope :provided
8
10
 
9
11
  plugin('org.codehaus.mojo:gwt-maven-plugin', GWT_VERSION) do |gwt|
10
12
  gwt.with({ :warSourceDirectory => "${basedir}/public",
@@ -28,6 +30,4 @@ profile("mac") do |mac|
28
30
  mac.activation.os.family "mac"
29
31
  mac.plugin('org.codehaus.mojo:gwt-maven-plugin').with(:extraJvmArgs => "-d32 -XstartOnFirstThread -Xmx512m")
30
32
  end
31
-
32
- repository(:snapshots).url "http://mojo.saumya.de"
33
33
  # vim: syntax=Ruby
@@ -0,0 +1,15 @@
1
+ plugin('org.codehaus.mojo.gwt-maven-plugin', '2.1.0') do |gwt|
2
+ gwt.with({ :logLevel => "INFO",
3
+ :style => "DETAILED",
4
+ :treeLogger => true,
5
+ :extraJvmArgs => "-Xmx512m",
6
+ :runTarget => "<%= application_name.underscore %>/<%= application_name.underscore %>.html",
7
+ :includes => "**/<%= application_name %>GWTTestSuite.java"
8
+ })
9
+ gwt.execute.goals << ["clean", "compile", "test"]
10
+ end
11
+ #-- Macs need the -d32 -XstartOnFirstThread jvm options -->
12
+ profile("mac") do |mac|
13
+ mac.activation << "<os><family>mac</family></os>"
14
+ plugin('org.codehaus.mojo.gwt-maven-plugin').with(:extraJvmArgs => "-d32 -XstartOnFirstThread -Xmx512m")
15
+ end
@@ -0,0 +1,12 @@
1
+ package <%= managed_package %>;
2
+
3
+ import javax.inject.Inject;
4
+
5
+ import <%= gwt_rails_package %>.places.RestfulPlaceHistoryMapper;
6
+
7
+ public class <%= application_name %>PlaceHistoryMapper extends RestfulPlaceHistoryMapper {
8
+
9
+ @Inject
10
+ public <%= application_name %>PlaceHistoryMapper(){
11
+ }
12
+ }
@@ -0,0 +1,7 @@
1
+ package <%= base_package %>.managed;
2
+
3
+ import com.google.gwt.activity.shared.Activity;
4
+ import com.google.inject.name.Named;
5
+
6
+ public interface ActivityFactory {
7
+ }
@@ -0,0 +1,22 @@
1
+ package <%= managed_package %>;
2
+
3
+ public abstract class RestfulPlace<T> extends ActivityPlace {
4
+
5
+ public final RestfulAction action;
6
+
7
+ private T resource;
8
+
9
+ public RestfulPlace(RestfulAction restfulActionEnum) {
10
+ this.action = restfulActionEnum;
11
+ }
12
+
13
+ public void setResource(T resource) {
14
+ if (this.resource == null) {
15
+ this.resource = resource;
16
+ }
17
+ }
18
+
19
+ public T getResource() {
20
+ return resource;
21
+ }
22
+ }
@@ -0,0 +1,71 @@
1
+ package org.dhamma.schedules.client;
2
+
3
+ import javax.inject.Inject;
4
+
5
+ import org.dhamma.schedules.client.managed.ActivityFactory;
6
+ import org.dhamma.schedules.client.models.User;
7
+ import org.dhamma.schedules.client.places.LoginPlace;
8
+
9
+ import com.google.gwt.activity.shared.Activity;
10
+ import com.google.gwt.place.shared.Place;
11
+
12
+ import de.mkristian.gwt.rails.Notice;
13
+ import de.mkristian.gwt.rails.RestfulPlace;
14
+ import de.mkristian.gwt.rails.session.NeedsAuthorization;
15
+ import de.mkristian.gwt.rails.session.NoAuthorization;
16
+ import de.mkristian.gwt.rails.session.SessionManager;
17
+
18
+ public class SessionActivityPlaceActivityMapper extends ActivityPlaceActivityMapper {
19
+
20
+ private final SessionManager<User> manager;
21
+
22
+ @Inject
23
+ public SessionActivityPlaceActivityMapper(ActivityFactory factory, SessionManager<User> manager, Notice notice) {
24
+ super(factory, notice);
25
+ this.manager = manager;
26
+ }
27
+
28
+ public Activity getActivity(Place place) {
29
+ return pessimisticGetActivity(place);
30
+ }
31
+
32
+ /**
33
+ * pessimistic in the sense that default is authorisation, only the places
34
+ * which implements {@link NoAuthorization} will be omitted by the check.
35
+ */
36
+ protected Activity pessimisticGetActivity(Place place) {
37
+ if (!(place instanceof NoAuthorization)) {
38
+ if(manager.isActive()){
39
+ if(!manager.isAllowed((RestfulPlace)place)){
40
+ notice.setText("nothing to see");
41
+ return null;
42
+ }
43
+ //TODO move into dispatch filter
44
+ manager.resetTimer();
45
+ }
46
+ else {
47
+ return LoginPlace.LOGIN.create(factory);
48
+ }
49
+ }
50
+ return super.getActivity(place);
51
+ }
52
+
53
+ /**
54
+ * optimistic in the sense that default is no authorisation, only the places
55
+ * which implements {@link NeedsAuthorization} will be checked.
56
+ */
57
+ protected Activity optimisticGetActivity(Place place) {
58
+ if (place instanceof NeedsAuthorization) {
59
+ if(manager.isActive()){
60
+ if(!manager.isAllowed((RestfulPlace)place)){
61
+ notice.setText("nothing to see");
62
+ return null;
63
+ }
64
+ }
65
+ else {
66
+ return LoginPlace.LOGIN.create(factory);
67
+ }
68
+ }
69
+ return super.getActivity(place);
70
+ }
71
+ }
@@ -0,0 +1,23 @@
1
+ package <%= restservices_package %>;
2
+
3
+ import javax.ws.rs.DELETE;
4
+ import javax.ws.rs.POST;
5
+ import javax.ws.rs.Path;
6
+
7
+ import <%= models_package %>.User;
8
+
9
+ import org.fusesource.restygwt.client.MethodCallback;
10
+ import org.fusesource.restygwt.client.RestService;
11
+
12
+ import de.mkristian.gwt.rails.session.Authentication;
13
+ import de.mkristian.gwt.rails.session.Session;
14
+
15
+ @Path("/session")
16
+ public interface SessionRestService extends RestService {
17
+
18
+ @POST
19
+ void create(Authentication authentication, MethodCallback<Session<User>> callback);
20
+
21
+ @DELETE
22
+ void destroy(MethodCallback<Void> callback);
23
+ }
@@ -1,12 +1,42 @@
1
1
  package <%= models_package %>;
2
2
 
3
+ import org.codehaus.jackson.annotate.JsonCreator;
4
+ import org.codehaus.jackson.annotate.JsonProperty;
5
+
3
6
  import org.fusesource.restygwt.client.Json;
4
7
  import org.fusesource.restygwt.client.Json.Style;
5
8
 
9
+ import <%= gwt_rails_package %>.models.IsUser;
10
+
6
11
  @Json(style = Style.RAILS)
7
- public class User {
12
+ public class User implements IsUser {
13
+
14
+ private String login;
15
+
16
+ private String name;
17
+
18
+ @JsonCreator
19
+ public User(@JsonProperty("login") String login,
20
+ @JsonProperty("name") String name){
21
+ this.login = login;
22
+ this.name = name;
23
+ }
24
+
25
+ public String getLogin(){
26
+ return login;
27
+ }
28
+
29
+ public String getName(){
30
+ return name;
31
+ }
32
+
33
+ public int hashCode(){
34
+ return login.hashCode();
35
+ }
8
36
 
9
- public String login;
37
+ public boolean equals(Object other){
38
+ return (other instanceof User) &&
39
+ ((User)other).login == login;
40
+ }
10
41
 
11
- public String name;
12
- }
42
+ }
@@ -1,3 +1,4 @@
1
1
  class Authentication < ActiveResource::Base
2
- self.site = Rails.application.config.remote_sso_url if Rails.application.config.respond_to? :remote_sso_url
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'
3
4
  end
@@ -0,0 +1,4 @@
1
+ class Authentication < ActiveResource::Base
2
+ self.site = Rails.application.config.remote_sso_url
3
+
4
+ end
@@ -15,3 +15,48 @@
15
15
  top:3em;
16
16
  opacity:.9;
17
17
  }
18
+ .gwt-rails-breadcrumbs *
19
+ {
20
+ float: right;
21
+ display: inline;
22
+ }
23
+ .gwt-rails-breadcrumbs *
24
+ {
25
+ margin-left: 1em;
26
+ }
27
+ .gwt-rails-menu *
28
+ {
29
+ float: left;
30
+ display: inline;
31
+ }
32
+ .gwt-rails-display, .gwt-rails-model-signature, .gwt-rails-model-fields
33
+ {
34
+ clear: both;
35
+ }
36
+ .gwt-rails-model-signature *
37
+ {
38
+ font-size: 0.7em;
39
+ float: left;
40
+ display: inline;
41
+ margin-right: .3em;
42
+ }
43
+ .gwt-rails-model-signature span
44
+ {
45
+ margin-right: 1em;
46
+ }
47
+ .gwt-rails-model-fields > div > *
48
+ {
49
+ display: block;
50
+ }
51
+ .gwt-rails-model-signature, .gwt-rails-buttons, .gwt-rails-display
52
+ {
53
+ margin-top: .3em;
54
+ }
55
+ .gwt-rails-model-fields .gwt-TextBox, .gwt-rails-model-fields .gwt-TextArea
56
+ {
57
+ width: 30%;
58
+ }
59
+ .gwt-rails-model-fields .gwt-TextArea
60
+ {
61
+ height: 6em;
62
+ }
@@ -0,0 +1 @@
1
+ Rails.application.config.middleware.use Resty::ChildPath <%= application_name.under_score %>
@@ -0,0 +1,27 @@
1
+ require 'action_dispatch/http/request'
2
+ require 'active_support/core_ext/hash/indifferent_access'
3
+
4
+ module ActionDispatch
5
+ class ParamsParser
6
+
7
+ alias :call_old :call
8
+ def call(env)
9
+ request = Request.new(env)
10
+ mime_type = content_type_from_legacy_post_data_format_header(env) ||
11
+ request.content_mime_type
12
+
13
+ case mime_type
14
+ when Mime::JSON
15
+ data = ActiveSupport::JSON.decode(request.body)
16
+ request.body.rewind if request.body.respond_to?(:rewind)
17
+ data = {:_json => data} unless data.is_a?(Hash)
18
+ env["action_dispatch.request.request_parameters"] = {:json => data}.with_indifferent_access
19
+
20
+ @app.call(env)
21
+ else
22
+ call_old(env)
23
+ end
24
+ end
25
+ end
26
+ end
27
+ #TODO under_score the keys and use :<controller-name> instead of generic :json and put the whole thing into resty-generators
@@ -1,43 +1,25 @@
1
- class Session
1
+ require 'ixtlan/guard/abstract_session'
2
+
3
+ class Session < Ixtlan::Guard::AbstractSession
2
4
  include ActiveModel::Serializers::JSON
3
5
  include ActiveModel::Serializers::Xml
4
6
 
5
- attr_accessor :permissions, :user
6
-
7
- def self.create(params = {})
8
- if Rails.application.config.respond_to? :remote_sso_url
9
- begin
10
- a = Authentication.create(:login => params[:login],
11
- :password => params[:password])
12
- result = new
13
- user = User.new
14
- user.login = a.login
15
- user.name = a.name
16
- user.groups = a.groups
17
- result.user = user
18
- result
19
- rescue ActiveResource::ResourceNotFound
20
- nil
21
- end
22
- else
23
- user = User.authenticate(params[:login], params[:password])
24
- if user
25
- result = new
26
- result.user = user
27
- result
28
- end
29
- end
30
- end
31
-
32
- def idle_session_timeout
33
- Rails.application.config.idle_session_timeout
34
- end
35
-
36
- def attributes
37
- {'idle_session_timeout' => idle_session_timeout, 'permissions' => permissions, 'user' => user}
7
+ def self.authenticate(login, password)
8
+ User.authenticate(login, password)
38
9
  end
39
10
 
40
- def id
41
- ""
11
+ def self.authenticate_remote(login, password)
12
+ begin
13
+ auth = Authentication.create(:login => login, :password => password)
14
+ user = User.new
15
+ user.login = auth.login
16
+ user.name = auth.name
17
+ user.groups = auth.groups
18
+ user
19
+ rescue ActiveResource::ResourceNotFound
20
+ result = User.new
21
+ result.log = "access denied #{login}" # error message
22
+ result
23
+ end
42
24
  end
43
25
  end
@@ -0,0 +1,45 @@
1
+ class Session
2
+ include ActiveModel::Serializers::JSON
3
+ include ActiveModel::Serializers::Xml
4
+
5
+ attr_accessor :permissions, :user
6
+
7
+ def self.create(params = {})
8
+ if Rails.application.config.respond_to? :remote_sso_url
9
+ begin
10
+ a = Authentication.create(:login => params[:login],
11
+ :password => params[:password])
12
+ result = new
13
+ user = User.new
14
+ user.login = a.login
15
+ user.name = a.name
16
+ user.groups = a.groups
17
+ result.user = user
18
+ result
19
+ rescue ActiveResource::ResourceNotFound
20
+ nil
21
+ end
22
+ else
23
+ user = User.authenticate(params[:login], params[:password])
24
+ if user
25
+ result = new
26
+ result.user = user
27
+ result
28
+ end
29
+ end
30
+ end
31
+
32
+ def idle_session_timeout
33
+ Configuration.instance.idle_session_timeout
34
+ end
35
+
36
+ def attributes
37
+ {'idle_session_timeout' => idle_session_timeout, 'permissions' => permissions, 'user' => user}
38
+ end
39
+
40
+ def id
41
+ ""
42
+ end
43
+ end
44
+ Session.include_root_in_json = false
45
+ Session