Skip to content

Commit

Permalink
Updating spring dependencies
Browse files Browse the repository at this point in the history
Updating hateos dependencies
  • Loading branch information
Mme-adorsys committed Sep 6, 2023
1 parent 2392ea8 commit 582127a
Show file tree
Hide file tree
Showing 18 changed files with 124 additions and 125 deletions.
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
package de.adorsys.multibanking.logging;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.reflect.FieldUtils;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.reflect.MethodSignature;
import org.slf4j.Marker;
import org.slf4j.MarkerFactory;
import org.springframework.hateoas.Resource;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.util.List;

@Slf4j
@Aspect
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.hateoas.CollectionModel;
import org.springframework.hateoas.EntityModel;
import org.springframework.hateoas.Link;
import org.springframework.hateoas.Resource;
import org.springframework.hateoas.Resources;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
Expand All @@ -34,8 +34,8 @@
import java.util.List;

import static java.util.stream.Collectors.toList;
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo;
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.methodOn;
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.linkTo;
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.methodOn;

@Timed("bank-access")
@Tag(name = "Bankaccess")
Expand Down Expand Up @@ -79,26 +79,26 @@ public ResponseEntity createBankAccess(@RequestBody BankAccessTO bankAccess) {
e.getAuthorisationId())).withSelfRel());
links.add(linkTo(methodOn(ConsentAuthorisationController.class).transactionAuthorisation(e.getConsentId(),
e.getAuthorisationId(), null)).withRel("transactionAuthorisation"));
return ResponseEntity.accepted().body(new Resource<>(consentAuthorisationMapper.toUpdateAuthResponseTO(e.getResponse()), links));
return ResponseEntity.accepted().body(EntityModel.of(consentAuthorisationMapper.toUpdateAuthResponseTO(e.getResponse()), links));
}
}

