This repository has been archived by the owner on Feb 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implementing Provenance API released in contracts v0.5.2
- Loading branch information
Showing
21 changed files
with
1,118 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
132 changes: 132 additions & 0 deletions
132
src/main/java/io/keyko/nevermined/api/ProvenanceAPI.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
package io.keyko.nevermined.api; | ||
|
||
import io.keyko.nevermined.exceptions.ProvenanceException; | ||
import io.keyko.nevermined.models.DID; | ||
import io.keyko.nevermined.models.contracts.ProvenanceEntry; | ||
import io.keyko.nevermined.models.contracts.ProvenanceEvent; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Exposes the Public API related with Provenance | ||
*/ | ||
public interface ProvenanceAPI { | ||
|
||
/** | ||
* Implements the W3C PROV Usage action | ||
* | ||
* @param provenanceId Provenance ID | ||
* @param did Identifier of the entity created | ||
* @param agentId Agent Identifier | ||
* @param activityId Identifier of the activity creating the new entity | ||
* @param signature Signature (optional) provided by the agent involved | ||
* @param attributes Attributes associated with the action | ||
* @return true if the provenance event was registered correctly | ||
* @throws ProvenanceException Error registering the event | ||
*/ | ||
boolean used(String provenanceId, DID did, String agentId, String activityId, String signature, String attributes) throws ProvenanceException; | ||
|
||
/** | ||
* Implements the W3C PROV Derivation action | ||
* | ||
* @param provenanceId Provenance ID | ||
* @param newEntityDid Identifier of the new entity derived | ||
* @param usedEntityDid Identifier of the entity used to derive the new entity | ||
* @param agentId Agent Identifier | ||
* @param activityId Identifier of the activity creating the new entity | ||
* @param attributes Attributes associated with the action | ||
* @return true if the provenance event was registered correctly | ||
* @throws ProvenanceException Error registering the event | ||
*/ | ||
boolean wasDerivedFrom(String provenanceId, DID newEntityDid, DID usedEntityDid, String agentId, String activityId, String attributes) throws ProvenanceException; | ||
|
||
/** | ||
* Implements the W3C PROV Association action | ||
* | ||
* @param provenanceId Provenance ID | ||
* @param did Identifier of the entity created | ||
* @param agentId Agent Identifier | ||
* @param activityId Identifier of the activity creating the new entity | ||
* @param attributes Attributes associated with the action | ||
* @return true if the provenance event was registered correctly | ||
* @throws ProvenanceException Error registering the event | ||
*/ | ||
boolean wasAssociatedWith(String provenanceId, DID did, String agentId, String activityId, String attributes) throws ProvenanceException; | ||
|
||
/** | ||
* Implements the W3C PROV Delegation action | ||
* | ||
* @param provenanceId Provenance ID | ||
* @param did Identifier of the entity created | ||
* @param delegateAgentId Delegate Agent Identifier | ||
* @param responsibleAgentId Responsible Agent Identifier | ||
* @param activityId Identifier of the activity creating the new entity | ||
* @param signature Signature provided by the delegated agent | ||
* @param attributes Attributes associated with the action | ||
* @return true if the provenance event was registered correctly | ||
* @throws ProvenanceException Error registering the event | ||
*/ | ||
boolean actedOnBehalf(String provenanceId, DID did, String delegateAgentId, String responsibleAgentId, String activityId, String signature, String attributes) throws ProvenanceException; | ||
|
||
/** | ||
* Fetch from the on-chain Provenance registry the information about one provenance event, given a provenance id | ||
* | ||
* @param provenanceId unique identifier of the provenance entry | ||
* @return ProvenanceEntry object with all the information stored on-chain | ||
* @throws ProvenanceException Error fetching the data | ||
*/ | ||
ProvenanceEntry getProvenanceEntry(String provenanceId) throws ProvenanceException; | ||
|
||
/** | ||
* Indicates if an address is a provenance delegate for a given DID | ||
* @param did Identifier of the asset | ||
* @param delegate address of the delegate | ||
* @return true if the address is a provenance delegate | ||
* @throws ProvenanceException Error fetching the data | ||
*/ | ||
boolean isProvenanceDelegate(DID did, String delegate) throws ProvenanceException; | ||
|
||
/** | ||
* Adds an address as delegate for a given DID | ||
* @param did Identifier of the asset | ||
* @param delegate address of the delegate | ||
* @return true if the address was added as a delegate for the DID given | ||
* @throws ProvenanceException Error fetching the data | ||
*/ | ||
boolean addDIDProvenanceDelegate(DID did, String delegate) throws ProvenanceException; | ||
|
||
/** | ||
* Remove an address as delegate for a given DID | ||
* @param did Identifier of the asset | ||
* @param delegate address of the delegate | ||
* @return true if the address was removed as a delegate for the DID given | ||
* @throws ProvenanceException Error fetching the data | ||
*/ | ||
boolean removeDIDProvenanceDelegate(DID did, String delegate) throws ProvenanceException; | ||
|
||
/** | ||
* Adds an address as delegate for a given DID | ||
* @param provenanceId unique identifier of the provenance entry | ||
* @return String with the address owning the provenance entry | ||
* @throws ProvenanceException Error fetching the data | ||
*/ | ||
String getProvenanceOwner(String provenanceId) throws ProvenanceException; | ||
|
||
/** | ||
* Search for ProvenanceAttributeRegistered events related with a specific DID | ||
* | ||
* @param did Identifier of the entity we are looking provenance events | ||
* @return List of ProvenanceEvents found | ||
* @throws ProvenanceException DDOException | ||
*/ | ||
List<ProvenanceEvent> getDIDProvenanceEvents(DID did) throws ProvenanceException; | ||
|
||
/** | ||
* Search for provenance methods (used, wasGeneratedBy, etc.) given a DID | ||
* | ||
* @param did Identifier of the entity we are looking provenance events | ||
* @return List of ProvenanceEvents found | ||
* @throws ProvenanceException DDOException | ||
*/ | ||
List<ProvenanceEvent> getProvenanceMethodEvents(ProvenanceEntry.ProvenanceMethod method, DID did) throws ProvenanceException; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
src/main/java/io/keyko/nevermined/api/impl/ProvenanceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package io.keyko.nevermined.api.impl; | ||
|
||
import io.keyko.nevermined.api.ProvenanceAPI; | ||
import io.keyko.nevermined.exceptions.ProvenanceException; | ||
import io.keyko.nevermined.manager.NeverminedManager; | ||
import io.keyko.nevermined.manager.ProvenanceManager; | ||
import io.keyko.nevermined.models.DID; | ||
import io.keyko.nevermined.models.contracts.ProvenanceEntry; | ||
import io.keyko.nevermined.models.contracts.ProvenanceEvent; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Implementation of AssetsAPI | ||
*/ | ||
public class ProvenanceImpl implements ProvenanceAPI { | ||
|
||
private NeverminedManager neverminedManager; | ||
private ProvenanceManager provenanceManager; | ||
|
||
|
||
/** | ||
* Constructor | ||
* | ||
* @param neverminedManager the neverminedManager | ||
* @param provenanceManager the provenanceManager | ||
*/ | ||
public ProvenanceImpl(NeverminedManager neverminedManager, ProvenanceManager provenanceManager) { | ||
|
||
this.neverminedManager = neverminedManager; | ||
this.provenanceManager = provenanceManager; | ||
} | ||
|
||
@Override | ||
public boolean used(String provenanceId, DID did, String agentId, String activityId, String signature, String attributes) throws ProvenanceException { | ||
return provenanceManager.used(provenanceId, did, agentId, activityId, signature, attributes); | ||
} | ||
|
||
@Override | ||
public boolean wasDerivedFrom(String provenanceId, DID newEntityDid, DID usedEntityDid, String agentId, String activityId, String attributes) throws ProvenanceException { | ||
return provenanceManager.wasDerivedFrom(provenanceId, newEntityDid, usedEntityDid, agentId, activityId, attributes); | ||
} | ||
|
||
@Override | ||
public boolean wasAssociatedWith(String provenanceId, DID did, String agentId, String activityId, String attributes) throws ProvenanceException { | ||
return provenanceManager.wasAssociatedWith(provenanceId, did, agentId, activityId, attributes); | ||
} | ||
|
||
@Override | ||
public boolean actedOnBehalf(String provenanceId, DID did, String delegateAgentId, String responsibleAgentId, String activityId, String signature, String attributes) throws ProvenanceException { | ||
return provenanceManager.actedOnBehalf(provenanceId, did, delegateAgentId, responsibleAgentId, activityId, signature, attributes); | ||
} | ||
|
||
@Override | ||
public ProvenanceEntry getProvenanceEntry(String provenanceId) throws ProvenanceException { | ||
return provenanceManager.getProvenanceEntry(provenanceId); | ||
} | ||
|
||
@Override | ||
public boolean isProvenanceDelegate(DID did, String delegate) throws ProvenanceException { | ||
return provenanceManager.isProvenanceDelegate(did, delegate); | ||
} | ||
|
||
@Override | ||
public boolean addDIDProvenanceDelegate(DID did, String delegate) throws ProvenanceException { | ||
return provenanceManager.addDIDProvenanceDelegate(did, delegate); | ||
} | ||
|
||
@Override | ||
public boolean removeDIDProvenanceDelegate(DID did, String delegate) throws ProvenanceException { | ||
return provenanceManager.removeDIDProvenanceDelegate(did, delegate); | ||
} | ||
|
||
@Override | ||
public String getProvenanceOwner(String provenanceId) throws ProvenanceException { | ||
return provenanceManager.getProvenanceOwner(provenanceId); | ||
} | ||
|
||
@Override | ||
public List<ProvenanceEvent> getDIDProvenanceEvents(DID did) throws ProvenanceException { | ||
return provenanceManager.getDIDProvenanceEvents(did); | ||
} | ||
|
||
@Override | ||
public List<ProvenanceEvent> getProvenanceMethodEvents(ProvenanceEntry.ProvenanceMethod method, DID did) throws ProvenanceException { | ||
return provenanceManager.getProvenanceMethodEvents(method, did); | ||
} | ||
|
||
|
||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/io/keyko/nevermined/exceptions/ProvenanceException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package io.keyko.nevermined.exceptions; | ||
|
||
/** | ||
* Business Exception related with Provenance issues | ||
*/ | ||
public class ProvenanceException extends NeverminedException { | ||
|
||
public ProvenanceException(String message, Throwable e) { | ||
super(message, e); | ||
} | ||
|
||
public ProvenanceException(String message) { | ||
super(message); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.