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