Tuesday 5 July 2016

Using MDS (MetaData Service) API to list all the deployed composites in SOA

The jar mdsrt.jar contains all the necessary API to explore contents inside MDS (MetaData Store). Unfortunately there is no javadoc for the classes inside this jar, atleast I couldn't find couple of blog links to understand the usage of some MDS APIs.

In this blog, my intention is to show how to read a file using MDS API.

The first task is to write the adf-mds-confix.xml file which contains the configuration information to connect to MDS and the <metadata-namespaces> contains the name of the folders whose sub-folders or files that will be accessed using MDS API.

<?xml version = '1.0' encoding = 'UTF-8'?>
 <adf-config xmlns="http://xmlns.oracle.com/adf/config">
    <adf-mds-config xmlns="http://xmlns.oracle.com/adf/mds/config">
       <mds-config version="11.1.1.000" xmlns="http://xmlns.oracle.com/mds/config">
                <persistence-config>
                         <metadata-namespaces>
                                 <namespace path="/soa/shared" metadata-store-usage="soa-infra-store">
                                 </namespace>
                                 <namespace path="/apps" metadata-store-usage="soa-infra-store"/>
                         </metadata-namespaces>
                         <metadata-store-usages>
                                <metadata-store-usage id="soa-infra-store">
                                        <metadata-store xmlns="http://xmlns.oracle.com/mds/config"
                                                                        class-name="oracle.mds.persistence.stores.db.DBMetadataStore">

                                                        <property name="jndi-datasource" value="jdbc/mds/owsm"/>

                                                          <property name="partition-name" value="soa-infra"/>
                                         </metadata-store>
                                  </metadata-store-usage>
                          </metadata-store-usages>

      </persistence-config>
 </mds-config>
     </adf-mds-config>
  </adf-config>




    /**
     * This API returns the list of deployed composited in SOA server
     * 
     * @return list of composites
     */
    public List<Composite> getDeployedComposites() {
        List<Composite> deployedList = new ArrayList<>();
        try {
            // Read the adf-mds-config.xml config file which has the configuration information for reading a file from MDS            
            File adfConfigPath = new File(configPath.toString());
            MDSConfig config = new MDSConfig(adfConfigPath.toURL());
            
            // Create MDS instance & Session
            MDSInstance mdsInstance = MDSInstance.getOrCreateInstance("TargetInstance", config);
            MDSSession mdsSession = mdsInstance.createSession(new SessionOptions(null, null, new CustConfig(new CustClassListMapping[0])), null);
            
            // Form a query which reads the deployed-composites.xml file
            NameQueryImpl query = new NameQueryImpl(mdsSession, ConditionFactory.createNameCondition("/deployed-composites", "deployed-composites.xml", true));
            Iterator<DocumentResult> r = query.execute();
            while(r.hasNext()) {
                DocumentResult dr = r.next();                
                if (dr.getAbsoluteName().endsWith(".xml")) {
                    MetadataObject mdObj = mdsSession.getMetadataObject(dr.getAbsoluteName());
                    
                    // Get the DOM object of the deployed-compisite.xml
                    Document doc = mdObj.getDocument(true);
                    
                    // Access the composite name from the xml
                    // eg: <composite-series name="default/ScheduledProcessFlow" default="default/ScheduledProcessFlow!2.0">
                    NodeList nList = doc.getElementsByTagName("composite-series");
                    for (int i=0;i<nList.getLength();i++) {
                            Node node = nList.item(i);
                            String str = node.getAttributes().getNamedItem("default").getNodeValue();
                            
                            // Add composite details to the list
                            deployedList.add(getCompositeObj(str));
                    }                    
                    break;
                }
            }
        } catch(Exception ex) {
           throw new RuntimeException("Unable to read the deployed-composites.xml file " + "\n" + ex.getMessage());
        }
        return deployedList;

    }


Some blog links which I referred


http://oraclemw.blogspot.in/2011/04/working-with-oracle-mds-repository.html

http://amulyamishras-tech-blog.blogspot.in/2013/07/adf-nds-use-mds-api-to-remove.html
http://www.oracle.com/technetwork/developer-tools/jdev/metadataservices-fmw-11gr1-130345.pdf

No comments:

Post a Comment