Populating Dynamic Values in a Drop-down Field
Configurable Governance Artifacts (RXT) extend the functionality of WSO2 Governance Registry. The RXT feature provides you to define your own data model. For more information on configurable Governance artifacts (RXT), see Configurable Governance Artifacts (RXT).
The elements of a RXT define all the properties with respect to an asset type that is stored in WSO2 G-Reg. A drop-down field corresponding to an RXT element is generally populated using static values that are defined in the RXT of that particular asset type. However, you can dynamically populate values to a drop-down field of an RXT element.
For an example, follow the steps below to populate names of all the WSDL files that are currently stored in your G-Reg server to the drop-down list of the WSDL field, when adding a SOAP Service.
Create a Java project by adding the following content (e.g.
populator.jar
).You need to implement the
DropDownDataPopulator
interface in the drop-down populator class.package org.sample.rxt.populator; import javax.servlet.ServletConfig; import javax.servlet.http.HttpServletRequest; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.governance.generic.stub.beans.xsd.ContentArtifactsBean; import org.wso2.carbon.governance.generic.ui.clients.ManageGenericArtifactServiceClient; import org.wso2.carbon.governance.generic.ui.utils.DropDownDataPopulator; import org.wso2.carbon.registry.core.Registry; import org.wso2.carbon.registry.core.session.UserRegistry; import org.wso2.carbon.registry.api.RegistryException; import org.wso2.carbon.governance.api.generic.GenericArtifactManager; import org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact; import org.wso2.carbon.governance.api.util.GovernanceArtifactConfiguration; import org.wso2.carbon.governance.api.util.GovernanceUtils; public class WSDLPopulator implements DropDownDataPopulator { private static final Log log = LogFactory.getLog(WSDLPopulator.class); String[] out = new String[1]; @Override public String[] getList(HttpServletRequest httpServletRequest, ServletConfig servletConfig) { try { ManageGenericArtifactServiceClient client = new ManageGenericArtifactServiceClient(servletConfig, httpServletRequest.getSession()); ContentArtifactsBean artifactsBean = client.listContentArtifacts("application/wsdl+xml"); if (artifactsBean.getName() != null && artifactsBean.getName().length > 0) { return artifactsBean.getName(); } else { out[0] = "None"; } } catch (RegistryException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } return out; } @Override public String[] getList(String uuid, String path, Registry registry) { try { GenericArtifact[] artifacts; Registry gov = GovernanceUtils.getGovernanceUserRegistry(registry, "admin"); GovernanceUtils.loadGovernanceArtifacts((UserRegistry) gov); GenericArtifactManager manager = new GenericArtifactManager(gov, "wsdl"); artifacts = manager.getAllGenericArtifacts(); if (artifacts != null && artifacts.length > 0) { String[] artifactNames = new String[artifacts.length]; for (int i = 0; i < artifacts.length; i++) { artifactNames[i] = artifacts[i].getQName().getLocalPart(); } return artifactNames; } else { out[0] = "None"; return out; } } catch (RegistryException e) { log.error("An error occurred while obtaining the list of lifecycles.", e); } return new String[0]; } }
- Place it in the
<G-REG_HOME>/repository/lib/
directory. - Log in to the Management Console of WSO2 G-Reg using the following URL and admin/admin credentials: https://<G-REG_HOST>:<G-REG_PORT>/carbon/
- Click Extensions, and then click Artifact Types in the Configure menu.
- Click the View/Edit link of the soapservice artifact type as shown below.
Add a new field after the Description field, and then click Save.
<field type="options"> <name label="WSDL">WSDL</name> <values class="org.sampl.rxt.populator.WSDLPopulator"/> </field>
- Click Main, and then click SOAP Services in the Add menu. You view the new field added with the populated drop-down list in the Add SOAP Service screen as shown below.
- Log in to the G-Reg Publisher using the following URL and admin/admin credentials: http://<G-REG_HOST>:<G-REG_PORT>/publisher
- Click the Add button in the SOAP Services box.
- Select Add a SOAP Service manually, and then click Continue. You view the new field added with the populated drop-down list in the Add SOAP Service screen as shown below.