Class OceanManager


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

      • log

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

      • getInstance

        public static OceanManager getInstance​(KeeperService keeperService,
                                               AquariusService aquariusService)
        Given the KeeperService and AquariusService, returns a new instance of OceanManager using them as attributes
        Parameters:
        keeperService - Keeper Dto
        aquariusService - Provider Dto
        Returns:
        OceanManager
      • 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
      • registerAsset

        public DDO registerAsset​(AssetMetadata metadata,
                                 ProviderConfig providerConfig,
                                 int threshold)
                          throws DDOException
        Creates a new DDO, registering it on-chain through DidRegistry contract and off-chain in Aquarius
        Parameters:
        metadata - the metadata
        providerConfig - the service Endpoints
        threshold - secret store threshold
        Returns:
        an instance of the DDO created
        Throws:
        DDOException - DDOException
      • purchaseAsset

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

        private io.reactivex.Flowable<com.oceanprotocol.keeper.contracts.EscrowAccessSecretStoreTemplate.AgreementCreatedEventResponse> initializeServiceAgreement​(DID did,
                                                                                                                                                                   DDO ddo,
                                                                                                                                                                   String serviceDefinitionId,
                                                                                                                                                                   String serviceAgreementId)
                                                                                                                                                            throws DDOException,
                                                                                                                                                                   ServiceException,
                                                                                                                                                                   ServiceAgreementException
        Initialize a new ServiceExecutionAgreement between a publisher and a consumer
        Parameters:
        did - the did
        ddo - the ddi
        serviceDefinitionId - the service definition id
        serviceAgreementId - the service agreement id
        Returns:
        a Flowable over an AgreementInitializedEventResponse
        Throws:
        DDOException - DDOException
        ServiceException - ServiceException
        ServiceAgreementException - ServiceAgreementException
      • fulfillLockReward

        private boolean fulfillLockReward​(DDO ddo,
                                          String serviceDefinitionId,
                                          String serviceAgreementId)
                                   throws ServiceException,
                                          LockRewardFulfillException
        Executes the fulfill of the LockRewardCondition
        Parameters:
        ddo - the ddo
        serviceDefinitionId - the serviceDefinition id
        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,
                                            String serviceDefinitionId,
                                            String serviceAgreementId)
                                     throws ServiceException,
                                            EscrowRewardException
        Executes the fulfill of the EscrowReward
        Parameters:
        ddo - the ddo
        serviceDefinitionId - the serviceDefinition id
        serviceAgreementId - service agreement id
        Returns:
        a flag that indicates if the function was executed correctly
        Throws:
        ServiceException - ServiceException
        EscrowRewardException - EscrowRewardException
      • getConsumeData

        private Map<String,​Object> getConsumeData​(DID did,
                                                        String serviceDefinitionId,
                                                        Boolean isIndexDownload,
                                                        Integer index)
                                                 throws ConsumeServiceException
        Gets the data needed to download an asset
        Parameters:
        did - the did
        serviceDefinitionId - the id of the service
        isIndexDownload - indicates if we want to download an especific file of the asset
        index - the index of the file we want to consume
        Returns:
        a Map with the data needed to consume the asset
        Throws:
        ConsumeServiceException - ConsumeServiceException
      • consume

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

        public boolean consume​(String serviceAgreementId,
                               DID did,
                               String serviceDefinitionId,
                               Boolean isIndexDownload,
                               Integer index,
                               String basePath,
                               int threshold)
                        throws ConsumeServiceException
        Downloads an Asset previously ordered through a Service Agreement
        Parameters:
        serviceAgreementId - the service agreement id
        did - the did
        serviceDefinitionId - the service definition id
        isIndexDownload - indicates if we want to download an especific file of the asset
        index - of the file inside the files definition in metadata
        basePath - the path where the asset will be downloaded
        threshold - secret store threshold
        Returns:
        a flag that indicates if the consume operation was executed correctly
        Throws:
        ConsumeServiceException - ConsumeServiceException
      • consumeBinary

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

        public InputStream consumeBinary​(String serviceAgreementId,
                                         DID did,
                                         String serviceDefinitionId,
                                         Integer index,
                                         Boolean isRangeRequest,
                                         Integer rangeStart,
                                         Integer rangeEnd,
                                         int threshold)
                                  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
        serviceDefinitionId - the service definition id
        index - 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
        threshold - secret store threshold
        Returns:
        an InputStream that represents the binary content
        Throws:
        ConsumeServiceException - ConsumeServiceException
      • getAccessConditionParams

        private Map<String,​Object> getAccessConditionParams​(String did,
                                                                  String price)
        Gets the Access ConditionStatusMap Params of a DDO
        Parameters:
        did - the did
        price - the price
        Returns:
        a Map with the params of the Access ConditionStatusMap
      • getBasicAssetInfo

        private BasicAssetInfo getBasicAssetInfo​(AccessService accessService)
        Gets some basic info of an Access Service
        Parameters:
        accessService - the access service
        Returns:
        BasicAssetInfo
      • getDIDOwner

        public String getDIDOwner​(DID did)
                           throws Exception
        Get the owner of a did already registered.
        Parameters:
        did - the did
        Returns:
        owner address
        Throws:
        Exception - Exception
      • getConsumerAssets

        public List<DID> getConsumerAssets​(String consumerAddress)
                                    throws ServiceException
        List of Asset objects purchased by consumerAddress
        Parameters:
        consumerAddress - ethereum address of consumer
        Returns:
        list of dids
        Throws:
        ServiceException - ServiceException
      • getOwnerAssets

        public List<DID> getOwnerAssets​(String ownerAddress)
                                 throws ServiceException
        List of Asset objects published by ownerAddress
        Parameters:
        ownerAddress - ethereum address of owner/publisher
        Returns:
        list of dids
        Throws:
        ServiceException - ServiceException