Package com.oceanprotocol.squid.manager
Class OceanManager
- java.lang.Object
-
- com.oceanprotocol.squid.manager.BaseManager
-
- com.oceanprotocol.squid.manager.OceanManager
-
public class OceanManager extends BaseManager
Handles several operations related with Ocean's flow
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.oceanprotocol.squid.manager.BaseManager
BaseManager.ContractAddresses
-
-
Field Summary
Fields Modifier and Type Field Description private static org.apache.logging.log4j.Logger
log
-
Fields inherited from class com.oceanprotocol.squid.manager.BaseManager
accessSecretStoreCondition, agreementStoreManager, conditionStoreManager, config, contractAddresses, didRegistry, dispenser, escrowAccessSecretStoreTemplate, escrowReward, lockRewardCondition, mainAccount, providerAddress, templateStoreManager, tokenContract
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
OceanManager(KeeperService keeperService, AquariusService aquariusService)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
consume(String serviceAgreementId, DID did, String serviceDefinitionId, Boolean isIndexDownload, Integer index, String basePath, int threshold)
Downloads an Asset previously ordered through a Service Agreementboolean
consume(String serviceAgreementId, DID did, String serviceDefinitionId, String basePath)
Downloads an Asset previously ordered through a Service AgreementInputStream
consumeBinary(String serviceAgreementId, DID did, String serviceDefinitionId, Integer index, int threshold)
Downloads a single file of an Asset previously ordered through a Service AgreementInputStream
consumeBinary(String serviceAgreementId, DID did, String serviceDefinitionId, Integer index, Boolean isRangeRequest, Integer rangeStart, Integer rangeEnd, int threshold)
Downloads a single file of an Asset previously ordered through a Service Agreement.private boolean
fulfillEscrowReward(DDO ddo, String serviceDefinitionId, String serviceAgreementId)
Executes the fulfill of the EscrowRewardprivate boolean
fulfillLockReward(DDO ddo, String serviceDefinitionId, String serviceAgreementId)
Executes the fulfill of the LockRewardConditionDID
generateDID(DDO ddo)
Given a DDO, returns a DID created using the ddoprivate Map<String,Object>
getAccessConditionParams(String did, String price)
Gets the Access ConditionStatusMap Params of a DDOprivate BasicAssetInfo
getBasicAssetInfo(AccessService accessService)
Gets some basic info of an Access Serviceprivate Map<String,Object>
getConsumeData(DID did, String serviceDefinitionId, Boolean isIndexDownload, Integer index)
Gets the data needed to download an assetList<DID>
getConsumerAssets(String consumerAddress)
List of Asset objects purchased by consumerAddressString
getDIDOwner(DID did)
Get the owner of a did already registered.static OceanManager
getInstance(KeeperService keeperService, AquariusService aquariusService)
Given the KeeperService and AquariusService, returns a new instance of OceanManager using them as attributesOrder
getOrder(String orderId)
List<DID>
getOwnerAssets(String ownerAddress)
List of Asset objects published by ownerAddressprivate io.reactivex.Flowable<com.oceanprotocol.keeper.contracts.EscrowAccessSecretStoreTemplate.AgreementCreatedEventResponse>
initializeServiceAgreement(DID did, DDO ddo, String serviceDefinitionId, String serviceAgreementId)
Initialize a new ServiceExecutionAgreement between a publisher and a consumerio.reactivex.Flowable<OrderResult>
purchaseAsset(DID did, String serviceDefinitionId)
Purchases an Asset represented by a DID.DDO
registerAsset(AssetMetadata metadata, ProviderConfig providerConfig, int threshold)
Creates a new DDO, registering it on-chain through DidRegistry contract and off-chain in Aquariusboolean
registerDID(DID did, String url, String checksum, List<String> providers)
Given a DID and a Metadata API url, register on-chain the DID.DDO
resolveDID(DID did)
Given a DID, scans the DIDRegistry events on-chain to resolve the Metadata API url and return the DDO foundList<AssetMetadata>
searchOrders()
-
Methods inherited from class com.oceanprotocol.squid.manager.BaseManager
buildDDO, buildDDO, getAccessSecretStoreCondition, getAquariusService, getContractAddresses, getEscrowReward, getEvmDto, getKeeperService, getLockRewardCondition, getMainAccount, getMetadataFiles, getProviderAddress, getSecretStoreDto, getSecretStoreManager, setAccessSecretStoreCondition, setAgreementStoreManagerContract, setAquariusService, setConditionStoreManagerContract, setDidRegistryContract, setDispenserContract, setEscrowAccessSecretStoreTemplate, setEscrowReward, setEvmDto, setKeeperService, setLockRewardCondition, setMainAccount, setProviderAddress, setSecretStoreDto, setSecretStoreManager, setTemplateStoreManagerContract, setTokenContract, toString
-
-
-
-
Constructor Detail
-
OceanManager
protected OceanManager(KeeperService keeperService, AquariusService aquariusService)
-
-
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 DtoaquariusService
- 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
-
resolveDID
public DDO resolveDID(DID did) throws EthereumException, DDOException
Given a DID, scans the DIDRegistry events on-chain to resolve the Metadata API url and return the DDO found- Parameters:
did
- the did- Returns:
- DDO
- Throws:
EthereumException
- EthereumExceptionDDOException
- DDOException
-
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 didurl
- metadata urlchecksum
- calculated hash of the metadataproviders
- 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 metadataproviderConfig
- the service Endpointsthreshold
- 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 didserviceDefinitionId
- 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 didddo
- the ddiserviceDefinitionId
- the service definition idserviceAgreementId
- the service agreement id- Returns:
- a Flowable over an AgreementInitializedEventResponse
- Throws:
DDOException
- DDOExceptionServiceException
- ServiceExceptionServiceAgreementException
- ServiceAgreementException
-
fulfillLockReward
private boolean fulfillLockReward(DDO ddo, String serviceDefinitionId, String serviceAgreementId) throws ServiceException, LockRewardFulfillException
Executes the fulfill of the LockRewardCondition- Parameters:
ddo
- the ddoserviceDefinitionId
- the serviceDefinition idserviceAgreementId
- service agreement id- Returns:
- a flag that indicates if the function was executed correctly
- Throws:
ServiceException
- ServiceExceptionLockRewardFulfillException
- LockRewardFulfillException
-
fulfillEscrowReward
private boolean fulfillEscrowReward(DDO ddo, String serviceDefinitionId, String serviceAgreementId) throws ServiceException, EscrowRewardException
Executes the fulfill of the EscrowReward- Parameters:
ddo
- the ddoserviceDefinitionId
- the serviceDefinition idserviceAgreementId
- service agreement id- Returns:
- a flag that indicates if the function was executed correctly
- Throws:
ServiceException
- ServiceExceptionEscrowRewardException
- 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 didserviceDefinitionId
- the id of the serviceisIndexDownload
- indicates if we want to download an especific file of the assetindex
- 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 iddid
- the didserviceDefinitionId
- the service definition idbasePath
- 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 iddid
- the didserviceDefinitionId
- the service definition idisIndexDownload
- indicates if we want to download an especific file of the assetindex
- of the file inside the files definition in metadatabasePath
- the path where the asset will be downloadedthreshold
- 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 iddid
- the didserviceDefinitionId
- the service definition idindex
- of the file inside the files definition in metadatathreshold
- 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 iddid
- the didserviceDefinitionId
- the service definition idindex
- of the file inside the files definition in metadataisRangeRequest
- indicates if is a request by range of bytesrangeStart
- the start of the bytes rangerangeEnd
- the end of the bytes rangethreshold
- secret store threshold- Returns:
- an InputStream that represents the binary content
- Throws:
ConsumeServiceException
- ConsumeServiceException
-
searchOrders
public List<AssetMetadata> searchOrders()
-
getAccessConditionParams
private Map<String,Object> getAccessConditionParams(String did, String price)
Gets the Access ConditionStatusMap Params of a DDO- Parameters:
did
- the didprice
- 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
-
-