This site contains the documentation that is relevant to older WSO2 product versions and offerings.
For the latest WSO2 documentation, visit https://wso2.com/documentation/.

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Next »

This sample explains how to create Accessible URLs for reports. You might also find the URL Accessibility For Searches Sample useful. We will be reusing the code of the Handler Sample and reusing logic of the Asset Models Sample in this example. This sample requires Apache Maven. See Installing Apache Maven for Governance Registry on Windows or Installing Apache Maven for Governance Registry on Linux.

Instructions

1. Navigate to GREG_HOME/ samples/handler/src to find the source code of the Handler Sample.

2. Add the following dependency to your POM file:

Tip

Project Object Model (POM) is an XML representation of a Maven project held in a file named pom.xml. You should find POM file by the name pom.xml inside GREG_HOME/ samples/handler/src.

<dependency>
    <groupId>org.wso2.carbon</groupId>
    <artifactId>org.wso2.carbon.governance.api</artifactId>
    <version>4.0.1</version>
</dependency>

3. Add a new Java Class named URIForReportHandler at 

GREG_HOME/samples/handler/src/src/main/java/org/wso2/carbon/registry/samples/handler/URIForReportHandler.java with the following source:

package org.wso2.carbon.registry.samples.handler;
 
import org.wso2.carbon.governance.api.exception.GovernanceException;
import org.wso2.carbon.governance.api.generic.GenericArtifactFilter;
import org.wso2.carbon.governance.api.generic.GenericArtifactManager;
import org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact;
import org.wso2.carbon.governance.api.util.GovernanceUtils;
import org.wso2.carbon.registry.core.ActionConstants;
import org.wso2.carbon.registry.core.exceptions.RegistryException;
import org.wso2.carbon.registry.core.jdbc.handlers.Handler;
import org.wso2.carbon.registry.core.jdbc.handlers.RequestContext;
import org.wso2.carbon.registry.core.session.CurrentSession;
import org.wso2.carbon.registry.core.utils.RegistryUtils;
import org.wso2.carbon.user.core.UserStoreException;
 
import javax.xml.namespace.QName;
 
public class URIForReportHandler extends Handler {
 
    private String resourceServletPath;
 
    public void setRegistryURL(String registryURL) {
        resourceServletPath = registryURL + (registryURL.endsWith("/") ? "resource" : "/resource");
    }
 
    public void put(RequestContext requestContext) throws RegistryException {
        GovernanceUtils.setTenantGovernanceSystemRegistry(CurrentSession.getTenantId());
        GenericArtifactManager manager = new GenericArtifactManager(
                GovernanceUtils.getGovernanceSystemRegistry(null), "uri");
        String path = requestContext.getResourcePath().getPath();
        final String uri = resourceServletPath + path;
        GenericArtifact[] artifacts = manager.findGenericArtifacts(new GenericArtifactFilter() {
            public boolean matches(GenericArtifact artifact) throws GovernanceException {
                return uri.matches(artifact.getAttribute("overview_uri"));
            }
        });
 
        if (artifacts.length == 0) {
            GenericArtifact artifact =
                    manager.newGovernanceArtifact(new QName(RegistryUtils.getResourceName(path)));
            artifact.setAttribute("overview_type", "Generic");
            artifact.setAttribute("overview_uri", uri);
            manager.addGenericArtifact(artifact);
 
            try {
                CurrentSession.getUserRealm().getAuthorizationManager().authorizeRole(
                        "wso2.anonymous.role", path, ActionConstants.GET);
            } catch (UserStoreException e) {
                throw new RegistryException("Unable to set role authorizations", e);
            }
        }
    }
 
    public void delete(RequestContext requestContext) throws RegistryException {
        GovernanceUtils.setTenantGovernanceSystemRegistry(CurrentSession.getTenantId());
        GenericArtifactManager manager = new GenericArtifactManager(
                GovernanceUtils.getGovernanceSystemRegistry(null), "uri");
        String path = requestContext.getResourcePath().getPath();
        final String uri = resourceServletPath + path;
        GenericArtifact[] artifacts = manager.findGenericArtifacts(new GenericArtifactFilter() {
            public boolean matches(GenericArtifact artifact) throws GovernanceException {
                return uri.matches(artifact.getAttribute("overview_uri"));
            }
        });
 
        if (artifacts.length > 0) {
            manager.removeGenericArtifact(artifacts[0].getId());
 
            try {
                CurrentSession.getUserRealm().getAuthorizationManager().clearRoleAuthorization(
                        "wso2.anonymous.role", path, ActionConstants.GET);
            } catch (UserStoreException e) {
                throw new RegistryException("Unable to clear role authorizations", e);
            }
        }
    }
}

4. Compile the source code by running the following command inside GREG_HOME/ samples/handler/src:

mvn clean install

Note

The command mvn clean install will trigger an Apache Maven Build in your command line. This requires you having installed Apache Maven. See Installing Apache Maven for Governance Registry on Windows or Installing Apache Maven for Governance Registry on Linux.

A successful run of Apache Maven will generate a report similar to the following:

5. Copy the GREG_HOME/ samples/handler/src/target/ org.wso2.carbon.registry.samples.handler-4.5.0.jar into GREG_HOME/repository/components/dropins.

6. Edit the registry.xml file which is in GREG_HOME/repository/conf folder and add the following XML snippet.

<handler class="org.wso2.carbon.registry.samples.handler.URIForReportHandler">
    <filter class="org.wso2.carbon.registry.core.jdbc.handlers.filters.URLMatcher">
        <property name="pattern">/_system/governance/reports/.*</property>
    </filter>
    <property name="registryURL">https://localhost:9443/registry</property>
</handler>

See also Handler Configuration Details.

7. Start the WSO2 Governance Registry. See Running the Product on Windows or Running the Product on Linux and Solaris.

8. Run the Asset Models Sample for Applications and create a few Applications in Governance Registry (to facilitate the generation of meaningful reports).

9. Navigate to the Manage Reports page, and Schedule the Application Report.

10. Fill in the following parameters and schedule the report generation:

  1. Cron Expression - 0/10 * * * * ?
  2. Registry URL - https://localhost:9443/registry
  3. Username - admin
  4. Password - admin
  5. Resource Path - /_system/governance/reports/ApplicationReport.pdf

Click the "Schedule" button to finish scheduling the report.

You should find a line similar to the following printed on your command prompt, which indicates that you task has successfully deployed.

[2012-09-17 00:42:49,204]  INFO {org.wso2.carbon.ntask.core.impl.AbstractQuartzTaskManager} -  Task scheduled: ApplicationReport

11. Finally navigate to the List URI page to see your URI added.

See also Managing URIs.

  • No labels