ce5fb4ee78a01179f2f53114b6eb52ca77811eb6
kate
  Wed Jan 23 10:08:41 2013 -0800
1. hgFileUi now only prints data restriction warning if the composite has a restricted object. 2. Add -cv option to mdbPrint to allow alternate CV file.  2. 3. A step toward modularizing restriction timestamp handling.  #10006  Mute File UI loud warnings when they are not applicable.
diff --git src/hg/lib/fileUi.c src/hg/lib/fileUi.c
index 5ac7cee..d38fa24 100644
--- src/hg/lib/fileUi.c
+++ src/hg/lib/fileUi.c
@@ -579,46 +579,47 @@
         #define FILTERBY_HELP_LINK  "<A HREF=\"../goldenPath/help/multiView.html\" " \
                                     "TARGET=ucscHelp>help</A>"
         cgiDown(0.9);
         printf("<B>Filter files by:</B> (select multiple %sitems - %s)\n"
                "<table><tr valign='bottom'>\n",
                (count >= 1 ? "categories and ":""),FILTERBY_HELP_LINK);
         printf("%s\n",dyStringContents(dyFilters));
         printf("</tr></table>\n");
         jsIncludeFile("ddcl.js",NULL);
         }
     dyStringFree(&dyFilters);
     }
 return filterableBits;
 }
 
-static void filesDownloadsPreamble(char *db, struct trackDb *tdb)
+static void filesDownloadsPreamble(char *db, struct trackDb *tdb, boolean isUnrestricted)
 // Replacement for preamble.html which should expose parent dir, files.txt and supplemental, but
 // not have any specialized notes per composite.  Specialized notes belong in track description.
 {
 char *server = hDownloadsServer();
 char *subDir = "";
 if (hIsBetaHost())
     {
     server = "hgdownload-test.cse.ucsc.edu"; // NOTE: Force this case because beta may think
     subDir = "/beta";                        // it's downloads server is "hgdownload.cse.ucsc.edu"
     }
-
+if (!isUnrestricted)
+    {
 cgiDown(0.9);
 puts("<B>Data is <A HREF='../ENCODE/terms.html' TARGET='_BLANK'>RESTRICTED FROM USE</a>");
 puts("in publication  until the restriction date noted for the given data file.</B>");
-
+}
 cgiDown(0.7);
 puts("Additional resources:");
 printf("<BR>&#149;&nbsp;<B><A HREF='http://%s/goldenPath/%s/%s/%s%s/files.txt' "
        "TARGET=ucscDownloads>files.txt</A></B> - lists the name and metadata for each download.\n",
        server,db,ENCODE_DCC_DOWNLOADS, tdb->track, subDir);
 printf("<BR>&#149;&nbsp;<B><A HREF='http://%s/goldenPath/%s/%s/%s%s/md5sum.txt' "
        "TARGET=ucscDownloads>md5sum.txt</A></B> - lists the md5sum output for each download.\n",
        server,db,ENCODE_DCC_DOWNLOADS, tdb->track, subDir);
 printf("<BR>&#149;&nbsp;<B><A HREF='http://%s/goldenPath/%s/%s/%s%s'>downloads server</A></B> - "
        "alternative access to downloadable files (may include obsolete data).\n",
        server,db,ENCODE_DCC_DOWNLOADS, tdb->track, subDir);
 
 struct fileDb *oneFile = fileDbGet(db, ENCODE_DCC_DOWNLOADS, tdb->track, "supplemental");
 if (oneFile != NULL)
     {
@@ -770,31 +771,31 @@
                             // This may not be needed because the filterBy code
                             // already eliminated these.
                             safecpy(buf,sizeof buf,field);
                             cleanClass = buf;
                             eraseNonAlphaNum(cleanClass);
                             }
                         }
                     safef(class,sizeof class," class='%s %s'",sortOrder->column[ix],cleanClass);
                     }
 
                 char *align = (sameString("labVersion",sortOrder->column[ix])
                             || sameString("softwareVersion",sortOrder->column[ix]) ?
                                " align='left'":" align='center'");
                 if (sameString("dateUnrestricted",sortOrder->column[ix])
                 &&  field
-                &&  dateIsOld(field,"%F"))
+                &&  dateIsOld(field, MDB_ENCODE_DATE_FORMAT))
                     printf("<TD%s nowrap style='color: #BBBBBB;'%s>%s</td>",align,class,field);
                 else
                     {
                     // use label
                     if (!isFieldEmpty && termHash)
                         {
                         char *label = hashFindVal(termHash,CV_LABEL);
                         if (label != NULL)
                             field = label;
                         }
                     printf("<TD%s nowrap%s>%s</td>",align,class,isFieldEmpty?" &nbsp;":field);
                     }
                 if (!sameString("fileType",sortOrder->column[ix]))
                     mdbObjRemoveOneVar(oneFile->mdb,sortOrder->column[ix],NULL);
                 }
