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