mirror of
https://github.com/sasjs/core.git
synced 2026-01-11 11:00:04 +00:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0b555bb31c | ||
|
|
40b513a9e3 | ||
|
|
4eacf4deae | ||
|
|
5824423c13 | ||
|
|
ce5bfd41dc |
30
all.sas
30
all.sas
@@ -133,7 +133,13 @@ options noquotelenmax;
|
|||||||
%macro mf_existfileref(fref
|
%macro mf_existfileref(fref
|
||||||
)/*/STORE SOURCE*/;
|
)/*/STORE SOURCE*/;
|
||||||
|
|
||||||
%if %sysfunc(fileref(&fref))=0 %then %do;
|
%local rc;
|
||||||
|
%let rc=%sysfunc(fileref(&fref));
|
||||||
|
%if &rc=0 %then %do;
|
||||||
|
1
|
||||||
|
%end;
|
||||||
|
%else %if &rc<0 %then %do;
|
||||||
|
%put &sysmacroname: Fileref &fref exists but the underlying file does not;
|
||||||
1
|
1
|
||||||
%end;
|
%end;
|
||||||
%else %do;
|
%else %do;
|
||||||
@@ -11665,18 +11671,20 @@ run;
|
|||||||
%mend mm_gettableid;/**
|
%mend mm_gettableid;/**
|
||||||
@file
|
@file
|
||||||
@brief Creates a dataset with all metadata tables for a particular library
|
@brief Creates a dataset with all metadata tables for a particular library
|
||||||
@details Will only show the tables to which a user has the requisite
|
@details Will only show the tables for which the executing user has the
|
||||||
metadata access.
|
requisite metadata access.
|
||||||
|
|
||||||
usage:
|
usage:
|
||||||
|
|
||||||
%mm_gettables(uri=A5X8AHW1.B40001S5)
|
%mm_gettables(uri=A5X8AHW1.B40001S5)
|
||||||
|
|
||||||
@param outds the dataset to create that contains the list of tables
|
@param [in] uri= the uri of the library for which to return tables
|
||||||
@param uri the uri of the library for which to return tables
|
@param [out] outds= (work.mm_gettables) the dataset to contain the list of
|
||||||
@param getauth= YES|NO - fetch the authdomain used in database connections.
|
tables
|
||||||
Set to NO to improve runtimes in larger environments, as there can be a
|
@param [in] getauth= (YES) Fetch the authdomain used in database connections.
|
||||||
performance hit on the `metadata_getattr(domainuri, "Name", AuthDomain)` call.
|
Set to NO to improve runtimes in larger environments, as there can be a
|
||||||
|
performance hit on the `metadata_getattr(domainuri, "Name", AuthDomain)`
|
||||||
|
call.
|
||||||
|
|
||||||
@returns outds dataset containing all groups in a column named "metagroup"
|
@returns outds dataset containing all groups in a column named "metagroup"
|
||||||
(defaults to work.mm_getlibs). The following columns are provided:
|
(defaults to work.mm_getlibs). The following columns are provided:
|
||||||
@@ -11704,8 +11712,8 @@ data &outds;
|
|||||||
libdesc $200 libref engine $8 IsDBMSLibname $1
|
libdesc $200 libref engine $8 IsDBMSLibname $1
|
||||||
tablename $50 /* metadata table names can be longer than $32 */
|
tablename $50 /* metadata table names can be longer than $32 */
|
||||||
;
|
;
|
||||||
keep libname libdesc libref engine ServerContext path_schema AuthDomain tableuri
|
keep libname libdesc libref engine ServerContext path_schema AuthDomain
|
||||||
tablename IsPreassigned IsDBMSLibname id;
|
tableuri tablename IsPreassigned IsDBMSLibname id;
|
||||||
call missing (of _all_);
|
call missing (of _all_);
|
||||||
|
|
||||||
uri=symget('uri');
|
uri=symget('uri');
|
||||||
|
|||||||
@@ -17,7 +17,13 @@
|
|||||||
%macro mf_existfileref(fref
|
%macro mf_existfileref(fref
|
||||||
)/*/STORE SOURCE*/;
|
)/*/STORE SOURCE*/;
|
||||||
|
|
||||||
%if %sysfunc(fileref(&fref))=0 %then %do;
|
%local rc;
|
||||||
|
%let rc=%sysfunc(fileref(&fref));
|
||||||
|
%if &rc=0 %then %do;
|
||||||
|
1
|
||||||
|
%end;
|
||||||
|
%else %if &rc<0 %then %do;
|
||||||
|
%put &sysmacroname: Fileref &fref exists but the underlying file does not;
|
||||||
1
|
1
|
||||||
%end;
|
%end;
|
||||||
%else %do;
|
%else %do;
|
||||||
|
|||||||
61
base/mf_getapploc.sas
Normal file
61
base/mf_getapploc.sas
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
/**
|
||||||
|
@file
|
||||||
|
@brief Returns the appLoc from the _program variable
|
||||||
|
@details When working with SASjs apps, web services / tests / jobs are always
|
||||||
|
deployed to a root (app) location in the SAS logical folder tree.
|
||||||
|
|
||||||
|
When building apps for use in other environments, you do not necessarily know
|
||||||
|
where the backend services will be deployed. Therefore a function like this
|
||||||
|
is handy in order to dynamically figure out the appLoc, and enable other
|
||||||
|
services to be connected by a relative reference.
|
||||||
|
|
||||||
|
SASjs apps always have the same immediate substructure (one or more of the
|
||||||
|
following):
|
||||||
|
|
||||||
|
@li /data
|
||||||
|
@li /jobs
|
||||||
|
@li /services
|
||||||
|
@li /tests/jobs
|
||||||
|
@li /tests/services
|
||||||
|
@li /tests/macros
|
||||||
|
|
||||||
|
This function works by testing for the existence of any of the above in the
|
||||||
|
automatic _program variable, and returning the part to the left of it.
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
|
||||||
|
%put %mf_getapploc(&_program)
|
||||||
|
|
||||||
|
%put %mf_getapploc(/some/location/services/admin/myservice);
|
||||||
|
%put %mf_getapploc(/some/location/jobs/extract/somejob/);
|
||||||
|
%put %mf_getapploc(/some/location/tests/jobs/somejob/);
|
||||||
|
|
||||||
|
|
||||||
|
@author Allan Bowe
|
||||||
|
**/
|
||||||
|
|
||||||
|
%macro mf_getapploc(pgm);
|
||||||
|
%if "&pgm"="" %then %do;
|
||||||
|
%put &sysmacroname: No value provided;
|
||||||
|
%return;
|
||||||
|
%end;
|
||||||
|
%local root;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* move up two levels to avoid matches on subfolder or service name
|
||||||
|
*/
|
||||||
|
%let root=%substr(&pgm,1,%length(&pgm)-%length(%scan(&pgm,-1,/))-1);
|
||||||
|
%let root=%substr(&root,1,%length(&root)-%length(%scan(&root,-1,/))-1);
|
||||||
|
|
||||||
|
%if %index(&root,/tests/) %then %do;
|
||||||
|
%let root=%substr(&root,1,%index(&root,/tests/)-1);
|
||||||
|
%end;
|
||||||
|
%else %if %index(&root,/services) %then %do;
|
||||||
|
%let root=%substr(&root,1,%index(&root,/services)-1);
|
||||||
|
%end;
|
||||||
|
%else %if %index(&root,/jobs) %then %do;
|
||||||
|
%let root=%substr(&root,1,%index(&root,/jobs)-1);
|
||||||
|
%end;
|
||||||
|
%else %put &sysmacroname: Could not find an app location from &pgm;
|
||||||
|
&root
|
||||||
|
%mend mf_getapploc ;
|
||||||
@@ -1,18 +1,20 @@
|
|||||||
/**
|
/**
|
||||||
@file
|
@file
|
||||||
@brief Creates a dataset with all metadata tables for a particular library
|
@brief Creates a dataset with all metadata tables for a particular library
|
||||||
@details Will only show the tables to which a user has the requisite
|
@details Will only show the tables for which the executing user has the
|
||||||
metadata access.
|
requisite metadata access.
|
||||||
|
|
||||||
usage:
|
usage:
|
||||||
|
|
||||||
%mm_gettables(uri=A5X8AHW1.B40001S5)
|
%mm_gettables(uri=A5X8AHW1.B40001S5)
|
||||||
|
|
||||||
@param outds the dataset to create that contains the list of tables
|
@param [in] uri= the uri of the library for which to return tables
|
||||||
@param uri the uri of the library for which to return tables
|
@param [out] outds= (work.mm_gettables) the dataset to contain the list of
|
||||||
@param getauth= YES|NO - fetch the authdomain used in database connections.
|
tables
|
||||||
Set to NO to improve runtimes in larger environments, as there can be a
|
@param [in] getauth= (YES) Fetch the authdomain used in database connections.
|
||||||
performance hit on the `metadata_getattr(domainuri, "Name", AuthDomain)` call.
|
Set to NO to improve runtimes in larger environments, as there can be a
|
||||||
|
performance hit on the `metadata_getattr(domainuri, "Name", AuthDomain)`
|
||||||
|
call.
|
||||||
|
|
||||||
@returns outds dataset containing all groups in a column named "metagroup"
|
@returns outds dataset containing all groups in a column named "metagroup"
|
||||||
(defaults to work.mm_getlibs). The following columns are provided:
|
(defaults to work.mm_getlibs). The following columns are provided:
|
||||||
@@ -40,8 +42,8 @@ data &outds;
|
|||||||
libdesc $200 libref engine $8 IsDBMSLibname $1
|
libdesc $200 libref engine $8 IsDBMSLibname $1
|
||||||
tablename $50 /* metadata table names can be longer than $32 */
|
tablename $50 /* metadata table names can be longer than $32 */
|
||||||
;
|
;
|
||||||
keep libname libdesc libref engine ServerContext path_schema AuthDomain tableuri
|
keep libname libdesc libref engine ServerContext path_schema AuthDomain
|
||||||
tablename IsPreassigned IsDBMSLibname id;
|
tableuri tablename IsPreassigned IsDBMSLibname id;
|
||||||
call missing (of _all_);
|
call missing (of _all_);
|
||||||
|
|
||||||
uri=symget('uri');
|
uri=symget('uri');
|
||||||
|
|||||||
35
tests/base/mf_existfileref.test.sas
Normal file
35
tests/base/mf_existfileref.test.sas
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
/**
|
||||||
|
@file
|
||||||
|
@brief Testing mf_existfileref macro
|
||||||
|
|
||||||
|
<h4> SAS Macros </h4>
|
||||||
|
@li mf_existfileref.sas
|
||||||
|
@li mp_assert.sas
|
||||||
|
|
||||||
|
**/
|
||||||
|
|
||||||
|
filename ref1 temp;
|
||||||
|
filename ref2 temp;
|
||||||
|
|
||||||
|
data _null_;
|
||||||
|
file ref1;
|
||||||
|
put 'exists';
|
||||||
|
run;
|
||||||
|
|
||||||
|
%mp_assert(
|
||||||
|
iftrue=(%mf_existfileref(ref1)=1),
|
||||||
|
desc=Checking fileref WITH target file exists,
|
||||||
|
outds=work.test_results
|
||||||
|
)
|
||||||
|
|
||||||
|
%mp_assert(
|
||||||
|
iftrue=(%mf_existfileref(ref2)=1),
|
||||||
|
desc=Checking fileref WITHOUT target file exists,
|
||||||
|
outds=work.test_results
|
||||||
|
)
|
||||||
|
|
||||||
|
%mp_assert(
|
||||||
|
iftrue=(%mf_existfileref(ref3)=0),
|
||||||
|
desc=Checking non-existant fref does not exist,
|
||||||
|
outds=work.test_results
|
||||||
|
)
|
||||||
41
tests/base/mf_getapploc.test.sas
Normal file
41
tests/base/mf_getapploc.test.sas
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
/**
|
||||||
|
@file
|
||||||
|
@brief Testing mf_getapploc macro
|
||||||
|
|
||||||
|
<h4> SAS Macros </h4>
|
||||||
|
@li mf_getapploc.sas
|
||||||
|
@li mp_assert.sas
|
||||||
|
|
||||||
|
**/
|
||||||
|
|
||||||
|
%mp_assert(
|
||||||
|
iftrue=(
|
||||||
|
"%mf_getapploc(/some/loc/tests/services/x/service)"="/some/loc"
|
||||||
|
),
|
||||||
|
desc=Checking test appLoc matches,
|
||||||
|
outds=work.test_results
|
||||||
|
)
|
||||||
|
|
||||||
|
%mp_assert(
|
||||||
|
iftrue=(
|
||||||
|
"%mf_getapploc(/some/loc/tests/services/tests/service)"="/some/loc"
|
||||||
|
),
|
||||||
|
desc=Checking nested services appLoc matches,
|
||||||
|
outds=work.test_results
|
||||||
|
)
|
||||||
|
|
||||||
|
%mp_assert(
|
||||||
|
iftrue=(
|
||||||
|
"%mf_getapploc(/some/area/services/admin/service)"="/some/area"
|
||||||
|
),
|
||||||
|
desc=Checking services appLoc matches,
|
||||||
|
outds=work.test_results
|
||||||
|
)
|
||||||
|
|
||||||
|
%mp_assert(
|
||||||
|
iftrue=(
|
||||||
|
"%mf_getapploc(/some/area/jobs/jobs/job)"="/some/area"
|
||||||
|
),
|
||||||
|
desc=Checking jobs appLoc matches,
|
||||||
|
outds=work.test_results
|
||||||
|
)
|
||||||
Reference in New Issue
Block a user