From 39105772364f251aa3397d1db9696639eea178b5 Mon Sep 17 00:00:00 2001 From: Neil Winton Date: Wed, 22 May 2019 10:35:06 +0200 Subject: [PATCH] Initial commit --- .gitignore | 9 + .travis.yml | 149 +++++++++++++++ applications/allocations-server/build.gradle | 5 + .../pivotal/pal/tracker/allocations/App.java | 29 +++ .../src/main/resources/application.properties | 6 + .../allocations/AllocationsAppTest.java | 19 ++ .../src/test/resources/application.properties | 6 + applications/backlog-server/build.gradle | 5 + .../io/pivotal/pal/tracker/backlog/App.java | 29 +++ .../src/main/resources/application.properties | 6 + .../pal/tracker/backlog/BacklogAppTest.java | 19 ++ .../src/test/resources/application.properties | 6 + applications/registration-server/build.gradle | 7 + .../pivotal/pal/tracker/registration/App.java | 23 +++ .../src/main/resources/application.properties | 6 + .../registration/RegistrationAppTest.java | 22 +++ .../src/test/resources/application.properties | 6 + applications/server.gradle | 14 ++ applications/timesheets-server/build.gradle | 5 + .../pivotal/pal/tracker/timesheets/App.java | 29 +++ .../src/main/resources/application.properties | 6 + .../tracker/timesheets/TimesheetsAppTest.java | 19 ++ .../src/test/resources/application.properties | 6 + build.gradle | 59 ++++++ buildSrc/build.gradle | 7 + .../gradlebuild/CfMigrationPlugin.groovy | 123 +++++++++++++ .../gradlebuild/DatabasesExtension.groovy | 8 + .../DependenciesGraphPlugin.groovy | 66 +++++++ .../gradlebuild/LocalMigrationPlugin.groovy | 46 +++++ components/accounts/build.gradle | 7 + .../tracker/accounts/AccountController.java | 39 ++++ .../pal/tracker/accounts/AccountInfo.java | 88 +++++++++ .../accounts/RegistrationController.java | 22 +++ .../tracker/accounts/RegistrationForm.java | 36 ++++ .../tracker/accounts/RegistrationService.java | 26 +++ .../accounts/data/AccountDataGateway.java | 54 ++++++ .../tracker/accounts/data/AccountRecord.java | 72 ++++++++ .../accounts/AccountControllerTest.java | 45 +++++ .../accounts/RegistrationControllerTest.java | 31 ++++ .../accounts/RegistrationServiceTest.java | 32 ++++ .../accounts/data/AccountDataGatewayTest.java | 62 +++++++ components/allocations/build.gradle | 6 + .../allocations/AllocationController.java | 75 ++++++++ .../tracker/allocations/AllocationForm.java | 89 +++++++++ .../tracker/allocations/AllocationInfo.java | 112 ++++++++++++ .../tracker/allocations/ProjectClient.java | 18 ++ .../pal/tracker/allocations/ProjectInfo.java | 37 ++++ .../data/AllocationDataGateway.java | 67 +++++++ .../allocations/data/AllocationFields.java | 87 +++++++++ .../allocations/data/AllocationRecord.java | 98 ++++++++++ .../allocations/AllocationControllerTest.java | 93 ++++++++++ .../AllocationDataGatewayTest.java | 74 ++++++++ .../pal/tracker/allocations/TestBuilders.java | 51 ++++++ components/backlog/build.gradle | 6 + .../pal/tracker/backlog/ProjectClient.java | 18 ++ .../pal/tracker/backlog/ProjectInfo.java | 37 ++++ .../pal/tracker/backlog/StoryController.java | 66 +++++++ .../pal/tracker/backlog/StoryForm.java | 66 +++++++ .../pal/tracker/backlog/StoryInfo.java | 89 +++++++++ .../backlog/data/StoryDataGateway.java | 61 +++++++ .../pal/tracker/backlog/data/StoryFields.java | 61 +++++++ .../pal/tracker/backlog/data/StoryRecord.java | 72 ++++++++ .../tracker/backlog/StoryControllerTest.java | 98 ++++++++++ .../pal/tracker/backlog/TestBuilders.java | 41 +++++ .../backlog/data/StoryDataGatewayTest.java | 66 +++++++ components/build.gradle | 2 + components/projects/build.gradle | 6 + .../tracker/projects/ProjectController.java | 69 +++++++ .../pal/tracker/projects/ProjectForm.java | 76 ++++++++ .../pal/tracker/projects/ProjectInfo.java | 99 ++++++++++ .../projects/data/ProjectDataGateway.java | 69 +++++++ .../tracker/projects/data/ProjectFields.java | 74 ++++++++ .../tracker/projects/data/ProjectRecord.java | 84 +++++++++ .../projects/ProjectControllerTest.java | 81 +++++++++ .../projects/ProjectDataGatewayTest.java | 79 ++++++++ .../pal/tracker/projects/TestBuilders.java | 45 +++++ components/rest-support/build.gradle | 4 + .../pal/tracker/restsupport/RestConfig.java | 25 +++ .../restsupport/SpringDefaultController.java | 13 ++ components/test-support/build.gradle | 6 + .../testsupport/TestDataSourceFactory.java | 18 ++ .../testsupport/TestScenarioSupport.java | 33 ++++ components/timesheets/build.gradle | 6 + .../pal/tracker/timesheets/ProjectClient.java | 18 ++ .../pal/tracker/timesheets/ProjectInfo.java | 37 ++++ .../timesheets/TimeEntryController.java | 71 ++++++++ .../pal/tracker/timesheets/TimeEntryForm.java | 92 ++++++++++ .../pal/tracker/timesheets/TimeEntryInfo.java | 109 +++++++++++ .../timesheets/data/TimeEntryDataGateway.java | 66 +++++++ .../timesheets/data/TimeEntryFields.java | 86 +++++++++ .../timesheets/data/TimeEntryRecord.java | 97 ++++++++++ .../pal/tracker/timesheets/TestBuilders.java | 51 ++++++ .../timesheets/TimeEntryControllerTest.java | 78 ++++++++ .../timesheets/TimeEntryDataGatewayTest.java | 75 ++++++++ components/users/build.gradle | 5 + .../pal/tracker/users/UserController.java | 31 ++++ .../pivotal/pal/tracker/users/UserInfo.java | 49 +++++ .../tracker/users/data/UserDataGateway.java | 50 +++++ .../pal/tracker/users/data/UserRecord.java | 39 ++++ .../pal/tracker/users/UserControllerTest.java | 27 +++ .../users/data/UserDataGatewayTest.java | 57 ++++++ databases/allocations-database/build.gradle | 6 + .../migrations/V1__initial_schema.sql | 11 ++ databases/backlog-database/build.gradle | 6 + .../migrations/V1__initial_schema.sql | 9 + databases/build.gradle | 7 + databases/create_databases.sql | 21 +++ databases/registration-database/build.gradle | 6 + .../migrations/V1__initial_schema.sql | 34 ++++ databases/timesheets-database/build.gradle | 6 + .../migrations/V1__initial_schema.sql | 11 ++ gradle.properties | 4 + gradle/wrapper/gradle-wrapper.jar | Bin 0 -> 55741 bytes gradle/wrapper/gradle-wrapper.properties | 5 + gradlew | 172 ++++++++++++++++++ gradlew.bat | 84 +++++++++ integration-test/build.gradle | 10 + .../test/pivotal/pal/tracker/FlowTest.java | 159 ++++++++++++++++ .../tracker/support/ApplicationServer.java | 80 ++++++++ .../pal/tracker/support/HttpClient.java | 67 +++++++ .../pal/tracker/support/MapBuilder.java | 26 +++ .../pivotal/pal/tracker/support/Response.java | 19 ++ manifest-allocations.yml | 12 ++ manifest-backlog.yml | 12 ++ manifest-registration.yml | 11 ++ manifest-timesheets.yml | 12 ++ requests.http | 49 +++++ settings.gradle | 23 +++ 128 files changed, 5431 insertions(+) create mode 100644 .gitignore create mode 100644 .travis.yml create mode 100644 applications/allocations-server/build.gradle create mode 100644 applications/allocations-server/src/main/java/io/pivotal/pal/tracker/allocations/App.java create mode 100644 applications/allocations-server/src/main/resources/application.properties create mode 100644 applications/allocations-server/src/test/java/test/pivotal/pal/tracker/allocations/AllocationsAppTest.java create mode 100644 applications/allocations-server/src/test/resources/application.properties create mode 100644 applications/backlog-server/build.gradle create mode 100644 applications/backlog-server/src/main/java/io/pivotal/pal/tracker/backlog/App.java create mode 100644 applications/backlog-server/src/main/resources/application.properties create mode 100644 applications/backlog-server/src/test/java/test/pivotal/pal/tracker/backlog/BacklogAppTest.java create mode 100644 applications/backlog-server/src/test/resources/application.properties create mode 100644 applications/registration-server/build.gradle create mode 100644 applications/registration-server/src/main/java/io/pivotal/pal/tracker/registration/App.java create mode 100644 applications/registration-server/src/main/resources/application.properties create mode 100644 applications/registration-server/src/test/java/test/pivotal/pal/tracker/registration/RegistrationAppTest.java create mode 100644 applications/registration-server/src/test/resources/application.properties create mode 100644 applications/server.gradle create mode 100644 applications/timesheets-server/build.gradle create mode 100644 applications/timesheets-server/src/main/java/io/pivotal/pal/tracker/timesheets/App.java create mode 100644 applications/timesheets-server/src/main/resources/application.properties create mode 100644 applications/timesheets-server/src/test/java/test/pivotal/pal/tracker/timesheets/TimesheetsAppTest.java create mode 100644 applications/timesheets-server/src/test/resources/application.properties create mode 100644 build.gradle create mode 100644 buildSrc/build.gradle create mode 100644 buildSrc/src/main/groovy/io/pivotal/pal/tracker/gradlebuild/CfMigrationPlugin.groovy create mode 100644 buildSrc/src/main/groovy/io/pivotal/pal/tracker/gradlebuild/DatabasesExtension.groovy create mode 100644 buildSrc/src/main/groovy/io/pivotal/pal/tracker/gradlebuild/DependenciesGraphPlugin.groovy create mode 100644 buildSrc/src/main/groovy/io/pivotal/pal/tracker/gradlebuild/LocalMigrationPlugin.groovy create mode 100644 components/accounts/build.gradle create mode 100644 components/accounts/src/main/java/io/pivotal/pal/tracker/accounts/AccountController.java create mode 100644 components/accounts/src/main/java/io/pivotal/pal/tracker/accounts/AccountInfo.java create mode 100644 components/accounts/src/main/java/io/pivotal/pal/tracker/accounts/RegistrationController.java create mode 100644 components/accounts/src/main/java/io/pivotal/pal/tracker/accounts/RegistrationForm.java create mode 100644 components/accounts/src/main/java/io/pivotal/pal/tracker/accounts/RegistrationService.java create mode 100644 components/accounts/src/main/java/io/pivotal/pal/tracker/accounts/data/AccountDataGateway.java create mode 100644 components/accounts/src/main/java/io/pivotal/pal/tracker/accounts/data/AccountRecord.java create mode 100644 components/accounts/src/test/java/test/pivotal/pal/tracker/accounts/AccountControllerTest.java create mode 100644 components/accounts/src/test/java/test/pivotal/pal/tracker/accounts/RegistrationControllerTest.java create mode 100644 components/accounts/src/test/java/test/pivotal/pal/tracker/accounts/RegistrationServiceTest.java create mode 100644 components/accounts/src/test/java/test/pivotal/pal/tracker/accounts/data/AccountDataGatewayTest.java create mode 100644 components/allocations/build.gradle create mode 100644 components/allocations/src/main/java/io/pivotal/pal/tracker/allocations/AllocationController.java create mode 100644 components/allocations/src/main/java/io/pivotal/pal/tracker/allocations/AllocationForm.java create mode 100644 components/allocations/src/main/java/io/pivotal/pal/tracker/allocations/AllocationInfo.java create mode 100644 components/allocations/src/main/java/io/pivotal/pal/tracker/allocations/ProjectClient.java create mode 100644 components/allocations/src/main/java/io/pivotal/pal/tracker/allocations/ProjectInfo.java create mode 100644 components/allocations/src/main/java/io/pivotal/pal/tracker/allocations/data/AllocationDataGateway.java create mode 100644 components/allocations/src/main/java/io/pivotal/pal/tracker/allocations/data/AllocationFields.java create mode 100644 components/allocations/src/main/java/io/pivotal/pal/tracker/allocations/data/AllocationRecord.java create mode 100644 components/allocations/src/test/java/test/pivotal/pal/tracker/allocations/AllocationControllerTest.java create mode 100644 components/allocations/src/test/java/test/pivotal/pal/tracker/allocations/AllocationDataGatewayTest.java create mode 100644 components/allocations/src/test/java/test/pivotal/pal/tracker/allocations/TestBuilders.java create mode 100644 components/backlog/build.gradle create mode 100644 components/backlog/src/main/java/io/pivotal/pal/tracker/backlog/ProjectClient.java create mode 100644 components/backlog/src/main/java/io/pivotal/pal/tracker/backlog/ProjectInfo.java create mode 100644 components/backlog/src/main/java/io/pivotal/pal/tracker/backlog/StoryController.java create mode 100644 components/backlog/src/main/java/io/pivotal/pal/tracker/backlog/StoryForm.java create mode 100644 components/backlog/src/main/java/io/pivotal/pal/tracker/backlog/StoryInfo.java create mode 100644 components/backlog/src/main/java/io/pivotal/pal/tracker/backlog/data/StoryDataGateway.java create mode 100644 components/backlog/src/main/java/io/pivotal/pal/tracker/backlog/data/StoryFields.java create mode 100644 components/backlog/src/main/java/io/pivotal/pal/tracker/backlog/data/StoryRecord.java create mode 100644 components/backlog/src/test/java/test/pivotal/pal/tracker/backlog/StoryControllerTest.java create mode 100644 components/backlog/src/test/java/test/pivotal/pal/tracker/backlog/TestBuilders.java create mode 100644 components/backlog/src/test/java/test/pivotal/pal/tracker/backlog/data/StoryDataGatewayTest.java create mode 100644 components/build.gradle create mode 100644 components/projects/build.gradle create mode 100644 components/projects/src/main/java/io/pivotal/pal/tracker/projects/ProjectController.java create mode 100644 components/projects/src/main/java/io/pivotal/pal/tracker/projects/ProjectForm.java create mode 100644 components/projects/src/main/java/io/pivotal/pal/tracker/projects/ProjectInfo.java create mode 100644 components/projects/src/main/java/io/pivotal/pal/tracker/projects/data/ProjectDataGateway.java create mode 100644 components/projects/src/main/java/io/pivotal/pal/tracker/projects/data/ProjectFields.java create mode 100644 components/projects/src/main/java/io/pivotal/pal/tracker/projects/data/ProjectRecord.java create mode 100644 components/projects/src/test/java/test/pivotal/pal/tracker/projects/ProjectControllerTest.java create mode 100644 components/projects/src/test/java/test/pivotal/pal/tracker/projects/ProjectDataGatewayTest.java create mode 100644 components/projects/src/test/java/test/pivotal/pal/tracker/projects/TestBuilders.java create mode 100644 components/rest-support/build.gradle create mode 100644 components/rest-support/src/main/java/io/pivotal/pal/tracker/restsupport/RestConfig.java create mode 100644 components/rest-support/src/main/java/io/pivotal/pal/tracker/restsupport/SpringDefaultController.java create mode 100644 components/test-support/build.gradle create mode 100644 components/test-support/src/main/java/io/pivotal/pal/tracker/testsupport/TestDataSourceFactory.java create mode 100644 components/test-support/src/main/java/io/pivotal/pal/tracker/testsupport/TestScenarioSupport.java create mode 100644 components/timesheets/build.gradle create mode 100644 components/timesheets/src/main/java/io/pivotal/pal/tracker/timesheets/ProjectClient.java create mode 100644 components/timesheets/src/main/java/io/pivotal/pal/tracker/timesheets/ProjectInfo.java create mode 100644 components/timesheets/src/main/java/io/pivotal/pal/tracker/timesheets/TimeEntryController.java create mode 100644 components/timesheets/src/main/java/io/pivotal/pal/tracker/timesheets/TimeEntryForm.java create mode 100644 components/timesheets/src/main/java/io/pivotal/pal/tracker/timesheets/TimeEntryInfo.java create mode 100644 components/timesheets/src/main/java/io/pivotal/pal/tracker/timesheets/data/TimeEntryDataGateway.java create mode 100644 components/timesheets/src/main/java/io/pivotal/pal/tracker/timesheets/data/TimeEntryFields.java create mode 100644 components/timesheets/src/main/java/io/pivotal/pal/tracker/timesheets/data/TimeEntryRecord.java create mode 100644 components/timesheets/src/test/java/test/pivotal/pal/tracker/timesheets/TestBuilders.java create mode 100644 components/timesheets/src/test/java/test/pivotal/pal/tracker/timesheets/TimeEntryControllerTest.java create mode 100644 components/timesheets/src/test/java/test/pivotal/pal/tracker/timesheets/TimeEntryDataGatewayTest.java create mode 100644 components/users/build.gradle create mode 100644 components/users/src/main/java/io/pivotal/pal/tracker/users/UserController.java create mode 100644 components/users/src/main/java/io/pivotal/pal/tracker/users/UserInfo.java create mode 100644 components/users/src/main/java/io/pivotal/pal/tracker/users/data/UserDataGateway.java create mode 100644 components/users/src/main/java/io/pivotal/pal/tracker/users/data/UserRecord.java create mode 100644 components/users/src/test/java/test/pivotal/pal/tracker/users/UserControllerTest.java create mode 100644 components/users/src/test/java/test/pivotal/pal/tracker/users/data/UserDataGatewayTest.java create mode 100644 databases/allocations-database/build.gradle create mode 100644 databases/allocations-database/migrations/V1__initial_schema.sql create mode 100644 databases/backlog-database/build.gradle create mode 100644 databases/backlog-database/migrations/V1__initial_schema.sql create mode 100644 databases/build.gradle create mode 100644 databases/create_databases.sql create mode 100644 databases/registration-database/build.gradle create mode 100644 databases/registration-database/migrations/V1__initial_schema.sql create mode 100644 databases/timesheets-database/build.gradle create mode 100644 databases/timesheets-database/migrations/V1__initial_schema.sql create mode 100644 gradle.properties create mode 100644 gradle/wrapper/gradle-wrapper.jar create mode 100644 gradle/wrapper/gradle-wrapper.properties create mode 100755 gradlew create mode 100644 gradlew.bat create mode 100644 integration-test/build.gradle create mode 100644 integration-test/src/test/java/test/pivotal/pal/tracker/FlowTest.java create mode 100644 integration-test/src/test/java/test/pivotal/pal/tracker/support/ApplicationServer.java create mode 100644 integration-test/src/test/java/test/pivotal/pal/tracker/support/HttpClient.java create mode 100644 integration-test/src/test/java/test/pivotal/pal/tracker/support/MapBuilder.java create mode 100644 integration-test/src/test/java/test/pivotal/pal/tracker/support/Response.java create mode 100644 manifest-allocations.yml create mode 100644 manifest-backlog.yml create mode 100644 manifest-registration.yml create mode 100644 manifest-timesheets.yml create mode 100644 requests.http create mode 100644 settings.gradle diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e1e3c15 --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +.gradle +build +.idea +*.iml +*.ipr +*.iws +.DS_Store +.env +ci/variables.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..eb0d7c5 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,149 @@ +dist: trusty +sudo: required +notifications: + email: false +env: + - RELEASE_TAG="release-$TRAVIS_BUILD_NUMBER" +stages: + - build and publish + - deploy + - migrate +if: tag IS blank + +jobs: + include: + - stage: build and publish + language: java + jdk: openjdk11 + addons: + mariadb: '10.2' + install: skip + before_script: + - mysql -uroot < databases/create_databases.sql + - ./gradlew testMigrate + script: + - APPLICATION=allocations + - ./gradlew clean :applications:${APPLICATION}-server:build + before_deploy: + - git config --local user.name "Travis CI" + - git config --local user.email "travis@example.com" + - git tag -f $RELEASE_TAG + deploy: &github + provider: releases + api_key: $GITHUB_OAUTH_TOKEN + file: + - "applications/${APPLICATION}-server/build/libs/${APPLICATION}-server.jar" + skip_cleanup: true + + - stage: build and publish + language: java + jdk: openjdk11 + addons: + mariadb: '10.2' + install: skip + before_script: + - mysql -uroot < databases/create_databases.sql + - ./gradlew testMigrate + script: + - APPLICATION=backlog + - ./gradlew clean :applications:${APPLICATION}-server:build + before_deploy: + - git config --local user.name "Travis CI" + - git config --local user.email "travis@example.com" + - git tag -f $RELEASE_TAG + deploy: + <<: *github + + - stage: build and publish + language: java + jdk: openjdk11 + addons: + mariadb: '10.2' + install: skip + before_script: + - mysql -uroot < databases/create_databases.sql + - ./gradlew testMigrate + script: + - APPLICATION=registration + - ./gradlew clean :applications:${APPLICATION}-server:build + before_deploy: + - git config --local user.name "Travis CI" + - git config --local user.email "travis@example.com" + - git tag -f $RELEASE_TAG + deploy: + <<: *github + + - stage: build and publish + language: java + jdk: openjdk11 + addons: + mariadb: '10.2' + install: skip + before_script: + - mysql -uroot < databases/create_databases.sql + - ./gradlew testMigrate + script: + - APPLICATION=timesheets + - ./gradlew clean :applications:${APPLICATION}-server:build + before_deploy: + - git config --local user.name "Travis CI" + - git config --local user.email "travis@example.com" + - git tag -f $RELEASE_TAG + deploy: + <<: *github + + - stage: deploy + language: bash + script: + - echo "Downloading allocations server $RELEASE_TAG" + - wget -P applications/allocations-server/build/libs https://github.com/$GITHUB_USERNAME/pal-tracker-distributed/releases/download/$RELEASE_TAG/allocations-server.jar + before_deploy: + - cp manifest-allocations.yml manifest.yml + - echo "Deploying allocations server $RELEASE_TAG" + deploy: &cloudfoundry + provider: cloudfoundry + api: $CF_API_URL + username: $CF_USERNAME + password: $CF_PASSWORD + organization: $CF_ORG + space: $CF_SPACE + - stage: deploy + language: bash + script: + - echo "Downloading backlog server $RELEASE_TAG" + - wget -P applications/backlog-server/build/libs https://github.com/$GITHUB_USERNAME/pal-tracker-distributed/releases/download/$RELEASE_TAG/backlog-server.jar + before_deploy: + - cp manifest-backlog.yml manifest.yml + - echo "Deploying backlog server $RELEASE_TAG" + deploy: + <<: *cloudfoundry + - stage: deploy + language: bash + script: + - echo "Downloading registration server $RELEASE_TAG" + - wget -P applications/registration-server/build/libs https://github.com/$GITHUB_USERNAME/pal-tracker-distributed/releases/download/$RELEASE_TAG/registration-server.jar + before_deploy: + - cp manifest-registration.yml manifest.yml + - echo "Deploying registration server $RELEASE_TAG" + deploy: + <<: *cloudfoundry + - stage: deploy + language: bash + script: + - echo "Downloading timesheets server $RELEASE_TAG" + - wget -P applications/timesheets-server/build/libs https://github.com/$GITHUB_USERNAME/pal-tracker-distributed/releases/download/$RELEASE_TAG/timesheets-server.jar + before_deploy: + - cp manifest-timesheets.yml manifest.yml + - echo "Deploying timesheets server $RELEASE_TAG" + deploy: + <<: *cloudfoundry + - stage: migrate + language: java + before_install: + - wget -q -O - https://packages.cloudfoundry.org/debian/cli.cloudfoundry.org.key | sudo apt-key add - + - echo "deb https://packages.cloudfoundry.org/debian stable main" | sudo tee /etc/apt/sources.list.d/cloudfoundry-cli.list + - sudo apt-get update + - sudo apt-get install cf-cli + script: + - cf login -a $CF_API_URL -u $CF_USERNAME -p $CF_PASSWORD -o $CF_ORG -s $CF_SPACE + - ./gradlew cfMigrate diff --git a/applications/allocations-server/build.gradle b/applications/allocations-server/build.gradle new file mode 100644 index 0000000..f73756a --- /dev/null +++ b/applications/allocations-server/build.gradle @@ -0,0 +1,5 @@ +apply from: "$projectDir/../server.gradle" + +dependencies { + compile project(":components:allocations") +} diff --git a/applications/allocations-server/src/main/java/io/pivotal/pal/tracker/allocations/App.java b/applications/allocations-server/src/main/java/io/pivotal/pal/tracker/allocations/App.java new file mode 100644 index 0000000..b034229 --- /dev/null +++ b/applications/allocations-server/src/main/java/io/pivotal/pal/tracker/allocations/App.java @@ -0,0 +1,29 @@ +package io.pivotal.pal.tracker.allocations; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.web.client.RestOperations; + +import java.util.TimeZone; + + +@SpringBootApplication +@ComponentScan({"io.pivotal.pal.tracker.allocations", "io.pivotal.pal.tracker.restsupport"}) +public class App { + + public static void main(String[] args) { + TimeZone.setDefault(TimeZone.getTimeZone("UTC")); + SpringApplication.run(App.class, args); + } + + @Bean + ProjectClient projectClient( + RestOperations restOperations, + @Value("${registration.server.endpoint}") String registrationEndpoint + ) { + return new ProjectClient(restOperations, registrationEndpoint); + } +} diff --git a/applications/allocations-server/src/main/resources/application.properties b/applications/allocations-server/src/main/resources/application.properties new file mode 100644 index 0000000..57cbd07 --- /dev/null +++ b/applications/allocations-server/src/main/resources/application.properties @@ -0,0 +1,6 @@ +spring.application.name=allocations-server + +server.port=8081 +spring.datasource.username=tracker +spring.datasource.url=jdbc:mysql://localhost:3306/tracker_allocations_dev?useSSL=false&useTimezone=true&serverTimezone=UTC&useLegacyDatetimeCode=false +registration.server.endpoint=http://localhost:8083 diff --git a/applications/allocations-server/src/test/java/test/pivotal/pal/tracker/allocations/AllocationsAppTest.java b/applications/allocations-server/src/test/java/test/pivotal/pal/tracker/allocations/AllocationsAppTest.java new file mode 100644 index 0000000..4577f49 --- /dev/null +++ b/applications/allocations-server/src/test/java/test/pivotal/pal/tracker/allocations/AllocationsAppTest.java @@ -0,0 +1,19 @@ +package test.pivotal.pal.tracker.allocations; + +import io.pivotal.pal.tracker.allocations.App; +import org.junit.Test; +import org.springframework.web.client.RestTemplate; + +import static org.assertj.core.api.Assertions.assertThat; + +public class AllocationsAppTest { + + @Test + public void embedded() { + App.main(new String[]{}); + + String response = new RestTemplate().getForObject("http://localhost:8181/allocations?projectId=0", String.class); + + assertThat(response).isEqualTo("[]"); + } +} diff --git a/applications/allocations-server/src/test/resources/application.properties b/applications/allocations-server/src/test/resources/application.properties new file mode 100644 index 0000000..9d25a30 --- /dev/null +++ b/applications/allocations-server/src/test/resources/application.properties @@ -0,0 +1,6 @@ +spring.application.name=allocations-server + +server.port=8181 +spring.datasource.username=tracker +spring.datasource.url=jdbc:mysql://localhost:3306/tracker_allocations_test?useSSL=false&useTimezone=true&serverTimezone=UTC&useLegacyDatetimeCode=false +registration.server.endpoint=http://localhost:8883 diff --git a/applications/backlog-server/build.gradle b/applications/backlog-server/build.gradle new file mode 100644 index 0000000..954e9c7 --- /dev/null +++ b/applications/backlog-server/build.gradle @@ -0,0 +1,5 @@ +apply from: "$projectDir/../server.gradle" + +dependencies { + compile project(":components:backlog") +} diff --git a/applications/backlog-server/src/main/java/io/pivotal/pal/tracker/backlog/App.java b/applications/backlog-server/src/main/java/io/pivotal/pal/tracker/backlog/App.java new file mode 100644 index 0000000..832ff65 --- /dev/null +++ b/applications/backlog-server/src/main/java/io/pivotal/pal/tracker/backlog/App.java @@ -0,0 +1,29 @@ +package io.pivotal.pal.tracker.backlog; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.web.client.RestOperations; + +import java.util.TimeZone; + + +@SpringBootApplication +@ComponentScan({"io.pivotal.pal.tracker.backlog", "io.pivotal.pal.tracker.restsupport"}) +public class App { + + public static void main(String[] args) { + TimeZone.setDefault(TimeZone.getTimeZone("UTC")); + SpringApplication.run(App.class, args); + } + + @Bean + ProjectClient projectClient( + RestOperations restOperations, + @Value("${registration.server.endpoint}") String registrationEndpoint + ) { + return new ProjectClient(restOperations, registrationEndpoint); + } +} diff --git a/applications/backlog-server/src/main/resources/application.properties b/applications/backlog-server/src/main/resources/application.properties new file mode 100644 index 0000000..8ea7201 --- /dev/null +++ b/applications/backlog-server/src/main/resources/application.properties @@ -0,0 +1,6 @@ +spring.application.name=backlog-server + +server.port=8082 +spring.datasource.username=tracker +spring.datasource.url=jdbc:mysql://localhost:3306/tracker_backlog_dev?useSSL=false&useTimezone=true&serverTimezone=UTC&useLegacyDatetimeCode=false +registration.server.endpoint=http://localhost:8083 diff --git a/applications/backlog-server/src/test/java/test/pivotal/pal/tracker/backlog/BacklogAppTest.java b/applications/backlog-server/src/test/java/test/pivotal/pal/tracker/backlog/BacklogAppTest.java new file mode 100644 index 0000000..dea2c61 --- /dev/null +++ b/applications/backlog-server/src/test/java/test/pivotal/pal/tracker/backlog/BacklogAppTest.java @@ -0,0 +1,19 @@ +package test.pivotal.pal.tracker.backlog; + +import io.pivotal.pal.tracker.backlog.App; +import org.junit.Test; +import org.springframework.web.client.RestTemplate; + +import static org.assertj.core.api.Assertions.assertThat; + +public class BacklogAppTest { + + @Test + public void embedded() { + App.main(new String[]{}); + + String response = new RestTemplate().getForObject("http://localhost:8181/stories?projectId=0", String.class); + + assertThat(response).isEqualTo("[]"); + } +} diff --git a/applications/backlog-server/src/test/resources/application.properties b/applications/backlog-server/src/test/resources/application.properties new file mode 100644 index 0000000..8b43acf --- /dev/null +++ b/applications/backlog-server/src/test/resources/application.properties @@ -0,0 +1,6 @@ +spring.application.name=backlog-server + +server.port=8181 +spring.datasource.username=tracker +spring.datasource.url=jdbc:mysql://localhost:3306/tracker_backlog_test?useSSL=false&useTimezone=true&serverTimezone=UTC&useLegacyDatetimeCode=false +registration.server.endpoint=http://localhost:8883 diff --git a/applications/registration-server/build.gradle b/applications/registration-server/build.gradle new file mode 100644 index 0000000..8b1cfbe --- /dev/null +++ b/applications/registration-server/build.gradle @@ -0,0 +1,7 @@ +apply from: "$projectDir/../server.gradle" + +dependencies { + compile project(":components:accounts") + compile project(":components:projects") + compile project(":components:users") +} diff --git a/applications/registration-server/src/main/java/io/pivotal/pal/tracker/registration/App.java b/applications/registration-server/src/main/java/io/pivotal/pal/tracker/registration/App.java new file mode 100644 index 0000000..d2d0ba2 --- /dev/null +++ b/applications/registration-server/src/main/java/io/pivotal/pal/tracker/registration/App.java @@ -0,0 +1,23 @@ +package io.pivotal.pal.tracker.registration; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.ComponentScan; + +import java.util.TimeZone; + + +@SpringBootApplication +@ComponentScan({ + "io.pivotal.pal.tracker.accounts", + "io.pivotal.pal.tracker.restsupport", + "io.pivotal.pal.tracker.projects", + "io.pivotal.pal.tracker.users", + "io.pivotal.pal.tracker.registration" +}) +public class App { + public static void main(String[] args) { + TimeZone.setDefault(TimeZone.getTimeZone("UTC")); + SpringApplication.run(App.class, args); + } +} diff --git a/applications/registration-server/src/main/resources/application.properties b/applications/registration-server/src/main/resources/application.properties new file mode 100644 index 0000000..ff88e76 --- /dev/null +++ b/applications/registration-server/src/main/resources/application.properties @@ -0,0 +1,6 @@ +spring.application.name=registration-server + +server.port=8083 +spring.datasource.username=tracker +spring.datasource.url=jdbc:mysql://localhost:3306/tracker_registration_dev?useSSL=false&useTimezone=true&serverTimezone=UTC&useLegacyDatetimeCode=false +registration.server.endpoint=http://localhost:8083 diff --git a/applications/registration-server/src/test/java/test/pivotal/pal/tracker/registration/RegistrationAppTest.java b/applications/registration-server/src/test/java/test/pivotal/pal/tracker/registration/RegistrationAppTest.java new file mode 100644 index 0000000..8b54159 --- /dev/null +++ b/applications/registration-server/src/test/java/test/pivotal/pal/tracker/registration/RegistrationAppTest.java @@ -0,0 +1,22 @@ +package test.pivotal.pal.tracker.registration; + +import io.pivotal.pal.tracker.registration.App; +import org.junit.Test; +import org.springframework.web.client.RestTemplate; + +import static org.assertj.core.api.Assertions.assertThat; + +public class RegistrationAppTest { + + @Test + public void embedded() { + App.main(new String[]{}); + + RestTemplate restTemplate = new RestTemplate(); + + assertThat(restTemplate.getForObject("http://localhost:8181/accounts?ownerId=0", String.class)).isEqualTo("[]"); + assertThat(restTemplate.getForObject("http://localhost:8181/projects?accountId=0", String.class)).isEqualTo("[]"); + assertThat(restTemplate.getForObject("http://localhost:8181/projects/0", String.class)).isEqualTo(null); + assertThat(restTemplate.getForObject("http://localhost:8181/users/0", String.class)).isEqualTo(null); + } +} diff --git a/applications/registration-server/src/test/resources/application.properties b/applications/registration-server/src/test/resources/application.properties new file mode 100644 index 0000000..ff6f375 --- /dev/null +++ b/applications/registration-server/src/test/resources/application.properties @@ -0,0 +1,6 @@ +spring.application.name=registration-server + +server.port=8181 +spring.datasource.username=tracker +spring.datasource.url=jdbc:mysql://localhost:3306/tracker_registration_test?useSSL=false&useTimezone=true&serverTimezone=UTC&useLegacyDatetimeCode=false +registration.server.endpoint=http://localhost:8883 diff --git a/applications/server.gradle b/applications/server.gradle new file mode 100644 index 0000000..7da92d9 --- /dev/null +++ b/applications/server.gradle @@ -0,0 +1,14 @@ +apply plugin: "org.springframework.boot" +apply plugin: "io.spring.dependency-management" + +dependencies { + compile project(":components:rest-support") + + compile "org.springframework.boot:spring-boot-starter-web" + + compile "com.zaxxer:HikariCP:$hikariVersion" + compile "mysql:mysql-connector-java:$mysqlVersion" + compile "ch.qos.logback:logback-classic:$logbackVersion" + + testCompile project(":components:test-support") +} diff --git a/applications/timesheets-server/build.gradle b/applications/timesheets-server/build.gradle new file mode 100644 index 0000000..0926483 --- /dev/null +++ b/applications/timesheets-server/build.gradle @@ -0,0 +1,5 @@ +apply from: "$projectDir/../server.gradle" + +dependencies { + compile project(":components:timesheets") +} diff --git a/applications/timesheets-server/src/main/java/io/pivotal/pal/tracker/timesheets/App.java b/applications/timesheets-server/src/main/java/io/pivotal/pal/tracker/timesheets/App.java new file mode 100644 index 0000000..9df368a --- /dev/null +++ b/applications/timesheets-server/src/main/java/io/pivotal/pal/tracker/timesheets/App.java @@ -0,0 +1,29 @@ +package io.pivotal.pal.tracker.timesheets; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.web.client.RestOperations; + +import java.util.TimeZone; + + +@SpringBootApplication +@ComponentScan({"io.pivotal.pal.tracker.timesheets", "io.pivotal.pal.tracker.restsupport"}) +public class App { + + public static void main(String[] args) { + TimeZone.setDefault(TimeZone.getTimeZone("UTC")); + SpringApplication.run(App.class, args); + } + + @Bean + ProjectClient projectClient( + RestOperations restOperations, + @Value("${registration.server.endpoint}") String registrationEndpoint + ) { + return new ProjectClient(restOperations, registrationEndpoint); + } +} diff --git a/applications/timesheets-server/src/main/resources/application.properties b/applications/timesheets-server/src/main/resources/application.properties new file mode 100644 index 0000000..606bf9d --- /dev/null +++ b/applications/timesheets-server/src/main/resources/application.properties @@ -0,0 +1,6 @@ +spring.application.name=timesheets-server + +server.port=8084 +spring.datasource.username=tracker +spring.datasource.url=jdbc:mysql://localhost:3306/tracker_timesheets_dev?useSSL=false&useTimezone=true&serverTimezone=UTC&useLegacyDatetimeCode=false +registration.server.endpoint=http://localhost:8083 diff --git a/applications/timesheets-server/src/test/java/test/pivotal/pal/tracker/timesheets/TimesheetsAppTest.java b/applications/timesheets-server/src/test/java/test/pivotal/pal/tracker/timesheets/TimesheetsAppTest.java new file mode 100644 index 0000000..b6eeae9 --- /dev/null +++ b/applications/timesheets-server/src/test/java/test/pivotal/pal/tracker/timesheets/TimesheetsAppTest.java @@ -0,0 +1,19 @@ +package test.pivotal.pal.tracker.timesheets; + +import io.pivotal.pal.tracker.timesheets.App; +import org.junit.Test; +import org.springframework.web.client.RestTemplate; + +import static org.assertj.core.api.Assertions.assertThat; + +public class TimesheetsAppTest { + + @Test + public void embedded() { + App.main(new String[]{}); + + String response = new RestTemplate().getForObject("http://localhost:8181/time-entries?userId=0", String.class); + + assertThat(response).isEqualTo("[]"); + } +} diff --git a/applications/timesheets-server/src/test/resources/application.properties b/applications/timesheets-server/src/test/resources/application.properties new file mode 100644 index 0000000..928f52e --- /dev/null +++ b/applications/timesheets-server/src/test/resources/application.properties @@ -0,0 +1,6 @@ +spring.application.name=timesheets-server + +server.port=8181 +spring.datasource.username=tracker +spring.datasource.url=jdbc:mysql://localhost:3306/tracker_timesheets_test?useSSL=false&useTimezone=true&serverTimezone=UTC&useLegacyDatetimeCode=false +registration.server.endpoint=http://localhost:8883 diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..2058cb6 --- /dev/null +++ b/build.gradle @@ -0,0 +1,59 @@ +import io.pivotal.pal.tracker.gradlebuild.DependenciesGraphPlugin + +buildscript { + ext { + springBootVersion = "2.0.6.RELEASE" + springVersion = "5.0.9.RELEASE" + mysqlVersion = "8.0.13" + jacksonVersion = "2.9.7" + slf4jVersion = "1.7.25" + mockitoVersion = "2.23.0" + assertJVersion = "3.11.1" + hikariVersion = "3.1.0" + logbackVersion = "1.2.3" + junitVersion = "4.12" + okhttpVersion = "3.12.0" + jsonPathVersion = "2.4.0" + } + + repositories { + mavenCentral() + jcenter() + } + + dependencies { + classpath "org.springframework.boot:spring-boot-gradle-plugin:$springBootVersion" + classpath "mysql:mysql-connector-java:$mysqlVersion" + } +} + +apply plugin: DependenciesGraphPlugin + +subprojects { + group "io.pivotal.pal.tracker" + + apply plugin: "java" + defaultTasks "clean", "build" + + repositories { + mavenCentral() + jcenter() + } + + dependencies { + compile "com.fasterxml.jackson.core:jackson-core:$jacksonVersion" + compile "com.fasterxml.jackson.core:jackson-databind:$jacksonVersion" + compile "com.fasterxml.jackson.core:jackson-annotations:$jacksonVersion" + compile "org.slf4j:slf4j-api:$slf4jVersion" + + testCompile "junit:junit:$junitVersion" + testCompile "org.mockito:mockito-core:$mockitoVersion" + testCompile "org.assertj:assertj-core:$assertJVersion" + } + + test { + testLogging { + exceptionFormat = 'full' + } + } +} diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle new file mode 100644 index 0000000..93f622c --- /dev/null +++ b/buildSrc/build.gradle @@ -0,0 +1,7 @@ +repositories { + mavenCentral() +} + +dependencies { + compile "org.flywaydb:flyway-gradle-plugin:5.2.1" +} diff --git a/buildSrc/src/main/groovy/io/pivotal/pal/tracker/gradlebuild/CfMigrationPlugin.groovy b/buildSrc/src/main/groovy/io/pivotal/pal/tracker/gradlebuild/CfMigrationPlugin.groovy new file mode 100644 index 0000000..59810ef --- /dev/null +++ b/buildSrc/src/main/groovy/io/pivotal/pal/tracker/gradlebuild/CfMigrationPlugin.groovy @@ -0,0 +1,123 @@ +package io.pivotal.pal.tracker.gradlebuild + +import groovy.json.JsonSlurper +import org.flywaydb.gradle.FlywayExtension +import org.flywaydb.gradle.task.FlywayMigrateTask +import org.flywaydb.gradle.task.FlywayRepairTask +import org.gradle.api.Plugin +import org.gradle.api.Project + +class CfMigrationPlugin implements Plugin { + private final static int TUNNEL_PORT = 63306 + private static final String KEY_NAME = 'flyway-migration-key' + + @Override + void apply(Project project) { + Process tunnelProcess = null + Map credentials = null + + project.with { + afterEvaluate { + def databases = project.extensions.findByType(DatabasesExtension) + def appName = databases.cfApp + def databaseInstanceName = databases.cfDatabase + + task( "acquireCredentials") { + doLast { + println "Acquiring database credentials" + credentials = acquireMysqlCredentials(databaseInstanceName) + } + } + + task("openTunnel") { + dependsOn "acquireCredentials" + doLast { + println "Opening Tunnel for $appName" + Thread.start { + tunnelProcess = "cf ssh -N -L ${TUNNEL_PORT}:${credentials['hostname']}:${credentials['port']} $appName".execute() + } + + waitForTunnelConnectivity() + } + } + + task("closeTunnel") { + doLast { + println "Closing Tunnel" + tunnelProcess?.destroyForcibly() + } + } + + task("cfMigrate", type: FlywayMigrateTask, group: "Migration") { + dependsOn "openTunnel" + finalizedBy "closeTunnel" + doFirst { extension = buildFlywayExtension(project, credentials) } + } + + task("cfRepair", type: FlywayRepairTask, group: "Migration") { + dependsOn "openTunnel" + finalizedBy "closeTunnel" + doFirst { extension = buildFlywayExtension(project, credentials) } + } + } + } + } + + private static void waitForTunnelConnectivity() { + int remainingAttempts = 20 + while (remainingAttempts > 0) { + remainingAttempts-- + try { + new Socket('localhost', TUNNEL_PORT).close() + remainingAttempts = 0 + } catch (ConnectException e) { + println "Waiting for tunnel ($remainingAttempts attempts remaining)" + sleep 1_000L + } + } + } + + private static def buildFlywayExtension(Project project, Map credentials) { + def extension = new FlywayExtension() + + extension.user = credentials['username'] + extension.password = credentials['password'] + def sslParam = '' + switch (credentials['jdbcUrl']) { + case ~/.*\buseSSL=false\b.*/: + sslParam = '?useSSL=false' + break + case ~/.*\buseSSL=true\b.*/: + sslParam = '?useSSL=true' + break + } + extension.url = "jdbc:mysql://127.0.0.1:${TUNNEL_PORT}/${credentials['name']}${sslParam}" + + extension.locations = ["filesystem:$project.projectDir/migrations"] + return extension + } + + // Some services store their credentials in credhub, so they are + // not available in VCAP_SERVICES seen by clients. Therefore, we + // create a service key and then obtain the database credentials + // from that value. Key creation appears idempotent, so there + // is no need to check for prior existence. + private static Map acquireMysqlCredentials(databaseInstanceName) { + execute(['cf', 'create-service-key', databaseInstanceName, KEY_NAME]) + + def serviceKeyJson = execute(['cf', 'service-key', databaseInstanceName, KEY_NAME]) + .replaceFirst(/(?s)^[^{]*/, '') + + return new JsonSlurper().parseText(serviceKeyJson) as Map + } + + private static String execute(List args) { + println "Executing command: ${args.join(' ')}" + def process = args.execute() + def output = process.text + process.waitFor() + + println "Result of command: ${output}" + return output + } +} diff --git a/buildSrc/src/main/groovy/io/pivotal/pal/tracker/gradlebuild/DatabasesExtension.groovy b/buildSrc/src/main/groovy/io/pivotal/pal/tracker/gradlebuild/DatabasesExtension.groovy new file mode 100644 index 0000000..b04d0a2 --- /dev/null +++ b/buildSrc/src/main/groovy/io/pivotal/pal/tracker/gradlebuild/DatabasesExtension.groovy @@ -0,0 +1,8 @@ +package io.pivotal.pal.tracker.gradlebuild + +class DatabasesExtension { + String devDatabase + String testDatabase + String cfDatabase + String cfApp +} diff --git a/buildSrc/src/main/groovy/io/pivotal/pal/tracker/gradlebuild/DependenciesGraphPlugin.groovy b/buildSrc/src/main/groovy/io/pivotal/pal/tracker/gradlebuild/DependenciesGraphPlugin.groovy new file mode 100644 index 0000000..eebd1f0 --- /dev/null +++ b/buildSrc/src/main/groovy/io/pivotal/pal/tracker/gradlebuild/DependenciesGraphPlugin.groovy @@ -0,0 +1,66 @@ +package io.pivotal.pal.tracker.gradlebuild + +import org.gradle.api.Plugin +import org.gradle.api.Project +import org.gradle.api.artifacts.Configuration +import org.gradle.api.artifacts.UnknownConfigurationException +import org.gradle.api.tasks.Delete +import org.gradle.api.tasks.Exec + +class DependenciesGraphPlugin implements Plugin { + + @Override + void apply(Project project) { + + project.with { + task("clean", type: Delete) { + delete "build" + } + + task("dependenciesGraphDot") { + mustRunAfter "clean" + group = "DependenciesGraph" + description = "Generate DOT file" + + def graphBuildDir = "build/dependenciesGraph" + def dotFile = file "$graphBuildDir/graph.dot" + + doLast { + delete graphBuildDir + mkdir graphBuildDir + + dotFile << "digraph dependencies {\n" + + subprojects.forEach { Project subProject -> + if (isProjectExcluded(subProject)) { + return + } + + try { + Configuration compileConfig = subProject.configurations["compile"] + + compileConfig + .dependencies + .grep { it.respondsTo("getDependencyProject") && !isProjectExcluded(it) } + .forEach { dotFile << """ "$subProject.name" -> "$it.dependencyProject.name"\n""" } + } catch (UnknownConfigurationException ignored) { + } + } + + dotFile << "}\n" + } + } + + task("dependenciesGraph", dependsOn: "dependenciesGraphDot", type: Exec) { + workingDir "$buildDir/dependenciesGraph" + commandLine "dot", "-O", "-Tpng", "graph.dot" + group = "DependenciesGraph" + description = "Generate PNG file" + } + } + } + + private static boolean isProjectExcluded(def project) { + return project.name.contains("support") + } +} diff --git a/buildSrc/src/main/groovy/io/pivotal/pal/tracker/gradlebuild/LocalMigrationPlugin.groovy b/buildSrc/src/main/groovy/io/pivotal/pal/tracker/gradlebuild/LocalMigrationPlugin.groovy new file mode 100644 index 0000000..da7a43a --- /dev/null +++ b/buildSrc/src/main/groovy/io/pivotal/pal/tracker/gradlebuild/LocalMigrationPlugin.groovy @@ -0,0 +1,46 @@ +package io.pivotal.pal.tracker.gradlebuild + +import org.flywaydb.gradle.FlywayExtension +import org.flywaydb.gradle.task.FlywayCleanTask +import org.flywaydb.gradle.task.FlywayMigrateTask +import org.flywaydb.gradle.task.FlywayRepairTask +import org.gradle.api.Plugin +import org.gradle.api.Project + +class LocalMigrationPlugin implements Plugin { + + @Override + void apply(Project project) { + + project.with { + def databases = new DatabasesExtension() + + extensions.add("flyway", new FlywayExtension()) + extensions.add("databases", databases) + + afterEvaluate { + addDbTask(project, "dev", databases.devDatabase) + addDbTask(project, "test", databases.testDatabase) + } + } + } + + private static addDbTask(Project project, String name, String dbName) { + def flywayExtension = buildFlywayExtension(project, dbName) + + project.task("${name}Migrate", type: FlywayMigrateTask, group: "Migration") { extension = flywayExtension } + project.task("${name}Clean", type: FlywayCleanTask, group: "Migration") { extension = flywayExtension } + project.task("${name}Repair", type: FlywayRepairTask, group: "Migration") { extension = flywayExtension } + } + + private static FlywayExtension buildFlywayExtension(Project project, String dbName) { + def ext = new FlywayExtension() + ext.with { + url = "jdbc:mysql://localhost:3306/$dbName?useSSL=false&serverTimezone=UTC" + user = "tracker" + outOfOrder = false + locations = ["filesystem:${project.projectDir}"] + } + return ext + } +} diff --git a/components/accounts/build.gradle b/components/accounts/build.gradle new file mode 100644 index 0000000..0eaa050 --- /dev/null +++ b/components/accounts/build.gradle @@ -0,0 +1,7 @@ +dependencies { + compile project(":components:rest-support") + compile project(":components:users") + compile "org.springframework:spring-jdbc:$springVersion" + + testCompile project(":components:test-support") +} diff --git a/components/accounts/src/main/java/io/pivotal/pal/tracker/accounts/AccountController.java b/components/accounts/src/main/java/io/pivotal/pal/tracker/accounts/AccountController.java new file mode 100644 index 0000000..3aa8161 --- /dev/null +++ b/components/accounts/src/main/java/io/pivotal/pal/tracker/accounts/AccountController.java @@ -0,0 +1,39 @@ +package io.pivotal.pal.tracker.accounts; + +import io.pivotal.pal.tracker.accounts.data.AccountDataGateway; +import io.pivotal.pal.tracker.accounts.data.AccountRecord; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +import static io.pivotal.pal.tracker.accounts.AccountInfo.accountInfoBuilder; +import static java.util.stream.Collectors.toList; + +@RestController +public class AccountController { + + private final AccountDataGateway gateway; + + public AccountController(AccountDataGateway gateway) { + this.gateway = gateway; + } + + @GetMapping("/accounts") + public List list(@RequestParam long ownerId) { + return gateway.findAllByOwnerId(ownerId) + .stream() + .map(this::present) + .collect(toList()); + } + + private AccountInfo present(AccountRecord record) { + return accountInfoBuilder() + .id(record.id) + .ownerId(record.ownerId) + .name(record.name) + .info("account info") + .build(); + } +} diff --git a/components/accounts/src/main/java/io/pivotal/pal/tracker/accounts/AccountInfo.java b/components/accounts/src/main/java/io/pivotal/pal/tracker/accounts/AccountInfo.java new file mode 100644 index 0000000..0dda9c1 --- /dev/null +++ b/components/accounts/src/main/java/io/pivotal/pal/tracker/accounts/AccountInfo.java @@ -0,0 +1,88 @@ +package io.pivotal.pal.tracker.accounts; + +public class AccountInfo { + + public final long id; + public final long ownerId; + public final String name; + public final String info; + + private AccountInfo() { // for jackson + this(accountInfoBuilder()); + } + + private AccountInfo(Builder builder) { + id = builder.id; + ownerId = builder.ownerId; + name = builder.name; + info = builder.info; + } + + public static Builder accountInfoBuilder() { + return new Builder(); + } + + public static class Builder { + private long id; + private long ownerId; + private String name; + private String info; + + public AccountInfo build() { + return new AccountInfo(this); + } + + public Builder id(long id) { + this.id = id; + return this; + } + + public Builder ownerId(long ownerId) { + this.ownerId = ownerId; + return this; + } + + public Builder name(String name) { + this.name = name; + return this; + } + + public Builder info(String info) { + this.info = info; + return this; + } + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + AccountInfo that = (AccountInfo) o; + + if (id != that.id) return false; + if (ownerId != that.ownerId) return false; + if (name != null ? !name.equals(that.name) : that.name != null) + return false; + return info != null ? info.equals(that.info) : that.info == null; + } + + @Override + public int hashCode() { + int result = (int) (id ^ (id >>> 32)); + result = 31 * result + (int) (ownerId ^ (ownerId >>> 32)); + result = 31 * result + (name != null ? name.hashCode() : 0); + result = 31 * result + (info != null ? info.hashCode() : 0); + return result; + } + + @Override + public String toString() { + return "AccountInfo{" + + "id=" + id + + ", ownerId=" + ownerId + + ", name='" + name + '\'' + + ", info='" + info + '\'' + + '}'; + } +} diff --git a/components/accounts/src/main/java/io/pivotal/pal/tracker/accounts/RegistrationController.java b/components/accounts/src/main/java/io/pivotal/pal/tracker/accounts/RegistrationController.java new file mode 100644 index 0000000..5234f64 --- /dev/null +++ b/components/accounts/src/main/java/io/pivotal/pal/tracker/accounts/RegistrationController.java @@ -0,0 +1,22 @@ +package io.pivotal.pal.tracker.accounts; + +import io.pivotal.pal.tracker.users.UserInfo; +import io.pivotal.pal.tracker.users.data.UserRecord; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class RegistrationController { + private final RegistrationService service; + + public RegistrationController(RegistrationService service) { + this.service = service; + } + + @PostMapping("/registration") + public UserInfo create(@RequestBody RegistrationForm form) { + UserRecord record = service.createUserWithAccount(form.name); + return new UserInfo(record.id, record.name, "registration info"); + } +} diff --git a/components/accounts/src/main/java/io/pivotal/pal/tracker/accounts/RegistrationForm.java b/components/accounts/src/main/java/io/pivotal/pal/tracker/accounts/RegistrationForm.java new file mode 100644 index 0000000..bc269a0 --- /dev/null +++ b/components/accounts/src/main/java/io/pivotal/pal/tracker/accounts/RegistrationForm.java @@ -0,0 +1,36 @@ +package io.pivotal.pal.tracker.accounts; + +public class RegistrationForm { + + public final String name; + + public RegistrationForm(String name) { + this.name = name; + } + + private RegistrationForm() { + this(null); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + RegistrationForm that = (RegistrationForm) o; + + return name != null ? name.equals(that.name) : that.name == null; + } + + @Override + public int hashCode() { + return name != null ? name.hashCode() : 0; + } + + @Override + public String toString() { + return "RegistrationForm{" + + "name='" + name + '\'' + + '}'; + } +} diff --git a/components/accounts/src/main/java/io/pivotal/pal/tracker/accounts/RegistrationService.java b/components/accounts/src/main/java/io/pivotal/pal/tracker/accounts/RegistrationService.java new file mode 100644 index 0000000..87b5eb0 --- /dev/null +++ b/components/accounts/src/main/java/io/pivotal/pal/tracker/accounts/RegistrationService.java @@ -0,0 +1,26 @@ +package io.pivotal.pal.tracker.accounts; + +import io.pivotal.pal.tracker.accounts.data.AccountDataGateway; +import io.pivotal.pal.tracker.users.data.UserDataGateway; +import io.pivotal.pal.tracker.users.data.UserRecord; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +public class RegistrationService { + + private final UserDataGateway userDataGateway; + private final AccountDataGateway accountDataGateway; + + public RegistrationService(UserDataGateway userDataGateway, AccountDataGateway accountDataGateway) { + this.userDataGateway = userDataGateway; + this.accountDataGateway = accountDataGateway; + } + + @Transactional + public UserRecord createUserWithAccount(String name) { + UserRecord user = userDataGateway.create(name); + accountDataGateway.create(user.id, String.format("%s's account", name)); + return user; + } +} diff --git a/components/accounts/src/main/java/io/pivotal/pal/tracker/accounts/data/AccountDataGateway.java b/components/accounts/src/main/java/io/pivotal/pal/tracker/accounts/data/AccountDataGateway.java new file mode 100644 index 0000000..607d277 --- /dev/null +++ b/components/accounts/src/main/java/io/pivotal/pal/tracker/accounts/data/AccountDataGateway.java @@ -0,0 +1,54 @@ +package io.pivotal.pal.tracker.accounts.data; + +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.core.RowMapper; +import org.springframework.jdbc.support.GeneratedKeyHolder; +import org.springframework.jdbc.support.KeyHolder; +import org.springframework.stereotype.Repository; + +import javax.sql.DataSource; +import java.sql.PreparedStatement; +import java.util.List; + +import static io.pivotal.pal.tracker.accounts.data.AccountRecord.accountRecordBuilder; +import static java.sql.Statement.RETURN_GENERATED_KEYS; + +@Repository +public class AccountDataGateway { + private final JdbcTemplate jdbcTemplate; + + public AccountDataGateway(DataSource dataSource) { + this.jdbcTemplate = new JdbcTemplate(dataSource); + } + + public AccountRecord create(long ownerId, String name) { + KeyHolder keyholder = new GeneratedKeyHolder(); + + jdbcTemplate.update(connection -> { + PreparedStatement ps = connection.prepareStatement( + "insert into accounts (owner_id, name) values (?, ?)", RETURN_GENERATED_KEYS + ); + + ps.setLong(1, ownerId); + ps.setString(2, name); + return ps; + }, keyholder); + + long id = keyholder.getKey().longValue(); + + return jdbcTemplate.queryForObject("select id, owner_id, name from accounts where id = ?", rowMapper, id); + } + + public List findAllByOwnerId(long ownerId) { + return jdbcTemplate.query( + "select id, owner_id, name from accounts where owner_id = ? order by name desc limit 1", + rowMapper, ownerId + ); + } + + private RowMapper rowMapper = (rs, num) -> accountRecordBuilder() + .id(rs.getLong("id")) + .ownerId(rs.getLong("owner_id")) + .name(rs.getString("name")) + .build(); +} diff --git a/components/accounts/src/main/java/io/pivotal/pal/tracker/accounts/data/AccountRecord.java b/components/accounts/src/main/java/io/pivotal/pal/tracker/accounts/data/AccountRecord.java new file mode 100644 index 0000000..8864f4d --- /dev/null +++ b/components/accounts/src/main/java/io/pivotal/pal/tracker/accounts/data/AccountRecord.java @@ -0,0 +1,72 @@ +package io.pivotal.pal.tracker.accounts.data; + +public class AccountRecord { + + public final long id; + public final long ownerId; + public final String name; + + private AccountRecord(Builder builder) { + this.id = builder.id; + this.ownerId = builder.ownerId; + this.name = builder.name; + } + + public static Builder accountRecordBuilder() { + return new Builder(); + } + + public static class Builder { + private long id; + private long ownerId; + private String name; + + public AccountRecord build() { + return new AccountRecord(this); + } + + public Builder id(long id) { + this.id = id; + return this; + } + + public Builder ownerId(long ownerId) { + this.ownerId = ownerId; + return this; + } + + public Builder name(String name) { + this.name = name; + return this; + } + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + AccountRecord that = (AccountRecord) o; + + if (id != that.id) return false; + if (ownerId != that.ownerId) return false; + return name != null ? name.equals(that.name) : that.name == null; + } + + @Override + public int hashCode() { + int result = (int) (id ^ (id >>> 32)); + result = 31 * result + (int) (ownerId ^ (ownerId >>> 32)); + result = 31 * result + (name != null ? name.hashCode() : 0); + return result; + } + + @Override + public String toString() { + return "AccountRecord{" + + "id=" + id + + ", ownerId=" + ownerId + + ", name='" + name + '\'' + + '}'; + } +} diff --git a/components/accounts/src/test/java/test/pivotal/pal/tracker/accounts/AccountControllerTest.java b/components/accounts/src/test/java/test/pivotal/pal/tracker/accounts/AccountControllerTest.java new file mode 100644 index 0000000..9c4d6b0 --- /dev/null +++ b/components/accounts/src/test/java/test/pivotal/pal/tracker/accounts/AccountControllerTest.java @@ -0,0 +1,45 @@ +package test.pivotal.pal.tracker.accounts; + +import io.pivotal.pal.tracker.accounts.AccountController; +import io.pivotal.pal.tracker.accounts.AccountInfo; +import io.pivotal.pal.tracker.accounts.data.AccountDataGateway; +import io.pivotal.pal.tracker.accounts.data.AccountRecord; +import org.junit.Test; + +import java.util.List; + +import static io.pivotal.pal.tracker.accounts.AccountInfo.accountInfoBuilder; +import static io.pivotal.pal.tracker.accounts.data.AccountRecord.accountRecordBuilder; +import static java.util.Collections.singletonList; +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.Mockito.*; + +public class AccountControllerTest { + + private AccountDataGateway gateway = mock(AccountDataGateway.class); + private AccountController controller = new AccountController(gateway); + + @Test + public void testList() { + AccountRecord recordToFind = accountRecordBuilder() + .id(13L) + .ownerId(2L) + .name("Some Name") + .build(); + doReturn(singletonList(recordToFind)).when(gateway).findAllByOwnerId(anyLong()); + + + List result = controller.list(13); + + + verify(gateway).findAllByOwnerId(13L); + assertThat(result).containsExactly(accountInfoBuilder() + .id(13L) + .ownerId(2L) + .name("Some Name") + .info("account info") + .build() + ); + } +} diff --git a/components/accounts/src/test/java/test/pivotal/pal/tracker/accounts/RegistrationControllerTest.java b/components/accounts/src/test/java/test/pivotal/pal/tracker/accounts/RegistrationControllerTest.java new file mode 100644 index 0000000..9b0a7d3 --- /dev/null +++ b/components/accounts/src/test/java/test/pivotal/pal/tracker/accounts/RegistrationControllerTest.java @@ -0,0 +1,31 @@ +package test.pivotal.pal.tracker.accounts; + +import io.pivotal.pal.tracker.accounts.RegistrationController; +import io.pivotal.pal.tracker.accounts.RegistrationForm; +import io.pivotal.pal.tracker.accounts.RegistrationService; +import io.pivotal.pal.tracker.users.UserInfo; +import io.pivotal.pal.tracker.users.data.UserRecord; +import org.junit.Test; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.*; + +public class RegistrationControllerTest { + + private RegistrationService registrationService = mock(RegistrationService.class); + private RegistrationController registrationController = new RegistrationController(registrationService); + + @Test + public void create() { + UserRecord userRecord = new UserRecord(24L, "Billy"); + doReturn(userRecord).when(registrationService).createUserWithAccount(any()); + + + UserInfo result = registrationController.create(new RegistrationForm("Billy")); + + + verify(registrationService).createUserWithAccount("Billy"); + assertThat(result).isEqualTo(new UserInfo(24L, "Billy", "registration info")); + } +} diff --git a/components/accounts/src/test/java/test/pivotal/pal/tracker/accounts/RegistrationServiceTest.java b/components/accounts/src/test/java/test/pivotal/pal/tracker/accounts/RegistrationServiceTest.java new file mode 100644 index 0000000..2b66392 --- /dev/null +++ b/components/accounts/src/test/java/test/pivotal/pal/tracker/accounts/RegistrationServiceTest.java @@ -0,0 +1,32 @@ +package test.pivotal.pal.tracker.accounts; + +import io.pivotal.pal.tracker.accounts.RegistrationService; +import io.pivotal.pal.tracker.accounts.data.AccountDataGateway; +import io.pivotal.pal.tracker.users.data.UserDataGateway; +import io.pivotal.pal.tracker.users.data.UserRecord; +import org.junit.Test; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.*; + +public class RegistrationServiceTest { + private UserDataGateway userDataGateway = mock(UserDataGateway.class); + private AccountDataGateway accountDataGateway = mock(AccountDataGateway.class); + private RegistrationService service = new RegistrationService(userDataGateway, accountDataGateway); + + @Test + public void testCreateUserWithAccount() { + UserRecord createdUser = new UserRecord(22L, "Some User"); + doReturn(createdUser).when(userDataGateway).create("Some User"); + + + UserRecord result = service.createUserWithAccount("Some User"); + + + verify(userDataGateway).create("Some User"); + verify(accountDataGateway).create(22L, "Some User's account"); + + UserRecord expectedResult = new UserRecord(22L, "Some User"); + assertThat(result).isEqualTo(expectedResult); + } +} diff --git a/components/accounts/src/test/java/test/pivotal/pal/tracker/accounts/data/AccountDataGatewayTest.java b/components/accounts/src/test/java/test/pivotal/pal/tracker/accounts/data/AccountDataGatewayTest.java new file mode 100644 index 0000000..e9fce58 --- /dev/null +++ b/components/accounts/src/test/java/test/pivotal/pal/tracker/accounts/data/AccountDataGatewayTest.java @@ -0,0 +1,62 @@ +package test.pivotal.pal.tracker.accounts.data; + +import io.pivotal.pal.tracker.accounts.data.AccountDataGateway; +import io.pivotal.pal.tracker.accounts.data.AccountRecord; +import io.pivotal.pal.tracker.testsupport.TestScenarioSupport; +import org.junit.Before; +import org.junit.Test; +import org.springframework.jdbc.core.JdbcTemplate; + +import java.util.List; +import java.util.Map; + +import static io.pivotal.pal.tracker.accounts.data.AccountRecord.accountRecordBuilder; +import static org.assertj.core.api.Assertions.assertThat; + +public class AccountDataGatewayTest { + + private TestScenarioSupport testScenarioSupport = new TestScenarioSupport("tracker_registration_test"); + private JdbcTemplate template = testScenarioSupport.template; + private AccountDataGateway gateway = new AccountDataGateway(testScenarioSupport.dataSource); + + @Before + public void setup() { + template.execute("DELETE FROM projects;"); + template.execute("DELETE FROM accounts;"); + template.execute("DELETE FROM users;"); + } + + @Test + public void testCreate() { + template.execute("insert into users (id, name) values (12, 'Jack')"); + + + AccountRecord created = gateway.create(12L, "anAccount"); + + + assertThat(created.id).isNotNull(); + assertThat(created.name).isEqualTo("anAccount"); + assertThat(created.ownerId).isEqualTo(12); + + Map persisted = template.queryForMap("SELECT * FROM accounts WHERE id = ?", created.id); + assertThat(persisted.get("name")).isEqualTo("anAccount"); + assertThat(persisted.get("owner_id")).isEqualTo(12L); + } + + @Test + public void testFindBy() { + template.execute("insert into users (id, name) values (12, 'Jack')"); + template.execute("insert into accounts (id, owner_id, name) values (1, 12, 'anAccount')"); + + + List result = gateway.findAllByOwnerId(12L); + + + assertThat(result).containsExactly(accountRecordBuilder() + .id(1L) + .ownerId(12L) + .name("anAccount") + .build() + ); + } +} diff --git a/components/allocations/build.gradle b/components/allocations/build.gradle new file mode 100644 index 0000000..4526bf7 --- /dev/null +++ b/components/allocations/build.gradle @@ -0,0 +1,6 @@ +dependencies { + compile project(":components:rest-support") + compile "org.springframework:spring-jdbc:$springVersion" + + testCompile project(":components:test-support") +} diff --git a/components/allocations/src/main/java/io/pivotal/pal/tracker/allocations/AllocationController.java b/components/allocations/src/main/java/io/pivotal/pal/tracker/allocations/AllocationController.java new file mode 100644 index 0000000..21318a5 --- /dev/null +++ b/components/allocations/src/main/java/io/pivotal/pal/tracker/allocations/AllocationController.java @@ -0,0 +1,75 @@ +package io.pivotal.pal.tracker.allocations; + +import io.pivotal.pal.tracker.allocations.data.AllocationDataGateway; +import io.pivotal.pal.tracker.allocations.data.AllocationFields; +import io.pivotal.pal.tracker.allocations.data.AllocationRecord; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import java.time.LocalDate; +import java.util.List; + +import static io.pivotal.pal.tracker.allocations.AllocationInfo.allocationInfoBuilder; +import static io.pivotal.pal.tracker.allocations.data.AllocationFields.allocationFieldsBuilder; +import static java.util.stream.Collectors.toList; + +@RestController +@RequestMapping("/allocations") +public class AllocationController { + + private final AllocationDataGateway gateway; + private final ProjectClient client; + + public AllocationController(AllocationDataGateway gateway, ProjectClient client) { + this.gateway = gateway; + this.client = client; + } + + + @PostMapping + public ResponseEntity create(@RequestBody AllocationForm form) { + + if (projectIsActive(form.projectId)) { + AllocationRecord record = gateway.create(formToFields(form)); + return new ResponseEntity<>(present(record), HttpStatus.CREATED); + } + + return new ResponseEntity<>(HttpStatus.SERVICE_UNAVAILABLE); + } + + @GetMapping + public List list(@RequestParam long projectId) { + return gateway.findAllByProjectId(projectId) + .stream() + .map(this::present) + .collect(toList()); + } + + + private boolean projectIsActive(long projectId) { + ProjectInfo project = client.getProject(projectId); + + return project != null && project.active; + } + + private AllocationFields formToFields(AllocationForm form) { + return allocationFieldsBuilder() + .projectId(form.projectId) + .userId(form.userId) + .firstDay(LocalDate.parse(form.firstDay)) + .lastDay(LocalDate.parse(form.lastDay)) + .build(); + } + + private AllocationInfo present(AllocationRecord record) { + return allocationInfoBuilder() + .id(record.id) + .projectId(record.projectId) + .userId(record.userId) + .firstDay(record.firstDay.toString()) + .lastDay(record.lastDay.toString()) + .info("allocation info") + .build(); + } +} diff --git a/components/allocations/src/main/java/io/pivotal/pal/tracker/allocations/AllocationForm.java b/components/allocations/src/main/java/io/pivotal/pal/tracker/allocations/AllocationForm.java new file mode 100644 index 0000000..35117be --- /dev/null +++ b/components/allocations/src/main/java/io/pivotal/pal/tracker/allocations/AllocationForm.java @@ -0,0 +1,89 @@ +package io.pivotal.pal.tracker.allocations; + +public class AllocationForm { + + public final long projectId; + public final long userId; + public final String firstDay; + public final String lastDay; + + private AllocationForm() { // for jackson + this(allocationFormBuilder()); + } + + public AllocationForm(Builder builder) { + projectId = builder.projectId; + userId = builder.userId; + firstDay = builder.firstDay; + lastDay = builder.lastDay; + } + + public static Builder allocationFormBuilder() { + return new Builder(); + } + + + public static class Builder { + private long projectId; + private long userId; + private String firstDay; + private String lastDay; + + public AllocationForm build() { + return new AllocationForm(this); + } + + public Builder projectId(long projectId) { + this.projectId = projectId; + return this; + } + + public Builder userId(long userId) { + this.userId = userId; + return this; + } + + public Builder firstDay(String firstDay) { + this.firstDay = firstDay; + return this; + } + + public Builder lastDay(String lastDay) { + this.lastDay = lastDay; + return this; + } + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + AllocationForm that = (AllocationForm) o; + + if (projectId != that.projectId) return false; + if (userId != that.userId) return false; + if (firstDay != null ? !firstDay.equals(that.firstDay) : that.firstDay != null) + return false; + return lastDay != null ? lastDay.equals(that.lastDay) : that.lastDay == null; + } + + @Override + public int hashCode() { + int result = (int) (projectId ^ (projectId >>> 32)); + result = 31 * result + (int) (userId ^ (userId >>> 32)); + result = 31 * result + (firstDay != null ? firstDay.hashCode() : 0); + result = 31 * result + (lastDay != null ? lastDay.hashCode() : 0); + return result; + } + + @Override + public String toString() { + return "AllocationForm{" + + "projectId=" + projectId + + ", userId=" + userId + + ", firstDay='" + firstDay + '\'' + + ", lastDay='" + lastDay + '\'' + + '}'; + } +} diff --git a/components/allocations/src/main/java/io/pivotal/pal/tracker/allocations/AllocationInfo.java b/components/allocations/src/main/java/io/pivotal/pal/tracker/allocations/AllocationInfo.java new file mode 100644 index 0000000..cdbce0b --- /dev/null +++ b/components/allocations/src/main/java/io/pivotal/pal/tracker/allocations/AllocationInfo.java @@ -0,0 +1,112 @@ +package io.pivotal.pal.tracker.allocations; + +public class AllocationInfo { + + public final long id; + public final long projectId; + public final long userId; + public final String firstDay; + public final String lastDay; + public final String info; + + private AllocationInfo() { // for jackson + this(allocationInfoBuilder()); + } + + public AllocationInfo(Builder builder) { + id = builder.id; + projectId = builder.projectId; + userId = builder.userId; + firstDay = builder.firstDay; + lastDay = builder.lastDay; + info = builder.info; + } + + public static Builder allocationInfoBuilder() { + return new Builder(); + } + + + public static class Builder { + private long id; + private long projectId; + private long userId; + private String firstDay; + private String lastDay; + private String info; + + public AllocationInfo build() { + return new AllocationInfo(this); + } + + public Builder id(long id) { + this.id = id; + return this; + } + + public Builder projectId(long projectId) { + this.projectId = projectId; + return this; + } + + public Builder userId(long userId) { + this.userId = userId; + return this; + } + + public Builder firstDay(String firstDay) { + this.firstDay = firstDay; + return this; + } + + public Builder lastDay(String lastDay) { + this.lastDay = lastDay; + return this; + } + + public Builder info(String info) { + this.info = info; + return this; + } + } + + @Override + public String toString() { + return "AllocationInfo{" + + "id=" + id + + ", projectId=" + projectId + + ", userId=" + userId + + ", firstDay=" + firstDay + + ", lastDay=" + lastDay + + ", info='" + info + '\'' + + '}'; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + AllocationInfo info1 = (AllocationInfo) o; + + if (id != info1.id) return false; + if (projectId != info1.projectId) return false; + if (userId != info1.userId) return false; + if (firstDay != null ? !firstDay.equals(info1.firstDay) : info1.firstDay != null) + return false; + if (lastDay != null ? !lastDay.equals(info1.lastDay) : info1.lastDay != null) + return false; + return info != null ? info.equals(info1.info) : info1.info == null; + } + + @Override + public int hashCode() { + int result = (int) (id ^ (id >>> 32)); + result = 31 * result + (int) (projectId ^ (projectId >>> 32)); + result = 31 * result + (int) (userId ^ (userId >>> 32)); + result = 31 * result + (firstDay != null ? firstDay.hashCode() : 0); + result = 31 * result + (lastDay != null ? lastDay.hashCode() : 0); + result = 31 * result + (info != null ? info.hashCode() : 0); + return result; + } +} diff --git a/components/allocations/src/main/java/io/pivotal/pal/tracker/allocations/ProjectClient.java b/components/allocations/src/main/java/io/pivotal/pal/tracker/allocations/ProjectClient.java new file mode 100644 index 0000000..2358dab --- /dev/null +++ b/components/allocations/src/main/java/io/pivotal/pal/tracker/allocations/ProjectClient.java @@ -0,0 +1,18 @@ +package io.pivotal.pal.tracker.allocations; + +import org.springframework.web.client.RestOperations; + +public class ProjectClient { + + private final RestOperations restOperations; + private final String registrationServerEndpoint; + + public ProjectClient(RestOperations restOperations, String registrationServerEndpoint) { + this.restOperations= restOperations; + this.registrationServerEndpoint = registrationServerEndpoint; + } + + public ProjectInfo getProject(long projectId) { + return restOperations.getForObject(registrationServerEndpoint + "/projects/" + projectId, ProjectInfo.class); + } +} diff --git a/components/allocations/src/main/java/io/pivotal/pal/tracker/allocations/ProjectInfo.java b/components/allocations/src/main/java/io/pivotal/pal/tracker/allocations/ProjectInfo.java new file mode 100644 index 0000000..3728382 --- /dev/null +++ b/components/allocations/src/main/java/io/pivotal/pal/tracker/allocations/ProjectInfo.java @@ -0,0 +1,37 @@ +package io.pivotal.pal.tracker.allocations; + +public class ProjectInfo { + + public final boolean active; + + private ProjectInfo() { + this(false); + } + + public ProjectInfo(boolean active) { + this.active = active; + } + + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + ProjectInfo that = (ProjectInfo) o; + + return active == that.active; + } + + @Override + public int hashCode() { + return (active ? 1 : 0); + } + + @Override + public String toString() { + return "ProjectInfo{" + + "active=" + active + + '}'; + } +} diff --git a/components/allocations/src/main/java/io/pivotal/pal/tracker/allocations/data/AllocationDataGateway.java b/components/allocations/src/main/java/io/pivotal/pal/tracker/allocations/data/AllocationDataGateway.java new file mode 100644 index 0000000..f996307 --- /dev/null +++ b/components/allocations/src/main/java/io/pivotal/pal/tracker/allocations/data/AllocationDataGateway.java @@ -0,0 +1,67 @@ +package io.pivotal.pal.tracker.allocations.data; + +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.core.RowMapper; +import org.springframework.jdbc.support.GeneratedKeyHolder; +import org.springframework.jdbc.support.KeyHolder; +import org.springframework.stereotype.Repository; + +import javax.sql.DataSource; +import java.sql.Date; +import java.sql.PreparedStatement; +import java.util.List; + +import static java.sql.Statement.RETURN_GENERATED_KEYS; + +@Repository +public class AllocationDataGateway { + + private JdbcTemplate jdbcTemplate; + + public AllocationDataGateway(DataSource dataSource) { + this.jdbcTemplate = new JdbcTemplate(dataSource); + } + + + public AllocationRecord create(AllocationFields fields) { + KeyHolder keyHolder = new GeneratedKeyHolder(); + + jdbcTemplate.update(connection -> { + PreparedStatement ps = connection.prepareStatement( + "insert into allocations (project_id, user_id, first_day, last_day) values (?, ?, ?, ?)", RETURN_GENERATED_KEYS + ); + + ps.setLong(1, fields.projectId); + ps.setLong(2, fields.userId); + ps.setDate(3, Date.valueOf(fields.firstDay)); + ps.setDate(4, Date.valueOf(fields.lastDay)); + return ps; + }, keyHolder); + + return find(keyHolder.getKey().longValue()); + } + + public List findAllByProjectId(Long projectId) { + return jdbcTemplate.query( + "select id, project_id, user_id, first_day, last_day from allocations where project_id = ? order by first_day", + rowMapper, projectId + ); + } + + + private AllocationRecord find(long id) { + return jdbcTemplate.queryForObject( + "select id, project_id, user_id, first_day, last_day from allocations where id = ?", + rowMapper, id + ); + } + + private RowMapper rowMapper = + (rs, rowNum) -> AllocationRecord.allocationRecordBuilder() + .id(rs.getLong("id")) + .projectId(rs.getLong("project_id")) + .userId(rs.getLong("user_id")) + .firstDay(rs.getDate("first_day").toLocalDate()) + .lastDay(rs.getDate("last_day").toLocalDate()) + .build(); +} diff --git a/components/allocations/src/main/java/io/pivotal/pal/tracker/allocations/data/AllocationFields.java b/components/allocations/src/main/java/io/pivotal/pal/tracker/allocations/data/AllocationFields.java new file mode 100644 index 0000000..61f73fb --- /dev/null +++ b/components/allocations/src/main/java/io/pivotal/pal/tracker/allocations/data/AllocationFields.java @@ -0,0 +1,87 @@ +package io.pivotal.pal.tracker.allocations.data; + +import java.time.LocalDate; + +public class AllocationFields { + + public final long projectId; + public final long userId; + public final LocalDate firstDay; + public final LocalDate lastDay; + + public AllocationFields(Builder builder) { + projectId = builder.projectId; + userId = builder.userId; + firstDay = builder.firstDay; + lastDay = builder.lastDay; + } + + public static Builder allocationFieldsBuilder() { + return new Builder(); + } + + public static class Builder { + private long projectId; + private long userId; + private LocalDate firstDay; + private LocalDate lastDay; + + public AllocationFields build() { + return new AllocationFields(this); + } + + public Builder projectId(long projectId) { + this.projectId = projectId; + return this; + } + + public Builder userId(long userId) { + this.userId = userId; + return this; + } + + public Builder firstDay(LocalDate firstDay) { + this.firstDay = firstDay; + return this; + } + + public Builder lastDay(LocalDate lastDay) { + this.lastDay = lastDay; + return this; + } + } + + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + AllocationFields that = (AllocationFields) o; + + if (projectId != that.projectId) return false; + if (userId != that.userId) return false; + if (firstDay != null ? !firstDay.equals(that.firstDay) : that.firstDay != null) + return false; + return lastDay != null ? lastDay.equals(that.lastDay) : that.lastDay == null; + } + + @Override + public int hashCode() { + int result = (int) (projectId ^ (projectId >>> 32)); + result = 31 * result + (int) (userId ^ (userId >>> 32)); + result = 31 * result + (firstDay != null ? firstDay.hashCode() : 0); + result = 31 * result + (lastDay != null ? lastDay.hashCode() : 0); + return result; + } + + @Override + public String toString() { + return "AllocationFields{" + + "projectId=" + projectId + + ", userId=" + userId + + ", firstDay=" + firstDay + + ", lastDay=" + lastDay + + '}'; + } +} diff --git a/components/allocations/src/main/java/io/pivotal/pal/tracker/allocations/data/AllocationRecord.java b/components/allocations/src/main/java/io/pivotal/pal/tracker/allocations/data/AllocationRecord.java new file mode 100644 index 0000000..6381534 --- /dev/null +++ b/components/allocations/src/main/java/io/pivotal/pal/tracker/allocations/data/AllocationRecord.java @@ -0,0 +1,98 @@ +package io.pivotal.pal.tracker.allocations.data; + +import java.time.LocalDate; + +public class AllocationRecord { + + public final long id; + public final long projectId; + public final long userId; + public final LocalDate firstDay; + public final LocalDate lastDay; + + public AllocationRecord(Builder builder) { + id = builder.id; + projectId = builder.projectId; + userId = builder.userId; + firstDay = builder.firstDay; + lastDay = builder.lastDay; + } + + public static Builder allocationRecordBuilder() { + return new Builder(); + } + + public static class Builder { + private long id; + private long projectId; + private long userId; + private LocalDate firstDay; + private LocalDate lastDay; + + public AllocationRecord build() { + return new AllocationRecord(this); + } + + public Builder id(long id) { + this.id = id; + return this; + } + + public Builder projectId(long projectId) { + this.projectId = projectId; + return this; + } + + public Builder userId(long userId) { + this.userId = userId; + return this; + } + + public Builder firstDay(LocalDate firstDay) { + this.firstDay = firstDay; + return this; + } + + public Builder lastDay(LocalDate lastDay) { + this.lastDay = lastDay; + return this; + } + } + + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + AllocationRecord that = (AllocationRecord) o; + + if (id != that.id) return false; + if (projectId != that.projectId) return false; + if (userId != that.userId) return false; + if (firstDay != null ? !firstDay.equals(that.firstDay) : that.firstDay != null) + return false; + return lastDay != null ? lastDay.equals(that.lastDay) : that.lastDay == null; + } + + @Override + public int hashCode() { + int result = (int) (id ^ (id >>> 32)); + result = 31 * result + (int) (projectId ^ (projectId >>> 32)); + result = 31 * result + (int) (userId ^ (userId >>> 32)); + result = 31 * result + (firstDay != null ? firstDay.hashCode() : 0); + result = 31 * result + (lastDay != null ? lastDay.hashCode() : 0); + return result; + } + + @Override + public String toString() { + return "AllocationRecord{" + + "id=" + id + + ", projectId=" + projectId + + ", userId=" + userId + + ", firstDay=" + firstDay + + ", lastDay=" + lastDay + + '}'; + } +} diff --git a/components/allocations/src/test/java/test/pivotal/pal/tracker/allocations/AllocationControllerTest.java b/components/allocations/src/test/java/test/pivotal/pal/tracker/allocations/AllocationControllerTest.java new file mode 100644 index 0000000..4618004 --- /dev/null +++ b/components/allocations/src/test/java/test/pivotal/pal/tracker/allocations/AllocationControllerTest.java @@ -0,0 +1,93 @@ +package test.pivotal.pal.tracker.allocations; + +import io.pivotal.pal.tracker.allocations.*; +import io.pivotal.pal.tracker.allocations.data.AllocationDataGateway; +import io.pivotal.pal.tracker.allocations.data.AllocationRecord; +import org.junit.Test; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; + +import java.time.LocalDate; +import java.util.List; + +import static java.util.Arrays.asList; +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.Mockito.*; +import static test.pivotal.pal.tracker.allocations.TestBuilders.*; + + +public class AllocationControllerTest { + + private AllocationDataGateway allocationDataGateway = mock(AllocationDataGateway.class); + private ProjectClient client = mock(ProjectClient.class); + private AllocationController allocationsController = new AllocationController(allocationDataGateway, client); + + + @Test + public void testCreate() { + AllocationRecord record = testAllocationRecordBuilder() + .id(20L) + .projectId(31L) + .firstDay(LocalDate.parse("2016-02-20")) + .build(); + doReturn(record).when(allocationDataGateway).create(any()); + doReturn(new ProjectInfo(true)).when(client).getProject(anyLong()); + + + AllocationForm form = testAllocationFormBuilder() + .projectId(31L) + .firstDay("2016-02-20") + .build(); + ResponseEntity response = allocationsController.create(form); + + + verify(allocationDataGateway).create(testAllocationFieldsBuilder() + .projectId(31L) + .firstDay(LocalDate.parse("2016-02-20")) + .build() + ); + verify(client).getProject(31L); + + assertThat(response.getStatusCode()).isEqualTo(HttpStatus.CREATED); + assertThat(response.getBody()).isEqualTo(testAllocationInfoBuilder() + .id(20L) + .projectId(31L) + .firstDay("2016-02-20") + .build() + ); + } + + @Test + public void testCreate_WhenProjectIsNotActive() { + doReturn(new ProjectInfo(false)).when(client).getProject(anyLong()); + + AllocationForm form = testAllocationFormBuilder().build(); + + + ResponseEntity response = allocationsController.create(form); + + + assertThat(response.getStatusCode()).isEqualTo(HttpStatus.SERVICE_UNAVAILABLE); + } + + @Test + public void testList() { + List records = asList( + testAllocationRecordBuilder().id(12L).build(), + testAllocationRecordBuilder().id(13L).build() + ); + doReturn(records).when(allocationDataGateway).findAllByProjectId(anyLong()); + + + List result = allocationsController.list(13); + + + verify(allocationDataGateway).findAllByProjectId(13L); + assertThat(result).containsExactlyInAnyOrder( + testAllocationInfoBuilder().id(12L).build(), + testAllocationInfoBuilder().id(13L).build() + ); + } +} diff --git a/components/allocations/src/test/java/test/pivotal/pal/tracker/allocations/AllocationDataGatewayTest.java b/components/allocations/src/test/java/test/pivotal/pal/tracker/allocations/AllocationDataGatewayTest.java new file mode 100644 index 0000000..8c7e5ef --- /dev/null +++ b/components/allocations/src/test/java/test/pivotal/pal/tracker/allocations/AllocationDataGatewayTest.java @@ -0,0 +1,74 @@ +package test.pivotal.pal.tracker.allocations; + +import io.pivotal.pal.tracker.allocations.data.AllocationDataGateway; +import io.pivotal.pal.tracker.allocations.data.AllocationFields; +import io.pivotal.pal.tracker.allocations.data.AllocationRecord; +import io.pivotal.pal.tracker.testsupport.TestScenarioSupport; +import org.junit.Before; +import org.junit.Test; +import org.springframework.jdbc.core.JdbcTemplate; + +import java.sql.Timestamp; +import java.time.LocalDate; +import java.util.List; +import java.util.Map; + +import static io.pivotal.pal.tracker.allocations.data.AllocationFields.allocationFieldsBuilder; +import static io.pivotal.pal.tracker.allocations.data.AllocationRecord.allocationRecordBuilder; +import static org.assertj.core.api.Assertions.assertThat; + +public class AllocationDataGatewayTest { + + private TestScenarioSupport testScenarioSupport = new TestScenarioSupport("tracker_allocations_test"); + private JdbcTemplate template = testScenarioSupport.template; + private AllocationDataGateway gateway = new AllocationDataGateway(testScenarioSupport.dataSource); + + @Before + public void setup() { + template.execute("delete from allocations;"); + } + + @Test + public void testCreate() { + AllocationFields fields = allocationFieldsBuilder() + .projectId(22L) + .userId(12L) + .firstDay(LocalDate.parse("2016-01-13")) + .lastDay(LocalDate.parse("2016-09-17")) + .build(); + + + AllocationRecord created = gateway.create(fields); + + + assertThat(created.id).isNotNull(); + assertThat(created.projectId).isEqualTo(22L); + assertThat(created.userId).isEqualTo(12L); + assertThat(created.firstDay).isEqualTo(LocalDate.parse("2016-01-13")); + assertThat(created.lastDay).isEqualTo(LocalDate.parse("2016-09-17")); + + Map persisted = template.queryForMap("select * from allocations WHERE id = ?", created.id); + + assertThat(persisted.get("project_id")).isEqualTo(22L); + assertThat(persisted.get("user_id")).isEqualTo(12L); + assertThat(persisted.get("first_day")).isEqualTo(Timestamp.valueOf("2016-01-13 00:00:00")); + assertThat(persisted.get("last_day")).isEqualTo(Timestamp.valueOf("2016-09-17 00:00:00")); + } + + @Test + public void testFindAllByProjectId() { + template.execute("insert into allocations (id, project_id, user_id, first_day, last_day) values (97336, 22, 12, '2016-01-13', '2016-09-17')"); + + + List result = gateway.findAllByProjectId(22L); + + + assertThat(result).containsExactly(allocationRecordBuilder() + .id(97336L) + .projectId(22L) + .userId(12L) + .firstDay(LocalDate.parse("2016-01-13")) + .lastDay(LocalDate.parse("2016-09-17")) + .build()); + } +} diff --git a/components/allocations/src/test/java/test/pivotal/pal/tracker/allocations/TestBuilders.java b/components/allocations/src/test/java/test/pivotal/pal/tracker/allocations/TestBuilders.java new file mode 100644 index 0000000..0caedc7 --- /dev/null +++ b/components/allocations/src/test/java/test/pivotal/pal/tracker/allocations/TestBuilders.java @@ -0,0 +1,51 @@ +package test.pivotal.pal.tracker.allocations; + +import io.pivotal.pal.tracker.allocations.AllocationForm; +import io.pivotal.pal.tracker.allocations.AllocationInfo; +import io.pivotal.pal.tracker.allocations.data.AllocationFields; +import io.pivotal.pal.tracker.allocations.data.AllocationRecord; + +import java.time.LocalDate; + +import static io.pivotal.pal.tracker.allocations.AllocationForm.allocationFormBuilder; +import static io.pivotal.pal.tracker.allocations.AllocationInfo.allocationInfoBuilder; +import static io.pivotal.pal.tracker.allocations.data.AllocationFields.allocationFieldsBuilder; +import static io.pivotal.pal.tracker.allocations.data.AllocationRecord.allocationRecordBuilder; + +public class TestBuilders { + + public static AllocationRecord.Builder testAllocationRecordBuilder() { + return allocationRecordBuilder() + .id(12L) + .projectId(13L) + .userId(14L) + .firstDay(LocalDate.parse("2016-02-22")) + .lastDay(LocalDate.parse("2017-02-23")); + } + + public static AllocationFields.Builder testAllocationFieldsBuilder() { + return allocationFieldsBuilder() + .projectId(13L) + .userId(14L) + .firstDay(LocalDate.parse("2016-02-22")) + .lastDay(LocalDate.parse("2017-02-23")); + } + + public static AllocationForm.Builder testAllocationFormBuilder() { + return allocationFormBuilder() + .projectId(13L) + .userId(14L) + .firstDay("2016-02-22") + .lastDay("2017-02-23"); + } + + public static AllocationInfo.Builder testAllocationInfoBuilder() { + return allocationInfoBuilder() + .id(12L) + .projectId(13L) + .userId(14L) + .firstDay("2016-02-22") + .lastDay("2017-02-23") + .info("allocation info"); + } +} diff --git a/components/backlog/build.gradle b/components/backlog/build.gradle new file mode 100644 index 0000000..4526bf7 --- /dev/null +++ b/components/backlog/build.gradle @@ -0,0 +1,6 @@ +dependencies { + compile project(":components:rest-support") + compile "org.springframework:spring-jdbc:$springVersion" + + testCompile project(":components:test-support") +} diff --git a/components/backlog/src/main/java/io/pivotal/pal/tracker/backlog/ProjectClient.java b/components/backlog/src/main/java/io/pivotal/pal/tracker/backlog/ProjectClient.java new file mode 100644 index 0000000..3cdd67d --- /dev/null +++ b/components/backlog/src/main/java/io/pivotal/pal/tracker/backlog/ProjectClient.java @@ -0,0 +1,18 @@ +package io.pivotal.pal.tracker.backlog; + +import org.springframework.web.client.RestOperations; + +public class ProjectClient { + + private final RestOperations restOperations; + private final String endpoint; + + public ProjectClient(RestOperations restOperations, String registrationServerEndpoint) { + this.restOperations = restOperations; + this.endpoint = registrationServerEndpoint; + } + + public ProjectInfo getProject(long projectId) { + return restOperations.getForObject(endpoint + "/projects/" + projectId, ProjectInfo.class); + } +} diff --git a/components/backlog/src/main/java/io/pivotal/pal/tracker/backlog/ProjectInfo.java b/components/backlog/src/main/java/io/pivotal/pal/tracker/backlog/ProjectInfo.java new file mode 100644 index 0000000..9f40610 --- /dev/null +++ b/components/backlog/src/main/java/io/pivotal/pal/tracker/backlog/ProjectInfo.java @@ -0,0 +1,37 @@ +package io.pivotal.pal.tracker.backlog; + +public class ProjectInfo { + + public final boolean active; + + private ProjectInfo() { + this(false); + } + + public ProjectInfo(boolean active) { + this.active = active; + } + + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + ProjectInfo that = (ProjectInfo) o; + + return active == that.active; + } + + @Override + public int hashCode() { + return (active ? 1 : 0); + } + + @Override + public String toString() { + return "ProjectInfo{" + + "active=" + active + + '}'; + } +} diff --git a/components/backlog/src/main/java/io/pivotal/pal/tracker/backlog/StoryController.java b/components/backlog/src/main/java/io/pivotal/pal/tracker/backlog/StoryController.java new file mode 100644 index 0000000..fc5c11f --- /dev/null +++ b/components/backlog/src/main/java/io/pivotal/pal/tracker/backlog/StoryController.java @@ -0,0 +1,66 @@ +package io.pivotal.pal.tracker.backlog; + +import io.pivotal.pal.tracker.backlog.data.StoryDataGateway; +import io.pivotal.pal.tracker.backlog.data.StoryFields; +import io.pivotal.pal.tracker.backlog.data.StoryRecord; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +import static io.pivotal.pal.tracker.backlog.StoryInfo.storyInfoBuilder; +import static io.pivotal.pal.tracker.backlog.data.StoryFields.storyFieldsBuilder; +import static java.util.stream.Collectors.toList; + +@RestController +@RequestMapping("/stories") +public class StoryController { + private final StoryDataGateway gateway; + private final ProjectClient client; + + public StoryController(StoryDataGateway gateway, ProjectClient client) { + this.gateway = gateway; + this.client = client; + } + + + @PostMapping + public ResponseEntity create(@RequestBody StoryForm form) { + if (projectIsActive(form.projectId)) { + StoryRecord record = gateway.create(mapToFields(form)); + return new ResponseEntity<>(present(record), HttpStatus.CREATED); + } + + return new ResponseEntity<>(HttpStatus.SERVICE_UNAVAILABLE); + } + + @GetMapping + public List list(@RequestParam long projectId) { + return gateway.findAllByProjectId(projectId).stream() + .map(this::present) + .collect(toList()); + } + + + private boolean projectIsActive(long projectId) { + ProjectInfo project = client.getProject(projectId); + return project != null && project.active; + } + + private StoryFields mapToFields(StoryForm form) { + return storyFieldsBuilder() + .projectId(form.projectId) + .name(form.name) + .build(); + } + + private StoryInfo present(StoryRecord record) { + return storyInfoBuilder() + .id(record.id) + .projectId(record.projectId) + .name(record.name) + .info("story info") + .build(); + } +} diff --git a/components/backlog/src/main/java/io/pivotal/pal/tracker/backlog/StoryForm.java b/components/backlog/src/main/java/io/pivotal/pal/tracker/backlog/StoryForm.java new file mode 100644 index 0000000..4c26ab2 --- /dev/null +++ b/components/backlog/src/main/java/io/pivotal/pal/tracker/backlog/StoryForm.java @@ -0,0 +1,66 @@ +package io.pivotal.pal.tracker.backlog; + +public class StoryForm { + + public final long projectId; + public final String name; + + private StoryForm() { + this(storyFormBuilder()); + } + + private StoryForm(Builder builder) { + projectId = builder.projectId; + name = builder.name; + } + + public static Builder storyFormBuilder() { + return new Builder(); + } + + + public static class Builder { + private long projectId; + private String name; + + public StoryForm build() { + return new StoryForm(this); + } + + public Builder projectId(long projectId) { + this.projectId = projectId; + return this; + } + + public Builder name(String name) { + this.name = name; + return this; + } + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + StoryForm storyForm = (StoryForm) o; + + if (projectId != storyForm.projectId) return false; + return name != null ? name.equals(storyForm.name) : storyForm.name == null; + } + + @Override + public int hashCode() { + int result = (int) (projectId ^ (projectId >>> 32)); + result = 31 * result + (name != null ? name.hashCode() : 0); + return result; + } + + @Override + public String toString() { + return "StoryForm{" + + "projectId=" + projectId + + ", name='" + name + '\'' + + '}'; + } +} diff --git a/components/backlog/src/main/java/io/pivotal/pal/tracker/backlog/StoryInfo.java b/components/backlog/src/main/java/io/pivotal/pal/tracker/backlog/StoryInfo.java new file mode 100644 index 0000000..b5bbb19 --- /dev/null +++ b/components/backlog/src/main/java/io/pivotal/pal/tracker/backlog/StoryInfo.java @@ -0,0 +1,89 @@ +package io.pivotal.pal.tracker.backlog; + +public class StoryInfo { + + public final long id; + public final long projectId; + public final String name; + public final String info; + + private StoryInfo() { + this(storyInfoBuilder()); + } + + private StoryInfo(Builder builder) { + id = builder.id; + projectId = builder.projectId; + name = builder.name; + info = builder.info; + } + + public static Builder storyInfoBuilder() { + return new Builder(); + } + + + public static class Builder { + private long id; + private long projectId; + private String name; + private String info; + + public StoryInfo build() { + return new StoryInfo(this); + } + + public Builder id(long id) { + this.id = id; + return this; + } + + public Builder projectId(long projectId) { + this.projectId = projectId; + return this; + } + + public Builder name(String name) { + this.name = name; + return this; + } + + public Builder info(String info) { + this.info = info; + return this; + } + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + StoryInfo storyInfo = (StoryInfo) o; + + if (id != storyInfo.id) return false; + if (projectId != storyInfo.projectId) return false; + if (name != null ? !name.equals(storyInfo.name) : storyInfo.name != null) + return false; + return info != null ? info.equals(storyInfo.info) : storyInfo.info == null; + } + + @Override + public int hashCode() { + int result = (int) (id ^ (id >>> 32)); + result = 31 * result + (int) (projectId ^ (projectId >>> 32)); + result = 31 * result + (name != null ? name.hashCode() : 0); + result = 31 * result + (info != null ? info.hashCode() : 0); + return result; + } + + @Override + public String toString() { + return "StoryInfo{" + + "id=" + id + + ", projectId=" + projectId + + ", name='" + name + '\'' + + ", info='" + info + '\'' + + '}'; + } +} diff --git a/components/backlog/src/main/java/io/pivotal/pal/tracker/backlog/data/StoryDataGateway.java b/components/backlog/src/main/java/io/pivotal/pal/tracker/backlog/data/StoryDataGateway.java new file mode 100644 index 0000000..5c28edb --- /dev/null +++ b/components/backlog/src/main/java/io/pivotal/pal/tracker/backlog/data/StoryDataGateway.java @@ -0,0 +1,61 @@ +package io.pivotal.pal.tracker.backlog.data; + +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.core.RowMapper; +import org.springframework.jdbc.support.GeneratedKeyHolder; +import org.springframework.jdbc.support.KeyHolder; +import org.springframework.stereotype.Repository; + +import javax.sql.DataSource; +import java.sql.PreparedStatement; +import java.util.List; + +import static io.pivotal.pal.tracker.backlog.data.StoryRecord.storyRecordBuilder; +import static java.sql.Statement.RETURN_GENERATED_KEYS; + +@Repository +public class StoryDataGateway { + private final JdbcTemplate jdbcTemplate; + + public StoryDataGateway(DataSource dataSource) { + this.jdbcTemplate = new JdbcTemplate(dataSource); + } + + public StoryRecord create(StoryFields fields) { + KeyHolder keyHolder = new GeneratedKeyHolder(); + + jdbcTemplate.update(connection -> { + PreparedStatement ps = connection.prepareStatement( + "insert into stories (project_id, name) values (?, ?)", RETURN_GENERATED_KEYS + ); + + ps.setLong(1, fields.projectId); + ps.setString(2, fields.name); + return ps; + }, keyHolder); + + return find(keyHolder.getKey().longValue()); + } + + public List findAllByProjectId(Long projectId) { + return jdbcTemplate.query( + "select id, project_id, name from stories where project_id = ?", + rowMapper, projectId + ); + } + + + private StoryRecord find(long id) { + return jdbcTemplate.queryForObject( + "select id, project_id, name from stories where id = ?", + rowMapper, id + ); + } + + private RowMapper rowMapper + = (rs, num) -> storyRecordBuilder() + .id(rs.getLong("id")) + .projectId(rs.getLong("project_id")) + .name(rs.getString("name")) + .build(); +} diff --git a/components/backlog/src/main/java/io/pivotal/pal/tracker/backlog/data/StoryFields.java b/components/backlog/src/main/java/io/pivotal/pal/tracker/backlog/data/StoryFields.java new file mode 100644 index 0000000..ce36232 --- /dev/null +++ b/components/backlog/src/main/java/io/pivotal/pal/tracker/backlog/data/StoryFields.java @@ -0,0 +1,61 @@ +package io.pivotal.pal.tracker.backlog.data; + +public class StoryFields { + + public final long projectId; + public final String name; + + private StoryFields(Builder builder) { + projectId = builder.projectId; + name = builder.name; + } + + public static Builder storyFieldsBuilder() { + return new Builder(); + } + + public static class Builder { + private long projectId; + private String name; + + public StoryFields build() { + return new StoryFields(this); + } + + public Builder projectId(long projectId) { + this.projectId = projectId; + return this; + } + + public Builder name(String name) { + this.name = name; + return this; + } + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + StoryFields that = (StoryFields) o; + + if (projectId != that.projectId) return false; + return name != null ? name.equals(that.name) : that.name == null; + } + + @Override + public int hashCode() { + int result = (int) (projectId ^ (projectId >>> 32)); + result = 31 * result + (name != null ? name.hashCode() : 0); + return result; + } + + @Override + public String toString() { + return "StoryFields{" + + "projectId=" + projectId + + ", name='" + name + '\'' + + '}'; + } +} diff --git a/components/backlog/src/main/java/io/pivotal/pal/tracker/backlog/data/StoryRecord.java b/components/backlog/src/main/java/io/pivotal/pal/tracker/backlog/data/StoryRecord.java new file mode 100644 index 0000000..ad98d9a --- /dev/null +++ b/components/backlog/src/main/java/io/pivotal/pal/tracker/backlog/data/StoryRecord.java @@ -0,0 +1,72 @@ +package io.pivotal.pal.tracker.backlog.data; + +public class StoryRecord { + + public final long id; + public final long projectId; + public final String name; + + private StoryRecord(Builder builder) { + id = builder.id; + projectId = builder.projectId; + name = builder.name; + } + + public static Builder storyRecordBuilder() { + return new Builder(); + } + + public static class Builder { + private long id; + private long projectId; + private String name; + + public StoryRecord build() { + return new StoryRecord(this); + } + + public Builder id(long id) { + this.id = id; + return this; + } + + public Builder projectId(long projectId) { + this.projectId = projectId; + return this; + } + + public Builder name(String name) { + this.name = name; + return this; + } + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + StoryRecord that = (StoryRecord) o; + + if (id != that.id) return false; + if (projectId != that.projectId) return false; + return name != null ? name.equals(that.name) : that.name == null; + } + + @Override + public int hashCode() { + int result = (int) (id ^ (id >>> 32)); + result = 31 * result + (int) (projectId ^ (projectId >>> 32)); + result = 31 * result + (name != null ? name.hashCode() : 0); + return result; + } + + @Override + public String toString() { + return "StoryRecord{" + + "id=" + id + + ", projectId=" + projectId + + ", name='" + name + '\'' + + '}'; + } +} diff --git a/components/backlog/src/test/java/test/pivotal/pal/tracker/backlog/StoryControllerTest.java b/components/backlog/src/test/java/test/pivotal/pal/tracker/backlog/StoryControllerTest.java new file mode 100644 index 0000000..2405438 --- /dev/null +++ b/components/backlog/src/test/java/test/pivotal/pal/tracker/backlog/StoryControllerTest.java @@ -0,0 +1,98 @@ +package test.pivotal.pal.tracker.backlog; + +import io.pivotal.pal.tracker.backlog.*; +import io.pivotal.pal.tracker.backlog.data.StoryDataGateway; +import io.pivotal.pal.tracker.backlog.data.StoryRecord; +import org.junit.Test; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; + +import java.util.List; + +import static io.pivotal.pal.tracker.backlog.StoryForm.storyFormBuilder; +import static io.pivotal.pal.tracker.backlog.StoryInfo.storyInfoBuilder; +import static io.pivotal.pal.tracker.backlog.data.StoryFields.storyFieldsBuilder; +import static io.pivotal.pal.tracker.backlog.data.StoryRecord.storyRecordBuilder; +import static java.util.Arrays.asList; +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.Mockito.*; +import static test.pivotal.pal.tracker.backlog.TestBuilders.*; + +public class StoryControllerTest { + + private StoryDataGateway storyDataGateway = mock(StoryDataGateway.class); + private ProjectClient client = mock(ProjectClient.class); + private StoryController storyController = new StoryController(storyDataGateway, client); + + @Test + public void testCreate() { + StoryRecord record = storyRecordBuilder() + .id(4L) + .projectId(3L) + .name("Something Fun") + .build(); + + doReturn(record).when(storyDataGateway).create( + storyFieldsBuilder().projectId(3L).name("Something Fun").build() + ); + + doReturn(new ProjectInfo(true)).when(client).getProject(anyLong()); + + StoryForm form = storyFormBuilder() + .projectId(3L) + .name("Something Fun") + .build(); + + + ResponseEntity response = storyController.create(form); + + + verify(client).getProject(3L); + + assertThat(response.getStatusCode()).isEqualTo(HttpStatus.CREATED); + assertThat(response.getBody()).isEqualTo(storyInfoBuilder() + .id(4L) + .projectId(3L) + .name("Something Fun") + .info("story info") + .build() + ); + } + + @Test + public void testFailedCreate() { + doReturn(new ProjectInfo(false)).when(client).getProject(anyLong()); + + StoryForm form = testStoryFormBuilder() + .projectId(3L) + .build(); + + + ResponseEntity response = storyController.create(form); + + + assertThat(response.getStatusCode()).isEqualTo(HttpStatus.SERVICE_UNAVAILABLE); + } + + @Test + public void testList() { + List records = asList( + testStoryRecordBuilder().id(12L).build(), + testStoryRecordBuilder().id(13L).build() + ); + + doReturn(records).when(storyDataGateway).findAllByProjectId(anyLong()); + + + List result = storyController.list(13); + + + verify(storyDataGateway).findAllByProjectId(13L); + + assertThat(result).containsExactlyInAnyOrder( + testStoryInfoBuilder().id(12L).build(), + testStoryInfoBuilder().id(13L).build() + ); + } +} diff --git a/components/backlog/src/test/java/test/pivotal/pal/tracker/backlog/TestBuilders.java b/components/backlog/src/test/java/test/pivotal/pal/tracker/backlog/TestBuilders.java new file mode 100644 index 0000000..0e786d4 --- /dev/null +++ b/components/backlog/src/test/java/test/pivotal/pal/tracker/backlog/TestBuilders.java @@ -0,0 +1,41 @@ +package test.pivotal.pal.tracker.backlog; + +import io.pivotal.pal.tracker.backlog.StoryForm; +import io.pivotal.pal.tracker.backlog.StoryInfo; +import io.pivotal.pal.tracker.backlog.data.StoryFields; +import io.pivotal.pal.tracker.backlog.data.StoryRecord; + +import static io.pivotal.pal.tracker.backlog.StoryForm.storyFormBuilder; +import static io.pivotal.pal.tracker.backlog.StoryInfo.storyInfoBuilder; +import static io.pivotal.pal.tracker.backlog.data.StoryFields.storyFieldsBuilder; +import static io.pivotal.pal.tracker.backlog.data.StoryRecord.storyRecordBuilder; + +public class TestBuilders { + + public static StoryRecord.Builder testStoryRecordBuilder() { + return storyRecordBuilder() + .id(4L) + .projectId(3L) + .name("Something Fun"); + } + + public static StoryFields.Builder testStoryFieldsBuilder() { + return storyFieldsBuilder() + .projectId(3L) + .name("Something Fun"); + } + + public static StoryInfo.Builder testStoryInfoBuilder() { + return storyInfoBuilder() + .id(4L) + .projectId(3L) + .name("Something Fun") + .info("story info"); + } + + public static StoryForm.Builder testStoryFormBuilder() { + return storyFormBuilder() + .projectId(3L) + .name("Something Fun"); + } +} diff --git a/components/backlog/src/test/java/test/pivotal/pal/tracker/backlog/data/StoryDataGatewayTest.java b/components/backlog/src/test/java/test/pivotal/pal/tracker/backlog/data/StoryDataGatewayTest.java new file mode 100644 index 0000000..e6d705b --- /dev/null +++ b/components/backlog/src/test/java/test/pivotal/pal/tracker/backlog/data/StoryDataGatewayTest.java @@ -0,0 +1,66 @@ +package test.pivotal.pal.tracker.backlog.data; + +import io.pivotal.pal.tracker.backlog.data.StoryDataGateway; +import io.pivotal.pal.tracker.backlog.data.StoryFields; +import io.pivotal.pal.tracker.backlog.data.StoryRecord; +import io.pivotal.pal.tracker.testsupport.TestScenarioSupport; +import org.junit.Before; +import org.junit.Test; +import org.springframework.jdbc.core.JdbcTemplate; + +import java.util.List; +import java.util.Map; + +import static io.pivotal.pal.tracker.backlog.data.StoryFields.storyFieldsBuilder; +import static io.pivotal.pal.tracker.backlog.data.StoryRecord.storyRecordBuilder; +import static org.assertj.core.api.Assertions.assertThat; + +public class StoryDataGatewayTest { + + private TestScenarioSupport testScenarioSupport = new TestScenarioSupport("tracker_backlog_test"); + private JdbcTemplate template = testScenarioSupport.template; + private StoryDataGateway gateway = new StoryDataGateway(testScenarioSupport.dataSource); + + @Before + public void setUp() throws Exception { + template.execute("DELETE FROM stories;"); + } + + @Test + public void testCreate() { + StoryFields fields = storyFieldsBuilder() + .projectId(22L) + .name("aStory") + .build(); + + + StoryRecord created = gateway.create(fields); + + + assertThat(created.id).isNotNull(); + assertThat(created.name).isEqualTo("aStory"); + assertThat(created.projectId).isEqualTo(22L); + + Map persisted = template.queryForMap("select * from stories where id = ?", created.id); + + assertThat(persisted.get("project_id")).isEqualTo(22L); + assertThat(persisted.get("name")).isEqualTo("aStory"); + } + + @Test + public void testFindBy() { + template.execute("insert into stories (id, project_id, name) values (1346, 22, 'aStory')"); + + + List result = gateway.findAllByProjectId(22L); + + + assertThat(result).containsExactly( + storyRecordBuilder() + .id(1346L) + .projectId(22L) + .name("aStory") + .build() + ); + } +} diff --git a/components/build.gradle b/components/build.gradle new file mode 100644 index 0000000..06f3dca --- /dev/null +++ b/components/build.gradle @@ -0,0 +1,2 @@ +subprojects { +} \ No newline at end of file diff --git a/components/projects/build.gradle b/components/projects/build.gradle new file mode 100644 index 0000000..4526bf7 --- /dev/null +++ b/components/projects/build.gradle @@ -0,0 +1,6 @@ +dependencies { + compile project(":components:rest-support") + compile "org.springframework:spring-jdbc:$springVersion" + + testCompile project(":components:test-support") +} diff --git a/components/projects/src/main/java/io/pivotal/pal/tracker/projects/ProjectController.java b/components/projects/src/main/java/io/pivotal/pal/tracker/projects/ProjectController.java new file mode 100644 index 0000000..03855ab --- /dev/null +++ b/components/projects/src/main/java/io/pivotal/pal/tracker/projects/ProjectController.java @@ -0,0 +1,69 @@ +package io.pivotal.pal.tracker.projects; + +import io.pivotal.pal.tracker.projects.data.ProjectDataGateway; +import io.pivotal.pal.tracker.projects.data.ProjectFields; +import io.pivotal.pal.tracker.projects.data.ProjectRecord; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +import static io.pivotal.pal.tracker.projects.ProjectInfo.projectInfoBuilder; +import static io.pivotal.pal.tracker.projects.data.ProjectFields.projectFieldsBuilder; +import static java.util.stream.Collectors.toList; + +@RestController +@RequestMapping("/projects") +public class ProjectController { + + private final ProjectDataGateway gateway; + + public ProjectController(ProjectDataGateway gateway) { + this.gateway = gateway; + } + + @PostMapping + public ResponseEntity create(@RequestBody ProjectForm form) { + ProjectRecord record = gateway.create(formToFields(form)); + return new ResponseEntity<>(present(record), HttpStatus.CREATED); + } + + @GetMapping + public List list(@RequestParam long accountId) { + return gateway.findAllByAccountId(accountId) + .stream() + .map(this::present) + .collect(toList()); + } + + @GetMapping("/{projectId}") + public ProjectInfo get(@PathVariable long projectId) { + ProjectRecord record = gateway.find(projectId); + + if (record != null) { + return present(record); + } + + return null; + } + + + private ProjectFields formToFields(ProjectForm form) { + return projectFieldsBuilder() + .accountId(form.accountId) + .name(form.name) + .active(form.active) + .build(); + } + + private ProjectInfo present(ProjectRecord record) { + return projectInfoBuilder() + .id(record.id) + .accountId(record.accountId) + .name(record.name) + .active(record.active) + .info("project info") + .build(); + } +} diff --git a/components/projects/src/main/java/io/pivotal/pal/tracker/projects/ProjectForm.java b/components/projects/src/main/java/io/pivotal/pal/tracker/projects/ProjectForm.java new file mode 100644 index 0000000..a29ef8a --- /dev/null +++ b/components/projects/src/main/java/io/pivotal/pal/tracker/projects/ProjectForm.java @@ -0,0 +1,76 @@ +package io.pivotal.pal.tracker.projects; + +public class ProjectForm { + + public final long accountId; + public final String name; + public final boolean active; + + private ProjectForm() { + this(projectFormBuilder()); + } + + public ProjectForm(Builder builder) { + accountId = builder.accountId; + name = builder.name; + active = builder.active; + } + + public static Builder projectFormBuilder() { + return new Builder(); + } + + public static class Builder { + private long accountId; + private String name; + private boolean active; + + public ProjectForm build() { + return new ProjectForm(this); + } + + public Builder accountId(long accountId) { + this.accountId = accountId; + return this; + } + + public Builder name(String name) { + this.name = name; + return this; + } + + public Builder active(boolean active) { + this.active = active; + return this; + } + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + ProjectForm that = (ProjectForm) o; + + if (accountId != that.accountId) return false; + if (active != that.active) return false; + return name != null ? name.equals(that.name) : that.name == null; + } + + @Override + public int hashCode() { + int result = (int) (accountId ^ (accountId >>> 32)); + result = 31 * result + (name != null ? name.hashCode() : 0); + result = 31 * result + (active ? 1 : 0); + return result; + } + + @Override + public String toString() { + return "ProjectForm{" + + "accountId=" + accountId + + ", name='" + name + '\'' + + ", active=" + active + + '}'; + } +} diff --git a/components/projects/src/main/java/io/pivotal/pal/tracker/projects/ProjectInfo.java b/components/projects/src/main/java/io/pivotal/pal/tracker/projects/ProjectInfo.java new file mode 100644 index 0000000..3819206 --- /dev/null +++ b/components/projects/src/main/java/io/pivotal/pal/tracker/projects/ProjectInfo.java @@ -0,0 +1,99 @@ +package io.pivotal.pal.tracker.projects; + +public class ProjectInfo { + + public final long id; + public final long accountId; + public final String name; + public final boolean active; + public final String info; + + private ProjectInfo() { + this(projectInfoBuilder()); + } + + public ProjectInfo(Builder builder) { + id = builder.id; + accountId = builder.accountId; + name = builder.name; + active = builder.active; + info = builder.info; + } + + public static Builder projectInfoBuilder() { + return new Builder(); + } + + public static class Builder { + private long id; + private long accountId; + private String name; + private boolean active; + private String info; + + public ProjectInfo build() { + return new ProjectInfo(this); + } + + public Builder id(long id) { + this.id = id; + return this; + } + + public Builder accountId(long accountId) { + this.accountId = accountId; + return this; + } + + public Builder name(String name) { + this.name = name; + return this; + } + + public Builder active(boolean active) { + this.active = active; + return this; + } + + public Builder info(String info) { + this.info = info; + return this; + } + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + ProjectInfo that = (ProjectInfo) o; + + if (id != that.id) return false; + if (accountId != that.accountId) return false; + if (active != that.active) return false; + if (name != null ? !name.equals(that.name) : that.name != null) + return false; + return info != null ? info.equals(that.info) : that.info == null; + } + + @Override + public int hashCode() { + int result = (int) (id ^ (id >>> 32)); + result = 31 * result + (int) (accountId ^ (accountId >>> 32)); + result = 31 * result + (name != null ? name.hashCode() : 0); + result = 31 * result + (active ? 1 : 0); + result = 31 * result + (info != null ? info.hashCode() : 0); + return result; + } + + @Override + public String toString() { + return "ProjectInfo{" + + "id=" + id + + ", accountId=" + accountId + + ", name='" + name + '\'' + + ", active=" + active + + ", info='" + info + '\'' + + '}'; + } +} diff --git a/components/projects/src/main/java/io/pivotal/pal/tracker/projects/data/ProjectDataGateway.java b/components/projects/src/main/java/io/pivotal/pal/tracker/projects/data/ProjectDataGateway.java new file mode 100644 index 0000000..af13ae2 --- /dev/null +++ b/components/projects/src/main/java/io/pivotal/pal/tracker/projects/data/ProjectDataGateway.java @@ -0,0 +1,69 @@ +package io.pivotal.pal.tracker.projects.data; + +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.core.RowMapper; +import org.springframework.jdbc.support.GeneratedKeyHolder; +import org.springframework.jdbc.support.KeyHolder; +import org.springframework.stereotype.Repository; + +import javax.sql.DataSource; +import java.sql.PreparedStatement; +import java.util.List; + +import static io.pivotal.pal.tracker.projects.data.ProjectRecord.projectRecordBuilder; +import static java.sql.Statement.RETURN_GENERATED_KEYS; + +@Repository +public class ProjectDataGateway { + + private final JdbcTemplate jdbcTemplate; + + public ProjectDataGateway(DataSource dataSource) { + this.jdbcTemplate = new JdbcTemplate(dataSource); + } + + + public ProjectRecord create(ProjectFields fields) { + KeyHolder keyholder = new GeneratedKeyHolder(); + + jdbcTemplate.update(connection -> { + PreparedStatement ps = connection.prepareStatement( + "insert into projects (account_id, name, active) values (?, ?, ?)", RETURN_GENERATED_KEYS); + ps.setLong(1, fields.accountId); + ps.setString(2, fields.name); + ps.setBoolean(3, true); + return ps; + }, keyholder); + + return find(keyholder.getKey().longValue()); + } + + public List findAllByAccountId(Long accountId) { + return jdbcTemplate.query( + "select id, account_id, name, active from projects where account_id = ? order by name asc", + rowMapper, accountId + ); + } + + public ProjectRecord find(long id) { + List list = jdbcTemplate.query( + "select id, account_id, name, active from projects where id = ? order by name asc", + rowMapper, id + ); + + if (list.isEmpty()) { + return null; + } + + return list.get(0); + } + + + private RowMapper rowMapper = + (rs, num) -> projectRecordBuilder() + .id(rs.getLong("id")) + .accountId(rs.getLong("account_id")) + .name(rs.getString("name")) + .active(rs.getBoolean("active")) + .build(); +} diff --git a/components/projects/src/main/java/io/pivotal/pal/tracker/projects/data/ProjectFields.java b/components/projects/src/main/java/io/pivotal/pal/tracker/projects/data/ProjectFields.java new file mode 100644 index 0000000..0be1274 --- /dev/null +++ b/components/projects/src/main/java/io/pivotal/pal/tracker/projects/data/ProjectFields.java @@ -0,0 +1,74 @@ +package io.pivotal.pal.tracker.projects.data; + +public class ProjectFields { + + public final long accountId; + public final String name; + public final boolean active; + + private ProjectFields(Builder builder) { + accountId = builder.accountId; + name = builder.name; + active = builder.active; + } + + public static Builder projectFieldsBuilder() { + return new Builder(); + } + + public static class Builder { + + private long accountId; + private String name; + private boolean active; + + public ProjectFields build() { + return new ProjectFields(this); + } + + public Builder accountId(long accountId) { + this.accountId = accountId; + return this; + } + + public Builder name(String name) { + this.name = name; + return this; + } + + public Builder active(boolean active) { + this.active = active; + return this; + } + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + ProjectFields that = (ProjectFields) o; + + if (accountId != that.accountId) return false; + if (active != that.active) return false; + return name != null ? name.equals(that.name) : that.name == null; + } + + @Override + public int hashCode() { + int result = (int) (accountId ^ (accountId >>> 32)); + result = 31 * result + (name != null ? name.hashCode() : 0); + result = 31 * result + (active ? 1 : 0); + return result; + } + + @Override + public String toString() { + return "ProjectFields{" + + "accountId=" + accountId + + ", name='" + name + '\'' + + ", active=" + active + + '}'; + } +} + diff --git a/components/projects/src/main/java/io/pivotal/pal/tracker/projects/data/ProjectRecord.java b/components/projects/src/main/java/io/pivotal/pal/tracker/projects/data/ProjectRecord.java new file mode 100644 index 0000000..14e3950 --- /dev/null +++ b/components/projects/src/main/java/io/pivotal/pal/tracker/projects/data/ProjectRecord.java @@ -0,0 +1,84 @@ +package io.pivotal.pal.tracker.projects.data; + +public class ProjectRecord { + + public final long id; + public final long accountId; + public final String name; + public final boolean active; + + private ProjectRecord(Builder builder) { + id = builder.id; + accountId = builder.accountId; + name = builder.name; + active = builder.active; + } + + public static Builder projectRecordBuilder() { + return new Builder(); + } + + public static class Builder { + private long id; + private long accountId; + private String name; + private boolean active; + + public ProjectRecord build() { + return new ProjectRecord(this); + } + + public Builder id(long id) { + this.id = id; + return this; + } + + public Builder accountId(long accountId) { + this.accountId = accountId; + return this; + } + + public Builder name(String name) { + this.name = name; + return this; + } + + public Builder active(boolean active) { + this.active = active; + return this; + } + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + ProjectRecord that = (ProjectRecord) o; + + if (id != that.id) return false; + if (accountId != that.accountId) return false; + if (active != that.active) return false; + return name != null ? name.equals(that.name) : that.name == null; + } + + @Override + public int hashCode() { + int result = (int) (id ^ (id >>> 32)); + result = 31 * result + (int) (accountId ^ (accountId >>> 32)); + result = 31 * result + (name != null ? name.hashCode() : 0); + result = 31 * result + (active ? 1 : 0); + return result; + } + + @Override + public String toString() { + return "ProjectRecord{" + + "id=" + id + + ", accountId=" + accountId + + ", name='" + name + '\'' + + ", active=" + active + + '}'; + } +} + diff --git a/components/projects/src/test/java/test/pivotal/pal/tracker/projects/ProjectControllerTest.java b/components/projects/src/test/java/test/pivotal/pal/tracker/projects/ProjectControllerTest.java new file mode 100644 index 0000000..a956f2e --- /dev/null +++ b/components/projects/src/test/java/test/pivotal/pal/tracker/projects/ProjectControllerTest.java @@ -0,0 +1,81 @@ +package test.pivotal.pal.tracker.projects; + +import io.pivotal.pal.tracker.projects.ProjectController; +import io.pivotal.pal.tracker.projects.ProjectInfo; +import io.pivotal.pal.tracker.projects.data.ProjectDataGateway; +import io.pivotal.pal.tracker.projects.data.ProjectRecord; +import org.junit.Test; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; + +import java.util.List; + +import static java.util.Arrays.asList; +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.Mockito.*; +import static test.pivotal.pal.tracker.projects.TestBuilders.*; + + +public class ProjectControllerTest { + + private ProjectDataGateway gateway = mock(ProjectDataGateway.class); + private ProjectController controller = new ProjectController(gateway); + + @Test + public void testCreate() { + ProjectRecord record = testProjectRecordBuilder().build(); + doReturn(record).when(gateway).create(any()); + + + ResponseEntity result = controller.create(testProjectFormBuilder().build()); + + + verify(gateway).create(testProjectFieldsBuilder().build()); + assertThat(result.getStatusCode()).isEqualTo(HttpStatus.CREATED); + assertThat(result.getBody()).isEqualTo(testProjectInfoBuilder().build()); + } + + @Test + public void testList() { + List records = asList( + testProjectRecordBuilder().id(12).build(), + testProjectRecordBuilder().id(13).build() + ); + doReturn(records).when(gateway).findAllByAccountId(anyLong()); + + + List result = controller.list(23); + + + verify(gateway).findAllByAccountId(23L); + assertThat(result).containsExactlyInAnyOrder( + testProjectInfoBuilder().id(12).build(), + testProjectInfoBuilder().id(13).build() + ); + } + + @Test + public void testGet() { + ProjectRecord record = testProjectRecordBuilder().id(99).build(); + doReturn(record).when(gateway).find(anyLong()); + + + ProjectInfo result = controller.get(99); + + + verify(gateway).find(99); + assertThat(result).isEqualTo(testProjectInfoBuilder().id(99).build()); + } + + @Test + public void testGet_WithNull() { + doReturn(null).when(gateway).find(anyLong()); + + ProjectInfo result = controller.get(88); + + verify(gateway).find(88); + assertThat(result).isNull(); + } +} diff --git a/components/projects/src/test/java/test/pivotal/pal/tracker/projects/ProjectDataGatewayTest.java b/components/projects/src/test/java/test/pivotal/pal/tracker/projects/ProjectDataGatewayTest.java new file mode 100644 index 0000000..a11e5d1 --- /dev/null +++ b/components/projects/src/test/java/test/pivotal/pal/tracker/projects/ProjectDataGatewayTest.java @@ -0,0 +1,79 @@ +package test.pivotal.pal.tracker.projects; + +import io.pivotal.pal.tracker.projects.data.ProjectDataGateway; +import io.pivotal.pal.tracker.projects.data.ProjectFields; +import io.pivotal.pal.tracker.projects.data.ProjectRecord; +import io.pivotal.pal.tracker.testsupport.TestScenarioSupport; +import org.junit.Before; +import org.junit.Test; +import org.springframework.jdbc.core.JdbcTemplate; + +import java.util.List; +import java.util.Map; + +import static io.pivotal.pal.tracker.projects.data.ProjectFields.projectFieldsBuilder; +import static io.pivotal.pal.tracker.projects.data.ProjectRecord.projectRecordBuilder; +import static org.assertj.core.api.Assertions.assertThat; + +public class ProjectDataGatewayTest { + + private TestScenarioSupport testScenarioSupport = new TestScenarioSupport("tracker_registration_test"); + private JdbcTemplate template = testScenarioSupport.template; + private ProjectDataGateway gateway = new ProjectDataGateway(testScenarioSupport.dataSource); + + @Before + public void setUp() throws Exception { + template.execute("DELETE FROM projects;"); + template.execute("DELETE FROM accounts;"); + template.execute("DELETE FROM users;"); + } + + @Test + public void testCreate() { + template.execute("insert into users (id, name) values (12, 'Jack')"); + template.execute("insert into accounts (id, owner_id, name) values (1, 12, 'anAccount')"); + + ProjectFields fields = projectFieldsBuilder().accountId(1).name("aProject").build(); + ProjectRecord created = gateway.create(fields); + + + assertThat(created.id).isNotNull(); + assertThat(created.name).isEqualTo("aProject"); + assertThat(created.accountId).isEqualTo(1L); + + Map persisted = template.queryForMap("SELECT * FROM projects WHERE id = ?", created.id); + + assertThat(persisted.get("name")).isEqualTo("aProject"); + assertThat(persisted.get("account_id")).isEqualTo(1L); + } + + @Test + public void testFindAllByAccountId() { + template.execute("insert into users (id, name) values (12, 'Jack')"); + template.execute("insert into accounts (id, owner_id, name) values (1, 12, 'anAccount')"); + template.execute("insert into projects (id, account_id, name) values (22, 1, 'aProject')"); + + + List result = gateway.findAllByAccountId(1L); + + + assertThat(result).containsExactlyInAnyOrder( + projectRecordBuilder().id(22L).accountId(1L).name("aProject").active(true).build() + ); + } + + @Test + public void testFind() { + template.execute("insert into users (id, name) values (12, 'Jack')"); + template.execute("insert into accounts (id, owner_id, name) values (1, 12, 'anAccount')"); + template.execute("insert into projects (id, account_id, name, active) values (22, 1, 'aProject', true)"); + + + ProjectRecord foundRecord = gateway.find(22L); + + + assertThat(foundRecord).isEqualTo( + projectRecordBuilder().id(22L).accountId(1L).name("aProject").active(true).build() + ); + } +} diff --git a/components/projects/src/test/java/test/pivotal/pal/tracker/projects/TestBuilders.java b/components/projects/src/test/java/test/pivotal/pal/tracker/projects/TestBuilders.java new file mode 100644 index 0000000..00dda82 --- /dev/null +++ b/components/projects/src/test/java/test/pivotal/pal/tracker/projects/TestBuilders.java @@ -0,0 +1,45 @@ +package test.pivotal.pal.tracker.projects; + +import io.pivotal.pal.tracker.projects.ProjectForm; +import io.pivotal.pal.tracker.projects.ProjectInfo; +import io.pivotal.pal.tracker.projects.data.ProjectFields; +import io.pivotal.pal.tracker.projects.data.ProjectRecord; + +import static io.pivotal.pal.tracker.projects.ProjectForm.projectFormBuilder; +import static io.pivotal.pal.tracker.projects.ProjectInfo.projectInfoBuilder; +import static io.pivotal.pal.tracker.projects.data.ProjectFields.projectFieldsBuilder; +import static io.pivotal.pal.tracker.projects.data.ProjectRecord.projectRecordBuilder; + +public class TestBuilders { + + public static ProjectRecord.Builder testProjectRecordBuilder() { + return projectRecordBuilder() + .id(9L) + .accountId(23L) + .name("MyInfo") + .active(true); + } + + public static ProjectInfo.Builder testProjectInfoBuilder() { + return projectInfoBuilder() + .id(9L) + .accountId(23L) + .name("MyInfo") + .active(true) + .info("project info"); + } + + public static ProjectFields.Builder testProjectFieldsBuilder() { + return projectFieldsBuilder() + .accountId(23L) + .name("MyInfo") + .active(true); + } + + public static ProjectForm.Builder testProjectFormBuilder() { + return projectFormBuilder() + .accountId(23L) + .name("MyInfo") + .active(true); + } +} diff --git a/components/rest-support/build.gradle b/components/rest-support/build.gradle new file mode 100644 index 0000000..6c827eb --- /dev/null +++ b/components/rest-support/build.gradle @@ -0,0 +1,4 @@ +dependencies { + compile "org.springframework:spring-web:$springVersion" + compile "org.springframework:spring-context:$springVersion" +} diff --git a/components/rest-support/src/main/java/io/pivotal/pal/tracker/restsupport/RestConfig.java b/components/rest-support/src/main/java/io/pivotal/pal/tracker/restsupport/RestConfig.java new file mode 100644 index 0000000..3120f4c --- /dev/null +++ b/components/rest-support/src/main/java/io/pivotal/pal/tracker/restsupport/RestConfig.java @@ -0,0 +1,25 @@ +package io.pivotal.pal.tracker.restsupport; + +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.client.RestOperations; +import org.springframework.web.client.RestTemplate; + + +@Configuration +public class RestConfig { + + @Bean + public RestOperations restOperations() { + return new RestTemplate(); + } + + @Bean + public ObjectMapper objectMapper() { + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + return mapper; + } +} diff --git a/components/rest-support/src/main/java/io/pivotal/pal/tracker/restsupport/SpringDefaultController.java b/components/rest-support/src/main/java/io/pivotal/pal/tracker/restsupport/SpringDefaultController.java new file mode 100644 index 0000000..cc6889b --- /dev/null +++ b/components/rest-support/src/main/java/io/pivotal/pal/tracker/restsupport/SpringDefaultController.java @@ -0,0 +1,13 @@ +package io.pivotal.pal.tracker.restsupport; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class SpringDefaultController { + + @GetMapping("/") + public String defaultRoute() { + return "Noop!"; + } +} diff --git a/components/test-support/build.gradle b/components/test-support/build.gradle new file mode 100644 index 0000000..156619b --- /dev/null +++ b/components/test-support/build.gradle @@ -0,0 +1,6 @@ +dependencies { + compile project(":components:rest-support") + compile "org.springframework:spring-jdbc:$springVersion" + compile "mysql:mysql-connector-java:$mysqlVersion" + compile "junit:junit:$junitVersion" +} diff --git a/components/test-support/src/main/java/io/pivotal/pal/tracker/testsupport/TestDataSourceFactory.java b/components/test-support/src/main/java/io/pivotal/pal/tracker/testsupport/TestDataSourceFactory.java new file mode 100644 index 0000000..cd99c55 --- /dev/null +++ b/components/test-support/src/main/java/io/pivotal/pal/tracker/testsupport/TestDataSourceFactory.java @@ -0,0 +1,18 @@ +package io.pivotal.pal.tracker.testsupport; + +import com.mysql.cj.jdbc.MysqlDataSource; + +import javax.sql.DataSource; + + +public class TestDataSourceFactory { + + public static DataSource create(String name) { + MysqlDataSource dataSource = new MysqlDataSource(); + + dataSource.setUrl("jdbc:mysql://localhost:3306/" + name + "?useSSL=false&useTimezone=true&serverTimezone=UTC&useLegacyDatetimeCode=false"); + dataSource.setUser("tracker"); + + return dataSource; + } +} diff --git a/components/test-support/src/main/java/io/pivotal/pal/tracker/testsupport/TestScenarioSupport.java b/components/test-support/src/main/java/io/pivotal/pal/tracker/testsupport/TestScenarioSupport.java new file mode 100644 index 0000000..fcb840f --- /dev/null +++ b/components/test-support/src/main/java/io/pivotal/pal/tracker/testsupport/TestScenarioSupport.java @@ -0,0 +1,33 @@ +package io.pivotal.pal.tracker.testsupport; + +import org.springframework.jdbc.core.JdbcTemplate; + +import javax.sql.DataSource; +import java.util.TimeZone; + +public class TestScenarioSupport { + + public final JdbcTemplate template; + public final DataSource dataSource; + + public TestScenarioSupport(String dbName) { + dataSource = TestDataSourceFactory.create(dbName); + template = new JdbcTemplate(dataSource); + TimeZone.setDefault(TimeZone.getTimeZone("UTC")); + } + + public static void clearAllDatabases() { + clearTables("tracker_allocations_test", "allocations"); + clearTables("tracker_backlog_test", "stories"); + clearTables("tracker_registration_test", "projects", "accounts", "users"); + clearTables("tracker_timesheets_test", "time_entries"); + } + + private static void clearTables(String dbName, String... tableNames) { + JdbcTemplate template = new JdbcTemplate(TestDataSourceFactory.create(dbName)); + + for (String tableName : tableNames) { + template.execute("delete from " + tableName); + } + } +} diff --git a/components/timesheets/build.gradle b/components/timesheets/build.gradle new file mode 100644 index 0000000..4526bf7 --- /dev/null +++ b/components/timesheets/build.gradle @@ -0,0 +1,6 @@ +dependencies { + compile project(":components:rest-support") + compile "org.springframework:spring-jdbc:$springVersion" + + testCompile project(":components:test-support") +} diff --git a/components/timesheets/src/main/java/io/pivotal/pal/tracker/timesheets/ProjectClient.java b/components/timesheets/src/main/java/io/pivotal/pal/tracker/timesheets/ProjectClient.java new file mode 100644 index 0000000..bdbdb5b --- /dev/null +++ b/components/timesheets/src/main/java/io/pivotal/pal/tracker/timesheets/ProjectClient.java @@ -0,0 +1,18 @@ +package io.pivotal.pal.tracker.timesheets; + +import org.springframework.web.client.RestOperations; + +public class ProjectClient { + + private final RestOperations restOperations; + private final String endpoint; + + public ProjectClient(RestOperations restOperations, String registrationServerEndpoint) { + this.restOperations = restOperations; + this.endpoint = registrationServerEndpoint; + } + + public ProjectInfo getProject(long projectId) { + return restOperations.getForObject(endpoint + "/projects/" + projectId, ProjectInfo.class); + } +} diff --git a/components/timesheets/src/main/java/io/pivotal/pal/tracker/timesheets/ProjectInfo.java b/components/timesheets/src/main/java/io/pivotal/pal/tracker/timesheets/ProjectInfo.java new file mode 100644 index 0000000..0c08b3f --- /dev/null +++ b/components/timesheets/src/main/java/io/pivotal/pal/tracker/timesheets/ProjectInfo.java @@ -0,0 +1,37 @@ +package io.pivotal.pal.tracker.timesheets; + +public class ProjectInfo { + + public final boolean active; + + private ProjectInfo() { + this(false); + } + + public ProjectInfo(boolean active) { + this.active = active; + } + + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + ProjectInfo that = (ProjectInfo) o; + + return active == that.active; + } + + @Override + public int hashCode() { + return (active ? 1 : 0); + } + + @Override + public String toString() { + return "ProjectInfo{" + + "active=" + active + + '}'; + } +} diff --git a/components/timesheets/src/main/java/io/pivotal/pal/tracker/timesheets/TimeEntryController.java b/components/timesheets/src/main/java/io/pivotal/pal/tracker/timesheets/TimeEntryController.java new file mode 100644 index 0000000..a69f6a0 --- /dev/null +++ b/components/timesheets/src/main/java/io/pivotal/pal/tracker/timesheets/TimeEntryController.java @@ -0,0 +1,71 @@ +package io.pivotal.pal.tracker.timesheets; + +import io.pivotal.pal.tracker.timesheets.data.TimeEntryDataGateway; +import io.pivotal.pal.tracker.timesheets.data.TimeEntryFields; +import io.pivotal.pal.tracker.timesheets.data.TimeEntryRecord; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import java.time.LocalDate; +import java.util.List; + +import static io.pivotal.pal.tracker.timesheets.TimeEntryInfo.timeEntryInfoBuilder; +import static io.pivotal.pal.tracker.timesheets.data.TimeEntryFields.timeEntryFieldsBuilder; +import static java.util.stream.Collectors.toList; + +@RestController +@RequestMapping("/time-entries") +public class TimeEntryController { + + private final TimeEntryDataGateway gateway; + private final ProjectClient client; + + public TimeEntryController(TimeEntryDataGateway gateway, ProjectClient client) { + this.gateway = gateway; + this.client = client; + } + + + @PostMapping + public ResponseEntity create(@RequestBody TimeEntryForm form) { + if (projectIsActive(form.projectId)) { + TimeEntryRecord record = gateway.create(mapToFields(form)); + return new ResponseEntity<>(present(record), HttpStatus.CREATED); + } + return new ResponseEntity<>(HttpStatus.SERVICE_UNAVAILABLE); + } + + @GetMapping + public List list(@RequestParam long userId) { + return gateway.findAllByUserId(userId).stream() + .map(this::present) + .collect(toList()); + } + + + private TimeEntryInfo present(TimeEntryRecord record) { + return timeEntryInfoBuilder() + .id(record.id) + .projectId(record.projectId) + .userId(record.userId) + .date(record.date.toString()) + .hours(record.hours) + .info("time entry info") + .build(); + } + + private TimeEntryFields mapToFields(TimeEntryForm form) { + return timeEntryFieldsBuilder() + .projectId(form.projectId) + .userId(form.userId) + .date(LocalDate.parse(form.date)) + .hours(form.hours) + .build(); + } + + private boolean projectIsActive(long projectId) { + ProjectInfo project = client.getProject(projectId); + return project != null && project.active; + } +} diff --git a/components/timesheets/src/main/java/io/pivotal/pal/tracker/timesheets/TimeEntryForm.java b/components/timesheets/src/main/java/io/pivotal/pal/tracker/timesheets/TimeEntryForm.java new file mode 100644 index 0000000..96006cd --- /dev/null +++ b/components/timesheets/src/main/java/io/pivotal/pal/tracker/timesheets/TimeEntryForm.java @@ -0,0 +1,92 @@ +package io.pivotal.pal.tracker.timesheets; + +public class TimeEntryForm { + public final long projectId; + public final long userId; + public final String date; + public final int hours; + + private TimeEntryForm() { // for jackson + this(timeEntryFormBuilder()); + } + + private TimeEntryForm(Builder builder) { + projectId = builder.projectId; + userId = builder.userId; + date = builder.date; + hours = builder.hours; + } + + public static Builder timeEntryFormBuilder() { + return new Builder(); + } + + public static class Builder { + private long id; + private long projectId; + private long userId; + private String date; + private int hours; + + public Builder id(long id) { + this.id = id; + return this; + } + + public Builder projectId(long projectId) { + this.projectId = projectId; + return this; + } + + public Builder userId(long userId) { + this.userId = userId; + return this; + } + + public Builder date(String date) { + this.date = date; + return this; + } + + public Builder hours(Integer hours) { + this.hours = hours; + return this; + } + + public TimeEntryForm build() { + return new TimeEntryForm(this); + } + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + TimeEntryForm that = (TimeEntryForm) o; + + if (projectId != that.projectId) return false; + if (userId != that.userId) return false; + if (hours != that.hours) return false; + return date != null ? date.equals(that.date) : that.date == null; + } + + @Override + public int hashCode() { + int result = (int) (projectId ^ (projectId >>> 32)); + result = 31 * result + (int) (userId ^ (userId >>> 32)); + result = 31 * result + (date != null ? date.hashCode() : 0); + result = 31 * result + hours; + return result; + } + + @Override + public String toString() { + return "TimeEntryForm{" + + "projectId=" + projectId + + ", userId=" + userId + + ", date='" + date + '\'' + + ", hours=" + hours + + '}'; + } +} diff --git a/components/timesheets/src/main/java/io/pivotal/pal/tracker/timesheets/TimeEntryInfo.java b/components/timesheets/src/main/java/io/pivotal/pal/tracker/timesheets/TimeEntryInfo.java new file mode 100644 index 0000000..df7b306 --- /dev/null +++ b/components/timesheets/src/main/java/io/pivotal/pal/tracker/timesheets/TimeEntryInfo.java @@ -0,0 +1,109 @@ +package io.pivotal.pal.tracker.timesheets; + +public class TimeEntryInfo { + public final long id; + public final long projectId; + public final long userId; + public final String date; + public final int hours; + public final String info; + + public TimeEntryInfo() { // for jackson + this(timeEntryInfoBuilder()); + } + + private TimeEntryInfo(Builder builder) { + id = builder.id; + projectId = builder.projectId; + userId = builder.userId; + date = builder.date; + hours = builder.hours; + info = builder.info; + } + + public static Builder timeEntryInfoBuilder() { + return new Builder(); + } + + public static class Builder { + private long id; + private long projectId; + private long userId; + private String date; + private int hours; + private String info; + + public Builder id(long id) { + this.id = id; + return this; + } + + public Builder projectId(long projectId) { + this.projectId = projectId; + return this; + } + + public Builder userId(long userId) { + this.userId = userId; + return this; + } + + public Builder date(String date) { + this.date = date; + return this; + } + + public Builder hours(int hours) { + this.hours = hours; + return this; + } + + public Builder info(String info) { + this.info = info; + return this; + } + + public TimeEntryInfo build() { + return new TimeEntryInfo(this); + } + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + TimeEntryInfo that = (TimeEntryInfo) o; + + if (id != that.id) return false; + if (projectId != that.projectId) return false; + if (userId != that.userId) return false; + if (hours != that.hours) return false; + if (date != null ? !date.equals(that.date) : that.date != null) + return false; + return info != null ? info.equals(that.info) : that.info == null; + } + + @Override + public int hashCode() { + int result = (int) (id ^ (id >>> 32)); + result = 31 * result + (int) (projectId ^ (projectId >>> 32)); + result = 31 * result + (int) (userId ^ (userId >>> 32)); + result = 31 * result + (date != null ? date.hashCode() : 0); + result = 31 * result + hours; + result = 31 * result + (info != null ? info.hashCode() : 0); + return result; + } + + @Override + public String toString() { + return "TimeEntryInfo{" + + "id=" + id + + ", projectId=" + projectId + + ", userId=" + userId + + ", date=" + date + + ", hours=" + hours + + ", info='" + info + '\'' + + '}'; + } +} diff --git a/components/timesheets/src/main/java/io/pivotal/pal/tracker/timesheets/data/TimeEntryDataGateway.java b/components/timesheets/src/main/java/io/pivotal/pal/tracker/timesheets/data/TimeEntryDataGateway.java new file mode 100644 index 0000000..2e569d2 --- /dev/null +++ b/components/timesheets/src/main/java/io/pivotal/pal/tracker/timesheets/data/TimeEntryDataGateway.java @@ -0,0 +1,66 @@ +package io.pivotal.pal.tracker.timesheets.data; + +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.core.RowMapper; +import org.springframework.jdbc.support.GeneratedKeyHolder; +import org.springframework.jdbc.support.KeyHolder; +import org.springframework.stereotype.Repository; + +import javax.sql.DataSource; +import java.sql.Date; +import java.sql.PreparedStatement; +import java.util.List; + +import static io.pivotal.pal.tracker.timesheets.data.TimeEntryRecord.timeEntryRecordBuilder; +import static java.sql.Statement.RETURN_GENERATED_KEYS; + +@Repository +public class TimeEntryDataGateway { + + private JdbcTemplate jdbcTemplate; + + public TimeEntryDataGateway(DataSource dataSource) { + this.jdbcTemplate = new JdbcTemplate(dataSource); + } + + public TimeEntryRecord create(TimeEntryFields fields) { + KeyHolder keyHolder = new GeneratedKeyHolder(); + + jdbcTemplate.update( + connection -> { + PreparedStatement ps = connection.prepareStatement( + "insert into time_entries (project_id, user_id, date, hours) values (?, ?, ?, ?)", RETURN_GENERATED_KEYS); + ps.setLong(1, fields.projectId); + ps.setLong(2, fields.userId); + ps.setDate(3, Date.valueOf(fields.date)); + ps.setInt(4, fields.hours); + return ps; + }, keyHolder); + + return find(keyHolder.getKey().longValue()); + } + + public List findAllByUserId(long userId) { + return jdbcTemplate.query( + "select id, project_id, user_id, date, hours from time_entries where user_id = ?", + rowMapper, userId + ); + } + + + private TimeEntryRecord find(long id) { + return jdbcTemplate.queryForObject( + "select id, project_id, user_id, date, hours from time_entries where id = ?", + rowMapper, id + ); + } + + private RowMapper rowMapper = (rs, num) -> + timeEntryRecordBuilder() + .id(rs.getLong("id")) + .projectId(rs.getLong("project_id")) + .userId(rs.getLong("user_id")) + .date(rs.getDate("date").toLocalDate()) + .hours(rs.getInt("hours")) + .build(); +} diff --git a/components/timesheets/src/main/java/io/pivotal/pal/tracker/timesheets/data/TimeEntryFields.java b/components/timesheets/src/main/java/io/pivotal/pal/tracker/timesheets/data/TimeEntryFields.java new file mode 100644 index 0000000..fe698a8 --- /dev/null +++ b/components/timesheets/src/main/java/io/pivotal/pal/tracker/timesheets/data/TimeEntryFields.java @@ -0,0 +1,86 @@ +package io.pivotal.pal.tracker.timesheets.data; + +import java.time.LocalDate; + +public class TimeEntryFields { + + public final long projectId; + public final long userId; + public final LocalDate date; + public final int hours; + + private TimeEntryFields(Builder builder) { + projectId = builder.projectId; + userId = builder.userId; + date = builder.date; + hours = builder.hours; + } + + public static Builder timeEntryFieldsBuilder() { + return new Builder(); + } + + public static class Builder { + + private long projectId; + private long userId; + private LocalDate date; + private int hours; + + public TimeEntryFields build() { + return new TimeEntryFields(this); + } + + public Builder projectId(long projectId) { + this.projectId = projectId; + return this; + } + + public Builder userId(long userId) { + this.userId = userId; + return this; + } + + public Builder date(LocalDate date) { + this.date = date; + return this; + } + + public Builder hours(int hours) { + this.hours = hours; + return this; + } + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + TimeEntryFields that = (TimeEntryFields) o; + + if (projectId != that.projectId) return false; + if (userId != that.userId) return false; + if (hours != that.hours) return false; + return date != null ? date.equals(that.date) : that.date == null; + } + + @Override + public int hashCode() { + int result = (int) (projectId ^ (projectId >>> 32)); + result = 31 * result + (int) (userId ^ (userId >>> 32)); + result = 31 * result + (date != null ? date.hashCode() : 0); + result = 31 * result + hours; + return result; + } + + @Override + public String toString() { + return "TimeEntryFields{" + + "projectId=" + projectId + + ", userId=" + userId + + ", date=" + date + + ", hours=" + hours + + '}'; + } +} diff --git a/components/timesheets/src/main/java/io/pivotal/pal/tracker/timesheets/data/TimeEntryRecord.java b/components/timesheets/src/main/java/io/pivotal/pal/tracker/timesheets/data/TimeEntryRecord.java new file mode 100644 index 0000000..4c81890 --- /dev/null +++ b/components/timesheets/src/main/java/io/pivotal/pal/tracker/timesheets/data/TimeEntryRecord.java @@ -0,0 +1,97 @@ +package io.pivotal.pal.tracker.timesheets.data; + +import java.time.LocalDate; + +public class TimeEntryRecord { + + public final long id; + public final long projectId; + public final long userId; + public final LocalDate date; + public final int hours; + + private TimeEntryRecord(Builder builder) { + id = builder.id; + projectId = builder.projectId; + userId = builder.userId; + date = builder.date; + hours = builder.hours; + } + + public static Builder timeEntryRecordBuilder() { + return new Builder(); + } + + public static class Builder { + + private long id; + private long projectId; + private long userId; + private LocalDate date; + private int hours; + + public TimeEntryRecord build() { + return new TimeEntryRecord(this); + } + + public Builder id(long id) { + this.id = id; + return this; + } + + public Builder projectId(long projectId) { + this.projectId = projectId; + return this; + } + + public Builder userId(long userId) { + this.userId = userId; + return this; + } + + public Builder date(LocalDate date) { + this.date = date; + return this; + } + + public Builder hours(int hours) { + this.hours = hours; + return this; + } + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + TimeEntryRecord that = (TimeEntryRecord) o; + + if (id != that.id) return false; + if (projectId != that.projectId) return false; + if (userId != that.userId) return false; + if (hours != that.hours) return false; + return date != null ? date.equals(that.date) : that.date == null; + } + + @Override + public int hashCode() { + int result = (int) (id ^ (id >>> 32)); + result = 31 * result + (int) (projectId ^ (projectId >>> 32)); + result = 31 * result + (int) (userId ^ (userId >>> 32)); + result = 31 * result + (date != null ? date.hashCode() : 0); + result = 31 * result + hours; + return result; + } + + @Override + public String toString() { + return "TimeEntryRecord{" + + "id=" + id + + ", projectId=" + projectId + + ", userId=" + userId + + ", date=" + date + + ", hours=" + hours + + '}'; + } +} diff --git a/components/timesheets/src/test/java/test/pivotal/pal/tracker/timesheets/TestBuilders.java b/components/timesheets/src/test/java/test/pivotal/pal/tracker/timesheets/TestBuilders.java new file mode 100644 index 0000000..aaf395c --- /dev/null +++ b/components/timesheets/src/test/java/test/pivotal/pal/tracker/timesheets/TestBuilders.java @@ -0,0 +1,51 @@ +package test.pivotal.pal.tracker.timesheets; + +import io.pivotal.pal.tracker.timesheets.TimeEntryForm; +import io.pivotal.pal.tracker.timesheets.TimeEntryInfo; +import io.pivotal.pal.tracker.timesheets.data.TimeEntryFields; +import io.pivotal.pal.tracker.timesheets.data.TimeEntryRecord; + +import java.time.LocalDate; + +import static io.pivotal.pal.tracker.timesheets.TimeEntryForm.timeEntryFormBuilder; +import static io.pivotal.pal.tracker.timesheets.TimeEntryInfo.timeEntryInfoBuilder; +import static io.pivotal.pal.tracker.timesheets.data.TimeEntryFields.timeEntryFieldsBuilder; +import static io.pivotal.pal.tracker.timesheets.data.TimeEntryRecord.timeEntryRecordBuilder; + +public class TestBuilders { + + public static TimeEntryRecord.Builder testTimeEntryRecordBuilder() { + return timeEntryRecordBuilder() + .id(11) + .projectId(12) + .userId(13) + .date(LocalDate.parse("2017-09-19")) + .hours(20); + } + + public static TimeEntryFields.Builder testTimeEntryFieldsBuilder() { + return timeEntryFieldsBuilder() + .projectId(12) + .userId(13) + .date(LocalDate.parse("2017-09-19")) + .hours(20); + } + + public static TimeEntryForm.Builder testTimeEntryFormBuilder() { + return timeEntryFormBuilder() + .projectId(12) + .userId(13) + .date("2017-09-19") + .hours(20); + } + + public static TimeEntryInfo.Builder testTimeEntryInfoBuilder() { + return timeEntryInfoBuilder() + .id(11) + .projectId(12) + .userId(13) + .date("2017-09-19") + .hours(20) + .info("time entry info"); + } +} diff --git a/components/timesheets/src/test/java/test/pivotal/pal/tracker/timesheets/TimeEntryControllerTest.java b/components/timesheets/src/test/java/test/pivotal/pal/tracker/timesheets/TimeEntryControllerTest.java new file mode 100644 index 0000000..ddc70c5 --- /dev/null +++ b/components/timesheets/src/test/java/test/pivotal/pal/tracker/timesheets/TimeEntryControllerTest.java @@ -0,0 +1,78 @@ +package test.pivotal.pal.tracker.timesheets; + +import io.pivotal.pal.tracker.timesheets.*; +import io.pivotal.pal.tracker.timesheets.data.TimeEntryDataGateway; +import io.pivotal.pal.tracker.timesheets.data.TimeEntryFields; +import io.pivotal.pal.tracker.timesheets.data.TimeEntryRecord; +import org.junit.Test; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; + +import java.util.List; + +import static java.util.Arrays.asList; +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.Mockito.*; +import static test.pivotal.pal.tracker.timesheets.TestBuilders.*; + + +public class TimeEntryControllerTest { + + private TimeEntryDataGateway gateway = mock(TimeEntryDataGateway.class); + private ProjectClient client = mock(ProjectClient.class); + private TimeEntryController controller = new TimeEntryController(gateway, client); + + + @Test + public void testCreate() { + TimeEntryRecord record = testTimeEntryRecordBuilder().projectId(12).build(); + TimeEntryFields fields = testTimeEntryFieldsBuilder().projectId(12).build(); + TimeEntryForm form = testTimeEntryFormBuilder().projectId(12).build(); + + doReturn(record).when(gateway).create(fields); + doReturn(new ProjectInfo(true)).when(client).getProject(anyLong()); + + + ResponseEntity result = controller.create(form); + + + verify(client).getProject(12L); + assertThat(result.getStatusCode()).isEqualTo(HttpStatus.CREATED); + assertThat(result.getBody()).isEqualTo(testTimeEntryInfoBuilder().projectId(12).build()); + } + + @Test + public void testCreate_WhenFailed() { + doReturn(new ProjectInfo(false)).when(client).getProject(anyLong()); + + + ResponseEntity result = controller.create(testTimeEntryFormBuilder().projectId(12).build()); + + + assertThat(result.getStatusCode()).isEqualTo(HttpStatus.SERVICE_UNAVAILABLE); + } + + @Test + public void testList() { + List records = asList( + testTimeEntryRecordBuilder().id(10).build(), + testTimeEntryRecordBuilder().id(11).build(), + testTimeEntryRecordBuilder().id(12).build() + ); + doReturn(records).when(gateway).findAllByUserId(anyLong()); + int userId = 210; + + + List result = controller.list(userId); + + + verify(gateway).findAllByUserId(userId); + + assertThat(result).containsExactlyInAnyOrder( + testTimeEntryInfoBuilder().id(10).build(), + testTimeEntryInfoBuilder().id(11).build(), + testTimeEntryInfoBuilder().id(12).build() + ); + } +} diff --git a/components/timesheets/src/test/java/test/pivotal/pal/tracker/timesheets/TimeEntryDataGatewayTest.java b/components/timesheets/src/test/java/test/pivotal/pal/tracker/timesheets/TimeEntryDataGatewayTest.java new file mode 100644 index 0000000..bea2719 --- /dev/null +++ b/components/timesheets/src/test/java/test/pivotal/pal/tracker/timesheets/TimeEntryDataGatewayTest.java @@ -0,0 +1,75 @@ +package test.pivotal.pal.tracker.timesheets; + +import io.pivotal.pal.tracker.testsupport.TestScenarioSupport; +import io.pivotal.pal.tracker.timesheets.data.TimeEntryDataGateway; +import io.pivotal.pal.tracker.timesheets.data.TimeEntryFields; +import io.pivotal.pal.tracker.timesheets.data.TimeEntryRecord; +import org.junit.Before; +import org.junit.Test; +import org.springframework.jdbc.core.JdbcTemplate; + +import java.sql.Timestamp; +import java.time.LocalDate; +import java.util.List; +import java.util.Map; + +import static io.pivotal.pal.tracker.timesheets.data.TimeEntryFields.timeEntryFieldsBuilder; +import static io.pivotal.pal.tracker.timesheets.data.TimeEntryRecord.timeEntryRecordBuilder; +import static org.assertj.core.api.Assertions.assertThat; + +public class TimeEntryDataGatewayTest { + + private TestScenarioSupport testScenarioSupport = new TestScenarioSupport("tracker_timesheets_test"); + private JdbcTemplate template = testScenarioSupport.template; + private TimeEntryDataGateway gateway = new TimeEntryDataGateway(testScenarioSupport.dataSource); + + + @Before + public void setUp() throws Exception { + template.execute("DELETE FROM time_entries;"); + } + + @Test + public void testCreate() { + TimeEntryFields fields = timeEntryFieldsBuilder() + .projectId(22L) + .userId(12L) + .date(LocalDate.parse("2016-02-28")) + .hours(8) + .build(); + TimeEntryRecord created = gateway.create(fields); + + + assertThat(created.id).isNotNull(); + assertThat(created.projectId).isEqualTo(22L); + assertThat(created.userId).isEqualTo(12L); + assertThat(created.date).isEqualTo(LocalDate.parse("2016-02-28")); + assertThat(created.hours).isEqualTo(8); + + Map persisted = template.queryForMap("SELECT * FROM time_entries WHERE id = ?", created.id); + + assertThat(persisted.get("project_id")).isEqualTo(22L); + assertThat(persisted.get("user_id")).isEqualTo(12L); + assertThat(persisted.get("date")).isEqualTo(Timestamp.valueOf("2016-02-28 00:00:00")); + assertThat(persisted.get("hours")).isEqualTo(8); + } + + @Test + public void testFindAllByUserId() { + template.execute("insert into time_entries (id, project_id, user_id, date, hours) values (2346, 22, 12, '2016-01-13', 8)"); + + + List result = gateway.findAllByUserId(12L); + + + assertThat(result).containsExactlyInAnyOrder( + timeEntryRecordBuilder() + .id(2346L) + .projectId(22L) + .userId(12L) + .date(LocalDate.parse("2016-01-13")) + .hours(8) + .build() + ); + } +} diff --git a/components/users/build.gradle b/components/users/build.gradle new file mode 100644 index 0000000..faf294b --- /dev/null +++ b/components/users/build.gradle @@ -0,0 +1,5 @@ +dependencies { + compile "org.springframework:spring-jdbc:$springVersion" + compile project(":components:rest-support") + testCompile project(":components:test-support") +} diff --git a/components/users/src/main/java/io/pivotal/pal/tracker/users/UserController.java b/components/users/src/main/java/io/pivotal/pal/tracker/users/UserController.java new file mode 100644 index 0000000..8e92af7 --- /dev/null +++ b/components/users/src/main/java/io/pivotal/pal/tracker/users/UserController.java @@ -0,0 +1,31 @@ +package io.pivotal.pal.tracker.users; + +import io.pivotal.pal.tracker.users.data.UserDataGateway; +import io.pivotal.pal.tracker.users.data.UserRecord; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/users") +public class UserController { + + private final UserDataGateway gateway; + + public UserController(UserDataGateway gateway) { + this.gateway = gateway; + } + + + @GetMapping("/{userId}") + public UserInfo show(@PathVariable long userId) { + UserRecord record = gateway.find(userId); + + if (record == null) { + return null; + } + + return new UserInfo(record.id, record.name, "user info"); + } +} diff --git a/components/users/src/main/java/io/pivotal/pal/tracker/users/UserInfo.java b/components/users/src/main/java/io/pivotal/pal/tracker/users/UserInfo.java new file mode 100644 index 0000000..a1b1675 --- /dev/null +++ b/components/users/src/main/java/io/pivotal/pal/tracker/users/UserInfo.java @@ -0,0 +1,49 @@ +package io.pivotal.pal.tracker.users; + +public class UserInfo { + + public final long id; + public final String name; + public final String info; + + public UserInfo(long id, String name, String info) { + this.id = id; + this.name = name; + this.info = info; + } + + private UserInfo() { + this(0, null, null); + } + + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + UserInfo userInfo = (UserInfo) o; + + if (id != userInfo.id) return false; + if (name != null ? !name.equals(userInfo.name) : userInfo.name != null) + return false; + return info != null ? info.equals(userInfo.info) : userInfo.info == null; + } + + @Override + public int hashCode() { + int result = (int) (id ^ (id >>> 32)); + result = 31 * result + (name != null ? name.hashCode() : 0); + result = 31 * result + (info != null ? info.hashCode() : 0); + return result; + } + + @Override + public String toString() { + return "UserInfo{" + + "id=" + id + + ", name='" + name + '\'' + + ", info='" + info + '\'' + + '}'; + } +} diff --git a/components/users/src/main/java/io/pivotal/pal/tracker/users/data/UserDataGateway.java b/components/users/src/main/java/io/pivotal/pal/tracker/users/data/UserDataGateway.java new file mode 100644 index 0000000..ccd7bac --- /dev/null +++ b/components/users/src/main/java/io/pivotal/pal/tracker/users/data/UserDataGateway.java @@ -0,0 +1,50 @@ +package io.pivotal.pal.tracker.users.data; + +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.core.RowMapper; +import org.springframework.jdbc.support.GeneratedKeyHolder; +import org.springframework.jdbc.support.KeyHolder; +import org.springframework.stereotype.Repository; + +import javax.sql.DataSource; +import java.sql.PreparedStatement; +import java.util.List; + +import static java.sql.Statement.RETURN_GENERATED_KEYS; + +@Repository +public class UserDataGateway { + + private final JdbcTemplate jdbcTemplate; + + public UserDataGateway(DataSource dataSource) { + this.jdbcTemplate = new JdbcTemplate(dataSource); + } + + + public UserRecord create(String name) { + KeyHolder keyholder = new GeneratedKeyHolder(); + + jdbcTemplate.update(connection -> { + PreparedStatement ps = connection.prepareStatement("insert into users (name) values (?)", RETURN_GENERATED_KEYS); + ps.setString(1, name); + return ps; + }, keyholder); + + return find(keyholder.getKey().longValue()); + } + + public UserRecord find(long id) { + List list = jdbcTemplate.query("select id, name from users where id = ? limit 1", rowMapper, id); + + if (list.isEmpty()) { + return null; + } + + return list.get(0); + } + + + private RowMapper rowMapper = + (rs, num) -> new UserRecord(rs.getLong("id"), rs.getString("name")); +} diff --git a/components/users/src/main/java/io/pivotal/pal/tracker/users/data/UserRecord.java b/components/users/src/main/java/io/pivotal/pal/tracker/users/data/UserRecord.java new file mode 100644 index 0000000..9e769b1 --- /dev/null +++ b/components/users/src/main/java/io/pivotal/pal/tracker/users/data/UserRecord.java @@ -0,0 +1,39 @@ +package io.pivotal.pal.tracker.users.data; + +public class UserRecord { + + public final long id; + public final String name; + + public UserRecord(long id, String name) { + this.id = id; + this.name = name; + } + + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + UserRecord that = (UserRecord) o; + + if (id != that.id) return false; + return name != null ? name.equals(that.name) : that.name == null; + } + + @Override + public int hashCode() { + int result = (int) (id ^ (id >>> 32)); + result = 31 * result + (name != null ? name.hashCode() : 0); + return result; + } + + @Override + public String toString() { + return "UserRecord{" + + "id=" + id + + ", name='" + name + '\'' + + '}'; + } +} diff --git a/components/users/src/test/java/test/pivotal/pal/tracker/users/UserControllerTest.java b/components/users/src/test/java/test/pivotal/pal/tracker/users/UserControllerTest.java new file mode 100644 index 0000000..22bdca4 --- /dev/null +++ b/components/users/src/test/java/test/pivotal/pal/tracker/users/UserControllerTest.java @@ -0,0 +1,27 @@ +package test.pivotal.pal.tracker.users; + +import io.pivotal.pal.tracker.users.UserController; +import io.pivotal.pal.tracker.users.UserInfo; +import io.pivotal.pal.tracker.users.data.UserDataGateway; +import io.pivotal.pal.tracker.users.data.UserRecord; +import org.junit.Test; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.Mockito.*; + +public class UserControllerTest { + + private UserDataGateway gateway = mock(UserDataGateway.class); + private UserController controller = new UserController(gateway); + + @Test + public void testShow() { + doReturn(new UserRecord(3L, "Some User")).when(gateway).find(anyLong()); + + UserInfo result = controller.show(3); + + verify(gateway).find(3L); + assertThat(result).isEqualTo(new UserInfo(3L, "Some User", "user info")); + } +} diff --git a/components/users/src/test/java/test/pivotal/pal/tracker/users/data/UserDataGatewayTest.java b/components/users/src/test/java/test/pivotal/pal/tracker/users/data/UserDataGatewayTest.java new file mode 100644 index 0000000..2f24120 --- /dev/null +++ b/components/users/src/test/java/test/pivotal/pal/tracker/users/data/UserDataGatewayTest.java @@ -0,0 +1,57 @@ +package test.pivotal.pal.tracker.users.data; + + +import io.pivotal.pal.tracker.testsupport.TestScenarioSupport; +import io.pivotal.pal.tracker.users.data.UserDataGateway; +import io.pivotal.pal.tracker.users.data.UserRecord; +import org.junit.Before; +import org.junit.Test; +import org.springframework.jdbc.core.JdbcTemplate; + +import java.util.Map; + +import static org.assertj.core.api.Assertions.assertThat; + +public class UserDataGatewayTest { + + private TestScenarioSupport testScenarioSupport = new TestScenarioSupport("tracker_registration_test"); + private JdbcTemplate template = testScenarioSupport.template; + private UserDataGateway gateway = new UserDataGateway(testScenarioSupport.dataSource); + + + @Before + public void setUp() throws Exception { + template.execute("DELETE FROM projects;"); + template.execute("DELETE FROM accounts;"); + template.execute("DELETE FROM users;"); + } + + @Test + public void testCreate() { + UserRecord createdUser = gateway.create("aUser"); + + + assertThat(createdUser.id).isGreaterThan(0); + assertThat(createdUser.name).isEqualTo("aUser"); + + Map persistedFields = template.queryForMap("SELECT id, name FROM users WHERE id = ?", createdUser.id); + assertThat(persistedFields.get("id")).isEqualTo(createdUser.id); + assertThat(persistedFields.get("name")).isEqualTo(createdUser.name); + } + + @Test + public void testFind() { + template.execute("INSERT INTO users(id, name) VALUES (42346, 'aName'), (42347, 'anotherName'), (42348, 'andAnotherName')"); + + + UserRecord record = gateway.find(42347L); + + + assertThat(record).isEqualTo(new UserRecord(42347L, "anotherName")); + } + + @Test + public void testFind_WhenNotFound() { + assertThat(gateway.find(42347L)).isNull(); + } +} diff --git a/databases/allocations-database/build.gradle b/databases/allocations-database/build.gradle new file mode 100644 index 0000000..641d39b --- /dev/null +++ b/databases/allocations-database/build.gradle @@ -0,0 +1,6 @@ +databases { + devDatabase = "tracker_allocations_dev" + testDatabase = "tracker_allocations_test" + cfDatabase = "tracker-allocations-database" + cfApp = "tracker-allocations" +} diff --git a/databases/allocations-database/migrations/V1__initial_schema.sql b/databases/allocations-database/migrations/V1__initial_schema.sql new file mode 100644 index 0000000..b08ab3e --- /dev/null +++ b/databases/allocations-database/migrations/V1__initial_schema.sql @@ -0,0 +1,11 @@ +create table allocations ( + id bigint(20) not null auto_increment, + project_id bigint(20), + user_id bigint(20), + first_day datetime, + last_day datetime, + + primary key (id) +) +engine = innodb +default charset = utf8; diff --git a/databases/backlog-database/build.gradle b/databases/backlog-database/build.gradle new file mode 100644 index 0000000..4b7cec9 --- /dev/null +++ b/databases/backlog-database/build.gradle @@ -0,0 +1,6 @@ +databases { + devDatabase = "tracker_backlog_dev" + testDatabase = "tracker_backlog_test" + cfDatabase = "tracker-backlog-database" + cfApp = "tracker-backlog" +} diff --git a/databases/backlog-database/migrations/V1__initial_schema.sql b/databases/backlog-database/migrations/V1__initial_schema.sql new file mode 100644 index 0000000..f83716d --- /dev/null +++ b/databases/backlog-database/migrations/V1__initial_schema.sql @@ -0,0 +1,9 @@ +create table stories ( + id bigint(20) not null auto_increment, + project_id bigint(20), + name VARCHAR(255), + + primary key (id) +) +engine = innodb +default charset = utf8; diff --git a/databases/build.gradle b/databases/build.gradle new file mode 100644 index 0000000..81469e0 --- /dev/null +++ b/databases/build.gradle @@ -0,0 +1,7 @@ +import io.pivotal.pal.tracker.gradlebuild.CfMigrationPlugin +import io.pivotal.pal.tracker.gradlebuild.LocalMigrationPlugin + +subprojects { + apply plugin: LocalMigrationPlugin + apply plugin: CfMigrationPlugin +} diff --git a/databases/create_databases.sql b/databases/create_databases.sql new file mode 100644 index 0000000..f9b793a --- /dev/null +++ b/databases/create_databases.sql @@ -0,0 +1,21 @@ +DROP DATABASE IF EXISTS tracker_allocations_dev; +DROP DATABASE IF EXISTS tracker_backlog_dev; +DROP DATABASE IF EXISTS tracker_registration_dev; +DROP DATABASE IF EXISTS tracker_timesheets_dev; +DROP DATABASE IF EXISTS tracker_allocations_test; +DROP DATABASE IF EXISTS tracker_backlog_test; +DROP DATABASE IF EXISTS tracker_registration_test; +DROP DATABASE IF EXISTS tracker_timesheets_test; + +CREATE USER IF NOT EXISTS 'tracker'@'localhost' + identified by ''; +GRANT ALL PRIVILEGES ON *.* TO 'tracker' @'localhost'; + +CREATE DATABASE tracker_allocations_dev; +CREATE DATABASE tracker_backlog_dev; +CREATE DATABASE tracker_registration_dev; +CREATE DATABASE tracker_timesheets_dev; +CREATE DATABASE tracker_allocations_test; +CREATE DATABASE tracker_backlog_test; +CREATE DATABASE tracker_registration_test; +CREATE DATABASE tracker_timesheets_test; diff --git a/databases/registration-database/build.gradle b/databases/registration-database/build.gradle new file mode 100644 index 0000000..e065f2a --- /dev/null +++ b/databases/registration-database/build.gradle @@ -0,0 +1,6 @@ +databases { + devDatabase = "tracker_registration_dev" + testDatabase = "tracker_registration_test" + cfDatabase = "tracker-registration-database" + cfApp = "tracker-registration" +} diff --git a/databases/registration-database/migrations/V1__initial_schema.sql b/databases/registration-database/migrations/V1__initial_schema.sql new file mode 100644 index 0000000..03e3d00 --- /dev/null +++ b/databases/registration-database/migrations/V1__initial_schema.sql @@ -0,0 +1,34 @@ +create table users ( + id bigint(20) not null auto_increment, + name VARCHAR(255), + + primary key (id), + unique key name (name) +) +engine = innodb +default charset = utf8; + +create table accounts ( + id bigint(20) not null auto_increment, + owner_id bigint(20), + name VARCHAR(255), + + primary key (id), + unique key name (name), + constraint foreign key (owner_id) references users (id) +) +engine = innodb +default charset = utf8; + +create table projects ( + id bigint(20) not null auto_increment, + account_id bigint(20), + name VARCHAR(255), + active bit(1) not null default b'1', + + primary key (id), + unique key name (name), + constraint foreign key (account_id) references accounts (id) +) +engine = innodb +default charset = utf8; diff --git a/databases/timesheets-database/build.gradle b/databases/timesheets-database/build.gradle new file mode 100644 index 0000000..db86817 --- /dev/null +++ b/databases/timesheets-database/build.gradle @@ -0,0 +1,6 @@ +databases { + devDatabase = "tracker_timesheets_dev" + testDatabase = "tracker_timesheets_test" + cfDatabase = "tracker-timesheets-database" + cfApp = "tracker-timesheets" +} diff --git a/databases/timesheets-database/migrations/V1__initial_schema.sql b/databases/timesheets-database/migrations/V1__initial_schema.sql new file mode 100644 index 0000000..f57f955 --- /dev/null +++ b/databases/timesheets-database/migrations/V1__initial_schema.sql @@ -0,0 +1,11 @@ +create table time_entries ( + id bigint(20) not null auto_increment, + project_id bigint(20), + user_id bigint(20), + date datetime, + hours int, + + primary key (id) +) +engine = innodb +default charset = utf8; diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..2e2e36f --- /dev/null +++ b/gradle.properties @@ -0,0 +1,4 @@ +org.gradle.workers.max=8 +# Need this to keep Travis CI happy on builds +# or you get an out of memory error. +org.gradle.jvmargs=-Xmx3g diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000000000000000000000000000000000000..457aad0d98108420a977756b7145c93c8910b076 GIT binary patch literal 55741 zcmafab95)swq`n=q+{FmFHU~x*tTukPP${;?%1|%+qP{@&)oNB=H9vQ&04jq>W_Wa zIlI<5`};OZPVze#DhLQ9BnSuy|6c(C0sUWh5D=)pPibK#et@`)2>o{uxqnjRs=Jxt z{;Qz$SN;zFKZ?@)GU6h_ib{0SB6rf`V^Wd;x*0f00QKbfRGk9DJoEO!?Kogqd_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ovQ{>%58R{_TyD*JnWBNWk3<2-(G9~QzQHj#d^RV^?z2Y-+Qf5 z4+aJXfZzpuel|3~p`L@OxdD}}p}wK1wf&!U@5QOeC&nhPDaIwmsA`zz0sEw7#6iK1 zFPShA0jB{n^#R}C0wKKt^zKj40L%MN1L&>2YLbEqyi}r6LNu>WEMszo|n1Y-s>n{|7ige~oPo?d&7~1lpaAHX1~YpHAezX+mF{3%@k10Dz% z@V^>I=!aht2;1rcs(&g1L>fh`EDR;Atjrv&e?2szwVQzTSHMPCz(A1y>^R^^3ScY0 z7@FUq|0px|o9+D?_i-ETYbgL_74X6T3vL+oFL6cxYjwZIv;Mess}Ha)aJbia4m7{U zv$V6PSo}%$f z^goOg;KaNx1Nj>Ibz!}q(DB;;1pU`Cd#_PnmzDX6dSU_)>;BIi{l_9RuK|Ap09e_7 z+HZwqel~H_zjX7rT(#FHzb-5D^JLe*pZwp-9{<}Hd=3A)RLDJ|7-ZyTJ=BSC2ao*{*|lz8uqnB`%l<1yMKcHa}44&=4-*; zpO{xJ|AhH_F2n!2Grrcw{fWBn`Y%xbw^Huw?!Q*|{7K~R`EQASAD%z7K3@~O)>8aQ z;NwA?@io(HX|0b%0z2wMy$BzJ&! zkUzN@zumF_bhG+nivIq4e*f|(wUyT_uM<~)vRtSBYnI!b&TsL&uIVOcwW1m zf0}sz$7B3;+~p@t=HUNx>Hb#~=D&UZZ_MS-K@-61*Pq%s0PKH7U}VHW0PmW=r7hCG O(FVj@M23F*_WuFL)$*MH literal 0 HcmV?d00001 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..ae45383 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.3-all.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew new file mode 100755 index 0000000..af6708f --- /dev/null +++ b/gradlew @@ -0,0 +1,172 @@ +#!/usr/bin/env sh + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=$(save "$@") + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong +if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then + cd "$(dirname "$0")" +fi + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..0f8d593 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,84 @@ +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windows variants + +if not "%OS%" == "Windows_NT" goto win9xME_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/integration-test/build.gradle b/integration-test/build.gradle new file mode 100644 index 0000000..68212ac --- /dev/null +++ b/integration-test/build.gradle @@ -0,0 +1,10 @@ +dependencies { + testCompile project(":components:test-support") + testCompile "com.squareup.okhttp3:okhttp:$okhttpVersion" + testCompile "com.jayway.jsonpath:json-path:$jsonPathVersion" +} + +test.dependsOn ":applications:allocations-server:assemble" +test.dependsOn ":applications:backlog-server:assemble" +test.dependsOn ":applications:registration-server:assemble" +test.dependsOn ":applications:timesheets-server:assemble" diff --git a/integration-test/src/test/java/test/pivotal/pal/tracker/FlowTest.java b/integration-test/src/test/java/test/pivotal/pal/tracker/FlowTest.java new file mode 100644 index 0000000..f21899c --- /dev/null +++ b/integration-test/src/test/java/test/pivotal/pal/tracker/FlowTest.java @@ -0,0 +1,159 @@ +package test.pivotal.pal.tracker; + + +import com.jayway.jsonpath.JsonPath; +import com.jayway.jsonpath.PathNotFoundException; +import io.pivotal.pal.tracker.testsupport.TestScenarioSupport; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import test.pivotal.pal.tracker.support.ApplicationServer; +import test.pivotal.pal.tracker.support.HttpClient; +import test.pivotal.pal.tracker.support.Response; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Fail.fail; +import static test.pivotal.pal.tracker.support.MapBuilder.jsonMapBuilder; + +public class FlowTest { + + private final HttpClient httpClient = new HttpClient(); + private final String workingDir = System.getProperty("user.dir"); + + private ApplicationServer registrationServer = new ApplicationServer(workingDir + "/../applications/registration-server/build/libs/registration-server.jar", "8883"); + private ApplicationServer allocationsServer = new ApplicationServer(workingDir + "/../applications/allocations-server/build/libs/allocations-server.jar", "8881"); + private ApplicationServer backlogServer = new ApplicationServer(workingDir + "/../applications/backlog-server/build/libs/backlog-server.jar", "8882"); + private ApplicationServer timesheetsServer = new ApplicationServer(workingDir + "/../applications/timesheets-server/build/libs/timesheets-server.jar", "8884"); + + private String registrationServerUrl(String path) { + return "http://localhost:8883" + path; + } + + private String allocationsServerUrl(String path) { + return "http://localhost:8881" + path; + } + + private String backlogServerUrl(String path) { + return "http://localhost:8882" + path; + } + + private String timesheetsServerUrl(String path) { + return "http://localhost:8884" + path; + } + + private long findResponseId(Response response) { + try { + return JsonPath.parse(response.body).read("$.id", Long.class); + } catch (PathNotFoundException e) { + try { + return JsonPath.parse(response.body).read("$[0].id", Long.class); + } catch (PathNotFoundException e1) { + fail("Could not find id in response body. Response was: \n" + response); + return -1; + } + } + } + + + @Before + public void setup() throws Exception { + registrationServer.startWithDatabaseName("tracker_registration_test"); + allocationsServer.startWithDatabaseName("tracker_allocations_test"); + backlogServer.startWithDatabaseName("tracker_backlog_test"); + timesheetsServer.startWithDatabaseName("tracker_timesheets_test"); + ApplicationServer.waitOnPorts("8881", "8882", "8883", "8884"); + TestScenarioSupport.clearAllDatabases(); + } + + @After + public void tearDown() { + registrationServer.stop(); + allocationsServer.stop(); + backlogServer.stop(); + timesheetsServer.stop(); + } + + @Test + public void testBasicFlow() throws Exception { + Response response; + + response = httpClient.get(registrationServerUrl("/")); + assertThat(response.body).isEqualTo("Noop!"); + + response = httpClient.post(registrationServerUrl("/registration"), jsonMapBuilder() + .put("name", "aUser") + .build() + ); + long createdUserId = findResponseId(response); + assertThat(createdUserId).isGreaterThan(0); + + response = httpClient.get(registrationServerUrl("/users/" + createdUserId)); + assertThat(response.body).isNotNull().isNotEmpty(); + + response = httpClient.get(registrationServerUrl("/accounts?ownerId=" + createdUserId)); + long createdAccountId = findResponseId(response); + assertThat(createdAccountId).isGreaterThan(0); + + response = httpClient.post(registrationServerUrl("/projects"), jsonMapBuilder() + .put("accountId", createdAccountId) + .put("name", "aProject") + .build() + ); + long createdProjectId = findResponseId(response); + assertThat(createdProjectId).isGreaterThan(0); + + response = httpClient.get(registrationServerUrl("/projects?accountId=" + createdAccountId)); + assertThat(findResponseId(response)).isEqualTo(createdProjectId); + + + response = httpClient.get(allocationsServerUrl("/")); + assertThat(response.body).isEqualTo("Noop!"); + + response = httpClient.post( + allocationsServerUrl("/allocations"), jsonMapBuilder() + .put("projectId", createdProjectId) + .put("userId", createdUserId) + .put("firstDay", "2015-05-17") + .put("lastDay", "2015-05-26") + .build() + ); + + long createdAllocationId = findResponseId(response); + assertThat(createdAllocationId).isGreaterThan(0); + + response = httpClient.get(allocationsServerUrl("/allocations?projectId=" + createdProjectId)); + assertThat(findResponseId(response)).isEqualTo(createdAllocationId); + + + response = httpClient.get(backlogServerUrl("/")); + assertThat(response.body).isEqualTo("Noop!"); + + response = httpClient.post(backlogServerUrl("/stories"), jsonMapBuilder() + .put("projectId", createdProjectId) + .put("name", "A story") + .build() + ); + long createdStoryId = findResponseId(response); + assertThat(createdStoryId).isGreaterThan(0); + + response = httpClient.get(backlogServerUrl("/stories?projectId=" + createdProjectId)); + assertThat(findResponseId(response)).isEqualTo(createdStoryId); + + + response = httpClient.get(timesheetsServerUrl("/")); + assertThat(response.body).isEqualTo("Noop!"); + + response = httpClient.post(timesheetsServerUrl("/time-entries"), jsonMapBuilder() + .put("projectId", createdProjectId) + .put("userId", createdUserId) + .put("date", "2015-12-17") + .put("hours", 8) + .build() + ); + long createdTimeEntryId = findResponseId(response); + assertThat(createdTimeEntryId).isGreaterThan(0); + + response = httpClient.get(timesheetsServerUrl("/time-entries?userId=" + createdUserId)); + assertThat(findResponseId(response)).isEqualTo(createdTimeEntryId); + } +} diff --git a/integration-test/src/test/java/test/pivotal/pal/tracker/support/ApplicationServer.java b/integration-test/src/test/java/test/pivotal/pal/tracker/support/ApplicationServer.java new file mode 100644 index 0000000..023b1b8 --- /dev/null +++ b/integration-test/src/test/java/test/pivotal/pal/tracker/support/ApplicationServer.java @@ -0,0 +1,80 @@ +package test.pivotal.pal.tracker.support; + +import java.io.IOException; +import java.time.Instant; +import java.time.temporal.ChronoUnit; +import java.util.Map; + +import static org.assertj.core.api.Assertions.fail; +import static test.pivotal.pal.tracker.support.MapBuilder.envMapBuilder; + +public class ApplicationServer { + + private final String jarPath; + private final String port; + + private Process serverProcess; + + public ApplicationServer(String jarPath, String port) { + this.jarPath = jarPath; + this.port = port; + } + + + public void start(Map env) throws IOException, InterruptedException { + ProcessBuilder processBuilder = new ProcessBuilder() + .command("java", "-jar", jarPath) + .inheritIO(); + + processBuilder.environment().put("SERVER_PORT", port); + env.forEach((key, value) -> processBuilder.environment().put(key, value)); + + serverProcess = processBuilder.start(); + } + + public void startWithDatabaseName(String dbName) throws IOException, InterruptedException { + String dbUrl = "jdbc:mysql://localhost:3306/" + dbName + "?useSSL=false&useTimezone=true&serverTimezone=UTC&useLegacyDatetimeCode=false"; + + start(envMapBuilder() + .put("SPRING_DATASOURCE_URL", dbUrl) + .put("REGISTRATION_SERVER_ENDPOINT", "http://localhost:8883") + .build() + ); + } + + public void stop() { + serverProcess.destroyForcibly(); + } + + + public static void waitOnPorts(String... ports) throws InterruptedException { + for (String port : ports) waitUntilServerIsUp(port); + } + + private static void waitUntilServerIsUp(String port) throws InterruptedException { + HttpClient httpClient = new HttpClient(); + int timeout = 120; + Instant start = Instant.now(); + boolean isUp = false; + + System.out.print("Waiting on port " + port + "..."); + + while (!isUp) { + try { + httpClient.get("http://localhost:" + port); + isUp = true; + System.out.println(" server is up."); + } catch (Throwable e) { + + long timeSpent = ChronoUnit.SECONDS.between(start, Instant.now()); + if (timeSpent > timeout) { + fail("Timed out waiting for server on port " + port); + } + + System.out.print("."); + Thread.sleep(200); + } + } + } +} + diff --git a/integration-test/src/test/java/test/pivotal/pal/tracker/support/HttpClient.java b/integration-test/src/test/java/test/pivotal/pal/tracker/support/HttpClient.java new file mode 100644 index 0000000..228761d --- /dev/null +++ b/integration-test/src/test/java/test/pivotal/pal/tracker/support/HttpClient.java @@ -0,0 +1,67 @@ +package test.pivotal.pal.tracker.support; + +import com.fasterxml.jackson.databind.ObjectMapper; +import okhttp3.*; + +import java.io.IOException; +import java.util.Map; + +public class HttpClient { + + private static final MediaType JSON = MediaType.parse("application/json"); + + private final OkHttpClient okHttp = new OkHttpClient(); + private final ObjectMapper objectMapper = new ObjectMapper(); + + + public Response get(String url) { + return fetch(new Request.Builder().url(url)); + } + + public Response post(String url, Map jsonBody) { + try { + Request.Builder reqBuilder = new Request.Builder() + .url(url) + .post(RequestBody.create(JSON, objectMapper.writeValueAsString(jsonBody))); + + return fetch(reqBuilder); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + public Response put(String url, Map jsonBody) { + try { + Request.Builder reqBuilder = new Request.Builder() + .url(url) + .put(RequestBody.create(JSON, objectMapper.writeValueAsString(jsonBody))); + + return fetch(reqBuilder); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + public Response delete(String url) { + return fetch(new Request.Builder().delete().url(url)); + } + + + private Response fetch(Request.Builder requestBuilder) { + try { + Request request = requestBuilder.build(); + + okhttp3.Response response = okHttp.newCall(request).execute(); + ResponseBody body = response.body(); + + if (body == null) { + return new Response(response.code(), ""); + } + + return new Response(response.code(), body.string()); + } catch (IOException e) { + throw new RuntimeException(e); + } + } +} + diff --git a/integration-test/src/test/java/test/pivotal/pal/tracker/support/MapBuilder.java b/integration-test/src/test/java/test/pivotal/pal/tracker/support/MapBuilder.java new file mode 100644 index 0000000..a47466f --- /dev/null +++ b/integration-test/src/test/java/test/pivotal/pal/tracker/support/MapBuilder.java @@ -0,0 +1,26 @@ +package test.pivotal.pal.tracker.support; + +import java.util.HashMap; +import java.util.Map; + +public class MapBuilder { + + private Map map = new HashMap<>(); + + public static MapBuilder envMapBuilder() { + return new MapBuilder<>(); + } + + public static MapBuilder jsonMapBuilder() { + return new MapBuilder<>(); + } + + public MapBuilder put(K key, V value) { + map.put(key, value); + return this; + } + + public Map build() { + return map; + } +} diff --git a/integration-test/src/test/java/test/pivotal/pal/tracker/support/Response.java b/integration-test/src/test/java/test/pivotal/pal/tracker/support/Response.java new file mode 100644 index 0000000..101b76f --- /dev/null +++ b/integration-test/src/test/java/test/pivotal/pal/tracker/support/Response.java @@ -0,0 +1,19 @@ +package test.pivotal.pal.tracker.support; + +public class Response { + public final int status; + public final String body; + + public Response(int status, String body) { + this.status = status; + this.body = body; + } + + @Override + public String toString() { + return "Response{" + + "status=" + status + + ", body='" + body + '\'' + + '}'; + } +} diff --git a/manifest-allocations.yml b/manifest-allocations.yml new file mode 100644 index 0000000..0049f3a --- /dev/null +++ b/manifest-allocations.yml @@ -0,0 +1,12 @@ +applications: +- name: tracker-allocations + path: ./applications/allocations-server/build/libs/allocations-server.jar + routes: + - route: allocations-pal-{UNIQUE_IDENTIFIER}.apps.chicken.pal.pivotal.io + memory: 1G + instances: 1 + env: + REGISTRATION_SERVER_ENDPOINT: http://FILL_ME_IN + JBP_CONFIG_OPEN_JDK_JRE: '{ jre: { version: 11.+ } }' + services: + - tracker-allocations-database diff --git a/manifest-backlog.yml b/manifest-backlog.yml new file mode 100644 index 0000000..2747909 --- /dev/null +++ b/manifest-backlog.yml @@ -0,0 +1,12 @@ +applications: +- name: tracker-backlog + path: ./applications/backlog-server/build/libs/backlog-server.jar + routes: + - route: backlog-pal-{UNIQUE_IDENTIFIER}.apps.chicken.pal.pivotal.io + memory: 1G + instances: 1 + env: + REGISTRATION_SERVER_ENDPOINT: http://FILL_ME_IN + JBP_CONFIG_OPEN_JDK_JRE: '{ jre: { version: 11.+ } }' + services: + - tracker-backlog-database diff --git a/manifest-registration.yml b/manifest-registration.yml new file mode 100644 index 0000000..3eb3e1d --- /dev/null +++ b/manifest-registration.yml @@ -0,0 +1,11 @@ +applications: +- name: tracker-registration + path: ./applications/registration-server/build/libs/registration-server.jar + routes: + - route: registration-pal-{UNIQUE_IDENTIFIER}.apps.chicken.pal.pivotal.io + memory: 1G + instances: 1 + env: + JBP_CONFIG_OPEN_JDK_JRE: '{ jre: { version: 11.+ } }' + services: + - tracker-registration-database diff --git a/manifest-timesheets.yml b/manifest-timesheets.yml new file mode 100644 index 0000000..abc6cf9 --- /dev/null +++ b/manifest-timesheets.yml @@ -0,0 +1,12 @@ +applications: +- name: tracker-timesheets + path: ./applications/timesheets-server/build/libs/timesheets-server.jar + routes: + - route: timesheets-pal-{UNIQUE_IDENTIFIER}.apps.chicken.pal.pivotal.io + memory: 1G + instances: 1 + env: + REGISTRATION_SERVER_ENDPOINT: http://FILL_ME_IN + JBP_CONFIG_OPEN_JDK_JRE: '{ jre: { version: 11.+ } }' + services: + - tracker-timesheets-database diff --git a/requests.http b/requests.http new file mode 100644 index 0000000..1d1532a --- /dev/null +++ b/requests.http @@ -0,0 +1,49 @@ +### Create user +POST {{registrationUrl}}/registration +Content-Type: application/json + +{"name": "Sally"} + +### Get user +GET {{registrationUrl}}/users/USER-ID + +### Get account +GET {{registrationUrl}}/accounts?ownerId=USER-ID + +### Create project +POST {{registrationUrl}}/projects +Content-Type: application/json + +{"name": "Basket Weaving III", "accountId": ACCOUNT-ID} + +### Get projects +GET {{registrationUrl}}/projects?accountId=ACCOUNT-ID + +### Create allocation +POST {{allocationsUrl}}/allocations +Content-Type: application/json + +{"projectId": PROJECT-ID, "userId": USER-ID, "firstDay": "2015-05-17", "lastDay": "2015-05-18"} + +### Get allocations +GET {{allocationsUrl}}/allocations?projectId=PROJECT-ID + +### Create story +POST {{backlogUrl}}/stories +Content-Type: application/json + +{"projectId": PROJECT-ID, "name": "Find some reeds"} + +### Get stories +GET {{backlogUrl}}/stories?projectId=PROJECT-ID + +### Create timesheet +POST {{timesheetsUrl}}/time-entries/ +Content-Type: application/json + +{"projectId": PROJECT-ID, "userId": USER-ID, "date": "2015-05-17", "hours": 6} + +### Get timesheets +GET {{timesheetsUrl}}/time-entries?userId=USER-ID + +### diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 0000000..307ee44 --- /dev/null +++ b/settings.gradle @@ -0,0 +1,23 @@ +rootProject.name = "pal-tracker-distributed" + +include "applications:allocations-server" +include "applications:backlog-server" +include "applications:registration-server" +include "applications:timesheets-server" + +include "components:accounts" +include "components:allocations" +include "components:backlog" +include "components:projects" +include "components:timesheets" +include "components:users" + +include "components:rest-support" +include "components:test-support" + +include "databases:allocations-database" +include "databases:backlog-database" +include "databases:registration-database" +include "databases:timesheets-database" + +include "integration-test"