100 stpname=SASjs Default STP
101 ,stpdesc=This stp was created automatically by the mm_createstp macro
102 ,filename=mm_createstp.sas
103 ,directory=SASEnvironment/SASCode
104 ,tree=/User Folders/sasdemo
107 ,outds=work.mm_createstp
114 ,LogicalServerType=Sps
118%
if &mDebug=1 %then %let mD=;
119%
else %let mD=%str(*);
120%&mD.put Executing mm_CreateSTP.sas;
124 iftrue=(%mf_verifymacvars(stpname filename directory tree)=0)
126 ,msg=%str(Empty inputs: stpname filename directory tree)
129%mp_dropmembers(%scan(&outds,2,.))
134 &LogicalServerType ne Sps
135 and &LogicalServerType ne Wks
136 and &LogicalServerType ne Any
139 ,msg=%str(Invalid value for LogicalServerType (&LogicalServerType))
146 length type uri $256;
147 rc=metadata_pathobj(
"",
"&tree",
"Folder",type,uri);
148 call symputx(
'foldertype',type,
'l');
149 call symputx(
'treeuri',uri,
'l');
151%
if &foldertype ne Tree %then %
do;
152 %put %str(WARN)ING: Tree &tree does not exist!;
161 length type uri $256;
162 rc=metadata_pathobj(
"",
"&tree/&stpname",
'StoredProcess',type,uri);
163 call symputx(
'cmtype',type,
'l');
164 call symputx(
'stpuri',uri,
'l');
166%
if &cmtype = ClassifierMap %then %
do;
167 %put %str(WARN)ING: Stored Process &stpname already exists in &tree!;
174%
if %sysfunc(fileexist(&directory/&filename)) ne 1 %then %
do;
175 %put %str(WARN)ING: FILE *&directory/&filename* NOT FOUND!;
179%
if &stptype=1 %then %
do;
181 %
if %sysevalf(&sysver lt 9.2) %then %
do;
182 %put %str(WARN)ING: Version 9.2 or later required;
188 length
id $20 dirtype $256;
189 rc=metadata_resolve(
"&directory",dirtype,
id);
190 call symputx(
'checkdirtype',dirtype,
'l');
193 %
if &checkdirtype ne Directory %then %
do;
194 %mm_getdirectories(path=&directory,outds=&outds ,mDebug=&mDebug)
195 %
if %mf_nobs(&outds)=0 or %sysfunc(exist(&outds))=0 %then %
do;
196 %put %str(WARN)ING: The directory
object does not exist
for &directory;
202 directoryuri=
"&directory";
206 data &outds (keep=stpuri prompturi fileuri texturi);
207 length stpuri prompturi fileuri texturi serveruri $256 ;
208 if _n_=1 then call missing (of _all_);
212 length
id $20 type $256;
213 __rc=metadata_resolve(
"&treeuri",type,
id);
214 if type ne
'Tree' then
do;
215 putlog
"%str(WARN)ING: Invalid tree URI: &treeuri";
218 __rc=metadata_resolve(directoryuri,type,
id);
219 if type ne
'Directory' then
do;
220 putlog
"%str(WARN)ING: Invalid directory URI: " directoryuri;
225 __rc=metadata_resolve(
"&server",type,serveruri);
226 if type ne
'LogicalServer' then
do;
227 __rc=metadata_getnobj(
"omsobj:LogicalServer?@Name='&server'",1,serveruri);
228 if serveruri=
'' then
do;
229 putlog
"%str(WARN)ING: Invalid server: &server";
240 rc1=METADATA_NEWOBJ(
'PromptGroup',prompturi,
'Parameters');
241 rc2=METADATA_SETATTR(prompturi,
'UsageVersion',
'1000000');
242 rc3=METADATA_SETATTR(prompturi,
'GroupType',
'2');
243 rc4=METADATA_SETATTR(prompturi,
'Name',
'Parameters');
244 rc5=METADATA_SETATTR(prompturi,
'PublicType',
'Embedded:PromptGroup');
246 "<PromptGroup promptId='PromptGroup_%sysfunc(datetime())_&sysprocessid'"
247 !!
" version='1.0'><Label><Text xml:lang='en-GB'>Parameters</Text>"
248 !!
"</Label></PromptGroup>";
249 rc6 = METADATA_SETATTR(prompturi,
'GroupInfo',groupinfo);
251 if sum(of rc1-rc6) ne 0 then
do;
252 putlog
"%str(WARN)ING: Issue creating prompt.";
253 if prompturi ne . then
do;
254 putlog
' Removing orphan: ' prompturi;
255 rc = METADATA_DELOBJ(prompturi);
262 rc7=METADATA_NEWOBJ(
'File',fileuri,
'SP Source File');
263 rc8=METADATA_SETATTR(fileuri,
'FileName',
"&filename");
264 rc9=METADATA_SETATTR(fileuri,
'IsARelativeName',
'1');
265 rc10=METADATA_SETASSN(fileuri,
'Directories',
'MODIFY',directoryuri);
266 if sum(of rc7-rc10) ne 0 then
do;
267 putlog
"%str(WARN)ING: Issue creating file.";
268 if fileuri ne . then
do;
269 putlog
' Removing orphans:' prompturi fileuri;
270 rc = METADATA_DELOBJ(prompturi);
271 rc = METADATA_DELOBJ(fileuri);
278 rc11= METADATA_NEWOBJ(
'TextStore',texturi,
'Stored Process');
279 rc12= METADATA_SETATTR(texturi,
'TextRole',
'StoredProcessConfiguration');
280 rc13= METADATA_SETATTR(texturi,
'TextType',
'XML');
281 storedtext=
'<?xml version="1.0" encoding="UTF-8"?><StoredProcess>'
282 !!
"<ResultCapabilities Package='&package' Streaming='&streaming'/>"
283 !!
"<OutputParameters/></StoredProcess>";
284 rc14= METADATA_SETATTR(texturi,
'StoredText',storedtext);
285 if sum(of rc11-rc14) ne 0 then
do;
286 putlog
"%str(WARN)ING: Issue creating TextStore.";
287 if texturi ne . then
do;
288 putlog
' Removing orphans: ' prompturi fileuri texturi;
289 rc = METADATA_DELOBJ(prompturi);
290 rc = METADATA_DELOBJ(fileuri);
291 rc = METADATA_DELOBJ(texturi);
298 rc15= METADATA_NEWOBJ(
'ClassifierMap',stpuri,
"&stpname");
299 rc16= METADATA_SETASSN(stpuri,
'Trees',
'MODIFY',treeuri);
300 rc17= METADATA_SETASSN(stpuri,
'ComputeLocations',
'MODIFY',serveruri);
301 rc18= METADATA_SETASSN(stpuri,
'SourceCode',
'MODIFY',fileuri);
302 rc19= METADATA_SETASSN(stpuri,
'Prompts',
'MODIFY',prompturi);
303 rc20= METADATA_SETASSN(stpuri,
'Notes',
'MODIFY',texturi);
304 rc21= METADATA_SETATTR(stpuri,
'PublicType',
'StoredProcess');
305 rc22= METADATA_SETATTR(stpuri,
'TransformRole',
'StoredProcess');
306 rc23= METADATA_SETATTR(stpuri,
'UsageVersion',
'1000000');
307 rc24= METADATA_SETATTR(stpuri,
'Desc',
"&stpdesc");
310 if sum(of rc15-rc24) ne 0 then
do;
311 putlog
"%str(WARN)ING: Issue creating STP.";
312 if stpuri ne . then
do;
313 putlog
' Removing orphans: ' prompturi fileuri texturi stpuri;
314 rc = METADATA_DELOBJ(prompturi);
315 rc = METADATA_DELOBJ(fileuri);
316 rc = METADATA_DELOBJ(texturi);
317 rc = METADATA_DELOBJ(stpuri);
322 fullpath=cats(
'_program=',treepath,
"/&stpname");
323 putlog
"NOTE: Stored Process Created!";
324 putlog
"NOTE- "; putlog
"NOTE-"; putlog
"NOTE-" fullpath;
325 putlog
"NOTE- "; putlog
"NOTE-";
331%
else %
if &stptype=2 %then %
do;
333 %
if %sysevalf(&sysver lt 9.3) %then %
do;
334 %put %str(WARN)ING: SAS version 9.3 or later required to create type2 STPs;
338 %mm_getservercontexts(outds=contexts)
339 %local serveruri; %let serveruri=NOTFOUND;
342 where upcase(servername)=
"%upcase(&server)";
343 call symputx(
'serveruri',serveruri);
345 %
if &serveruri=NOTFOUND %then %
do;
346 %put %str(WARN)ING: ServerContext *&server* not found!;
353 filename &frefin temp;
356 treeuri=quote(symget(
'treeuri'));
357 serveruri=quote(symget(
'serveruri'));
358 stpdesc=quote(symget(
'stpdesc'));
359 stpname=quote(symget(
'stpname'));
361 put
"<AddMetadata><Reposid>$METAREPOSITORY</Reposid><Metadata> "/
362 '<ClassifierMap UsageVersion="2000000" IsHidden="0" IsUserDefined="0" '/
363 ' IsActive="1" PublicType="StoredProcess" TransformRole="StoredProcess" '/
364 ' Name=' stpname
' Desc=' stpdesc
'>'/
365 " <ComputeLocations>"/
366 " <ServerContext ObjRef=" serveruri
"/>"/
367 " </ComputeLocations>"/
369 ' <TextStore IsHidden="0" Name="SourceCode" UsageVersion="0" '/
370 ' TextRole="StoredProcessSourceCode" StoredText="%put hello world!;" />'/
371 ' <TextStore IsHidden="0" Name="Stored Process" UsageVersion="0" '/
372 ' TextRole="StoredProcessConfiguration" TextType="XML" '/
373 ' StoredText="<?xml version="1.0" encoding="UTF-8&qu'@@
374 'ot;?><StoredProcess><ServerContext LogicalServerType="'@@
375 "&LogicalServerType"@@
376 '" OtherAllowed="false"/><ResultCapabilities Packa'@@
377 'ge="' @@
"&package" @@
'" Streaming="' @@
"&streaming" @@
378 '"/><OutputParameters/></StoredProcess>" />' /
381 ' <PromptGroup Name="Parameters" GroupType="2" IsHidden="0" '/
382 ' PublicType="Embedded:PromptGroup" UsageVersion="1000000" '/
383 ' GroupInfo="<PromptGroup promptId="PromptGroup_1502797359253'@@
384 '_802080" version="1.0"><Label><Text xml:lang='@@
385 '"en-US">Parameters</Text></Label></PromptGro'@@
388 "<Trees><Tree ObjRef=" treeuri
"/></Trees>"/
389 "</ClassifierMap></Metadata><NS>SAS</NS>"/
390 "<Flags>268435456</Flags></AddMetadata>";
393 filename &frefout temp;
395 proc metadata in= &frefin out=&frefout ;
398 %
if &mdebug=1 %then %
do;
401 infile &frefout lrecl=1048576;
410 %mm_updatestpsourcecode(stp=&tree/&stpname
411 ,stpcode=
"&directory/&filename"
418 %put %str(WARN)ING: STPTYPE=*&stptype* not recognised!;