Thursday Aug 11, 2011

Full access to MDS Repository

JDeveloper allows you to browse the tree structure of any MDS repository, DB or File based. After creating the appropriate connection, a JTree is created, and all documents and packages of the MDS repository are available in it. To manipulate those documents, it is not unusual to use WLST (WebLogic Scripting Tool). MDS provides a few APIs for now, obviously dedicated to the manipulation of the documents needed and managed by the SOA/SCA part of the stack. MDS can definitely be used to store any sharable document, whether they are related to SCA or not. Currently this manipulation of the MDS artifacts using WLST is not supported in 11g, however in this blog post we are sharing a way to access those documents from the command line scripting tool. The approach we took was to use the tools JDeveloper is using to build the MDS Connection tree. The linked archive provides a JDeveloper project that contains one class, named MDSUtils. It requires a couple of libraries to be used at compilation and runtime (mentioned in the project available at the bottom of the post). This class contains a main method, illustrating the way to use it from Java.
   public static void main(String[] args)
   {
     try
     {
       MDSInstance mdsInstance = null;
       mdsInstance = MDSUtils.initializeDBStore("TEST_MDS",
                                                "welcome1",                                                
                                                "jdbc:oracle:thin:@<machine.name>:1521:XE",
                                                "soa-infra",
                                                MDS_CONNECTION_NAME);
       // Recurse and display, from the root.
       recurse(mdsInstance, null, 0);

       // Find a resource
       List list = MDSUtils.findResource(mdsInstance, "deployed-composites", false);
       System.out.println("List: (" + list.size() + " element(s))");
       for (ResourceName rn : list)
         System.out.println("Found : " + rn.getAbsoluteName() + " (a " + 
                            (rn.isPackageName()?"package":"document") + ")");

       MDSUtils.createFolder(mdsInstance, PackageName.createPackageName("/oliv"));

       // Deleting folder
       List list = MDSUtils.findResource(mdsInstance, "oliv", false);
       System.out.println("List: (" + list.size() + " element(s))");
       for (ResourceName rn : list)
       {
         System.out.println("Found : " + rn.getAbsoluteName() + " (a " + 
                                  (rn.isPackageName()?"package":"document") + ")");
         if (rn.isPackageName() && rn.getAbsoluteName().equals("/oliv"))
         {
           System.out.println("Deleting " + rn.getAbsoluteName());
           MDSUtils.deleteResource(mdsInstance, rn);
         }
         else
           System.out.println("Leaving " + rn.getAbsoluteName() + " alone.");
       }
       System.out.println("Done");
     }
As WLST is based on Jython, and as Jython can make Java calls, the bridge between WLST and the Java code above is obvious. Here is a code snippet doing the something close to the Java code above, that can be run using WLST:
print "-----------------------------"
y = "Yes"
Y = y
n = "No"
N = n
from oracle.ateam import MDSUtils
mdsUtils = MDSUtils()
# setup Connection parameters
# The first call (createFolder, deleteFolder) will create the 
MDSInstance with those parameters.
mdsUtils.setUserName("TEST_MDS")
mdsUtils.setPassword("welcome1")
mdsUtils.setPartition("soa-infra")
mdsUtils.setDbUrl("jdbc:oracle:thin:@machine.name:1521:XE")
#
response = input("Do we create the \"oliv\" directory ? [y|n] > ")
if response == y:
   print "Creating directory"
   mdsUtils.createFolder("/oliv")
response = input("Do we delete the \"oliv\" directory ? [y|n] > ")
if response == y:
   print "Deleting directory"
   mdsUtils.deleteFolder("/oliv")
print "Done."
print "Bye now"

The only thing to do before running this snippet from WLST is to put the required classes in WLST's classpath. A script contained in the archive is illustrating this point.

The JDeveloper project containing the code is available from here.

About


This is the blog for the Oracle FMW Architects team fondly known as the A-Team. The A-Team is the central, technical, outbound team as part of the FMW Development organization working with Oracle's largest and most important customers. We support Oracle Sales, Consulting and Support when deep technical and architectural help is needed from Oracle Development.
Primarily this blog is tailored for SOA issues (BPEL, OSB, BPM, Adapters, CEP, B2B, JCAP)that are encountered by our team. Expect real solutions to customer problems, encountered during customer engagements.
We will highlight best practices, workarounds, architectural discussions, and discuss topics that are relevant in the SOA technical space today.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today