80%macro mv_createfile(path=
84 ,contentdisp=attachment
86 ,access_token_var=ACCESS_TOKEN
87 ,grant_type=sas_services
94%
if &mdebug=1 %then %
do;
95 %put &sysmacroname entry vars:;
101 iftrue=(&syscc ne 0),
102 msg=Cannot enter &sysmacroname with syscc=&syscc
106%
if &grant_type=detect %then %
do;
107 %
if %symexist(&access_token_var) %then %let grant_type=authorization_code;
108 %
else %let grant_type=sas_services;
110%
if &grant_type=sas_services %then %
do;
111 %let oauth_bearer=oauth_bearer=sas_services;
112 %let &access_token_var=;
115%mp_abort(iftrue=(&grant_type ne authorization_code and &grant_type ne password
116 and &grant_type ne sas_services
119 ,msg=%str(Invalid value
for grant_type: &grant_type)
122%mp_abort(iftrue=(%mf_isblank(&path)=1 or %length(&path)=1)
124 ,msg=%str(path value must be provided)
126%mp_abort(iftrue=(%mf_isblank(&name)=1 or %length(&name)=1)
128 ,msg=%str(name value with length >1 must be provided)
133%let fref=%mf_getuniquefileref();
135%
if %upcase(&intype)=BINARY %then %let fref=&inref;
136%
else %
if %upcase(&intype)=BASE64 %then %
do;
137 %mp_base64copy(inref=&inref, outref=&fref, action=DECODE)
139%
else %put %str(ERR)OR: invalid value
for intype: &intype;
141%
if "&swap" ne
"0" %then %
do;
142 %mp_replace(
"%sysfunc(pathname(&fref))"
143 ,findvar=%scan(&swap,1,%str( ))
144 ,replacevar=%scan(&swap,2,%str( ))
148%
if &mdebug=1 %then %
do;
150 infile &fref lrecl=32767;
156options noquotelenmax;
158%let base_uri=%trim(%mf_getplatform(VIYARESTAPI));
161%local folderds self_uri;
162%let folderds=%mf_getuniquename(prefix=folderds);
163%mv_createfolder(path=&path
164 ,access_token_var=&access_token_var
165 ,grant_type=&grant_type
171 call symputx(
'self_uri',self_uri,
'l');
175%let force=%upcase(&force);
177%let fileuri=%trim(%mfv_getpathuri(&path/&name));
178%mp_abort(iftrue=(%mf_isblank(&fileuri)=0 and &force ne YES)
180 ,msg=%str(File &path/&name already exists and force=&force)
183 iftrue=(&syscc ne 0),
185 msg=syscc=&syscc after mfv_getpathuri
188%
if %mf_isblank(&fileuri)=0 and &force=YES %then %
do;
189 proc http method=
"DELETE" url=
"&base_uri&fileuri" &oauth_bearer;
191 %
if &grant_type=authorization_code %then %
do;
192 "Authorization"=
"Bearer &&&access_token_var"
196 %put &sysmacroname DELETE &base_uri&fileuri;
197 %
if &SYS_PROCHTTP_STATUS_CODE ne 204 %then %
do;
198 %put &=SYS_PROCHTTP_STATUS_CODE &=SYS_PROCHTTP_STATUS_PHRASE;
202%local url mimetype ext;
203%let url=&base_uri/files/files?parentFolderUri=&self_uri;
204%let ext=%upcase(%trim(%scan(&name,-1,.)));
207%mv_getViyaFileExtParms(&ext
208 ,propertiesVar=viyaProperties
209 ,typeDefNameVar=viyaTypeDefName
215%let fname1=%mf_getuniquefileref();
216proc http method=
'POST' out=&fname1 &oauth_bearer in=&fref
217 %
if "&ctype" =
"0" %then %
do;
218 %let mimetype=%mf_mimetype(&ext);
226 %
if not %mf_isBlank(&viyaTypeDefName) %then %
do;
227 url=
"&url%str(&)typeDefName=&viyaTypeDefName";
230 %
if "&ext"=
"HTM" or
"&ext"=
"HTML" or
"&ext"=
"XHTML" %then %
do;
231 url=
"&url%str(&)typeDefName=file_html";
234 %
if "&ext"=
"CSS" or
"&ext"=
"JS" or
"&ext"=
"PNG" or
"&ext"=
"SVG" %then %
do;
235 url=
"&url%str(&)typeDefName=file_%lowcase(&ext)";
243 headers
"Accept"=
"application/json"
244 %
if &grant_type=authorization_code %then %
do;
245 "Authorization"=
"Bearer &&&access_token_var"
247 "Content-Disposition"=
248 %
if "&ext"=
"SVG" or
"&ext"=
"HTML" %then %
do;
249 "filename=""&name"";"
252 "&contentdisp filename=""&name""; name=""&name"";"
256%
if &mdebug=1 %then %put &sysmacroname POST &=url
257 &=SYS_PROCHTTP_STATUS_CODE &=SYS_PROCHTTP_STATUS_PHRASE;
258%mp_abort(iftrue=(&SYS_PROCHTTP_STATUS_CODE ne 201)
260 ,msg=%str(&SYS_PROCHTTP_STATUS_CODE &SYS_PROCHTTP_STATUS_PHRASE)
264%let libref2=%mf_getuniquelibref();
265libname &libref2 JSON fileref=&fname1;
268 set &libref2..links end=last;
269 if rel=
'createChild' then
do;
275%let fileuri=%trim(%mfv_getpathuri(&path/&name));
278%
if not %mf_isBlank(%superq(viyaProperties)) %then %
do;
281 %let viyapatch=%sysfunc(pathname(work))/%mf_getuniquename(prefix=patch_json_);
284 file
"&viyapatch" lrecl=32767;
285 put
'{ "name": "' "&name" '",';
286 line = cat(
'"properties": ',symget(
"viyaProperties"));
292 %
if &mdebug=1 %then %
do;
294 if (_n_ eq 1) then put
'DEBUG: ** PATCH JSON **';
295 infile
"&viyapatch" end=last;
302 %let fref=%mf_getuniquefileref();
303 filename &fref
"&viyapatch";
304 %let url=&base_uri&fileuri;
306 proc http method=
'PATCH' oauth_bearer=sas_services in=&fref
308 headers
"Accept"=
"application/json"
309 "Content-Type"=
"application/json"
311 %
if &mdebug=1 %then %
do;
315 %
if &mdebug=1 %then %put &sysmacroname PATCH &=url
316 &=SYS_PROCHTTP_STATUS_CODE &=SYS_PROCHTTP_STATUS_PHRASE;
317 %mp_abort(iftrue=(&SYS_PROCHTTP_STATUS_CODE ne 200)
319 ,msg=%str(&SYS_PROCHTTP_STATUS_CODE &SYS_PROCHTTP_STATUS_PHRASE)
323%put &sysmacroname: &base_uri&fileuri;
324%put /SASJobExecution?_file=&path/&name;%put;
326%
if &mdebug=0 %then %
do;
328 filename &fname1 clear;
329 filename &fref clear;
330 libname &libref2 clear;
334 iftrue=(&syscc ne 0),
335 msg=Cannot leave &sysmacroname with syscc=&syscc