Skip to content

Commit

Permalink
Merge pull request #467 from ArcBees/cv_dispatch_interoperability
Browse files Browse the repository at this point in the history
Rest/Rpc dispatch interoperability
  • Loading branch information
meriouma committed Jul 30, 2014
2 parents cfad85a + ed3f510 commit 6e33a2f
Show file tree
Hide file tree
Showing 35 changed files with 399 additions and 238 deletions.
20 changes: 20 additions & 0 deletions gwtp-carstore/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<description>Simple application used for testing GWTP features.</description>

<properties>
<target.jdk>1.7</target.jdk>
<webappDirectory>${project.build.directory}/${project.build.finalName}</webappDirectory>
<gae.home>
${settings.localRepository}/com/google/appengine/appengine-java-sdk/${gae.version}/appengine-java-sdk-${gae.version}
Expand All @@ -25,8 +26,11 @@
<gae.port>8888</gae.port>
<gae.address>127.0.0.1</gae.address>

<slf4j-api.version>1.7.7</slf4j-api.version>
<resteasy.version>3.0.8.Final</resteasy.version>
<arcbees.version>1.1.1</arcbees.version>

<objectify-gwt.version>1.0</objectify-gwt.version>
</properties>

<build>
Expand Down Expand Up @@ -133,12 +137,23 @@
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>gwtp-dispatch-rpc-client</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>gwtp-dispatch-rest</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>gwtp-dispatch-rpc-server-guice</artifactId>
<version>${project.version}</version>
</dependency>

