Skip to content

Commit a56e9d5

Browse files
author
Michael Wunderlich
committed
Merge branch 'master' into xray
Conflicts: build.gradle
2 parents 988912c + 9c19686 commit a56e9d5

File tree

8 files changed

+32
-63
lines changed

8 files changed

+32
-63
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ build/*
77
!.elasticbeanstalk/*.global.yml
88
*.zip
99
*.sh
10+
!bin/*.sh
1011
lib

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Deploy the source code for the project to your Elastic Beanstalk environment.
3636
5. Upload **eb-java-scorekeep-v1.zip** and click **Deploy**.
3737
6. Open the environment URL.
3838

39-
![Scorekeep front page](/img/scorekeep-frontpage.png)
39+
![Scorekeep flow](/img/scorekeep-flow.png)
4040

4141
Click through the app to explore its functionality. Use the network console in your browser to see the HTTP requests that it sends to the API to read and write users, sessions, games, moves and game state to DynamoDB via the API.
4242

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ dependencies {
4545

4646
dependencyManagement {
4747
imports {
48-
mavenBom("com.amazonaws:aws-java-sdk-bom:1.11.52")
48+
mavenBom("com.amazonaws:aws-java-sdk-bom:1.11.67")
4949
mavenBom("com.amazonaws:aws-xray-recorder-sdk-bom:1.0.0-beta")
5050
}
5151
}

img/scorekeep-flow.png

45 KB
Loading

public/app/userCollection.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module.service('UserCollection', function(UserService, api) {
66
return UserService.get({ id: userid })
77
}
88
var user = new UserService();
9-
if ( username == "random") {
9+
if ( username === "random") {
1010
return user.$save();
1111
} else {
1212
user.name = username;

src/main/java/scorekeep/MoveFactory.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package scorekeep;
2-
import java.util.*;
3-
import java.security.SecureRandom;
2+
43
import java.math.BigInteger;
5-
import java.lang.Exception;
4+
import java.security.SecureRandom;
5+
import java.util.HashMap;
6+
import java.util.List;
7+
import java.util.Set;
68

79
public class MoveFactory {
810
private SecureRandom random = new SecureRandom();
@@ -22,7 +24,7 @@ public Move newMove(String sessionId, String gameId, String userId, String moveT
2224
Move move = new Move(moveId, sessionId, gameId, userId, moveText);
2325
// load game state
2426
Game game = gameController.getGame(sessionId, gameId);
25-
ArrayList<String> states = game.getStates();
27+
List<String> states = game.getStates();
2628
State oldState = stateController.getState(sessionId, gameId, states.get(states.size() - 1));
2729
Set<String> oldTurn = oldState.getTurn();
2830
// check turn

src/main/java/scorekeep/MoveModel.java

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,15 @@
11
package scorekeep;
22

3-
import java.io.File;
4-
import java.util.Iterator;
5-
import java.util.Map;
6-
import java.util.HashMap;
7-
import java.util.List;
8-
import java.util.Set;
9-
10-
import com.amazonaws.auth.AWSCredentials;
11-
import com.amazonaws.auth.profile.ProfileCredentialsProvider;
12-
import com.amazonaws.auth.AWSCredentialsProvider;
3+
import com.amazonaws.regions.Regions;
134
import com.amazonaws.services.dynamodbv2.AmazonDynamoDB;
145
import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClientBuilder;
156
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper;
167
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBQueryExpression;
178
import com.amazonaws.services.dynamodbv2.model.AttributeValue;
18-
import com.amazonaws.regions.Regions;
19-
import com.fasterxml.jackson.core.JsonFactory;
20-
import com.fasterxml.jackson.core.JsonParser;
21-
import com.fasterxml.jackson.databind.JsonNode;
22-
import com.fasterxml.jackson.databind.ObjectMapper;
23-
import com.fasterxml.jackson.databind.node.ObjectNode;
24-
import java.lang.Exception;
25-
import java.lang.Throwable;
9+
10+
import java.util.HashMap;
11+
import java.util.List;
12+
import java.util.Map;
2613

2714
public class MoveModel {
2815
/** AWS SDK credentials. */
@@ -37,17 +24,13 @@ public void saveMove(Move move) throws SessionNotFoundException, GameNotFoundExc
3724
// check session
3825
String sessionId = move.getSession();
3926
String gameId = move.getGame();
40-
try {
41-
if (sessionModel.loadSession(sessionId) == null ) {
42-
throw new SessionNotFoundException(sessionId);
43-
}
44-
if (gameModel.loadGame(gameId) == null ) {
45-
throw new GameNotFoundException(gameId);
46-
}
47-
mapper.save(move);
48-
} catch (Exception e) {
49-
throw e;
27+
if (sessionModel.loadSession(sessionId) == null ) {
28+
throw new SessionNotFoundException(sessionId);
29+
}
30+
if (gameModel.loadGame(gameId) == null ) {
31+
throw new GameNotFoundException(gameId);
5032
}
33+
mapper.save(move);
5134
}
5235

5336
public Move loadMove(String moveId) throws MoveNotFoundException {

src/main/java/scorekeep/StateModel.java

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,15 @@
11
package scorekeep;
22

3-
import java.io.File;
4-
import java.util.Iterator;
5-
import java.util.Map;
6-
import java.util.HashMap;
7-
import java.util.List;
8-
import java.util.Set;
9-
10-
import com.amazonaws.auth.AWSCredentials;
11-
import com.amazonaws.auth.profile.ProfileCredentialsProvider;
12-
import com.amazonaws.auth.AWSCredentialsProvider;
3+
import com.amazonaws.regions.Regions;
134
import com.amazonaws.services.dynamodbv2.AmazonDynamoDB;
145
import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClientBuilder;
156
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper;
167
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBQueryExpression;
178
import com.amazonaws.services.dynamodbv2.model.AttributeValue;
18-
import com.amazonaws.regions.Regions;
19-
import com.fasterxml.jackson.core.JsonFactory;
20-
import com.fasterxml.jackson.core.JsonParser;
21-
import com.fasterxml.jackson.databind.JsonNode;
22-
import com.fasterxml.jackson.databind.ObjectMapper;
23-
import com.fasterxml.jackson.databind.node.ObjectNode;
24-
import java.lang.Exception;
25-
import java.lang.Throwable;
9+
10+
import java.util.HashMap;
11+
import java.util.List;
12+
import java.util.Map;
2613

2714
/** Saves state objects to DynamoDB
2815
Loads state objects from DynamoDB
@@ -41,17 +28,13 @@ public void saveState(State state) throws SessionNotFoundException, GameNotFound
4128
// check session
4229
String sessionId = state.getSession();
4330
String gameId = state.getGame();
44-
try {
45-
if (sessionModel.loadSession(sessionId) == null ) {
46-
throw new SessionNotFoundException(sessionId);
47-
}
48-
if (gameModel.loadGame(gameId) == null ) {
49-
throw new GameNotFoundException(gameId);
50-
}
51-
mapper.save(state);
52-
} catch (Exception e) {
53-
throw e;
31+
if (sessionModel.loadSession(sessionId) == null ) {
32+
throw new SessionNotFoundException(sessionId);
33+
}
34+
if (gameModel.loadGame(gameId) == null ) {
35+
throw new GameNotFoundException(gameId);
5436
}
37+
mapper.save(state);
5538
}
5639

5740
public State loadState(String stateId) throws StateNotFoundException {

0 commit comments

Comments
 (0)