Skip to content

Commit dea7ff2

Browse files
committed
upgrade to CORE 4.0.0
1 parent d20260b commit dea7ff2

File tree

8 files changed

+113
-35
lines changed

8 files changed

+113
-35
lines changed

README.md

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Work Microservice
1+
# Review Microservice
22
A microservice for generic units of work (e.g., a challenge)
33

44
## Getting Started
@@ -8,7 +8,7 @@ This microservice is using [dropwizard](dropwizard.io) as the REST API framework
88
We are using Maven 2 to build and building is as simple as `mvn package`. *Make sure you are using Java 8 for build and runtime*
99

1010
### Configuration
11-
Configuration is managed through a yaml file. The `src/main/resources/work-service.yaml` file should contain the necessary configuration for you to run locally.
11+
Configuration is managed through a yaml file. The `src/main/resources/review-service.yaml` file should contain the necessary configuration for you to run locally.
1212

1313
### Framework Stack
1414
- dropwizard-core - core REST API
@@ -22,30 +22,28 @@ Configuration is managed through a yaml file. The `src/main/resources/work-servi
2222
### Database
2323
We are using mysql RDS for the database. For development use, connect to the topcoder-dev instance. Database access should be limited to the DAO layer. We are using the [JDBI](http://jdbi.org/) framework for database access. Where possible we should use the [SQL Objects API](http://jdbi.org/sql_object_overview/) approach listed in the JDBI documentation.
2424

25-
For this service, the DAO is managed by `WorkItemDAO`
25+
For this service, the DAO is managed by `ReviewDAO`
2626

2727
**We need to keep the data model clean and name properties of our representation (model) objects as the column names so we can use the automatic bean mapping facilities instead of needing to manually wire things together. Any deviation requires prior approval.**
2828

2929
### API Endpoint
30-
The API endpoint for this service is `com.appirio.service.work.resources.WorkItemResource` It contains the specific resource paths supported by this service. The root of the service is /v3/workitem. API methods should be annotated with the appropriate jax-rs annotations and the `@Timed` annotation for metrics. An example method is shown below.
30+
The API endpoint for this service is `com.appirio.service.review.resources.ReviewResource` It contains the specific resource paths supported by this service. The root of the service is /v3/reviews. API methods should be annotated with the appropriate jax-rs annotations and the `@Timed` annotation for metrics. An example method is shown below.
3131
```
3232
@GET
3333
@Timed
34-
@Path("{id}")
35-
public WorkItem getWorkItemById(@Auth TCAuth auth, @PathParam("id") LongParam id) {
36-
logger.debug("get work item for id {}", id);
34+
public ApiResponse getReviews(@Auth AuthUser auth,
35+
@APIQueryParam(repClass = Review.class) QueryParameter queryParameter)
36+
logger.debug("getReviews, filter : " + queryParameter.getFilter().getFields());
3737
38-
WorkItem wi = dao.findWorkItemById(id.get());
39-
return wi;
38+
return MetadataApiResponseFactory.createResponse(reviewManager.getReviews(auth, queryParameter,
39+
new BaseAuthorizationContext(auth)));
4040
}
4141
```
4242

4343
Note the `TCAuth` parameter provided by the `ServiceAuthenticator` class will provide user auth information and is a required parameterfor all secured API calls.
44+
You must set up `TC_JWT_KEY` environment variable, the sample value is `4WvoZLWhFPZ5jauw2+XCU+p772S4oBN25tNPyjHR`.
4445

4546
### Testing
4647
All API endpoint methods should have unit tests. For this service we are following the dropwizard testing recommendations as described [here](http://dropwizard.io/manual/testing.html)
4748

4849
For manual API testing, the [postman chrome app](https://chrome.google.com/webstore/detail/postman-rest-client/fdmmgilgnpjigdojojpjoooidkmcomcm?hl=en) is useful.
49-
50-
### Healthcheck
51-
This service has a healhcheck service located at `com.appirio.service.work.health.ServiceHealthCheck`. If any new dependent services are added, the healthcheck service should be updated to test its availability in order to determine if this service is healthy. This is important for application monitoring and failover.

local/docker-compose.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
version: '2'
2+
services:
3+
informix:
4+
image: "appiriodevops/informix:1b3d4ef"
5+
ports:
6+
- "2021:2021"
7+
kafka:
8+
image: spotify/kafka
9+
environment:
10+
ADVERTISED_HOST: $DOCKER_IP
11+
ADVERTISED_PORT: 9092
12+
ports:
13+
- "2181:2181"
14+
- "9092:9092"

service/pom.xml

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@
66
<version>1.0.2-SNAPSHOT</version>
77
<name>Review Microservice</name>
88
<properties>
9-
<dropwizard.version>0.7.1</dropwizard.version>
10-
<powermock.version>1.5.4</powermock.version>
11-
<jackson-version>2.7.3</jackson-version>
9+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
10+
<dropwizard.version>1.0.0</dropwizard.version>
11+
<powermock.version>1.5.4</powermock.version>
12+
<jackson-version>2.7.3</jackson-version>
13+
<core.api.version>4.0.0</core.api.version>
14+
<supply-library.version>1.0.15-SNAPSHOT</supply-library.version>
1215
</properties>
1316

1417
<build>
@@ -124,7 +127,7 @@
124127
<dependency>
125128
<groupId>appirio.platform</groupId>
126129
<artifactId>supply-library</artifactId>
127-
<version>1.0.7-SNAPSHOT</version>
130+
<version>${supply-library.version}</version>
128131
</dependency>
129132
<dependency>
130133
<groupId>org.projectlombok</groupId>
@@ -175,9 +178,9 @@
175178
<version>${dropwizard.version}</version>
176179
</dependency>
177180
<dependency>
178-
<groupId>com.appirio.tech.core.api</groupId>
179-
<artifactId>tech.core.api</artifactId>
180-
<version>API-3.0.0.8-SNAPSHOT</version>
181+
<groupId>com.topcoder</groupId>
182+
<artifactId>core.api</artifactId>
183+
<version>${core.api.version}</version>
181184
</dependency>
182185
<dependency>
183186
<groupId>com.informix.jdbc</groupId>

service/src/main/java/com/appirio/service/review/resources/ScorecardQuestionResource.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,20 @@
66
import com.appirio.supply.ErrorHandler;
77
import com.appirio.tech.core.api.v3.request.QueryParameter;
88
import com.appirio.tech.core.api.v3.request.annotation.APIQueryParam;
9+
import com.appirio.tech.core.api.v3.request.annotation.AllowAnonymous;
910
import com.appirio.tech.core.api.v3.response.ApiResponse;
1011
import com.appirio.tech.core.auth.AuthUser;
1112
import com.codahale.metrics.annotation.Timed;
12-
import io.dropwizard.auth.Auth;
1313
import org.slf4j.Logger;
1414
import org.slf4j.LoggerFactory;
1515

1616
import javax.ws.rs.Consumes;
1717
import javax.ws.rs.GET;
1818
import javax.ws.rs.Path;
1919
import javax.ws.rs.Produces;
20+
import javax.ws.rs.core.Context;
2021
import javax.ws.rs.core.MediaType;
22+
import javax.ws.rs.core.SecurityContext;
2123

2224
/**
2325
* Resource to expose scorecard question REST API
@@ -49,15 +51,17 @@ public ScorecardQuestionResource(ScorecardQuestionManager scorecardQuestionManag
4951
/**
5052
* Fetches scorecard questions based on API query parameters
5153
*
52-
* @param auth authentication user
5354
* @param queryParameter query parameter
55+
* @param securityContext security context
5456
* @return api response
5557
*/
5658
@GET
5759
@Timed
58-
public ApiResponse getScorecardQuestions(@Auth(required = false) AuthUser auth, @APIQueryParam(repClass = Scorecard.class) QueryParameter queryParameter) {
60+
@AllowAnonymous
61+
public ApiResponse getScorecardQuestions(@APIQueryParam(repClass = Scorecard.class) QueryParameter queryParameter, @Context SecurityContext securityContext) {
5962
try {
6063
logger.debug("getScorecardQuestions, filter : " + queryParameter.getFilter().getFields());
64+
AuthUser auth = (AuthUser)securityContext.getUserPrincipal();
6165
return MetadataApiResponseFactory.createResponse(scorecardQuestionManager.
6266
getScorecardQuestions(auth, queryParameter));
6367
} catch (Exception e) {

service/src/main/java/com/appirio/service/review/resources/ScorecardResource.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,20 @@
66
import com.appirio.supply.ErrorHandler;
77
import com.appirio.tech.core.api.v3.request.QueryParameter;
88
import com.appirio.tech.core.api.v3.request.annotation.APIQueryParam;
9+
import com.appirio.tech.core.api.v3.request.annotation.AllowAnonymous;
910
import com.appirio.tech.core.api.v3.response.ApiResponse;
1011
import com.appirio.tech.core.auth.AuthUser;
1112
import com.codahale.metrics.annotation.Timed;
12-
import io.dropwizard.auth.Auth;
1313
import org.slf4j.Logger;
1414
import org.slf4j.LoggerFactory;
1515

1616
import javax.ws.rs.Consumes;
1717
import javax.ws.rs.GET;
1818
import javax.ws.rs.Path;
1919
import javax.ws.rs.Produces;
20+
import javax.ws.rs.core.Context;
2021
import javax.ws.rs.core.MediaType;
22+
import javax.ws.rs.core.SecurityContext;
2123

2224
/**
2325
* Resource to expose scorecard REST API
@@ -53,15 +55,18 @@ public ScorecardResource(ScorecardManager scorecardManager) {
5355
/**
5456
* Fetches scorecards based on the API query parameters
5557
*
56-
* @param auth authentication user
5758
* @param queryParameter query parameter
59+
* @param securityContext security context
5860
* @return api response
5961
*/
6062
@GET
6163
@Timed
62-
public ApiResponse getScorecards(@Auth(required = false) AuthUser auth, @APIQueryParam(repClass = Scorecard.class) QueryParameter queryParameter) {
64+
@AllowAnonymous
65+
public ApiResponse getScorecards(@APIQueryParam(repClass = Scorecard.class) QueryParameter
66+
queryParameter, @Context SecurityContext securityContext) {
6367
try {
6468
logger.debug("getScorecards, filter : " + queryParameter.getFilter().getFields());
69+
AuthUser auth = (AuthUser)securityContext.getUserPrincipal();
6570
return MetadataApiResponseFactory.createResponse(scorecardManager
6671
.getScorecards(auth, queryParameter));
6772
} catch (Exception e) {

service/src/main/resources/review-service.yaml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,17 @@ databases:
1111
driverClass: com.informix.jdbc.IfxDriver
1212

1313
# the username
14-
user: coder
14+
user: "${OLTP_USER}"
15+
16+
password: "${OLTP_PW}"
1517

1618
# the password
1719
# NOTE: password is set as a java system property: i.e., -Ddw.database.password=<password>
1820

1921
validationQuery: select 1 from systables
2022

2123
# the JDBC URL
22-
url: jdbc:informix-sqli://localhost:2021/tcs_catalog:INFORMIXSERVER=informixoltp_tcp;IFX_LOCK_MODE_WAIT=5;OPTCOMPIND=0;STMT_CACHE=1;
24+
url: "${OLTP_URL}"
2325

2426
# the minimum number of connections to keep open
2527
minSize: 2
@@ -36,15 +38,17 @@ databases:
3638
driverClass: com.informix.jdbc.IfxDriver
3739

3840
# the username
39-
user: coder
41+
user: "${DW_USER}"
42+
43+
password: "${DW_PW}"
4044

4145
# the password
4246
# NOTE: password is set as a java system property: i.e., -Ddw.database.password=<password>
4347

4448
validationQuery: select 1 from systables
4549

4650
# the JDBC URL
47-
url: jdbc:informix-sqli://localhost:2021/topcoder_dw:INFORMIXSERVER=datawarehouse_tcp;IFX_LOCK_MODE_WAIT=5;OPTCOMPIND=0;STMT_CACHE=1;
51+
url: "${DW_URL}"
4852

4953
# the minimum number of connections to keep open
5054
minSize: 2
@@ -64,6 +68,7 @@ databases:
6468
# port: 8080
6569

6670
server:
71+
rootPath: '/v3/*'
6772
# softNofileLimit: 1000
6873
# hardNofileLimit: 1000
6974
applicationConnectors:

service/src/test/java/com/appirio/service/test/resources/ScorecardQuestionResourceTest.java

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
import com.appirio.supply.SupplyException;
77
import org.junit.Test;
88

9+
import javax.ws.rs.core.SecurityContext;
10+
11+
import java.security.Principal;
12+
913
import static org.mockito.Mockito.*;
1014

1115
public class ScorecardQuestionResourceTest extends BaseTest {
@@ -14,7 +18,28 @@ public class ScorecardQuestionResourceTest extends BaseTest {
1418

1519
@Test
1620
public void testGetScoreCards() throws SupplyException {
17-
unit.getScorecardQuestions(createUser("1"), createQueryParam(""));
21+
SecurityContext securityContext = new SecurityContext() {
22+
@Override
23+
public Principal getUserPrincipal() {
24+
return createUser("1");
25+
}
26+
27+
@Override
28+
public boolean isUserInRole(String s) {
29+
return false;
30+
}
31+
32+
@Override
33+
public boolean isSecure() {
34+
return false;
35+
}
36+
37+
@Override
38+
public String getAuthenticationScheme() {
39+
return null;
40+
}
41+
};
42+
unit.getScorecardQuestions(createQueryParam(""), securityContext);
1843
verify(mockScorecardQuestionManager).getScorecardQuestions(anyObject(),anyObject());
1944
}
2045

service/src/test/java/com/appirio/service/test/resources/ScorecardResourceTest.java

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,46 @@
11
package com.appirio.service.test.resources;
22

33
import com.appirio.service.review.manager.ScorecardManager;
4-
import static org.mockito.Mockito.*;
5-
import static org.junit.Assert.*;
6-
74
import com.appirio.service.review.resources.ScorecardResource;
85
import com.appirio.service.test.BaseTest;
96
import com.appirio.supply.SupplyException;
10-
import org.junit.Before;
117
import org.junit.Test;
128

9+
import javax.ws.rs.core.SecurityContext;
10+
import java.security.Principal;
11+
12+
import static org.mockito.Mockito.anyObject;
13+
import static org.mockito.Mockito.mock;
14+
import static org.mockito.Mockito.verify;
15+
1316
public class ScorecardResourceTest extends BaseTest {
1417
public static final ScorecardManager mockScorecardManager = mock(ScorecardManager.class);
1518
public static final ScorecardResource unit = new ScorecardResource(mockScorecardManager);
1619

1720
@Test
1821
public void testGetScoreCards() throws SupplyException {
19-
unit.getScorecards(createUser("1"),createQueryParam(""));
22+
SecurityContext securityContext = new SecurityContext() {
23+
@Override
24+
public Principal getUserPrincipal() {
25+
return createUser("1");
26+
}
27+
28+
@Override
29+
public boolean isUserInRole(String s) {
30+
return false;
31+
}
32+
33+
@Override
34+
public boolean isSecure() {
35+
return false;
36+
}
37+
38+
@Override
39+
public String getAuthenticationScheme() {
40+
return null;
41+
}
42+
};
43+
unit.getScorecards(createQueryParam(""), securityContext);
2044
verify(mockScorecardManager).getScorecards(anyObject(),anyObject());
2145
}
2246

0 commit comments

Comments
 (0)