@@ -839,57 +840,64 @@
 
 printf("</TD></TR>\n");
 printf("</TFOOT></TABLE>\n");
 
 if (parentTdb == NULL)
     printf("<script type='text/javascript'>{$(document).ready(function() {"
            "sortTable.initialize($('table.sortable')[0],true,true);});}</script>\n");
 
 if (timeIt)
     uglyTime("Finished table");
 return filesCount;
 }
 
 
 static int filesFindInDir(char *db, struct mdbObj **pmdbFiles, struct fileDb **pFileList,
-                          char *fileType, int limit,boolean *exceededLimit)
+                      char *fileType, int limit, boolean *exceededLimit, boolean *isUnrestricted)
 // Prints list of files in downloads directories matching mdb search terms. Returns count
 {
 int fileCount = 0;
+if (isUnrestricted != NULL)
+    *isUnrestricted = TRUE;
+
 // Verify file existance and make fileList of those found
 struct fileDb *fileList = NULL, *oneFile = NULL; // Will contain found files
 struct mdbObj *mdbFiles = NULL; // Will caontain a list of mdbs for the found files
 struct mdbObj *mdbList = *pmdbFiles;
 while (mdbList && (limit == 0 || fileCount < limit))
     {
     boolean found = FALSE;
     struct mdbObj *mdbFile = slPopHead(&mdbList);
     char *composite = mdbObjFindValue(mdbFile,MDB_VAR_COMPOSITE);
     if (composite == NULL)
         {
         mdbObjsFree(&mdbFile);
         continue;
         }
 
     // First for FileName
     char *fileName = mdbObjFindValue(mdbFile,MDB_VAR_FILENAME);
     if (fileName == NULL)
         {
         mdbObjsFree(&mdbFile);
         continue;
         }
 
+    // Are any files still restricted access under ENCODE data policy ?
+    if (isUnrestricted != NULL && *isUnrestricted)
+        *isUnrestricted = mdbObjEncodeIsUnrestricted(mdbFile);
+
     struct slName *fileSet = slNameListFromComma(fileName);
     struct slName *md5Set = NULL;
     char *md5sums = mdbObjFindValue(mdbFile,MDB_VAR_MD5SUM);
     if (md5sums != NULL)
         md5Set = slNameListFromComma(md5sums);
 
     // Could be that "bai" is implicit with "bam"
     if ((slCount(fileSet) == 1) && endsWith(fileSet->name,".bam"))
         {
         char buf[512];
         safef(buf,sizeof(buf),"%s.bai",fileSet->name);
         slNameAddTail(&fileSet, buf);
         }
     while (fileSet != NULL)
         {
@@ -1023,52 +1031,53 @@
 
 if (mdbList)
     (void)mdbObjsFilter(&mdbList,"objStatus","re*",TRUE); // revoked, replaced, renamed
 
 if (slCount(mdbList) == 0)
     {
     warn("No files specified in metadata for: %s\n%s",tdb->track,tdb->longLabel);
     return;
     }
 if (timeIt)
     uglyTime("Found %d mdb objects",slCount(mdbList));
 
 // Verify file existance and make fileList of those found
 struct fileDb *fileList = NULL; // Will contain found files
 
-int fileCount = filesFindInDir(db, &mdbList, &fileList, NULL, 0, NULL);
+boolean isUnrestricted;
+int fileCount = filesFindInDir(db, &mdbList, &fileList, NULL, 0, NULL, &isUnrestricted);
 if (timeIt)
     uglyTime("Found %d files in dir",fileCount);
 assert(fileCount == slCount(fileList));
 
 if (fileCount == 0)
     {
     warn("No downloadable files currently available for: %s\n%s",tdb->track,tdb->longLabel);
     return;  // No files so nothing to do.
     }
 if (debug)
     {
     warn("The following files are in goldenPath/%s/%s/%s/ but NOT in the mdb:",
          db,ENCODE_DCC_DOWNLOADS, tdb->track);
     fileDbGet(db, ENCODE_DCC_DOWNLOADS, tdb->track, "listAll");
     }
 
 jsIncludeFile("hui.js",NULL);
 jsIncludeFile("ajax.js",NULL);
 
 // standard preamble
-filesDownloadsPreamble(db,tdb);
+filesDownloadsPreamble(db,tdb, isUnrestricted);
 
 // remove these now to get them out of the way
 mdbObjRemoveVars(mdbList,MDB_VAR_FILENAME " " MDB_VAR_FILEINDEX " "
                          MDB_VAR_COMPOSITE " " MDB_VAR_PROJECT);
 if (timeIt)
     uglyTime("<BR>Removed 4 unwanted vars");
 
 // Now update all files with their sortable fields and sort the list
 mdbObjReorderByCv(mdbList,FALSE);// Start with cv defined order for visible vars.
                                  // NOTE: will not need to reorder during print!
 sortOrder_t *sortOrder = fileSortOrderGet(cart,tdb,mdbList);
 int filterable = 0;
 if (sortOrder != NULL)
     {
     int removed = removeCommonMdbVarsNotInSortOrder(mdbList,sortOrder);
@@ -1117,31 +1126,32 @@
 if (slCount(mdbList) == 0)
     {
     printf("<DIV id='filesFound'><BR>No files found.<BR></DIV><BR>\n");
     return 0;
     }
 if (timeIt)
     uglyTime("Found %d mdb objects",slCount(mdbList));
 
 // Now sort mdbObjs so that composites will stay together & lookup of files will be most efficient
 mdbObjsSortOnVars(&mdbList, MDB_VAR_COMPOSITE);
 
 #define FOUND_FILE_LIMIT 1000
 struct fileDb *fileList = NULL; // Will contain found files
 int filesExpected = slCount(mdbList);
 boolean exceededLimit = FALSE;
-int fileCount = filesFindInDir(db, &mdbList, &fileList, fileType, FOUND_FILE_LIMIT, &exceededLimit);
+int fileCount = filesFindInDir(db, &mdbList, &fileList, fileType, FOUND_FILE_LIMIT, 
+                                &exceededLimit, NULL);
 if (timeIt)
     uglyTime("Found %d files in dir",fileCount);
 assert(fileCount == slCount(fileList));
 
 if (fileCount == 0)
     {
     printf("<DIV id='filesFound'><BR>No files found.<BR></DIV><BR>\n");
     return 0;  // No files so nothing to do.
     }
 
 // remove these now to get them out of the way
 mdbObjRemoveVars(mdbList,MDB_VAR_FILENAME " " MDB_VAR_FILEINDEX " "
                          MDB_VAR_PROJECT " " MDB_VAR_TABLENAME);
 if (timeIt)
     uglyTime("Removed 4 unwanted vars");