CORE
mm_createstp.sas
Go to the documentation of this file.
1 
62 %macro mm_CreateSTP(
63  stpname=Macro People STP
64  ,stpdesc=This stp was created automatically by the mm_createstp macro
65  ,filename=mm_createstp.sas
66  ,directory=SASEnvironment/SASCode
67  ,tree=/User Folders/sasdemo
68  ,package=false
69  ,streaming=true
70  ,outds=work.mm_createstp
71  ,mDebug=0
72  ,server=SASApp - Logical Stored Process Server
73  );
74 
75 %local mD;
76 %if &mDebug=1 %then %let mD=;
77 %else %let mD=%str(*);
78 %&mD.put Executing mm_CreateSTP.sas;
79 %&mD.put _local_;
80 
81 %mf_verifymacvars(stpname filename directory tree)
82 %mp_dropmembers(%scan(&outds,2,.))
83 
84 /* check uris */
85 data _null_;
86  length id $20 dirtype $256;
87  rc=metadata_resolve("&directory",dirtype,id);
88  call symputx('checkdirtype',dirtype,'l');
89 run;
90 
91 %if &checkdirtype ne Directory %then %do;
92  %mm_getDirectories(path=&directory,outds=&outds ,mDebug=&mDebug)
93  %if %mf_nobs(&outds)=0 or %sysfunc(exist(&outds))=0 %then %do;
94  %put WARNING: The directory object does not exist for &directory;
95  %return;
96  %end;
97 %end;
98 %else %do;
99  data &outds;
100  directoryuri="&directory";
101  run;
102 %end;
103 
104 /* get tree info */
105 %mm_getTree(tree=&tree, inds=&outds, outds=&outds, mDebug=&mDebug)
106 
107 /* check to be sure the STP does not already exist */
108 data &outds;
109  length id type loc $256;
110  call missing(id,type,loc);
111  drop id type rc loc;
112  set &outds;
113  loc=cats(treepath,"/&stpname");
114  rc=metadata_pathobj(' ',loc,'StoredProcess',type,id);
115  put (_all_)(=);
116  if rc>0 then do;
117  putlog "WARNING: An STP already exists at " treepath "/&stpname.";
118  putlog "WARNING- It will not be overwritten.";
119  stop;
120  end;
121  else output;
122 run;
123 %if %mf_nobs(&outds)=0 %then %return;
124 
125 data &outds (keep=stpuri prompturi fileuri texturi);
126  length stpuri prompturi fileuri texturi serveruri $256 ;
127  set &outds;
128 
129  /* final checks on uris */
130  length id $20 type $256;
131  __rc=metadata_resolve(treeuri,type,id);
132  if type ne 'Tree' then do;
133  putlog 'WARNING: Invalid tree URI: ' treeuri;
134  stopme=1;
135  end;
136  __rc=metadata_resolve(directoryuri,type,id);
137  if type ne 'Directory' then do;
138  putlog 'WARNING: Invalid directory URI: ' directoryuri;
139  stopme=1;
140  end;
141 
142 /* get server info */
143  __rc=metadata_resolve("&server",type,serveruri);
144  if type ne 'LogicalServer' then do;
145  __rc=metadata_getnobj("omsobj:LogicalServer?@Name='&server'",1,serveruri);
146  if serveruri='' then do;
147  putlog "WARNING: Invalid server: &server";
148  stopme=1;
149  end;
150  end;
151 
152  if stopme=1 then do;
153  putlog (_all_)(=);
154  stop;
155  end;
156 
157  /* create empty prompt */
158  rc1=METADATA_NEWOBJ('PromptGroup',prompturi,'Parameters');
159  rc2=METADATA_SETATTR(prompturi, 'UsageVersion', '1000000');
160  rc3=METADATA_SETATTR(prompturi, 'GroupType','2');
161  rc4=METADATA_SETATTR(prompturi, 'Name','Parameters');
162  rc5=METADATA_SETATTR(prompturi, 'PublicType','Embedded:PromptGroup');
163  GroupInfo="<PromptGroup promptId='PromptGroup_%sysfunc(datetime())_&sysprocessid'"
164  !!" version='1.0'><Label><Text xml:lang='en-GB'>Parameters</Text>"
165  !!"</Label></PromptGroup>";
166  rc6 = METADATA_SETATTR(prompturi, 'GroupInfo',groupinfo);
167 
168  if sum(of rc1-rc6) ne 0 then do;
169  putlog 'WARNING: Issue creating prompt.';
170  if prompturi ne . then do;
171  putlog ' Removing orphan: ' prompturi;
172  rc = METADATA_DELOBJ(prompturi);
173  put rc=;
174  end;
175  stop;
176  end;
177 
178  /* create a file uri */
179  rc7=METADATA_NEWOBJ('File',fileuri,'SP Source File');
180  rc8=METADATA_SETATTR(fileuri, 'FileName',"&filename");
181  rc9=METADATA_SETATTR(fileuri, 'IsARelativeName','1');
182  rc10=METADATA_SETASSN(fileuri, 'Directories','MODIFY',directoryuri);
183  if sum(of rc7-rc10) ne 0 then do;
184  putlog 'WARNING: Issue creating file.';
185  if fileuri ne . then do;
186  putlog ' Removing orphans:' prompturi fileuri;
187  rc = METADATA_DELOBJ(prompturi);
188  rc = METADATA_DELOBJ(fileuri);
189  put (_all_)(=);
190  end;
191  stop;
192  end;
193 
194  /* create a TextStore object */
195  rc11= METADATA_NEWOBJ('TextStore',texturi,'Stored Process');
196  rc12= METADATA_SETATTR(texturi, 'TextRole','StoredProcessConfiguration');
197  rc13= METADATA_SETATTR(texturi, 'TextType','XML');
198  storedtext='<?xml version="1.0" encoding="UTF-8"?><StoredProcess>'
199  !!"<ResultCapabilities Package='&package' Streaming='&streaming'/>"
200  !!"<OutputParameters/></StoredProcess>";
201  rc14= METADATA_SETATTR(texturi, 'StoredText',storedtext);
202  if sum(of rc11-rc14) ne 0 then do;
203  putlog 'WARNING: Issue creating TextStore.';
204  if texturi ne . then do;
205  putlog ' Removing orphans: ' prompturi fileuri texturi;
206  rc = METADATA_DELOBJ(prompturi);
207  rc = METADATA_DELOBJ(fileuri);
208  rc = METADATA_DELOBJ(texturi);
209  put (_all_)(=);
210  end;
211  stop;
212  end;
213 
214  /* create meta obj */
215  rc15= METADATA_NEWOBJ('ClassifierMap',stpuri,"&stpname");
216  rc16= METADATA_SETASSN(stpuri, 'Trees','MODIFY',treeuri);
217  rc17= METADATA_SETASSN(stpuri, 'ComputeLocations','MODIFY',serveruri);
218  rc18= METADATA_SETASSN(stpuri, 'SourceCode','MODIFY',fileuri);
219  rc19= METADATA_SETASSN(stpuri, 'Prompts','MODIFY',prompturi);
220  rc20= METADATA_SETASSN(stpuri, 'Notes','MODIFY',texturi);
221  rc21= METADATA_SETATTR(stpuri, 'PublicType', 'StoredProcess');
222  rc22= METADATA_SETATTR(stpuri, 'TransformRole', 'StoredProcess');
223  rc23= METADATA_SETATTR(stpuri, 'UsageVersion', '1000000');
224  rc24= METADATA_SETATTR(stpuri, 'Desc', "&stpdesc");
225 
226  /* tidy up if error */
227  if sum(of rc15-rc24) ne 0 then do;
228  putlog 'WARNING: Issue creating STP.';
229  if stpuri ne . then do;
230  putlog ' Removing orphans: ' prompturi fileuri texturi stpuri;
231  rc = METADATA_DELOBJ(prompturi);
232  rc = METADATA_DELOBJ(fileuri);
233  rc = METADATA_DELOBJ(texturi);
234  rc = METADATA_DELOBJ(stpuri);
235  put (_all_)(=);
236  end;
237  end;
238  else do;
239  fullpath=cats('_program=',treepath,"/&stpname");
240  putlog "NOTE: Stored Process Created!";
241  putlog "NOTE- "; putlog "NOTE-"; putlog "NOTE-" fullpath;
242  putlog "NOTE- "; putlog "NOTE-";
243  end;
244  output;
245  stop;
246 run;
247 %mend;