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 @note 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 * Now we can create the application
105 */
106filename &frefin temp;
107
108/* write header XML */
109data _null_;
110 file &frefin;
111 name=quote(symget('name'));
112 desc=quote(symget('desc'));
113 ClassIdentifier=quote(symget('ClassIdentifier'));
114 version=quote(symget('version'));
115 params=quote(symget('params'));
116 treeuri=quote(symget('treeuri'));
117
118 put "<AddMetadata><Reposid>$METAREPOSITORY</Reposid><Metadata> "/
119 '<SoftwareComponent IsHidden="0" Name=' name ' ProductName=' name /
120 ' ClassIdentifier=' ClassIdentifier ' Desc=' desc /
121 ' SoftwareVersion=' version ' SpecVersion=' version /
122 ' Major="1" Minor="1" UsageVersion="1000000" PublicType="Application" >' /
123 ' <Notes>' /
124 ' <TextStore Name="Public Configuration Properties" IsHidden="0" ' /
125 ' UsageVersion="0" StoredText=' params '/>' /
126 ' </Notes>' /
127 "<Trees><Tree ObjRef=" treeuri "/></Trees>"/
128 "</SoftwareComponent></Metadata><NS>SAS</NS>"/
129 "<Flags>268435456</Flags></AddMetadata>";
130run;
131
132filename &frefout temp;
133
134proc metadata in= &frefin out=&frefout verbose;
135run;
136
137%if &mdebug=1 %then %do;
138 /* write the response to the log for debugging */
139 data _null_;
140 infile &frefout lrecl=1048576;
141 input;
142 put _infile_;
143 run;
144%end;
145
146%put NOTE: Checking to ensure application (&name) was created;
147data _null_;
148 length type uri $256;
149 rc=metadata_pathobj("","&tree/&name","Application",type,uri);
150 call symputx('apptype',type,'l');
151 %if &mdebug=1 %then putlog (_all_)(=);;
152run;
153%if &apptype ne SoftwareComponent %then %do;
154 %put %str(ERR)OR: Could not find (&name) at (&tree)!!;
155 %return;
156%end;
157%else %put NOTE: Application (&name) successfully created in (&tree)!;
158
159%mend mm_createapplication;