Package io.keyko.nevermined.manager
Class NeverminedManager
- java.lang.Object
-
- io.keyko.nevermined.manager.BaseManager
-
- io.keyko.nevermined.manager.NeverminedManager
-
public class NeverminedManager extends BaseManager
Handles several operations related with Ocean's flow
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class io.keyko.nevermined.manager.BaseManager
BaseManager.ContractAddresses
-
-
Field Summary
Fields Modifier and Type Field Description private AgreementsManager
agreementsManager
private static org.apache.logging.log4j.Logger
log
private TemplatesManager
templatesManager
-
Fields inherited from class io.keyko.nevermined.manager.BaseManager
accessSecretStoreCondition, agreementStoreManager, computeExecutionCondition, condition, conditionStoreManager, config, contractAddresses, didRegistry, dispenser, escrowAccessSecretStoreTemplate, escrowComputeExecutionTemplate, escrowReward, lockRewardCondition, mainAccount, providerAddress, templateStoreManager, tokenContract
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
NeverminedManager(io.keyko.common.web3.KeeperService keeperService, MetadataApiService metadataApiService)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
access(String serviceAgreementId, DID did, int serviceIndex, int fileIndex, String basePath)
Downloads an Asset previously ordered through a Service Agreementboolean
access(String serviceAgreementId, DID did, int serviceIndex, String basePath)
Downloads an Asset previously ordered through a Service Agreementprivate Map<String,Object>
buildBasicAccessServiceConfiguration(ProviderConfig providerConfig, String price, String creatorAddress)
private Map<String,Object>
buildBasicComputingServiceConfiguration(ProviderConfig providerConfig, ComputingService.Provider computingProvider, String price, String creatorAddress)
private boolean
checkAgreementStatus(String serviceAgreementId)
InputStream
consumeBinary(String serviceAgreementId, DID did, int serviceIndex, int fileIndex)
Downloads a single file of an Asset previously ordered through a Service AgreementInputStream
consumeBinary(String serviceAgreementId, DID did, int serviceIndex, int fileIndex, Boolean isRangeRequest, Integer rangeStart, Integer rangeEnd)
Downloads a single file of an Asset previously ordered through a Service Agreement.String
executeComputeService(String agreementId, DID did, int index, String workflowId)
Executes a remote service associated with an asset and serviceAgreementIdprivate Map<String,Object>
fetchAssetDataBeforeConsume(DID did, int serviceIndex)
Gets the data needed to download an assetprivate boolean
fulfillEscrowReward(DDO ddo, int serviceIndex, String serviceAgreementId)
Executes the fulfill of the EscrowRewardprivate boolean
fulfillLockReward(DDO ddo, int serviceIndex, String serviceAgreementId)
Executes the fulfill of the LockRewardConditionDID
generateDID(DDO ddo)
Given a DDO, returns a DID created using the ddoList<byte[]>
generateServiceConditionsId(String serviceAgreementId, String consumerAddress, DDO ddo, int serviceIndex)
String
generateSignature(String message)
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 attributesOrder
getOrder(String orderId)
private boolean
initializeServiceAgreement(DDO ddo, int serviceIndex, String serviceAgreementId)
Initialize a new ServiceExecutionAgreement between a publisher and a consumerprotected boolean
initializeServiceAgreementDirect(DDO ddo, int serviceIndex, String serviceAgreementId)
Initialize a new ServiceExecutionAgreement between a publisher and a consumerprotected io.reactivex.Flowable<String>
initializeServiceAgreementFlowable(DDO ddo, int serviceIndex, String serviceAgreementId)
Initialize a new ServiceExecutionAgreement between a publisher and a consumer return a flowable to listen contract initialization eventsboolean
isConditionFulfilled(String serviceAgreementId, Condition.ConditionTypes conditionType)
OrderResult
purchaseAssetDirect(DID did, int serviceIndex)
Purchases an Asset represented by a DID.io.reactivex.Flowable<OrderResult>
purchaseAssetFlowable(DID did, int serviceIndex)
Purchases an Asset represented by a DID.DDO
registerAccessServiceAsset(AssetMetadata metadata, ProviderConfig providerConfig)
Creates a new DDO with an AccessServiceDDO
registerAccessServiceAsset(AssetMetadata metadata, ProviderConfig providerConfig, AuthConfig authConfig)
Creates a new DDO with an AccessServiceprivate DDO
registerAsset(AssetMetadata metadata, ProviderConfig providerConfig, Service service, AuthConfig authConfig)
Creates a new DDO, registering it on-chain through DidRegistry contract and off-chain in Metadata ApiDDO
registerComputingServiceAsset(AssetMetadata metadata, ProviderConfig providerConfig, ComputingService.Provider computingProvider)
Creates a new DDO with a ComputeServiceboolean
registerDID(DID did, String url, String checksum, List<String> providers)
Given a DID and a Metadata API url, register on-chain the DID.List<AssetMetadata>
searchOrders()
NeverminedManager
setAgreementManager(AgreementsManager agreementManager)
NeverminedManager
setTemplatesManager(TemplatesManager templatesManager)
-
Methods inherited from class io.keyko.nevermined.manager.BaseManager
buildDDO, getAccessSecretStoreCondition, getComputeExecutionCondition, getContractAddresses, getDecriptedSecretStoreMetadataFiles, getDecriptedSecretStoreMetadataFiles, getEscrowComputeExecutionTemplate, getEscrowReward, getEvmDto, getKeeperService, getLockRewardCondition, getMainAccount, getMetadataApiService, getProviderAddress, getSecretStoreDto, getSecretStoreManager, getTemplateIdByName, resolveDID, setAccessSecretStoreCondition, setAgreementStoreManagerContract, setComputeExecutionCondition, setConditionStoreManagerContract, setDidRegistryContract, setDispenserContract, setEscrowAccessSecretStoreTemplate, setEscrowComputeExecutionTemplate, setEscrowReward, setEvmDto, setKeeperService, setLockRewardCondition, setMainAccount, setMetadataApiService, setProviderAddress, setSecretStoreDto, setSecretStoreManager, setTemplateStoreManagerContract, setTokenContract, tokenApprove, toString
-
-
-
-
Field Detail
-
log
private static final org.apache.logging.log4j.Logger log
-
agreementsManager
private AgreementsManager agreementsManager
-
templatesManager
private TemplatesManager templatesManager
-
-
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 DtometadataApiService
- Provider Dto- Returns:
- NeverminedManager
-
setAgreementManager
public NeverminedManager setAgreementManager(AgreementsManager agreementManager)
-
setTemplatesManager
public NeverminedManager setTemplatesManager(TemplatesManager templatesManager)
-
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 didurl
- metadata urlchecksum
- calculated hash of the metadataproviders
- list of providers addresses to give access- Returns:
- boolean success
- Throws:
DIDRegisterException
- DIDRegisterException
-
buildBasicAccessServiceConfiguration
private Map<String,Object> buildBasicAccessServiceConfiguration(ProviderConfig providerConfig, String price, String creatorAddress)
-
buildBasicComputingServiceConfiguration
private Map<String,Object> buildBasicComputingServiceConfiguration(ProviderConfig providerConfig, ComputingService.Provider computingProvider, String price, String creatorAddress)
-
registerAccessServiceAsset
public DDO registerAccessServiceAsset(AssetMetadata metadata, ProviderConfig providerConfig) throws DDOException
Creates a new DDO with an AccessService- Parameters:
metadata
- the metadataproviderConfig
- 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 metadataproviderConfig
- the service EndpointsauthConfig
- 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 metadataproviderConfig
- the service EndpointscomputingProvider
- 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 metadataproviderConfig
- the service Endpointsservice
- the serviceauthConfig
- auth configuration- Returns:
- an instance of the DDO created
- Throws:
DDOException
- DDOException
-
isConditionFulfilled
public boolean isConditionFulfilled(String serviceAgreementId, Condition.ConditionTypes conditionType) throws Exception
- Throws:
Exception
-
purchaseAssetDirect
public OrderResult purchaseAssetDirect(DID did, int serviceIndex) throws OrderException, ServiceException, EscrowRewardException
Purchases an Asset represented by a DID. It implies to initialize a Service Agreement between publisher and consumer- Parameters:
did
- the didserviceIndex
- the index of the service- Returns:
- true if the asset was purchased successfully, if not false
- Throws:
OrderException
- OrderExceptionServiceException
- ServiceExceptionEscrowRewardException
- EscrowRewardException
-
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 didserviceIndex
- 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
-
generateServiceConditionsId
public List<byte[]> generateServiceConditionsId(String serviceAgreementId, String consumerAddress, DDO ddo, int serviceIndex) throws ServiceAgreementException, ServiceException
-
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 ddiserviceIndex
- the service indexserviceAgreementId
- the service agreement id- Returns:
- true if the agreement was initialized correctly, if not false
- Throws:
ServiceException
- ServiceExceptionServiceAgreementException
- 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 ddiserviceIndex
- the service indexserviceAgreementId
- the service agreement id- Returns:
- true if the agreement was initialized correctly, if not false
- Throws:
ServiceException
- ServiceExceptionServiceAgreementException
- 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 ddiserviceIndex
- the service indexserviceAgreementId
- the service agreement id- Returns:
- a Flowable over an AgreementInitializedEventResponse
- Throws:
ServiceException
- ServiceExceptionServiceAgreementException
- ServiceAgreementException
-
checkAgreementStatus
private boolean checkAgreementStatus(String serviceAgreementId) throws ServiceAgreementException
- Throws:
ServiceAgreementException
-
fulfillLockReward
private boolean fulfillLockReward(DDO ddo, int serviceIndex, String serviceAgreementId) throws ServiceException, LockRewardFulfillException
Executes the fulfill of the LockRewardCondition- Parameters:
ddo
- the ddoserviceIndex
- the index of the serviceserviceAgreementId
- service agreement id- Returns:
- a flag that indicates if the function was executed correctly
- Throws:
ServiceException
- ServiceExceptionLockRewardFulfillException
- LockRewardFulfillException
-
fulfillEscrowReward
private boolean fulfillEscrowReward(DDO ddo, int serviceIndex, String serviceAgreementId) throws ServiceException, EscrowRewardException
Executes the fulfill of the EscrowReward- Parameters:
ddo
- the ddoserviceIndex
- the index of the serviceserviceAgreementId
- service agreement id- Returns:
- a flag that indicates if the function was executed correctly
- Throws:
ServiceException
- ServiceExceptionEscrowRewardException
- EscrowRewardException
-
fetchAssetDataBeforeConsume
private Map<String,Object> fetchAssetDataBeforeConsume(DID did, int serviceIndex) throws ConsumeServiceException
Gets the data needed to download an asset- Parameters:
did
- the didserviceIndex
- 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 iddid
- the didserviceIndex
- the service index in the DDObasePath
- 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 iddid
- the didserviceIndex
- id of the service in the DDOfileIndex
- of the file inside the files definition in metadatabasePath
- 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 iddid
- the didserviceIndex
- the id of the service index in the DDOfileIndex
- 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 iddid
- the didserviceIndex
- id of the service in the DDOfileIndex
- 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 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 iddid
- the didindex
- the index of the serviceworkflowId
- the workflow id- Returns:
- an execution id
- Throws:
ServiceException
- ServiceException
-
searchOrders
public List<AssetMetadata> searchOrders()
-
-