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%mp_abort(iftrue= (%mf_verifymacvars(tree name)=0)
63 ,mac=&sysmacroname
64 ,msg=%str(Empty inputs: tree name)
65)
66
67/**
68 * check tree exists
69 */
70
71data _null_;
72 length type uri $256;
73 rc=metadata_pathobj("","&tree","Folder",type,uri);
74 call symputx('type',type,'l');
75 call symputx('treeuri',uri,'l');
76run;
77
78%mp_abort(
79 iftrue= (&type ne Tree)
80 ,mac=mm_createapplication.sas
81 ,msg=Tree &tree does not exist!
82)
83
84/**
85 * Check object does not exist already
86 */
87data _null_;
88 length type uri $256;
89 rc=metadata_pathobj("","&tree/&name","Application",type,uri);
90 call symputx('type',type,'l');
91 putlog (_all_)(=);
92run;
93
94%mp_abort(
95 iftrue= (&type = SoftwareComponent)
96 ,mac=mm_createapplication.sas
97 ,msg=Application &name already exists in &tree!
98)
99
100
101/**
102 * Now we can create the application
103 */
104filename &frefin temp;
105
106/* write header XML */
107data _null_;
108 file &frefin;
109 name=quote(symget('name'));
110 desc=quote(symget('desc'));
111 ClassIdentifier=quote(symget('ClassIdentifier'));
112 version=quote(symget('version'));
113 params=quote(symget('params'));
114 treeuri=quote(symget('treeuri'));
115
116 put "<AddMetadata><Reposid>$METAREPOSITORY</Reposid><Metadata> "/
117 '<SoftwareComponent IsHidden="0" Name=' name ' ProductName=' name /
118 ' ClassIdentifier=' ClassIdentifier ' Desc=' desc /
119 ' SoftwareVersion=' version ' SpecVersion=' version /
120 ' Major="1" Minor="1" UsageVersion="1000000" PublicType="Application" >' /
121 ' <Notes>' /
122 ' <TextStore Name="Public Configuration Properties" IsHidden="0" ' /
123 ' UsageVersion="0" StoredText=' params '/>' /
124 ' </Notes>' /
125 "<Trees><Tree ObjRef=" treeuri "/></Trees>"/
126 "</SoftwareComponent></Metadata><NS>SAS</NS>"/
127 "<Flags>268435456</Flags></AddMetadata>";
128run;
129
130filename &frefout temp;
131
132proc metadata in= &frefin out=&frefout verbose;
133run;
134
135%if &mdebug=1 %then %do;
136 /* write the response to the log for debugging */
137 data _null_;
138 infile &frefout lrecl=1048576;
139 input;
140 put _infile_;
141 run;
142%end;
143
144%put NOTE: Checking to ensure application (&name) was created;
145data _null_;
146 length type uri $256;
147 rc=metadata_pathobj("","&tree/&name","Application",type,uri);
148 call symputx('apptype',type,'l');
149 %if &mdebug=1 %then putlog (_all_)(=);;
150run;
151%if &apptype ne SoftwareComponent %then %do;
152 %put %str(ERR)OR: Could not find (&name) at (&tree)!!;
153 %return;
154%end;
155%else %put NOTE: Application (&name) successfully created in (&tree)!;
156
157
158%mend mm_createapplication;