As of December 1, 2020, Focal Point is retired and repurposed as a reference repository. We value the wealth of knowledge that's been shared here over the years. You'll continue to have access to this treasure trove of knowledge, for search purposes only.
Join the TIBCO Community TIBCO Community is a collaborative space for users to share knowledge and support one another in making the best use of TIBCO products and services. There are several TIBCO WebFOCUS resources in the community.
From the Home page, select Predict: WebFOCUS to view articles, questions, and trending articles.
Select Products from the top navigation bar, scroll, and then select the TIBCO WebFOCUS product page to view product overview, articles, and discussions.
Request access to the private WebFOCUS User Group (login required) to network with fellow members.
Former myibi community members should have received an email on 8/3/22 to activate their user accounts to join the community. Check your Spam folder for the email. Please get in touch with us at community@tibco.com for further assistance. Reference the community FAQ to learn more about the community.
So I ran into an issue where we audit reports and what users are doing in the reports, which is a bit more complex than what you get out of the WF box. Each audit is created by Day, so our logs don't get too big. While doing that, we find our self with many files in our audit folder sitting on the app server. This code below will allow user interaction, but also can be used within an automated tool as well.
[UPDATE]: Added the ability to View and download the files as well. This required the ability to create a master file on the fly. [UPDATE2]: Added, when day picker changes, change the date under it to reflect what will be deleted without refreshing the page.
Hope you all can get something useful out of it. It is notable that we have Restful services as part of our WF purchase, so if you don't you can use the full URL instead, the same way.
SET ASNAME=MIXED
-*Set Defaults, accepting params
-DEFAULTH &KEEPDAYS = 5;
-DEFAULTH &DEL = 'N';
-DEFAULTH &DL = 'N';
-DEFAULTH &FILEN = _FOC_NULL;
STATE foccache/tmpfile.mas
-RUN
-SET &FILEEXISTS = IF &RETCODE EQ 0 THEN 'Y' ELSE 'N';
-*If return code is zero, then try to delete file, else check to see if source file exists.
-IF &FILEEXISTS EQ 'N' THEN GOTO SKIPDEL;
APP DELETEF 'foccache' 'tmpfile' 'mas'
-SKIPDEL
-TYPE FILEN = &FILEN;
-IF &FILEN EQ _FOC_NULL THEN GOTO SKIPREAD;
-SET &CSVFILE = 'audit_logger/&FILEN.EVAL';
-TYPE CSVFILE = &CSVFILE;
FILEDEF MASTERFILE DISK foccache/tmpfile.mas
-RUN
-WRITE MASTERFILE FILENAME=tmpfile, SUFFIX=TAB , DATASET=&CSVFILE, $
-WRITE MASTERFILE SEGMENT=SEG1, SEGTYPE=S0, $
-WRITE MASTERFILE FIELDNAME=ROWDATE, ALIAS=Date, USAGE=A10, ACTUAL=A10, $
-WRITE MASTERFILE FIELDNAME=ROWTIME, ALIAS=Time, USAGE=A12, ACTUAL=A12, $
-WRITE MASTERFILE FIELDNAME=ROWUSER, ALIAS=User, USAGE=A25, ACTUAL=A25, $
-WRITE MASTERFILE FIELDNAME=ROWIPADDR, ALIAS=IPAddr, USAGE=A20, ACTUAL=A20, $
-WRITE MASTERFILE FIELDNAME=ROWPAGE, ALIAS=Page, USAGE=A255, ACTUAL=A255, $
-WRITE MASTERFILE FIELDNAME=ROWINFORMATION, ALIAS=Information, USAGE=A1000, ACTUAL=A1000, $
-RUN
-SKIPREAD
-IF &DL = 'Y' AND &FILEN.LENGTH GT 1 THEN GOTO DOWNLOADFILE;
-*Set fixed vars
-SET &BASEURL = '/ibi_apps/rs/ibfs/WFC/Repository/Validation/ViewLogs.fex?IBIRS_action=run';
-SET &FileNM = _FOC_NULL;
-SET &APPNAME = _FOC_NULL;
-*Get the New
-SET &THENDTTM = (DATECVT((DATEADD((DATECVT(&YYMD,'I8YYMD','YYMD')),D,-&KEEPDAYS)),'YYMD','I8YYMD'));
-SET &YEAR = SUBSTR(&THENDTTM.LENGTH, &THENDTTM, 1, &THENDTTM.LENGTH, 4, 'A4');
-SET &MONTH = SUBSTR(&THENDTTM.LENGTH, &THENDTTM, 5, &THENDTTM.LENGTH, 2, 'A2');
-SET &DAY = SUBSTR(&THENDTTM.LENGTH, &THENDTTM, 7, &THENDTTM.LENGTH, 2, 'A2');
-TYPE YEAR = &YEAR;
-TYPE MONTH = &MONTH;
-TYPE DAY = &DAY;
-*-SET &THENDTTMDISP = '<div id=mdy>' | &MONTH | '/' | &DAY | '/' | &YEAR | '</div>';
-SET &THENDTTMDISP = &MONTH | '/' | &DAY | '/' | &YEAR;
-TYPE THENDTTM = &THENDTTM
-TYPE THENDTTMDISP = &THENDTTMDISP
-*Get a list of files in the audit_logger app folder.
APP QUERY audit_logger HOLD
-RUN
-*build some new fields to view and query against.
DEFINE FILE FOCAPPQ
D/I2 = EDIT(GETTOK(DATE,10,1,'/',2,'A2')) ;
M/I2 = EDIT(GETTOK(DATE,10,2,'/',2,'A2')) ;
INTDATE/I9 = EDIT(GETTOK(DATE,10,3,'/',4,'A4') | EDIT(M) | EDIT(D));
FILEDATE/A8MDYY = EDIT(M) | EDIT(D) | GETTOK(DATE,10,3,'/',4,'A4');
SELECTDAYS/A255 = '<select id="KEEPDAYS" onchange="keepDayChanged()"><option>1</options><option>5</options><option>10</options><option>20</options><option>30</options><option>60</options><option>90</options></select>';
DELETEBUTTON/A255 = '<button id="deleteBtn" class="deleteBtn" onclick="runDelete()">Delete</button>';
THENDTTMDISP/A255 = '<div style="display: inline;" id="mdy">&THENDTTMDISP.EVAL</div>';
SHOWBUTTON/A255 = '<button id="showBtn" class="showBtn" onclick="runShow()">Show</button>';
VIEWFILE/A255 = '<button id="viewBtn" class="viewBtn" onclick=runView("'|FILENAME||'")>View</button>';
ISFILTERED/I2 = POSIT(FILENAME, 70, '.mas', 4, 'I3')+POSIT(FILENAME, 70, '.foc', 4, 'I3')+POSIT(FILENAME, 70, '.acx', 4, 'I3')+POSIT(FILENAME, 70, '.fex', 4, 'I3');
END
-*put the list of files into a hold file, so they can be viewed or looped through and physically deleted.
TABLEF FILE FOCAPPQ
PRINT
FILEDATE
FILENAME AS 'FileNM';
APPNAME
INTDATE
SIZE
SELECTDAYS
DELETEBUTTON
SHOWBUTTON
VIEWFILE
ISFILTERED
THENDTTMDISP
-IF &DEL EQ 'N' THEN GOTO SKIPWHERE;
WHERE INTDATE LE '&THENDTTM';
-SKIPWHERE
WHERE ISFILTERED EQ 0;
ON TABLE HOLD AS FILELIST
END
-RUN
-*? HOLD FILELIST
-*-EXIT
-IF &DEL EQ 'Y' THEN GOTO DELETEFILES;
-*Display the files on the screen, coloring the files to be deleted in red.
TABLE FILE FILELIST
PRINT
FILEDATE
FileNM
COMPUTE SIZE/A25V = FPRINT(ATODBL(SIZE, '12', 'D12C'), 'D12C', 'A25V'); AS 'Size(b)'
VIEWFILE AS 'View File'
HEADING
"Delete files older than <SELECTDAYS days <SHOWBUTTON"
"Delete files on or before <THENDTTMDISP <DELETEBUTTON"
"Anything in red will be deleted."
BY HIGHEST INTDATE NOPRINT
ON TABLE SET PAGE-NUM OFF
ON TABLE SET STYLE *
TYPE=DATA, COLUMN=FileNM, COLOR=RGB(255 0 0), WHEN=INTDATE LE &THENDTTM, $
ENDSTYLE
END
-*create function to call back and delete files.
-HTMLFORM BEGIN
<script>
{
var keepdays = document.getElementById('KEEPDAYS');
keepdays.value = '&KEEPDAYS';
}
Number.prototype.pad = function(size) {
var s = String(this);
while (s.length < (size || 2)) {s = "0" + s;}
return s;
}
Date.prototype.addDays = function(days) {
var dat = new Date(this.valueOf());
var ret = new Date(dat.setDate(dat.getDate() + days));
return ret;
}
Date.prototype.subtractDays = function(days) {
var dat = new Date(this.valueOf());
var ret = new Date(dat.setDate(dat.getDate() - days));
return ret;
}
function keepDayChanged() {
var result = new Date();
var newResult = result.subtractDays(keepdays.value);
var month = (newResult.getMonth()+1).pad(2);
var day = (newResult.getDate()).pad(2);
var year = newResult.getFullYear();
var newDate = month + '/' + day + '/' + year;
var mdy = document.getElementById('mdy');
mdy.textContent = newDate;
}
function runView(fileName) {
location.href='&BASEURL.EVAL&|FILEN='+fileName+'&|KEEPDAYS='+keepdays.value;
}
function runDelete() {
if(confirm('Are you sure you want to delete files older than ' + keepdays.value + ' days old?'))
location.href='&BASEURL.EVAL&|DEL=Y&|KEEPDAYS='+keepdays.value;
}
function runShow() {
location.href='&BASEURL.EVAL&|KEEPDAYS='+keepdays.value;
}
function runDownload(fileName) {
location.href='&BASEURL.EVAL&|KEEPDAYS='+keepdays.value+'&|FILEN='+fileName+'&|DL=Y';
}
</script>
<style>
button {
margin-top: 2px;
margin-right: 2px;
float: right;
width: 70px;
}
.deleteBtn {
margin-bottom: 2px;
}
.downloadBtn {
margin-bottom: 2px;
}
</style>
<div style="position: absolute; top: 8px; left: 450px;">
-HTMLFORM END
-DOWNLOADFILE
DEFINE FILE foccache/TMPFILE
DLFILE/A255 = '<button id="downloadBtn" class="downloadBtn" onclick=runDownload("&FILEN.EVAL")>Download XLSX</button>';
END
TABLE FILE foccache/TMPFILE
PRINT ROWTIME AS ''
ROWUSER AS ''
ROWIPADDR AS ''
ROWPAGE AS ''
ROWINFORMATION AS ''
-IF &DL EQ 'Y' THEN GOTO SKIPHEADING;
HEADING
"Viewing file: &FILEN.EVAL <DLFILE"
-SKIPHEADING
-IF &DL EQ 'N' THEN GOTO SKIPDOWNLOAD;
ON TABLE PCHOLD FORMAT XLSX AS &FILEN
-SKIPDOWNLOAD
ON TABLE SET PAGE-NUM OFF
ON TABLE SET LINES 999999
ON TABLE SET STYLE *
TYPE=HEADING, COLOR=RGB(255 0 0), $
TYPE=DATA, COLOR=RGB(255 0 0), WHEN=ROWTIME EQ 'Time', $
ENDSTYLE
END
-SKIPDISP
-IF &DL = 'Y' AND &FILEN.LENGTH GT 1 THEN GOTO EXIT;
-HTMLFORM BEGIN
</div>
-HTMLFORM END
-EXIT
-DELETEFILES
-*Loop through file list and delete them.
-REPEAT ENDLOOP &LINES TIMES
-READFILE FILELIST
-*strip trailing spaces
-SET &FileNM = TRUNCATE(&FileNM);
-*find the extension
-SET &loc = POSIT(&FileNM, &FileNM.LENGTH, '.', 1, 'I2');
-SET &Ext = TRUNCATE(SUBSTR(&FileNM.LENGTH, &FileNM, &loc+1, &FileNM.LENGTH, &FileNM.LENGTH, 'A&FileNM.LENGTH'));
-TYPE Ext = &Ext;
-*make sure there isn't more periods in the file.
-SET &loc = POSIT(&Ext, &Ext.LENGTH, '.', 1, 'I2');
-IF &loc EQ 0 THEN GOTO GETFILE;
-FINDEXT
-*go to the next period found.
-SET &Ext = TRUNCATE(SUBSTR(&Ext.LENGTH, &Ext, &loc+1, &Ext.LENGTH, &Ext.LENGTH, 'A&Ext.LENGTH'));
-TYPE Ext = &Ext;
-SET &loc = POSIT(&Ext, &Ext.LENGTH, '.', 1, 'I2');
-IF &loc GT 0 THEN GOTO FINDEXT;
-GETFILE
-*Get only the file name without extension by replaceing the extension with blank.
-SET &FileNM = TRUNCATE(STRREP(&FileNM.LENGTH, &FileNM, &Ext.LENGTH+1, '.'|&Ext, 0, '', &FileNM.LENGTH, 'A&FileNM.LENGTH'));
-TYPE FileNM = &FileNM;
-TYPE Ext = &Ext;
-*Delete file.
APP DELETEF '&APPNAME' '&FileNM' '&Ext'
-ENDLOOP
-*reload page, displaying files left.
-HTMLFORM BEGIN
<script>
{
location.href='&BASEURL.EVAL&|KEEPDAYS=&KEEPDAYS.EVAL'
}
</script>
-HTMLFORM END
This message has been edited. Last edited by: GavinL,
- FOCUS Man, just FOCUS! ----------------------------- Product: WebFOCUS Version: 8.1.04 Server: Windows 2008 Server