Skip to content

Commit

Permalink
Fixes based on static analysis (#765)
Browse files Browse the repository at this point in the history
  • Loading branch information
dk2k authored May 7, 2024
1 parent 480ca90 commit 06c843b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

@Service
Expand Down Expand Up @@ -107,7 +108,7 @@ public void chooseDefaultAddress(Long id) {
List<UserAddress> userAddressList = userAddressRepository.findAllByUserId(userId);
List<UserAddress> newUserAddressList = new ArrayList<>();
for (UserAddress userAddress : userAddressList) {
if (userAddress.getAddressId() == id) {
if (Objects.equals(userAddress.getAddressId(), id)) {
userAddress.setIsActive(true);
} else {
userAddress.setIsActive(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -841,10 +841,9 @@ public void updateProductQuantity(List<ProductQuantityPostVm> productQuantityPos
List<Long> productIds = productQuantityPostVms.stream().map(ProductQuantityPostVm::productId).toList();
List<Product> products = productRepository.findAllByIdIn(productIds);
products.parallelStream().forEach(product -> {
ProductQuantityPostVm productQuantityPostVm = productQuantityPostVms.parallelStream()
.filter(productPostVm -> product.getId().equals(productPostVm.productId())).findFirst().get();

product.setStockQuantity(productQuantityPostVm.stockQuantity());
Optional<ProductQuantityPostVm> productQuantityPostVmOptional = productQuantityPostVms.parallelStream()
.filter(productPostVm -> product.getId().equals(productPostVm.productId())).findFirst();
productQuantityPostVmOptional.ifPresent(productQuantityPostVm -> product.setStockQuantity(productQuantityPostVm.stockQuantity()));
});

productRepository.saveAll(products);
Expand Down
25 changes: 10 additions & 15 deletions tax/src/main/java/com/yas/tax/service/TaxRateService.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.yas.tax.service;

import com.yas.tax.exception.DuplicatedException;
import com.yas.tax.exception.NotFoundException;
import com.yas.tax.model.TaxRate;
import com.yas.tax.repository.TaxClassRepository;
Expand Down Expand Up @@ -135,20 +134,16 @@ public TaxRateListGetVm getPageableTaxRates(int pageNo, int pageSize) {
//Call location service to get country names and state or province name by list of state or province ids
List<StateOrProvinceAndCountryGetNameVm> stateOrProvinceAndCountryGetNameVms = locationService.getStateOrProvinceAndCountryNames(stateOrProvinceIds);
taxRates.forEach(taxRate -> {
StateOrProvinceAndCountryGetNameVm stateOrProvinceAndCountryGetNameVm = stateOrProvinceAndCountryGetNameVms.stream()
.filter(x -> x.stateOrProvinceId().equals(taxRate.getStateOrProvinceId()))
.findAny()
.orElse(null);

if(stateOrProvinceAndCountryGetNameVm != null) {
taxRateGetDetailVms.add(new TaxRateGetDetailVm(
taxRate.getId(),
taxRate.getRate(),
taxRate.getZipCode(),
taxRate.getTaxClass().getName(),
stateOrProvinceAndCountryGetNameVm.stateOrProvinceName(),
stateOrProvinceAndCountryGetNameVm.countryName()));
}
stateOrProvinceAndCountryGetNameVms.stream()
.filter(x -> x.stateOrProvinceId().equals(taxRate.getStateOrProvinceId()))
.findAny().ifPresent(stateOrProvinceAndCountryGetNameVm -> taxRateGetDetailVms.add(new TaxRateGetDetailVm(
taxRate.getId(),
taxRate.getRate(),
taxRate.getZipCode(),
taxRate.getTaxClass().getName(),
stateOrProvinceAndCountryGetNameVm.stateOrProvinceName(),
stateOrProvinceAndCountryGetNameVm.countryName())));

});
}

Expand Down

0 comments on commit 06c843b

Please sign in to comment.