86 stpname=Macro People STP
87 ,stpdesc=This stp was created automatically by the mm_createstp macro
88 ,filename=mm_createstp.sas
89 ,directory=SASEnvironment/SASCode
90 ,tree=/User Folders/sasdemo
93 ,outds=work.mm_createstp
103 %
if &mDebug=1 %then %let mD=;
104 %
else %let mD=%str(*);
105 %&mD.put Executing mm_CreateSTP.sas;
108 %mf_verifymacvars(stpname filename directory tree)
109 %mp_dropmembers(%scan(&outds,2,.))
115 length type uri $256;
116 rc=metadata_pathobj("","&tree","Folder",type,uri);
117 call symputx('foldertype',type,'l');
118 call symputx('treeuri',uri,'l');
120 %if &foldertype ne Tree %then %do;
121 %put WARNING: Tree &tree does not exist!;
130 length type uri $256;
131 rc=metadata_pathobj("","&tree/&stpname",'StoredProcess',type,uri);
132 call symputx('cmtype',type,'l');
133 call symputx('stpuri',uri,'l');
135 %if &cmtype = ClassifierMap %then %do;
136 %put WARNING: Stored Process &stpname already exists in &tree!;
143 %if %sysfunc(fileexist(&directory/&filename)) ne 1 %then %do;
144 %put WARNING: FILE *&directory/&filename* NOT FOUND!;
148 %if &stptype=1 %then %do;
150 %if %sysevalf(&sysver lt 9.2) %then %do;
151 %put WARNING: Version 9.2 or later required;
157 length
id $20 dirtype $256;
158 rc=metadata_resolve("&directory",dirtype,
id);
159 call symputx('checkdirtype',dirtype,'l');
162 %if &checkdirtype ne Directory %then %do;
163 %mm_getdirectories(path=&directory,outds=&outds ,mDebug=&mDebug)
164 %if %mf_nobs(&outds)=0 or %sysfunc(exist(&outds))=0 %then %do;
165 %put WARNING: The directory
object does not exist for &directory;
171 directoryuri="&directory";
175 data &outds (keep=stpuri prompturi fileuri texturi);
176 length stpuri prompturi fileuri texturi serveruri $256 ;
180 length
id $20 type $256;
181 __rc=metadata_resolve("&treeuri",type,
id);
182 if type ne 'Tree' then do;
183 putlog "WARNING: Invalid tree URI: &treeuri";
186 __rc=metadata_resolve(directoryuri,type,
id);
187 if type ne 'Directory' then do;
188 putlog 'WARNING: Invalid directory URI: ' directoryuri;
193 __rc=metadata_resolve("&server",type,serveruri);
194 if type ne 'LogicalServer' then do;
195 __rc=metadata_getnobj("omsobj:LogicalServer?@Name='&server'",1,serveruri);
196 if serveruri='' then do;
197 putlog "WARNING: Invalid server: &server";
208 rc1=METADATA_NEWOBJ('PromptGroup',prompturi,'Parameters');
209 rc2=METADATA_SETATTR(prompturi, 'UsageVersion', '1000000');
210 rc3=METADATA_SETATTR(prompturi, 'GroupType','2');
211 rc4=METADATA_SETATTR(prompturi, 'Name','Parameters');
212 rc5=METADATA_SETATTR(prompturi, 'PublicType','Embedded:PromptGroup');
213 GroupInfo="<PromptGroup promptId='PromptGroup_%sysfunc(datetime())_&sysprocessid'"
214 !!" version='1.0'><Label><Text xml:lang='en-GB'>Parameters</Text>"
215 !!"</Label></PromptGroup>";
216 rc6 = METADATA_SETATTR(prompturi, 'GroupInfo',groupinfo);
218 if sum(of rc1-rc6) ne 0 then do;
219 putlog 'WARNING: Issue creating prompt.';
220 if prompturi ne . then do;
221 putlog ' Removing orphan: ' prompturi;
222 rc = METADATA_DELOBJ(prompturi);
229 rc7=METADATA_NEWOBJ('File',fileuri,'SP Source File');
230 rc8=METADATA_SETATTR(fileuri, 'FileName',"&filename");
231 rc9=METADATA_SETATTR(fileuri, 'IsARelativeName','1');
232 rc10=METADATA_SETASSN(fileuri, 'Directories','MODIFY',directoryuri);
233 if sum(of rc7-rc10) ne 0 then do;
234 putlog 'WARNING: Issue creating file.';
235 if fileuri ne . then do;
236 putlog ' Removing orphans:' prompturi fileuri;
237 rc = METADATA_DELOBJ(prompturi);
238 rc = METADATA_DELOBJ(fileuri);
245 rc11= METADATA_NEWOBJ('TextStore',texturi,'Stored Process');
246 rc12= METADATA_SETATTR(texturi, 'TextRole','StoredProcessConfiguration');
247 rc13= METADATA_SETATTR(texturi, 'TextType','XML');
248 storedtext='<?xml version="1.0" encoding="UTF-8"?><StoredProcess>'
249 !!"<ResultCapabilities Package='&package' Streaming='&streaming'/>"
250 !!"<OutputParameters/></StoredProcess>";
251 rc14= METADATA_SETATTR(texturi, 'StoredText',storedtext);
252 if sum(of rc11-rc14) ne 0 then do;
253 putlog 'WARNING: Issue creating TextStore.';
254 if texturi ne . then do;
255 putlog ' Removing orphans: ' prompturi fileuri texturi;
256 rc = METADATA_DELOBJ(prompturi);
257 rc = METADATA_DELOBJ(fileuri);
258 rc = METADATA_DELOBJ(texturi);
265 rc15= METADATA_NEWOBJ('ClassifierMap',stpuri,"&stpname");
266 rc16= METADATA_SETASSN(stpuri, 'Trees','MODIFY',treeuri);
267 rc17= METADATA_SETASSN(stpuri, 'ComputeLocations','MODIFY',serveruri);
268 rc18= METADATA_SETASSN(stpuri, 'SourceCode','MODIFY',fileuri);
269 rc19= METADATA_SETASSN(stpuri, 'Prompts','MODIFY',prompturi);
270 rc20= METADATA_SETASSN(stpuri, 'Notes','MODIFY',texturi);
271 rc21= METADATA_SETATTR(stpuri, 'PublicType', 'StoredProcess');
272 rc22= METADATA_SETATTR(stpuri, 'TransformRole', 'StoredProcess');
273 rc23= METADATA_SETATTR(stpuri, 'UsageVersion', '1000000');
274 rc24= METADATA_SETATTR(stpuri, 'Desc', "&stpdesc");
277 if sum(of rc15-rc24) ne 0 then do;
278 putlog "%str(WARN)ING: Issue creating STP.";
279 if stpuri ne . then do;
280 putlog ' Removing orphans: ' prompturi fileuri texturi stpuri;
281 rc = METADATA_DELOBJ(prompturi);
282 rc = METADATA_DELOBJ(fileuri);
283 rc = METADATA_DELOBJ(texturi);
284 rc = METADATA_DELOBJ(stpuri);
289 fullpath=cats('_program=',treepath,"/&stpname");
290 putlog "NOTE: Stored Process Created!";
291 putlog "NOTE- "; putlog "NOTE-"; putlog "NOTE-" fullpath;
292 putlog "NOTE- "; putlog "NOTE-";
298 %else %if &stptype=2 %then %do;
300 %if %sysevalf(&sysver lt 9.3) %then %do;
301 %put WARNING: SAS version 9.3 or later required to create type2 STPs;
305 %mm_getservercontexts(outds=contexts)
306 %local serveruri; %let serveruri=NOTFOUND;
309 where upcase(servername)="%upcase(&server)";
310 call symputx('serveruri',serveruri);
312 %if &serveruri=NOTFOUND %then %do;
313 %put WARNING: ServerContext *&server* not found!;
320 filename &frefin temp;
323 treeuri=quote(symget('treeuri'));
324 serveruri=quote(symget('serveruri'));
325 stpdesc=quote(symget('stpdesc'));
326 stpname=quote(symget('stpname'));
328 put "<AddMetadata><Reposid>$METAREPOSITORY</Reposid><Metadata> "/
329 '<ClassifierMap UsageVersion="2000000" IsHidden="0" IsUserDefined="0" '/
330 ' IsActive="1" PublicType="StoredProcess" TransformRole="StoredProcess" '/
331 ' Name=' stpname ' Desc=' stpdesc '>'/
332 " <ComputeLocations>"/
333 " <ServerContext ObjRef=" serveruri "/>"/
334 " </ComputeLocations>"/
336 ' <TextStore IsHidden="0" Name="SourceCode" UsageVersion="0" '/
337 ' TextRole="StoredProcessSourceCode" StoredText="%put hello world!;" />'/
338 ' <TextStore IsHidden="0" Name="Stored Process" UsageVersion="0" '/
339 ' TextRole="StoredProcessConfiguration" TextType="XML" '/
340 ' StoredText="<?xml version="1.0" encoding="UTF-8&qu'@@
341 'ot;?><StoredProcess><ServerContext LogicalServerType="S'@@
342 'ps" OtherAllowed="false"/><ResultCapabilities Packa'@@
343 'ge="' @@ "&package" @@ '" Streaming="' @@ "&streaming" @@
344 '"/><OutputParameters/></StoredProcess>" />' /
347 ' <PromptGroup Name="Parameters" GroupType="2" IsHidden="0" '/
348 ' PublicType="Embedded:PromptGroup" UsageVersion="1000000" '/
349 ' GroupInfo="<PromptGroup promptId="PromptGroup_1502797359253'@@
350 '_802080" version="1.0"><Label><Text xml:lang='@@
351 '"en-US">Parameters</Text></Label></PromptGro'@@
354 "<Trees><Tree ObjRef=" treeuri "/></Trees>"/
355 "</ClassifierMap></Metadata><NS>SAS</NS>"/
356 "<Flags>268435456</Flags></AddMetadata>";
359 filename &frefout temp;
361 proc metadata in= &frefin out=&frefout ;
364 %if &mdebug=1 %then %do;
367 infile &frefout lrecl=1048576;
376 %mm_updatestpsourcecode(stp=&tree/&stpname
377 ,stpcode="&directory/&filename"
386 %put WARNING: STPTYPE=*&stptype* not recognised!;