Class NeverminedManager


  • public class NeverminedManager
    extends BaseManager
    Handles several operations related with Ocean's flow
    • Field Detail

      • log

        private static final org.apache.logging.log4j.Logger log
    • Constructor Detail

      • NeverminedManager

        protected NeverminedManager​(io.keyko.common.web3.KeeperService keeperService,
                                    MetadataApiService metadataApiService)
    • Method Detail

      • getInstance

        public static NeverminedManager getInstance​(io.keyko.common.web3.KeeperService keeperService,
                                                    MetadataApiService metadataApiService)
        Given the KeeperService and MetadataApiService, returns a new instance of OceanManager using them as attributes
        Parameters:
        keeperService - Keeper Dto
        metadataApiService - Provider Dto
        Returns:
        NeverminedManager
      • generateDID

        public DID generateDID​(DDO ddo)
                        throws DIDFormatException
        Given a DDO, returns a DID created using the ddo
        Parameters:
        ddo - the DDO
        Returns:
        DID
        Throws:
        DIDFormatException - DIDFormatException
      • registerDID

        public boolean registerDID​(DID did,
                                   String url,
                                   String checksum,
                                   List<String> providers)
                            throws DIDRegisterException
        Given a DID and a Metadata API url, register on-chain the DID. It allows to resolve DDO's using DID's as input
        Parameters:
        did - the did
        url - metadata url
        checksum - calculated hash of the metadata
        providers - list of providers addresses to give access
        Returns:
        boolean success
        Throws:
        DIDRegisterException - DIDRegisterException
      • registerAccessServiceAsset

        public DDO registerAccessServiceAsset​(AssetMetadata metadata,
                                              ProviderConfig providerConfig)
                                       throws DDOException
        Creates a new DDO with an AccessService
        Parameters:
        metadata - the metadata
        providerConfig - the service Endpoints
        Returns:
        an instance of the DDO created
        Throws:
        DDOException - DDOException
      • registerAccessServiceAsset

        public DDO registerAccessServiceAsset​(AssetMetadata metadata,
                                              ProviderConfig providerConfig,
                                              AuthConfig authConfig)
                                       throws DDOException
        Creates a new DDO with an AccessService
        Parameters:
        metadata - the metadata
        providerConfig - the service Endpoints
        authConfig - auth configuration
        Returns:
        an instance of the DDO created
        Throws:
        DDOException - DDOException
      • registerComputingServiceAsset

        public DDO registerComputingServiceAsset​(AssetMetadata metadata,
                                                 ProviderConfig providerConfig,
                                                 ComputingService.Provider computingProvider)
                                          throws DDOException
        Creates a new DDO with a ComputeService
        Parameters:
        metadata - the metadata
        providerConfig - the service Endpoints
        computingProvider - the data relative to the provider
        Returns:
        an instance of the DDO created
        Throws:
        DDOException - DDOException
      • registerAsset

        private DDO registerAsset​(AssetMetadata metadata,
                                  ProviderConfig providerConfig,
                                  Service service,
                                  AuthConfig authConfig)
                           throws DDOException
        Creates a new DDO, registering it on-chain through DidRegistry contract and off-chain in Metadata Api
        Parameters:
        metadata - the metadata
        providerConfig - the service Endpoints
        service - the service
        authConfig - auth configuration
        Returns:
        an instance of the DDO created
        Throws:
        DDOException - DDOException
      • purchaseAssetFlowable

        public io.reactivex.Flowable<OrderResult> purchaseAssetFlowable​(DID did,
                                                                        int serviceIndex)
                                                                 throws OrderException
        Purchases an Asset represented by a DID. It implies to initialize a Service Agreement between publisher and consumer
        Parameters:
        did - the did
        serviceIndex - the index of the service
        Returns:
        a Flowable instance over an OrderResult to get the result of the flow in an asynchronous fashion
        Throws:
        OrderException - OrderException
      • initializeServiceAgreement

        private boolean initializeServiceAgreement​(DDO ddo,
                                                   int serviceIndex,
                                                   String serviceAgreementId)
                                            throws ServiceException,
                                                   ServiceAgreementException
        Initialize a new ServiceExecutionAgreement between a publisher and a consumer
        Parameters:
        ddo - the ddi
        serviceIndex - the service index
        serviceAgreementId - the service agreement id
        Returns:
        true if the agreement was initialized correctly, if not false
        Throws:
        ServiceException - ServiceException
        ServiceAgreementException - ServiceAgreementException
      • initializeServiceAgreementDirect

        protected boolean initializeServiceAgreementDirect​(DDO ddo,
                                                           int serviceIndex,
                                                           String serviceAgreementId)
                                                    throws ServiceException,
                                                           ServiceAgreementException
        Initialize a new ServiceExecutionAgreement between a publisher and a consumer
        Parameters:
        ddo - the ddi
        serviceIndex - the service index
        serviceAgreementId - the service agreement id
        Returns:
        true if the agreement was initialized correctly, if not false
        Throws:
        ServiceException - ServiceException
        ServiceAgreementException - ServiceAgreementException
      • initializeServiceAgreementFlowable

        protected io.reactivex.Flowable<String> initializeServiceAgreementFlowable​(DDO ddo,
                                                                                   int serviceIndex,
                                                                                   String serviceAgreementId)
                                                                            throws ServiceException,
                                                                                   ServiceAgreementException
        Initialize a new ServiceExecutionAgreement between a publisher and a consumer return a flowable to listen contract initialization events
        Parameters:
        ddo - the ddi
        serviceIndex - the service index
        serviceAgreementId - the service agreement id
        Returns:
        a Flowable over an AgreementInitializedEventResponse
        Throws:
        ServiceException - ServiceException
        ServiceAgreementException - ServiceAgreementException
      • fulfillLockReward

        private boolean fulfillLockReward​(DDO ddo,
                                          int serviceIndex,
                                          String serviceAgreementId)
                                   throws ServiceException,
                                          LockRewardFulfillException
        Executes the fulfill of the LockRewardCondition
        Parameters:
        ddo - the ddo
        serviceIndex - the index of the service
        serviceAgreementId - service agreement id
        Returns:
        a flag that indicates if the function was executed correctly
        Throws:
        ServiceException - ServiceException
        LockRewardFulfillException - LockRewardFulfillException
      • fulfillEscrowReward

        private boolean fulfillEscrowReward​(DDO ddo,
                                            int serviceIndex,
                                            String serviceAgreementId)
                                     throws ServiceException,
                                            EscrowRewardException
        Executes the fulfill of the EscrowReward
        Parameters:
        ddo - the ddo
        serviceIndex - the index of the service
        serviceAgreementId - service agreement id
        Returns:
        a flag that indicates if the function was executed correctly
        Throws:
        ServiceException - ServiceException
        EscrowRewardException - EscrowRewardException
      • fetchAssetDataBeforeConsume

        private Map<String,​Object> fetchAssetDataBeforeConsume​(DID did,
                                                                     int serviceIndex)
                                                              throws ConsumeServiceException
        Gets the data needed to download an asset
        Parameters:
        did - the did
        serviceIndex - the id of the service in the DDO
        Returns:
        a Map with the data needed to consume the asset
        Throws:
        ConsumeServiceException - ConsumeServiceException
      • access

        public boolean access​(String serviceAgreementId,
                              DID did,
                              int serviceIndex,
                              String basePath)
                       throws ConsumeServiceException
        Downloads an Asset previously ordered through a Service Agreement
        Parameters:
        serviceAgreementId - the service agreement id
        did - the did
        serviceIndex - the service index in the DDO
        basePath - the path where the asset will be downloaded
        Returns:
        a flag that indicates if the consume operation was executed correctly
        Throws:
        ConsumeServiceException - ConsumeServiceException
      • access

        public boolean access​(String serviceAgreementId,
                              DID did,
                              int serviceIndex,
                              int fileIndex,
                              String basePath)
                       throws ConsumeServiceException
        Downloads an Asset previously ordered through a Service Agreement
        Parameters:
        serviceAgreementId - the service agreement id
        did - the did
        serviceIndex - id of the service in the DDO
        fileIndex - of the file inside the files definition in metadata
        basePath - the path where the asset will be downloaded
        Returns:
        a flag that indicates if the consume operation was executed correctly
        Throws:
        ConsumeServiceException - ConsumeServiceException
      • generateSignature

        public String generateSignature​(String message)
                                 throws IOException,
                                        org.web3j.crypto.CipherException
        Throws:
        IOException
        org.web3j.crypto.CipherException
      • consumeBinary

        public InputStream consumeBinary​(String serviceAgreementId,
                                         DID did,
                                         int serviceIndex,
                                         int fileIndex)
                                  throws ConsumeServiceException
        Downloads a single file of an Asset previously ordered through a Service Agreement
        Parameters:
        serviceAgreementId - the service agreement id
        did - the did
        serviceIndex - the id of the service index in the DDO
        fileIndex - of the file inside the files definition in metadata
        Returns:
        an InputStream that represents the binary content
        Throws:
        ConsumeServiceException - ConsumeServiceException
      • consumeBinary

        public InputStream consumeBinary​(String serviceAgreementId,
                                         DID did,
                                         int serviceIndex,
                                         int fileIndex,
                                         Boolean isRangeRequest,
                                         Integer rangeStart,
                                         Integer rangeEnd)
                                  throws ConsumeServiceException
        Downloads a single file of an Asset previously ordered through a Service Agreement. It could be a request by range of bytes
        Parameters:
        serviceAgreementId - the service agreement id
        did - the did
        serviceIndex - id of the service in the DDO
        fileIndex - of the file inside the files definition in metadata
        isRangeRequest - indicates if is a request by range of bytes
        rangeStart - the start of the bytes range
        rangeEnd - the end of the bytes range
        Returns:
        an InputStream that represents the binary content
        Throws:
        ConsumeServiceException - ConsumeServiceException
      • executeComputeService

        public String executeComputeService​(String agreementId,
                                            DID did,
                                            int index,
                                            String workflowId)
                                     throws ServiceException
        Executes a remote service associated with an asset and serviceAgreementId
        Parameters:
        agreementId - the agreement id
        did - the did
        index - the index of the service
        workflowId - the workflow id
        Returns:
        an execution id
        Throws:
        ServiceException - ServiceException