Untitled

mail@pastecode.io avatar
unknown
java
2 years ago
1.9 kB
2
Indexable
Never
    public Device getDevice(String basketId, String platformSessionId, Segment segment, String deviceFamily, String deviceId) {
        final ShoppingCart shoppingCart = shoppingCartClient.getShoppingCart(basketId);
        final List<ProductOffering> deviceFamilyDevices = DeviceServiceHelper.filterByDeviceFamily(productCatalogueClient.getProductsByCharacteristicValue(deviceFamily), deviceFamily);
        final ProductOffering selectedDevice = DeviceServiceHelper.getSelectedDevice(deviceFamilyDevices, deviceId);
        Optional<ProductOfferingPrice> devicePrice = Optional.ofNullable(productCatalogueClient
                .getProductOfferingPrice(selectedDevice.getProductOfferingPrice().get(0).getId()));

        ProductSpecification productSpecResponse = productCatalogueClient.getProductSpecificationImages(selectedDevice.getProductSpecification().getId());

        return Device.builder()
                .title(selectedDevice.getName())
                .description(selectedDevice.getDescription())
                .configuration(DeviceServiceHelper.getDeviceConfiguration(platformSessionId, segment, deviceFamilyDevices, selectedDevice))
                .maxAllowedDeviceQty(mobilePillarService.getPlansCoreAmount(shoppingCart) - mobilePillarService.getProductCartItemsAmount(mobilePillarService.getCartItemsAddOn(shoppingCart, AddOnType.Device)))
                .quantity(ADD_VIEW_QUANTITY)
                .images(DeviceServiceHelper.getFilteredDeviceImages(IMAGE_FILTER_FULL, productSpecResponse.getAttachment()))
                .thumbnails(DeviceServiceHelper.getFilteredDeviceImages(IMAGE_FILTER_THUMBS, productSpecResponse.getAttachment()))
                .unitPrice(devicePrice.map(productOfferingPrice -> BigDecimal.valueOf(productOfferingPrice.getPrice().getValue()).setScale(BIGDECIMAL_SCALE, RoundingMode.HALF_UP)).orElse(BigDecimal.ZERO))
                .build();
    }