From ad0d32b3c07e15e0739090993f857a1e8871e42c Mon Sep 17 00:00:00 2001
From: Qun Huang
Date: Thu, 5 Oct 2017 15:42:15 +0800
Subject: [PATCH 01/19] updates to run the code locally
---
README.md | 177 ++++++++++++++----
local/docker-compose.yml | 5 +-
local/test_data.sql | 58 ++++++
...eview-microservice.postman_collection.json | 75 ++++++++
...view-microservice.postman_environment.json | 28 +++
service/pom.xml | 24 +--
6 files changed, 316 insertions(+), 51 deletions(-)
mode change 100644 => 100755 README.md
create mode 100755 local/test_data.sql
create mode 100755 postman/review-microservice.postman_collection.json
create mode 100755 postman/review-microservice.postman_environment.json
diff --git a/README.md b/README.md
old mode 100644
new mode 100755
index 2bfe06a..dbe61ee
--- a/README.md
+++ b/README.md
@@ -1,49 +1,158 @@
# Review Microservice
-A microservice for generic units of work (e.g., a challenge)
+Microservice for supporting Topcoder Online Review platform.
-## Getting Started
-This microservice is using [dropwizard](dropwizard.io) as the REST API framework and implements the [v3 API spec](https://docs.google.com/a/appirio.com/presentation/d/15pucEI0MHj9y778EyaAWGh4MBH-I73i1-GS0ir7FhxE/edit#slide=id.g29c3ffcc3_020). If you are unfamiliar with dropwizard, take a look at their [Getting Started](http://dropwizard.io/getting-started.html) page.
+# Prerequisities
-### Building
-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*
+- Java 8 with Maven 2+
+- Docker
-### Configuration
-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.
+# Local Deployment
-### Framework Stack
-- dropwizard-core - core REST API
-- dropwizard-auth - user authentication
-- dropwizard-jdbi - database access
-- dropwizard-testing - unit testing
-- mysql-connector-java - mysql JDBC driver
-- fest-assert-core, mockito-core - unit testing
-- slf4j - logging
+### Start Informix instance via Docker
-### Database
-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.
+- Set an IP for Docker by setting the environment variable `DOCKER_IP`. Recommended to set to `0.0.0.0`
-For this service, the DAO is managed by `ReviewDAO`
+- Command to set the environment variable `DOCKER_IP`
-**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.**
+```
+export DOCKER_IP=0.0.0.0
+```
+
+- To run Informix locally, go to the `local` folder and execute the following command:
+
+```
+docker-compose up
+```
-### API Endpoint
-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.
+If you should ever encounter the error:
+
+```
+[java] Caused by: com.topcoder.db.connectionfactory.DBConnectionException: error occurs while creating the connection.
+You already have 20 connections at this
+time. Any further connections
```
-@GET
-@Timed
-public ApiResponse getReviews(@Auth AuthUser auth,
- @APIQueryParam(repClass = Review.class) QueryParameter queryParameter)
- logger.debug("getReviews, filter : " + queryParameter.getFilter().getFields());
- return MetadataApiResponseFactory.createResponse(reviewManager.getReviews(auth, queryParameter,
- new BaseAuthorizationContext(auth)));
-}
+Try to restart the informix database server as below:
+```
+#### log into the container based on the container name got in the previous step
+docker exec -it local_informix bash
+
+#### restart the database server
+onmode -ky
+oninit
+```
+
+### Inserting test records
+
+- Test data is present in SQL file (`test_data.sql`) in `local` folder.
+
+- Transfer the `test_data.sql` to docker environment by executing the following command
+
```
+docker cp test_data.sql local_informix:/home/informix
+```
+
+- Insert the records in `tcs_catalog` database by executing the following command
+
+```
+docker exec -it local_informix dbaccess tcs_catalog test_data.sql
+```
+
+- Docker environment is ready to be used in our service.
+
+### Configuration Variables
+The configuration file `service/src/main/resources/review-service.yaml` contain the necessary configuration to run the microservice locally. Below configuration variables need to be set using environment variables.
+
+|Name | Description |
+|--------------------|:-----------------------------------------:|
+|AUTH_DOMAIN | Authentication domain of JWT, Dont set unless you have valid tokens with given AUTH_DOMAIN, Defaulted to 'topcoder-dev.com' |
+|IP | The IP of your docker container |
+|OLTP_USER | The Informix OLTP user |
+|OLTP_PW | The Informix OLTP user password |
+|OLTP_URL | The JDBC URL of Informix OLTP database |
+|DW_USER | The Informix DW user |
+|DW_PW | The Informix DW user password |
+|DW_URL | The JDBC URL of Informix DW database |
+|TC_JWT_KEY | Secret used in JWT Service, Used for signature verification as well |
+
+In Linux, Set the environment variables as
+
+```
+export AUTH_DOMAIN=...
+export IP=...
+export OLTP_USER=...
+export OLTP_PW=...
+export OLTP_URL=...
+export DW_USER=...
+export DW_PW=...
+export DW_URL=...
+```
+
+### Working credentials for local deployment
+
+```
+export IP=0.0.0.0
+export OLTP_USER=informix
+export OLTP_PW=1nf0rm1x
+export OLTP_URL=jdbc:informix-sqli://$IP:2021/tcs_catalog:INFORMIXSERVER=informixoltp_tcp;IFX_LOCK_MODE_WAIT=5;OPTCOMPIND=0;STMT_CACHE=1
+export DW_USER=informix
+export DW_PW=1nf0rm1x
+export DW_URL=jdbc:informix-sqli://$IP:2021/common_dw:INFORMIXSERVER=informixoltp_tcp;IFX_LOCK_MODE_WAIT=5;OPTCOMPIND=0;STMT_CACHE=1
+export TC_JWT_KEY=secret
+```
+
+### Set up Local Maven repository for Appirio Maven
+
+- Since maven.appirio.net is not accessible, We need to set up a local maven repository with the zip file `temp-maven-repo-master.zip`
+
+- Unzip the contents to any of the directory in your System. **In Linux, the directory should not be a mounted directory like pen drive, hard disk, etc..**
+
+- Open `pom.xml` in `service` directory and replace the `` of Local repository with `absolute path of the unzipped file`. E.g. If you have unzipped the files to `/home/user/temp-maven-repo-master`, then POM entry will look like
+
+```
+
+ 1_temp_appirio_maven_repo
+ Appirio Maven Local Repository
+ file:///home/user/temp-maven-repo-master
+
+```
+
+### Build Microservice
+
+In the `service` folder of this project, run the following command to build the service.
+
+```
+mvn clean package
+```
+
+### Start Microservice
+
+- Before starting please ensure that all environment variables listed above is set properly and docker is up and running.
+
+- Then start the service using the following command in the 'service' folder:
+
+```
+java -jar ./target/review-microservice-*.jar server ./src/main/resources/review-service.yaml
+```
+
+### Verification
+
+Though there are many endpoints, For starters, it's sufficient to verify two end points.
+
+- Endpoint `/v3/scorecards` doesn't require Authentication
+
+- Endpoint `/v3/reviews` require Authentication
+
+Use the postman collection in `Postman` directory to verify the end points.
+
+- **Ensure to import the postman environment before testing the endpoints**
+
+- Request `Get list of all Scorecards` returns all scorecard templates present in the database
+
+**Loaded test data has details for 3 submissions for a single competition reviewed by 2 reviewers**
-Note the `TCAuth` parameter provided by the `ServiceAuthenticator` class will provide user auth information and is a required parameterfor all secured API calls.
-You must set up `TC_JWT_KEY` environment variable, the sample value is `4WvoZLWhFPZ5jauw2+XCU+p772S4oBN25tNPyjHR`.
+- Request `Get list of all reviews Reviewer1` return the reviews done by Reviewer 1.
-### Testing
-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)
+- Request `Get list of all reviews Reviewer2` return the reviews done by Reviewer 2.
-For manual API testing, the [postman chrome app](https://chrome.google.com/webstore/detail/postman-rest-client/fdmmgilgnpjigdojojpjoooidkmcomcm?hl=en) is useful.
+ **Note: Some of the fields in returned output will be NULL, It's expected. That's how the internal controllers and services are written**
diff --git a/local/docker-compose.yml b/local/docker-compose.yml
index f8f55a9..4c69346 100644
--- a/local/docker-compose.yml
+++ b/local/docker-compose.yml
@@ -1,14 +1,15 @@
version: '2'
services:
informix:
+ container_name: local_informix
image: "appiriodevops/informix:1b3d4ef"
ports:
- "2021:2021"
kafka:
image: spotify/kafka
environment:
- ADVERTISED_HOST: $DOCKER_IP
- ADVERTISED_PORT: 9092
+ ADVERTISED_HOST: ${DOCKER_IP}
+ ADVERTISED_PORT: 2181
ports:
- "2181:2181"
- "9092:9092"
diff --git a/local/test_data.sql b/local/test_data.sql
new file mode 100755
index 0000000..6a63f2b
--- /dev/null
+++ b/local/test_data.sql
@@ -0,0 +1,58 @@
+database tcs_catalog;
+
+/* Data for a project*/
+
+insert into project(project_id, project_status_id, project_category_id, create_user, create_date, modify_user, modify_date)
+values(1, 1, 1, 132456, current, 132456, current);
+
+/* Data for 2 reviewers and 3 submitters based on the token provided */
+insert into resource(resource_id, resource_role_id, project_id, project_phase_id, user_id, create_user, create_date, modify_user, modify_date) values(2, 4, 1, 13, 1234, 132456, current, 132456, current);
+
+insert into resource(resource_id, resource_role_id, project_id, project_phase_id, user_id, create_user, create_date, modify_user, modify_date) values(3, 4, 1, 13, 1235, 132456, current, 132456, current);
+
+insert into resource(resource_id, resource_role_id, project_id, project_phase_id, user_id, create_user, create_date, modify_user, modify_date) values(4, 1, 1, 13, 1200, 132456, current, 132456, current);
+
+insert into resource(resource_id, resource_role_id, project_id, project_phase_id, user_id, create_user, create_date, modify_user, modify_date) values(5, 1, 1, 13, 1201, 132456, current, 132456, current);
+
+insert into resource(resource_id, resource_role_id, project_id, project_phase_id, user_id, create_user, create_date, modify_user, modify_date) values(6, 1, 1, 13, 1202, 132456, current, 132456, current);
+
+/* Data for 3 uploads */
+
+insert into upload(upload_id, project_id, project_phase_id, resource_id, upload_type_id, upload_status_id, parameter, create_user, create_date, modify_user, modify_date) values(1, 1, 12, 4, 1, 1, 'someparam', 132456, current, 132456, current);
+
+insert into upload(upload_id, project_id, project_phase_id, resource_id, upload_type_id, upload_status_id, parameter, create_user, create_date, modify_user, modify_date) values(2, 1, 12, 5, 1, 1, 'someparam', 132456, current, 132456, current);
+
+insert into upload(upload_id, project_id, project_phase_id, resource_id, upload_type_id, upload_status_id, parameter, create_user, create_date, modify_user, modify_date) values(3, 1, 12, 6, 1, 1, 'someparam', 132456, current, 132456, current);
+
+
+/* Data for 3 submission */
+
+insert into submission(submission_id, upload_id, submission_status_id, submission_type_id, create_user, create_date, modify_user, modify_date)
+values(1, 1, 1, 1, 132456, current, 132456, current);
+
+insert into submission(submission_id, upload_id, submission_status_id, submission_type_id, create_user, create_date, modify_user, modify_date)
+values(2, 2, 1, 1, 132456, current, 132456, current);
+
+insert into submission(submission_id, upload_id, submission_status_id, submission_type_id, create_user, create_date, modify_user, modify_date)
+values(3, 3, 1, 1, 132456, current, 132456, current);
+
+
+/* 3 submissions for a single competition reviewed by 2 reviewers*/
+
+insert into review(review_id, resource_id, submission_id, project_phase_id, scorecard_id, committed, score, initial_score, create_user, create_date, modify_user, modify_date)
+ values(1, 2, 1, 13, 30000410, 1, 100, 95, 132456, current, 132456, current);
+
+insert into review(review_id, resource_id, submission_id, project_phase_id, scorecard_id, committed, score, initial_score, create_user, create_date, modify_user, modify_date)
+ values(2, 3, 1, 13, 30000410, 1, 100, 95, 132456, current, 132456, current);
+
+insert into review(review_id, resource_id, submission_id, project_phase_id, scorecard_id, committed, score, initial_score, create_user, create_date, modify_user, modify_date)
+ values(3, 2, 2, 13, 30000410, 1, 65, 55, 132456, current, 132456, current);
+
+insert into review(review_id, resource_id, submission_id, project_phase_id, scorecard_id, committed, score, initial_score, create_user, create_date, modify_user, modify_date)
+ values(4, 3, 2, 13, 30000410, 1, 70, 60, 132456, current, 132456, current);
+
+insert into review(review_id, resource_id, submission_id, project_phase_id, scorecard_id, committed, score, initial_score, create_user, create_date, modify_user, modify_date)
+ values(5, 2, 3, 13, 30000410, 1, 90, 87, 132456, current, 132456, current);
+
+insert into review(review_id, resource_id, submission_id, project_phase_id, scorecard_id, committed, score, initial_score, create_user, create_date, modify_user, modify_date)
+ values(6, 3, 3, 13, 30000410, 1, 84.36, 78, 132456, current, 132456, current);
diff --git a/postman/review-microservice.postman_collection.json b/postman/review-microservice.postman_collection.json
new file mode 100755
index 0000000..7546b96
--- /dev/null
+++ b/postman/review-microservice.postman_collection.json
@@ -0,0 +1,75 @@
+{
+ "variables": [],
+ "info": {
+ "name": "review-microservice",
+ "_postman_id": "6ebf34a8-a02f-658e-d692-ea743cb31056",
+ "description": "",
+ "schema": "https://schema.getpostman.com/json/collection/v2.0.0/collection.json"
+ },
+ "item": [
+ {
+ "name": "Get list of all Scorecards",
+ "request": {
+ "url": "{{apiUrl}}/v3/scorecards",
+ "method": "GET",
+ "header": [
+ {
+ "key": "Content-Type",
+ "value": "application/json",
+ "description": ""
+ }
+ ],
+ "body": {
+ "mode": "raw",
+ "raw": ""
+ },
+ "description": ""
+ },
+ "response": []
+ },
+ {
+ "name": "Get list of all reviews Reviewer1",
+ "request": {
+ "url": "{{apiUrl}}/v3/reviews",
+ "method": "GET",
+ "header": [
+ {
+ "key": "Authorization",
+ "value": "{{Reviewer1 Token}}",
+ "description": ""
+ },
+ {
+ "key": "Content-Type",
+ "value": "application/json",
+ "description": ""
+ }
+ ],
+ "body": {},
+ "description": ""
+ },
+ "response": []
+ },
+ {
+ "name": "Get list of all reviews Reviewer2",
+ "request": {
+ "url": "{{apiUrl}}/v3/reviews",
+ "method": "GET",
+ "header": [
+ {
+ "key": "Authorization",
+ "value": "{{Reviewer2 Token}}",
+ "description": ""
+ },
+ {
+ "key": "Content-Type",
+ "value": "application/json",
+ "description": ""
+ }
+ ],
+ "body": {},
+ "description": ""
+ },
+ "response": []
+ }
+ ]
+}
diff --git a/postman/review-microservice.postman_environment.json b/postman/review-microservice.postman_environment.json
new file mode 100755
index 0000000..10b6eaf
--- /dev/null
+++ b/postman/review-microservice.postman_environment.json
@@ -0,0 +1,28 @@
+{
+ "id": "0e76601a-1e30-b51c-a3d4-daf7bcb2ab94",
+ "name": "review-microservice",
+ "values": [
+ {
+ "enabled": true,
+ "key": "apiUrl",
+ "value": "http://localhost:8080",
+ "type": "text"
+ },
+ {
+ "enabled": true,
+ "key": "Reviewer1 Token",
+ "value": "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJyb2xlcyI6WyJyZXZpZXdlciJdLCJpc3MiOiJodHRwczovL2FwaS50b3Bjb2Rlci1kZXYuY29tIiwiaGFuZGxlIjoicmV2aWV3ZXIxIiwiZXhwIjoxNzY2Mjg5MjQ2LCJ1c2VySWQiOiIxMjM0IiwiaWF0IjoxNDUwOTI5MjQ2LCJlbWFpbCI6bnVsbCwianRpIjoiMTM2OWM2MDAtZTBhMS00NTI1LWE3YzctNTZiZTdkODEzZjUxIn0.4AOKcnvm4Wms_lY_RyYv61OHXCC-I__JnEPRZEN3-vM",
+ "type": "text"
+ },
+ {
+ "enabled": true,
+ "key": "Reviewer2 Token",
+ "value": "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJyb2xlcyI6WyJyZXZpZXdlciJdLCJpc3MiOiJodHRwczovL2FwaS50b3Bjb2Rlci1kZXYuY29tIiwiaGFuZGxlIjoicmV2aWV3ZXIyIiwiZXhwIjoxNzY2Mjg5MjQ2LCJ1c2VySWQiOiIxMjM1IiwiaWF0IjoxNDUwOTI5MjQ2LCJlbWFpbCI6bnVsbCwianRpIjoiMTM2OWM2MDAtZTBhMS00NTI1LWE3YzctNTZiZTdkODEzZjUxIn0.RrkQ7srca99ctABa_VM9VYediC2mcg4hPOiQ1Roou14",
+ "type": "text"
+ }
+ ],
+ "timestamp": 1507127109350,
+ "_postman_variable_scope": "environment",
+ "_postman_exported_at": "2017-10-04T14:29:09.546Z",
+ "_postman_exported_using": "Postman/4.10.7"
+}
diff --git a/service/pom.xml b/service/pom.xml
index 51aa367..89376b9 100644
--- a/service/pom.xml
+++ b/service/pom.xml
@@ -11,7 +11,7 @@
1.5.4
2.7.3
4.0.0
- 1.0.16-SNAPSHOT
+ 1.0.20-SNAPSHOT
@@ -220,7 +220,7 @@
com.appirio
ap-events-bus
- 0.0.4-SNAPSHOT
+ 0.0.1-SNAPSHOT
org.slf4j
@@ -242,12 +242,12 @@
appirio-repo
Appirio Maven Repository
- file:///mnt/maven/repository
+ file:///Users/qun/Desktop/temp-maven-repo-master
appirio-repo
Appirio Maven Repository
- file:///mnt/maven/repository
+ file:///Users/qun/Desktop/temp-maven-repo-master
@@ -294,26 +294,20 @@
+
+ 1_temp_appirio_maven_repo
+ Appirio Maven Local Repository
+ file:///Users/qun/Desktop/temp-maven-repo-master
+
com.springsource.repository.bundles.release
SpringSource Enterprise Bundle Repository - SpringSource Bundle Releases
http://repository.springsource.com/maven/bundles/release
-
com.springsource.repository.bundles.external
SpringSource Enterprise Bundle Repository - External Bundle Releases
http://repository.springsource.com/maven/bundles/external
-
- Appirio Technology Maven Repository
- http://maven.appirio.net:8080/
-
- always
-
-
- always
-
-
From 31e28ce9117b2f5fb963ef98ae6e1f9dab729fd4 Mon Sep 17 00:00:00 2001
From: Qun Huang
Date: Sat, 7 Oct 2017 02:04:32 +0800
Subject: [PATCH 02/19] updates to run the services locally
---
service/pom.xml | 8 ++++----
service/sql/populate-db-samples.sql | 2 +-
service/sql/review-process.sql | 2 +-
3 files changed, 6 insertions(+), 6 deletions(-)
mode change 100644 => 100755 service/sql/populate-db-samples.sql
mode change 100644 => 100755 service/sql/review-process.sql
diff --git a/service/pom.xml b/service/pom.xml
index 89376b9..96ae609 100644
--- a/service/pom.xml
+++ b/service/pom.xml
@@ -220,7 +220,7 @@
com.appirio
ap-events-bus
- 0.0.1-SNAPSHOT
+ 0.0.4-SNAPSHOT
org.slf4j
@@ -242,12 +242,12 @@
appirio-repo
Appirio Maven Repository
- file:///Users/qun/Desktop/temp-maven-repo-master
+ file:///mnt/maven/repository
appirio-repo
Appirio Maven Repository
- file:///Users/qun/Desktop/temp-maven-repo-master
+ file:///mnt/maven/repository
@@ -297,7 +297,7 @@
1_temp_appirio_maven_repo
Appirio Maven Local Repository
- file:///Users/qun/Desktop/temp-maven-repo-master
+ file:///mnt/maven/repository
com.springsource.repository.bundles.release
diff --git a/service/sql/populate-db-samples.sql b/service/sql/populate-db-samples.sql
old mode 100644
new mode 100755
index 5da42b3..84f4012
--- a/service/sql/populate-db-samples.sql
+++ b/service/sql/populate-db-samples.sql
@@ -394,4 +394,4 @@ INSERT INTO REVIEW_PROCESS (
'PEER',
'PEER',
1
-);
\ No newline at end of file
+);
diff --git a/service/sql/review-process.sql b/service/sql/review-process.sql
old mode 100644
new mode 100755
index 53afeb2..cf85813
--- a/service/sql/review-process.sql
+++ b/service/sql/review-process.sql
@@ -90,4 +90,4 @@ CREATE TABLE SCORECARD_ITEM (
FOREIGN KEY (scorecardId) references SCORECARD(id),
FOREIGN KEY (questionId) references SCORECARD_QUESTION(id),
FOREIGN KEY (questionOptionId) references SCORECARD_QUESTION_OPTION(id)
-);
\ No newline at end of file
+);
From 9dfa9b36e658ff5ab96b61342dd9bf0c2b827d48 Mon Sep 17 00:00:00 2001
From: Qun Huang
Date: Sat, 7 Oct 2017 12:49:16 +0800
Subject: [PATCH 03/19] update to use core.api 4.0.1-DEV
---
service/pom.xml | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/service/pom.xml b/service/pom.xml
index 96ae609..ce4fd3d 100644
--- a/service/pom.xml
+++ b/service/pom.xml
@@ -10,7 +10,7 @@
1.0.0
1.5.4
2.7.3
- 4.0.0
+ 4.0.1-DEV
1.0.20-SNAPSHOT
@@ -105,7 +105,7 @@
-
+
org.javassist
@@ -265,7 +265,7 @@
false
-
org.apache.maven.plugins
From 2a83d453940209a1c35b14029c8c7086e1570e22 Mon Sep 17 00:00:00 2001
From: Qun Huang
Date: Thu, 19 Oct 2017 10:43:31 -0700
Subject: [PATCH 04/19] add appirio dev repo
---
service/pom.xml | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/service/pom.xml b/service/pom.xml
index ce4fd3d..3ee3722 100644
--- a/service/pom.xml
+++ b/service/pom.xml
@@ -299,6 +299,16 @@
Appirio Maven Local Repository
file:///mnt/maven/repository
+
+ Appirio Technology Maven Repository
+ http://maven.topcoder-dev.com:8080/
+
+ always
+
+
+ always
+
+
com.springsource.repository.bundles.release
SpringSource Enterprise Bundle Repository - SpringSource Bundle Releases
From 2c4a4cc10e2ffded452bc99506a5720ba6b69389 Mon Sep 17 00:00:00 2001
From: Qun Huang
Date: Thu, 19 Oct 2017 11:07:26 -0700
Subject: [PATCH 05/19] new review services for admin app
---
local/run.sh | 11 +
...eview-microservice.postman_collection.json | 598 ++++-
...view-microservice.postman_environment.json | 14 +-
.../resourcefactory/ReviewFactory.java | 12 +-
.../appirio/service/review/api/AutoPilot.java | 20 +
.../appirio/service/review/api/Challenge.java | 35 +
.../manager/ReviewAuthorizationManager.java | 21 +-
.../service/review/dao/ChallengeDAO.java | 25 +
.../appirio/service/review/dao/ReviewDAO.java | 113 +-
.../review/manager/ChallengeManager.java | 40 +
.../service/review/manager/ReviewManager.java | 134 +-
.../review/resources/ReviewResource.java | 238 +-
.../appirio/service/review/util/Helper.java | 62 +
.../src/main/resources/new-relic-url-patterns | 7 +-
.../resources/sql/challenge/get-by-id.sql | 13 +
.../resources/sql/review/delete-review.sql | 5 +
.../resources/sql/review/reopen-review.sql | 1 +
.../sql/review/reset-aggregation.sql | 58 +
.../resources/sql/review/reset-review.sql | 36 +
.../resources/sql/review/update-autopilot.sql | 5 +
.../test/resources/ReviewResourceTest.java | 4 +-
swagger.yaml | 2161 +++++++++--------
22 files changed, 2571 insertions(+), 1042 deletions(-)
create mode 100755 local/run.sh
create mode 100644 service/src/main/java/com/appirio/service/review/api/AutoPilot.java
create mode 100644 service/src/main/java/com/appirio/service/review/api/Challenge.java
create mode 100644 service/src/main/java/com/appirio/service/review/dao/ChallengeDAO.java
create mode 100644 service/src/main/java/com/appirio/service/review/manager/ChallengeManager.java
create mode 100644 service/src/main/java/com/appirio/service/review/util/Helper.java
create mode 100644 service/src/main/resources/sql/challenge/get-by-id.sql
create mode 100644 service/src/main/resources/sql/review/delete-review.sql
create mode 100644 service/src/main/resources/sql/review/reopen-review.sql
create mode 100644 service/src/main/resources/sql/review/reset-aggregation.sql
create mode 100644 service/src/main/resources/sql/review/reset-review.sql
create mode 100644 service/src/main/resources/sql/review/update-autopilot.sql
diff --git a/local/run.sh b/local/run.sh
new file mode 100755
index 0000000..7d47abb
--- /dev/null
+++ b/local/run.sh
@@ -0,0 +1,11 @@
+export IP=192.168.1.2
+export OLTP_USER=informix
+export OLTP_PW=1nf0rm1x
+export OLTP_URL=jdbc:informix-sqli://$IP:2021/tcs_catalog:INFORMIXSERVER=informixoltp_tcp;IFX_LOCK_MODE_WAIT=5;OPTCOMPIND=0;STMT_CACHE=1
+export DW_USER=informix
+export DW_PW=1nf0rm1x
+export DW_URL=jdbc:informix-sqli://$IP:2021/common_dw:INFORMIXSERVER=informixoltp_tcp;IFX_LOCK_MODE_WAIT=5;OPTCOMPIND=0;STMT_CACHE=1
+export TC_JWT_KEY=secret
+
+
+java -jar ../service/target/review-microservice-*.jar server ../service/src/main/resources/review-service.yaml
\ No newline at end of file
diff --git a/postman/review-microservice.postman_collection.json b/postman/review-microservice.postman_collection.json
index 7546b96..b9a2646 100755
--- a/postman/review-microservice.postman_collection.json
+++ b/postman/review-microservice.postman_collection.json
@@ -2,11 +2,597 @@
"variables": [],
"info": {
"name": "review-microservice",
- "_postman_id": "6ebf34a8-a02f-658e-d692-ea743cb31056",
+ "_postman_id": "b6914582-b6ca-29d2-9b12-de70d5e4cb81",
"description": "",
"schema": "https://schema.getpostman.com/json/collection/v2.0.0/collection.json"
},
"item": [
+ {
+ "name": "Delete Review",
+ "description": "",
+ "item": [
+ {
+ "name": "Anonymous - Delete Review - 401",
+ "request": {
+ "url": "{{apiUrl}}/v3/reviews/71492",
+ "method": "DELETE",
+ "header": [],
+ "body": {
+ "mode": "raw",
+ "raw": ""
+ },
+ "description": ""
+ },
+ "response": []
+ },
+ {
+ "name": "Admin - Delete Review",
+ "request": {
+ "url": "{{apiUrl}}/v3/reviews/71492",
+ "method": "DELETE",
+ "header": [
+ {
+ "key": "Authorization",
+ "value": "{{Administrator Token}}",
+ "description": ""
+ },
+ {
+ "key": "Content-Type",
+ "value": "application/json",
+ "description": ""
+ }
+ ],
+ "body": {
+ "mode": "raw",
+ "raw": ""
+ },
+ "description": ""
+ },
+ "response": []
+ },
+ {
+ "name": "Admin - Delete Review - Not Found",
+ "request": {
+ "url": "{{apiUrl}}/v3/reviews/4582",
+ "method": "DELETE",
+ "header": [
+ {
+ "key": "Authorization",
+ "value": "{{Administrator Token}}",
+ "description": ""
+ },
+ {
+ "key": "Content-Type",
+ "value": "application/json",
+ "description": ""
+ }
+ ],
+ "body": {
+ "mode": "raw",
+ "raw": ""
+ },
+ "description": ""
+ },
+ "response": []
+ },
+ {
+ "name": "Non-Admin - Delete Review",
+ "request": {
+ "url": "{{apiUrl}}/v3/reviews/71492",
+ "method": "DELETE",
+ "header": [
+ {
+ "key": "Authorization",
+ "value": "{{Reviewer1 Token}}",
+ "description": ""
+ },
+ {
+ "key": "Content-Type",
+ "value": "application/json",
+ "description": ""
+ }
+ ],
+ "body": {
+ "mode": "raw",
+ "raw": ""
+ },
+ "description": ""
+ },
+ "response": []
+ }
+ ]
+ },
+ {
+ "name": "Re-open Review",
+ "description": "",
+ "item": [
+ {
+ "name": "Admin - Reopen Review",
+ "request": {
+ "url": "{{apiUrl}}/v3/reviews/71492/reopen",
+ "method": "POST",
+ "header": [
+ {
+ "key": "Authorization",
+ "value": "{{Administrator Token}}",
+ "description": ""
+ },
+ {
+ "key": "Content-Type",
+ "value": "application/json",
+ "description": ""
+ }
+ ],
+ "body": {
+ "mode": "raw",
+ "raw": ""
+ },
+ "description": ""
+ },
+ "response": []
+ },
+ {
+ "name": "Anonymous - Reopen Review - 401",
+ "request": {
+ "url": "{{apiUrl}}/v3/reviews/71492/reopen",
+ "method": "POST",
+ "header": [
+ {
+ "key": "Authorization",
+ "value": "{{Administrator Token}}",
+ "description": "",
+ "disabled": true
+ },
+ {
+ "key": "Content-Type",
+ "value": "application/json",
+ "description": ""
+ }
+ ],
+ "body": {
+ "mode": "raw",
+ "raw": ""
+ },
+ "description": ""
+ },
+ "response": []
+ },
+ {
+ "name": "Admin - Reopen Review - Not Found",
+ "request": {
+ "url": "{{apiUrl}}/v3/reviews/7452/reopen",
+ "method": "POST",
+ "header": [
+ {
+ "key": "Authorization",
+ "value": "{{Administrator Token}}",
+ "description": ""
+ },
+ {
+ "key": "Content-Type",
+ "value": "application/json",
+ "description": ""
+ }
+ ],
+ "body": {
+ "mode": "raw",
+ "raw": ""
+ },
+ "description": ""
+ },
+ "response": []
+ },
+ {
+ "name": "Non-Admin - Reopen Review",
+ "request": {
+ "url": "{{apiUrl}}/v3/reviews/71492/reopen",
+ "method": "POST",
+ "header": [
+ {
+ "key": "Authorization",
+ "value": "{{Reviewer1 Token}}",
+ "description": ""
+ },
+ {
+ "key": "Content-Type",
+ "value": "application/json",
+ "description": ""
+ }
+ ],
+ "body": {
+ "mode": "raw",
+ "raw": ""
+ },
+ "description": ""
+ },
+ "response": []
+ }
+ ]
+ },
+ {
+ "name": "Reset Aggregation",
+ "description": "",
+ "item": [
+ {
+ "name": "Admin - Reset Aggregation",
+ "request": {
+ "url": "{{apiUrl}}/v3/reviews/30005520/resetAggregation",
+ "method": "POST",
+ "header": [
+ {
+ "key": "Authorization",
+ "value": "{{Administrator Token}}",
+ "description": ""
+ },
+ {
+ "key": "Content-Type",
+ "value": "application/json",
+ "description": ""
+ }
+ ],
+ "body": {
+ "mode": "raw",
+ "raw": ""
+ },
+ "description": ""
+ },
+ "response": []
+ },
+ {
+ "name": "Non Admin - Reset Aggregation",
+ "request": {
+ "url": "{{apiUrl}}/v3/reviews/30005520/resetAggregation",
+ "method": "POST",
+ "header": [
+ {
+ "key": "Authorization",
+ "value": "{{Reviewer1 Token}}",
+ "description": ""
+ },
+ {
+ "key": "Content-Type",
+ "value": "application/json",
+ "description": ""
+ }
+ ],
+ "body": {
+ "mode": "raw",
+ "raw": ""
+ },
+ "description": ""
+ },
+ "response": []
+ },
+ {
+ "name": "Anonymous - Reset Aggregation - 401",
+ "request": {
+ "url": "{{apiUrl}}/v3/reviews/30005520/resetAggregation",
+ "method": "POST",
+ "header": [
+ {
+ "key": "Authorization",
+ "value": "{{Administrator Token}}",
+ "description": "",
+ "disabled": true
+ },
+ {
+ "key": "Content-Type",
+ "value": "application/json",
+ "description": ""
+ }
+ ],
+ "body": {
+ "mode": "raw",
+ "raw": ""
+ },
+ "description": ""
+ },
+ "response": []
+ },
+ {
+ "name": "Admin - Reset Aggregation - Not Found",
+ "request": {
+ "url": "{{apiUrl}}/v3/reviews/13/resetAggregation",
+ "method": "POST",
+ "header": [
+ {
+ "key": "Authorization",
+ "value": "{{Administrator Token}}",
+ "description": ""
+ },
+ {
+ "key": "Content-Type",
+ "value": "application/json",
+ "description": ""
+ }
+ ],
+ "body": {
+ "mode": "raw",
+ "raw": ""
+ },
+ "description": ""
+ },
+ "response": []
+ },
+ {
+ "name": "Admin - Reset Aggregation - Challenge Not Active - 400",
+ "request": {
+ "url": "{{apiUrl}}/v3/reviews/11/resetAggregation",
+ "method": "POST",
+ "header": [
+ {
+ "key": "Authorization",
+ "value": "{{Administrator Token}}",
+ "description": ""
+ },
+ {
+ "key": "Content-Type",
+ "value": "application/json",
+ "description": ""
+ }
+ ],
+ "body": {
+ "mode": "raw",
+ "raw": ""
+ },
+ "description": ""
+ },
+ "response": []
+ }
+ ]
+ },
+ {
+ "name": "Reset Review",
+ "description": "",
+ "item": [
+ {
+ "name": "Admin - Reset Review",
+ "request": {
+ "url": "{{apiUrl}}/v3/reviews/30005520/resetReview",
+ "method": "POST",
+ "header": [
+ {
+ "key": "Authorization",
+ "value": "{{Administrator Token}}",
+ "description": ""
+ },
+ {
+ "key": "Content-Type",
+ "value": "application/json",
+ "description": ""
+ }
+ ],
+ "body": {
+ "mode": "raw",
+ "raw": ""
+ },
+ "description": ""
+ },
+ "response": []
+ },
+ {
+ "name": "Admin - Reset Review - Not Found",
+ "request": {
+ "url": "{{apiUrl}}/v3/reviews/30005520/resetReview",
+ "method": "POST",
+ "header": [
+ {
+ "key": "Authorization",
+ "value": "{{Administrator Token}}",
+ "description": ""
+ },
+ {
+ "key": "Content-Type",
+ "value": "application/json",
+ "description": ""
+ }
+ ],
+ "body": {
+ "mode": "raw",
+ "raw": ""
+ },
+ "description": ""
+ },
+ "response": []
+ },
+ {
+ "name": "Non Admin - Reset Review",
+ "request": {
+ "url": "{{apiUrl}}/v3/reviews/30005520/resetReview",
+ "method": "POST",
+ "header": [
+ {
+ "key": "Authorization",
+ "value": "{{Reviewer1 Token}}",
+ "description": ""
+ },
+ {
+ "key": "Content-Type",
+ "value": "application/json",
+ "description": ""
+ }
+ ],
+ "body": {
+ "mode": "raw",
+ "raw": ""
+ },
+ "description": ""
+ },
+ "response": []
+ },
+ {
+ "name": "Anonymous - Reset Review - Unauthorized - 401",
+ "request": {
+ "url": "{{apiUrl}}/v3/reviews/30005520/resetReview",
+ "method": "POST",
+ "header": [
+ {
+ "key": "Content-Type",
+ "value": "application/json",
+ "description": ""
+ }
+ ],
+ "body": {
+ "mode": "raw",
+ "raw": ""
+ },
+ "description": ""
+ },
+ "response": []
+ }
+ ]
+ },
+ {
+ "name": "Update Autopilot",
+ "description": "",
+ "item": [
+ {
+ "name": "Admin - Enable Autopilot",
+ "request": {
+ "url": "{{apiUrl}}/v3/reviews/30005520/updateAutopilot",
+ "method": "POST",
+ "header": [
+ {
+ "key": "Authorization",
+ "value": "{{Administrator Token}}",
+ "description": ""
+ },
+ {
+ "key": "Content-Type",
+ "value": "application/json",
+ "description": ""
+ }
+ ],
+ "body": {
+ "mode": "raw",
+ "raw": "{\n \"param\" : {\n \t\"enable\" : true\n }\n \n}"
+ },
+ "description": ""
+ },
+ "response": []
+ },
+ {
+ "name": "Admin - Enable Autopilot - Bad Request - 400",
+ "request": {
+ "url": "{{apiUrl}}/v3/reviews/30005520/updateAutopilot",
+ "method": "POST",
+ "header": [
+ {
+ "key": "Authorization",
+ "value": "{{Administrator Token}}",
+ "description": ""
+ },
+ {
+ "key": "Content-Type",
+ "value": "application/json",
+ "description": ""
+ }
+ ],
+ "body": {
+ "mode": "raw",
+ "raw": "{\n \"param\" : {\n \t\"enable\" : \n }\n \n}"
+ },
+ "description": ""
+ },
+ "response": []
+ },
+ {
+ "name": "Admin - Disable Autopilot",
+ "request": {
+ "url": "{{apiUrl}}/v3/reviews/30005520/updateAutopilot",
+ "method": "POST",
+ "header": [
+ {
+ "key": "Authorization",
+ "value": "{{Administrator Token}}",
+ "description": ""
+ },
+ {
+ "key": "Content-Type",
+ "value": "application/json",
+ "description": ""
+ }
+ ],
+ "body": {
+ "mode": "raw",
+ "raw": "{\n \"param\" : {\n \t\"enable\" : false\n }\n \n}"
+ },
+ "description": ""
+ },
+ "response": []
+ },
+ {
+ "name": "Non Admin - Enable Autopilot",
+ "request": {
+ "url": "{{apiUrl}}/v3/reviews/30005520/updateAutopilot",
+ "method": "POST",
+ "header": [
+ {
+ "key": "Authorization",
+ "value": "{{Reviewer1 Token}}",
+ "description": ""
+ },
+ {
+ "key": "Content-Type",
+ "value": "application/json",
+ "description": ""
+ }
+ ],
+ "body": {
+ "mode": "raw",
+ "raw": "{\n \"param\" : {\n \t\"enable\" : true\n }\n \n}"
+ },
+ "description": ""
+ },
+ "response": []
+ },
+ {
+ "name": "Anonymous - Enable Autopilot - Unauthorized - 401",
+ "request": {
+ "url": "{{apiUrl}}/v3/reviews/30005520/updateAutopilot",
+ "method": "POST",
+ "header": [
+ {
+ "key": "Content-Type",
+ "value": "application/json",
+ "description": ""
+ }
+ ],
+ "body": {
+ "mode": "raw",
+ "raw": "{\n \"param\" : {\n \t\"enable\" : true\n }\n \n}"
+ },
+ "description": ""
+ },
+ "response": []
+ },
+ {
+ "name": "Admin - Enable Autopilot - Not Found",
+ "request": {
+ "url": "{{apiUrl}}/v3/reviews/13/updateAutopilot",
+ "method": "POST",
+ "header": [
+ {
+ "key": "Authorization",
+ "value": "{{Administrator Token}}",
+ "description": ""
+ },
+ {
+ "key": "Content-Type",
+ "value": "application/json",
+ "description": ""
+ }
+ ],
+ "body": {
+ "mode": "raw",
+ "raw": "{\n \"param\" : {\n \t\"enable\" : true\n }\n \n}"
+ },
+ "description": ""
+ },
+ "response": []
+ }
+ ]
+ },
{
"name": "Get list of all Scorecards",
"request": {
@@ -44,7 +630,10 @@
"description": ""
}
],
- "body": {},
+ "body": {
+ "mode": "raw",
+ "raw": ""
+ },
"description": ""
},
"response": []
@@ -66,7 +655,10 @@
"description": ""
}
],
- "body": {},
+ "body": {
+ "mode": "raw",
+ "raw": ""
+ },
"description": ""
},
"response": []
diff --git a/postman/review-microservice.postman_environment.json b/postman/review-microservice.postman_environment.json
index 10b6eaf..748b0f3 100755
--- a/postman/review-microservice.postman_environment.json
+++ b/postman/review-microservice.postman_environment.json
@@ -1,5 +1,5 @@
{
- "id": "0e76601a-1e30-b51c-a3d4-daf7bcb2ab94",
+ "id": "de37a461-f5ae-23ea-9c06-fdf7e8e05622",
"name": "review-microservice",
"values": [
{
@@ -19,10 +19,16 @@
"key": "Reviewer2 Token",
"value": "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJyb2xlcyI6WyJyZXZpZXdlciJdLCJpc3MiOiJodHRwczovL2FwaS50b3Bjb2Rlci1kZXYuY29tIiwiaGFuZGxlIjoicmV2aWV3ZXIyIiwiZXhwIjoxNzY2Mjg5MjQ2LCJ1c2VySWQiOiIxMjM1IiwiaWF0IjoxNDUwOTI5MjQ2LCJlbWFpbCI6bnVsbCwianRpIjoiMTM2OWM2MDAtZTBhMS00NTI1LWE3YzctNTZiZTdkODEzZjUxIn0.RrkQ7srca99ctABa_VM9VYediC2mcg4hPOiQ1Roou14",
"type": "text"
+ },
+ {
+ "enabled": true,
+ "key": "Administrator Token",
+ "value": "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJyb2xlcyI6WyJhZG1pbmlzdHJhdG9yIl0sImlzcyI6Imh0dHBzOi8vYXBpLnRvcGNvZGVyLWRldi5jb20iLCJoYW5kbGUiOiJhZG1pbiIsImV4cCI6MTc2NjI4OTI0NiwidXNlcklkIjoiNTU1NSIsImlhdCI6MTQ1MDkyOTI0NiwiZW1haWwiOm51bGwsImp0aSI6IjEzNjljNjAwLWUwYTEtNDUyNS1hN2M3LTU2YmU3ZDgxM2Y1MSJ9.Wg4nPCva9opNyrYQTngSoXetXr-W-ZSDtD2jae1gswk",
+ "type": "text"
}
],
- "timestamp": 1507127109350,
+ "timestamp": 1507999856202,
"_postman_variable_scope": "environment",
- "_postman_exported_at": "2017-10-04T14:29:09.546Z",
- "_postman_exported_using": "Postman/4.10.7"
+ "_postman_exported_at": "2017-10-14T21:32:17.437Z",
+ "_postman_exported_using": "Postman/5.3.0"
}
diff --git a/service/src/main/java/com/appirio/service/resourcefactory/ReviewFactory.java b/service/src/main/java/com/appirio/service/resourcefactory/ReviewFactory.java
index 9abab88..3b126d7 100644
--- a/service/src/main/java/com/appirio/service/resourcefactory/ReviewFactory.java
+++ b/service/src/main/java/com/appirio/service/resourcefactory/ReviewFactory.java
@@ -3,6 +3,7 @@
import io.dropwizard.setup.Environment;
import com.appirio.service.review.ReviewServiceConfiguration;
+import com.appirio.service.review.manager.ChallengeManager;
import com.appirio.service.review.manager.ReviewManager;
import com.appirio.service.review.resources.ReviewResource;
import com.appirio.service.supply.resources.ResourceFactory;
@@ -10,8 +11,12 @@
/**
* Factory for ReviewResource
- *
- * @author rrecharla@appirio.com
+ *
+ * v1.1 Updates : https://www.topcoder.com/challenge-details/30059779/?type=develop
+ * Updated getResourceInstance() to set the ChallengeManager field.
+ *
+ * @author rrecharla@appirio.com, TCSCODE
+ * @version 1.1
*/
public class ReviewFactory implements ResourceFactory {
@@ -43,6 +48,7 @@ public ReviewFactory(ReviewServiceConfiguration config, Environment env) {
@Override
public ReviewResource getResourceInstance() throws SupplyException {
final ReviewManager reviewManager = new ReviewManager();
- return new ReviewResource(reviewManager);
+ final ChallengeManager challengeManager = new ChallengeManager();
+ return new ReviewResource(reviewManager, challengeManager);
}
}
diff --git a/service/src/main/java/com/appirio/service/review/api/AutoPilot.java b/service/src/main/java/com/appirio/service/review/api/AutoPilot.java
new file mode 100644
index 0000000..7b22a8a
--- /dev/null
+++ b/service/src/main/java/com/appirio/service/review/api/AutoPilot.java
@@ -0,0 +1,20 @@
+package com.appirio.service.review.api;
+
+import javax.validation.constraints.NotNull;
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+
+/**
+ * This class represents a challenge instance
+ */
+@AllArgsConstructor
+@NoArgsConstructor
+@Getter
+@Setter
+public class AutoPilot {
+ @NotNull
+ private Boolean enable;
+}
\ No newline at end of file
diff --git a/service/src/main/java/com/appirio/service/review/api/Challenge.java b/service/src/main/java/com/appirio/service/review/api/Challenge.java
new file mode 100644
index 0000000..eafa289
--- /dev/null
+++ b/service/src/main/java/com/appirio/service/review/api/Challenge.java
@@ -0,0 +1,35 @@
+package com.appirio.service.review.api;
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+
+/**
+ * This class represents a challenge instance
+ */
+@AllArgsConstructor
+@NoArgsConstructor
+@Getter
+@Setter
+public class Challenge {
+ /**
+ * The challenge id.
+ */
+ private Long id;
+
+ /**
+ * The challenge name.
+ */
+ private String name;
+
+ /**
+ * The challenge status.
+ */
+ private String status;
+
+ /**
+ * The challenge current active phase.
+ */
+ private String activePhase;
+}
\ No newline at end of file
diff --git a/service/src/main/java/com/appirio/service/review/authorization/manager/ReviewAuthorizationManager.java b/service/src/main/java/com/appirio/service/review/authorization/manager/ReviewAuthorizationManager.java
index ec05fd4..8346f8f 100644
--- a/service/src/main/java/com/appirio/service/review/authorization/manager/ReviewAuthorizationManager.java
+++ b/service/src/main/java/com/appirio/service/review/authorization/manager/ReviewAuthorizationManager.java
@@ -11,9 +11,16 @@
* Review authorization manager
*
* @see AuthorizationManager
+ *
+ * v1.1 (ADMIN APP CHALLENGE FEE AND REVIEW MANAGEMENT API)
+ *
+ * - Updated canRead() to allow the administrator to read a review
+ * - Updated canReadWriteDelete() to allow administrator to delete reviews
+ *
+ *
*
- * @author mdesiderio@appirio.com
- *
+ * @author mdesiderio@appirio.com, TCSCODER
+ * @version 1.1
*/
public class ReviewAuthorizationManager extends AuthorizationManager {
@@ -91,7 +98,8 @@ public boolean canRead(Review model, AuthorizationContext context) {
// -- The user is the reviewer resource
// -- The user is the submitter and the review is committed
return principalIsReviewer(model, context)
- || (principalIsSubmitter(model, context) && reviewIsCommitted(model));
+ || (principalIsSubmitter(model, context) && reviewIsCommitted(model))
+ || context.getPrincipal().hasRole("administrator");
}
/**
@@ -119,10 +127,7 @@ public boolean canReadWrite(Review model, AuthorizationContext context) {
*/
@Override
public boolean canReadWriteDelete(Review model, AuthorizationContext context) {
- // Only administrators can delete reviews, and this functionality is not
- // yet implemented in the
- // review microservice
- return false;
+ // Only administrators are allowed to delete reviews.
+ return context.getPrincipal().hasRole("administrator");
}
-
}
diff --git a/service/src/main/java/com/appirio/service/review/dao/ChallengeDAO.java b/service/src/main/java/com/appirio/service/review/dao/ChallengeDAO.java
new file mode 100644
index 0000000..cf50dd3
--- /dev/null
+++ b/service/src/main/java/com/appirio/service/review/dao/ChallengeDAO.java
@@ -0,0 +1,25 @@
+package com.appirio.service.review.dao;
+
+import org.skife.jdbi.v2.sqlobject.Bind;
+import com.appirio.service.review.api.Challenge;
+import com.appirio.supply.dataaccess.DatasourceName;
+import com.appirio.supply.dataaccess.SqlQueryFile;
+
+/**
+ * DAO to access challenge related data
+ *
+ * @author TCSCODER
+ * @version 1.0
+ */
+@DatasourceName("oltp")
+public interface ChallengeDAO {
+
+ /**
+ * Get a challenge by id.
+ *
+ * @param challengeId the id of the challenge to retrieve.
+ * @return The Challenge instance
+ */
+ @SqlQueryFile("sql/challenge/get-by-id.sql")
+ Challenge getChallenge(@Bind("challengeId") Long challengeId);
+}
\ No newline at end of file
diff --git a/service/src/main/java/com/appirio/service/review/dao/ReviewDAO.java b/service/src/main/java/com/appirio/service/review/dao/ReviewDAO.java
index f264ee4..082e3a2 100644
--- a/service/src/main/java/com/appirio/service/review/dao/ReviewDAO.java
+++ b/service/src/main/java/com/appirio/service/review/dao/ReviewDAO.java
@@ -18,13 +18,24 @@
import java.util.Map;
/**
- * DAO to handle review data
+ * DAO to handle review data.
+ *
+ *
+ * Version 1.1 (ADMIN APP CHALLENGE FEE AND REVIEW MANAGEMENT API)
+ *
+ * - Added method resetAggregation()
+ * - Added method resetReview()
+ * - Added method updateAutoPilot()
+ * - Added method reopenReview()
+ * - Added method deleteReview()
+ *
+ *
*
- * @author mdesiderio@appirio.com
+ * @author mdesiderio@appirio.com, TCSCODER
+ * @version 1.1
*/
@DatasourceName("oltp")
public interface ReviewDAO {
-
/**
* Get a single review by id. Authenticated version to be invoked by
* managers / resources
@@ -35,8 +46,7 @@ public interface ReviewDAO {
*/
@AuthManager(ReviewAuthorizationManager.class)
@SqlQueryFile("sql/review/review-by-id-query.sql")
- Review getReview(@Bind("reviewId") Long reviewId,
- @AuthContext AuthorizationContext authContext);
+ Review getReview(@Bind("reviewId") Long reviewId, @AuthContext AuthorizationContext authContext);
/**
* Get a single review by id. Unauthenticated version for internal use
@@ -49,16 +59,15 @@ Review getReview(@Bind("reviewId") Long reviewId,
// TODO: document this
@SqlUpdateFile("sql/review/review-update.sql")
- void updateReview(@Audit @Validate @BindBean Review review,
- @AuditActionPerformer @Bind("userId") Long userId);
+ void updateReview(@Audit @Validate @BindBean Review review, @AuditActionPerformer @Bind("userId") Long userId);
// TODO: document this
// TODO: Test this
@SqlUpdateFile("sql/review/review-update-user-editable-fields.sql")
void updateReviewUserEditableFields(
- @AuthManager(ReviewAuthorizationManager.class) @Audit @Validate @BindBean Review review,
- @AuditActionPerformer @Bind("userId") Long userId,
- @AuthContext AuthorizationContext authContext);
+ @AuthManager(ReviewAuthorizationManager.class) @Audit @Validate @BindBean Review review,
+ @AuditActionPerformer @Bind("userId") Long userId,
+ @AuthContext AuthorizationContext authContext);
/**
* Creates a new review
@@ -67,8 +76,7 @@ void updateReviewUserEditableFields(
* @param userId user id
*/
@SqlUpdateFile("sql/review/review-insert.sql")
- void createReview(@Audit @Validate @BindBean Review review,
- @AuditActionPerformer @Bind("userId") Long userId);
+ void createReview(@Audit @Validate @BindBean Review review, @AuditActionPerformer @Bind("userId") Long userId);
/**
* For a given user and a given challenge, returns the counts of how many
@@ -79,8 +87,7 @@ void createReview(@Audit @Validate @BindBean Review review,
* @return returns counts of pending, submitted and total reviews
*/
@SqlQueryFile("sql/review/user-review-count-query.sql")
- Map getUserReviewsCount(@Bind("userId") Long userId,
- @Bind("challengeId") Long challengeId);
+ Map getUserReviewsCount(@Bind("userId") Long userId, @Bind("challengeId") Long challengeId);
/**
* Submissions associated with a challenge, not reviewed by the user, not
@@ -95,9 +102,8 @@ Map getUserReviewsCount(@Bind("userId") Long userId,
* @return list of submissions
*/
@SqlQueryFile("sql/review/next-submission-to-review-by-required-reviews-query.sql")
- List