@Operation(description = "Read bank accesses", security = {
@SecurityRequirement(name = "multibanking_auth", scopes = "openid")})
@GetMapping
public Resources<Resource<BankAccessTO>> getBankAccesses() {
public CollectionModel<EntityModel<BankAccessTO>> getBankAccesses() {
if (!userRepository.exists(principal.getName())) {
return new Resources<>(Collections.emptyList());
return CollectionModel.empty();
}

List<BankAccessEntity> accessEntities = bankAccessRepository.findByUserId(principal.getName());
return new Resources<>(mapToResources(accessEntities));
return CollectionModel.of(mapToEntityModels(accessEntities));
}

@Operation(description = "Read bank access", security = {
@SecurityRequirement(name = "multibanking_auth", scopes = "openid")})
@GetMapping("/{accessId}")
public Resource<BankAccessTO> getBankAccess(@PathVariable String accessId) {
public EntityModel<BankAccessTO> getBankAccess(@PathVariable String accessId) {
BankAccessEntity bankAccessEntity = bankAccessRepository.findByUserIdAndId(principal.getName(), accessId)
.orElseThrow(() -> new ResourceNotFoundException(BankAccessEntity.class, accessId));

Expand Down Expand Up @@ -130,14 +130,14 @@ public HttpEntity<Void> deleteBankAccess(@PathVariable String accessId) {
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}

private List<Resource<BankAccessTO>> mapToResources(List<BankAccessEntity> accessEntities) {
private List<EntityModel<BankAccessTO>> mapToEntityModels(List<BankAccessEntity> accessEntities) {
return accessEntities.stream()
.map(this::mapToResource)
.collect(toList());
}

private Resource<BankAccessTO> mapToResource(BankAccessEntity accessEntity) {
return new Resource<>(bankAccessMapper.toBankAccessTO(accessEntity),
private EntityModel<BankAccessTO> mapToResource(BankAccessEntity accessEntity) {
return EntityModel.of(bankAccessMapper.toBankAccessTO(accessEntity),
linkTo(methodOn(BankAccessController.class).getBankAccess(accessEntity.getId())).withSelfRel(),
linkTo(methodOn(BankAccountController.class).getBankAccounts(accessEntity.getId())).withRel("accounts"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.hateoas.Resource;
import org.springframework.hateoas.EntityModel;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
Expand All @@ -41,8 +41,8 @@ public class BankAccountAnalyticsController {
@Operation(description = "Read account analytics", security = {
@SecurityRequirement(name = "multibanking_auth", scopes = "openid")})
@GetMapping
public Resource<AnalyticsTO> getAccountAnalytics(@PathVariable String accessId,
@PathVariable String accountId) {
public EntityModel<AnalyticsTO> getAccountAnalytics(@PathVariable String accessId,
@PathVariable String accountId) {
if (!bankAccessRepository.exists(accessId)) {
throw new ResourceNotFoundException(BankAccessEntity.class, accessId);
}
Expand All @@ -60,6 +60,6 @@ public Resource<AnalyticsTO> getAccountAnalytics(@PathVariable String accessId,
"user-id: " + principal.getName()
));

return new Resource<>(analyticsMapper.toAnalyticsTO(accountAnalyticsEntity));
return EntityModel.of(analyticsMapper.toAnalyticsTO(accountAnalyticsEntity));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.hateoas.CollectionModel;
import org.springframework.hateoas.EntityModel;
import org.springframework.hateoas.Link;
import org.springframework.hateoas.Resource;
import org.springframework.hateoas.Resources;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
Expand All @@ -36,8 +36,8 @@

import static de.adorsys.multibanking.domain.ScaStatus.FINALISED;
import static java.util.stream.Collectors.toList;
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo;
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.methodOn;
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.linkTo;
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.methodOn;

@Timed("bank-account")
@Tag(name = "Bankaccount")
Expand All @@ -62,15 +62,15 @@ public class BankAccountController {
@Content(schema = @Schema(implementation = Messages.class))
})
@GetMapping
public Resources<Resource<BankAccountTO>> getBankAccounts(@PathVariable String accessId) {
public CollectionModel<EntityModel<BankAccountTO>> getBankAccounts(@PathVariable String accessId) {
List<BankAccountEntity> bankAccounts = bankAccountService.getBankAccounts(principal.getName(), accessId);
return new Resources<>(mapToResources(bankAccounts, accessId));
return CollectionModel.of(mapToResources(bankAccounts, accessId));
}

@Operation(description = "Read bank account", security = {
@SecurityRequirement(name = "multibanking_auth", scopes = "openid")})
@GetMapping("/{accountId}")
public Resource<BankAccountTO> getBankAccount(@PathVariable String accessId,
public EntityModel<BankAccountTO> getBankAccount(@PathVariable String accessId,
@PathVariable("accountId") String accountId) {
if (!bankAccessRepository.exists(accessId)) {
throw new ResourceNotFoundException(BankAccessEntity.class, accessId);
Expand Down Expand Up @@ -111,18 +111,18 @@ public ResponseEntity syncBookings(@PathVariable String accessId, @PathVariable
e.getAuthorisationId())).withSelfRel());
links.add(linkTo(methodOn(ConsentAuthorisationController.class).transactionAuthorisation(e.getConsentId(),
e.getAuthorisationId(), null)).withRel("transactionAuthorisation"));
return ResponseEntity.accepted().body(new Resource<>(consentAuthorisationMapper.toUpdateAuthResponseTO(e.getResponse()), links));
return ResponseEntity.accepted().body(EntityModel.of(consentAuthorisationMapper.toUpdateAuthResponseTO(e.getResponse()), links));
}
}

private List<Resource<BankAccountTO>> mapToResources(List<BankAccountEntity> accountEntities, String accessId) {
private List<EntityModel<BankAccountTO>> mapToResources(List<BankAccountEntity> accountEntities, String accessId) {
return accountEntities.stream()
.map(accountEntity -> mapToResource(accountEntity, accessId))
.collect(toList());
}

private Resource<BankAccountTO> mapToResource(BankAccountEntity accountEntity, String accessId) {
return new Resource<>(bankAccountMapper.toBankAccountTO(accountEntity),
private EntityModel<BankAccountTO> mapToResource(BankAccountEntity accountEntity, String accessId) {
return EntityModel.of(bankAccountMapper.toBankAccountTO(accountEntity),
linkTo(methodOn(BankAccountController.class).getBankAccount(accessId, accountEntity.getId())).withSelfRel(),
linkTo(methodOn(BankAccessController.class).getBankAccess(accessId)).withRel("bankAccess"),
linkTo(methodOn(BankAccountAnalyticsController.class).getAccountAnalytics(accessId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.hateoas.Resource;
import org.springframework.hateoas.Resources;
import org.springframework.hateoas.CollectionModel;
import org.springframework.hateoas.EntityModel;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
Expand All @@ -22,8 +22,8 @@
import java.util.List;

import static java.util.stream.Collectors.toList;
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo;
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.methodOn;
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.linkTo;
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.methodOn;

@Tag(name = "Bank")
@RequiredArgsConstructor
Expand All @@ -38,7 +38,7 @@ public class BankController {

@Operation(description = "get bank by bank code")
@GetMapping(value = "/{bankCode}")
public Resource<BankTO> getBank(@PathVariable String bankCode) {
public EntityModel<BankTO> getBank(@PathVariable String bankCode) {
long start = System.currentTimeMillis();
Exception exception = null;

Expand All @@ -56,8 +56,8 @@ public Resource<BankTO> getBank(@PathVariable String bankCode) {
@Timed("bank")
@Operation(description = "find bank")
@GetMapping
public Resources<Resource<BankTO>> searchBank(@RequestParam String query) {
return new Resources<>(mapToResources(bankService.search(query)));
public CollectionModel<EntityModel<BankTO>> searchBank(@RequestParam String query) {
return CollectionModel.of(mapToResources(bankService.search(query)));
}

@Timed("bank")
Expand All @@ -73,14 +73,14 @@ public HttpEntity<Void> uploadBanks(@RequestParam MultipartFile banksFile) {
}
}

private List<Resource<BankTO>> mapToResources(List<BankEntity> entities) {
private List<EntityModel<BankTO>> mapToResources(List<BankEntity> entities) {
return entities.stream()
.map(this::mapToResource)
.collect(toList());
}

private Resource<BankTO> mapToResource(BankEntity entity) {
return new Resource<>(bankMapper.toBankTO(entity),
private EntityModel<BankTO> mapToResource(BankEntity entity) {
return EntityModel.of(bankMapper.toBankTO(entity),
linkTo(methodOn(BankController.class).getBank(entity.getBankCode())).withSelfRel());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
import org.springframework.data.domain.Sort;
import org.springframework.data.web.PageableDefault;
import org.springframework.data.web.PagedResourcesAssembler;
import org.springframework.hateoas.Resource;
import org.springframework.hateoas.Resources;
import org.springframework.hateoas.CollectionModel;
import org.springframework.hateoas.EntityModel;
import org.springframework.http.HttpEntity;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
Expand All @@ -32,8 +32,8 @@
import java.util.List;
import java.util.Optional;

import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo;
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.methodOn;
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.linkTo;
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.methodOn;

@Timed("booking")
@Tag(name = "Booking")
Expand All @@ -55,13 +55,13 @@ public class BookingController {
@Operation(description = "Read account bookings", security = {
@SecurityRequirement(name = "multibanking_auth", scopes = "openid")})
@GetMapping
public Resources<BookingTO> getBookings(@PathVariable String accessId,
@PathVariable String accountId,
@RequestParam(required = false) BankApiTO bankApi,
@RequestParam(required = false) List<String> ids,
@PageableDefault(size = 20, sort = "valutaDate", direction =
public CollectionModel<BookingTO> getBookings(@PathVariable String accessId,
@PathVariable String accountId,
@RequestParam(required = false) BankApiTO bankApi,
@RequestParam(required = false) List<String> ids,
@PageableDefault(size = 20, sort = "valutaDate", direction =
Sort.Direction.DESC) Pageable pageable,
PagedResourcesAssembler assembler) {
PagedResourcesAssembler assembler) {
checkBankAccountExists(accessId, accountId);

if (bankAccountRepository.getSyncStatus(accountId) == BankAccount.SyncStatus.SYNC) {
Expand All @@ -71,20 +71,20 @@ public Resources<BookingTO> getBookings(@PathVariable String accessId,
return Optional.ofNullable(ids)
.map(strings -> {
Iterable<BookingEntity> bookingEntities = bookingService.getBookingsById(principal.getName(), ids);
return new Resources<>(bookingMapper.toBookingTOs(bookingEntities));
return CollectionModel.of(bookingMapper.toBookingTOs(bookingEntities));
})
.orElseGet(() -> {
Page<BookingEntity> bookingEntities = bookingService.getBookingsPageable(pageable,
principal.getName(), accessId, accountId, bankApiMapper.toBankApi(bankApi));
return assembler.toResource(bookingEntities.map(bookingMapper::toBookingTO));
return assembler.toModel(bookingEntities.map(bookingMapper::toBookingTO));
});
}

@Operation(description = "Read account bookings search index", security = {
@SecurityRequirement(name = "multibanking_auth", scopes = "openid")})
@GetMapping("/index")
public Resource<BookingsIndexEntity> getBookingsIndex(@PathVariable String accessId,
@PathVariable String accountId) {
public EntityModel<BookingsIndexEntity> getBookingsIndex(@PathVariable String accessId,
@PathVariable String accountId) {
checkBankAccountExists(accessId, accountId);

if (bankAccountRepository.getSyncStatus(accountId) == BankAccount.SyncStatus.SYNC) {
Expand All @@ -94,7 +94,7 @@ public Resource<BookingsIndexEntity> getBookingsIndex(@PathVariable String acces
BookingsIndexEntity bookingsIndexEntity = bookingService.getSearchIndex(principal.getName(), accountId)
.orElseThrow(() -> new ResourceNotFoundException(BookingsIndexEntity.class, accountId));

return new Resource<>(bookingsIndexEntity);
return EntityModel.of(bookingsIndexEntity);
}

@Operation(description = "Download bookings", security = {
Expand All @@ -111,7 +111,7 @@ public HttpEntity<String> downloadBookings(@PathVariable String accessId, @PathV
@Operation(description = "Read booking", security = {
@SecurityRequirement(name = "multibanking_auth", scopes = "openid")})
@GetMapping("/{bookingId}")
public Resource<BookingTO> getBooking(@PathVariable String accessId, @PathVariable String accountId,
public EntityModel<BookingTO> getBooking(@PathVariable String accessId, @PathVariable String accountId,
@PathVariable String bookingId) {
checkBankAccountExists(accessId, accountId);

Expand All @@ -130,8 +130,8 @@ private void checkBankAccountExists(String accessId, String accountId) {
}
}

private Resource<BookingTO> mapToResource(BookingEntity entity, String accessId, String accountId) {
return new Resource<>(bookingMapper.toBookingTO(entity),
private EntityModel<BookingTO> mapToResource(BookingEntity entity, String accessId, String accountId) {
return EntityModel.of(bookingMapper.toBookingTO(entity),
linkTo(methodOn(BookingController.class).getBooking(accessId, accountId, entity.getId()))
.withSelfRel());
}
Expand Down
Loading

0 comments on commit 582127a

Please sign in to comment.