From 7ea73f21cd64d6989db30a231a4a6a5959d812a9 Mon Sep 17 00:00:00 2001 From: Azher2Ali <121898125+Azher2Ali@users.noreply.github.com> Date: Fri, 14 Apr 2023 01:56:14 -0400 Subject: [PATCH 1/4] commiting changes related to visa implementation --- .../ego/controller/VisaController.java | 103 ++++++++++++++++++ .../overture/ego/model/dto/VisaRequest.java | 24 ++++ .../bio/overture/ego/model/entity/Visa.java | 67 ++++++++++++ .../overture/ego/model/enums/JavaFields.java | 5 + .../overture/ego/model/enums/SqlFields.java | 4 + .../bio/overture/ego/model/enums/Tables.java | 2 + .../overture/ego/model/enums/VisaType.java | 47 ++++++++ .../ego/repository/VisaRepository.java | 16 +++ .../bio/overture/ego/service/VisaService.java | 91 ++++++++++++++++ 9 files changed, 359 insertions(+) create mode 100644 src/main/java/bio/overture/ego/controller/VisaController.java create mode 100644 src/main/java/bio/overture/ego/model/dto/VisaRequest.java create mode 100644 src/main/java/bio/overture/ego/model/entity/Visa.java create mode 100644 src/main/java/bio/overture/ego/model/enums/VisaType.java create mode 100644 src/main/java/bio/overture/ego/repository/VisaRepository.java create mode 100644 src/main/java/bio/overture/ego/service/VisaService.java diff --git a/src/main/java/bio/overture/ego/controller/VisaController.java b/src/main/java/bio/overture/ego/controller/VisaController.java new file mode 100644 index 000000000..e6a44a51b --- /dev/null +++ b/src/main/java/bio/overture/ego/controller/VisaController.java @@ -0,0 +1,103 @@ +package bio.overture.ego.controller; + +import static bio.overture.ego.controller.resolver.PageableResolver.*; +import static org.springframework.web.bind.annotation.RequestMethod.*; + +import bio.overture.ego.model.dto.*; +import bio.overture.ego.model.entity.*; +import bio.overture.ego.security.AdminScoped; +import bio.overture.ego.service.*; +import bio.overture.ego.view.Views; +import com.fasterxml.jackson.annotation.JsonView; +import io.swagger.annotations.*; +import java.util.UUID; +import lombok.NonNull; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Pageable; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.*; +import springfox.documentation.annotations.ApiIgnore; + +@Slf4j +@RestController +@RequestMapping("/visa") +@Api(tags = "Visa") +public class VisaController { + + /** Dependencies */ + private final VisaService visaService; + + private final UserPermissionService userPermissionService; + private final GroupPermissionService groupPermissionService; + private final ApplicationPermissionService applicationPermissionService; + + @Autowired + public VisaController( + @NonNull VisaService visaService, + @NonNull UserPermissionService userPermissionService, + @NonNull GroupPermissionService groupPermissionService, + @NonNull ApplicationPermissionService applicationPermissionService) { + this.visaService = visaService; + this.groupPermissionService = groupPermissionService; + this.userPermissionService = userPermissionService; + this.applicationPermissionService = applicationPermissionService; + } + + @AdminScoped + @RequestMapping(method = GET, value = "/{id}") + @ApiResponses( + value = {@ApiResponse(code = 200, message = "Get Visa by id", response = Visa.class)}) + @JsonView(Views.REST.class) + public @ResponseBody Visa getVisa( + @ApiIgnore @RequestHeader(value = "Authorization", required = true) + final String authorization, + @PathVariable(value = "id", required = true) UUID id) { + return visaService.getById(id); + } + + @AdminScoped + @RequestMapping(method = GET, value = "") + @ApiResponses(value = {@ApiResponse(code = 200, message = "All Visas")}) + @JsonView(Views.REST.class) + public @ResponseBody PageDTO listVisa( + @ApiIgnore @RequestHeader(value = "Authorization", required = true) + final String authorization, + @ApiIgnore Pageable pageable) { + return new PageDTO<>(visaService.listVisa(pageable)); + } + + @AdminScoped + @RequestMapping(method = POST, value = "") + @ApiResponses( + value = { + @ApiResponse(code = 200, message = "New Visa", response = Visa.class), + }) + public @ResponseBody Visa createVisa( + @ApiIgnore @RequestHeader(value = "Authorization", required = true) + final String authorization, + @RequestBody(required = true) VisaRequest visaRequest) { + return visaService.create(visaRequest); + } + + @AdminScoped + @RequestMapping(method = PUT, value = "/{id}") + @ApiResponses(value = {@ApiResponse(code = 200, message = "Update Visa", response = Visa.class)}) + public @ResponseBody Visa updateVisa( + @ApiIgnore @RequestHeader(value = "Authorization", required = true) + final String authorization, + @PathVariable(value = "id") UUID id, + @RequestBody(required = true) VisaRequest visaRequest) { + return visaService.partialUpdate(id, visaRequest); + } + + @AdminScoped + @RequestMapping(method = DELETE, value = "/{id}") + @ResponseStatus(value = HttpStatus.OK) + public void deleteVisa( + @ApiIgnore @RequestHeader(value = "Authorization", required = true) + final String authorization, + @PathVariable(value = "id", required = true) UUID id) { + visaService.delete(id); + } +} diff --git a/src/main/java/bio/overture/ego/model/dto/VisaRequest.java b/src/main/java/bio/overture/ego/model/dto/VisaRequest.java new file mode 100644 index 000000000..dcf7a0d01 --- /dev/null +++ b/src/main/java/bio/overture/ego/model/dto/VisaRequest.java @@ -0,0 +1,24 @@ +package bio.overture.ego.model.dto; + +import javax.validation.constraints.NotNull; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class VisaRequest { + + @NotNull private String id; + + @NotNull private String type; + + @NotNull private String source; + + @NotNull private String value; + + @NotNull private String by; +} diff --git a/src/main/java/bio/overture/ego/model/entity/Visa.java b/src/main/java/bio/overture/ego/model/entity/Visa.java new file mode 100644 index 000000000..295c7bdc6 --- /dev/null +++ b/src/main/java/bio/overture/ego/model/entity/Visa.java @@ -0,0 +1,67 @@ +package bio.overture.ego.model.entity; + +import bio.overture.ego.model.enums.JavaFields; +import bio.overture.ego.model.enums.SqlFields; +import bio.overture.ego.model.enums.Tables; +import bio.overture.ego.view.Views; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import com.fasterxml.jackson.annotation.JsonView; +import java.util.UUID; +import javax.persistence.*; +import javax.validation.constraints.NotNull; +import lombok.*; +import lombok.experimental.FieldNameConstants; +import org.hibernate.annotations.GenericGenerator; + +@Entity +@Table(name = Tables.GA4GHVISA) +@JsonInclude() +@JsonPropertyOrder({ + JavaFields.ID, + JavaFields.TYPE, + JavaFields.SOURCE, + JavaFields.VALUE, + JavaFields.BY +}) +@JsonView(Views.REST.class) +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +@FieldNameConstants +@EqualsAndHashCode(of = {"id"}) +@NamedEntityGraph( + name = "policy-entity-with-relationships", + attributeNodes = { + @NamedAttributeNode(value = JavaFields.USERPERMISSIONS), + @NamedAttributeNode(value = JavaFields.GROUPPERMISSIONS), + }) +public class Visa implements Identifiable { + + @Id + @Column(name = SqlFields.ID, updatable = false, nullable = false) + @GenericGenerator(name = "visa_uuid", strategy = "org.hibernate.id.UUIDGenerator") + @GeneratedValue(generator = "visa_uuid") + private UUID id; + + @NotNull + @Column(name = SqlFields.TYPE, nullable = false) + @JsonView({Views.JWTAccessToken.class, Views.REST.class}) + private String type; + + @NotNull + @JsonView({Views.JWTAccessToken.class, Views.REST.class}) + @Column(name = SqlFields.SOURCE) + private String source; + + @NotNull + @JsonView({Views.JWTAccessToken.class, Views.REST.class}) + @Column(name = SqlFields.VALUE) + private String value; + + @NotNull + @JsonView({Views.JWTAccessToken.class, Views.REST.class}) + @Column(name = SqlFields.BY) + private String by; +} diff --git a/src/main/java/bio/overture/ego/model/enums/JavaFields.java b/src/main/java/bio/overture/ego/model/enums/JavaFields.java index 7ec650a4e..38f9df6c1 100644 --- a/src/main/java/bio/overture/ego/model/enums/JavaFields.java +++ b/src/main/java/bio/overture/ego/model/enums/JavaFields.java @@ -66,4 +66,9 @@ public class JavaFields { public static final String PROVIDERTYPE = "providerType"; public static final String PROVIDER_SUBJECT_ID = "providerSubjectId"; public static final String ERROR_REDIRECT_URI = "errorRedirectUri"; + // Visas Added + public static final String SOURCE = "source"; + public static final String VALUE = "value"; + + public static final String BY = "by"; } diff --git a/src/main/java/bio/overture/ego/model/enums/SqlFields.java b/src/main/java/bio/overture/ego/model/enums/SqlFields.java index 5fde6918d..afc7d0845 100644 --- a/src/main/java/bio/overture/ego/model/enums/SqlFields.java +++ b/src/main/java/bio/overture/ego/model/enums/SqlFields.java @@ -38,4 +38,8 @@ public class SqlFields { public static final String PROVIDERSUBJECTID = "providersubjectid"; public static final String INITIALIZED = "initialized"; public static final String ERRORREDIRECTURI = "errorredirecturi"; + public static final String SOURCE = "source"; + public static final String VALUE = "value"; + + public static final String BY = "by"; } diff --git a/src/main/java/bio/overture/ego/model/enums/Tables.java b/src/main/java/bio/overture/ego/model/enums/Tables.java index 9eab02c90..50ec199aa 100644 --- a/src/main/java/bio/overture/ego/model/enums/Tables.java +++ b/src/main/java/bio/overture/ego/model/enums/Tables.java @@ -22,4 +22,6 @@ public class Tables { public static final String APPLICATION_PERMISSION = "applicationpermission"; public static final String DEFAULTPROVIDERTRIPWIRE = "defaultprovidertripwire"; public static final String INITTRIPWIRE = "inittripwire"; + + public static final String GA4GHVISA = "ga4ghvisa"; } diff --git a/src/main/java/bio/overture/ego/model/enums/VisaType.java b/src/main/java/bio/overture/ego/model/enums/VisaType.java new file mode 100644 index 000000000..0eb87dab1 --- /dev/null +++ b/src/main/java/bio/overture/ego/model/enums/VisaType.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2017. The Ontario Institute for Cancer Research. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package bio.overture.ego.model.enums; + +import static bio.overture.ego.utils.Joiners.COMMA; +import static bio.overture.ego.utils.Streams.stream; +import static java.lang.String.format; + +import lombok.NonNull; +import lombok.RequiredArgsConstructor; + +@RequiredArgsConstructor +public enum VisaType { + STANDARD_VISA_TYPE, + CUSTOM_VISA_TYPE; + + public static VisaType resolveStatusType(@NonNull String statusType) { + return stream(values()) + .filter(x -> x.toString().equals(statusType)) + .findFirst() + .orElseThrow( + () -> + new IllegalArgumentException( + format( + "The status type '%s' cannot be resolved. Must be one of: [%s]", + statusType, COMMA.join(values())))); + } + + @Override + public String toString() { + return this.name(); + } +} diff --git a/src/main/java/bio/overture/ego/repository/VisaRepository.java b/src/main/java/bio/overture/ego/repository/VisaRepository.java new file mode 100644 index 000000000..50d1ec130 --- /dev/null +++ b/src/main/java/bio/overture/ego/repository/VisaRepository.java @@ -0,0 +1,16 @@ +package bio.overture.ego.repository; + +import bio.overture.ego.model.entity.Visa; +import java.util.List; +import java.util.Optional; +import java.util.UUID; + +public interface VisaRepository extends NamedRepository { + @Override + @Deprecated + default Optional findByName(String name) { + return null; + } + + List findAll(); +} diff --git a/src/main/java/bio/overture/ego/service/VisaService.java b/src/main/java/bio/overture/ego/service/VisaService.java new file mode 100644 index 000000000..c8ac9968d --- /dev/null +++ b/src/main/java/bio/overture/ego/service/VisaService.java @@ -0,0 +1,91 @@ +package bio.overture.ego.service; + +import static bio.overture.ego.model.exceptions.NotFoundException.checkNotFound; +import static bio.overture.ego.model.exceptions.RequestValidationException.checkRequestValid; +import static org.mapstruct.factory.Mappers.getMapper; + +import bio.overture.ego.event.token.ApiKeyEventsPublisher; +import bio.overture.ego.model.dto.PolicyRequest; +import bio.overture.ego.model.dto.VisaRequest; +import bio.overture.ego.model.entity.Policy; +import bio.overture.ego.model.entity.Visa; +import bio.overture.ego.repository.VisaRepository; +import java.util.Optional; +import java.util.UUID; +import lombok.NonNull; +import lombok.extern.slf4j.Slf4j; +import lombok.val; +import org.mapstruct.Mapper; +import org.mapstruct.MappingTarget; +import org.mapstruct.NullValueCheckStrategy; +import org.mapstruct.ReportingPolicy; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Slf4j +@Service +@Transactional +public class VisaService extends AbstractNamedService { + + /** Constants */ + private static final VisaService.VisaConverter VISA_CONVERTER = getMapper(VisaService.VisaConverter.class); + + /** Dependencies */ + @Autowired + + private VisaRepository visaRepository; + + private final ApiKeyEventsPublisher apiKeyEventsPublisher; + + @Autowired + public VisaService( + @NonNull VisaRepository visaRepository, + @NonNull ApiKeyEventsPublisher apiKeyEventsPublisher) { + super(Visa.class, visaRepository); + this.visaRepository = visaRepository; + this.apiKeyEventsPublisher = apiKeyEventsPublisher; + } + + public Visa create(@NonNull VisaRequest createRequest) { + checkRequestValid(createRequest); + val visa = VISA_CONVERTER.convertToVisa(createRequest); + return getRepository().save(visa); + } + + @Override + public Visa getById(@NonNull UUID uuid) { + val result = (Optional) getRepository().findById(uuid); + checkNotFound(result.isPresent(), "The visaId '%s' does not exist", uuid); + return result.get(); + } + + public void delete(@NonNull UUID id) { + checkExistence(id); + super.delete(id); + } + + @Override + public Visa getWithRelationships(UUID uuid) { + return null; + } + + public Page listVisa(@NonNull Pageable pageable) { + return visaRepository.findAll(pageable); + } + + public Visa partialUpdate(@NonNull UUID id, @NonNull VisaRequest updateRequest) { + val visa = getById(id); + VISA_CONVERTER.updateVisa(updateRequest, visa); + return getRepository().save(visa); + } + @Mapper( + nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS, + unmappedTargetPolicy = ReportingPolicy.WARN) + public abstract static class VisaConverter { + public abstract Visa convertToVisa(VisaRequest request); + public abstract void updateVisa(VisaRequest request, @MappingTarget Visa visaToUpdate); + + }} From 8da9be8be8729850fc315da0d2e589fa3b2b4cf4 Mon Sep 17 00:00:00 2001 From: Azher2Ali <121898125+Azher2Ali@users.noreply.github.com> Date: Fri, 14 Apr 2023 12:18:22 -0400 Subject: [PATCH 2/4] commiting changes related to visa implementation --- .../ego/controller/VisaController.java | 5 ++-- .../overture/ego/model/dto/VisaRequest.java | 3 ++- .../ego/model/dto/VisaUpdateRequest.java | 25 ++++++++++++++++++ .../bio/overture/ego/model/entity/Visa.java | 6 ----- .../bio/overture/ego/service/VisaService.java | 26 +++++++++---------- .../resources/flyway/sql/V1_22__add_visa.sql | 8 ++++++ 6 files changed, 50 insertions(+), 23 deletions(-) create mode 100644 src/main/java/bio/overture/ego/model/dto/VisaUpdateRequest.java create mode 100644 src/main/resources/flyway/sql/V1_22__add_visa.sql diff --git a/src/main/java/bio/overture/ego/controller/VisaController.java b/src/main/java/bio/overture/ego/controller/VisaController.java index e6a44a51b..f0b56c4a0 100644 --- a/src/main/java/bio/overture/ego/controller/VisaController.java +++ b/src/main/java/bio/overture/ego/controller/VisaController.java @@ -86,9 +86,8 @@ public VisaController( public @ResponseBody Visa updateVisa( @ApiIgnore @RequestHeader(value = "Authorization", required = true) final String authorization, - @PathVariable(value = "id") UUID id, - @RequestBody(required = true) VisaRequest visaRequest) { - return visaService.partialUpdate(id, visaRequest); + @RequestBody(required = true) VisaUpdateRequest visaRequest) { + return visaService.partialUpdate(visaRequest); } @AdminScoped diff --git a/src/main/java/bio/overture/ego/model/dto/VisaRequest.java b/src/main/java/bio/overture/ego/model/dto/VisaRequest.java index dcf7a0d01..2a60d7a60 100644 --- a/src/main/java/bio/overture/ego/model/dto/VisaRequest.java +++ b/src/main/java/bio/overture/ego/model/dto/VisaRequest.java @@ -1,5 +1,6 @@ package bio.overture.ego.model.dto; +import java.util.UUID; import javax.validation.constraints.NotNull; import lombok.AllArgsConstructor; import lombok.Builder; @@ -12,7 +13,7 @@ @NoArgsConstructor public class VisaRequest { - @NotNull private String id; + private UUID id; @NotNull private String type; diff --git a/src/main/java/bio/overture/ego/model/dto/VisaUpdateRequest.java b/src/main/java/bio/overture/ego/model/dto/VisaUpdateRequest.java new file mode 100644 index 000000000..d7008a759 --- /dev/null +++ b/src/main/java/bio/overture/ego/model/dto/VisaUpdateRequest.java @@ -0,0 +1,25 @@ +package bio.overture.ego.model.dto; + +import java.util.UUID; +import javax.validation.constraints.NotNull; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class VisaUpdateRequest { + + @NotNull private UUID id; + + @NotNull private String type; + + @NotNull private String source; + + @NotNull private String value; + + @NotNull private String by; +} diff --git a/src/main/java/bio/overture/ego/model/entity/Visa.java b/src/main/java/bio/overture/ego/model/entity/Visa.java index 295c7bdc6..b4204f4c8 100644 --- a/src/main/java/bio/overture/ego/model/entity/Visa.java +++ b/src/main/java/bio/overture/ego/model/entity/Visa.java @@ -31,12 +31,6 @@ @AllArgsConstructor @FieldNameConstants @EqualsAndHashCode(of = {"id"}) -@NamedEntityGraph( - name = "policy-entity-with-relationships", - attributeNodes = { - @NamedAttributeNode(value = JavaFields.USERPERMISSIONS), - @NamedAttributeNode(value = JavaFields.GROUPPERMISSIONS), - }) public class Visa implements Identifiable { @Id diff --git a/src/main/java/bio/overture/ego/service/VisaService.java b/src/main/java/bio/overture/ego/service/VisaService.java index c8ac9968d..7adc66f08 100644 --- a/src/main/java/bio/overture/ego/service/VisaService.java +++ b/src/main/java/bio/overture/ego/service/VisaService.java @@ -5,9 +5,8 @@ import static org.mapstruct.factory.Mappers.getMapper; import bio.overture.ego.event.token.ApiKeyEventsPublisher; -import bio.overture.ego.model.dto.PolicyRequest; import bio.overture.ego.model.dto.VisaRequest; -import bio.overture.ego.model.entity.Policy; +import bio.overture.ego.model.dto.VisaUpdateRequest; import bio.overture.ego.model.entity.Visa; import bio.overture.ego.repository.VisaRepository; import java.util.Optional; @@ -31,12 +30,11 @@ public class VisaService extends AbstractNamedService { /** Constants */ - private static final VisaService.VisaConverter VISA_CONVERTER = getMapper(VisaService.VisaConverter.class); + private static final VisaService.VisaConverter VISA_CONVERTER = + getMapper(VisaService.VisaConverter.class); /** Dependencies */ - @Autowired - - private VisaRepository visaRepository; + @Autowired private VisaRepository visaRepository; private final ApiKeyEventsPublisher apiKeyEventsPublisher; @@ -76,16 +74,18 @@ public Page listVisa(@NonNull Pageable pageable) { return visaRepository.findAll(pageable); } - public Visa partialUpdate(@NonNull UUID id, @NonNull VisaRequest updateRequest) { - val visa = getById(id); + public Visa partialUpdate(@NonNull VisaUpdateRequest updateRequest) { + val visa = getById(updateRequest.getId()); VISA_CONVERTER.updateVisa(updateRequest, visa); return getRepository().save(visa); } + @Mapper( - nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS, - unmappedTargetPolicy = ReportingPolicy.WARN) + nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS, + unmappedTargetPolicy = ReportingPolicy.WARN) public abstract static class VisaConverter { - public abstract Visa convertToVisa(VisaRequest request); - public abstract void updateVisa(VisaRequest request, @MappingTarget Visa visaToUpdate); + public abstract Visa convertToVisa(VisaRequest request); - }} + public abstract void updateVisa(VisaUpdateRequest request, @MappingTarget Visa visaToUpdate); + } +} diff --git a/src/main/resources/flyway/sql/V1_22__add_visa.sql b/src/main/resources/flyway/sql/V1_22__add_visa.sql new file mode 100644 index 000000000..bf99727bf --- /dev/null +++ b/src/main/resources/flyway/sql/V1_22__add_visa.sql @@ -0,0 +1,8 @@ +CREATE TABLE GA4GHVISA ( + id UUID PRIMARY KEY, + type varchar(255) NOT NULL, + source varchar(255) NOT NULL, + value varchar(255) NOT NULL, + by varchar(255) NOT NULL +); + From 409b7997d07ccec03da79f6a09e835df765229fb Mon Sep 17 00:00:00 2001 From: Azher2Ali <121898125+Azher2Ali@users.noreply.github.com> Date: Fri, 21 Apr 2023 00:30:22 -0400 Subject: [PATCH 3/4] Committing changes related to visa update api review comment changes --- .../java/bio/overture/ego/controller/VisaController.java | 3 ++- .../java/bio/overture/ego/model/dto/VisaUpdateRequest.java | 3 --- src/main/java/bio/overture/ego/service/VisaService.java | 5 +++-- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/main/java/bio/overture/ego/controller/VisaController.java b/src/main/java/bio/overture/ego/controller/VisaController.java index f0b56c4a0..c1e71b29d 100644 --- a/src/main/java/bio/overture/ego/controller/VisaController.java +++ b/src/main/java/bio/overture/ego/controller/VisaController.java @@ -86,8 +86,9 @@ public VisaController( public @ResponseBody Visa updateVisa( @ApiIgnore @RequestHeader(value = "Authorization", required = true) final String authorization, + @PathVariable(value = "id", required = true) UUID id, @RequestBody(required = true) VisaUpdateRequest visaRequest) { - return visaService.partialUpdate(visaRequest); + return visaService.partialUpdate(id, visaRequest); } @AdminScoped diff --git a/src/main/java/bio/overture/ego/model/dto/VisaUpdateRequest.java b/src/main/java/bio/overture/ego/model/dto/VisaUpdateRequest.java index d7008a759..ecf7d08f2 100644 --- a/src/main/java/bio/overture/ego/model/dto/VisaUpdateRequest.java +++ b/src/main/java/bio/overture/ego/model/dto/VisaUpdateRequest.java @@ -1,6 +1,5 @@ package bio.overture.ego.model.dto; -import java.util.UUID; import javax.validation.constraints.NotNull; import lombok.AllArgsConstructor; import lombok.Builder; @@ -13,8 +12,6 @@ @NoArgsConstructor public class VisaUpdateRequest { - @NotNull private UUID id; - @NotNull private String type; @NotNull private String source; diff --git a/src/main/java/bio/overture/ego/service/VisaService.java b/src/main/java/bio/overture/ego/service/VisaService.java index 7adc66f08..191f89b81 100644 --- a/src/main/java/bio/overture/ego/service/VisaService.java +++ b/src/main/java/bio/overture/ego/service/VisaService.java @@ -11,6 +11,7 @@ import bio.overture.ego.repository.VisaRepository; import java.util.Optional; import java.util.UUID; +import javax.validation.constraints.NotNull; import lombok.NonNull; import lombok.extern.slf4j.Slf4j; import lombok.val; @@ -74,8 +75,8 @@ public Page listVisa(@NonNull Pageable pageable) { return visaRepository.findAll(pageable); } - public Visa partialUpdate(@NonNull VisaUpdateRequest updateRequest) { - val visa = getById(updateRequest.getId()); + public Visa partialUpdate(@NotNull UUID id, @NonNull VisaUpdateRequest updateRequest) { + val visa = getById(id); VISA_CONVERTER.updateVisa(updateRequest, visa); return getRepository().save(visa); } From 07d4ead86ca9101721d8886da6e3092c67a85569 Mon Sep 17 00:00:00 2001 From: Azher2Ali <121898125+Azher2Ali@users.noreply.github.com> Date: Fri, 21 Apr 2023 00:39:07 -0400 Subject: [PATCH 4/4] Committing changes related to visa update api review comment changes --- .../ego/controller/VisaController.java | 2 +- .../overture/ego/model/dto/VisaRequest.java | 3 --- .../ego/model/dto/VisaUpdateRequest.java | 22 ------------------- .../bio/overture/ego/service/VisaService.java | 5 ++--- 4 files changed, 3 insertions(+), 29 deletions(-) delete mode 100644 src/main/java/bio/overture/ego/model/dto/VisaUpdateRequest.java diff --git a/src/main/java/bio/overture/ego/controller/VisaController.java b/src/main/java/bio/overture/ego/controller/VisaController.java index c1e71b29d..853400cdc 100644 --- a/src/main/java/bio/overture/ego/controller/VisaController.java +++ b/src/main/java/bio/overture/ego/controller/VisaController.java @@ -87,7 +87,7 @@ public VisaController( @ApiIgnore @RequestHeader(value = "Authorization", required = true) final String authorization, @PathVariable(value = "id", required = true) UUID id, - @RequestBody(required = true) VisaUpdateRequest visaRequest) { + @RequestBody(required = true) VisaRequest visaRequest) { return visaService.partialUpdate(id, visaRequest); } diff --git a/src/main/java/bio/overture/ego/model/dto/VisaRequest.java b/src/main/java/bio/overture/ego/model/dto/VisaRequest.java index 2a60d7a60..6225d995a 100644 --- a/src/main/java/bio/overture/ego/model/dto/VisaRequest.java +++ b/src/main/java/bio/overture/ego/model/dto/VisaRequest.java @@ -1,6 +1,5 @@ package bio.overture.ego.model.dto; -import java.util.UUID; import javax.validation.constraints.NotNull; import lombok.AllArgsConstructor; import lombok.Builder; @@ -13,8 +12,6 @@ @NoArgsConstructor public class VisaRequest { - private UUID id; - @NotNull private String type; @NotNull private String source; diff --git a/src/main/java/bio/overture/ego/model/dto/VisaUpdateRequest.java b/src/main/java/bio/overture/ego/model/dto/VisaUpdateRequest.java deleted file mode 100644 index ecf7d08f2..000000000 --- a/src/main/java/bio/overture/ego/model/dto/VisaUpdateRequest.java +++ /dev/null @@ -1,22 +0,0 @@ -package bio.overture.ego.model.dto; - -import javax.validation.constraints.NotNull; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; - -@Data -@Builder -@AllArgsConstructor -@NoArgsConstructor -public class VisaUpdateRequest { - - @NotNull private String type; - - @NotNull private String source; - - @NotNull private String value; - - @NotNull private String by; -} diff --git a/src/main/java/bio/overture/ego/service/VisaService.java b/src/main/java/bio/overture/ego/service/VisaService.java index 191f89b81..9f5b07a66 100644 --- a/src/main/java/bio/overture/ego/service/VisaService.java +++ b/src/main/java/bio/overture/ego/service/VisaService.java @@ -6,7 +6,6 @@ import bio.overture.ego.event.token.ApiKeyEventsPublisher; import bio.overture.ego.model.dto.VisaRequest; -import bio.overture.ego.model.dto.VisaUpdateRequest; import bio.overture.ego.model.entity.Visa; import bio.overture.ego.repository.VisaRepository; import java.util.Optional; @@ -75,7 +74,7 @@ public Page listVisa(@NonNull Pageable pageable) { return visaRepository.findAll(pageable); } - public Visa partialUpdate(@NotNull UUID id, @NonNull VisaUpdateRequest updateRequest) { + public Visa partialUpdate(@NotNull UUID id, @NonNull VisaRequest updateRequest) { val visa = getById(id); VISA_CONVERTER.updateVisa(updateRequest, visa); return getRepository().save(visa); @@ -87,6 +86,6 @@ public Visa partialUpdate(@NotNull UUID id, @NonNull VisaUpdateRequest updateReq public abstract static class VisaConverter { public abstract Visa convertToVisa(VisaRequest request); - public abstract void updateVisa(VisaUpdateRequest request, @MappingTarget Visa visaToUpdate); + public abstract void updateVisa(VisaRequest request, @MappingTarget Visa visaToUpdate); } }