This repository has been archived by the owner on Mar 15, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New resource and repository methods to control the activity lifecycle…
… on the server instead on the client side
- Loading branch information
Showing
28 changed files
with
1,174 additions
and
651 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
src/main/java/name/pehl/karaka/client/activity/dispatch/CopyActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package name.pehl.karaka.client.activity.dispatch; | ||
|
||
import com.gwtplatform.dispatch.annotation.GenDispatch; | ||
import com.gwtplatform.dispatch.annotation.In; | ||
import com.gwtplatform.dispatch.annotation.Out; | ||
import name.pehl.karaka.shared.model.Activity; | ||
|
||
/** | ||
* Used to save new and update existing activities. | ||
* | ||
* @author $LastChangedBy:$ | ||
* @version $LastChangedRevision:$ | ||
*/ | ||
@GenDispatch | ||
public class CopyActivity | ||
{ | ||
@In(1) Activity activity; | ||
@In(2) String period; | ||
@Out(1) Activity copy; | ||
} |
64 changes: 64 additions & 0 deletions
64
src/main/java/name/pehl/karaka/client/activity/dispatch/CopyActivityHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package name.pehl.karaka.client.activity.dispatch; | ||
|
||
import com.google.gwt.json.client.JSONObject; | ||
import com.google.gwt.user.client.rpc.AsyncCallback; | ||
import com.google.inject.Inject; | ||
import com.gwtplatform.dispatch.shared.SecurityCookie; | ||
import com.gwtplatform.dispatch.shared.SecurityCookieAccessor; | ||
import name.pehl.karaka.client.activity.model.ActivityReader; | ||
import name.pehl.karaka.client.dispatch.KarakaActionHandler; | ||
import name.pehl.karaka.client.dispatch.KarakaJsonCallback; | ||
import name.pehl.karaka.client.rest.UrlBuilder; | ||
import name.pehl.karaka.shared.model.Activity; | ||
import name.pehl.piriti.json.client.JsonReader; | ||
import org.fusesource.restygwt.client.Method; | ||
import org.fusesource.restygwt.client.Resource; | ||
|
||
import static name.pehl.karaka.client.dispatch.KarakaActionHandler.HttpMethod.PUT; | ||
import static org.fusesource.restygwt.client.Resource.CONTENT_TYPE_JSON; | ||
import static org.fusesource.restygwt.client.Resource.HEADER_CONTENT_TYPE; | ||
|
||
/** | ||
* @author $Author:$ | ||
* @version $Date:$ $Revision:$ | ||
*/ | ||
public class CopyActivityHandler extends KarakaActionHandler<CopyActivityAction, CopyActivityResult> | ||
{ | ||
private final ActivityReader activityReader; | ||
|
||
|
||
@Inject | ||
protected CopyActivityHandler(@SecurityCookie String securityCookieName, | ||
SecurityCookieAccessor securityCookieAccessor, ActivityReader activityReader) | ||
{ | ||
super(CopyActivityAction.class, securityCookieName, securityCookieAccessor); | ||
this.activityReader = activityReader; | ||
} | ||
|
||
@Override | ||
protected Resource resourceFor(CopyActivityAction action) | ||
{ | ||
UrlBuilder urlBuilder = new UrlBuilder().module("rest") | ||
.path("activities", "copy", action.getActivity().getId()); | ||
return new Resource(urlBuilder.toUrl()); | ||
} | ||
|
||
@Override | ||
protected Method methodFor(CopyActivityAction action, Resource resource) | ||
{ | ||
return new Method(resource, PUT.name()).header(HEADER_CONTENT_TYPE, CONTENT_TYPE_JSON); | ||
} | ||
|
||
@Override | ||
protected void executeMethod(final Method method, final AsyncCallback<CopyActivityResult> resultCallback) | ||
{ | ||
method.send(new KarakaJsonCallback<Activity, CopyActivityResult>(activityReader, resultCallback) | ||
{ | ||
@Override | ||
protected CopyActivityResult extractResult(final JsonReader<Activity> reader, final JSONObject json) | ||
{ | ||
return new CopyActivityResult(reader.read(json)); | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/main/java/name/pehl/karaka/client/activity/dispatch/StartActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package name.pehl.karaka.client.activity.dispatch; | ||
|
||
import com.gwtplatform.dispatch.annotation.GenDispatch; | ||
import com.gwtplatform.dispatch.annotation.In; | ||
import com.gwtplatform.dispatch.annotation.Out; | ||
import name.pehl.karaka.shared.model.Activity; | ||
|
||
import java.util.Set; | ||
|
||
/** | ||
* Used to save new and update existing activities. | ||
* | ||
* @author $LastChangedBy:$ | ||
* @version $LastChangedRevision:$ | ||
*/ | ||
@GenDispatch | ||
public class StartActivity | ||
{ | ||
@In(1) Activity activity; | ||
@Out(1) Set<Activity> modified; | ||
} |
79 changes: 79 additions & 0 deletions
79
src/main/java/name/pehl/karaka/client/activity/dispatch/StartActivityHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package name.pehl.karaka.client.activity.dispatch; | ||
|
||
import com.google.gwt.json.client.JSONObject; | ||
import com.google.gwt.user.client.rpc.AsyncCallback; | ||
import com.google.inject.Inject; | ||
import com.gwtplatform.dispatch.shared.SecurityCookie; | ||
import com.gwtplatform.dispatch.shared.SecurityCookieAccessor; | ||
import name.pehl.karaka.client.activity.model.ActivityReader; | ||
import name.pehl.karaka.client.activity.model.ActivityWriter; | ||
import name.pehl.karaka.client.dispatch.KarakaActionHandler; | ||
import name.pehl.karaka.client.dispatch.KarakaJsonCallback; | ||
import name.pehl.karaka.client.rest.UrlBuilder; | ||
import name.pehl.karaka.shared.model.Activity; | ||
import name.pehl.piriti.json.client.JsonReader; | ||
import org.fusesource.restygwt.client.Method; | ||
import org.fusesource.restygwt.client.Resource; | ||
|
||
import java.util.HashSet; | ||
|
||
import static name.pehl.karaka.client.dispatch.KarakaActionHandler.HttpMethod.PUT; | ||
import static org.fusesource.restygwt.client.Resource.CONTENT_TYPE_JSON; | ||
import static org.fusesource.restygwt.client.Resource.HEADER_CONTENT_TYPE; | ||
|
||
/** | ||
* @author $Author:$ | ||
* @version $Date:$ $Revision:$ | ||
*/ | ||
public class StartActivityHandler extends KarakaActionHandler<StartActivityAction, StartActivityResult> | ||
{ | ||
private final ActivityReader activityReader; | ||
private final ActivityWriter activityWriter; | ||
|
||
|
||
@Inject | ||
protected StartActivityHandler(@SecurityCookie String securityCookieName, | ||
SecurityCookieAccessor securityCookieAccessor, ActivityReader activityReader, ActivityWriter activityWriter) | ||
{ | ||
super(StartActivityAction.class, securityCookieName, securityCookieAccessor); | ||
this.activityReader = activityReader; | ||
this.activityWriter = activityWriter; | ||
} | ||
|
||
@Override | ||
protected Resource resourceFor(StartActivityAction action) | ||
{ | ||
Activity activity = action.getActivity(); | ||
UrlBuilder urlBuilder = new UrlBuilder().module("rest").path("activities", "start"); | ||
if (!activity.isTransient()) | ||
{ | ||
urlBuilder = urlBuilder.path(activity.getId()); | ||
} | ||
return new Resource(urlBuilder.toUrl()); | ||
} | ||
|
||
@Override | ||
protected Method methodFor(StartActivityAction action, Resource resource) | ||
{ | ||
Activity activity = action.getActivity(); | ||
Method method = new Method(resource, PUT.name()).header(HEADER_CONTENT_TYPE, CONTENT_TYPE_JSON); | ||
if (action.getActivity().isTransient()) | ||
{ | ||
method = method.text(activityWriter.toJson(activity)); | ||
} | ||
return method; | ||
} | ||
|
||
@Override | ||
protected void executeMethod(final Method method, final AsyncCallback<StartActivityResult> resultCallback) | ||
{ | ||
method.send(new KarakaJsonCallback<Activity, StartActivityResult>(activityReader, resultCallback) | ||
{ | ||
@Override | ||
protected StartActivityResult extractResult(final JsonReader<Activity> reader, final JSONObject json) | ||
{ | ||
return new StartActivityResult(new HashSet<Activity>(reader.readList(json))); | ||
} | ||
}); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/name/pehl/karaka/client/activity/dispatch/StopActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package name.pehl.karaka.client.activity.dispatch; | ||
|
||
import com.gwtplatform.dispatch.annotation.GenDispatch; | ||
import com.gwtplatform.dispatch.annotation.In; | ||
import com.gwtplatform.dispatch.annotation.Out; | ||
import name.pehl.karaka.shared.model.Activity; | ||
|
||
/** | ||
* Used to save new and update existing activities. | ||
* | ||
* @author $LastChangedBy:$ | ||
* @version $LastChangedRevision:$ | ||
*/ | ||
@GenDispatch | ||
public class StopActivity | ||
{ | ||
@In(1) Activity activity; | ||
@Out(1) Activity stopped; | ||
} |
93 changes: 93 additions & 0 deletions
93
src/main/java/name/pehl/karaka/client/activity/dispatch/StopActivityHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package name.pehl.karaka.client.activity.dispatch; | ||
|
||
import com.google.gwt.http.client.Request; | ||
import com.google.gwt.http.client.RequestCallback; | ||
import com.google.gwt.http.client.RequestException; | ||
import com.google.gwt.http.client.Response; | ||
import com.google.gwt.json.client.JSONObject; | ||
import com.google.gwt.user.client.rpc.AsyncCallback; | ||
import com.google.inject.Inject; | ||
import com.gwtplatform.dispatch.shared.SecurityCookie; | ||
import com.gwtplatform.dispatch.shared.SecurityCookieAccessor; | ||
import name.pehl.karaka.client.activity.model.ActivityReader; | ||
import name.pehl.karaka.client.dispatch.KarakaActionHandler; | ||
import name.pehl.karaka.client.dispatch.KarakaJsonCallback; | ||
import name.pehl.karaka.client.rest.UrlBuilder; | ||
import name.pehl.karaka.shared.model.Activity; | ||
import name.pehl.piriti.json.client.JsonReader; | ||
import org.fusesource.restygwt.client.Method; | ||
import org.fusesource.restygwt.client.Resource; | ||
|
||
import static name.pehl.karaka.client.dispatch.KarakaActionHandler.HttpMethod.PUT; | ||
import static org.fusesource.restygwt.client.Resource.CONTENT_TYPE_JSON; | ||
import static org.fusesource.restygwt.client.Resource.HEADER_CONTENT_TYPE; | ||
|
||
/** | ||
* @author $Author:$ | ||
* @version $Date:$ $Revision:$ | ||
*/ | ||
public class StopActivityHandler extends KarakaActionHandler<StopActivityAction, StopActivityResult> | ||
{ | ||
private final ActivityReader activityReader; | ||
|
||
@Inject | ||
protected StopActivityHandler(@SecurityCookie String securityCookieName, | ||
SecurityCookieAccessor securityCookieAccessor, ActivityReader activityReader) | ||
{ | ||
super(StopActivityAction.class, securityCookieName, securityCookieAccessor); | ||
this.activityReader = activityReader; | ||
} | ||
|
||
|
||
@Override | ||
protected Resource resourceFor(StopActivityAction action) | ||
{ | ||
UrlBuilder urlBuilder = new UrlBuilder().module("rest").path("activities", "stop", action.getActivity().getId()); | ||
return new Resource(urlBuilder.toUrl()); | ||
} | ||
|
||
|
||
@Override | ||
protected Method methodFor(StopActivityAction action, Resource resource) | ||
{ | ||
return new Method(resource, PUT.name()).header(HEADER_CONTENT_TYPE, CONTENT_TYPE_JSON); | ||
} | ||
|
||
|
||
@Override | ||
protected void executeMethod(final Method method, final AsyncCallback<StopActivityResult> resultCallback) | ||
{ | ||
method.send(new KarakaJsonCallback<Activity, StopActivityResult>(activityReader, resultCallback) | ||
{ | ||
@Override | ||
protected StopActivityResult extractResult(final JsonReader<Activity> reader, final JSONObject json) | ||
{ | ||
return new StopActivityResult(reader.read(json)); | ||
} | ||
}); | ||
|
||
|
||
try | ||
{ | ||
method.send(new RequestCallback() | ||
{ | ||
@Override | ||
public void onResponseReceived(Request request, Response response) | ||
{ | ||
resultCallback.onSuccess(new StopActivityResult()); | ||
} | ||
|
||
|
||
@Override | ||
public void onError(Request request, Throwable exception) | ||
{ | ||
resultCallback.onFailure(exception); | ||
} | ||
}); | ||
} | ||
catch (RequestException e) | ||
{ | ||
resultCallback.onFailure(e); | ||
} | ||
} | ||
} |
Oops, something went wrong.