├── .editorconfig
├── .github
└── workflows
│ ├── cd-development.yml
│ └── ci.yml
├── .gitignore
├── CONTRIBUTING.md
├── LICENSE
├── README.md
├── build.gradle
├── etc
├── dependency-check
│ └── suppressions.xml
├── docker
│ └── docker-compose.yml
├── fixtures
│ ├── clean
│ │ ├── 01-groups.sql
│ │ ├── 02-users.sql
│ │ ├── 03-users_groups.sql
│ │ └── 04-voting.sql
│ ├── fixtures.yaml
│ └── load
│ │ ├── 01-groups.sql
│ │ ├── 02-users.sql
│ │ ├── 03-users_groups.sql
│ │ └── 04-voting.sql
├── license
│ └── gpl3.license
├── pmd
│ └── rulesets-general.xml
├── site
│ └── imgs
│ │ ├── five_50.png
│ │ ├── four_50.png
│ │ ├── one_50.png
│ │ ├── patio.png
│ │ ├── three_50.png
│ │ └── two_50.png
└── spotbugs
│ └── exclude.xml
├── gradle.properties
├── gradle
├── docker.gradle
├── docs.gradle
├── fixtures.gradle
├── quality.gradle
├── security.gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── micronaut-cli.yml
└── src
├── main
├── java
│ └── patio
│ │ ├── Application.java
│ │ ├── common
│ │ ├── domain
│ │ │ └── utils
│ │ │ │ ├── Builder.java
│ │ │ │ ├── Check.java
│ │ │ │ ├── Error.java
│ │ │ │ ├── NotNull.java
│ │ │ │ ├── NotPresent.java
│ │ │ │ ├── OffsetPaginationRequest.java
│ │ │ │ ├── OffsetPaginationResult.java
│ │ │ │ ├── PaginationRequest.java
│ │ │ │ ├── PaginationResult.java
│ │ │ │ └── Result.java
│ │ └── graphql
│ │ │ ├── ArgumentUtils.java
│ │ │ └── CommonScalarProvider.java
│ │ ├── group
│ │ ├── domain
│ │ │ ├── Group.java
│ │ │ ├── UserGroup.java
│ │ │ └── UserGroupKey.java
│ │ ├── graphql
│ │ │ ├── AddUserToGroupInput.java
│ │ │ ├── GetGroupInput.java
│ │ │ ├── GroupFetcher.java
│ │ │ ├── GroupFetcherUtils.java
│ │ │ ├── GroupProvider.java
│ │ │ ├── GroupTypeProvider.java
│ │ │ ├── LeaveGroupInput.java
│ │ │ ├── ListUsersGroupInput.java
│ │ │ ├── UpsertGroupInput.java
│ │ │ ├── UserGroupFetcher.java
│ │ │ └── UserGroupFetcherUtils.java
│ │ ├── repositories
│ │ │ ├── GroupRepository.java
│ │ │ ├── UserGroupRepository.java
│ │ │ └── internal
│ │ │ │ ├── MicroGroupRepository.java
│ │ │ │ └── MicroUserGroupRepository.java
│ │ └── services
│ │ │ ├── GroupService.java
│ │ │ ├── UserGroupService.java
│ │ │ └── internal
│ │ │ ├── DefaultGroupService.java
│ │ │ ├── DefaultUserGroupService.java
│ │ │ ├── UserCanSeeGroupMembers.java
│ │ │ ├── UserIsGroupAdmin.java
│ │ │ ├── UserIsInGroup.java
│ │ │ ├── UserIsNotInGroup.java
│ │ │ └── UserIsNotUniqueGroupAdmin.java
│ │ ├── infrastructure
│ │ ├── email
│ │ │ ├── domain
│ │ │ │ └── Email.java
│ │ │ └── services
│ │ │ │ ├── EmailComposer.java
│ │ │ │ ├── EmailService.java
│ │ │ │ └── internal
│ │ │ │ ├── AwsSesMailService.java
│ │ │ │ ├── DefaultAwsCredentialsProvider.java
│ │ │ │ ├── EmailComposerService.java
│ │ │ │ ├── MessagesFactory.java
│ │ │ │ └── templates
│ │ │ │ ├── JadeConfigurationFactory.java
│ │ │ │ ├── JadeTemplateService.java
│ │ │ │ ├── MailResourceBundleFactory.java
│ │ │ │ └── URLResolverService.java
│ │ ├── graphql
│ │ │ ├── Context.java
│ │ │ ├── ExecutionInputCustomizer.java
│ │ │ ├── GraphQLFactory.java
│ │ │ ├── GraphQLSchemaFactory.java
│ │ │ ├── I18nGraphQLError.java
│ │ │ ├── MutationProvider.java
│ │ │ ├── QueryProvider.java
│ │ │ ├── ResultUtils.java
│ │ │ ├── ScalarProvider.java
│ │ │ ├── TypeDefinitionRegistryFactory.java
│ │ │ ├── TypeProvider.java
│ │ │ ├── dataloader
│ │ │ │ └── DataLoaderRegistryFactory.java
│ │ │ ├── instrumentation
│ │ │ │ ├── AuthenticationCheck.java
│ │ │ │ └── AuthenticationCheckState.java
│ │ │ └── scalars
│ │ │ │ ├── ScalarsConstants.java
│ │ │ │ └── internal
│ │ │ │ ├── DayOfWeekCoercing.java
│ │ │ │ ├── ScalarsUtils.java
│ │ │ │ └── UUIDCoercing.java
│ │ ├── persistence
│ │ │ └── MicroBaseRepository.java
│ │ └── utils
│ │ │ ├── ErrorConstants.java
│ │ │ ├── FunctionsUtils.java
│ │ │ ├── IterableUtils.java
│ │ │ └── OptionalUtils.java
│ │ ├── security
│ │ ├── domain
│ │ │ ├── Login.java
│ │ │ └── Tokens.java
│ │ ├── graphql
│ │ │ ├── ChangePasswordInput.java
│ │ │ ├── LoginInput.java
│ │ │ ├── ResetPasswordFetcher.java
│ │ │ ├── SecurityFetcher.java
│ │ │ ├── SecurityFetcherUtils.java
│ │ │ └── SecurityProvider.java
│ │ └── services
│ │ │ ├── CryptoService.java
│ │ │ ├── GoogleUserService.java
│ │ │ ├── OauthService.java
│ │ │ ├── ResetPasswordService.java
│ │ │ ├── SecurityService.java
│ │ │ └── internal
│ │ │ ├── AlgorithmFactory.java
│ │ │ ├── Auth0CryptoService.java
│ │ │ ├── DefaultGoogleUserService.java
│ │ │ ├── DefaultResetPasswordService.java
│ │ │ ├── DefaultSecurityService.java
│ │ │ ├── OtpExpiredForUser.java
│ │ │ ├── PasswordIsBlank.java
│ │ │ ├── SamePassword.java
│ │ │ ├── ScribeOauth2ServiceProvider.java
│ │ │ ├── ScribeOauthService.java
│ │ │ └── SecurityConfiguration.java
│ │ ├── user
│ │ ├── domain
│ │ │ └── User.java
│ │ ├── graphql
│ │ │ ├── UserBatchLoader.java
│ │ │ ├── UserFetcher.java
│ │ │ └── UserProvider.java
│ │ ├── repositories
│ │ │ ├── UserRepository.java
│ │ │ └── internal
│ │ │ │ └── MicroUserRepository.java
│ │ └── services
│ │ │ ├── UserService.java
│ │ │ └── internal
│ │ │ ├── DefaultUserInitService.java
│ │ │ └── DefaultUserService.java
│ │ └── voting
│ │ ├── domain
│ │ ├── Vote.java
│ │ ├── VoteByMoodDTO.java
│ │ ├── Voting.java
│ │ └── VotingStats.java
│ │ ├── graphql
│ │ ├── CreateVoteInput.java
│ │ ├── CreateVotingInput.java
│ │ ├── DidIVoteInput.java
│ │ ├── GetLastVotingInput.java
│ │ ├── GetStatsByGroupInput.java
│ │ ├── GetVotingInput.java
│ │ ├── ListVotingsGroupInput.java
│ │ ├── UserVotesInGroupInput.java
│ │ ├── VotingFetcher.java
│ │ ├── VotingFetcherUtils.java
│ │ ├── VotingProvider.java
│ │ ├── VotingStatsFetcher.java
│ │ ├── VotingStatsFetcherUtils.java
│ │ └── VotingStatsInput.java
│ │ ├── repositories
│ │ ├── VoteRepository.java
│ │ ├── VotingRepository.java
│ │ ├── VotingStatsRepository.java
│ │ └── internal
│ │ │ ├── MicroVoteRepository.java
│ │ │ ├── MicroVotingRepository.java
│ │ │ └── MicroVotingStatsRepository.java
│ │ └── services
│ │ ├── VotingScheduling.java
│ │ ├── VotingService.java
│ │ ├── VotingStatsService.java
│ │ └── internal
│ │ ├── DefaultVotingService.java
│ │ ├── DefaultVotingStatsService.java
│ │ ├── UserOnlyVotedOnce.java
│ │ ├── VoteAnonymousAllowedInGroup.java
│ │ ├── VoteScoreBoundaries.java
│ │ ├── VotingHasExpired.java
│ │ └── VotingSchedulingService.java
└── resources
│ ├── application-prod.yml
│ ├── application.yml.template
│ ├── graphql
│ └── schema.graphqls
│ ├── logback.xml
│ ├── messages.properties
│ ├── messages_es.properties
│ ├── messages_fr.properties
│ ├── migrations
│ ├── V10__remove_visible_member_list.sql
│ ├── V11__add_expired_to_voting.sql
│ ├── V12__set_expired_to_existing_votings.sql
│ ├── V13__add_voting_duration_to_group.sql
│ ├── V14__set_voting_duration_to_existing_groups.sql
│ ├── V1__initial_schema.sql
│ ├── V2__users.sql
│ ├── V3__voting.sql
│ ├── V4__add_otp_creation_date_to_users.sql
│ ├── V5__voting_average_to_float.sql
│ ├── V6__add_hue_mood_to_vote.sql
│ ├── V7__create_table_voting_stats.sql
│ ├── V8__fix_created_at_data_from_voting_stats.sql
│ └── V9__calculates_moving_averages.sql
│ └── templates
│ ├── resetPassword.pug
│ └── voting.pug
└── test
├── java
└── patio
│ ├── ArchitectureLayersTests.java
│ ├── common
│ └── domain
│ │ └── utils
│ │ └── BuilderTests.java
│ ├── group
│ ├── repositories
│ │ └── GroupRepositoryTests.java
│ └── services
│ │ └── UserGroupServiceTests.java
│ ├── infrastructure
│ ├── email
│ │ └── services
│ │ │ ├── EmailComposerServiceTests.java
│ │ │ └── internal
│ │ │ └── templates
│ │ │ ├── JadeTemplateServiceTests.java
│ │ │ ├── MailResourceBundleFactoryTests.java
│ │ │ └── UrlResolverServiceTests.java
│ ├── graphql
│ │ ├── AuthenticationCheckTests.java
│ │ ├── ExecutionInputCustomizerTests.java
│ │ ├── GraphQLFactoryTest.java
│ │ ├── dataloader
│ │ │ └── DataLoaderRegistryFactoryTests.java
│ │ ├── fetchers
│ │ │ ├── GroupFetcherTests.java
│ │ │ ├── ResetPasswordFetcherTests.java
│ │ │ ├── SecurityFetcherTests.java
│ │ │ ├── UserFetcherTests.java
│ │ │ ├── UserGroupFetcherTests.java
│ │ │ ├── VotingFetcherTests.java
│ │ │ ├── VotingStatsFetcherTests.java
│ │ │ ├── archunit
│ │ │ │ └── FetchersTests.java
│ │ │ └── utils
│ │ │ │ └── FetcherTestUtils.java
│ │ └── scalars
│ │ │ ├── DayOfWeekTests.java
│ │ │ └── IDTests.java
│ └── tests
│ │ └── Fixtures.java
│ ├── security
│ └── services
│ │ ├── ResetPasswordServiceTests.java
│ │ └── internal
│ │ ├── AlgorithmFactoryTests.java
│ │ ├── Auth0CryptoServiceTests.java
│ │ └── DefaultSecurityServiceTests.java
│ ├── user
│ ├── domain
│ │ └── UserTests.java
│ ├── repositories
│ │ └── UserRepositoryTests.java
│ └── services
│ │ └── UserServiceTests.java
│ └── voting
│ ├── repositories
│ ├── VoteRepositoryTests.java
│ ├── VotingRepositoryTests.java
│ └── VotingStatsRepositoryTests.java
│ └── services
│ ├── VotingServiceTests.java
│ ├── VotingStatsServiceTests.java
│ └── internal
│ └── VotingSchedulingServiceTests.java
└── resources
├── application.yml
├── patio
├── group
│ └── repositories
│ │ ├── testFindAllByDayOfWeekAndVotingTimeLessEq.sql
│ │ ├── testFindAllByVotingCreatedAtBetween.sql
│ │ ├── testFindExpiredVotingsGroup.sql
│ │ └── testFindFavouriteGroup.sql
├── infrastructure
│ └── graphql
│ │ ├── anonymousallowed_schema.graphql
│ │ └── scalars
│ │ ├── dayofweek_schema.graphql
│ │ └── id_schema.graphql
├── user
│ └── repositories
│ │ ├── testFindByIdAndVotingUser.sql
│ │ ├── testListUsersByIds.sql
│ │ └── testListUsersByIdsSameOrderAsListUsers.sql
└── voting
│ └── repositories
│ ├── testFindAllVotesByMood.sql
│ ├── testFindByIdAndVotingUser.sql
│ ├── testFindMovingAverageByGroup.sql
│ ├── testGetAvgVoteCountByVoting.sql
│ ├── testGetMaxExpectedVoteCountByVoting.sql
│ ├── testGetVoteCountByVoting.sql
│ └── testListUsersByIdsSameOrderAsListUsers.sql
└── templates
└── example.pug
/.editorconfig:
--------------------------------------------------------------------------------
1 | [*]
2 | charset=utf-8
3 | end_of_line=lf
4 | insert_final_newline=false
5 | indent_style=space
6 | indent_size=4
7 |
8 | [*.json]
9 | indent_style=space
10 | indent_size=2
11 |
12 | [{*.yml,*.yaml}]
13 | indent_style=space
14 | indent_size=2
15 |
16 |
--------------------------------------------------------------------------------
/.github/workflows/ci.yml:
--------------------------------------------------------------------------------
1 | name: API Continuos Integration
2 |
3 | on: [push, pull_request]
4 |
5 | jobs:
6 | check:
7 | runs-on: ubuntu-latest
8 | container: "openjdk:11-slim"
9 | steps:
10 | - uses: actions/checkout@v2
11 | - uses: actions/cache@v1
12 | with:
13 | path: ~/.gradle/caches
14 | key: ${{ runner.os }}-patio-api-gradle-${{ hashFiles('**/*.gradle') }}
15 | restore-keys: |
16 | ${{ runner.os }}-patio-api-gradle-
17 | - uses: actions/cache@v1
18 | with:
19 | path: ~/.gradle/wrapper
20 | key: ${{ runner.os }}-patio-api-wrapper-${{ hashFiles('**/*.gradle') }}
21 | restore-keys: |
22 | ${{ runner.os }}-patio-api-wrapper-
23 | - name: Tests
24 | run: ./gradlew test
25 | - name: PMD (src/main)
26 | run: ./gradlew pmdMain
27 | - name: PMD (src/test)
28 | run: ./gradlew pmdTest
29 | - name: Files have the license header
30 | run: ./gradlew license
31 | - name: Formatter (Spotless)
32 | run: ./gradlew spotlessCheck
33 | - name: Spotbugs (Main)
34 | run: ./gradlew spotbugsMain
35 | - name: Spotbugs (Test)
36 | run: ./gradlew spotbugsTest
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | Thumbs.db
2 | .DS_Store
3 | .gradle
4 | build/
5 | target/
6 | out/
7 | .idea
8 | *.iml
9 | *.ipr
10 | *.iws
11 | .project
12 | .settings
13 | .classpath
14 | src/main/resources/application.yml
15 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing to patio
2 |
3 | We love your input! We want to make contributing to this project as easy and transparent as possible,
4 | whether it's:
5 |
6 | * Reporting a bug
7 | * Discussing the current state of the code
8 | * Submitting a fix
9 | * Proposing new features
10 | * Becoming a maintainer
11 |
12 | ## Issue reports
13 |
14 | Great issue Reports tend to have:
15 |
16 | * A quick summary and/or background
17 | * Steps to reproduce
18 | * Be specific!
19 | * Give sample code if you can.
20 | * What you expected would happen
21 | * What actually happens
22 | * Notes (possibly including why you think this might be happening, or stuff you tried that didn't work)
23 |
24 | We love thorough bug reports.
25 |
26 | ## Merge requests
27 |
28 | Before submitting anything, please make sure:
29 |
30 | * You're compiling the code with the proper JDK
31 | * All tests are passing
32 | * All code style checkers are passing
33 | * Static analysis passes
34 |
35 | Anything you need to run all those tasks can be found in the [README.md](README.md) document
36 |
37 | Then whether you are fixing a bug or improving some part of the code please open an issue
38 | following the issue reports guidelines.
39 |
40 | We'll try to answer you asap to start the conversation about your contribution. And hopefully,
41 | if everything seems ok, we'll be very happy to merge your code :)
42 |
43 | ## Licensing and attribution
44 |
45 | patio is licensed under [APACHE 2.0](https://www.apache.org/licenses/LICENSE-2.0).
46 | All source code falls under this license.
47 |
48 | The source code will not contain attribution information (e.g. Javadoc) for contributed code.
49 | Contributions will be recognised elsewhere in the project documentation.
--------------------------------------------------------------------------------
/etc/dependency-check/suppressions.xml:
--------------------------------------------------------------------------------
1 |
2 |
21 |
22 |
23 |
26 | f5f8b415bd87d0e3bdeaa48751ec79bbdcd2e414
27 | CVE-2018-1258
28 | cpe:/a:pivotal_software:spring_security
29 |
30 |
--------------------------------------------------------------------------------
/etc/docker/docker-compose.yml:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright (C) 2019 Kaleidos Open Source SL
3 | #
4 | # This file is part of PATIO.
5 | # PATIO is free software: you can redistribute it and/or modify
6 | # it under the terms of the GNU General Public License as published by
7 | # the Free Software Foundation, either version 3 of the License, or
8 | # (at your option) any later version.
9 | #
10 | # PATIO is distributed in the hope that it will be useful,
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | # GNU General Public License for more details.
14 | #
15 | # You should have received a copy of the GNU General Public License
16 | # along with PATIO. If not, see
17 | #
18 |
19 | version: '3'
20 | services:
21 | patio-db:
22 | image: postgres:10-alpine
23 | volumes:
24 | - db_data:/var/lib/postgresql/data
25 | ports:
26 | - 5433:5432
27 | environment:
28 | - POSTGRES_USER=patio
29 | - POSTGRES_PASSWORD=patio
30 | - POSTGRES_DB=patio
31 |
32 | volumes:
33 | db_data:
34 | driver: local
--------------------------------------------------------------------------------
/etc/fixtures/clean/01-groups.sql:
--------------------------------------------------------------------------------
1 | --
2 | -- Copyright (C) 2019 Kaleidos Open Source SL
3 | --
4 | -- This file is part of PATIO.
5 | -- PATIO is free software: you can redistribute it and/or modify
6 | -- it under the terms of the GNU General Public License as published by
7 | -- the Free Software Foundation, either version 3 of the License, or
8 | -- (at your option) any later version.
9 | --
10 | -- PATIO is distributed in the hope that it will be useful,
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | -- GNU General Public License for more details.
14 | --
15 | -- You should have received a copy of the GNU General Public License
16 | -- along with PATIO. If not, see
17 | --
18 |
19 | delete from groups;
--------------------------------------------------------------------------------
/etc/fixtures/clean/02-users.sql:
--------------------------------------------------------------------------------
1 | --
2 | -- Copyright (C) 2019 Kaleidos Open Source SL
3 | --
4 | -- This file is part of PATIO.
5 | -- PATIO is free software: you can redistribute it and/or modify
6 | -- it under the terms of the GNU General Public License as published by
7 | -- the Free Software Foundation, either version 3 of the License, or
8 | -- (at your option) any later version.
9 | --
10 | -- PATIO is distributed in the hope that it will be useful,
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | -- GNU General Public License for more details.
14 | --
15 | -- You should have received a copy of the GNU General Public License
16 | -- along with PATIO. If not, see
17 | --
18 |
19 | delete from users;
20 |
21 |
--------------------------------------------------------------------------------
/etc/fixtures/clean/03-users_groups.sql:
--------------------------------------------------------------------------------
1 | --
2 | -- Copyright (C) 2019 Kaleidos Open Source SL
3 | --
4 | -- This file is part of PATIO.
5 | -- PATIO is free software: you can redistribute it and/or modify
6 | -- it under the terms of the GNU General Public License as published by
7 | -- the Free Software Foundation, either version 3 of the License, or
8 | -- (at your option) any later version.
9 | --
10 | -- PATIO is distributed in the hope that it will be useful,
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | -- GNU General Public License for more details.
14 | --
15 | -- You should have received a copy of the GNU General Public License
16 | -- along with PATIO. If not, see
17 | --
18 |
19 | truncate users_groups;
20 |
21 |
--------------------------------------------------------------------------------
/etc/fixtures/clean/04-voting.sql:
--------------------------------------------------------------------------------
1 | --
2 | -- Copyright (C) 2019 Kaleidos Open Source SL
3 | --
4 | -- This file is part of PATIO.
5 | -- PATIO is free software: you can redistribute it and/or modify
6 | -- it under the terms of the GNU General Public License as published by
7 | -- the Free Software Foundation, either version 3 of the License, or
8 | -- (at your option) any later version.
9 | --
10 | -- PATIO is distributed in the hope that it will be useful,
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | -- GNU General Public License for more details.
14 | --
15 | -- You should have received a copy of the GNU General Public License
16 | -- along with PATIO. If not, see
17 | --
18 |
19 | TRUNCATE voting CASCADE;
--------------------------------------------------------------------------------
/etc/fixtures/fixtures.yaml:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright (C) 2019 Kaleidos Open Source SL
3 | #
4 | # This file is part of PATIO.
5 | # PATIO is free software: you can redistribute it and/or modify
6 | # it under the terms of the GNU General Public License as published by
7 | # the Free Software Foundation, either version 3 of the License, or
8 | # (at your option) any later version.
9 | #
10 | # PATIO is distributed in the hope that it will be useful,
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | # GNU General Public License for more details.
14 | #
15 | # You should have received a copy of the GNU General Public License
16 | # along with PATIO. If not, see
17 | #
18 |
19 | dataSource:
20 | url: jdbc:postgresql://localhost:5433/patio
21 | user: patio
22 | password: patio
23 | driverClassName: org.postgresql.Driver
--------------------------------------------------------------------------------
/etc/fixtures/load/01-groups.sql:
--------------------------------------------------------------------------------
1 | --
2 | -- Copyright (C) 2019 Kaleidos Open Source SL
3 | --
4 | -- This file is part of PATIO.
5 | -- PATIO is free software: you can redistribute it and/or modify
6 | -- it under the terms of the GNU General Public License as published by
7 | -- the Free Software Foundation, either version 3 of the License, or
8 | -- (at your option) any later version.
9 | --
10 | -- PATIO is distributed in the hope that it will be useful,
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | -- GNU General Public License for more details.
14 | --
15 | -- You should have received a copy of the GNU General Public License
16 | -- along with PATIO. If not, see
17 | --
18 |
19 | INSERT INTO groups (id, name, anonymous_vote, voting_time, voting_days, voting_duration) VALUES ('d64db962-3455-11e9-b210-d663bd873d93','Fantastic Four', true, time with time zone '14:48:12.146512+01:00', '{"MONDAY"}', 24);
20 | INSERT INTO groups (id, name, anonymous_vote, voting_time, voting_days, voting_duration) VALUES ('dedc6675-ab79-495e-9245-1fc20545eb83', 'Avengers', true, time with time zone '14:48:12.146512+01:00', '{"MONDAY", "TUESDAY"}', 24);
21 | INSERT INTO groups (id, name, anonymous_vote, voting_time, voting_days, voting_duration) VALUES ('d5847624-4b50-4d4a-abd3-ed9209a5448b', 'Illuminati', false, time with time zone '12:00:00.146512+01:00', '{"MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY"}', 24);
22 |
--------------------------------------------------------------------------------
/etc/license/gpl3.license:
--------------------------------------------------------------------------------
1 | Copyright (C) 2019 Kaleidos Open Source SL
2 |
3 | This file is part of PATIO.
4 | PATIO is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | PATIO is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with PATIO. If not, see
--------------------------------------------------------------------------------
/etc/site/imgs/five_50.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/patio-team/patio-api/0967e4bd78aedb7f628733982676df225c9cc208/etc/site/imgs/five_50.png
--------------------------------------------------------------------------------
/etc/site/imgs/four_50.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/patio-team/patio-api/0967e4bd78aedb7f628733982676df225c9cc208/etc/site/imgs/four_50.png
--------------------------------------------------------------------------------
/etc/site/imgs/one_50.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/patio-team/patio-api/0967e4bd78aedb7f628733982676df225c9cc208/etc/site/imgs/one_50.png
--------------------------------------------------------------------------------
/etc/site/imgs/patio.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/patio-team/patio-api/0967e4bd78aedb7f628733982676df225c9cc208/etc/site/imgs/patio.png
--------------------------------------------------------------------------------
/etc/site/imgs/three_50.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/patio-team/patio-api/0967e4bd78aedb7f628733982676df225c9cc208/etc/site/imgs/three_50.png
--------------------------------------------------------------------------------
/etc/site/imgs/two_50.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/patio-team/patio-api/0967e4bd78aedb7f628733982676df225c9cc208/etc/site/imgs/two_50.png
--------------------------------------------------------------------------------
/etc/spotbugs/exclude.xml:
--------------------------------------------------------------------------------
1 |
2 |
21 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | version = 0.1.0
--------------------------------------------------------------------------------
/gradle/docker.gradle:
--------------------------------------------------------------------------------
1 | docker {
2 | registryCredentials {
3 | username = project.properties.registryUser
4 | password = project.properties.registryKey
5 | }
6 |
7 | javaApplication {
8 | baseImage = 'openjdk:11-slim'
9 | // tag = "kaleidosteam/patio-api:$version"
10 | tag = "kaleidosteam/patio-api:latest"
11 | }
12 | }
--------------------------------------------------------------------------------
/gradle/docs.gradle:
--------------------------------------------------------------------------------
1 | /**
2 | * Javadoc configuration
3 | *
4 | * @since 0.1.0
5 | */
6 | javadoc {
7 | failOnError = true
8 | }
9 |
10 | /**
11 | * Makes javadoc to fail if there're warnings too
12 | *
13 | * @since 0.1.0
14 | */
15 | tasks.withType(Javadoc) {
16 | options.addStringOption('Xwerror', '-quiet')
17 | }
--------------------------------------------------------------------------------
/gradle/fixtures.gradle:
--------------------------------------------------------------------------------
1 | /**
2 | * Configures configuration paths for fixture
3 | * loading/removal and database configuration
4 | *
5 | * @since 0.1.0
6 | */
7 | fixtures {
8 | loadDir 'etc/fixtures/load'
9 | cleanDir 'etc/fixtures/clean'
10 | configFile 'etc/fixtures/fixtures.yaml'
11 | }
--------------------------------------------------------------------------------
/gradle/security.gradle:
--------------------------------------------------------------------------------
1 | dependencyCheck {
2 | failOnError = false
3 | analyzedTypes = ['jar']
4 | skipConfigurations = ['dockerJava', 'spotbugs']
5 | suppressionFile = 'etc/dependency-check/suppressions.xml'
6 | }
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/patio-team/patio-api/0967e4bd78aedb7f628733982676df225c9cc208/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Tue Feb 19 15:44:30 CET 2019
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.0-all.zip
7 |
--------------------------------------------------------------------------------
/micronaut-cli.yml:
--------------------------------------------------------------------------------
1 | profile: service
2 | defaultPackage: patio
3 | ---
4 | testFramework: junit
5 | sourceLanguage: java
--------------------------------------------------------------------------------
/src/main/java/patio/Application.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Kaleidos Open Source SL
3 | *
4 | * This file is part of PATIO.
5 | * PATIO is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * PATIO is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with PATIO. If not, see
17 | */
18 | package patio;
19 |
20 | import io.micronaut.runtime.Micronaut;
21 |
22 | /**
23 | * Application's entry point
24 | *
25 | * @since 0.1.0
26 | */
27 | @SuppressWarnings("PMD.UseUtilityClass")
28 | public class Application {
29 |
30 | /**
31 | * Executes the application
32 | *
33 | * @param args possible command line arguments
34 | * @since 0.1.0
35 | */
36 | public static void main(String[] args) {
37 | Micronaut.run(Application.class);
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/main/java/patio/common/domain/utils/Error.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Kaleidos Open Source SL
3 | *
4 | * This file is part of PATIO.
5 | * PATIO is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * PATIO is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with PATIO. If not, see
17 | */
18 | package patio.common.domain.utils;
19 |
20 | /**
21 | * Represents a business logic error. It should be used and passed as a value.
22 | *
23 | * @since 0.1.0
24 | */
25 | public class Error {
26 | private final String code;
27 | private final String message;
28 |
29 | /**
30 | * Initializes the error with a code and a developer friendly message
31 | *
32 | * @param code i18n code
33 | * @param message developer friendly message
34 | * @since 0.1.0
35 | */
36 | public Error(String code, String message) {
37 | this.code = code;
38 | this.message = message;
39 | }
40 |
41 | /**
42 | * Returns error code
43 | *
44 | * @return a code that can be used as i18n code
45 | * @since 0.1.0
46 | */
47 | public String getCode() {
48 | return code;
49 | }
50 |
51 | /**
52 | * Returns error message
53 | *
54 | * @return the error developer friendly message
55 | * @since 0.1.0
56 | */
57 | public String getMessage() {
58 | return message;
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/src/main/java/patio/common/domain/utils/NotNull.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Kaleidos Open Source SL
3 | *
4 | * This file is part of PATIO.
5 | * PATIO is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * PATIO is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with PATIO. If not, see
17 | */
18 | package patio.common.domain.utils;
19 |
20 | import static patio.common.domain.utils.Check.checkIsTrue;
21 |
22 | import patio.infrastructure.utils.ErrorConstants;
23 |
24 | /**
25 | * This checker expects the argument passed to be not null, otherwise it will return a failing
26 | * {@link Result}
27 | *
28 | * @since 0.1.0
29 | */
30 | public class NotNull {
31 |
32 | /**
33 | * Checks that the argument passed as parameter is not null. Otherwise will build a failing {@link
34 | * Result} containing an error {@link ErrorConstants#NOT_FOUND}
35 | *
36 | * @param object the object checked
37 | * @return a failing {@link Result} if the object is null
38 | * @since 0.1.0
39 | */
40 | public Check check(Object object) {
41 | return checkIsTrue(object != null, ErrorConstants.NOT_FOUND);
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/main/java/patio/common/domain/utils/NotPresent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Kaleidos Open Source SL
3 | *
4 | * This file is part of PATIO.
5 | * PATIO is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * PATIO is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with PATIO. If not, see
17 | */
18 | package patio.common.domain.utils;
19 |
20 | import static patio.common.domain.utils.Check.checkIsTrue;
21 |
22 | import java.util.Optional;
23 | import patio.infrastructure.utils.ErrorConstants;
24 |
25 | /**
26 | * This checker expects the argument passed to be present, otherwise it will return a failing {@link
27 | * Check}
28 | *
29 | * @since 0.1.0
30 | */
31 | public class NotPresent {
32 | /**
33 | * Checks that the argument passed as parameter is not null. Otherwise will build a failing {@link
34 | * Check} containing an error {@link ErrorConstants#NOT_FOUND}
35 | *
36 | * @param object the object checked
37 | * @return a failing {@link Check} if the object is not present
38 | * @since 0.1.0
39 | */
40 | public Check check(Optional object) {
41 | return check(object, ErrorConstants.NOT_FOUND);
42 | }
43 |
44 | /**
45 | * Checks that the argument passed as parameter is not null. Otherwise will build a failing {@link
46 | * Check} containing an error
47 | *
48 | * @param object the object to check
49 | * @param error error to show when check didn't pass
50 | * @return a failing {@link Check} if the object is not present
51 | * @since 0.1.0
52 | */
53 | public Check check(Optional object, Error error) {
54 | return checkIsTrue(object.isPresent(), error);
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/src/main/java/patio/common/domain/utils/OffsetPaginationRequest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Kaleidos Open Source SL
3 | *
4 | * This file is part of PATIO.
5 | * PATIO is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * PATIO is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with PATIO. If not, see
17 | */
18 | package patio.common.domain.utils;
19 |
20 | /**
21 | * Provides information on how to paginate using offset pagination
22 | *
23 | * @see OffsetPaginationResult
24 | */
25 | public class OffsetPaginationRequest {
26 |
27 | private final int offset;
28 | private final int max;
29 |
30 | /**
31 | * Inits a new {@link OffsetPaginationRequest} with offset and max
32 | *
33 | * @param offset the offset number
34 | * @param max the maximum number of results
35 | */
36 | public OffsetPaginationRequest(int offset, int max) {
37 | this.offset = offset;
38 | this.max = max;
39 | }
40 |
41 | /**
42 | * Returns the pagination offset
43 | *
44 | * @return the pagination offset
45 | */
46 | public int getOffset() {
47 | return offset;
48 | }
49 |
50 | /**
51 | * Returns the maximum number of results
52 | *
53 | * @return the maximum number of results
54 | */
55 | public int getMax() {
56 | return max;
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/src/main/java/patio/common/domain/utils/OffsetPaginationResult.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Kaleidos Open Source SL
3 | *
4 | * This file is part of PATIO.
5 | * PATIO is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * PATIO is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with PATIO. If not, see
17 | */
18 | package patio.common.domain.utils;
19 |
20 | import java.util.List;
21 |
22 | /**
23 | * Represents the result of an offset pagination
24 | *
25 | * @param the wrapped type to be paginated over
26 | * @see OffsetPaginationRequest
27 | */
28 | public class OffsetPaginationResult {
29 |
30 | private final int totalCount;
31 | private final int offset;
32 | private final List data;
33 |
34 | /**
35 | * Inits an {@link OffsetPaginationResult} with the potential total number of results from
36 | * database, the current offset, and the partial results
37 | *
38 | * @param totalCount total number of records in database
39 | * @param offset the current offset
40 | * @param data partial results
41 | */
42 | public OffsetPaginationResult(int totalCount, int offset, List data) {
43 | this.totalCount = totalCount;
44 | this.offset = offset;
45 | this.data = data;
46 | }
47 |
48 | /**
49 | * Creates an empty result
50 | *
51 | * @param the wrapped type to be paginated over
52 | * @return an empty result
53 | */
54 | public static OffsetPaginationResult empty() {
55 | return new OffsetPaginationResult(0, 0, List.of());
56 | }
57 |
58 | /**
59 | * Returns total number of records in database
60 | *
61 | * @return total number of records in database
62 | */
63 | public int getTotalCount() {
64 | return totalCount;
65 | }
66 |
67 | /**
68 | * Returns current offset
69 | *
70 | * @return current offset
71 | */
72 | public int getOffset() {
73 | return offset;
74 | }
75 |
76 | /**
77 | * Returns partial results
78 | *
79 | * @return partial results
80 | */
81 | public List getData() {
82 | return data;
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/src/main/java/patio/common/domain/utils/PaginationRequest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Kaleidos Open Source SL
3 | *
4 | * This file is part of PATIO.
5 | * PATIO is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * PATIO is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with PATIO. If not, see
17 | */
18 | package patio.common.domain.utils;
19 |
20 | /**
21 | * Holds the information on how to paginate a result
22 | *
23 | * @see PaginationResult
24 | */
25 | public final class PaginationRequest {
26 |
27 | private final int max;
28 | private final int page;
29 |
30 | private PaginationRequest(int max, int page) {
31 | this.max = max;
32 | this.page = page;
33 | }
34 |
35 | /**
36 | * Creates a new instance of {@link PaginationRequest} from an max limit and the page where the
37 | * pagination begins
38 | *
39 | * @param max the maximum number of elements to show
40 | * @param page where to begin to count the elements to show
41 | * @return an instance of {@link PaginationRequest}
42 | */
43 | public static PaginationRequest from(int max, int page) {
44 | return new PaginationRequest(max, page);
45 | }
46 |
47 | /**
48 | * Returns the maximum number of elements to show
49 | *
50 | * @return the maximum number of elements to show
51 | */
52 | public int getMax() {
53 | return max;
54 | }
55 |
56 | /**
57 | * Returns where to start counting the elements to show
58 | *
59 | * @return where to start counting the elements to show
60 | */
61 | public int getPage() {
62 | return page;
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/src/main/java/patio/common/graphql/ArgumentUtils.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Kaleidos Open Source SL
3 | *
4 | * This file is part of PATIO.
5 | * PATIO is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * PATIO is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with PATIO. If not, see
17 | */
18 | package patio.common.graphql;
19 |
20 | import graphql.schema.DataFetchingEnvironment;
21 | import patio.common.domain.utils.OffsetPaginationRequest;
22 | import patio.common.domain.utils.PaginationRequest;
23 |
24 | /**
25 | * Utils to extract arguments from {@link DataFetchingEnvironment} objects
26 | *
27 | * @see DataFetchingEnvironment
28 | */
29 | public final class ArgumentUtils {
30 |
31 | private ArgumentUtils() {
32 | /* empty */
33 | }
34 |
35 | /**
36 | * Extracts a {@link PaginationRequest} from the current GraphQL request. It looks for an offset
37 | * and a max arguments
38 | *
39 | * @param env GraphQL {@link DataFetchingEnvironment} object to extract arguments from
40 | * @return an instance of type {@link PaginationRequest}
41 | */
42 | @SuppressWarnings("PMD.ConfusingTernary")
43 | public static PaginationRequest extractPaginationFrom(DataFetchingEnvironment env) {
44 | Integer page = env.getArgument("page");
45 | Integer max = env.getArgument("max");
46 |
47 | return PaginationRequest.from(max != null ? max : 20, page != null ? page : 0);
48 | }
49 |
50 | /**
51 | * Extracts an {@link OffsetPaginationRequest}
52 | *
53 | * @param env GraphQL {@link DataFetchingEnvironment} object to extract arguments from
54 | * @return an instance of type {@link OffsetPaginationRequest}
55 | */
56 | public static OffsetPaginationRequest extractOffsetPaginationFrom(DataFetchingEnvironment env) {
57 | Integer offset = env.getArgument("offset");
58 | Integer max = env.getArgument("max");
59 |
60 | return new OffsetPaginationRequest(offset, max);
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/src/main/java/patio/common/graphql/CommonScalarProvider.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Kaleidos Open Source SL
3 | *
4 | * This file is part of PATIO.
5 | * PATIO is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * PATIO is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with PATIO. If not, see
17 | */
18 | package patio.common.graphql;
19 |
20 | import graphql.schema.idl.RuntimeWiring;
21 | import java.util.function.UnaryOperator;
22 | import javax.inject.Singleton;
23 | import patio.infrastructure.graphql.ScalarProvider;
24 | import patio.infrastructure.graphql.scalars.ScalarsConstants;
25 |
26 | /**
27 | * Contains the implementation of custom scalars used in the schema
28 | *
29 | * @see ScalarsConstants
30 | */
31 | @Singleton
32 | public class CommonScalarProvider implements ScalarProvider {
33 | @Override
34 | public UnaryOperator getScalars() {
35 | return (builder) ->
36 | builder
37 | .scalar(ScalarsConstants.ID)
38 | .scalar(ScalarsConstants.DATE)
39 | .scalar(ScalarsConstants.TIME)
40 | .scalar(ScalarsConstants.DATE_TIME)
41 | .scalar(ScalarsConstants.DAY_OF_WEEK);
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/main/java/patio/group/domain/UserGroupKey.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Kaleidos Open Source SL
3 | *
4 | * This file is part of PATIO.
5 | * PATIO is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * PATIO is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with PATIO. If not, see
17 | */
18 | package patio.group.domain;
19 |
20 | import java.io.Serializable;
21 | import java.util.UUID;
22 | import javax.persistence.Column;
23 | import javax.persistence.Embeddable;
24 |
25 | /** Represents the id of a {@link UserGroup} instance */
26 | @Embeddable
27 | public class UserGroupKey implements Serializable {
28 |
29 | private static final long serialVersionUID = 0;
30 |
31 | @Column(name = "user_id")
32 | private UUID userId;
33 |
34 | @Column(name = "group_id")
35 | private UUID groupId;
36 |
37 | /** Default constructor */
38 | public UserGroupKey() {
39 | /* empty */
40 | }
41 |
42 | /**
43 | * Initializes a {@link UserGroupKey} with the user's id and the group's id
44 | *
45 | * @param userId user's id
46 | * @param groupId group's id
47 | */
48 | public UserGroupKey(UUID userId, UUID groupId) {
49 | this.userId = userId;
50 | this.groupId = groupId;
51 | }
52 |
53 | /**
54 | * Returns id of the user
55 | *
56 | * @return id of the user
57 | */
58 | public UUID getUserId() {
59 | return userId;
60 | }
61 |
62 | /**
63 | * Sets the user's id
64 | *
65 | * @param userId the user's id
66 | */
67 | public void setUserId(UUID userId) {
68 | this.userId = userId;
69 | }
70 |
71 | /**
72 | * Returns the group's id
73 | *
74 | * @return the group's id
75 | */
76 | public UUID getGroupId() {
77 | return groupId;
78 | }
79 |
80 | /**
81 | * Sets the group's id
82 | *
83 | * @param groupId the group's id
84 | */
85 | public void setGroupId(UUID groupId) {
86 | this.groupId = groupId;
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/src/main/java/patio/group/graphql/AddUserToGroupInput.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Kaleidos Open Source SL
3 | *
4 | * This file is part of PATIO.
5 | * PATIO is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * PATIO is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with PATIO. If not, see
17 | */
18 | package patio.group.graphql;
19 |
20 | import java.util.UUID;
21 |
22 | /**
23 | * AddUserToGroupInput input. It contains the ids for a user and a group
24 | *
25 | * @since 0.1.0
26 | */
27 | public class AddUserToGroupInput {
28 | private final String email;
29 | private final UUID groupId;
30 | private final UUID currentUserId;
31 |
32 | /**
33 | * Returns the email of the user
34 | *
35 | * @return the email of the user
36 | * @since 0.1.0
37 | */
38 | public String getEmail() {
39 | return email;
40 | }
41 |
42 | /**
43 | * Returns the id of the group
44 | *
45 | * @return the id of the group
46 | * @since 0.1.0
47 | */
48 | public UUID getGroupId() {
49 | return groupId;
50 | }
51 |
52 | /**
53 | * Returns the id of the current user
54 | *
55 | * @return the id of the current user
56 | * @since 0.1.0
57 | */
58 | public UUID getCurrentUserId() {
59 | return currentUserId;
60 | }
61 |
62 | /**
63 | * Initializes the input with the user email and the group id
64 | *
65 | * @param currentUserId the id of the current user
66 | * @param email the email of the user
67 | * @param groupId the id of the group
68 | * @since 0.1.0
69 | */
70 | public AddUserToGroupInput(UUID currentUserId, String email, UUID groupId) {
71 | this.currentUserId = currentUserId;
72 | this.email = email;
73 | this.groupId = groupId;
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/src/main/java/patio/group/graphql/GroupTypeProvider.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Kaleidos Open Source SL
3 | *
4 | * This file is part of PATIO.
5 | * PATIO is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * PATIO is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with PATIO. If not, see
17 | */
18 | package patio.group.graphql;
19 |
20 | import graphql.schema.idl.RuntimeWiring;
21 | import java.util.function.UnaryOperator;
22 | import javax.inject.Singleton;
23 | import patio.infrastructure.graphql.TypeProvider;
24 | import patio.voting.graphql.VotingFetcher;
25 |
26 | /**
27 | * Contains all mapped fetchers for for group related types
28 | *
29 | * @see TypeProvider
30 | */
31 | @Singleton
32 | public class GroupTypeProvider implements TypeProvider {
33 |
34 | private final transient UserGroupFetcher userGroupFetcher;
35 | private final transient VotingFetcher votingFetcher;
36 |
37 | /**
38 | * Initializes provider with its dependencies
39 | *
40 | * @param userGroupFetcher user/group related data fetchers
41 | * @param votingFetcher voting related fetchers
42 | */
43 | public GroupTypeProvider(UserGroupFetcher userGroupFetcher, VotingFetcher votingFetcher) {
44 | this.userGroupFetcher = userGroupFetcher;
45 | this.votingFetcher = votingFetcher;
46 | }
47 |
48 | @Override
49 | public UnaryOperator getTypes() {
50 | return (runtime) ->
51 | runtime.type(
52 | "Group",
53 | builder ->
54 | builder
55 | .dataFetcher("members", userGroupFetcher::listUsersGroup)
56 | .dataFetcher("isCurrentUserAdmin", userGroupFetcher::isCurrentUserAdmin)
57 | .dataFetcher("votings", votingFetcher::listVotingsGroup));
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/src/main/java/patio/group/graphql/ListUsersGroupInput.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Kaleidos Open Source SL
3 | *
4 | * This file is part of PATIO.
5 | * PATIO is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * PATIO is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with PATIO. If not, see
17 | */
18 | package patio.group.graphql;
19 |
20 | import java.util.UUID;
21 |
22 | /**
23 | * ListUsersGroupInput input. It contains the ids for a user and a group, and a boolean indicating
24 | * if the group has a visible member list
25 | *
26 | * @since 0.1.0
27 | */
28 | public class ListUsersGroupInput {
29 | private final UUID userId;
30 | private final UUID groupId;
31 |
32 | /**
33 | * Returns the id of the user
34 | *
35 | * @return the id of the user
36 | * @since 0.1.0
37 | */
38 | public UUID getUserId() {
39 | return userId;
40 | }
41 |
42 | /**
43 | * Returns the id of the group
44 | *
45 | * @return the id of the group
46 | * @since 0.1.0
47 | */
48 | public UUID getGroupId() {
49 | return groupId;
50 | }
51 |
52 | /**
53 | * Initializes the input with the user id, the group id, and visibleMemberList
54 | *
55 | * @param userId the id of the user
56 | * @param groupId the id of the group
57 | * @since 0.1.0
58 | */
59 | public ListUsersGroupInput(UUID userId, UUID groupId) {
60 | this.userId = userId;
61 | this.groupId = groupId;
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/src/main/java/patio/group/repositories/UserGroupRepository.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Kaleidos Open Source SL
3 | *
4 | * This file is part of PATIO.
5 | * PATIO is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * PATIO is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with PATIO. If not, see
17 | */
18 | package patio.group.repositories;
19 |
20 | import io.micronaut.data.repository.PageableRepository;
21 | import patio.group.domain.UserGroup;
22 | import patio.group.domain.UserGroupKey;
23 |
24 | /** All database actions related to {@link UserGroup} entity */
25 | public interface UserGroupRepository extends PageableRepository {}
26 |
--------------------------------------------------------------------------------
/src/main/java/patio/group/repositories/internal/MicroGroupRepository.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Kaleidos Open Source SL
3 | *
4 | * This file is part of PATIO.
5 | * PATIO is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * PATIO is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with PATIO. If not, see
17 | */
18 | package patio.group.repositories.internal;
19 |
20 | import io.micronaut.data.annotation.Repository;
21 | import javax.persistence.EntityManager;
22 | import patio.group.domain.Group;
23 | import patio.group.repositories.GroupRepository;
24 | import patio.infrastructure.persistence.MicroBaseRepository;
25 |
26 | /** Persistence implementation access for {@link Group} */
27 | @Repository
28 | public abstract class MicroGroupRepository extends MicroBaseRepository implements GroupRepository {
29 |
30 | /**
31 | * Initializes repository with {@link EntityManager}
32 | *
33 | * @param entityManager persistence {@link EntityManager} instance
34 | */
35 | public MicroGroupRepository(EntityManager entityManager) {
36 | super(entityManager);
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/main/java/patio/group/repositories/internal/MicroUserGroupRepository.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Kaleidos Open Source SL
3 | *
4 | * This file is part of PATIO.
5 | * PATIO is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * PATIO is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with PATIO. If not, see
17 | */
18 | package patio.group.repositories.internal;
19 |
20 | import io.micronaut.data.annotation.Repository;
21 | import javax.persistence.EntityManager;
22 | import patio.group.domain.UserGroup;
23 | import patio.group.repositories.UserGroupRepository;
24 | import patio.infrastructure.persistence.MicroBaseRepository;
25 |
26 | /** Persistence implementation access for {@link UserGroup} */
27 | @Repository
28 | public abstract class MicroUserGroupRepository extends MicroBaseRepository
29 | implements UserGroupRepository {
30 |
31 | /**
32 | * Initializes repository with {@link EntityManager}
33 | *
34 | * @param entityManager persistence {@link EntityManager} instance
35 | */
36 | public MicroUserGroupRepository(EntityManager entityManager) {
37 | super(entityManager);
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/main/java/patio/group/services/UserGroupService.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Kaleidos Open Source SL
3 | *
4 | * This file is part of PATIO.
5 | * PATIO is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * PATIO is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with PATIO. If not, see
17 | */
18 | package patio.group.services;
19 |
20 | import java.util.UUID;
21 | import patio.common.domain.utils.Result;
22 | import patio.group.domain.Group;
23 | import patio.group.graphql.AddUserToGroupInput;
24 | import patio.group.graphql.LeaveGroupInput;
25 | import patio.group.graphql.ListUsersGroupInput;
26 | import patio.user.domain.User;
27 |
28 | /**
29 | * Business logic contracts regarding user groups
30 | *
31 | * @since 0.1.0
32 | */
33 | public interface UserGroupService {
34 |
35 | /**
36 | * Adds an user to a group, if the current user is admin of the group
37 | *
38 | * @param input user and group information
39 | * @return an instance of {@link Result} (Boolean | {@link Error})
40 | * @since 0.1.0
41 | */
42 | Result addUserToGroup(AddUserToGroupInput input);
43 |
44 | /**
45 | * Fetches the list of users in a Group. ifMatches the user is not allowed to build them, returns
46 | * an empty list
47 | *
48 | * @param input a {@link AddUserToGroupInput} with the user and the group
49 | * @return a list of {@link User} instances
50 | * @since 0.1.0
51 | */
52 | Iterable listUsersGroup(ListUsersGroupInput input);
53 |
54 | /**
55 | * Make the current user leave the specified group
56 | *
57 | * @param input required data to retrieve a {@link Group}
58 | * @return The requested {@link Group}
59 | * @since 0.1.0
60 | */
61 | Result leaveGroup(LeaveGroupInput input);
62 |
63 | /**
64 | * Checks whether the user is admin is a given group or not
65 | *
66 | * @param userId user's id
67 | * @param groupId group's id
68 | * @return true if the user is admin in the given group
69 | */
70 | boolean isAdmin(UUID userId, UUID groupId);
71 | }
72 |
--------------------------------------------------------------------------------
/src/main/java/patio/group/services/internal/UserIsGroupAdmin.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Kaleidos Open Source SL
3 | *
4 | * This file is part of PATIO.
5 | * PATIO is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * PATIO is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with PATIO. If not, see
17 | */
18 | package patio.group.services.internal;
19 |
20 | import static patio.common.domain.utils.Check.checkIsTrue;
21 |
22 | import java.util.Optional;
23 | import java.util.UUID;
24 | import patio.common.domain.utils.Check;
25 | import patio.common.domain.utils.Result;
26 | import patio.group.domain.UserGroup;
27 | import patio.group.domain.UserGroupKey;
28 | import patio.group.repositories.UserGroupRepository;
29 | import patio.infrastructure.utils.ErrorConstants;
30 |
31 | /**
32 | * Checks that the user is a given group's admin
33 | *
34 | * @since 0.1.0
35 | */
36 | public class UserIsGroupAdmin {
37 |
38 | private final transient UserGroupRepository repository;
39 |
40 | /**
41 | * Constructor receiving access to the underlying datastore
42 | *
43 | * @param repository an instance of type {@link UserGroupRepository}
44 | * @since 0.1.0
45 | */
46 | public UserIsGroupAdmin(UserGroupRepository repository) {
47 | this.repository = repository;
48 | }
49 |
50 | /**
51 | * @param userId the user checked
52 | * @param groupId the group the user belongs
53 | * @return a failing {@link Result} if the user is not an admin of the group passed
54 | * @since 0.1.0
55 | */
56 | public Check check(UUID userId, UUID groupId) {
57 | Optional userGroup = repository.findById(new UserGroupKey(userId, groupId));
58 |
59 | return checkIsTrue(
60 | userGroup.map(UserGroup::isAdmin).orElse(false), ErrorConstants.NOT_AN_ADMIN);
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/src/main/java/patio/group/services/internal/UserIsInGroup.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Kaleidos Open Source SL
3 | *
4 | * This file is part of PATIO.
5 | * PATIO is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * PATIO is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with PATIO. If not, see
17 | */
18 | package patio.group.services.internal;
19 |
20 | import static patio.common.domain.utils.Check.checkIsTrue;
21 |
22 | import java.util.Optional;
23 | import java.util.stream.Collectors;
24 | import patio.common.domain.utils.Check;
25 | import patio.common.domain.utils.Result;
26 | import patio.group.domain.Group;
27 | import patio.group.domain.UserGroup;
28 | import patio.infrastructure.utils.ErrorConstants;
29 | import patio.user.domain.User;
30 |
31 | /**
32 | * Checks if a given user belongs to a given group
33 | *
34 | * @since 0.1.0
35 | */
36 | public class UserIsInGroup {
37 |
38 | /**
39 | * Checks whether a user belongs to a group or not
40 | *
41 | * @param user user belonging to a group
42 | * @param group group of the user
43 | * @return a failing {@link Result} if the user doesn't belong to the group
44 | * @since 0.1.0
45 | */
46 | public Check check(Optional user, Optional group) {
47 | var userGroups =
48 | user.stream()
49 | .flatMap(u -> u.getGroups().stream())
50 | .map(UserGroup::getGroup)
51 | .collect(Collectors.toSet());
52 | var userIsInGroup = group.map(userGroups::contains).orElse(false);
53 |
54 | return checkIsTrue(userIsInGroup, ErrorConstants.USER_NOT_IN_GROUP);
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/src/main/java/patio/group/services/internal/UserIsNotInGroup.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Kaleidos Open Source SL
3 | *
4 | * This file is part of PATIO.
5 | * PATIO is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * PATIO is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with PATIO. If not, see
17 | */
18 | package patio.group.services.internal;
19 |
20 | import static patio.common.domain.utils.Check.checkIsTrue;
21 |
22 | import java.util.Optional;
23 | import java.util.UUID;
24 | import patio.common.domain.utils.Check;
25 | import patio.common.domain.utils.Result;
26 | import patio.group.domain.UserGroup;
27 | import patio.group.domain.UserGroupKey;
28 | import patio.group.repositories.UserGroupRepository;
29 | import patio.infrastructure.utils.ErrorConstants;
30 |
31 | /**
32 | * Checks that the user should not belong to a given group
33 | *
34 | * @since 0.1.0
35 | */
36 | public class UserIsNotInGroup {
37 |
38 | private final transient UserGroupRepository repository;
39 |
40 | /**
41 | * Constructor receiving access to the underlying data store
42 | *
43 | * @param repository an instance of {@link UserGroupRepository}
44 | * @since 0.1.0
45 | */
46 | public UserIsNotInGroup(UserGroupRepository repository) {
47 | this.repository = repository;
48 | }
49 |
50 | /**
51 | * Checks that a user is not in a group
52 | *
53 | * @param userId the user's id
54 | * @param groupId the group's id
55 | * @return a failing {@link Result} if the user belongs to the group
56 | * @since 0.1.0
57 | */
58 | public Check check(UUID userId, UUID groupId) {
59 | Optional userGroup = repository.findById(new UserGroupKey(userId, groupId));
60 |
61 | return checkIsTrue(userGroup.isEmpty(), ErrorConstants.USER_ALREADY_ON_GROUP);
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/src/main/java/patio/group/services/internal/UserIsNotUniqueGroupAdmin.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Kaleidos Open Source SL
3 | *
4 | * This file is part of PATIO.
5 | * PATIO is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * PATIO is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with PATIO. If not, see
17 | */
18 | package patio.group.services.internal;
19 |
20 | import static patio.common.domain.utils.Check.checkIsFalse;
21 |
22 | import java.util.Collection;
23 | import java.util.Optional;
24 | import java.util.stream.Collectors;
25 | import patio.common.domain.utils.Check;
26 | import patio.common.domain.utils.Result;
27 | import patio.group.domain.Group;
28 | import patio.group.domain.UserGroup;
29 | import patio.infrastructure.utils.ErrorConstants;
30 |
31 | /**
32 | * Checks that a given user is not the unique admin in a group
33 | *
34 | * @since 0.1.0
35 | */
36 | public class UserIsNotUniqueGroupAdmin {
37 |
38 | /**
39 | * Checks that a given user is not the only admin in a group
40 | *
41 | * @param userGroup the user-group relationship to check
42 | * @return a failing {@link Result} if the user is the only admin in a group
43 | * @since 0.1.0
44 | */
45 | public Check check(Optional userGroup) {
46 | var allGroupUserStream =
47 | userGroup.map(UserGroup::getGroup).map(Group::getUsers).stream()
48 | .flatMap(Collection::stream);
49 | var adminUserList =
50 | allGroupUserStream
51 | .filter(UserGroup::isAdmin)
52 | .map(UserGroup::getUser)
53 | .collect(Collectors.toList());
54 |
55 | long adminUserCount = adminUserList.size();
56 | boolean isUserAdmin = userGroup.map(UserGroup::isAdmin).orElse(false);
57 | boolean isUniqueAdmin = adminUserCount == 1 && isUserAdmin;
58 |
59 | return checkIsFalse(isUniqueAdmin, ErrorConstants.UNIQUE_ADMIN);
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/src/main/java/patio/infrastructure/email/services/EmailComposer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Kaleidos Open Source SL
3 | *
4 | * This file is part of PATIO.
5 | * PATIO is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * PATIO is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with PATIO. If not, see
17 | */
18 | package patio.infrastructure.email.services;
19 |
20 | import java.util.Map;
21 | import patio.infrastructure.email.domain.Email;
22 |
23 | /**
24 | * Different methods and utilities regarding the composition of emails
25 | *
26 | * @since 0.1.0
27 | */
28 | public interface EmailComposer {
29 |
30 | /**
31 | * Compose an {@link Email} from its different parts
32 | *
33 | * @param recipient the email recipient (jsmith@example.com)
34 | * @param subject the email subject
35 | * @param bodyTemplate the path where the html body template is located (with the html email body)
36 | * @param bodyVariables the Map of variables the bodyTemplate requires to be interpolated with
37 | * @return the composed {@link Email}
38 | */
39 | Email composeEmail(
40 | String recipient, String subject, String bodyTemplate, Map bodyVariables);
41 |
42 | /**
43 | * Get a text message from a messages.properties file
44 | *
45 | * @param key the key to which recover the text from
46 | * @param variables the variables in the text that should be interpolated
47 | * @return the text message
48 | */
49 | String getMessage(String key, Map variables);
50 |
51 | /**
52 | * Get a plain text message, no variables to interpolate, from a messages.properties file
53 | *
54 | * @param key the key to which recover the text from
55 | * @return the text message
56 | */
57 | String getMessage(String key);
58 |
59 | /**
60 | * Get a composed message representing the current date
61 | *
62 | * @return the textual date
63 | */
64 | String getTodayMessage();
65 | }
66 |
--------------------------------------------------------------------------------
/src/main/java/patio/infrastructure/email/services/EmailService.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Kaleidos Open Source SL
3 | *
4 | * This file is part of PATIO.
5 | * PATIO is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * PATIO is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with PATIO. If not, see
17 | */
18 | package patio.infrastructure.email.services;
19 |
20 | import patio.infrastructure.email.domain.Email;
21 |
22 | /**
23 | * Represents the actions available in an email service
24 | *
25 | * @since 0.1.0
26 | */
27 | public interface EmailService {
28 |
29 | /**
30 | * Sends the email passed as parameter
31 | *
32 | * @param email an instance of type {@link Email}
33 | * @since 0.1.0
34 | */
35 | void send(Email email);
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/patio/infrastructure/email/services/internal/DefaultAwsCredentialsProvider.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Kaleidos Open Source SL
3 | *
4 | * This file is part of PATIO.
5 | * PATIO is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * PATIO is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with PATIO. If not, see
17 | */
18 | package patio.infrastructure.email.services.internal;
19 |
20 | import com.amazonaws.auth.AWSCredentials;
21 | import com.amazonaws.auth.AWSCredentialsProvider;
22 | import com.amazonaws.auth.BasicAWSCredentials;
23 | import io.micronaut.context.annotation.Value;
24 | import javax.inject.Singleton;
25 |
26 | /**
27 | * Given a configuration provides AWS credentials
28 | *
29 | * @since 0.1.0
30 | */
31 | @Singleton
32 | public class DefaultAwsCredentialsProvider implements AWSCredentialsProvider {
33 | private final transient String accessKey;
34 | private final transient String secretKey;
35 |
36 | /**
37 | * Initializes the provider with configuration
38 | *
39 | * @param awsAccessKey credentials access key
40 | * @param awsSecretKey credentials secret key
41 | * @since 0.1.0
42 | */
43 | public DefaultAwsCredentialsProvider(
44 | @Value("${aws.credentials.accesskey:none}") String awsAccessKey,
45 | @Value("${aws.credentials.secretkey:none}") String awsSecretKey) {
46 | this.accessKey = awsAccessKey;
47 | this.secretKey = awsSecretKey;
48 | }
49 |
50 | @Override
51 | public AWSCredentials getCredentials() {
52 | return new BasicAWSCredentials(this.accessKey, this.secretKey);
53 | }
54 |
55 | @Override
56 | public void refresh() {
57 | // not implemented
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/src/main/java/patio/infrastructure/email/services/internal/MessagesFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Kaleidos Open Source SL
3 | *
4 | * This file is part of PATIO.
5 | * PATIO is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * PATIO is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with PATIO. If not, see
17 | */
18 | package patio.infrastructure.email.services.internal;
19 |
20 | import io.micronaut.context.MessageSource;
21 | import io.micronaut.context.annotation.Bean;
22 | import io.micronaut.context.annotation.Factory;
23 | import io.micronaut.context.annotation.Value;
24 | import io.micronaut.context.i18n.ResourceBundleMessageSource;
25 | import java.util.Locale;
26 | import java.util.Optional;
27 | import javax.inject.Singleton;
28 |
29 | /** Handle the message template resolution and variables interpolation */
30 | @Factory
31 | public class MessagesFactory {
32 |
33 | /**
34 | * Initializes MessageSource with the locale taken from configuration
35 | *
36 | * @param locale language for {@link Locale}
37 | * @return The message source backed by the locale resource bundle {@link
38 | * ResourceBundleMessageSource}
39 | */
40 | @Singleton
41 | @Bean
42 | /* default */ MessageSource messageSource(@Value("${locale}") Optional locale) {
43 | Locale configLocale = locale.map(Locale::new).orElse(Locale.ENGLISH);
44 | return new ResourceBundleMessageSource("messages", configLocale);
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/src/main/java/patio/infrastructure/email/services/internal/templates/JadeConfigurationFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Kaleidos Open Source SL
3 | *
4 | * This file is part of PATIO.
5 | * PATIO is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * PATIO is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with PATIO. If not, see
17 | */
18 | package patio.infrastructure.email.services.internal.templates;
19 |
20 | import de.neuland.jade4j.JadeConfiguration;
21 | import de.neuland.jade4j.template.ClasspathTemplateLoader;
22 | import de.neuland.jade4j.template.TemplateLoader;
23 | import io.micronaut.context.annotation.Value;
24 | import javax.inject.Provider;
25 | import javax.inject.Singleton;
26 |
27 | /**
28 | * Configuration related to templating behavior
29 | *
30 | * @since 0.1.0
31 | */
32 | @Singleton
33 | public class JadeConfigurationFactory implements Provider {
34 |
35 | private final transient String encoding;
36 | private final transient boolean cached;
37 |
38 | /**
39 | * Default constructor
40 | *
41 | * @param encoding encoding type (UTF-8, ISO-...)
42 | * @param cached whether the templates are cached or not
43 | * @since 0.1.0
44 | */
45 | public JadeConfigurationFactory(
46 | @Value("${templates.encoding}") String encoding,
47 | @Value("${templates.cached}") boolean cached) {
48 | this.cached = cached;
49 | this.encoding = encoding;
50 | }
51 |
52 | @Override
53 | public JadeConfiguration get() {
54 | JadeConfiguration configuration = new JadeConfiguration();
55 | TemplateLoader templateLoader = new ClasspathTemplateLoader(this.encoding);
56 |
57 | configuration.setCaching(this.cached);
58 | configuration.setTemplateLoader(templateLoader);
59 |
60 | return configuration;
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/src/main/java/patio/infrastructure/email/services/internal/templates/MailResourceBundleFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Kaleidos Open Source SL
3 | *
4 | * This file is part of PATIO.
5 | * PATIO is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * PATIO is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with PATIO. If not, see
17 | */
18 | package patio.infrastructure.email.services.internal.templates;
19 |
20 | import static java.util.ResourceBundle.getBundle;
21 |
22 | import io.micronaut.context.annotation.Value;
23 | import java.util.Locale;
24 | import java.util.Optional;
25 | import java.util.ResourceBundle;
26 | import javax.inject.Provider;
27 | import javax.inject.Singleton;
28 |
29 | /**
30 | * Loads all mail related messages in the locale configured in application configuration file
31 | *
32 | * @since 0.1.0
33 | */
34 | @Singleton
35 | public class MailResourceBundleFactory implements Provider {
36 |
37 | private final transient Optional locale;
38 |
39 | /**
40 | * Loads all messages of the chosen locale
41 | *
42 | * @param locale optional locale required to load the messages
43 | * @since 0.1.0
44 | */
45 | public MailResourceBundleFactory(@Value("${locale}") Optional locale) {
46 | this.locale = locale;
47 | }
48 |
49 | @Override
50 | public ResourceBundle get() {
51 | return this.locale.map(locale -> getBundle("messages", locale)).orElse(getBundle("messages"));
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/src/main/java/patio/infrastructure/email/services/internal/templates/URLResolverService.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Kaleidos Open Source SL
3 | *
4 | * This file is part of PATIO.
5 | * PATIO is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * PATIO is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with PATIO. If not, see
17 | */
18 | package patio.infrastructure.email.services.internal.templates;
19 |
20 | import io.micronaut.context.annotation.Value;
21 | import java.net.URI;
22 | import java.text.MessageFormat;
23 | import javax.inject.Singleton;
24 |
25 | /**
26 | * Resolves all links relative to the host declared in applcation configuration
27 | *
28 | * @since 0.1.0
29 | */
30 | @Singleton
31 | public class URLResolverService {
32 |
33 | private final transient String host;
34 |
35 | /**
36 | * Initializes service with the declared application host
37 | *
38 | * @param host host all links are going to be resolved against
39 | * @since 0.1.0
40 | */
41 | public URLResolverService(@Value("${urlresolver.host}") String host) {
42 | this.host = host;
43 | }
44 |
45 | /**
46 | * Resolves link relative to declared host domain
47 | *
48 | * @param pattern url path pattern
49 | * @param values values to substitue in the path part of the url
50 | * @return complete url
51 | * @since 0.1.0
52 | */
53 | public String resolve(String pattern, Object... values) {
54 | String path = MessageFormat.format(pattern, values);
55 |
56 | return URI.create(host).resolve(path).toString();
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/src/main/java/patio/infrastructure/graphql/Context.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Kaleidos Open Source SL
3 | *
4 | * This file is part of PATIO.
5 | * PATIO is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * PATIO is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with PATIO. If not, see
17 | */
18 | package patio.infrastructure.graphql;
19 |
20 | import patio.user.domain.User;
21 |
22 | /**
23 | * Represents the GraphQL context of the application
24 | *
25 | * @since 0.1.0
26 | */
27 | public class Context {
28 |
29 | private User authenticatedUser;
30 |
31 | /**
32 | * Returns the current authenticated user
33 | *
34 | * @return the authenticated user
35 | * @since 0.1.0
36 | */
37 | public User getAuthenticatedUser() {
38 | return authenticatedUser;
39 | }
40 |
41 | /**
42 | * Sets the current authenticated user
43 | *
44 | * @param authenticatedUser the authenticated user
45 | * @since 0.1.0
46 | */
47 | public void setAuthenticatedUser(User authenticatedUser) {
48 | this.authenticatedUser = authenticatedUser;
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/src/main/java/patio/infrastructure/graphql/GraphQLFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Kaleidos Open Source SL
3 | *
4 | * This file is part of PATIO.
5 | * PATIO is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * PATIO is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with PATIO. If not, see
17 | */
18 | package patio.infrastructure.graphql;
19 |
20 | import graphql.GraphQL;
21 | import graphql.execution.instrumentation.dataloader.DataLoaderDispatcherInstrumentation;
22 | import graphql.schema.GraphQLSchema;
23 | import io.micronaut.context.annotation.Bean;
24 | import io.micronaut.context.annotation.Factory;
25 | import javax.inject.Singleton;
26 | import patio.infrastructure.graphql.instrumentation.AuthenticationCheck;
27 |
28 | /**
29 | * Maps the schema with the functions that are actually operating over the real data
30 | *
31 | * @since 0.1.0
32 | */
33 | @Factory
34 | public class GraphQLFactory {
35 |
36 | /**
37 | * Configures the GraphQL environment mapping fetchers with fields in the schema.
38 | *
39 | * @param schema the {@link GraphQLSchema}
40 | * @return an instance of {@link GraphQL}
41 | * @since 0.1.0
42 | */
43 | @Bean
44 | @Singleton
45 | public GraphQL graphQL(GraphQLSchema schema) {
46 | return GraphQL.newGraphQL(schema)
47 | .instrumentation(new AuthenticationCheck())
48 | .instrumentation(new DataLoaderDispatcherInstrumentation())
49 | .build();
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/main/java/patio/infrastructure/graphql/I18nGraphQLError.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Kaleidos Open Source SL
3 | *
4 | * This file is part of PATIO.
5 | * PATIO is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * PATIO is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with PATIO. If not, see
17 | */
18 | package patio.infrastructure.graphql;
19 |
20 | import graphql.ErrorType;
21 | import graphql.GraphQLError;
22 | import graphql.language.SourceLocation;
23 | import java.util.List;
24 | import java.util.Map;
25 |
26 | /**
27 | * Custom {@link GraphQLError} that only shows two fields code and message
28 | *
29 | * @since 0.1.0
30 | * @see GraphQLError
31 | */
32 | public class I18nGraphQLError implements GraphQLError {
33 |
34 | private static final long serialVersionUID = 1L;
35 | private final String code;
36 | private final String message;
37 | /**
38 | * Initializes the error with its code and message
39 | *
40 | * @param code i18n code
41 | * @param message developer friendly message
42 | * @since 0.1.0
43 | */
44 | public I18nGraphQLError(String code, String message) {
45 | this.code = code;
46 | this.message = message;
47 | }
48 |
49 | @Override
50 | public Map getExtensions() {
51 | return Map.of("code", this.getCode());
52 | }
53 |
54 | /**
55 | * Returns the error code
56 | *
57 | * @return the error code
58 | * @since 0.1.0
59 | */
60 | public String getCode() {
61 | return this.code;
62 | }
63 |
64 | @Override
65 | public String getMessage() {
66 | return this.message;
67 | }
68 |
69 | @Override
70 | public List getLocations() {
71 | return null;
72 | }
73 |
74 | @Override
75 | public ErrorType getErrorType() {
76 | return ErrorType.OperationNotSupported;
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/src/main/java/patio/infrastructure/graphql/MutationProvider.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Kaleidos Open Source SL
3 | *
4 | * This file is part of PATIO.
5 | * PATIO is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * PATIO is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with PATIO. If not, see
17 | */
18 | package patio.infrastructure.graphql;
19 |
20 | import graphql.schema.idl.TypeRuntimeWiring;
21 | import java.util.function.UnaryOperator;
22 |
23 | /**
24 | * A class implementing this interface it's supposed to provide data fetchers to handle mutation
25 | * calls
26 | */
27 | @FunctionalInterface
28 | public interface MutationProvider {
29 |
30 | /**
31 | * It should return a function that will receive a {@link TypeRuntimeWiring.Builder} and will
32 | * return that same {@link TypeRuntimeWiring.Builder}. The builder received by that function could
33 | * be use to chain several {@link TypeRuntimeWiring.Builder#dataFetcher(String,
34 | * graphql.schema.DataFetcher)} calls to register mutation fetchers
35 | *
36 | * @return a function that will receive a {@link TypeRuntimeWiring.Builder} and will return that
37 | * same {@link TypeRuntimeWiring.Builder}
38 | */
39 | UnaryOperator getMutations();
40 | }
41 |
--------------------------------------------------------------------------------
/src/main/java/patio/infrastructure/graphql/QueryProvider.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Kaleidos Open Source SL
3 | *
4 | * This file is part of PATIO.
5 | * PATIO is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * PATIO is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with PATIO. If not, see
17 | */
18 | package patio.infrastructure.graphql;
19 |
20 | import graphql.schema.idl.TypeRuntimeWiring;
21 | import java.util.function.UnaryOperator;
22 |
23 | /**
24 | * A class implementing this interface it's supposed to provide data fetchers to handle query calls
25 | */
26 | @FunctionalInterface
27 | public interface QueryProvider {
28 |
29 | /**
30 | * It should return a function that will receive a {@link TypeRuntimeWiring.Builder} and will
31 | * return that same {@link TypeRuntimeWiring.Builder}. The builder received by that function could
32 | * be use to chain several {@link TypeRuntimeWiring.Builder#dataFetcher(String,
33 | * graphql.schema.DataFetcher)} calls to register query fetchers
34 | *
35 | * @return a function that will receive a {@link TypeRuntimeWiring.Builder} and will return that
36 | * same {@link TypeRuntimeWiring.Builder}
37 | */
38 | UnaryOperator getQueries();
39 | }
40 |
--------------------------------------------------------------------------------
/src/main/java/patio/infrastructure/graphql/ScalarProvider.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Kaleidos Open Source SL
3 | *
4 | * This file is part of PATIO.
5 | * PATIO is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * PATIO is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with PATIO. If not, see
17 | */
18 | package patio.infrastructure.graphql;
19 |
20 | import graphql.schema.idl.RuntimeWiring;
21 | import java.util.function.UnaryOperator;
22 |
23 | /**
24 | * A class implementing this interface it's supposed to provide implementation for scalar types
25 | * defined in the schema
26 | */
27 | @FunctionalInterface
28 | public interface ScalarProvider {
29 |
30 | /**
31 | * Returns a function that receives a {@link RuntimeWiring.Builder} and returns a {@link
32 | * RuntimeWiring.Builder}
33 | *
34 | * @return a {@link UnaryOperator} of type {@link RuntimeWiring.Builder}
35 | */
36 | UnaryOperator getScalars();
37 | }
38 |
--------------------------------------------------------------------------------
/src/main/java/patio/infrastructure/graphql/TypeDefinitionRegistryFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Kaleidos Open Source SL
3 | *
4 | * This file is part of PATIO.
5 | * PATIO is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * PATIO is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with PATIO. If not, see
17 | */
18 | package patio.infrastructure.graphql;
19 |
20 | import static java.nio.charset.StandardCharsets.UTF_8;
21 |
22 | import graphql.schema.idl.SchemaParser;
23 | import graphql.schema.idl.TypeDefinitionRegistry;
24 | import io.micronaut.context.annotation.Bean;
25 | import io.micronaut.context.annotation.Factory;
26 | import io.micronaut.context.annotation.Value;
27 | import io.micronaut.core.io.ResourceResolver;
28 | import java.io.BufferedReader;
29 | import java.io.InputStreamReader;
30 | import javax.inject.Singleton;
31 |
32 | /**
33 | * Factory to creates an instance of type {@link TypeDefinitionRegistry}
34 | *
35 | * @see TypeDefinitionRegistry
36 | */
37 | @Factory
38 | public class TypeDefinitionRegistryFactory {
39 |
40 | /**
41 | * Creates an instance of type {@link TypeDefinitionRegistry}
42 | *
43 | * @param path where is located the schema
44 | * @param resourceResolver required to know how to resolve the path
45 | * @return an instance of type {@link TypeDefinitionRegistry}
46 | */
47 | @Bean
48 | @Singleton
49 | public TypeDefinitionRegistry load(
50 | @Value("${graphql.schema}") String path, ResourceResolver resourceResolver) {
51 | var typeRegistry = new TypeDefinitionRegistry();
52 | var schemaParser = new SchemaParser();
53 | var schemaReader =
54 | resourceResolver
55 | .getResourceAsStream(path)
56 | .map(inputStream -> new InputStreamReader(inputStream, UTF_8))
57 | .map(BufferedReader::new);
58 |
59 | return schemaReader.map(schemaParser::parse).map(typeRegistry::merge).orElse(null);
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/src/main/java/patio/infrastructure/graphql/TypeProvider.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Kaleidos Open Source SL
3 | *
4 | * This file is part of PATIO.
5 | * PATIO is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * PATIO is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with PATIO. If not, see
17 | */
18 | package patio.infrastructure.graphql;
19 |
20 | import graphql.schema.idl.RuntimeWiring;
21 | import java.util.function.UnaryOperator;
22 |
23 | /**
24 | * A class implementing this interface it's supposed to provide implementation for type's fields
25 | * fetchers defined in the schema
26 | */
27 | @FunctionalInterface
28 | public interface TypeProvider {
29 |
30 | /**
31 | * Returns a function
32 | *
33 | * @return an {@link UnaryOperator} of type {@link RuntimeWiring.Builder}
34 | */
35 | UnaryOperator getTypes();
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/patio/infrastructure/graphql/dataloader/DataLoaderRegistryFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Kaleidos Open Source SL
3 | *
4 | * This file is part of PATIO.
5 | * PATIO is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * PATIO is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with PATIO. If not, see
17 | */
18 | package patio.infrastructure.graphql.dataloader;
19 |
20 | import io.micronaut.context.annotation.Bean;
21 | import io.micronaut.context.annotation.Factory;
22 | import javax.inject.Singleton;
23 | import org.dataloader.DataLoader;
24 | import org.dataloader.DataLoaderRegistry;
25 | import patio.user.domain.User;
26 | import patio.user.graphql.UserBatchLoader;
27 |
28 | /**
29 | * Data loaders are important specially when batching data in nested GraphQL queries
30 | *
31 | * @since 0.1.0
32 | */
33 | @Factory
34 | public class DataLoaderRegistryFactory {
35 |
36 | /**
37 | * Key that can be used within a {@link graphql.schema.DataFetcher} to get an instance of a {@link
38 | * UserBatchLoader}
39 | *
40 | * @since 0.1.0
41 | */
42 | public static final String DL_USERS_BY_IDS = "users_by_id";
43 |
44 | /**
45 | * Creates a new {@link DataLoaderRegistry}
46 | *
47 | * @param userBatchLoader an instance of {@link UserBatchLoader} to load {@link User} data
48 | * @return a new instance of {@link DataLoaderRegistry}
49 | * @since 0.1.0
50 | */
51 | @Bean
52 | @Singleton
53 | public DataLoaderRegistry create(UserBatchLoader userBatchLoader) {
54 | DataLoaderRegistry registry = new DataLoaderRegistry();
55 |
56 | return registry.register(DL_USERS_BY_IDS, DataLoader.newDataLoader(userBatchLoader));
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/src/main/java/patio/infrastructure/graphql/instrumentation/AuthenticationCheckState.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Kaleidos Open Source SL
3 | *
4 | * This file is part of PATIO.
5 | * PATIO is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * PATIO is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with PATIO. If not, see
17 | */
18 | package patio.infrastructure.graphql.instrumentation;
19 |
20 | import graphql.execution.instrumentation.InstrumentationState;
21 |
22 | /**
23 | * Represents the current state of the hierarchy of a field that could be annotated by
24 | * the @anonymousAllowed directive
25 | *
26 | * @since 0.1.0
27 | */
28 | class AuthenticationCheckState implements InstrumentationState {
29 | private boolean allowed;
30 |
31 | /**
32 | * Initial state
33 | *
34 | * @param allowed if the hierarchy parent has been already allowed
35 | * @since 0.1.0
36 | */
37 | /* default */ AuthenticationCheckState(boolean allowed) {
38 | this.allowed = allowed;
39 | }
40 |
41 | /**
42 | * Returns whether the field hierarchy has been already allowed or not
43 | *
44 | * @return true if the field hierarchy has been already allowed, false otherwise
45 | * @since 0.1.0
46 | */
47 | /* default */ boolean isAllowed() {
48 | return allowed;
49 | }
50 |
51 | /**
52 | * @param allowed true if the field hierarchy has been already allowed, false otherwise
53 | * @since 0.1.0
54 | */
55 | /* default */ void setAllowed(boolean allowed) {
56 | this.allowed = allowed;
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/src/main/java/patio/infrastructure/persistence/MicroBaseRepository.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Kaleidos Open Source SL
3 | *
4 | * This file is part of PATIO.
5 | * PATIO is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * PATIO is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with PATIO. If not, see
17 | */
18 | package patio.infrastructure.persistence;
19 |
20 | import javax.persistence.EntityManager;
21 | import javax.persistence.PersistenceContext;
22 |
23 | /** Base repository to access {@link EntityManager} */
24 | public class MicroBaseRepository {
25 | @PersistenceContext private final transient EntityManager entityManager;
26 |
27 | /**
28 | * Initializes repository with {@link EntityManager}
29 | *
30 | * @param entityManager persistence {@link EntityManager} instance
31 | */
32 | public MicroBaseRepository(EntityManager entityManager) {
33 | this.entityManager = entityManager;
34 | }
35 |
36 | /**
37 | * Returns the current {@link EntityManager}
38 | *
39 | * @return an {@link EntityManager}
40 | */
41 | public EntityManager getEntityManager() {
42 | return entityManager;
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/main/java/patio/infrastructure/utils/IterableUtils.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Kaleidos Open Source SL
3 | *
4 | * This file is part of PATIO.
5 | * PATIO is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * PATIO is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with PATIO. If not, see
17 | */
18 | package patio.infrastructure.utils;
19 |
20 | import java.util.stream.Stream;
21 | import java.util.stream.StreamSupport;
22 |
23 | /** Functions to handle {@link Iterable} instances */
24 | public final class IterableUtils {
25 |
26 | private IterableUtils() {
27 | /* empty */
28 | }
29 |
30 | /**
31 | * Transforms an {@link Iterable} to {@link Stream}
32 | *
33 | * @param type of the elements of the iterable
34 | * @param iterable instance of type {@link Iterable} to transform
35 | * @return an instance of type {@link Stream}
36 | */
37 | public static Stream iterableToStream(Iterable iterable) {
38 | return StreamSupport.stream(iterable.spliterator(), false);
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/main/java/patio/security/domain/Login.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Kaleidos Open Source SL
3 | *
4 | * This file is part of PATIO.
5 | * PATIO is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * PATIO is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with PATIO. If not, see
17 | */
18 | package patio.security.domain;
19 |
20 | import patio.user.domain.User;
21 |
22 | /**
23 | * Information delivered when a used authenticates successfully in the system
24 | *
25 | * @since 0.1.0
26 | */
27 | public class Login {
28 | private final Tokens tokens;
29 | private final User user;
30 |
31 | /**
32 | * Initializes a login instance
33 | *
34 | * @param tokens the user's tokens
35 | * @param user the user's general information
36 | * @since 0.1.0
37 | */
38 | public Login(Tokens tokens, User user) {
39 | this.tokens = tokens;
40 | this.user = user;
41 | }
42 |
43 | /**
44 | * Returns the user's tokens
45 | *
46 | * @return the generated tokens for user
47 | * @since 0.1.0
48 | */
49 | public Tokens getTokens() {
50 | return tokens;
51 | }
52 |
53 | /**
54 | * @return the user's information
55 | * @since 0.1.0
56 | */
57 | public User getUser() {
58 | return user;
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/src/main/java/patio/security/domain/Tokens.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Kaleidos Open Source SL
3 | *
4 | * This file is part of PATIO.
5 | * PATIO is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * PATIO is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with PATIO. If not, see
17 | */
18 | package patio.security.domain;
19 |
20 | import patio.common.domain.utils.Builder;
21 |
22 | /**
23 | * Represents a normal JWT login response with an authentication and a refresh tokens
24 | *
25 | * @since 0.1.0
26 | */
27 | public class Tokens {
28 | private String authenticationToken;
29 | private String refreshToken;
30 |
31 | /**
32 | * Creates a builder to build a {@link Tokens} instance
33 | *
34 | * @return an instance of {@link Builder}
35 | * @since 0.1.0
36 | */
37 | public static Builder builder() {
38 | return Builder.build(Tokens::new);
39 | }
40 |
41 | /**
42 | * Returns the authentication token
43 | *
44 | * @return the authentication token
45 | * @since 0.1.0
46 | */
47 | public String getAuthenticationToken() {
48 | return authenticationToken;
49 | }
50 |
51 | /**
52 | * Returns the refresh token
53 | *
54 | * @return the refresh token
55 | * @since 0.1.0
56 | */
57 | public String getRefreshToken() {
58 | return refreshToken;
59 | }
60 |
61 | /**
62 | * Sets the authentication token
63 | *
64 | * @param refreshToken the refresh token
65 | * @since 0.1.0
66 | */
67 | public void setRefreshToken(String refreshToken) {
68 | this.refreshToken = refreshToken;
69 | }
70 |
71 | /**
72 | * Sets the authentication token
73 | *
74 | * @param authenticationToken the authentication token
75 | * @since 0.1.0
76 | */
77 | public void setAuthenticationToken(String authenticationToken) {
78 | this.authenticationToken = authenticationToken;
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/src/main/java/patio/security/graphql/ChangePasswordInput.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Kaleidos Open Source SL
3 | *
4 | * This file is part of PATIO.
5 | * PATIO is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * PATIO is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with PATIO. If not, see
17 | */
18 | package patio.security.graphql;
19 |
20 | /**
21 | * Input to change the password for a user
22 | *
23 | * @since 0.1.0
24 | */
25 | public class ChangePasswordInput {
26 |
27 | private final String otpCode;
28 | private final String password;
29 |
30 | /**
31 | * Creates an input instance with the required dependencies
32 | *
33 | * @param otpCode the OTP code to change the password
34 | * @param password the new password
35 | */
36 | public ChangePasswordInput(String otpCode, String password) {
37 | this.otpCode = otpCode;
38 | this.password = password;
39 | }
40 |
41 | /**
42 | * Returns the input's password
43 | *
44 | * @return input password
45 | * @since 0.1.0
46 | */
47 | public String getPassword() {
48 | return password;
49 | }
50 |
51 | /**
52 | * Returns the otp code used for changing the password
53 | *
54 | * @return the otp code used for changing the password
55 | */
56 | public String getOtpCode() {
57 | return otpCode;
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/src/main/java/patio/security/graphql/LoginInput.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Kaleidos Open Source SL
3 | *
4 | * This file is part of PATIO.
5 | * PATIO is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * PATIO is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with PATIO. If not, see
17 | */
18 | package patio.security.graphql;
19 |
20 | /**
21 | * Authentication input. It contains credentials to authenticate a given user.
22 | *
23 | * @since 0.1.0
24 | */
25 | public class LoginInput {
26 |
27 | private final String email;
28 | private final String password;
29 |
30 | /**
31 | * Initializes the input with the user's email and password
32 | *
33 | * @param email user's email
34 | * @param password user's password
35 | * @since 0.1.0
36 | */
37 | public LoginInput(String email, String password) {
38 | this.email = email;
39 | this.password = password;
40 | }
41 |
42 | /**
43 | * Returns input's email
44 | *
45 | * @return input's email
46 | * @since 0.1.0
47 | */
48 | public String getEmail() {
49 | return email;
50 | }
51 |
52 | /**
53 | * Returns the input's password
54 | *
55 | * @return input password
56 | * @since 0.1.0
57 | */
58 | public String getPassword() {
59 | return password;
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/src/main/java/patio/security/graphql/ResetPasswordFetcher.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Kaleidos Open Source SL
3 | *
4 | * This file is part of PATIO.
5 | * PATIO is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * PATIO is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with PATIO. If not, see
17 | */
18 | package patio.security.graphql;
19 |
20 | import graphql.schema.DataFetchingEnvironment;
21 | import javax.inject.Singleton;
22 | import patio.security.services.ResetPasswordService;
23 | import patio.user.domain.User;
24 | import patio.user.services.internal.DefaultUserService;
25 |
26 | /**
27 | * All related GraphQL operations over the {@link User} password
28 | *
29 | * @since 0.1.0
30 | */
31 | @Singleton
32 | public class ResetPasswordFetcher {
33 |
34 | /**
35 | * Instance handling the business logic
36 | *
37 | * @since 0.1.0
38 | */
39 | private final transient ResetPasswordService service;
40 |
41 | /**
42 | * Constructor initializing the access to the business logic
43 | *
44 | * @param service instance of {@link DefaultUserService}
45 | * @since 0.1.0
46 | */
47 | public ResetPasswordFetcher(ResetPasswordService service) {
48 | this.service = service;
49 | }
50 |
51 | /**
52 | * Initiates the process of resetting the password for a user
53 | *
54 | * @param env GraphQL execution environment
55 | * @return true
56 | */
57 | public Boolean resetPassword(DataFetchingEnvironment env) {
58 | String email = env.getArgument("email");
59 | service.resetPasswordRequest(email);
60 | return true;
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/src/main/java/patio/security/graphql/SecurityFetcherUtils.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Kaleidos Open Source SL
3 | *
4 | * This file is part of PATIO.
5 | * PATIO is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * PATIO is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with PATIO. If not, see
17 | */
18 | package patio.security.graphql;
19 |
20 | import graphql.schema.DataFetchingEnvironment;
21 |
22 | /**
23 | * Contains functions to build domain inputs from the underlying {@link DataFetchingEnvironment}
24 | * coming from the GraphQL engine execution. This class is meant to be used only for the {@link
25 | * SecurityFetcher} instance and related tests.
26 | *
27 | * @since 0.1.0
28 | */
29 | final class SecurityFetcherUtils {
30 |
31 | private SecurityFetcherUtils() {
32 | /* empty */
33 | }
34 |
35 | /**
36 | * Creates a {@link LoginInput} from the data coming from the {@link DataFetchingEnvironment}
37 | *
38 | * @param environment the GraphQL {@link DataFetchingEnvironment}
39 | * @return an instance of {@link LoginInput}
40 | * @since 0.1.0
41 | */
42 | /* default */ static LoginInput login(DataFetchingEnvironment environment) {
43 | String email = environment.getArgument("email");
44 | String password = environment.getArgument("password");
45 |
46 | return new LoginInput(email, password);
47 | }
48 |
49 | /**
50 | * Creates a {@link ChangePasswordInput} from the data coming from the {@link
51 | * DataFetchingEnvironment}
52 | *
53 | * @param environment the GraphQL {@link DataFetchingEnvironment}
54 | * @return an instance of {@link ChangePasswordInput}
55 | * @since 0.1.0
56 | */
57 | /* default */ static ChangePasswordInput changePassword(DataFetchingEnvironment environment) {
58 | String otpCode = environment.getArgument("otp");
59 | String password = environment.getArgument("password");
60 |
61 | return new ChangePasswordInput(otpCode, password);
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/src/main/java/patio/security/services/CryptoService.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Kaleidos Open Source SL
3 | *
4 | * This file is part of PATIO.
5 | * PATIO is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * PATIO is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with PATIO. If not, see
17 | */
18 | package patio.security.services;
19 |
20 | import com.auth0.jwt.interfaces.DecodedJWT;
21 | import java.util.Optional;
22 | import patio.security.domain.Tokens;
23 | import patio.user.domain.User;
24 |
25 | /**
26 | * Service responsible for creating and validating JWT tokens
27 | *
28 | * @since 0.1.0
29 | */
30 | public interface CryptoService {
31 |
32 | /**
33 | * Creates a new token from the {@link User} information
34 | *
35 | * @param user user to create the token from
36 | * @return a valid pair of tokens
37 | * @since 0.1.0
38 | */
39 | Tokens createTokens(User user);
40 |
41 | /**
42 | * Verifies that the provided token is valid
43 | *
44 | * @param token the token to validate
45 | * @return the token subject if the token is valid, is empty otherwise
46 | * @since 0.1.0
47 | */
48 | Optional verifyToken(String token);
49 |
50 | /**
51 | * Decodes without verifying anything the token passed as argument
52 | *
53 | * @param token token to decode
54 | * @return an instance of {@link DecodedJWT}
55 | * @since 0.1.0
56 | */
57 | Optional decode(String token);
58 |
59 | /**
60 | * Hashes a given text
61 | *
62 | * @param text the text to hash
63 | * @return the hashed text
64 | * @since 0.1.0
65 | */
66 | String hash(String text);
67 |
68 | /**
69 | * Verifies that the plain text provided matches the hashed version
70 | *
71 | * @param plain plain text
72 | * @param hashed hashed version of the plain text
73 | * @return true if plain text and hashed password are considered equal
74 | * @since 0.1.0
75 | */
76 | boolean verifyWithHash(String plain, String hashed);
77 | }
78 |
--------------------------------------------------------------------------------
/src/main/java/patio/security/services/GoogleUserService.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Kaleidos Open Source SL
3 | *
4 | * This file is part of PATIO.
5 | * PATIO is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * PATIO is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with PATIO. If not, see
17 | */
18 | package patio.security.services;
19 |
20 | import java.util.Optional;
21 | import patio.user.domain.User;
22 |
23 | /**
24 | * Service to access user's Google basic information
25 | *
26 | * @since 0.1.0
27 | */
28 | public interface GoogleUserService {
29 |
30 | /**
31 | * Loads a given's user information from a previously acquired access token
32 | *
33 | * @param accessToken Google's access token
34 | * @return a basic {@link User}'s information
35 | * @since 0.1.0
36 | */
37 | Optional loadFromAccessToken(String accessToken);
38 | }
39 |
--------------------------------------------------------------------------------
/src/main/java/patio/security/services/OauthService.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Kaleidos Open Source SL
3 | *
4 | * This file is part of PATIO.
5 | * PATIO is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * PATIO is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with PATIO. If not, see
17 | */
18 | package patio.security.services;
19 |
20 | import java.util.Optional;
21 |
22 | /**
23 | * Service to complete authorization workflow. Workflow has started in the front-end getting the
24 | * authorization code and the service completes the flow by getting an access token from the
25 | * previous authorization code.
26 | *
27 | * @since 0.1.0
28 | */
29 | public interface OauthService {
30 |
31 | /**
32 | * Gets an access token from a previously acquired authorization code
33 | *
34 | * @param authorizationCode authorization code acquired in oauth2 previous steps
35 | * @return an access token
36 | * @since 0.1.0
37 | */
38 | Optional getAccessToken(String authorizationCode);
39 | }
40 |
--------------------------------------------------------------------------------
/src/main/java/patio/security/services/ResetPasswordService.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Kaleidos Open Source SL
3 | *
4 | * This file is part of PATIO.
5 | * PATIO is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * PATIO is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with PATIO. If not, see
17 | */
18 | package patio.security.services;
19 |
20 | /**
21 | * Business logic to handle user password operations
22 | *
23 | * @since 0.1.0
24 | */
25 | public interface ResetPasswordService {
26 |
27 | /**
28 | * Sends an userEmail to the user with a generated OTP link to reset her previous password
29 | *
30 | * @param userEmail user userEmail
31 | */
32 | void resetPasswordRequest(String userEmail);
33 | }
34 |
--------------------------------------------------------------------------------
/src/main/java/patio/security/services/internal/PasswordIsBlank.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Kaleidos Open Source SL
3 | *
4 | * This file is part of PATIO.
5 | * PATIO is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * PATIO is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with PATIO. If not, see
17 | */
18 | package patio.security.services.internal;
19 |
20 | import static patio.common.domain.utils.Check.checkIsFalse;
21 |
22 | import patio.common.domain.utils.Check;
23 | import patio.common.domain.utils.Result;
24 | import patio.infrastructure.utils.ErrorConstants;
25 |
26 | /**
27 | * This checker expects the argument passed is not blank, otherwise it will return a failing {@link
28 | * Result}
29 | *
30 | * @since 0.1.0
31 | */
32 | public class PasswordIsBlank {
33 |
34 | /**
35 | * Checks that the argument passed as parameter is not blank. Otherwise will build a failing
36 | * {@link Result} containing an error {@link ErrorConstants#NOT_FOUND}
37 | *
38 | * @param text the object checked
39 | * @return a failing {@link Result} if the object is null
40 | * @since 0.1.0
41 | */
42 | public Check check(String text) {
43 | return checkIsFalse(text.isBlank(), ErrorConstants.BLANK_PASSWORD);
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/main/java/patio/security/services/internal/SamePassword.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Kaleidos Open Source SL
3 | *
4 | * This file is part of PATIO.
5 | * PATIO is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * PATIO is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with PATIO. If not, see
17 | */
18 | package patio.security.services.internal;
19 |
20 | import static patio.common.domain.utils.Check.checkIsFalse;
21 |
22 | import patio.common.domain.utils.Check;
23 | import patio.common.domain.utils.Result;
24 | import patio.infrastructure.utils.ErrorConstants;
25 | import patio.security.services.CryptoService;
26 | import patio.user.domain.User;
27 |
28 | /**
29 | * Checks if the user has already defined the same password as the one provided
30 | *
31 | * @since 0.1.0
32 | */
33 | public class SamePassword {
34 |
35 | private final transient CryptoService cryptoService;
36 |
37 | /**
38 | * This checker expects the password being updated to be different
39 | *
40 | * @param cryptoService an instance of {@link CryptoService}
41 | */
42 | public SamePassword(CryptoService cryptoService) {
43 | this.cryptoService = cryptoService;
44 | }
45 |
46 | /**
47 | * Checks the new password is not the same the one user already has
48 | *
49 | * @param user the {@link User}
50 | * @param newPassword the new password has to be different
51 | * @return a failing {@link Result} if the user has already defined that password
52 | * @since 0.1.0
53 | */
54 | public Check check(User user, String newPassword) {
55 | return checkIsFalse(
56 | cryptoService.verifyWithHash(newPassword, user.getPassword()),
57 | ErrorConstants.SAME_PASSWORD);
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/src/main/java/patio/security/services/internal/ScribeOauth2ServiceProvider.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Kaleidos Open Source SL
3 | *
4 | * This file is part of PATIO.
5 | * PATIO is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * PATIO is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with PATIO. If not, see
17 | */
18 | package patio.security.services.internal;
19 |
20 | import com.github.scribejava.apis.GoogleApi20;
21 | import com.github.scribejava.core.builder.ServiceBuilder;
22 | import com.github.scribejava.core.oauth.OAuth20Service;
23 | import io.micronaut.context.annotation.Value;
24 | import javax.inject.Provider;
25 | import javax.inject.Singleton;
26 |
27 | /**
28 | * Creates an instance of {@link OAuth20Service} with its properties configured from the
29 | * application.yml values
30 | *
31 | * @since 0.1.0
32 | */
33 | @Singleton
34 | public class ScribeOauth2ServiceProvider implements Provider {
35 |
36 | private final transient String apiKey;
37 | private final transient String apiSecret;
38 | private final transient String callback;
39 |
40 | /**
41 | * Creates a new provider setting the Oauth2 apiKey and apiSecret properties
42 | *
43 | * @param apiKey the Oauth2 api key
44 | * @param apiSecret the Oauth2 api secret
45 | * @param callback a valid url callback declared in oauth2 service provider
46 | * @since 0.1.0
47 | */
48 | public ScribeOauth2ServiceProvider(
49 | @Value("${oauth2.apikey:none}") String apiKey,
50 | @Value("${oauth2.apisecret:none}") String apiSecret,
51 | @Value("${oauth2.callback:none}") String callback) {
52 | this.apiKey = apiKey;
53 | this.apiSecret = apiSecret;
54 | this.callback = callback;
55 | }
56 |
57 | @Override
58 | public OAuth20Service get() {
59 | return new ServiceBuilder(this.apiKey)
60 | .apiSecret(this.apiSecret)
61 | .callback(this.callback)
62 | .build(GoogleApi20.instance());
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/src/main/java/patio/security/services/internal/ScribeOauthService.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Kaleidos Open Source SL
3 | *
4 | * This file is part of PATIO.
5 | * PATIO is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * PATIO is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with PATIO. If not, see
17 | */
18 | package patio.security.services.internal;
19 |
20 | import com.github.scribejava.core.model.OAuth2AccessToken;
21 | import com.github.scribejava.core.oauth.OAuth20Service;
22 | import java.io.IOException;
23 | import java.util.Optional;
24 | import java.util.concurrent.ExecutionException;
25 | import javax.inject.Inject;
26 | import javax.inject.Singleton;
27 | import org.slf4j.Logger;
28 | import org.slf4j.LoggerFactory;
29 | import patio.security.services.OauthService;
30 |
31 | /**
32 | * Default implementation of an Oauth2 service to get required access tokens from a previous step in
33 | * oauth2 authorization flow.
34 | *
35 | * @since 0.1.0
36 | */
37 | @Singleton
38 | public class ScribeOauthService implements OauthService {
39 |
40 | private static final Logger LOGGER = LoggerFactory.getLogger(ScribeOauthService.class);
41 | private final transient OAuth20Service oAuth20Service;
42 |
43 | /**
44 | * Default constructor
45 | *
46 | * @param oAuth20Service implementation used
47 | * @since 0.1.0
48 | */
49 | @Inject
50 | public ScribeOauthService(OAuth20Service oAuth20Service) {
51 | this.oAuth20Service = oAuth20Service;
52 | }
53 |
54 | @Override
55 | public Optional getAccessToken(String authorizationCode) {
56 | Optional accessToken = Optional.empty();
57 | try {
58 | accessToken =
59 | Optional.of(oAuth20Service.getAccessToken(authorizationCode))
60 | .map(OAuth2AccessToken::getAccessToken);
61 | } catch (IOException | InterruptedException | ExecutionException e) {
62 | LOGGER.error("error while getting access token from auth code");
63 | }
64 |
65 | return accessToken;
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/src/main/java/patio/user/graphql/UserBatchLoader.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Kaleidos Open Source SL
3 | *
4 | * This file is part of PATIO.
5 | * PATIO is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * PATIO is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with PATIO. If not, see
17 | */
18 | package patio.user.graphql;
19 |
20 | import java.util.List;
21 | import java.util.UUID;
22 | import java.util.concurrent.CompletableFuture;
23 | import java.util.concurrent.CompletionStage;
24 | import java.util.stream.Collectors;
25 | import javax.inject.Singleton;
26 | import org.dataloader.BatchLoader;
27 | import patio.infrastructure.utils.IterableUtils;
28 | import patio.user.domain.User;
29 | import patio.user.services.UserService;
30 | import patio.user.services.internal.DefaultUserService;
31 |
32 | /**
33 | * Loads a list of {@link User} by their ids
34 | *
35 | * @since 0.1.0
36 | */
37 | @Singleton
38 | public class UserBatchLoader implements BatchLoader {
39 |
40 | private final transient UserService userService;
41 |
42 | /**
43 | * Initializes the data loader with a {@link DefaultUserService}
44 | *
45 | * @param userService required to retrieve users
46 | * @since 0.1.0
47 | */
48 | public UserBatchLoader(UserService userService) {
49 | this.userService = userService;
50 | }
51 |
52 | @Override
53 | public CompletionStage> load(List keys) {
54 | List userList =
55 | IterableUtils.iterableToStream(userService.listUsersByIds(keys))
56 | .collect(Collectors.toList());
57 | return CompletableFuture.supplyAsync(() -> userList);
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/src/main/java/patio/user/repositories/UserRepository.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Kaleidos Open Source SL
3 | *
4 | * This file is part of PATIO.
5 | * PATIO is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * PATIO is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with PATIO. If not, see
17 | */
18 | package patio.user.repositories;
19 |
20 | import io.micronaut.data.repository.PageableRepository;
21 | import java.util.List;
22 | import java.util.Optional;
23 | import java.util.UUID;
24 | import patio.group.domain.Group;
25 | import patio.user.domain.User;
26 |
27 | /** All database actions related to {@link User} entity */
28 | public interface UserRepository extends PageableRepository {
29 |
30 | /**
31 | * Gets a list of {@link User} instances by their ids sorted by these ids
32 | *
33 | * @param ids list of ids of the {@link User} instances to get
34 | * @return a list of {@link User} instances
35 | */
36 | List findAllByIdInList(List ids);
37 |
38 | /**
39 | * Finds all users of a given {@link Group}
40 | *
41 | * @param group the {@link Group} the users belong to
42 | * @return a list of groups users {@link User}
43 | */
44 | Iterable findAllByGroup(Group group);
45 |
46 | /**
47 | * Tries to find a given user in the database and if it's not there, then the {@link User} is
48 | * persisted
49 | *
50 | * @param user instance of the user to find/persist
51 | * @return the persisted instance of {@link User}
52 | */
53 | Optional findByEmailOrCreate(User user);
54 |
55 | /**
56 | * Gets a persisted {@link User} by its email
57 | *
58 | * @param email the user's email
59 | * @return an {@link Optional} of the {@link User}
60 | */
61 | Optional findByEmail(String email);
62 |
63 | /**
64 | * Gets a persisted {@link User} by its OTP
65 | *
66 | * @param otpCode the user's OTP code
67 | * @return an {@link Optional} of the {@link User}
68 | */
69 | Optional findByOtp(String otpCode);
70 | }
71 |
--------------------------------------------------------------------------------
/src/main/java/patio/user/repositories/internal/MicroUserRepository.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Kaleidos Open Source SL
3 | *
4 | * This file is part of PATIO.
5 | * PATIO is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * PATIO is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with PATIO. If not, see
17 | */
18 | package patio.user.repositories.internal;
19 |
20 | import io.micronaut.data.annotation.Repository;
21 | import java.util.Optional;
22 | import javax.persistence.EntityManager;
23 | import patio.group.domain.Group;
24 | import patio.group.domain.UserGroup;
25 | import patio.infrastructure.persistence.MicroBaseRepository;
26 | import patio.user.domain.User;
27 | import patio.user.repositories.UserRepository;
28 |
29 | /** Persistence implementation access for {@link User} */
30 | @Repository
31 | public abstract class MicroUserRepository extends MicroBaseRepository implements UserRepository {
32 |
33 | /**
34 | * Initializes repository with {@link EntityManager}
35 | *
36 | * @param entityManager persistence {@link EntityManager} instance
37 | */
38 | public MicroUserRepository(EntityManager entityManager) {
39 | super(entityManager);
40 | }
41 |
42 | @Override
43 | public Iterable findAllByGroup(Group group) {
44 | var builder = getEntityManager().getCriteriaBuilder();
45 | var query = builder.createQuery(User.class);
46 | var root = query.from(UserGroup.class);
47 | var select = query.select(root.get("user")).where(builder.equal(root.get("group"), group));
48 |
49 | return getEntityManager().createQuery(select).getResultList();
50 | }
51 |
52 | @Override
53 | public Optional findByEmailOrCreate(User user) {
54 | return Optional.ofNullable(user.getEmail())
55 | .flatMap(this::findByEmail)
56 | .or(() -> Optional.of(save(user)));
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/src/main/java/patio/user/services/UserService.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Kaleidos Open Source SL
3 | *
4 | * This file is part of PATIO.
5 | * PATIO is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * PATIO is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with PATIO. If not, see
17 | */
18 | package patio.user.services;
19 |
20 | import java.util.List;
21 | import java.util.Optional;
22 | import java.util.UUID;
23 | import patio.user.domain.User;
24 |
25 | /**
26 | * Business logic contracts regarding {@link User}
27 | *
28 | * @since 0.1.0
29 | */
30 | public interface UserService {
31 |
32 | /**
33 | * Fetches the list of available users in the system
34 | *
35 | * @return a list of {@link User} instances
36 | * @since 0.1.0
37 | */
38 | Iterable listUsers();
39 |
40 | /**
41 | * Get the specified user
42 | *
43 | * @param id user identifier
44 | * @return The requested {@link User}
45 | * @since 0.1.0
46 | */
47 | Optional getUser(UUID id);
48 |
49 | /**
50 | * Listing users by their ids. It's mainly used for batching purposes in GraphQL calls
51 | *
52 | * @param ids {@link User}s ids
53 | * @return a list of {@link User} instances
54 | * @since 0.1.0
55 | */
56 | Iterable listUsersByIds(List ids);
57 | }
58 |
--------------------------------------------------------------------------------
/src/main/java/patio/user/services/internal/DefaultUserService.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Kaleidos Open Source SL
3 | *
4 | * This file is part of PATIO.
5 | * PATIO is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * PATIO is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with PATIO. If not, see
17 | */
18 | package patio.user.services.internal;
19 |
20 | import java.util.Comparator;
21 | import java.util.List;
22 | import java.util.Optional;
23 | import java.util.UUID;
24 | import java.util.stream.Collectors;
25 | import javax.inject.Singleton;
26 | import javax.transaction.Transactional;
27 | import patio.user.domain.User;
28 | import patio.user.repositories.UserRepository;
29 | import patio.user.services.UserService;
30 |
31 | /**
32 | * Business logic regarding {@link User} domain
33 | *
34 | * @since 0.1.0
35 | */
36 | @Singleton
37 | @Transactional
38 | public class DefaultUserService implements UserService {
39 |
40 | private final transient UserRepository userRepository;
41 |
42 | /**
43 | * Initializes service by using the database repositories
44 | *
45 | * @param userRepository an instance of {@link UserRepository}
46 | * @since 0.1.0
47 | */
48 | public DefaultUserService(UserRepository userRepository) {
49 | this.userRepository = userRepository;
50 | }
51 |
52 | @Override
53 | public Iterable listUsers() {
54 | return userRepository.findAll();
55 | }
56 |
57 | @Override
58 | public Optional getUser(UUID id) {
59 | return userRepository.findById(id);
60 | }
61 |
62 | @Override
63 | public Iterable listUsersByIds(List ids) {
64 | Comparator comparator = Comparator.comparing((User user) -> ids.indexOf(user.getId()));
65 |
66 | return userRepository.findAllByIdInList(ids).stream()
67 | .sorted(comparator)
68 | .collect(Collectors.toList());
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/src/main/java/patio/voting/domain/VoteByMoodDTO.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Kaleidos Open Source SL
3 | *
4 | * This file is part of PATIO.
5 | * PATIO is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * PATIO is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with PATIO. If not, see
17 | */
18 | package patio.voting.domain;
19 |
20 | /**
21 | * Represents the aggregation count of mood types in a given voting
22 | *
23 | * @see Voting
24 | */
25 | public class VoteByMoodDTO {
26 |
27 | private final int mood;
28 | private final long count;
29 |
30 | /**
31 | * Initializes a new {@link VoteByMoodDTO}
32 | *
33 | * @param count how many people did vote this mood
34 | * @param mood the type of mood
35 | */
36 | public VoteByMoodDTO(long count, int mood) {
37 | this.mood = mood;
38 | this.count = count;
39 | }
40 |
41 | /**
42 | * Returns the type of mood
43 | *
44 | * @return the type of mood
45 | */
46 | public int getMood() {
47 | return mood;
48 | }
49 |
50 | /**
51 | * Returns how many people did vote a given type of mood
52 | *
53 | * @return how many people did vote a given type of mood
54 | */
55 | public long getCount() {
56 | return count;
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/src/main/java/patio/voting/graphql/DidIVoteInput.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Kaleidos Open Source SL
3 | *
4 | * This file is part of PATIO.
5 | * PATIO is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * PATIO is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with PATIO. If not, see
17 | */
18 | package patio.voting.graphql;
19 |
20 | import java.util.UUID;
21 | import patio.user.domain.User;
22 |
23 | /**
24 | * Input to know whether a user's voted in a given voting or not
25 | *
26 | * @see VotingFetcher
27 | */
28 | public class DidIVoteInput {
29 | private final User user;
30 | private final UUID votingId;
31 |
32 | /**
33 | * Initializes with the user and voting to check against
34 | *
35 | * @param user the current {@link User}
36 | * @param votingId voting's id to check against
37 | */
38 | public DidIVoteInput(User user, UUID votingId) {
39 | this.user = user;
40 | this.votingId = votingId;
41 | }
42 |
43 | /**
44 | * Returns the user to check
45 | *
46 | * @return the user to check
47 | */
48 | public User getUser() {
49 | return user;
50 | }
51 |
52 | /**
53 | * Returns the voting's id to check against
54 | *
55 | * @return the voting's id to check against
56 | */
57 | public UUID getVotingId() {
58 | return votingId;
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/src/main/java/patio/voting/graphql/GetLastVotingInput.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Kaleidos Open Source SL
3 | *
4 | * This file is part of PATIO.
5 | * PATIO is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * PATIO is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with PATIO. If not, see
17 | */
18 | package patio.voting.graphql;
19 |
20 | import java.util.UUID;
21 | import patio.common.domain.utils.Builder;
22 | import patio.voting.domain.Voting;
23 |
24 | /**
25 | * Input to get the last voting for a group
26 | *
27 | * @since 0.1.0
28 | */
29 | public class GetLastVotingInput {
30 | private UUID groupId;
31 | private UUID currentUserId;
32 |
33 | /**
34 | * Creates a new fluent builder to build instances of type {@link Voting}
35 | *
36 | * @return an instance of the voting builder
37 | * @since 0.1.0
38 | */
39 | public static Builder newBuilder() {
40 | return Builder.build(GetLastVotingInput::new);
41 | }
42 |
43 | /**
44 | * Gets group id.
45 | *
46 | * @return the group id
47 | */
48 | public UUID getGroupId() {
49 | return groupId;
50 | }
51 |
52 | /**
53 | * Gets the current user.
54 | *
55 | * @return the current user
56 | */
57 | public UUID getCurrentUserId() {
58 | return currentUserId;
59 | }
60 |
61 | /**
62 | * Sets the group id
63 | *
64 | * @param groupId the group id
65 | * @since 0.1.0
66 | */
67 | public void setGroupId(UUID groupId) {
68 | this.groupId = groupId;
69 | }
70 |
71 | /**
72 | * Sets the group id
73 | *
74 | * @param currentUserId the group id
75 | * @since 0.1.0
76 | */
77 | public void setCurrentUserId(UUID currentUserId) {
78 | this.currentUserId = currentUserId;
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/src/main/java/patio/voting/graphql/GetStatsByGroupInput.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Kaleidos Open Source SL
3 | *
4 | * This file is part of PATIO.
5 | * PATIO is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * PATIO is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with PATIO. If not, see
17 | */
18 | package patio.voting.graphql;
19 |
20 | import java.util.UUID;
21 | import patio.common.domain.utils.Builder;
22 |
23 | /**
24 | * Class containing the input to recover the statistics given a group
25 | *
26 | * @since 0.1.0
27 | */
28 | public class GetStatsByGroupInput {
29 |
30 | private UUID groupId;
31 |
32 | /**
33 | * Creates a new builder to create a new instance of type {@link GetStatsByGroupInput}
34 | *
35 | * @return an instance of the builder to build instances of type GetStatsByGroupInput
36 | * @since 0.1.0
37 | */
38 | public static Builder newBuilder() {
39 | return Builder.build(GetStatsByGroupInput::new);
40 | }
41 |
42 | /**
43 | * Returns the id of the group
44 | *
45 | * @return the id of the group
46 | * @since 0.1.0
47 | */
48 | public UUID getGroupId() {
49 | return groupId;
50 | }
51 |
52 | /**
53 | * Sets the group id
54 | *
55 | * @param groupId of type {@link UUID} to get its stats
56 | */
57 | public void setGroupId(UUID groupId) {
58 | this.groupId = groupId;
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/src/main/java/patio/voting/graphql/VotingStatsFetcher.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Kaleidos Open Source SL
3 | *
4 | * This file is part of PATIO.
5 | * PATIO is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * PATIO is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with PATIO. If not, see
17 | */
18 | package patio.voting.graphql;
19 |
20 | import static patio.common.graphql.ArgumentUtils.extractOffsetPaginationFrom;
21 |
22 | import graphql.schema.DataFetchingEnvironment;
23 | import javax.inject.Singleton;
24 | import patio.common.domain.utils.OffsetPaginationRequest;
25 | import patio.common.domain.utils.OffsetPaginationResult;
26 | import patio.group.domain.Group;
27 | import patio.voting.domain.Vote;
28 | import patio.voting.domain.VotingStats;
29 | import patio.voting.services.VotingStatsService;
30 |
31 | /**
32 | * All related GraphQL operations over the {@link Group} domain
33 | *
34 | * @since 0.1.0
35 | */
36 | @Singleton
37 | public class VotingStatsFetcher {
38 |
39 | /**
40 | * Instance handling the business logic
41 | *
42 | * @since 0.1.0
43 | */
44 | private final transient VotingStatsService service;
45 |
46 | /**
47 | * Constructor initializing the access to the business logic
48 | *
49 | * @param service class handling the logic over groups
50 | * @since 0.1.0
51 | */
52 | public VotingStatsFetcher(VotingStatsService service) {
53 | this.service = service;
54 | }
55 |
56 | /**
57 | * Fetches the voting statistics for a group between a time interval
58 | *
59 | * @param env GraphQL execution environment
60 | * @return a list of available {@link Vote}
61 | * @since 0.1.0
62 | */
63 | public OffsetPaginationResult getVotingStatsByGroup(DataFetchingEnvironment env) {
64 | GetStatsByGroupInput input = VotingStatsFetcherUtils.createGetStatsByGroupInput(env);
65 | OffsetPaginationRequest pagination = extractOffsetPaginationFrom(env);
66 |
67 | return service.getVotingStatsByGroup(input, pagination);
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/src/main/java/patio/voting/graphql/VotingStatsFetcherUtils.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Kaleidos Open Source SL
3 | *
4 | * This file is part of PATIO.
5 | * PATIO is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * PATIO is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with PATIO. If not, see
17 | */
18 | package patio.voting.graphql;
19 |
20 | import graphql.schema.DataFetchingEnvironment;
21 | import java.util.UUID;
22 |
23 | /**
24 | * Contains functions to build domain inputs from the underlying {@link DataFetchingEnvironment}
25 | * coming from the GraphQL engine execution. This class is meant to be used only for the {@link
26 | * VotingFetcher} instance and related tests.
27 | *
28 | * @since 0.1.0
29 | */
30 | final class VotingStatsFetcherUtils {
31 |
32 | private VotingStatsFetcherUtils() {
33 | /* empty */
34 | }
35 |
36 | /**
37 | * Creates a {@link GetStatsByGroupInput}
38 | *
39 | * @param environment the GraphQL {@link DataFetchingEnvironment}
40 | * @return an instance of type {@link ListVotingsGroupInput}
41 | * @since 0.1.0
42 | */
43 | /* default */ static GetStatsByGroupInput createGetStatsByGroupInput(
44 | DataFetchingEnvironment environment) {
45 | UUID groupId = environment.getArgument("groupId");
46 |
47 | return GetStatsByGroupInput.newBuilder().with(i -> i.setGroupId(groupId)).build();
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/main/java/patio/voting/graphql/VotingStatsInput.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Kaleidos Open Source SL
3 | *
4 | * This file is part of PATIO.
5 | * PATIO is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * PATIO is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with PATIO. If not, see
17 | */
18 | package patio.voting.graphql;
19 |
20 | import java.util.UUID;
21 | import patio.common.domain.utils.Builder;
22 |
23 | /**
24 | * Input object to request for voting stats
25 | *
26 | * @see patio.voting.domain.Voting
27 | */
28 | public class VotingStatsInput {
29 | private UUID votingId;
30 |
31 | /**
32 | * Returns the id of the voting
33 | *
34 | * @return the id of the user
35 | * @since 0.1.0
36 | */
37 | public UUID getVotingId() {
38 | return votingId;
39 | }
40 |
41 | /**
42 | * Sets voting id
43 | *
44 | * @param votingId the voting id
45 | */
46 | public void setVotingId(UUID votingId) {
47 | this.votingId = votingId;
48 | }
49 |
50 | /**
51 | * Returns true if there is a voting id false otherwise
52 | *
53 | * @return true if there is a voting id false otherwise
54 | */
55 | public boolean hasVoting() {
56 | return this.votingId != null;
57 | }
58 |
59 | /**
60 | * Creates a builder to build instances of type {@link VotingStatsInput}
61 | *
62 | * @return a {@link Builder} that creates instances of type {@link VotingStatsInput}
63 | * @since 0.1.0
64 | */
65 | public static Builder builder() {
66 | return Builder.build(VotingStatsInput::new);
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/src/main/java/patio/voting/repositories/VotingStatsRepository.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Kaleidos Open Source SL
3 | *
4 | * This file is part of PATIO.
5 | * PATIO is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * PATIO is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with PATIO. If not, see
17 | */
18 | package patio.voting.repositories;
19 |
20 | import io.micronaut.data.annotation.Query;
21 | import io.micronaut.data.repository.PageableRepository;
22 | import java.time.OffsetDateTime;
23 | import java.util.Optional;
24 | import java.util.UUID;
25 | import patio.common.domain.utils.OffsetPaginationRequest;
26 | import patio.common.domain.utils.OffsetPaginationResult;
27 | import patio.group.domain.Group;
28 | import patio.voting.domain.VotingStats;
29 |
30 | /**
31 | * Handles database operations over {@link VotingStats} instances
32 | *
33 | * @since 0.1.0
34 | */
35 | public interface VotingStatsRepository extends PageableRepository {
36 |
37 | /**
38 | * Gets the moving average for a {@link Group}
39 | *
40 | * @param group the group to get its moving average from
41 | * @param interval the interval from which the average is referred to
42 | * @return the moving average
43 | */
44 | @Query(
45 | "SELECT AVG(vs.average) "
46 | + "FROM Voting v JOIN v.stats vs "
47 | + "WHERE v.group = :group "
48 | + "AND v.createdAtDateTime > :interval "
49 | + "AND vs.average is not null")
50 | Optional findMovingAverageByGroup(Group group, OffsetDateTime interval);
51 |
52 | /**
53 | * Finds all statistics for a given group between a time interval
54 | *
55 | * @param group the id of the group to get its statistics from
56 | * @param paginationRequest pagination information
57 | * @return a paginated result of {@link VotingStats} instances from the given {@link Group}
58 | */
59 | OffsetPaginationResult findStatsByGroup(
60 | Group group, OffsetPaginationRequest paginationRequest);
61 | }
62 |
--------------------------------------------------------------------------------
/src/main/java/patio/voting/repositories/internal/MicroVoteRepository.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Kaleidos Open Source SL
3 | *
4 | * This file is part of PATIO.
5 | * PATIO is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * PATIO is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with PATIO. If not, see
17 | */
18 | package patio.voting.repositories.internal;
19 |
20 | import io.micronaut.data.annotation.Repository;
21 | import javax.persistence.EntityManager;
22 | import patio.infrastructure.persistence.MicroBaseRepository;
23 | import patio.voting.domain.Vote;
24 | import patio.voting.repositories.VoteRepository;
25 |
26 | /** Persistence implementation access for {@link Vote} */
27 | @Repository
28 | public abstract class MicroVoteRepository extends MicroBaseRepository implements VoteRepository {
29 |
30 | /**
31 | * Initializes repository with {@link EntityManager}
32 | *
33 | * @param entityManager persistence {@link EntityManager} instance
34 | */
35 | public MicroVoteRepository(EntityManager entityManager) {
36 | super(entityManager);
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/main/java/patio/voting/repositories/internal/MicroVotingRepository.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Kaleidos Open Source SL
3 | *
4 | * This file is part of PATIO.
5 | * PATIO is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * PATIO is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with PATIO. If not, see
17 | */
18 | package patio.voting.repositories.internal;
19 |
20 | import io.micronaut.data.annotation.Repository;
21 | import java.math.BigDecimal;
22 | import java.util.Optional;
23 | import javax.persistence.EntityManager;
24 | import patio.infrastructure.persistence.MicroBaseRepository;
25 | import patio.voting.domain.Vote;
26 | import patio.voting.domain.Voting;
27 | import patio.voting.repositories.VotingRepository;
28 |
29 | /** Persistence implementation access for {@link Voting} and {@link Vote} */
30 | @Repository
31 | public abstract class MicroVotingRepository extends MicroBaseRepository
32 | implements VotingRepository {
33 |
34 | /**
35 | * Initializes repository with {@link EntityManager}
36 | *
37 | * @param entityManager persistence {@link EntityManager} instance
38 | */
39 | public MicroVotingRepository(EntityManager entityManager) {
40 | super(entityManager);
41 | }
42 |
43 | @Override
44 | public Optional getAvgVoteCountByVoting(Voting voting) {
45 | var subquery =
46 | "select "
47 | + "count(vo.*) as counter, "
48 | + "v.id "
49 | + "from voting v join vote vo on "
50 | + "vo.voting_id = v.id "
51 | + "join groups g on "
52 | + "v.group_id = g.id "
53 | + "where g.id = ? "
54 | + "group by v.id";
55 |
56 | var query = " select round(avg(x.counter)) from (" + subquery + ") x";
57 | var nativeQuery = getEntityManager().createNativeQuery(query);
58 |
59 | BigDecimal bigDecimal =
60 | (BigDecimal) nativeQuery.setParameter(1, voting.getGroup().getId()).getSingleResult();
61 |
62 | return Optional.ofNullable(bigDecimal).map(BigDecimal::longValue);
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/src/main/java/patio/voting/services/VotingScheduling.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Kaleidos Open Source SL
3 | *
4 | * This file is part of PATIO.
5 | * PATIO is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * PATIO is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with PATIO. If not, see
17 | */
18 | package patio.voting.services;
19 |
20 | /**
21 | * Scheduled tasks
22 | *
23 | * @since 0.1.0
24 | */
25 | public interface VotingScheduling {
26 |
27 | /**
28 | * Checks whether a new voting should be created, and if so, creates the new {@link
29 | * patio.voting.domain.Voting} instance and sends a notification to all members of that voting's
30 | * group
31 | *
32 | * @since 0.1.0
33 | */
34 | void scheduleVoting();
35 | }
36 |
--------------------------------------------------------------------------------
/src/main/java/patio/voting/services/internal/UserOnlyVotedOnce.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Kaleidos Open Source SL
3 | *
4 | * This file is part of PATIO.
5 | * PATIO is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * PATIO is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with PATIO. If not, see
17 | */
18 | package patio.voting.services.internal;
19 |
20 | import static patio.common.domain.utils.Check.checkIsTrue;
21 |
22 | import java.util.Optional;
23 | import patio.common.domain.utils.Check;
24 | import patio.common.domain.utils.Result;
25 | import patio.infrastructure.utils.ErrorConstants;
26 | import patio.infrastructure.utils.OptionalUtils;
27 | import patio.user.domain.User;
28 | import patio.voting.domain.Vote;
29 | import patio.voting.domain.Voting;
30 | import patio.voting.repositories.VoteRepository;
31 |
32 | /**
33 | * Checks that a given user has not voted already.
34 | *
35 | * @since 0.1.0
36 | */
37 | public class UserOnlyVotedOnce {
38 |
39 | private final transient VoteRepository repository;
40 |
41 | /**
42 | * Constructor receiving the required repository to be able to query the underlying datastore
43 | *
44 | * @param repository an instance of {@link VoteRepository}
45 | * @since 0.1.0
46 | */
47 | public UserOnlyVotedOnce(VoteRepository repository) {
48 | this.repository = repository;
49 | }
50 |
51 | /**
52 | * Checks that the user has not voted already or it's an anonymous user
53 | *
54 | * @param user the user that could have created the vote
55 | * @param voting the voting the vote belongs to
56 | * @return a failing {@link Result} if the user already voted
57 | * @since 0.1.0
58 | */
59 | public Check check(Optional user, Optional voting) {
60 | Optional voteFound =
61 | OptionalUtils.combine(user, voting).flatmapInto(repository::findByCreatedByAndVoting);
62 |
63 | return checkIsTrue(user.isEmpty() || voteFound.isEmpty(), ErrorConstants.USER_ALREADY_VOTE);
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/src/main/java/patio/voting/services/internal/VoteAnonymousAllowedInGroup.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Kaleidos Open Source SL
3 | *
4 | * This file is part of PATIO.
5 | * PATIO is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * PATIO is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with PATIO. If not, see
17 | */
18 | package patio.voting.services.internal;
19 |
20 | import static patio.common.domain.utils.Check.checkIsTrue;
21 | import static patio.infrastructure.utils.ErrorConstants.VOTE_CANT_BE_ANONYMOUS;
22 |
23 | import patio.common.domain.utils.Check;
24 | import patio.common.domain.utils.Result;
25 |
26 | /**
27 | * Checker testing whether the anonymous vote is allowed or not
28 | *
29 | * @since 0.1.0
30 | */
31 | public class VoteAnonymousAllowedInGroup {
32 |
33 | /**
34 | * Returns a failing {@link Result} if the vote is anonymous and the group doesn't allow that type
35 | * of vote. Returns false otherwise.
36 | *
37 | * @param isAnonymousVote whether the vote is anonymous or not
38 | * @param groupIsAnonymous whether the group allows anonymous voting or not
39 | * @return an instance of {@link Result} with an error if the condition hasn't been met
40 | * @since 0.1.0
41 | */
42 | public Check check(boolean isAnonymousVote, boolean groupIsAnonymous) {
43 | return checkIsTrue(!isAnonymousVote || groupIsAnonymous, VOTE_CANT_BE_ANONYMOUS);
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/main/java/patio/voting/services/internal/VoteScoreBoundaries.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Kaleidos Open Source SL
3 | *
4 | * This file is part of PATIO.
5 | * PATIO is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * PATIO is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with PATIO. If not, see
17 | */
18 | package patio.voting.services.internal;
19 |
20 | import static patio.common.domain.utils.Check.checkIsTrue;
21 |
22 | import patio.common.domain.utils.Check;
23 | import patio.common.domain.utils.Result;
24 | import patio.infrastructure.utils.ErrorConstants;
25 |
26 | /**
27 | * Checks that a given vote's score is within the expected values
28 | *
29 | * @since 0.1.0
30 | */
31 | public class VoteScoreBoundaries {
32 |
33 | /**
34 | * Checks if a given vote matches the score rules
35 | *
36 | * @param score the vote's score
37 | * @return a failing {@link Result} if the score doesn't match the rule
38 | */
39 | public Check check(Integer score) {
40 | return checkIsTrue(score != null && score >= 1 && score <= 5, ErrorConstants.SCORE_IS_INVALID);
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/main/java/patio/voting/services/internal/VotingHasExpired.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Kaleidos Open Source SL
3 | *
4 | * This file is part of PATIO.
5 | * PATIO is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * PATIO is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with PATIO. If not, see
17 | */
18 | package patio.voting.services.internal;
19 |
20 | import static patio.common.domain.utils.Check.checkIsFalse;
21 | import static patio.infrastructure.utils.ErrorConstants.VOTING_HAS_EXPIRED;
22 |
23 | import java.util.Optional;
24 | import patio.common.domain.utils.Check;
25 | import patio.common.domain.utils.Result;
26 | import patio.voting.domain.Voting;
27 |
28 | /**
29 | * Checks whether a voting has expired or not
30 | *
31 | * @since 0.1.0
32 | */
33 | public class VotingHasExpired {
34 |
35 | /**
36 | * Checks if the voting has expired or not
37 | *
38 | * @param voting the voting
39 | * @return a failing {@link Result} if the voting has expired
40 | */
41 | public Check check(Optional voting) {
42 | boolean hasExpired = voting.map(Voting::getExpired).orElse(true);
43 |
44 | return checkIsFalse(hasExpired, VOTING_HAS_EXPIRED);
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/src/main/resources/logback.xml:
--------------------------------------------------------------------------------
1 |
20 |
21 |
22 |
23 |
25 |
26 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
27 |
28 |
29 |
30 |
34 |
39 |
40 |
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/src/main/resources/messages.properties:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright (C) 2019 Kaleidos Open Source SL
3 | #
4 | # This file is part of PATIO.
5 | # PATIO is free software: you can redistribute it and/or modify
6 | # it under the terms of the GNU General Public License as published by
7 | # the Free Software Foundation, either version 3 of the License, or
8 | # (at your option) any later version.
9 | #
10 | # PATIO is distributed in the hope that it will be useful,
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | # GNU General Public License for more details.
14 | #
15 | # You should have received a copy of the GNU General Public License
16 | # along with PATIO. If not, see
17 | #
18 |
19 | voting.greetings=Hello {username}!
20 | voting.today=Today is {today}.
21 | voting.question=How do you feel today at {groupName}?
22 | voting.thanks=Thanks!
23 | voting.disclaimer=You are receiving this email because you are in a patio team.
24 | voting.bodyTemplate=templates/voting.pug
25 | voting.subject=Today is {today}. How do you feel today at {groupName} ?
26 |
27 | resetPassword.subject=Reset your password here
28 | resetPassword.greetings=Hi {username}!
29 | resetPassword.main=We received a password reset request for your patio account. To reset your password simply click the following link and follow the instructions.
30 | resetPassword.notRequested=If you didn’t request a new password, you can safely delete this email.
31 | resetPassword.thanks=Regards,
32 | resetPassword.patioTeam=patio.team
33 | resetPassword.bodyTemplate=templates/resetPassword.pug
--------------------------------------------------------------------------------
/src/main/resources/messages_es.properties:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright (C) 2019 Kaleidos Open Source SL
3 | #
4 | # This file is part of PATIO.
5 | # PATIO is free software: you can redistribute it and/or modify
6 | # it under the terms of the GNU General Public License as published by
7 | # the Free Software Foundation, either version 3 of the License, or
8 | # (at your option) any later version.
9 | #
10 | # PATIO is distributed in the hope that it will be useful,
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | # GNU General Public License for more details.
14 | #
15 | # You should have received a copy of the GNU General Public License
16 | # along with PATIO. If not, see
17 | #
18 |
19 | voting.greetings=¡Hola, {username}!
20 | voting.today=Hoy es {today}.
21 | voting.question=¿Estás feliz en {groupName}?
22 | voting.thanks=¡Gracias por votar!
23 | voting.disclaimer=Recibes este correo porque formas parte de un equipo de patio.
24 | voting.bodyTemplate=templates/voting.pug
25 | voting.subject=Hoy es {today}. ¿Estás feliz en {groupName}?
26 |
27 | resetPassword.subject=Cambia aquí tu contraseña
28 | resetPassword.greetings=¡Hola, {username}!
29 | resetPassword.main=Hemos recibido una petición de reinicio de contraseña para tu cuenta de patio. Sigue las instrucciones del siguiente enlace para cambiarla.
30 | resetPassword.notRequested=Si no solicitaste una nueva constraseña, por favor, ignora este correo.
31 | resetPassword.thanks=Un saludo,
32 | resetPassword.patioTeam=patio.team
33 | resetPassword.bodyTemplate=templates/resetPassword.pug
--------------------------------------------------------------------------------
/src/main/resources/messages_fr.properties:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright (C) 2019 Kaleidos Open Source SL
3 | #
4 | # This file is part of PATIO.
5 | # PATIO is free software: you can redistribute it and/or modify
6 | # it under the terms of the GNU General Public License as published by
7 | # the Free Software Foundation, either version 3 of the License, or
8 | # (at your option) any later version.
9 | #
10 | # PATIO is distributed in the hope that it will be useful,
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | # GNU General Public License for more details.
14 | #
15 | # You should have received a copy of the GNU General Public License
16 | # along with PATIO. If not, see
17 | #
18 |
19 | voting.greetings=Bonjour {username}!
20 | voting.today=Aujourd'hui nous sommes {today}
21 | voting.question=Êtes-vous heureux dans {groupName}?
22 | voting.thanks=Merci d'avoir voté!
23 | voting.disclaimer=Vous recevez cet email car vous fais partie un équipement de Patio..
24 | voting.bodyTemplate=templates/voting.pug
25 | voting.subject=Aujourd'hui nous sommes {today}. Êtes-vous heureux dans {groupName} ?
26 |
27 | resetPassword.subject=Cliquer ici pour réinitialiser votre mot de passe
28 | resetPassword.greetings=Bonjour {username}!
29 | resetPassword.main=Nous avons reçu une demande de réinitialisation de mot de passe pour votre compte. Suivez les instructions sur le lien suivant pour changer votre mot de passe.
30 | resetPassword.notRequested=Si vous n'avez pas demandé de nouveau mot de passe, vous pouvez supprimer cet e-mail en toute sécurité.
31 | resetPassword.thanks=Au revoir,
32 | resetPassword.patioTeam=patio.team
33 | resetPassword.bodyTemplate=templates/resetPassword.pug
--------------------------------------------------------------------------------
/src/main/resources/migrations/V10__remove_visible_member_list.sql:
--------------------------------------------------------------------------------
1 | --
2 | -- Copyright (C) 2019 Kaleidos Open Source SL
3 | --
4 | -- This file is part of PATIO.
5 | -- PATIO is free software: you can redistribute it and/or modify
6 | -- it under the terms of the GNU General Public License as published by
7 | -- the Free Software Foundation, either version 3 of the License, or
8 | -- (at your option) any later version.
9 | --
10 | -- PATIO is distributed in the hope that it will be useful,
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | -- GNU General Public License for more details.
14 | --
15 | -- You should have received a copy of the GNU General Public License
16 | -- along with PATIO. If not, see
17 | --
18 |
19 | ALTER TABLE groups DROP COLUMN visible_member_list;
--------------------------------------------------------------------------------
/src/main/resources/migrations/V11__add_expired_to_voting.sql:
--------------------------------------------------------------------------------
1 | --
2 | -- Copyright (C) 2019 Kaleidos Open Source SL
3 | --
4 | -- This file is part of PATIO.
5 | -- PATIO is free software: you can redistribute it and/or modify
6 | -- it under the terms of the GNU General Public License as published by
7 | -- the Free Software Foundation, either version 3 of the License, or
8 | -- (at your option) any later version.
9 | --
10 | -- PATIO is distributed in the hope that it will be useful,
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | -- GNU General Public License for more details.
14 | --
15 | -- You should have received a copy of the GNU General Public License
16 | -- along with PATIO. If not, see
17 | --
18 |
19 | ALTER TABLE voting ADD COLUMN IF NOT EXISTS expired boolean NOT NULL DEFAULT false;
--------------------------------------------------------------------------------
/src/main/resources/migrations/V12__set_expired_to_existing_votings.sql:
--------------------------------------------------------------------------------
1 | --
2 | -- Copyright (C) 2019 Kaleidos Open Source SL
3 | --
4 | -- This file is part of PATIO.
5 | -- PATIO is free software: you can redistribute it and/or modify
6 | -- it under the terms of the GNU General Public License as published by
7 | -- the Free Software Foundation, either version 3 of the License, or
8 | -- (at your option) any later version.
9 | --
10 | -- PATIO is distributed in the hope that it will be useful,
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | -- GNU General Public License for more details.
14 | --
15 | -- You should have received a copy of the GNU General Public License
16 | -- along with PATIO. If not, see
17 | --
18 |
19 | UPDATE voting SET expired = TRUE;
--------------------------------------------------------------------------------
/src/main/resources/migrations/V13__add_voting_duration_to_group.sql:
--------------------------------------------------------------------------------
1 | --
2 | -- Copyright (C) 2019 Kaleidos Open Source SL
3 | --
4 | -- This file is part of PATIO.
5 | -- PATIO is free software: you can redistribute it and/or modify
6 | -- it under the terms of the GNU General Public License as published by
7 | -- the Free Software Foundation, either version 3 of the License, or
8 | -- (at your option) any later version.
9 | --
10 | -- PATIO is distributed in the hope that it will be useful,
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | -- GNU General Public License for more details.
14 | --
15 | -- You should have received a copy of the GNU General Public License
16 | -- along with PATIO. If not, see
17 | --
18 |
19 | ALTER TABLE groups ADD COLUMN IF NOT EXISTS voting_duration int NULL;
20 |
--------------------------------------------------------------------------------
/src/main/resources/migrations/V14__set_voting_duration_to_existing_groups.sql:
--------------------------------------------------------------------------------
1 | --
2 | -- Copyright (C) 2019 Kaleidos Open Source SL
3 | --
4 | -- This file is part of PATIO.
5 | -- PATIO is free software: you can redistribute it and/or modify
6 | -- it under the terms of the GNU General Public License as published by
7 | -- the Free Software Foundation, either version 3 of the License, or
8 | -- (at your option) any later version.
9 | --
10 | -- PATIO is distributed in the hope that it will be useful,
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | -- GNU General Public License for more details.
14 | --
15 | -- You should have received a copy of the GNU General Public License
16 | -- along with PATIO. If not, see
17 | --
18 |
19 | UPDATE groups SET voting_duration = 24;
20 |
21 | ALTER TABLE groups ALTER COLUMN voting_duration SET NOT NULL
22 |
--------------------------------------------------------------------------------
/src/main/resources/migrations/V1__initial_schema.sql:
--------------------------------------------------------------------------------
1 | --
2 | -- Copyright (C) 2019 Kaleidos Open Source SL
3 | --
4 | -- This file is part of PATIO.
5 | -- PATIO is free software: you can redistribute it and/or modify
6 | -- it under the terms of the GNU General Public License as published by
7 | -- the Free Software Foundation, either version 3 of the License, or
8 | -- (at your option) any later version.
9 | --
10 | -- PATIO is distributed in the hope that it will be useful,
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | -- GNU General Public License for more details.
14 | --
15 | -- You should have received a copy of the GNU General Public License
16 | -- along with PATIO. If not, see
17 | --
18 |
19 | CREATE TABLE IF NOT EXISTS groups (
20 | id UUID PRIMARY KEY,
21 | name varchar(200) NOT NULL,
22 | visible_member_list boolean NOT NULL DEFAULT false,
23 | anonymous_vote boolean NOT NULL DEFAULT false,
24 | voting_time time with time zone,
25 | voting_days varchar[]
26 | );
--------------------------------------------------------------------------------
/src/main/resources/migrations/V2__users.sql:
--------------------------------------------------------------------------------
1 | --
2 | -- Copyright (C) 2019 Kaleidos Open Source SL
3 | --
4 | -- This file is part of PATIO.
5 | -- PATIO is free software: you can redistribute it and/or modify
6 | -- it under the terms of the GNU General Public License as published by
7 | -- the Free Software Foundation, either version 3 of the License, or
8 | -- (at your option) any later version.
9 | --
10 | -- PATIO is distributed in the hope that it will be useful,
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | -- GNU General Public License for more details.
14 | --
15 | -- You should have received a copy of the GNU General Public License
16 | -- along with PATIO. If not, see
17 | --
18 |
19 | CREATE TABLE IF NOT EXISTS users (
20 | id UUID PRIMARY KEY,
21 | name varchar(200) NOT NULL,
22 | email varchar(200) NOT NULL,
23 | password varchar(200),
24 | otp varchar(200) NULL
25 | );
26 |
27 |
28 | CREATE TABLE IF NOT EXISTS users_groups (
29 | user_id UUID,
30 | group_id UUID,
31 | is_admin boolean NOT NULL DEFAULT false,
32 | CONSTRAINT PK_Users_Groups PRIMARY KEY (user_id, group_id),
33 | FOREIGN KEY (user_id) REFERENCES users(id),
34 | FOREIGN KEY (group_id) REFERENCES groups(id)
35 | );
--------------------------------------------------------------------------------
/src/main/resources/migrations/V3__voting.sql:
--------------------------------------------------------------------------------
1 | --
2 | -- Copyright (C) 2019 Kaleidos Open Source SL
3 | --
4 | -- This file is part of PATIO.
5 | -- PATIO is free software: you can redistribute it and/or modify
6 | -- it under the terms of the GNU General Public License as published by
7 | -- the Free Software Foundation, either version 3 of the License, or
8 | -- (at your option) any later version.
9 | --
10 | -- PATIO is distributed in the hope that it will be useful,
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | -- GNU General Public License for more details.
14 | --
15 | -- You should have received a copy of the GNU General Public License
16 | -- along with PATIO. If not, see
17 | --
18 |
19 | CREATE TABLE IF NOT EXISTS voting (
20 | id UUID PRIMARY KEY,
21 | group_id UUID NOT NULL,
22 | created_at timestamp with time zone NOT NULL,
23 | created_by UUID,
24 | average int,
25 | FOREIGN KEY (created_by) REFERENCES users(id),
26 | FOREIGN KEY (group_id) REFERENCES groups(id)
27 | );
28 |
29 | CREATE TABLE IF NOT EXISTS vote (
30 | id UUID PRIMARY KEY,
31 | voting_id UUID NOT NULL,
32 | created_by UUID,
33 | created_at timestamp with time zone NOT NULL,
34 | comment text,
35 | score int NOT NULL,
36 | FOREIGN KEY (created_by) REFERENCES users(id),
37 | FOREIGN KEY (voting_id) REFERENCES voting(id)
38 | );
--------------------------------------------------------------------------------
/src/main/resources/migrations/V4__add_otp_creation_date_to_users.sql:
--------------------------------------------------------------------------------
1 | --
2 | -- Copyright (C) 2019 Kaleidos Open Source SL
3 | --
4 | -- This file is part of PATIO.
5 | -- PATIO is free software: you can redistribute it and/or modify
6 | -- it under the terms of the GNU General Public License as published by
7 | -- the Free Software Foundation, either version 3 of the License, or
8 | -- (at your option) any later version.
9 | --
10 | -- PATIO is distributed in the hope that it will be useful,
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | -- GNU General Public License for more details.
14 | --
15 | -- You should have received a copy of the GNU General Public License
16 | -- along with PATIO. If not, see
17 | --
18 |
19 | ALTER TABLE users ADD COLUMN IF NOT EXISTS otp_creation_date timestamp with time zone NULL;
20 |
--------------------------------------------------------------------------------
/src/main/resources/migrations/V5__voting_average_to_float.sql:
--------------------------------------------------------------------------------
1 | --
2 | -- Copyright (C) 2019 Kaleidos Open Source SL
3 | --
4 | -- This file is part of PATIO.
5 | -- PATIO is free software: you can redistribute it and/or modify
6 | -- it under the terms of the GNU General Public License as published by
7 | -- the Free Software Foundation, either version 3 of the License, or
8 | -- (at your option) any later version.
9 | --
10 | -- PATIO is distributed in the hope that it will be useful,
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | -- GNU General Public License for more details.
14 | --
15 | -- You should have received a copy of the GNU General Public License
16 | -- along with PATIO. If not, see
17 | --
18 |
19 | ALTER TABLE voting ALTER COLUMN average type DECIMAL(10,2);
20 |
21 | UPDATE voting
22 | SET average = subquery.average
23 | FROM (
24 | SELECT AVG(vote.score) AS average, voting.id AS voting_id
25 | FROM vote, voting
26 | WHERE voting.id = vote.voting_id
27 | GROUP BY voting.id
28 | ) AS subquery
29 | WHERE subquery.voting_id = id;
--------------------------------------------------------------------------------
/src/main/resources/migrations/V6__add_hue_mood_to_vote.sql:
--------------------------------------------------------------------------------
1 | --
2 | -- Copyright (C) 2019 Kaleidos Open Source SL
3 | --
4 | -- This file is part of PATIO.
5 | -- PATIO is free software: you can redistribute it and/or modify
6 | -- it under the terms of the GNU General Public License as published by
7 | -- the Free Software Foundation, either version 3 of the License, or
8 | -- (at your option) any later version.
9 | --
10 | -- PATIO is distributed in the hope that it will be useful,
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | -- GNU General Public License for more details.
14 | --
15 | -- You should have received a copy of the GNU General Public License
16 | -- along with PATIO. If not, see
17 | --
18 |
19 | ALTER TABLE vote ADD COLUMN IF NOT EXISTS hue_mood VARCHAR (200) NULL;
20 |
--------------------------------------------------------------------------------
/src/main/resources/migrations/V7__create_table_voting_stats.sql:
--------------------------------------------------------------------------------
1 | --
2 | -- Copyright (C) 2019 Kaleidos Open Source SL
3 | --
4 | -- This file is part of PATIO.
5 | -- PATIO is free software: you can redistribute it and/or modify
6 | -- it under the terms of the GNU General Public License as published by
7 | -- the Free Software Foundation, either version 3 of the License, or
8 | -- (at your option) any later version.
9 | --
10 | -- PATIO is distributed in the hope that it will be useful,
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | -- GNU General Public License for more details.
14 | --
15 | -- You should have received a copy of the GNU General Public License
16 | -- along with PATIO. If not, see
17 | --
18 |
19 | CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
20 |
21 | CREATE TABLE IF NOT EXISTS voting_stats (
22 | id UUID NOT NULL PRIMARY KEY,
23 | voting_id UUID NOT NULL,
24 | created_at timestamp with time zone NOT NULL,
25 | average DECIMAL(10,2) NULL,
26 | moving_average DECIMAL(10,2) NULL,
27 | FOREIGN KEY (voting_id) REFERENCES voting(id) ON DELETE CASCADE
28 | );
29 |
30 | INSERT INTO voting_stats (id, voting_id, average, created_at)
31 | SELECT
32 | uuid_generate_v4(),
33 | voting.id AS voting_id,
34 | AVG(vote.score) AS average,
35 | now()
36 | FROM vote RIGHT OUTER JOIN voting ON
37 | voting.id = vote.voting_id
38 | GROUP BY voting.id;
39 |
40 | ALTER TABLE voting
41 | ADD COLUMN voting_stats_id UUID NULL,
42 | ADD CONSTRAINT voting_stats_id
43 | FOREIGN KEY (voting_stats_id) REFERENCES voting_stats(id) DEFERRABLE INITIALLY DEFERRED,
44 | DROP COLUMN average;
45 |
46 | UPDATE voting
47 | SET voting_stats_id = vs.id
48 | FROM voting_stats vs
49 | WHERE voting.id = vs.voting_id;
50 |
51 |
52 |
--------------------------------------------------------------------------------
/src/main/resources/migrations/V8__fix_created_at_data_from_voting_stats.sql:
--------------------------------------------------------------------------------
1 | --
2 | -- Copyright (C) 2019 Kaleidos Open Source SL
3 | --
4 | -- This file is part of PATIO.
5 | -- PATIO is free software: you can redistribute it and/or modify
6 | -- it under the terms of the GNU General Public License as published by
7 | -- the Free Software Foundation, either version 3 of the License, or
8 | -- (at your option) any later version.
9 | --
10 | -- PATIO is distributed in the hope that it will be useful,
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | -- GNU General Public License for more details.
14 | --
15 | -- You should have received a copy of the GNU General Public License
16 | -- along with PATIO. If not, see
17 | --
18 |
19 | -- Populates `create_at` field from voting_stats, taking the last vote from each `voting`
20 |
21 | UPDATE
22 | voting_stats
23 | SET
24 | created_at = x.created_at
25 | FROM
26 | (
27 | SELECT
28 | vs.id AS id,
29 | v.created_at
30 | FROM
31 | voting v
32 | JOIN voting_stats vs ON
33 | vs.voting_id = v.id
34 | ) x
35 | WHERE
36 | voting_stats.id = x.id
37 |
--------------------------------------------------------------------------------
/src/main/resources/migrations/V9__calculates_moving_averages.sql:
--------------------------------------------------------------------------------
1 | --
2 | -- Copyright (C) 2019 Kaleidos Open Source SL
3 | --
4 | -- This file is part of PATIO.
5 | -- PATIO is free software: you can redistribute it and/or modify
6 | -- it under the terms of the GNU General Public License as published by
7 | -- the Free Software Foundation, either version 3 of the License, or
8 | -- (at your option) any later version.
9 | --
10 | -- PATIO is distributed in the hope that it will be useful,
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | -- GNU General Public License for more details.
14 | --
15 | -- You should have received a copy of the GNU General Public License
16 | -- along with PATIO. If not, see
17 | --
18 |
19 | -- Populates `moving_average` field from `voting_stats` calculating the data from its `voting` data
20 |
21 | DO $$
22 | DECLARE
23 | gid uuid;
24 | BEGIN
25 | FOR gid IN SELECT * FROM "groups" LOOP
26 | update
27 | voting_stats
28 | set
29 | moving_average = subquery.moving_average_60
30 | from
31 | (
32 | select
33 | vs.id as voting_stats_id,
34 | average,
35 | avg(vs.average) over(
36 | order by vs.created_at rows between 59 preceding and current row) as moving_average_60
37 | from
38 | voting_stats vs
39 | join voting v on
40 | vs.voting_id = v.id
41 | join "groups" g on
42 | v.group_id = g.id
43 | where
44 | vs.average is not null
45 | and voting_id in (select id from voting where group_id = gid)
46 | ) subquery
47 | where
48 | id = subquery.voting_stats_id;
49 | END LOOP;
50 | END $$;
51 |
--------------------------------------------------------------------------------
/src/main/resources/templates/resetPassword.pug:
--------------------------------------------------------------------------------
1 | div
2 | p #{greetings}
3 | p #{main}
4 | p
5 | div
6 | a(href='#{link}') #{link}
7 | p #{notRequested}
8 |
9 | p #{thanks}
10 | p #{patioTeam}
11 |
12 |
--------------------------------------------------------------------------------
/src/test/java/patio/infrastructure/email/services/internal/templates/JadeTemplateServiceTests.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Kaleidos Open Source SL
3 | *
4 | * This file is part of PATIO.
5 | * PATIO is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * PATIO is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with PATIO. If not, see
17 | */
18 | package patio.infrastructure.email.services.internal.templates;
19 |
20 | import static org.junit.jupiter.api.Assertions.*;
21 |
22 | import java.util.Map;
23 | import org.junit.jupiter.api.Test;
24 |
25 | public class JadeTemplateServiceTests {
26 |
27 | @Test
28 | void testRenderingTemplate() {
29 | // given: a configuration data
30 | var configuration = new JadeConfigurationFactory("UTF-8", false).get();
31 |
32 | // and: a template service
33 | var templateService = new JadeTemplateService(configuration);
34 |
35 | // and: provided data
36 | var data = Map.of("name", "john", "age", 22);
37 |
38 | // when: rendering the template with the provided data
39 | String result = templateService.render("templates/example.pug", data);
40 |
41 | // then: the result should contain provided data
42 | assertTrue(result.contains("john"), "rendered template should contain provided data");
43 |
44 | // and:
45 | assertTrue(result.contains("22"), "rendered template should contain provided data");
46 | }
47 |
48 | @Test
49 | void testFailingWhenTemplateNotFound() {
50 | // given: a configuration data
51 | var configuration = new JadeConfigurationFactory("UTF-8", false).get();
52 |
53 | // and: a template service
54 | var templateService = new JadeTemplateService(configuration);
55 |
56 | // when: rendering and unknown template
57 | var emptyResult = templateService.render("templates/unknown.pig", Map.of());
58 |
59 | // then: the result will be empty
60 | assertEquals("", emptyResult);
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/src/test/java/patio/infrastructure/email/services/internal/templates/MailResourceBundleFactoryTests.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Kaleidos Open Source SL
3 | *
4 | * This file is part of PATIO.
5 | * PATIO is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * PATIO is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with PATIO. If not, see
17 | */
18 | package patio.infrastructure.email.services.internal.templates;
19 |
20 | import static org.junit.jupiter.api.Assertions.assertEquals;
21 |
22 | import java.util.Locale;
23 | import java.util.Optional;
24 | import org.junit.jupiter.api.Test;
25 |
26 | public class MailResourceBundleFactoryTests {
27 |
28 | @Test
29 | void resolveMessageSuccessfully() {
30 | // given: an instance of a resource bundle
31 | var factory = new MailResourceBundleFactory(Optional.of(Locale.ENGLISH));
32 | var bundle = factory.get();
33 |
34 | // when: getting an i18n string by its key
35 | var message = bundle.getString("voting.thanks");
36 |
37 | // then: we should get the expected i18n message
38 | assertEquals("Thanks!", message);
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/test/java/patio/infrastructure/email/services/internal/templates/UrlResolverServiceTests.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Kaleidos Open Source SL
3 | *
4 | * This file is part of PATIO.
5 | * PATIO is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * PATIO is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with PATIO. If not, see
17 | */
18 | package patio.infrastructure.email.services.internal.templates;
19 |
20 | import static org.junit.jupiter.api.Assertions.assertEquals;
21 |
22 | import org.junit.jupiter.api.Test;
23 |
24 | public class UrlResolverServiceTests {
25 |
26 | @Test
27 | void testResolveLink() {
28 | // given: an instance of resolver
29 | var service = new URLResolverService("http://mydomain.com");
30 |
31 | // when: resolving link
32 | var result = service.resolve("/api/car/{0}", 1);
33 |
34 | // then: we should get the expected url
35 | assertEquals(result, "http://mydomain.com/api/car/1");
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/test/java/patio/infrastructure/graphql/dataloader/DataLoaderRegistryFactoryTests.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Kaleidos Open Source SL
3 | *
4 | * This file is part of PATIO.
5 | * PATIO is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * PATIO is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with PATIO. If not, see
17 | */
18 | package patio.infrastructure.graphql.dataloader;
19 |
20 | import static org.junit.jupiter.api.Assertions.assertNotNull;
21 |
22 | import org.dataloader.DataLoaderRegistry;
23 | import org.junit.jupiter.api.Test;
24 | import org.mockito.Mockito;
25 | import patio.user.graphql.UserBatchLoader;
26 |
27 | /**
28 | * Tests {@link DataLoaderRegistryFactory}
29 | *
30 | * @since 0.1.0
31 | */
32 | public class DataLoaderRegistryFactoryTests {
33 |
34 | @Test
35 | void testInitialization() {
36 | // given: an instance of factory
37 | DataLoaderRegistryFactory factory = new DataLoaderRegistryFactory();
38 |
39 | // when: adding required data loaders
40 | UserBatchLoader mockedLoader = Mockito.mock(UserBatchLoader.class);
41 | DataLoaderRegistry registry = factory.create(mockedLoader);
42 |
43 | // then: you should be able to retrieve data loaders by its key
44 | assertNotNull(registry.getDataLoader(DataLoaderRegistryFactory.DL_USERS_BY_IDS));
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/src/test/java/patio/infrastructure/graphql/fetchers/archunit/FetchersTests.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Kaleidos Open Source SL
3 | *
4 | * This file is part of PATIO.
5 | * PATIO is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * PATIO is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with PATIO. If not, see
17 | */
18 | package patio.infrastructure.graphql.fetchers.archunit;
19 |
20 | import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes;
21 |
22 | import com.tngtech.archunit.core.domain.JavaClasses;
23 | import com.tngtech.archunit.junit.AnalyzeClasses;
24 | import com.tngtech.archunit.junit.ArchTest;
25 |
26 | /**
27 | * BaseService fetcher constraints
28 | *
29 | * @since 0.1.0
30 | */
31 | @AnalyzeClasses(packages = "patio.api.graphql.fetchers")
32 | public class FetchersTests {
33 |
34 | private static final String NAME_FETCHER_SUFFIX_ = "Fetcher";
35 | private static final String NAME_FETCHER_UTIL_SUFFIX = "FetcherUtils";
36 |
37 | @ArchTest
38 | void checkClassNamingConvention(JavaClasses classes) {
39 | classes()
40 | .should()
41 | .haveSimpleNameEndingWith(NAME_FETCHER_SUFFIX_)
42 | .orShould()
43 | .haveSimpleNameEndingWith(NAME_FETCHER_UTIL_SUFFIX)
44 | .check(classes);
45 | }
46 |
47 | @ArchTest
48 | void checkRelationshipBetweenFetchersAndUtils() {
49 | classes()
50 | .that()
51 | .haveSimpleNameEndingWith(NAME_FETCHER_UTIL_SUFFIX)
52 | .should()
53 | .onlyBeAccessed()
54 | .byClassesThat()
55 | .haveSimpleNameEndingWith(NAME_FETCHER_SUFFIX_);
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/src/test/java/patio/security/services/internal/AlgorithmFactoryTests.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Kaleidos Open Source SL
3 | *
4 | * This file is part of PATIO.
5 | * PATIO is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * PATIO is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with PATIO. If not, see
17 | */
18 | package patio.security.services.internal;
19 |
20 | import static org.junit.jupiter.api.Assertions.assertEquals;
21 | import static org.junit.jupiter.api.Assertions.assertNotNull;
22 |
23 | import org.junit.jupiter.api.Test;
24 |
25 | /**
26 | * Tests {@link patio.security.services.internal.AlgorithmFactory}
27 | *
28 | * @since 0.1.0
29 | */
30 | public class AlgorithmFactoryTests {
31 |
32 | @Test
33 | void testCreateAlgorithm() throws Exception {
34 | // when: creating a new algorithm instance
35 | var factory = new AlgorithmFactory();
36 | var algorithm = factory.create("secret", "HS256");
37 |
38 | // then: we should expect a new instance
39 | assertNotNull(algorithm);
40 |
41 | // and: we should expect it to be a certain algorithm type
42 | assertEquals("HS256", algorithm.getName());
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/test/java/patio/user/domain/UserTests.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Kaleidos Open Source SL
3 | *
4 | * This file is part of PATIO.
5 | * PATIO is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * PATIO is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with PATIO. If not, see
17 | */
18 | package patio.user.domain;
19 |
20 | import static org.junit.jupiter.api.Assertions.assertEquals;
21 |
22 | import org.junit.jupiter.params.ParameterizedTest;
23 | import org.junit.jupiter.params.provider.ValueSource;
24 |
25 | /**
26 | * Tests some functions in domain classes other than getters and setters.
27 | *
28 | * @since 0.1.0
29 | */
30 | public class UserTests {
31 |
32 | @ParameterizedTest(name = "Test getting hash emails: email [{0}]")
33 | @ValueSource(strings = {"somebody@email.com", "SOMEBODY@email.com", "somebody@EMAIL.com"})
34 | void testGetHash(String email) {
35 | // given: a user with email
36 | User user = User.builder().with(u -> u.setEmail(email)).build();
37 |
38 | // when: getting user's hash
39 | String hash = user.getHash();
40 |
41 | // then: it should match the provided value
42 | assertEquals(hash, "66b0ef1ce525f909ad733d06415331d5");
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/test/resources/application.yml:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright (C) 2019 Kaleidos Open Source SL
3 | #
4 | # This file is part of PATIO.
5 | # PATIO is free software: you can redistribute it and/or modify
6 | # it under the terms of the GNU General Public License as published by
7 | # the Free Software Foundation, either version 3 of the License, or
8 | # (at your option) any later version.
9 | #
10 | # PATIO is distributed in the hope that it will be useful,
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | # GNU General Public License for more details.
14 | #
15 | # You should have received a copy of the GNU General Public License
16 | # along with PATIO. If not, see
17 | #
18 |
19 | locale: es
20 |
21 | micronaut:
22 | application:
23 | name: patio-api
24 | ---
25 | datasources:
26 | default:
27 | url: jdbc:tc:postgresql:10-alpine://localhost/patio
28 | username: patio
29 | password: patio
30 | driverClassName: org.testcontainers.jdbc.ContainerDatabaseDriver
31 | jpa:
32 | default:
33 | properties:
34 | hibernate:
35 | show_sql: true
36 | dialect: org.hibernate.dialect.PostgreSQL95Dialect
37 |
38 | flyway:
39 | datasources:
40 | default:
41 | locations: classpath:migrations
42 |
43 | graphql:
44 | enabled: true
45 | path: /graphql
46 | schema: "classpath:graphql/schema.graphqls"
47 |
48 | duser:
49 | enabled: false
50 | name: unknown
51 | email: unknown
52 | password: unknown
53 |
54 | email:
55 | voting:
56 | recipient: somebody@email.com
57 | subjectTemplate: How are you today %s ?
58 | bodyTemplate: |
59 | Hi %s:
60 |
61 | Looking forward to hearing from you in group %s.
62 |
63 | Cheers
64 | Admin
65 |
66 | front:
67 | urls:
68 | voting: "/team/{0}/{1}/vote"
69 | change-password: "/change-password?otp={0}"
70 |
--------------------------------------------------------------------------------
/src/test/resources/patio/group/repositories/testFindAllByDayOfWeekAndVotingTimeLessEq.sql:
--------------------------------------------------------------------------------
1 | --
2 | -- Copyright (C) 2019 Kaleidos Open Source SL
3 | --
4 | -- This file is part of PATIO.
5 | -- PATIO is free software: you can redistribute it and/or modify
6 | -- it under the terms of the GNU General Public License as published by
7 | -- the Free Software Foundation, either version 3 of the License, or
8 | -- (at your option) any later version.
9 | --
10 | -- PATIO is distributed in the hope that it will be useful,
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | -- GNU General Public License for more details.
14 | --
15 | -- You should have received a copy of the GNU General Public License
16 | -- along with PATIO. If not, see
17 | --
18 |
19 | INSERT INTO users (id, name, email, password, otp) VALUES ('486590a3-fcc1-4657-a9ed-5f0f95dadea6','Sue Storm', 'sstorm@email.com', 'password', '');
20 |
21 | -- Voting times are open from midnight, all day long
22 | INSERT INTO groups (id, name, anonymous_vote, voting_time, voting_days, voting_duration) VALUES ('d64db962-3455-11e9-b210-d663bd873d93','Fantastic Four', true, time with time zone '00:00:00.146512+01:00', '{"MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY"}', 24);
23 | INSERT INTO groups (id, name, anonymous_vote, voting_time, voting_days, voting_duration) VALUES ('d64db962-3455-11e9-b210-d663bd873d94','Avengers', true, time with time zone '00:00:00.146512+01:00', '{"MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY"}', 24);
24 |
25 | INSERT INTO users_groups (group_id, user_id, is_admin) VALUES ('d64db962-3455-11e9-b210-d663bd873d93','486590a3-fcc1-4657-a9ed-5f0f95dadea6', 'f');
26 | INSERT INTO users_groups (group_id, user_id, is_admin) VALUES ('d64db962-3455-11e9-b210-d663bd873d94','486590a3-fcc1-4657-a9ed-5f0f95dadea6', 'f');
27 |
--------------------------------------------------------------------------------
/src/test/resources/patio/group/repositories/testFindAllByVotingCreatedAtBetween.sql:
--------------------------------------------------------------------------------
1 | --
2 | -- Copyright (C) 2019 Kaleidos Open Source SL
3 | --
4 | -- This file is part of PATIO.
5 | -- PATIO is free software: you can redistribute it and/or modify
6 | -- it under the terms of the GNU General Public License as published by
7 | -- the Free Software Foundation, either version 3 of the License, or
8 | -- (at your option) any later version.
9 | --
10 | -- PATIO is distributed in the hope that it will be useful,
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | -- GNU General Public License for more details.
14 | --
15 | -- You should have received a copy of the GNU General Public License
16 | -- along with PATIO. If not, see
17 | --
18 |
19 | INSERT INTO users (id, name, email, password, otp) VALUES ('486590a3-fcc1-4657-a9ed-5f0f95dadea6','Sue Storm', 'sstorm@email.com', 'password', '');
20 |
21 | -- Voting times are open from midnight, all day long
22 | INSERT INTO groups (id, name, anonymous_vote, voting_time, voting_days, voting_duration) VALUES ('d64db962-3455-11e9-b210-d663bd873d93','Fantastic Four', true, time with time zone '00:00:00.146512+01:00', '{"MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY"}', 24);
23 | INSERT INTO groups (id, name, anonymous_vote, voting_time, voting_days, voting_duration) VALUES ('d64db962-3455-11e9-b210-d663bd873d94','Avengers', true, time with time zone '00:00:00.146512+01:00', '{"MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY"}', 24);
24 |
25 | INSERT INTO users_groups (group_id, user_id, is_admin) VALUES ('d64db962-3455-11e9-b210-d663bd873d93','486590a3-fcc1-4657-a9ed-5f0f95dadea6', 'f');
26 | INSERT INTO users_groups (group_id, user_id, is_admin) VALUES ('d64db962-3455-11e9-b210-d663bd873d94','486590a3-fcc1-4657-a9ed-5f0f95dadea6', 'f');
27 | INSERT INTO voting (id, group_id, voting_stats_id, created_at, created_by) VALUES ('7772e35c-5a87-4ba3-ab93-da8a957037fd', 'd64db962-3455-11e9-b210-d663bd873d93', 'b3576bc7-2cb4-4680-9445-bda0bc615238', now(), '486590a3-fcc1-4657-a9ed-5f0f95dadea6');
28 | INSERT INTO voting_stats (id, voting_id, created_at, average) VALUES ('b3576bc7-2cb4-4680-9445-bda0bc615238', '7772e35c-5a87-4ba3-ab93-da8a957037fd', now() + interval '5 minutes', 3);
--------------------------------------------------------------------------------
/src/test/resources/patio/infrastructure/graphql/anonymousallowed_schema.graphql:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright (C) 2019 Kaleidos Open Source SL
3 | #
4 | # This file is part of PATIO.
5 | # PATIO is free software: you can redistribute it and/or modify
6 | # it under the terms of the GNU General Public License as published by
7 | # the Free Software Foundation, either version 3 of the License, or
8 | # (at your option) any later version.
9 | #
10 | # PATIO is distributed in the hope that it will be useful,
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | # GNU General Public License for more details.
14 | #
15 | # You should have received a copy of the GNU General Public License
16 | # along with PATIO. If not, see
17 | #
18 |
19 | directive @anonymousAllowed on FIELD_DEFINITION
20 |
21 | type Query {
22 | sayHi: String @anonymousAllowed
23 | sayHiAuthenticated: String
24 | }
--------------------------------------------------------------------------------
/src/test/resources/patio/infrastructure/graphql/scalars/dayofweek_schema.graphql:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright (C) 2019 Kaleidos Open Source SL
3 | #
4 | # This file is part of PATIO.
5 | # PATIO is free software: you can redistribute it and/or modify
6 | # it under the terms of the GNU General Public License as published by
7 | # the Free Software Foundation, either version 3 of the License, or
8 | # (at your option) any later version.
9 | #
10 | # PATIO is distributed in the hope that it will be useful,
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | # GNU General Public License for more details.
14 | #
15 | # You should have received a copy of the GNU General Public License
16 | # along with PATIO. If not, see
17 | #
18 |
19 | scalar DayOfWeek
20 |
21 | type Query {
22 | findDayOfWeek(day: DayOfWeek): DayOfWeek
23 | }
--------------------------------------------------------------------------------
/src/test/resources/patio/infrastructure/graphql/scalars/id_schema.graphql:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright (C) 2019 Kaleidos Open Source SL
3 | #
4 | # This file is part of PATIO.
5 | # PATIO is free software: you can redistribute it and/or modify
6 | # it under the terms of the GNU General Public License as published by
7 | # the Free Software Foundation, either version 3 of the License, or
8 | # (at your option) any later version.
9 | #
10 | # PATIO is distributed in the hope that it will be useful,
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | # GNU General Public License for more details.
14 | #
15 | # You should have received a copy of the GNU General Public License
16 | # along with PATIO. If not, see
17 | #
18 |
19 | type Query {
20 | findById(id: ID): ID
21 | }
--------------------------------------------------------------------------------
/src/test/resources/patio/user/repositories/testFindByIdAndVotingUser.sql:
--------------------------------------------------------------------------------
1 | --
2 | -- Copyright (C) 2019 Kaleidos Open Source SL
3 | --
4 | -- This file is part of PATIO.
5 | -- PATIO is free software: you can redistribute it and/or modify
6 | -- it under the terms of the GNU General Public License as published by
7 | -- the Free Software Foundation, either version 3 of the License, or
8 | -- (at your option) any later version.
9 | --
10 | -- PATIO is distributed in the hope that it will be useful,
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | -- GNU General Public License for more details.
14 | --
15 | -- You should have received a copy of the GNU General Public License
16 | -- along with PATIO. If not, see
17 | --
18 |
19 | INSERT INTO users (id, name, email, password, otp) VALUES ('486590a3-fcc1-4657-a9ed-5f0f95dadea6','Sue Storm', 'sstorm@email.com', 'password', '');
20 | INSERT INTO users (id, name, email, password, otp) VALUES ('486590a3-fcc1-4657-a9ed-5f0f95dadea7','Unknown', 'unknown@email.com', 'password', '');
21 |
22 | INSERT INTO groups (id, name, anonymous_vote, voting_time, voting_days, voting_duration) VALUES ('d64db962-3455-11e9-b210-d663bd873d93','Fantastic Four', true, time with time zone '10:48:12.146512+01:00', '{"MONDAY"}', 24);
23 | INSERT INTO users_groups (group_id, user_id, is_admin) VALUES ('d64db962-3455-11e9-b210-d663bd873d93','486590a3-fcc1-4657-a9ed-5f0f95dadea6', 'f');
24 | INSERT INTO voting (id, group_id, voting_stats_id, created_at, created_by) VALUES ('7772e35c-5a87-4ba3-ab93-da8a957037fd', 'd64db962-3455-11e9-b210-d663bd873d93', 'b3576bc7-2cb4-4680-9445-bda0bc615238', '2020-05-04T10:15:30+01:00', '486590a3-fcc1-4657-a9ed-5f0f95dadea6');
25 | INSERT INTO voting_stats (id, voting_id, created_at, average) VALUES ('b3576bc7-2cb4-4680-9445-bda0bc615238', '7772e35c-5a87-4ba3-ab93-da8a957037fd', now(), 3);
26 | INSERT INTO vote (id, voting_id, created_at, created_by, comment, score) VALUES ('d246d65c-be84-4140-85e1-9cf495523730', '7772e35c-5a87-4ba3-ab93-da8a957037fd', now() - interval '5 day', '486590a3-fcc1-4657-a9ed-5f0f95dadea6', 'Ut sit labore eius.', 3);
27 |
28 |
29 |
--------------------------------------------------------------------------------
/src/test/resources/patio/user/repositories/testListUsersByIds.sql:
--------------------------------------------------------------------------------
1 | --
2 | -- Copyright (C) 2019 Kaleidos Open Source SL
3 | --
4 | -- This file is part of PATIO.
5 | -- PATIO is free software: you can redistribute it and/or modify
6 | -- it under the terms of the GNU General Public License as published by
7 | -- the Free Software Foundation, either version 3 of the License, or
8 | -- (at your option) any later version.
9 | --
10 | -- PATIO is distributed in the hope that it will be useful,
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | -- GNU General Public License for more details.
14 | --
15 | -- You should have received a copy of the GNU General Public License
16 | -- along with PATIO. If not, see
17 | --
18 |
19 | INSERT INTO users (id, name, email, password, otp) VALUES ('486590a3-fcc1-4657-a9ed-5f0f95dadea6','Sue Storm', 'sstorm@email.com', 'password', '');
20 | INSERT INTO users (id, name, email, password, otp) VALUES ('c2a771bc-f8c5-4112-a440-c80fa4c8e382','Ben Grim', 'bgrim@email.com', 'password', '');
21 | INSERT INTO users (id, name, email, password, otp) VALUES ('84d48a35-7659-4710-ad13-4c47785a0e9d','Johnny Storm', 'jstorm@email.com', 'password', '');
22 | INSERT INTO users (id, name, email, password, otp) VALUES ('1998c588-d93b-4db6-92e2-a9dbb4cf03b5','Steve Rogers', 'srogers@email.com', 'password', '');
23 | INSERT INTO users (id, name, email, password, otp) VALUES ('3465094c-5545-4007-a7bc-da2b1a88d9dc','Tony Stark', 'tstark@email.com', 'password', '');
--------------------------------------------------------------------------------
/src/test/resources/patio/voting/repositories/testFindByIdAndVotingUser.sql:
--------------------------------------------------------------------------------
1 | --
2 | -- Copyright (C) 2019 Kaleidos Open Source SL
3 | --
4 | -- This file is part of PATIO.
5 | -- PATIO is free software: you can redistribute it and/or modify
6 | -- it under the terms of the GNU General Public License as published by
7 | -- the Free Software Foundation, either version 3 of the License, or
8 | -- (at your option) any later version.
9 | --
10 | -- PATIO is distributed in the hope that it will be useful,
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | -- GNU General Public License for more details.
14 | --
15 | -- You should have received a copy of the GNU General Public License
16 | -- along with PATIO. If not, see
17 | --
18 |
19 | INSERT INTO users (id, name, email, password, otp) VALUES ('486590a3-fcc1-4657-a9ed-5f0f95dadea6','Sue Storm', 'sstorm@email.com', 'password', '');
20 | INSERT INTO users (id, name, email, password, otp) VALUES ('486590a3-fcc1-4657-a9ed-5f0f95dadea7','Unknown', 'unknown@email.com', 'password', '');
21 |
22 | INSERT INTO groups (id, name, anonymous_vote, voting_time, voting_days, voting_duration) VALUES ('d64db962-3455-11e9-b210-d663bd873d93','Fantastic Four', true, time with time zone '10:48:12.146512+01:00', '{"MONDAY"}', 24);
23 | INSERT INTO users_groups (group_id, user_id, is_admin) VALUES ('d64db962-3455-11e9-b210-d663bd873d93','486590a3-fcc1-4657-a9ed-5f0f95dadea6', 'f');
24 | INSERT INTO voting (id, group_id, voting_stats_id, created_at, created_by) VALUES ('7772e35c-5a87-4ba3-ab93-da8a957037fd', 'd64db962-3455-11e9-b210-d663bd873d93', 'b3576bc7-2cb4-4680-9445-bda0bc615238', '2020-05-04T10:15:30+01:00', '486590a3-fcc1-4657-a9ed-5f0f95dadea6');
25 | INSERT INTO voting_stats (id, voting_id, created_at, average) VALUES ('b3576bc7-2cb4-4680-9445-bda0bc615238', '7772e35c-5a87-4ba3-ab93-da8a957037fd', now(), 3);
26 | INSERT INTO vote (id, voting_id, created_at, created_by, comment, score) VALUES ('d246d65c-be84-4140-85e1-9cf495523730', '7772e35c-5a87-4ba3-ab93-da8a957037fd', now() - interval '5 day', '486590a3-fcc1-4657-a9ed-5f0f95dadea6', 'Ut sit labore eius.', 3);
--------------------------------------------------------------------------------
/src/test/resources/templates/example.pug:
--------------------------------------------------------------------------------
1 | div
2 | h1 #{name}
3 | h2 #{age}
--------------------------------------------------------------------------------