com.atlassian.confluence.content.render.xhtml.migration.exceptions.UnknownMacroMigrationException: The macro 'next_previous_links' is unknown.

Configurable Governance Artifacts with API

Note

Please follow the documentation on how to create a client-side connection to use the Governance API before following these examples.

Follow the instructions below to learn how to access Registry extensions using Governance API.

Add a New Artifact

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.

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);

Note

Please note that you need to invoke the following method before using the Governance API for generic artifacts.

GovernanceUtils.loadGovernanceArtifacts((UserRegistry) registry);

Update an Artifact

To make further changes to a Artifact which already in the Registry you can use the updateGenericArtifact() method.

artifact.addAttribute("EventName","Running");
artifactManager.updateGenericArtifact(artifact);

Remove an 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.

String artifactId = artifact.getId();
artifactManager.removeGenericArtifact(artifactId);

Retrieve an Artifact

To retrieve an Artifact you can use the getGenericArtifact() method.

GenericArtifact artifact = artifactManager.getGenericArtifact(artifactId);

Note

In order to use the getGenericArtifact() method you have to have the Artifact reference ID. If you don't have it you can use the discovery method discussed below.

Discover an Artifact

Using the service discovery methods, you can retrieve Artifacts that match a given criteria. Here is an example on how to retrieve a set of Artifacts that has the attributes:

  • Key - EventName.
  • Value - Running.
GenericArtifact[] artifacts = artifactManager.findGenericArtifacts(
    new GenericArtifactFilter() {
        public boolean matches(GenericArtifact artifact) throws GovernanceException {
            String attributeVal = artifact.getAttribute("EventName");
            return (attributeVal != null && attributeVal.equals("Running"));
        }
    });

Associate a Lifecycle to the Artifact

To associate a Lifecycle to the Artifact you can use the attachLifecycle() method.

artifact.attachLifecycle("LifeCycleName");
artifactManager.updateGenericArtifact(artifact);

Retrieving Dependents And Dependencies

To get the dependents and dependencies of an Artifact you can use the getDependents() and getDependencies() methods.

GovernanceArtifact[] dependents = artifact.getDependents();
GovernanceArtifact[] dependencies = artifact.getDependencies();

See also /wiki/spaces/~yohanna@wso2.com/pages/21233721 and /wiki/spaces/~yohanna@wso2.com/pages/21239018.

com.atlassian.confluence.content.render.xhtml.migration.exceptions.UnknownMacroMigrationException: The macro 'next_previous_links2' is unknown.