Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
2.8 kB
1
Indexable
Never
package br.com.senior.erpxcomven.pedido.report.service;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.UUID;
import java.util.stream.Collectors;

import javax.inject.Inject;

import org.springframework.stereotype.Service;

import br.com.senior.erpxcomven.foundation.E075derImageEntity;
import br.com.senior.erpxcomven.pedido.dto.ProductFile;
import br.com.senior.erpxcomven.pedido.repository.impl.E075derImageRepositoryImpl;
import br.com.senior.erpxcomven.pedido.stub.StubFactory;
import br.com.senior.platform.blobservice.BlobRequest;
import br.com.senior.platform.blobservice.RequestDownloadsInput;
import br.com.senior.platform.blobservice.RequestDownloadsOutput;

@Service
public class ProductImageBlobServiceImpl implements ProductImageBlobService {

    private static final long TIMEOUT = 20_000;
    @Inject
    private E075derImageRepositoryImpl e075derImageRepositoryCustom;
    @Inject
    private StubFactory stubFactory;
    
    @Override
    public List<ProductFile> retrieveProductFilesFromBlobService(UUID e120pedId) {
        List<E075derImageEntity> e075derImages = e075derImageRepositoryCustom.listProductImagesByE120ped(e120pedId);
        List<BlobRequest> blobRequestList = e075derImages.stream()
                .map(image -> {
                    var blobRequest = new BlobRequest();
                    blobRequest.domainName = "erpx_fnd";
                    blobRequest.serviceName = "produto";
                    blobRequest.areaSecret = "PUHQSYX3BASRQJUG4V03WAI9IT158HEO";
                    blobRequest.targetObjectId = image.getTargetObjectId();
                    blobRequest.fileName = image.getFileName();
                    blobRequest.version = image.getVersion();
                    return blobRequest;
                })
                .collect(Collectors.toList());
        
        RequestDownloadsOutput output = stubFactory.getBlobServiceStub().requestDownloads(new RequestDownloadsInput(blobRequestList), TIMEOUT);
        List<ProductFile> productFiles = new ArrayList<>();
        
        output.blobDetails.stream().forEach(blob -> {
            E075derImageEntity image = e075derImages.stream().filter(e075derImage -> e075derImage.getTargetObjectId().equals(blob.targetObjectId)).findFirst().orElse(null);
            if(Objects.nonNull(image)) {
                var productFile = new ProductFile();
                productFile.setCode(image.getE075der().getCodDer());
                productFile.setDescription(image.getE075der().getDesDer());
                productFile.setUrl(blob.location.uri);
                productFiles.add(productFile);
            }        
        });
        return productFiles;
    }
}