83 stpname=Macro People STP
84 ,stpdesc=This stp was created automatically by the mm_createstp macro
85 ,filename=mm_createstp.sas
86 ,directory=SASEnvironment/SASCode
87 ,tree=/User Folders/sasdemo
90 ,outds=work.mm_createstp
100 %
if &mDebug=1 %then %let mD=;
101 %
else %let mD=%str(*);
102 %&mD.put Executing mm_CreateSTP.sas;
105 %mf_verifymacvars(stpname filename directory tree)
106 %mp_dropmembers(%scan(&outds,2,.))
112 length type uri $256;
113 rc=metadata_pathobj("","&tree","Folder",type,uri);
114 call symputx('foldertype',type,'l');
115 call symputx('treeuri',uri,'l');
117 %if &foldertype ne Tree %then %do;
118 %put WARNING: Tree &tree does not exist!;
127 length type uri $256;
128 rc=metadata_pathobj("","&tree/&stpname",'StoredProcess',type,uri);
129 call symputx('cmtype',type,'l');
130 call symputx('stpuri',uri,'l');
132 %if &cmtype = ClassifierMap %then %do;
133 %put WARNING: Stored Process &stpname already exists in &tree!;
140 %if %sysfunc(fileexist(&directory/&filename)) ne 1 %then %do;
141 %put WARNING: FILE *&directory/&filename* NOT FOUND!;
145 %if &stptype=1 %then %do;
147 %if %sysevalf(&sysver lt 9.2) %then %do;
148 %put WARNING: Version 9.2 or later required;
154 length
id $20 dirtype $256;
155 rc=metadata_resolve("&directory",dirtype,
id);
156 call symputx('checkdirtype',dirtype,'l');
159 %if &checkdirtype ne Directory %then %do;
160 %mm_getdirectories(path=&directory,outds=&outds ,mDebug=&mDebug)
161 %if %mf_nobs(&outds)=0 or %sysfunc(exist(&outds))=0 %then %do;
162 %put WARNING: The directory
object does not exist for &directory;
168 directoryuri="&directory";
172 data &outds (keep=stpuri prompturi fileuri texturi);
173 length stpuri prompturi fileuri texturi serveruri $256 ;
177 length
id $20 type $256;
178 __rc=metadata_resolve("&treeuri",type,
id);
179 if type ne 'Tree' then do;
180 putlog "WARNING: Invalid tree URI: &treeuri";
183 __rc=metadata_resolve(directoryuri,type,
id);
184 if type ne 'Directory' then do;
185 putlog 'WARNING: Invalid directory URI: ' directoryuri;
190 __rc=metadata_resolve("&server",type,serveruri);
191 if type ne 'LogicalServer' then do;
192 __rc=metadata_getnobj("omsobj:LogicalServer?@Name='&server'",1,serveruri);
193 if serveruri='' then do;
194 putlog "WARNING: Invalid server: &server";
205 rc1=METADATA_NEWOBJ('PromptGroup',prompturi,'Parameters');
206 rc2=METADATA_SETATTR(prompturi, 'UsageVersion', '1000000');
207 rc3=METADATA_SETATTR(prompturi, 'GroupType','2');
208 rc4=METADATA_SETATTR(prompturi, 'Name','Parameters');
209 rc5=METADATA_SETATTR(prompturi, 'PublicType','Embedded:PromptGroup');
210 GroupInfo="<PromptGroup promptId='PromptGroup_%sysfunc(datetime())_&sysprocessid'"
211 !!" version='1.0'><Label><Text xml:lang='en-GB'>Parameters</Text>"
212 !!"</Label></PromptGroup>";
213 rc6 = METADATA_SETATTR(prompturi, 'GroupInfo',groupinfo);
215 if sum(of rc1-rc6) ne 0 then do;
216 putlog 'WARNING: Issue creating prompt.';
217 if prompturi ne . then do;
218 putlog ' Removing orphan: ' prompturi;
219 rc = METADATA_DELOBJ(prompturi);
226 rc7=METADATA_NEWOBJ('File',fileuri,'SP Source File');
227 rc8=METADATA_SETATTR(fileuri, 'FileName',"&filename");
228 rc9=METADATA_SETATTR(fileuri, 'IsARelativeName','1');
229 rc10=METADATA_SETASSN(fileuri, 'Directories','MODIFY',directoryuri);
230 if sum(of rc7-rc10) ne 0 then do;
231 putlog 'WARNING: Issue creating file.';
232 if fileuri ne . then do;
233 putlog ' Removing orphans:' prompturi fileuri;
234 rc = METADATA_DELOBJ(prompturi);
235 rc = METADATA_DELOBJ(fileuri);
242 rc11= METADATA_NEWOBJ('TextStore',texturi,'Stored Process');
243 rc12= METADATA_SETATTR(texturi, 'TextRole','StoredProcessConfiguration');
244 rc13= METADATA_SETATTR(texturi, 'TextType','XML');
245 storedtext='<?xml version="1.0" encoding="UTF-8"?><StoredProcess>'
246 !!"<ResultCapabilities Package='&package' Streaming='&streaming'/>"
247 !!"<OutputParameters/></StoredProcess>";
248 rc14= METADATA_SETATTR(texturi, 'StoredText',storedtext);
249 if sum(of rc11-rc14) ne 0 then do;
250 putlog 'WARNING: Issue creating TextStore.';
251 if texturi ne . then do;
252 putlog ' Removing orphans: ' prompturi fileuri texturi;
253 rc = METADATA_DELOBJ(prompturi);
254 rc = METADATA_DELOBJ(fileuri);
255 rc = METADATA_DELOBJ(texturi);
262 rc15= METADATA_NEWOBJ('ClassifierMap',stpuri,"&stpname");
263 rc16= METADATA_SETASSN(stpuri, 'Trees','MODIFY',treeuri);
264 rc17= METADATA_SETASSN(stpuri, 'ComputeLocations','MODIFY',serveruri);
265 rc18= METADATA_SETASSN(stpuri, 'SourceCode','MODIFY',fileuri);
266 rc19= METADATA_SETASSN(stpuri, 'Prompts','MODIFY',prompturi);
267 rc20= METADATA_SETASSN(stpuri, 'Notes','MODIFY',texturi);
268 rc21= METADATA_SETATTR(stpuri, 'PublicType', 'StoredProcess');
269 rc22= METADATA_SETATTR(stpuri, 'TransformRole', 'StoredProcess');
270 rc23= METADATA_SETATTR(stpuri, 'UsageVersion', '1000000');
271 rc24= METADATA_SETATTR(stpuri, 'Desc', "&stpdesc");
274 if sum(of rc15-rc24) ne 0 then do;
275 putlog 'WARNING: Issue creating STP.';
276 if stpuri ne . then do;
277 putlog ' Removing orphans: ' prompturi fileuri texturi stpuri;
278 rc = METADATA_DELOBJ(prompturi);
279 rc = METADATA_DELOBJ(fileuri);
280 rc = METADATA_DELOBJ(texturi);
281 rc = METADATA_DELOBJ(stpuri);
286 fullpath=cats('_program=',treepath,"/&stpname");
287 putlog "NOTE: Stored Process Created!";
288 putlog "NOTE- "; putlog "NOTE-"; putlog "NOTE-" fullpath;
289 putlog "NOTE- "; putlog "NOTE-";
295 %else %if &stptype=2 %then %do;
297 %if %sysevalf(&sysver lt 9.3) %then %do;
298 %put WARNING: SAS version 9.3 or later required to create type2 STPs;
303 length type uri $256;
304 rc=metadata_resolve("omsobj:ServerContext?@Name='&server'",type,uri);
305 call symputx('servertype',type,'l');
306 call symputx('serveruri',uri,'l');
309 %if &servertype ne ServerContext %then %do;
310 %put WARNING: ServerContext *&server* not found!;
317 filename &frefin temp;
320 treeuri=quote(symget('treeuri'));
321 serveruri=quote(symget('serveruri'));
322 stpdesc=quote(symget('stpdesc'));
323 stpname=quote(symget('stpname'));
325 put "<AddMetadata><Reposid>$METAREPOSITORY</Reposid><Metadata> "/
326 '<ClassifierMap UsageVersion="2000000" IsHidden="0" IsUserDefined="0" '/
327 ' IsActive="1" PublicType="StoredProcess" TransformRole="StoredProcess" '/
328 ' Name=' stpname ' Desc=' stpdesc '>'/
329 " <ComputeLocations>"/
330 " <ServerContext ObjRef=" serveruri "/>"/
331 " </ComputeLocations>"/
333 ' <TextStore IsHidden="0" Name="SourceCode" UsageVersion="0" '/
334 ' TextRole="StoredProcessSourceCode" StoredText="%put hello world!;" />'/
335 ' <TextStore IsHidden="0" Name="Stored Process" UsageVersion="0" '/
336 ' TextRole="StoredProcessConfiguration" TextType="XML" '/
337 ' StoredText="<?xml version="1.0" encoding="UTF-8&qu'@@
338 'ot;?><StoredProcess><ServerContext LogicalServerType="S'@@
339 'ps" OtherAllowed="false"/><ResultCapabilities Packa'@@
340 'ge="' @@ "&package" @@ '" Streaming="' @@ "&streaming" @@
341 '"/><OutputParameters/></StoredProcess>" />' /
344 ' <PromptGroup Name="Parameters" GroupType="2" IsHidden="0" '/
345 ' PublicType="Embedded:PromptGroup" UsageVersion="1000000" '/
346 ' GroupInfo="<PromptGroup promptId="PromptGroup_1502797359253'@@
347 '_802080" version="1.0"><Label><Text xml:lang='@@
348 '"en-US">Parameters</Text></Label></PromptGro'@@
351 "<Trees><Tree ObjRef=" treeuri "/></Trees>"/
352 "</ClassifierMap></Metadata><NS>SAS</NS>"/
353 "<Flags>268435456</Flags></AddMetadata>";
356 filename &frefout temp;
358 proc metadata in= &frefin out=&frefout verbose;
361 %if &mdebug=1 %then %do;
364 infile &frefout lrecl=1048576;
373 %mm_updatestpsourcecode(stp=&tree/&stpname
374 ,stpcode="&directory/&filename"
383 %put WARNING: STPTYPE=*&stptype* not recognised!;