79%macro mv_createfile(path=
83 ,contentdisp=attachment
85 ,access_token_var=ACCESS_TOKEN
86 ,grant_type=sas_services
93%
if &mdebug=1 %then %
do;
94 %put &sysmacroname entry vars:;
100 iftrue=(&syscc ne 0),
101 msg=Cannot enter &sysmacroname with syscc=&syscc
105%
if &grant_type=detect %then %
do;
106 %
if %symexist(&access_token_var) %then %let grant_type=authorization_code;
107 %
else %let grant_type=sas_services;
109%
if &grant_type=sas_services %then %
do;
110 %let oauth_bearer=oauth_bearer=sas_services;
111 %let &access_token_var=;
114%mp_abort(iftrue=(&grant_type ne authorization_code and &grant_type ne password
115 and &grant_type ne sas_services
118 ,msg=%str(Invalid value
for grant_type: &grant_type)
121%mp_abort(iftrue=(%mf_isblank(&path)=1 or %length(&path)=1)
123 ,msg=%str(path value must be provided)
125%mp_abort(iftrue=(%mf_isblank(&name)=1 or %length(&name)=1)
127 ,msg=%str(name value with length >1 must be provided)
132%let fref=%mf_getuniquefileref();
134%
if %upcase(&intype)=BINARY %then %let fref=&inref;
135%
else %
if %upcase(&intype)=BASE64 %then %
do;
136 %mp_base64copy(inref=&inref, outref=&fref, action=DECODE)
138%
else %put %str(ERR)OR: invalid value
for intype: &intype;
140%
if "&swap" ne
"0" %then %
do;
141 %mp_replace(
"%sysfunc(pathname(&fref))"
142 ,findvar=%scan(&swap,1,%str( ))
143 ,replacevar=%scan(&swap,2,%str( ))
147%
if &mdebug=1 %then %
do;
149 infile &fref lrecl=32767;
155options noquotelenmax;
157%let base_uri=%trim(%mf_getplatform(VIYARESTAPI));
160%local folderds self_uri;
161%let folderds=%mf_getuniquename(prefix=folderds);
162%mv_createfolder(path=&path
163 ,access_token_var=&access_token_var
164 ,grant_type=&grant_type
170 call symputx(
'self_uri',self_uri,
'l');
174%let force=%upcase(&force);
176%let fileuri=%trim(%mfv_getpathuri(&path/&name));
177%mp_abort(iftrue=(%mf_isblank(&fileuri)=0 and &force ne YES)
179 ,msg=%str(File &path/&name already exists and force=&force)
182 iftrue=(&syscc ne 0),
184 msg=syscc=&syscc after mfv_getpathuri
187%
if %mf_isblank(&fileuri)=0 and &force=YES %then %
do;
188 proc http method=
"DELETE" url=
"&base_uri&fileuri" &oauth_bearer;
190 %
if &grant_type=authorization_code %then %
do;
191 "Authorization"=
"Bearer &&&access_token_var"
195 %put &sysmacroname DELETE &base_uri&fileuri;
196 %
if &SYS_PROCHTTP_STATUS_CODE ne 204 %then %
do;
197 %put &=SYS_PROCHTTP_STATUS_CODE &=SYS_PROCHTTP_STATUS_PHRASE;
201%local url mimetype ext;
202%let url=&base_uri/files/files?parentFolderUri=&self_uri;
203%let ext=%upcase(%trim(%scan(&name,-1,.)));
206%mv_getViyaFileExtParms(&ext
207 ,propertiesVar=viyaProperties
208 ,typeDefNameVar=viyaTypeDefName
214%let fname1=%mf_getuniquefileref();
215proc http method=
'POST' out=&fname1 &oauth_bearer in=&fref
216 %
if "&ctype" =
"0" %then %
do;
217 %let mimetype=%mf_mimetype(&ext);
225 %
if not %mf_isBlank(&viyaTypeDefName) %then %
do;
226 url=
"&url%str(&)typeDefName=&viyaTypeDefName";
229 %
if "&ext"=
"HTM" or
"&ext"=
"HTML" or
"&ext"=
"XHTML" %then %
do;
230 url=
"&url%str(&)typeDefName=file_html";
233 %
if "&ext"=
"CSS" or
"&ext"=
"JS" or
"&ext"=
"PNG" or
"&ext"=
"SVG" %then %
do;
234 url=
"&url%str(&)typeDefName=file_%lowcase(&ext)";
242 headers
"Accept"=
"application/json"
243 %
if &grant_type=authorization_code %then %
do;
244 "Authorization"=
"Bearer &&&access_token_var"
246 "Content-Disposition"=
247 %
if "&ext"=
"SVG" or
"&ext"=
"HTML" %then %
do;
248 "filename=""&name"";"
251 "&contentdisp filename=""&name""; name=""&name"";"
255%
if &mdebug=1 %then %put &sysmacroname POST &=url
256 &=SYS_PROCHTTP_STATUS_CODE &=SYS_PROCHTTP_STATUS_PHRASE;
257%mp_abort(iftrue=(&SYS_PROCHTTP_STATUS_CODE ne 201)
259 ,msg=%str(&SYS_PROCHTTP_STATUS_CODE &SYS_PROCHTTP_STATUS_PHRASE)
263%let libref2=%mf_getuniquelibref();
264libname &libref2 JSON fileref=&fname1;
267 set &libref2..links end=last;
268 if rel=
'createChild' then
do;
274%let fileuri=%trim(%mfv_getpathuri(&path/&name));
277%
if not %mf_isBlank(%superq(viyaProperties)) %then %
do;
280 %let viyapatch=%sysfunc(pathname(work))/%mf_getuniquename(prefix=patch_json_);
283 file
"&viyapatch" lrecl=32767;
284 put
'{ "name": "' "&name" '",';
285 line = cat(
'"properties": ',symget(
"viyaProperties"));
291 %
if &mdebug=1 %then %
do;
293 if (_n_ eq 1) then put
'DEBUG: ** PATCH JSON **';
294 infile
"&viyapatch" end=last;
301 %let fref=%mf_getuniquefileref();
302 filename &fref
"&viyapatch";
303 %let url=&base_uri&fileuri;
305 proc http method=
'PATCH' oauth_bearer=sas_services in=&fref
307 headers
"Accept"=
"application/json"
308 "Content-Type"=
"application/json"
310 %
if &mdebug=1 %then %
do;
314 %
if &mdebug=1 %then %put &sysmacroname PATCH &=url
315 &=SYS_PROCHTTP_STATUS_CODE &=SYS_PROCHTTP_STATUS_PHRASE;
316 %mp_abort(iftrue=(&SYS_PROCHTTP_STATUS_CODE ne 200)
318 ,msg=%str(&SYS_PROCHTTP_STATUS_CODE &SYS_PROCHTTP_STATUS_PHRASE)
322%put &sysmacroname: &base_uri&fileuri;
323%put /SASJobExecution?_file=&path/&name;%put;
325%
if &mdebug=0 %then %
do;
327 filename &fname1 clear;
328 filename &fref clear;
329 libname &libref2 clear;
333 iftrue=(&syscc ne 0),
334 msg=Cannot leave &sysmacroname with syscc=&syscc