Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.8 kB
2
Indexable
Never
package br.com.senior.erpxfnd.produto.factory;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;

import br.com.senior.messaging.context.functional.MessageSupplier;
import br.com.senior.messaging.context.functional.MessengerSupplier;
import br.com.senior.messaging.context.functional.TenantSupplier;
import br.com.senior.messaging.context.functional.UserSupplier;
import br.com.senior.platform.blobservice.BlobServiceStub;
import br.com.senior.platform.blobservice.BlobServiceStubImpl;
import br.com.senior.sdl.user.BasicUserIdentifier;
import br.com.senior.utils.ProjectConstants;
import lombok.AccessLevel;
import lombok.Setter;
import lombok.experimental.FieldDefaults;

@Primary
@Component
@Setter(onMethod_ = @Autowired)
@FieldDefaults(level = AccessLevel.PRIVATE)
public class StubFactory {

    MessengerSupplier messengerSupplier;
    TenantSupplier tenantSupplier;
    UserSupplier userSupplier;
    MessageSupplier messageSupplier;

    public BlobServiceStub getBlobServiceStub() {
        return new BlobServiceStubImpl( //
                () -> messengerSupplier.get(), //
                new BasicUserIdentifier(userSupplier.get(), tenantSupplier.get(), /* trusted */false), //
                () -> messageSupplier.get() //
        );
    }

    public BlobServiceStub getBlobServiceTrustedStub() {
        return new BlobServiceStubImpl( //
                () -> messengerSupplier.get(), //
                new BasicUserIdentifier(ProjectConstants.ADMIN_USER, tenantSupplier.get(), /* trusted */true), //
                () -> messageSupplier.get() //
        );
    }

}