<!-- GWT -->
<dependency>
Expand Down Expand Up @@ -229,6 +244,11 @@
<artifactId>objectify</artifactId>
<version>${objectify.version}</version>
</dependency>
<dependency>
<groupId>com.googlecode.objectify</groupId>
<artifactId>objectify-gwt</artifactId>
<version>${objectify-gwt.version}</version>
</dependency>
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,12 @@
import com.gwtplatform.carstore.client.place.NameTokens;
import com.gwtplatform.carstore.client.place.ParameterTokens;
import com.gwtplatform.carstore.client.resources.LoginMessages;
import com.gwtplatform.carstore.client.rest.SessionService;
import com.gwtplatform.carstore.client.security.CurrentUser;
import com.gwtplatform.carstore.shared.dispatch.LogInRequest;
import com.gwtplatform.carstore.shared.dispatch.ActionType;
import com.gwtplatform.carstore.shared.dispatch.LogInAction;
import com.gwtplatform.carstore.shared.dispatch.LogInResult;
import com.gwtplatform.carstore.shared.dto.ActionType;
import com.gwtplatform.carstore.shared.dto.CurrentUserDto;
import com.gwtplatform.dispatch.rest.shared.RestDispatch;
import com.gwtplatform.dispatch.rpc.shared.DispatchAsync;
import com.gwtplatform.mvp.client.HasUiHandlers;
import com.gwtplatform.mvp.client.Presenter;
import com.gwtplatform.mvp.client.View;
Expand Down Expand Up @@ -69,9 +68,9 @@ interface MyProxy extends ProxyPlace<LoginPresenter> {
public static final String LOGIN_COOKIE_NAME = "LoggedInCookie";

private static final Logger logger = Logger.getLogger(LoginPresenter.class.getName());

private final PlaceManager placeManager;
private final RestDispatch dispatchAsync;
private final SessionService sessionService;
private final DispatchAsync dispatcher;
private final CurrentUser currentUser;
private final LoginMessages messages;

Expand All @@ -80,15 +79,13 @@ interface MyProxy extends ProxyPlace<LoginPresenter> {
MyView view,
MyProxy proxy,
PlaceManager placeManager,
RestDispatch dispatchAsync,
SessionService sessionService,
DispatchAsync dispatcher,
CurrentUser currentUser,
LoginMessages messages) {
super(eventBus, view, proxy, RevealType.RootLayout);

this.placeManager = placeManager;
this.dispatchAsync = dispatchAsync;
this.sessionService = sessionService;
this.dispatcher = dispatcher;
this.currentUser = currentUser;
this.messages = messages;

Expand All @@ -97,8 +94,8 @@ interface MyProxy extends ProxyPlace<LoginPresenter> {

@Override
public void login(String username, String password) {
LogInRequest loginRequest = new LogInRequest(username, password);
callServerLoginAction(loginRequest);
LogInAction logInAction = new LogInAction(username, password);
callServerLoginAction(logInAction);
}

@Override
Expand All @@ -110,8 +107,8 @@ protected void onReveal() {
}
}

private void callServerLoginAction(LogInRequest loginRequest) {
dispatchAsync.execute(sessionService.login(loginRequest), new AsyncCallback<LogInResult>() {
private void callServerLoginAction(LogInAction logInAction) {
dispatcher.execute(logInAction, new AsyncCallback<LogInResult>() {
@Override
public void onFailure(Throwable e) {
DisplayMessageEvent.fire(LoginPresenter.this, new Message(messages.unableToContactServer(),
Expand Down Expand Up @@ -190,8 +187,8 @@ private String getDomain() {

private void tryLoggingInWithCookieFirst() {
getView().setLoginButtonEnabled(false);
LogInRequest loginRequest = new LogInRequest(getLoggedInCookie());
callServerLoginAction(loginRequest);
LogInAction logInAction = new LogInAction(getLoggedInCookie());
callServerLoginAction(logInAction);
}

private String getLoggedInCookie() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ interface MyProxy extends ProxyPlace<StatisticsPresenter> {
}

@Override
@SuppressWarnings("deprecation")
public void extractYear(final Date date) {
getView().setResult("");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.gwtplatform.carstore.client.place.NameTokens;
import com.gwtplatform.carstore.client.security.SecurityModule;
import com.gwtplatform.dispatch.rest.client.gin.RestDispatchAsyncModule;
import com.gwtplatform.dispatch.rpc.client.gin.RpcDispatchAsyncModule;
import com.gwtplatform.mvp.client.annotations.DefaultPlace;
import com.gwtplatform.mvp.client.annotations.ErrorPlace;
import com.gwtplatform.mvp.client.annotations.UnauthorizedPlace;
Expand All @@ -31,6 +32,7 @@ protected void configure() {
install(new DefaultModule());
install(new SecurityModule());
install(new RestDispatchAsyncModule());
install(new RpcDispatchAsyncModule());

// DefaultPlaceManager Places
bindConstant().annotatedWith(DefaultPlace.class).to(NameTokens.LOGIN);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,8 @@

import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;

import com.gwtplatform.carstore.shared.dispatch.LogInRequest;
import com.gwtplatform.carstore.shared.dispatch.LogInResult;
import com.gwtplatform.carstore.shared.dto.CurrentUserDto;
import com.gwtplatform.dispatch.rest.shared.RestAction;

Expand All @@ -35,7 +32,4 @@ public interface SessionService {

@GET
RestAction<CurrentUserDto> getCurrentUser();

@POST
RestAction<LogInResult> login(LogInRequest logInRequest);
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,16 @@
import java.util.List;
import java.util.Map;

import javax.inject.Inject;

import com.google.common.collect.Lists;
import com.googlecode.objectify.Key;
import com.googlecode.objectify.cmd.LoadType;
import com.gwtplatform.carstore.server.dao.objectify.Ofy;
import com.gwtplatform.carstore.server.dao.objectify.OfyFactory;
import com.gwtplatform.carstore.server.dao.objectify.OfyService;
import com.gwtplatform.carstore.shared.dto.Dto;

public class BaseDao<T extends Dto> {
private final Class<T> clazz;

@Inject
OfyFactory ofyFactory;

private Ofy lazyOfy;

protected BaseDao(final Class<T> clazz) {
this.clazz = clazz;
}
Expand Down Expand Up @@ -93,7 +86,7 @@ public void delete(Long id) {
public void delete(List<T> objects) {
ofy().delete().entities(objects);
}

public void deleteAll() {
List<T> entities = getAll();
ofy().delete().entities(entities);
Expand All @@ -102,20 +95,17 @@ public void deleteAll() {
public List<T> get(List<Key<T>> keys) {
return Lists.newArrayList(ofy().load().keys(keys).values());
}

public int countAll() {
return ofy().load().type(clazz).count();
}

public List<T> getSome(Integer offset, Integer limit) {
return ofy().query(clazz).offset(offset).limit(limit).list();
}

protected Ofy ofy() {
if (lazyOfy == null) {
lazyOfy = ofyFactory.begin();
}
return lazyOfy;
return OfyService.ofy();
}

protected LoadType<T> query() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
package com.gwtplatform.carstore.server.dao.objectify;

import com.googlecode.objectify.Key;
import com.googlecode.objectify.Objectify;
import com.googlecode.objectify.ObjectifyFactory;
import com.googlecode.objectify.cmd.LoadType;
import com.googlecode.objectify.util.cmd.ObjectifyWrapper;
import com.googlecode.objectify.impl.ObjectifyImpl;

public class Ofy extends ObjectifyWrapper<Ofy, OfyFactory> {
public Ofy(Objectify base) {
super(base);
public class Ofy extends ObjectifyImpl<Ofy> {
public Ofy(ObjectifyFactory factory) {
super(factory);
}

public <T> LoadType<T> query(Class<T> clazz) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,12 @@

package com.gwtplatform.carstore.server.dao.objectify;

import com.googlecode.objectify.Objectify;
import com.googlecode.objectify.ObjectifyFactory;

import static com.gwtplatform.carstore.server.dao.objectify.OfyService.ofy;

public class OfyFactory extends ObjectifyFactory {
public OfyFactory() {
}

@Override
public Ofy begin() {
return new Ofy(ofy());
public Objectify begin() {
return new Ofy(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package com.gwtplatform.carstore.server.dao.objectify;

import com.googlecode.objectify.Objectify;
import com.googlecode.objectify.ObjectifyFactory;
import com.googlecode.objectify.ObjectifyService;
import com.gwtplatform.carstore.server.dao.domain.Car;
Expand All @@ -28,6 +27,7 @@

public class OfyService {
static {
ObjectifyService.setFactory(new OfyFactory());
factory().register(Car.class);
factory().register(CarProperties.class);
factory().register(Manufacturer.class);
Expand All @@ -36,8 +36,8 @@ public class OfyService {
factory().register(UserSession.class);
}

public static Objectify ofy() {
return ObjectifyService.ofy();
public static Ofy ofy() {
return (Ofy) ObjectifyService.ofy();
}

public static ObjectifyFactory factory() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* Copyright 2014 ArcBees Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/

package com.gwtplatform.carstore.server.dispatch;

import com.gwtplatform.carstore.shared.dispatch.LogInAction;
import com.gwtplatform.dispatch.rpc.server.guice.HandlerModule;

public class DispatchModule extends HandlerModule {
@Override
protected void configureHandlers() {
install(new com.gwtplatform.dispatch.rpc.server.guice.DispatchModule());

bindHandler(LogInAction.class, LogInHandler.class);
}
}
Loading

0 comments on commit 6e33a2f

Please sign in to comment.