From d85cdb9b22a7549e553eba5672247c07fda4752d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Wo=C5=BAniak?= Date: Tue, 8 Dec 2020 18:26:35 +0100 Subject: [PATCH 01/15] Added gitci MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marcin Woźniak --- .gitlab-ci.yml | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 .gitlab-ci.yml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..4095436 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,40 @@ +stages: + - build + - deploy + +build: + stage: build + image: java:14 + script: + - echo "Start building App" + - rm -rf restservice/src/main/resources/application.properties + - echo "spring.profiles.active=prod" > restservice/src/main/resources/application.properties + - mvn clean + - mvn install + - cd restservice + - mvn clean package spring-boot:repackage + - echo "Build successfully!" + artifacts: + expire_in: 1 hour + paths: + - restservice/target/ + +deploy_production: + stage: deploy + before_script: + - apt-get update + - apt-get --yes --force-yes install rsync + script: + - 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )' + - eval $(ssh-agent -s) + - ssh-add <(echo "$SSH_PRIVATE_KEY") + - mkdir -p ~/.ssh + - '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config' + - echo "Deploying to server" + - ssh backend@wmi-backend-gc.plannaplan.pl -t "sudo systemctl stop plannaplan-backend" + - rsync --progress target/*.jar --delete backend@wmi-backend-gc.plannaplan.pl:/opt/plannaplan-backend/backend.jar + - sleep 5 + - ssh backend@wmi-backend-gc.plannaplan.pl -t "sudo systemctl start plannaplan-backend" + - echo "Deployed" + #only: + #- master From 9f3e41e6016617cc02ef503ae1d7b8020db2d2e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Wo=C5=BAniak?= Date: Tue, 8 Dec 2020 18:31:07 +0100 Subject: [PATCH 02/15] Updated .git-ci MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marcin Woźniak --- .gitlab-ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 4095436..9bae65e 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -4,7 +4,7 @@ stages: build: stage: build - image: java:14 + image: openjdk14 script: - echo "Start building App" - rm -rf restservice/src/main/resources/application.properties @@ -18,7 +18,7 @@ build: expire_in: 1 hour paths: - restservice/target/ - + deploy_production: stage: deploy before_script: From 0c471162f22b841fd9830321ad3ade1c0bbffe08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Wo=C5=BAniak?= Date: Tue, 8 Dec 2020 18:31:58 +0100 Subject: [PATCH 03/15] Updated .git-ci MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marcin Woźniak --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 9bae65e..9781098 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -4,7 +4,7 @@ stages: build: stage: build - image: openjdk14 + image: adoptopenjdk/openjdk14 script: - echo "Start building App" - rm -rf restservice/src/main/resources/application.properties From 086e4be4581f539cc3af40a986c4c12579453330 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Wo=C5=BAniak?= Date: Tue, 8 Dec 2020 18:37:02 +0100 Subject: [PATCH 04/15] Updated .git-ci MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marcin Woźniak --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 9781098..6f485fc 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -4,7 +4,7 @@ stages: build: stage: build - image: adoptopenjdk/openjdk14 + image: maven script: - echo "Start building App" - rm -rf restservice/src/main/resources/application.properties From b495fd7f65ebab3f5fa7abb2519a29c194a7a5d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Wo=C5=BAniak?= Date: Tue, 8 Dec 2020 18:41:08 +0100 Subject: [PATCH 05/15] Updated .git-ci MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marcin Woźniak --- .gitlab-ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 6f485fc..c8d3ec0 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -32,7 +32,8 @@ deploy_production: - '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config' - echo "Deploying to server" - ssh backend@wmi-backend-gc.plannaplan.pl -t "sudo systemctl stop plannaplan-backend" - - rsync --progress target/*.jar --delete backend@wmi-backend-gc.plannaplan.pl:/opt/plannaplan-backend/backend.jar + - ssh backend@wmi-backend-gc.plannaplan.pl -t "rm -rf /opt/plannaplan-backend/backend.jar" + - rsync --progress target/*.jar backend@wmi-backend-gc.plannaplan.pl:/opt/plannaplan-backend/backend.jar - sleep 5 - ssh backend@wmi-backend-gc.plannaplan.pl -t "sudo systemctl start plannaplan-backend" - echo "Deployed" From 181d93082c7d672fb08a11719f5a3a6a94b09659 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Wo=C5=BAniak?= Date: Tue, 8 Dec 2020 18:42:18 +0100 Subject: [PATCH 06/15] Updated .git-ci MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marcin Woźniak --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index c8d3ec0..fa40c22 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -33,7 +33,7 @@ deploy_production: - echo "Deploying to server" - ssh backend@wmi-backend-gc.plannaplan.pl -t "sudo systemctl stop plannaplan-backend" - ssh backend@wmi-backend-gc.plannaplan.pl -t "rm -rf /opt/plannaplan-backend/backend.jar" - - rsync --progress target/*.jar backend@wmi-backend-gc.plannaplan.pl:/opt/plannaplan-backend/backend.jar + - rsync --progress restservice/target/*.jar backend@wmi-backend-gc.plannaplan.pl:/opt/plannaplan-backend/backend.jar - sleep 5 - ssh backend@wmi-backend-gc.plannaplan.pl -t "sudo systemctl start plannaplan-backend" - echo "Deployed" From 2921c98c354b6f9c26a0c5dfd9ad336e7ef4e785 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Wo=C5=BAniak?= Date: Tue, 8 Dec 2020 19:02:02 +0100 Subject: [PATCH 07/15] Updated .git-ci MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marcin Woźniak --- .gitlab-ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index fa40c22..a31a8d0 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -37,5 +37,5 @@ deploy_production: - sleep 5 - ssh backend@wmi-backend-gc.plannaplan.pl -t "sudo systemctl start plannaplan-backend" - echo "Deployed" - #only: - #- master + only: + - master From 1cdb301adf4331fe9e829165887be3921d083ec9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Wo=C5=BAniak?= Date: Tue, 8 Dec 2020 19:09:35 +0100 Subject: [PATCH 08/15] Updated .git-ci MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marcin Woźniak --- .gitlab-ci.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index a31a8d0..b5d2ac6 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -7,7 +7,6 @@ build: image: maven script: - echo "Start building App" - - rm -rf restservice/src/main/resources/application.properties - echo "spring.profiles.active=prod" > restservice/src/main/resources/application.properties - mvn clean - mvn install From 52abb281ff20fce81445eb9d71fb6fb022f14d2d Mon Sep 17 00:00:00 2001 From: Filip Izydorczyk Date: Thu, 10 Dec 2020 15:17:13 +0100 Subject: [PATCH 09/15] commision date fix --- .../plannaplan/responses/models/CommisionResponse.java | 8 +++----- .../responses/mappers/CommisionResponseMappersTest.java | 4 ++-- .../responses/models/CommisionResponseTest.java | 2 +- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/restservice/src/main/java/com/plannaplan/responses/models/CommisionResponse.java b/restservice/src/main/java/com/plannaplan/responses/models/CommisionResponse.java index 63df94d..e995e27 100755 --- a/restservice/src/main/java/com/plannaplan/responses/models/CommisionResponse.java +++ b/restservice/src/main/java/com/plannaplan/responses/models/CommisionResponse.java @@ -1,7 +1,5 @@ package com.plannaplan.responses.models; -import java.sql.Timestamp; - import com.plannaplan.entities.Commision; import io.swagger.annotations.ApiModel; @@ -13,14 +11,14 @@ public class CommisionResponse { private Long id; @ApiModelProperty(value = "Timestamp where the user commit the commision") - private Timestamp commisionDate; + private String commisionDate; public CommisionResponse(Commision commision) { this.id = commision.getId(); - this.commisionDate = commision.getCommisionDate(); + this.commisionDate = commision.getCommisionDate().toString(); } - public Timestamp getCommisionDate() { + public String getCommisionDate() { return commisionDate; } diff --git a/restservice/src/test/java/com/plannaplan/responses/mappers/CommisionResponseMappersTest.java b/restservice/src/test/java/com/plannaplan/responses/mappers/CommisionResponseMappersTest.java index 95d02a6..e378617 100755 --- a/restservice/src/test/java/com/plannaplan/responses/mappers/CommisionResponseMappersTest.java +++ b/restservice/src/test/java/com/plannaplan/responses/mappers/CommisionResponseMappersTest.java @@ -17,7 +17,7 @@ public class CommisionResponseMappersTest { final List resposne = CommisionResponseMappers.mapToResponse(coms); assertTrue(resposne.get(0) instanceof CommisionResponse); - assertTrue(resposne.get(0).getCommisionDate().equals(coms.get(0).getCommisionDate())); - assertTrue(resposne.get(1).getCommisionDate().equals(coms.get(1).getCommisionDate())); + assertTrue(resposne.get(0).getCommisionDate().equals(coms.get(0).getCommisionDate().toString())); + assertTrue(resposne.get(1).getCommisionDate().equals(coms.get(1).getCommisionDate().toString())); } } diff --git a/restservice/src/test/java/com/plannaplan/responses/models/CommisionResponseTest.java b/restservice/src/test/java/com/plannaplan/responses/models/CommisionResponseTest.java index 23edc29..6a151ae 100755 --- a/restservice/src/test/java/com/plannaplan/responses/models/CommisionResponseTest.java +++ b/restservice/src/test/java/com/plannaplan/responses/models/CommisionResponseTest.java @@ -12,6 +12,6 @@ public class CommisionResponseTest { final Commision com = new Commision(null); final CommisionResponse comResponse = new CommisionResponse(com); - assertTrue(comResponse.getCommisionDate().equals(com.getCommisionDate())); + assertTrue(comResponse.getCommisionDate().equals(com.getCommisionDate().toString())); } } From f31a50aa06a9028a5a0879850158f8d39fb8b906 Mon Sep 17 00:00:00 2001 From: Filip Izydorczyk Date: Thu, 10 Dec 2020 16:13:03 +0100 Subject: [PATCH 10/15] Commision with grouos response --- .../controllers/CommisionController.java | 17 +++++++-- .../mappers/CommisionResponseMappers.java | 6 ++++ .../models/CommisionWithGroupsResponse.java | 36 +++++++++++++++++++ .../mappers/CommisionResponseMappersTest.java | 34 ++++++++++++++++++ .../CommisionWithGroupsResponseTest.java | 34 ++++++++++++++++++ 5 files changed, 124 insertions(+), 3 deletions(-) create mode 100755 restservice/src/main/java/com/plannaplan/responses/models/CommisionWithGroupsResponse.java create mode 100755 restservice/src/test/java/com/plannaplan/responses/models/CommisionWithGroupsResponseTest.java diff --git a/restservice/src/main/java/com/plannaplan/controllers/CommisionController.java b/restservice/src/main/java/com/plannaplan/controllers/CommisionController.java index 03c835c..ba5b603 100755 --- a/restservice/src/main/java/com/plannaplan/controllers/CommisionController.java +++ b/restservice/src/main/java/com/plannaplan/controllers/CommisionController.java @@ -33,6 +33,7 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.util.Assert; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; @RestController @CrossOrigin @@ -96,10 +97,20 @@ public class CommisionController extends TokenBasedController { @GetMapping("/user") @ApiOperation("Return list of user all commisions (history of schedules)") - public ResponseEntity> getAlCommisions() throws UserNotFoundException { + public ResponseEntity> getAlCommisions( + @RequestParam(name = "groups", defaultValue = "false") @ApiParam(value = "Boolean if we want to display wiht commision's group ids") Boolean groups) + throws UserNotFoundException { User user = this.getCurrentUser().orElseThrow(() -> new NullPointerException()); - List result = CommisionResponseMappers - .mapToResponse(this.commisionService.getUsersCommisions(user)); + + List result; + + if (!groups) { + result = CommisionResponseMappers.mapToResponse(this.commisionService.getUsersCommisions(user)); + } else { + result = CommisionResponseMappers + .mapToResponseWithGroups(this.commisionService.getUsersCommisions(user)); + } + return new ResponseEntity<>(result, HttpStatus.OK); } diff --git a/restservice/src/main/java/com/plannaplan/responses/mappers/CommisionResponseMappers.java b/restservice/src/main/java/com/plannaplan/responses/mappers/CommisionResponseMappers.java index 3303e96..7ce70d2 100755 --- a/restservice/src/main/java/com/plannaplan/responses/mappers/CommisionResponseMappers.java +++ b/restservice/src/main/java/com/plannaplan/responses/mappers/CommisionResponseMappers.java @@ -6,9 +6,15 @@ import java.util.stream.Collectors; import com.plannaplan.entities.Commision; import com.plannaplan.responses.models.CommisionResponse; +import com.plannaplan.responses.models.CommisionWithGroupsResponse; public class CommisionResponseMappers { public static final List mapToResponse(List commisions) { return commisions.stream().filter(Objects::nonNull).map(CommisionResponse::new).collect(Collectors.toList()); } + + public static final List mapToResponseWithGroups(List commisions) { + return commisions.stream().filter(Objects::nonNull).map(CommisionWithGroupsResponse::new) + .collect(Collectors.toList()); + } } diff --git a/restservice/src/main/java/com/plannaplan/responses/models/CommisionWithGroupsResponse.java b/restservice/src/main/java/com/plannaplan/responses/models/CommisionWithGroupsResponse.java new file mode 100755 index 0000000..435f754 --- /dev/null +++ b/restservice/src/main/java/com/plannaplan/responses/models/CommisionWithGroupsResponse.java @@ -0,0 +1,36 @@ +package com.plannaplan.responses.models; + +import java.util.List; +import java.util.Objects; +import java.util.function.Function; +import java.util.stream.Collectors; + +import com.plannaplan.entities.Assignment; +import com.plannaplan.entities.Commision; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +@ApiModel(description = "Response shows information about commision and its groups.", value = "CommisionWithGroupsResponse") +public class CommisionWithGroupsResponse extends CommisionResponse { + + @ApiModelProperty(value = "List of groups ids in databse that belongs to commision") + private List groups; + + public CommisionWithGroupsResponse(Commision commision) { + super(commision); + this.groups = commision.getAssignments().stream().filter(Objects::nonNull) + .map(new Function() { + + @Override + public Long apply(Assignment arg0) { + return arg0.getGroup().getId(); + } + }).collect(Collectors.toList()); + } + + public List getGroups() { + return groups; + } + +} diff --git a/restservice/src/test/java/com/plannaplan/responses/mappers/CommisionResponseMappersTest.java b/restservice/src/test/java/com/plannaplan/responses/mappers/CommisionResponseMappersTest.java index e378617..a46b58a 100755 --- a/restservice/src/test/java/com/plannaplan/responses/mappers/CommisionResponseMappersTest.java +++ b/restservice/src/test/java/com/plannaplan/responses/mappers/CommisionResponseMappersTest.java @@ -2,11 +2,16 @@ package com.plannaplan.responses.mappers; import static org.junit.jupiter.api.Assertions.assertTrue; +import java.lang.reflect.Field; import java.util.Arrays; import java.util.List; +import com.plannaplan.entities.Assignment; import com.plannaplan.entities.Commision; +import com.plannaplan.entities.Groups; import com.plannaplan.responses.models.CommisionResponse; +import com.plannaplan.responses.models.CommisionWithGroupsResponse; +import com.plannaplan.types.WeekDay; import org.junit.Test; @@ -20,4 +25,33 @@ public class CommisionResponseMappersTest { assertTrue(resposne.get(0).getCommisionDate().equals(coms.get(0).getCommisionDate().toString())); assertTrue(resposne.get(1).getCommisionDate().equals(coms.get(1).getCommisionDate().toString())); } + + @Test + public void shouldMapListWithEntityToListOfResponsesWithGroups() + throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { + + final Field reader = Commision.class.getDeclaredField("assignments"); + final Field groupReader = Groups.class.getDeclaredField("id"); + reader.setAccessible(true); + groupReader.setAccessible(true); + + final Commision com1 = new Commision(null); + final Groups group1 = new Groups(43, "BRAK", null, 840, WeekDay.MONDAY, null); + + groupReader.set(group1, Long.valueOf(8)); + reader.set(com1, Arrays.asList(new Assignment(group1, com1))); + + final Commision com2 = new Commision(null); + final Groups group2 = new Groups(124, "BRAK", null, 900, WeekDay.WEDNESDAY, null); + + groupReader.set(group2, Long.valueOf(9)); + reader.set(com2, Arrays.asList(new Assignment(group2, com2))); + + final List resposne = CommisionResponseMappers + .mapToResponseWithGroups(Arrays.asList(com1, com2)); + + assertTrue(resposne.size() == 2); + assertTrue(resposne.get(0).getGroups().get(0) == 8); + assertTrue(resposne.get(1).getGroups().get(0) == 9); + } } diff --git a/restservice/src/test/java/com/plannaplan/responses/models/CommisionWithGroupsResponseTest.java b/restservice/src/test/java/com/plannaplan/responses/models/CommisionWithGroupsResponseTest.java new file mode 100755 index 0000000..e9ef476 --- /dev/null +++ b/restservice/src/test/java/com/plannaplan/responses/models/CommisionWithGroupsResponseTest.java @@ -0,0 +1,34 @@ +package com.plannaplan.responses.models; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.lang.reflect.Field; +import java.util.Arrays; + +import com.plannaplan.entities.Assignment; +import com.plannaplan.entities.Commision; +import com.plannaplan.entities.Groups; +import com.plannaplan.types.WeekDay; + +import org.junit.Test; + +public class CommisionWithGroupsResponseTest { + @Test + public void shouldMapCommisionToResponse() + throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { + final Field reader = Commision.class.getDeclaredField("assignments"); + final Field groupReader = Groups.class.getDeclaredField("id"); + reader.setAccessible(true); + groupReader.setAccessible(true); + + final Commision com = new Commision(null); + final Groups group = new Groups(43, "BRAK", null, 840, WeekDay.MONDAY, null); + + groupReader.set(group, Long.valueOf(8)); + reader.set(com, Arrays.asList(new Assignment(group, com))); + + final CommisionWithGroupsResponse comResponse = new CommisionWithGroupsResponse(com); + + assertTrue(comResponse.getGroups().get(0) == 8); + } +} From 7c457ce2325f78a4e3a4b0852da3b2e81b9b3a49 Mon Sep 17 00:00:00 2001 From: Filip Izydorczyk Date: Thu, 10 Dec 2020 16:19:58 +0100 Subject: [PATCH 11/15] Deanery response --- .../controllers/CommisionController.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/restservice/src/main/java/com/plannaplan/controllers/CommisionController.java b/restservice/src/main/java/com/plannaplan/controllers/CommisionController.java index ba5b603..b009fea 100755 --- a/restservice/src/main/java/com/plannaplan/controllers/CommisionController.java +++ b/restservice/src/main/java/com/plannaplan/controllers/CommisionController.java @@ -117,11 +117,19 @@ public class CommisionController extends TokenBasedController { @PreAuthorize("hasRole('ROLE_DEANERY')") @GetMapping("/user/{id}") @ApiOperation("Return list of commisions for given user. To be able to access this data u need to provide DEANERY token") - public ResponseEntity> getCommision(@PathVariable(name = "id") Long userId) + public ResponseEntity> getCommision(@PathVariable(name = "id") Long userId, + @RequestParam(name = "groups", defaultValue = "false") @ApiParam(value = "Boolean if we want to display wiht commision's group ids") Boolean groups) throws UserNotFoundException { User user = this.userService.getById(userId).orElseThrow(() -> new NullPointerException()); - List result = CommisionResponseMappers - .mapToResponse(this.commisionService.getUsersCommisions(user)); + List result; + + if (!groups) { + result = CommisionResponseMappers.mapToResponse(this.commisionService.getUsersCommisions(user)); + } else { + result = CommisionResponseMappers + .mapToResponseWithGroups(this.commisionService.getUsersCommisions(user)); + } + return new ResponseEntity<>(result, HttpStatus.OK); } From dfe534a8359a91e768c5074629ffb68d1428a864 Mon Sep 17 00:00:00 2001 From: Filip Izydorczyk Date: Thu, 10 Dec 2020 16:34:42 +0100 Subject: [PATCH 12/15] endpointsd refactore --- .../controllers/AssignmentsController.java | 4 ++- .../controllers/CommisionController.java | 35 +++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/restservice/src/main/java/com/plannaplan/controllers/AssignmentsController.java b/restservice/src/main/java/com/plannaplan/controllers/AssignmentsController.java index 2f07c2a..06313e8 100755 --- a/restservice/src/main/java/com/plannaplan/controllers/AssignmentsController.java +++ b/restservice/src/main/java/com/plannaplan/controllers/AssignmentsController.java @@ -29,7 +29,8 @@ import org.springframework.web.bind.annotation.RequestMapping; @CrossOrigin @RequestMapping("/api/" + App.API_VERSION + "/assignments") @Api(tags = { - "Assignments" }, value = "Assignments", description = "Assignment is representation of student willing to join given group (lecture or calss)") + "Assignments" }, value = "Assignments", description = "Assignment is representation of student willing to join given group (lecture or calss). This comtroller is depreaceted. Use commission instead") +@Deprecated public class AssignmentsController extends TokenBasedController { @Autowired @@ -40,6 +41,7 @@ public class AssignmentsController extends TokenBasedController { @GetMapping("/user") @ApiOperation(value = "Return user current assignemts (from newest commision). STUDENT Token needs to be provided.") + @Deprecated public ResponseEntity> getCurrentAssignments() throws Exception { User user = this.getCurrentUser().orElseThrow(() -> new NullPointerException("User not found")); Optional com = this.commisionService.getNewestCommision(user); diff --git a/restservice/src/main/java/com/plannaplan/controllers/CommisionController.java b/restservice/src/main/java/com/plannaplan/controllers/CommisionController.java index b009fea..7ef71e2 100755 --- a/restservice/src/main/java/com/plannaplan/controllers/CommisionController.java +++ b/restservice/src/main/java/com/plannaplan/controllers/CommisionController.java @@ -35,6 +35,11 @@ import org.springframework.util.Assert; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; +import java.util.ArrayList; + +import com.plannaplan.responses.mappers.AssignmentResponseMappers; +import com.plannaplan.responses.models.AssignmentResponse; + @RestController @CrossOrigin @RequestMapping("/api/" + App.API_VERSION + "/commisions") @@ -114,6 +119,20 @@ public class CommisionController extends TokenBasedController { return new ResponseEntity<>(result, HttpStatus.OK); } + @GetMapping("/user/shedule") + @ApiOperation(value = "Return user current assignemts (from newest commision). STUDENT Token needs to be provided.") + public ResponseEntity> getCurrentAssignments() throws Exception { + User user = this.getCurrentUser().orElseThrow(() -> new NullPointerException("User not found")); + Optional com = this.commisionService.getNewestCommision(user); + + if (com.isPresent()) { + List respone = this.assignmentService.getCommisionAssignments(com.get()); + return new ResponseEntity<>(AssignmentResponseMappers.mapToResponse(respone), HttpStatus.OK); + } + + return new ResponseEntity<>(new ArrayList<>(), HttpStatus.OK); + } + @PreAuthorize("hasRole('ROLE_DEANERY')") @GetMapping("/user/{id}") @ApiOperation("Return list of commisions for given user. To be able to access this data u need to provide DEANERY token") @@ -133,4 +152,20 @@ public class CommisionController extends TokenBasedController { return new ResponseEntity<>(result, HttpStatus.OK); } + @PreAuthorize("hasRole('ROLE_DEANERY')") + @GetMapping("/user/{id}/shedule") + @ApiOperation(value = "Return given user current assignemts (from newest commision). DEANERY Token needs to be provided.") + public ResponseEntity> getCurrentAssignmentsDeanery( + @PathVariable(name = "id") Long userId) throws Exception { + User user = this.userService.getById(userId).orElseThrow(() -> new NullPointerException()); + Optional com = this.commisionService.getNewestCommision(user); + + if (com.isPresent()) { + List respone = this.assignmentService.getCommisionAssignments(com.get()); + return new ResponseEntity<>(AssignmentResponseMappers.mapToResponse(respone), HttpStatus.OK); + } + + return new ResponseEntity<>(new ArrayList<>(), HttpStatus.OK); + } + } From 831358128ee78bfefa633180a4585f0cb5e90bbb Mon Sep 17 00:00:00 2001 From: Filip Izydorczyk Date: Thu, 10 Dec 2020 16:35:23 +0100 Subject: [PATCH 13/15] endpointsd refactore --- .../java/com/plannaplan/controllers/CommisionController.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/restservice/src/main/java/com/plannaplan/controllers/CommisionController.java b/restservice/src/main/java/com/plannaplan/controllers/CommisionController.java index 7ef71e2..5b08dc8 100755 --- a/restservice/src/main/java/com/plannaplan/controllers/CommisionController.java +++ b/restservice/src/main/java/com/plannaplan/controllers/CommisionController.java @@ -119,7 +119,7 @@ public class CommisionController extends TokenBasedController { return new ResponseEntity<>(result, HttpStatus.OK); } - @GetMapping("/user/shedule") + @GetMapping("/user/schedule") @ApiOperation(value = "Return user current assignemts (from newest commision). STUDENT Token needs to be provided.") public ResponseEntity> getCurrentAssignments() throws Exception { User user = this.getCurrentUser().orElseThrow(() -> new NullPointerException("User not found")); @@ -153,7 +153,7 @@ public class CommisionController extends TokenBasedController { } @PreAuthorize("hasRole('ROLE_DEANERY')") - @GetMapping("/user/{id}/shedule") + @GetMapping("/user/{id}/schedule") @ApiOperation(value = "Return given user current assignemts (from newest commision). DEANERY Token needs to be provided.") public ResponseEntity> getCurrentAssignmentsDeanery( @PathVariable(name = "id") Long userId) throws Exception { From a6acab932c520c1e35dd005957ad93616b732e93 Mon Sep 17 00:00:00 2001 From: Filip Izydorczyk Date: Thu, 10 Dec 2020 16:50:47 +0100 Subject: [PATCH 14/15] New endpints tests --- .../controllers/AssignmentsController.java | 2 +- .../controllers/CommisionController.java | 5 ++ .../controllers/CommisionControllerTest.java | 53 +++++++++++++++++++ 3 files changed, 59 insertions(+), 1 deletion(-) diff --git a/restservice/src/main/java/com/plannaplan/controllers/AssignmentsController.java b/restservice/src/main/java/com/plannaplan/controllers/AssignmentsController.java index 06313e8..8a0a786 100755 --- a/restservice/src/main/java/com/plannaplan/controllers/AssignmentsController.java +++ b/restservice/src/main/java/com/plannaplan/controllers/AssignmentsController.java @@ -40,7 +40,7 @@ public class AssignmentsController extends TokenBasedController { private AssignmentService assignmentService; @GetMapping("/user") - @ApiOperation(value = "Return user current assignemts (from newest commision). STUDENT Token needs to be provided.") + @ApiOperation(value = "Return user current assignemts (from newest commision). STUDENT Token needs to be provided. This method is depreaceted. Use `/api/v1/commisions/user/schedule` instead.") @Deprecated public ResponseEntity> getCurrentAssignments() throws Exception { User user = this.getCurrentUser().orElseThrow(() -> new NullPointerException("User not found")); diff --git a/restservice/src/main/java/com/plannaplan/controllers/CommisionController.java b/restservice/src/main/java/com/plannaplan/controllers/CommisionController.java index 5b08dc8..2388f12 100755 --- a/restservice/src/main/java/com/plannaplan/controllers/CommisionController.java +++ b/restservice/src/main/java/com/plannaplan/controllers/CommisionController.java @@ -158,6 +158,11 @@ public class CommisionController extends TokenBasedController { public ResponseEntity> getCurrentAssignmentsDeanery( @PathVariable(name = "id") Long userId) throws Exception { User user = this.userService.getById(userId).orElseThrow(() -> new NullPointerException()); + + if (user.getRole() == UserRoles.DEANERY) { + return new ResponseEntity<>(null, HttpStatus.BAD_REQUEST); + } + Optional com = this.commisionService.getNewestCommision(user); if (com.isPresent()) { diff --git a/restservice/src/test/java/com/plannaplan/controllers/CommisionControllerTest.java b/restservice/src/test/java/com/plannaplan/controllers/CommisionControllerTest.java index f426785..5ff2377 100755 --- a/restservice/src/test/java/com/plannaplan/controllers/CommisionControllerTest.java +++ b/restservice/src/test/java/com/plannaplan/controllers/CommisionControllerTest.java @@ -43,6 +43,7 @@ public class CommisionControllerTest extends AbstractControllerTest { private static final String ADD_COMMISION_ENDPOINT = "/api/v1/commisions/user"; private static final String GET_COMMISIONS_ENDPOINT = "/api/v1/commisions/user"; private static final String GET_SOMEONE_COMMISIONS_ENDPOINT = "/api/v1/commisions/user"; + private static final String GET_USER_SCHEDULE_ENDPOINT = "/api/v1/commisions/user/schedule"; private static final MediaType APPLICATION_JSON_UTF8 = new MediaType(MediaType.APPLICATION_JSON.getType(), MediaType.APPLICATION_JSON.getSubtype(), Charset.forName("utf8")); @@ -190,6 +191,58 @@ public class CommisionControllerTest extends AbstractControllerTest { .header("Authorization", "Bearer " + token)).andExpect(status().is4xxClientError()); } + @Test + public void shouldReturn4xxInScheduleEndpoint() throws Exception { + MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build(); + mockMvc.perform(get(GET_USER_SCHEDULE_ENDPOINT)).andExpect(status().is4xxClientError()); + } + + @Test + public void shouldReturnOkInScheduleEdnpoint() throws Exception { + final User user = this.service.checkForUser(TEST_COMMISIONS_STUDENT_EMAIL, null); + final String token = this.service.login(user).getToken(); + + MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build(); + mockMvc.perform(get(GET_USER_SCHEDULE_ENDPOINT).header("Authorization", "Bearer " + token)) + .andExpect(status().isOk()); + } + + @Test + public void shouldReturnOkInScheduleEdnpointByDeanery() throws Exception { + this.checkUsers(); + final User user = this.service.checkForUser(TEST_COMMISIONS_DEANERY_EMAIL, null); + final User student = this.service.checkForUser(TEST_COMMISIONS_STUDENT_EMAIL, null); + final String token = this.service.login(user).getToken(); + + MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build(); + mockMvc.perform(get(GET_COMMISIONS_ENDPOINT + "/" + student.getId() + "/schedule").header("Authorization", + "Bearer " + token)).andExpect(status().isOk()); + } + + @Test + public void shouldFailInScheduleEdnpointByOtherStudent() throws Exception { + this.checkUsers(); + final User student = this.service.checkForUser(TEST_COMMISIONS_STUDENT_EMAIL, null); + final User otherStudent = this.service.checkForUser(TEST_COMMISIONS_OTHER_STUDENT_EMAIL, null); + final String token = this.service.login(student).getToken(); + + MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build(); + mockMvc.perform(get(GET_COMMISIONS_ENDPOINT + "/" + otherStudent.getId() + "/schedule").header("Authorization", + "Bearer " + token)).andExpect(status().is4xxClientError()); + } + + @Test + public void shouldFailInScheduleEdnpointByDeaneryDeaneryRelation() throws Exception { + this.checkUsers(); + final User deanery = this.service.checkForUser(TEST_COMMISIONS_DEANERY_EMAIL, null); + final User otherDeanery = this.service.checkForUser(TEST_COMMISIONS_OTHER_DEANERY_EMAIL, null); + final String token = this.service.login(deanery).getToken(); + + MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build(); + mockMvc.perform(get(GET_COMMISIONS_ENDPOINT + "/" + otherDeanery.getId() + "/schedule").header("Authorization", + "Bearer " + token)).andExpect(status().is4xxClientError()); + } + private void checkUsers() { if (CommisionControllerTest.user == null) { CommisionControllerTest.user = new User(null, null, TEST_COMMISIONS_STUDENT_EMAIL, UserRoles.STUDENT); From e9927f832d70dc556e88ba6f1207d2b9c180b503 Mon Sep 17 00:00:00 2001 From: Filip Izydorczyk Date: Thu, 10 Dec 2020 16:58:55 +0100 Subject: [PATCH 15/15] permission problems --- .gitlab-ci.yml | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 .gitlab-ci.yml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml old mode 100644 new mode 100755