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

URL Accessibility For Searches Sample

This sample explains how to create Accessible URLs for searches. You might also find the URL Accessibility for Reports Sample useful. We will be reusing the code of the Handler Sample in this example. This sample requires Apache Maven. See System Requirements for links on how to install it.

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. Make sure you update the current version of carbon governance (e.g. 4.6.3). 

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.governance</groupId>
<artifactId>org.wso2.carbon.governance.api</artifactId>
<version>{current version of the carbon.governance}</version>
</dependency>

3. Add a new Java Class named URIForSearchHandler at 

GREG_HOME/samples/handler/src/src/main/java/org/wso2/carbon/registry/samples/handler/URIForSearchHandler.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.Resource;
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 javax.xml.namespace.QName;
import java.util.List;
import java.util.Map;
import java.util.Properties;
 
public class URIForSearchHandler extends Handler {
 
    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 = buildURI(requestContext.getResource());
        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);
        }
    }
 
    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 = buildURI(requestContext.getResource());
        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());
        }
    }
 
    private String buildURI(Resource resource) {
        StringBuilder url = new StringBuilder("https://localhost:9443/carbon/search/" +
                "advancedSearch.jsp?region=region3&item=registry_search_menu");
        Properties props = resource.getProperties();
        for (Map.Entry<Object, Object> entry : props.entrySet()) {
            if (!RegistryUtils.isHiddenProperty((String)entry.getKey())
                    && entry.getValue() != null && ((List<String>)entry.getValue()).get(0).length() > 0) {
                url.append("&").append(entry.getKey()).append("=").append(((List<String>)entry.getValue()).get(
                        0));
            }
        }
        return url.toString();
    }
}

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

mvn clean install

The command mvn clean install will trigger an Apache Maven Build in your command line. This requires you having installed Apache Maven. See System Requirements for links on how to install it.

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

5. Copy the <G-REG_HOME>/ samples/handler/src/target/ org.wso2.carbon.registry.samples.handler-5.2.0.jar file into the <G-REG_HOME>/repository/components/dropins/ directory.

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.URIForSearchHandler">
    <filter class="org.wso2.carbon.registry.core.jdbc.handlers.filters.URLMatcher">
        <property name="pattern">/_system/config/users/.*/searchFilters/.*</property>
    </filter>
</handler>

See also Handler Configuration Details.

7. Start the WSO2 Governance Registry. See Running the Product for more information.

8. Navigate to the Search page and search for resources by the name "_system".

See also Search.

9. Once the search has been completed, save the search with the Filter Name "SystemColSearch".

Click the "Save" button to save the search.

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

See also /wiki/spaces/~yohanna@wso2.com/pages/21233754.

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