77dde8a831004c9007488a90784605b6b6ee168e chmalee Tue Apr 16 11:22:04 2019 -0700 First pass on validate hub tab for hgHubConnect, currently hg.conf controlled. Work in progress still, refs #18870 diff --git src/hg/hgHubConnect/hgHubConnect.c src/hg/hgHubConnect/hgHubConnect.c index d2de99c..37ed605 100644 --- src/hg/hgHubConnect/hgHubConnect.c +++ src/hg/hgHubConnect/hgHubConnect.c @@ -369,30 +369,174 @@ ourPrintCell(""); if (hub->trackHub != NULL) printGenomes(hub->trackHub, count, !hubHasError); else ourPrintCell(""); puts(""); } printf("\n"); printf(""); } +int doCheckTrackDb(struct dyString *errors, struct trackHub *hub, + struct trackHubGenome *genome) +/* Attempt to open a trackDb from a hub and report errors back. + * Eventually will check every stanza and not die if there's an error with the first one*/ +{ +int errorCount = 0; +struct trackDb *tdb = NULL; +struct errCatch *errCatch = errCatchNew(); +if (errCatchStart(errCatch)) + { + tdb = trackHubTracksForGenome(hub, genome); + tdb = trackDbLinkUpGenerations(tdb); + tdb = trackDbPolishAfterLinkup(tdb, genome->name); + if (tdb != NULL) + { + dyStringPrintf(errors, ""); + } + } +errCatchEnd(errCatch); +if (errCatch->gotError) + { + errorCount += 1; + dyStringPrintf(errors, "\n", + errCatch->message->string); + } +errCatchFree(&errCatch); +return errorCount; +} + +int doCheckGenomesFile(struct dyString *errors, struct trackHub *hub) +/* Mostly just calls doCheckTrackDb() but applies correct styling to error messages */ +{ +struct trackHubGenome *genome = NULL; +int errorCount = 0; +int trackDbErrorCount = 0; +struct dyString *trackDbErrorString = dyStringNew(0); +for (genome = hub->genomeList; genome != NULL; genome = genome->next) + { + trackDbErrorCount = 0; + dyStringPrintf(errors, "\n", trackDbErrorCount, trackDbErrorString->string); + else + dyStringPrintf(errors, " (%d errors)\n%s\n", trackDbErrorCount, trackDbErrorString->string); + } + else + dyStringPrintf(errors, ""); + dyStringClear(trackDbErrorString); + } +dyStringFree(&trackDbErrorString); +return errorCount; +} + +struct trackHub *trackHubCheckHubFile(struct dyString *errors, char *hubUrl) +/* Wrap trackHubOpen in an errCatch, HTML style the error message */ +{ +struct trackHub *hub = NULL; +struct errCatch *errCatch = errCatchNew(); +if (errCatchStart(errCatch)) + hub = trackHubOpen(hubUrl, ""); +errCatchEnd(errCatch); +if (errCatch->gotError) + dyStringPrintf(errors, "Error: %s", errCatch->message->string); +errCatchFree(&errCatch); +return hub; +} + +void doValidateNewHub(char *hubUrl) +/* Open up a track hub and report errors to user. */ +{ +struct trackHub *hub = NULL; +struct dyString *errors = dyStringNew(0); // string with HTML of all the errors +udcSetCacheTimeout(1); +printf(""); +hub = trackHubCheckHubFile(errors, hubUrl); +if (hub) + { + // go through each genome and check each trackDb stanza, building up errors string + int errorCount = doCheckGenomesFile(errors, hub); + if (errorCount > 0) + { + printf("
"); + if (errorCount == 1) + printf("
"); +} + +void hgHubConnectValidateNewHub() +{ +// put out the top of our page +char *hubUrl = cartOptionalString(cart, "validateHubUrl"); +printf("
\n" + " \n" + " \n"); +printf(" \n" + " \n"); + +if (hubUrl == NULL) + printf(" \n"); +else + doValidateNewHub(hubUrl); +printf("
\n"); +if (hubUrl != NULL) + { + printf(" \n", hubUrl); + } +else + { + printf(" \n"); + } +printf("\n" + "
Enter URL to hub to check settings
"); + +jsOnEventById("click", "hubValidateButton", + "var validateText = document.getElementById('validateHubUrl');" + "validateText.value=$.trim(validateText.value);" + "if(validateUrl($('#validateHubUrl').val())) { " + " document.validateHubForm.elements['validateHubUrl'].value=validateText.value;" + " document.validateHubForm.submit(); return true; }" + "else { return false; }" + ); +} static void addPublicHubsToHubStatus(struct sqlConnection *conn, char *publicTable, char *statusTable) /* Add urls in the hubPublic table to the hubStatus table if they aren't there already */ { char query[1024]; sqlSafef(query, sizeof(query), "select %s.hubUrl from %s left join %s on %s.hubUrl = %s.hubUrl where %s.hubUrl is NULL", publicTable, publicTable, statusTable, publicTable, statusTable, statusTable); struct sqlResult *sr = sqlGetResult(conn, query); char **row; while ((row = sqlNextRow(sr)) != NULL) { char *errorMessage = NULL; char *url = row[0]; @@ -1463,42 +1607,56 @@ // this is the form for the reset hub button printf("
\n", "../cgi-bin/hgHubConnect"); cgiMakeHiddenVar(hgHubCheckUrl, ""); cartSaveSession(cart); puts("
"); // this is the form for the search hub button printf("
\n", "../cgi-bin/hgHubConnect"); cgiMakeHiddenVar(hgHubSearchTerms, ""); cgiMakeHiddenVar(hgHubDoSearch, "on"); cgiMakeHiddenVar(hgHubDbFilter, ""); cartSaveSession(cart); puts("
"); +// this is the form for the validate button +boolean doValidate = cfgOptionBooleanDefault("hgHubConnect.validateHub", FALSE); +if (doValidate) + { + printf("
\n", "../cgi-bin/hgHubConnect"); + cgiMakeHiddenVar("validateHubUrl", ""); + cartSaveSession(cart); + puts("
"); + } + // ... and now the main form printf("
\n", "../cgi-bin/hgGateway"); cartSaveSession(cart); // we have two tabs for the public and unlisted hubs printf("
" " "); + "
  • My Hubs
  • "); +if (doValidate) // put up the validate tab if hg.conf statement present + printf("
  • Validate Hub
  • "); +printf(" "); struct hash *publicHash = hgHubConnectPublic(); hgHubConnectUnlisted(hubList, publicHash); +if (doValidate) + hgHubConnectValidateNewHub(); printf("
    "); printf("
    "); printf("" "Contact us to add a public hub." "\n"); printf("
    "); cgiMakeHiddenVar(hgHubConnectRemakeTrackHub, "on"); puts("
    "); printf("
    \n"); jsInline(