Ever stumbled across a familiar statement
import %metadata:*;
Well PS itself rarely uses this. I was lucky enough to realize its potential during a Apps/Tools upgrade. We were moving from FSCM 8/8.21 to FSCM 8.9/8.48.
This metadata API has not been documented anywhere in PeopleBooks. I feel this is by far the most robust API that PS has delivered till date. I actually went ahead and used this API as pilot to see the real benefits of it. The custom solution was designed to create PS Projects and migrate them from PIA itself. Though the script used to compare (Pre/Post) and migrate the project was courtesy Written by Praj Basnet & Copyright 2008 the custom solution is totally original :)
The API can be extended as follows
import %metadata:ProjectDefn:*;import %metadata:RecordDefn:*;I only tried it for a few more objects, but you realize it can be similarly extended for all other DEFN Tables (PeopleTools definition tables used for PS Objects)
What is important to note is that to use this API you need to make sure you keep the following in mind
- For all imports like above, you need to define a manager object:
For example -
&mgr = create %metadata:ProjectDefn:ProjectDefn_Manager(); &mgrRec_ = create %metadata:RecordDefn:RecordDefn_Manager(); 2. A similar property also needs to be defined:
For example -
property %metadata:ProjectDefn:ProjectDefn_Manager mgr; property %metadata:RecordDefn:RecordDefn_Manager mgrRec_;You can then define your own methods like
1. insertAppPackage
2. insertRecord
3. insertAE
and so on to cover all/some PS Objects
But the most important of all methods is the
insertItemToProjectSome very basic PeopleCode to get you started -
/******************************************/
import %metadata:*;
import %metadata:ProjectDefn:*;
import %metadata:RecordDefn:*;
class PPProject
method PPProject();
method CreateProject();
method insertItemToProject(&iObjectType As integer, &iObjectID0 As integer, &sObjectValue0 As string, &iObjectID1 As integer, &sObjectValue1 As string, &iObjectID2 As integer, &sObjectValue2 As string, &iObjectID3 As integer, &sObjectValue3 As string, &iUpgradeAction As integer, &defn As %metadata:ProjectDefn:ProjectDefn);
method insertAE(&sAEProgramName As string);
method insertRecord(&sRecordName As string);
method insertAppPackage(&sAppPackage As string);
method initializeProjects();
method getProject(&sProjectName As string) Returns %metadata:ProjectDefn:ProjectDefn;
method getRecordDoNotUse(&sRecordName As string) Returns %metadata:RecordDefn:RecordDefn;
property string sCreateProject;
property %metadata:ProjectDefn:ProjectDefn_Manager mgr;
property %metadata:RecordDefn:RecordDefn_Manager mgrRec_;
end-class;
method PPProject
&mgr = create %metadata:ProjectDefn:ProjectDefn_Manager();
&mgrRec_ = create %metadata:RecordDefn:RecordDefn_Manager();
rem &sCreateProject = "PTPATCHIBCONVERT";
%This.CreateProject();
end-method;
method CreateProject
rem this class will be used to create Projects in App Designer;
&sCreateProject = Z_LONG_TBL.EMPLID.Value;
MessageBox(0, "", 0, 0, "&ProjectName_ " | &sCreateProject);
end-method;
method insertItemToProject
/+ &iObjectType as Integer, +/
/+ &iObjectID0 as Integer, +/
/+ &sObjectValue0 as String, +/
/+ &iObjectID1 as Integer, +/
/+ &sObjectValue1 as String, +/
/+ &iObjectID2 as Integer, +/
/+ &sObjectValue2 as String, +/
/+ &iObjectID3 as Integer, +/
/+ &sObjectValue3 as String, +/
/+ &iUpgradeAction as Integer, +/
/+ &defn as %Metadata:ProjectDefn:ProjectDefn +/
Local string &sProjectName;
/*Check to see if the item already exists in the project , modified the select to query only basd on keys*/
rem SQLExec("SELECT PROJECTNAME FROM PSPROJECTITEM WHERE PROJECTNAME = :1 AND OBJECTTYPE = :2 AND OBJECTID1 = :3 AND OBJECTVALUE1 = :4 AND OBJECTID2 = :5 AND OBJECTVALUE2 = :6 AND OBJECTID3 = :7 AND OBJECTVALUE3 = :8", &defn.ProjectName, &iObjectType, &iObjectID0, &sObjectValue0, &iObjectID1, &sObjectValue1, &iObjectID2, &sObjectValue2, &sProjectName);
SQLExec("SELECT PROJECTNAME FROM PSPROJECTITEM WHERE PROJECTNAME = :1 AND OBJECTTYPE = :2 AND OBJECTVALUE1 = :3 AND OBJECTVALUE2 = :4 AND OBJECTVALUE3 = :5", &defn.ProjectName, &iObjectType, &sObjectValue0, &sObjectValue1, &sObjectValue2, &sProjectName);
If &sProjectName <> "" Then
Return;
End-If;
Local %metadata:ProjectDefn:PjmPit &newPit;
Local integer &iCount = &defn.Count_Pit;
&newPit = &defn.Append_Pit(&iCount);
&newPit.ObjectType = &iObjectType;
&newPit.ObjectID#0# = &iObjectID0;
&newPit.ObjectValue#0# = &sObjectValue0;
&newPit.ObjectID#1# = &iObjectID1;
&newPit.ObjectValue#1# = &sObjectValue1;
&newPit.ObjectID#2# = &iObjectID2;
&newPit.ObjectValue#2# = &sObjectValue2;
&newPit.ObjectID#3# = &iObjectID3;
&newPit.ObjectValue#3# = &sObjectValue3;
&newPit.TakeAction = True;
/* 1 for Delete, 0 for Copy */
&newPit.UpgradeAction = &iUpgradeAction;
If Not (&defn.UpdateDefn()) Then
/*Todo throw error */
End-If;
end-method;
method insertAE
/+ &sAEProgramName as String +/
If &sCreateProject <> "" Then
Local %metadata:ProjectDefn:ProjectDefn &defn;
&defn = %This.getProject(&sCreateProject);
rem By default insert all related definitions;
%This.insertItemToProject(33, 66, &sAEProgramName, 0, "", 0, "", 0, "", 0, &defn);
%This.insertItemToProject(34, 66, &sAEProgramName, 77, "MAIN", 0, "", 0, "", 0, &defn);
%This.insertItemToProject(43, 66, &sAEProgramName, 77, "MAIN GBLdefault 1900-01-01", 78, "Step02", 12, "OnExecute", 0, &defn);
End-If;
end-method;
method insertRecord
/+ &sRecordName as String +/
If &sCreateProject <> "" Then
Local %metadata:ProjectDefn:ProjectDefn &defn;
Local %metadata:RecordDefn:RecordDefn &Recdefn_;
&defn = %This.getProject(&sCreateProject);
&Recdefn_ = %This.getRecordDoNotUse(&sRecordName);
rem &Recdefn_.RecDescr = "AE REN State Record";
%This.insertItemToProject(0, 1, &sRecordName, 0, "", 0, "", 0, "", 0, &defn);
%This.insertItemToProject(8, 1, &sRecordName, 0, "", 0, "", 0, "", 0, &defn);
End-If;
end-method;
method insertAppPackage
/+ &sAppPackage as String +/
Local string &AppClassID_, &PckgRoot_, &QlfyPath_, &QlfyPath1_;
If &sCreateProject <> "" Then
Local %metadata:ProjectDefn:ProjectDefn &defn;
&defn = %This.getProject(&sCreateProject);
rem Ideally queries should be used to retrieve the defns from Object Defn Tables;
Local string &AppPackageSQL_ = "SELECT PACKAGEROOT, QUALIFYPATH FROM PSPACKAGEDEFN WHERE PACKAGEID = :1";
Local string &AppClassSQL_ = "SELECT APPCLASSID, PACKAGEROOT, QUALIFYPATH FROM PSAPPCLASSDEFN WHERE PACKAGEROOT = :1";
SQLExec(&AppPackageSQL_, &sAppPackage, &PckgRoot_, &QlfyPath_);
SQLExec(&AppClassSQL_, &sAppPackage, &AppClassID_, &PckgRoot_, &QlfyPath1_);
%This.insertItemToProject(57, 104, &sAppPackage, 116, &PckgRoot_, 117, &QlfyPath_, 0, "", 0, &defn);
%This.insertItemToProject(58, 104, &sAppPackage, 105, &QlfyPath1_, 107, &AppClassID_, 0, "", 0, &defn);
/*
%This.insertItemToProject(57, 104, &sAppPackage, 116, "Z_PSTOKEN", 117, ".", 0, "", 0, &defn);
%This.insertItemToProject(58, 104, &sAppPackage, 105, "PSToken", 107, "PSTOKEN", 0, "", 0, &defn);
*/
End-If;
end-method;
method initializeProjects
Local %metadata:ProjectDefn:ProjectDefn &oCreateDefn, &oDeleteDefn;
&oCreateDefn = %This.getProject(&sCreateProject);
end-method;
/*******************************************************************************
method: getProject
purpose: Checks to see if the project already exists, if not it creates it
*******************************************************************************/
method getProject
/+ &sProjectName as String +/
/+ Returns %Metadata:ProjectDefn:ProjectDefn +/
Local %metadata:Key &key = create %metadata:Key(Key:Class_Project, &sProjectName);
Local %metadata:ProjectDefn:ProjectDefn &defn = &mgr.GetDefn(&key);
If Not (&mgr.DefnExists(&key)) Then
&defn = &mgr.CreateDefn();
&defn.ProjectName = &sProjectName;
&defn.ProjectDescr = "PPs code created project";
&defn.ReleaseDttm = "2009-04-13 15:52:19.000";
&defn.ObjectOwnerId = "PPT";
&defn.DescrLong = "This Project is created by PP's App Package to create Projects in Application Designer";
&defn.CommitLimit = 50;
If Not (&defn.SaveNewDefn()) Then
/*ToDo log error */
End-If;
Return &defn;
Else
Local %metadata:ProjectDefn:ProjectDefn &ProjectDefn = &mgr.GetPrivateDefn(&key);
Return &ProjectDefn;
End-If;
end-method;
/******************************************/
FYIThere is a case on metalink3 about %metadata
https://metalink3.oracle.com/od/faces/secure/km/DocumentDisplay.jspx?id=849911.1
Thanks!!