...
To create a new Artifact you can use the following code. Here registry refers to valid org.wso2.carbon.registry.core.Registry
object and projectKey
refers to shortName
in the Registry extension file.
Code Block |
---|
import org.wso2.carbon.governance.api.generic.GenericArtifactManager; import org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact; GovernanceUtils.loadGovernanceArtifacts((UserRegistry) registry); GenericArtifactManager artifactManager = new GenericArtifactManager(registry, projectKey); GenericArtifact artifact = artifactManager.newGovernanceArtifact(new QName("http://www.example.com","event")); artifactManager.addGenericArtifact(artifact); |
...
To make further changes to a Artifact which already in the Registry you can use the updateGenericArtifact()
method.
Code Block |
---|
artifact.addAttribute("EventName","Running"); artifactManager.updateGenericArtifact(artifact); |
...
To remove an Artifact you should have the reference to that Artifact, which can be retrieve using artifact.getId()
. Then you can use the removeGenericArtifact()
method to remove the Artifact.
Code Block |
---|
String artifactId = artifact.getId(); artifactManager.removeGenericArtifact(artifactId); |
...
To retrieve an Artifact you can use the getGenericArtifact()
method.
Code Block |
---|
GenericArtifact artifact = artifactManager.getGenericArtifact(artifactId);
|
...
- Key - EventName.
- Value - Running.
Code Block |
---|
GenericArtifact[] artifacts = artifactManager.findGenericArtifacts( new GenericArtifactFilter() { public boolean matches(GenericArtifact genericArtifact) throws GovernanceException { String attributeVal = artifact.getAttribute("EventName"); if(attributeVal != null && attributeVal == "Running"){ return (attributeVal != null return true&& attributeVal.equals("Running")); } } return false; } }); |
Associate a Lifecycle to the Artifact
To associate a Lifecycle to the Artifact you can use the attachLifecycle()
method.
Code Block |
---|
artifact.attachLifecycle("LifeCycleName");
artifactManager.updateGenericArtifact(artifact);
|
...
To get the dependents and dependencies of an Artifact you can use the getDependents()
and getDependencies()
methods.
Code Block |
---|
GovernanceArtifact[] dependents = artifact.getDependents();
GovernanceArtifact[] dependencies = artifact.getDependencies(); |
See also Configurable Governance Artifacts and Governance Artifacts.
Excerpt | ||
---|---|---|
| ||
Instructions on how to access Registry extensions using Governance API. |