wso2artifactwso2-governance-registry

How can I getAttributeValue in Governance Artifacts whith wso2 Governance?


Situation is like this I define a Artifact Type like this:

<artifactType type="application/vnd.wso2-tets+xml" shortName="test" singularLabel="tests" pluralLabel="tests" hasNamespace="false" iconSet="9">
    <storagePath>/applications/@{name}/@{overview_version}</storagePath>
    <nameAttribute>overview_name</nameAttribute>
    <ui>
        <list>
            <column name="Name">
                <data type="path" value="overview_name" href="/applications/@{name}"/>
            </column>
            <column name="Version">
                <data type="path" value="overview_version" href="@{storagePath}"/>
            </column>
        </list>
    </ui>
    <content>
        <table name="Overview">
            <field type="text" required="true">
                <name>Name</name>
            </field>
            <field type="text" required="true">
                <name>Version</name>
            </field>
            <field type="text-area">
                <name>Description</name>
            </field>
            <field type="options">
         <name label="Zcos">Zcos</name>
         <values class="cn.oge.wso2.populator.AlgPopulator"/>
       </field>
        </table>
    </content>
</artifactType>

At the same time I also defines a handler,the mediaType is "application/vnd.wso2-tets+xml" the handler code like this:

public class XcosMediaTypeHandler extends Handler {

    public Resource get(RequestContext requestContext) throws RegistryException {
        return null;
    }

    public void put(RequestContext requestContext) throws RegistryException {
        Resource resource = requestContext.getResource();
        String name = "";
        String version = "";
        String description = "";
        String zcos = "";

        byte[] content = (byte[]) resource.getContent();
        ByteArrayInputStream in = new ByteArrayInputStream(content);
        OMElement docElement = null;
        try {
            StAXOMBuilder builder = new StAXOMBuilder(in);
            docElement = builder.getDocumentElement();
        } catch (Exception ae) {
            throw new RegistryException(
                    "Failed to parse the propject proposal. "
                            + "All project proposals should be in XML format.");
        }
        System.out.println("==========================================");
        OMElement firstElement = docElement.getFirstElement();
        System.out.println(firstElement);
        Iterator<OMElement> ite = firstElement.getChildElements();
        for (OMElement e = ite.next(); ite.hasNext(); e = ite.next()) {
            if (e.getLocalName().equals("name")) {
                name = e.getText();
            } else if (e.getLocalName().equals("version")) {
                version = e.getText();
            } else if (e.getLocalName().equals("description")) {
                description = e.getText();
            } else if (e.getLocalName().equals("zcos")) {
                zcos = e.getText();
            }
        }

        System.out.println("Name:" + name);
        System.out.println("Version:" + version);
        System.out.println("Description:" + description);
        System.out.println("zcos:" + zcos);         
    }

    public void importResource(RequestContext requestContext)
            throws RegistryException {
        System.out.println("importResource");
    }

    public void delete(RequestContext requestContext) throws RegistryException {

    }

    public void putChild(RequestContext requestContext)
            throws RegistryException {
        System.out.println("putChild");
    }

    public void importChild(RequestContext requestContext)
            throws RegistryException {
        System.out.println("importChild");
    }

}

The question is coming , When I use UI to add a Artifact ,For example: enter image description here

In the above code , I can get attribute value for Name,Version and Description. but I can't get attribute value for Zcos. In the define of Artifact the Zos of the filed type is options ,The other attributes of the filed type is text or text-area. Why I can't get Zcos property value?Thanks in advance!


Solution

  • for less confusion make the filed reference lowercase like below,

    <field type="options">
      <name label="Zcos">zcos</name>
      <values class="cn.oge.wso2.populator.AlgPopulator"/>
    </field>
    

    find below code to get zcos value,

    // Get the first OMElement child with name 'overview'
    OMElement elementOverview = getFirstChild(docElement, "overview");
    // Get the first OMElement child with name 'zcos' and appending absolute path prefix.
    String zcos = getFirstChild(elementOverview, "zcos").getText();
    

    To find a sample code please find this blog post.