Production Ready Macros for SAS Application Developers
https://github.com/sasjs/core
mm_createapplication.sas
Go to the documentation of this file.
1/**
2 @file
3 @brief Create an Application object in a metadata folder
4 @details Application objects are useful for storing properties in metadata.
5 This macro is idempotent - it will not create an object with the same name
6 in the same location, twice.
7
8 usage:
9
10 %mm_createapplication(tree=/User Folders/sasdemo
11 ,name=MyApp
12 ,classidentifier=myAppSeries
13 ,params= name1=value1
name2=value2
emptyvalue=
14 )
15
16 @warning application components do not get deleted when removing the container
17 folder! be sure you have the administrative priviliges to remove this kind of
18 metadata from the SMC plugin (or be ready to do to so programmatically).
19
20 <h4> SAS Macros </h4>
21 @li mp_abort.sas
22 @li mf_verifymacvars.sas
23
24 @param tree= The metadata folder uri, or the metadata path, in which to
25 create the object. This must exist.
26 @param name= Application object name. Avoid spaces.
27 @param ClassIdentifier= the class of applications to which this app belongs
28 @param params= name=value pairs which will become public properties of the
29 application object. These are delimited using &#x0a; (newline character)
30
31 @param desc= Application description (optional). Avoid ampersands as these
32 are illegal characters (unless they are escapted- eg &amp;)
33 @param version= version number of application
34 @param frefin= fileref to use (enables change if there is a conflict). The
35 filerefs are left open, to enable inspection after running the
36 macro (or importing into an xmlmap if needed).
37 @param frefout= fileref to use (enables change if there is a conflict)
38 @param mDebug= set to 1 to show debug messages in the log
39
40 @author Allan Bowe
41
42**/
43
44%macro mm_createapplication(
45 tree=/User Folders/sasdemo
46 ,name=myApp
47 ,ClassIdentifier=mcore
48 ,desc=Created by mm_createapplication
49 ,params= param1=1&#x0a;param2=blah
50 ,version=
51 ,frefin=mm_in
52 ,frefout=mm_out
53 ,mDebug=1
54 );
55
56%local mD;
57%if &mDebug=1 %then %let mD=;
58%else %let mD=%str(*);
59%&mD.put Executing &sysmacroname..sas;
60%&mD.put _local_;
61
62%mf_verifymacvars(tree name)
63
64/**
65 * check tree exists
66 */
67
68data _null_;
69 length type uri $256;
70 rc=metadata_pathobj("","&tree","Folder",type,uri);
71 call symputx('type',type,'l');
72 call symputx('treeuri',uri,'l');
73run;
74
75%mp_abort(
76 iftrue= (&type ne Tree)
77 ,mac=mm_createapplication.sas
78 ,msg=Tree &tree does not exist!
79)
80
81/**
82 * Check object does not exist already
83 */
84data _null_;
85 length type uri $256;
86 rc=metadata_pathobj("","&tree/&name","Application",type,uri);
87 call symputx('type',type,'l');
88 putlog (_all_)(=);
89run;
90
91%mp_abort(
92 iftrue= (&type = SoftwareComponent)
93 ,mac=mm_createapplication.sas
94 ,msg=Application &name already exists in &tree!
95)
96
97
98/**
99 * Now we can create the application
100 */
101filename &frefin temp;
102
103/* write header XML */
104data _null_;
105 file &frefin;
106 name=quote(symget('name'));
107 desc=quote(symget('desc'));
108 ClassIdentifier=quote(symget('ClassIdentifier'));
109 version=quote(symget('version'));
110 params=quote(symget('params'));
111 treeuri=quote(symget('treeuri'));
112
113 put "<AddMetadata><Reposid>$METAREPOSITORY</Reposid><Metadata> "/
114 '<SoftwareComponent IsHidden="0" Name=' name ' ProductName=' name /
115 ' ClassIdentifier=' ClassIdentifier ' Desc=' desc /
116 ' SoftwareVersion=' version ' SpecVersion=' version /
117 ' Major="1" Minor="1" UsageVersion="1000000" PublicType="Application" >' /
118 ' <Notes>' /
119 ' <TextStore Name="Public Configuration Properties" IsHidden="0" ' /
120 ' UsageVersion="0" StoredText=' params '/>' /
121 ' </Notes>' /
122 "<Trees><Tree ObjRef=" treeuri "/></Trees>"/
123 "</SoftwareComponent></Metadata><NS>SAS</NS>"/
124 "<Flags>268435456</Flags></AddMetadata>";
125run;
126
127filename &frefout temp;
128
129proc metadata in= &frefin out=&frefout verbose;
130run;
131
132%if &mdebug=1 %then %do;
133 /* write the response to the log for debugging */
134 data _null_;
135 infile &frefout lrecl=1048576;
136 input;
137 put _infile_;
138 run;
139%end;
140
141%put NOTE: Checking to ensure application (&name) was created;
142data _null_;
143 length type uri $256;
144 rc=metadata_pathobj("","&tree/&name","Application",type,uri);
145 call symputx('apptype',type,'l');
146 %if &mdebug=1 %then putlog (_all_)(=);;
147run;
148%if &apptype ne SoftwareComponent %then %do;
149 %put %str(ERR)OR: Could not find (&name) at (&tree)!!;
150 %return;
151%end;
152%else %put NOTE: Application (&name) successfully created in (&tree)!;
153
154
155%mend mm_createapplication;