/** * This class is designed to be a stand-alone program to validate that the DataSet.properties file * contains valid information for all datasets listed by validDataSets in DataSet.properties. * Don't run this on the coastwatch computer. * * @param args is ignored */ public static void main(String args[]) throws Exception { String2.log("ValidatDataSetProperties (testing DataSet.properties validDataSets"); // find a browser properties file (e.g., CWBrowser.properties) String contextDirectory = SSR.getContextDirectory(); // with / separator and / at the end String[] propList = RegexFilenameFilter.list( contextDirectory + "WEB-INF/classes/gov/noaa/pfel/coastwatch/", ".+\\.properties"); int which = -1; for (int i = 0; i < propList.length; i++) { if (!propList[i].equals("DataSet.properties")) { which = i; break; } } Test.ensureNotEqual( which, -1, String2.ERROR + ": No non-DataSet.properties properties files found in\n" + contextDirectory + "WEB-INF/classes/gov/noaa/pfel/coastwatch/.\n" + ".properties files=" + String2.toCSSVString(propList)); FileNameUtility fnu = new FileNameUtility( "gov.noaa.pfel.coastwatch." + File2.getNameNoExtension(propList[which])); ResourceBundle2 dataSetRB2 = new ResourceBundle2("gov.noaa.pfel.coastwatch.DataSet"); String infoUrlBaseUrl = dataSetRB2.getString("infoUrlBaseUrl", null); String tDataSetList[] = String2.split(dataSetRB2.getString("validDataSets", null), '`'); int nDataSets = tDataSetList.length; // Test.ensureEqual(nDataSets, 228, "nDataSets"); //useful to me, but Dave can't add dataset // without recompiling this String2.log(" testing " + nDataSets + " data sets"); boolean excessivelyStrict = true; for (int i = OneOf.N_DUMMY_GRID_DATASETS; i < nDataSets; i++) { // "2" in order to skip 0=OneOf.NO_DATA, 1=BATHYMETRY String seven = tDataSetList[i]; Test.ensureTrue(seven != null && seven.length() > 0, " tDataSetList[" + i + "] is ''."); fnu.ensureValidDataSetProperties(seven, excessivelyStrict); String infoUrl = dataSetRB2.getString(seven + "InfoUrl", null); Test.ensureNotNull(infoUrl, seven + "InfoUrl is null."); SSR.getUrlResponse( infoUrlBaseUrl + infoUrl); // on all computers except coastwatch, all are accessible as urls } String2.log( " ValidatDataSetProperties successfully tested n=" + nDataSets + " last=" + tDataSetList[nDataSets - 1]); }
/** * This creates a font and throws exception if font family not available * * @param fontFamily * @throws Exception if fontFamily not available */ public static Font getFont(String fontFamily) { // minor or major failures return a default font ("Dialog"!) Font font = new Font(fontFamily, Font.PLAIN, 10); // Font.ITALIC if (!font.getFamily().equals(fontFamily)) Test.error( String2.ERROR + " in SgtUtil.getFont: " + fontFamily + " not available.\n" + String2.javaInfo() + "\n" + "Fonts available: " + String2.noLongLinesAtSpace( String2.toCSSVString( GraphicsEnvironment.getLocalGraphicsEnvironment() .getAvailableFontFamilyNames()), 80, " ")); return font; }
/** Constructor */ public CWDataBrowser() throws Exception { super("gov.noaa.pfel.coastwatch.CWDataBrowser"); constructorDateTime = Calendar2.getCurrentISODateTimeStringLocal(); // addAttribute(new EmaLabel(this, "instructions")); addAttribute(dataSet = new EmaSelect(this, "dataSet")); addAttribute(region = new EmaSelect(this, "region")); addAttribute(timePeriod = new EmaSelect(this, "timePeriod")); addAttribute(date = new EmaSelect(this, "date")); addAttribute(formSubmitted = new EmaHidden(this, "formSubmitted")); addAttribute(submitForm = new EmaButton(this, "submitForm")); // one time things verbose = classRB2.getBoolean("verbose", false); // contextDirectory and logs (file will be in same dir as this class's source code, named // log.txt) contextDirectory = classRB2.getString("contextDirectory", ""); int logPo = fullClassName.lastIndexOf('.'); String logDir = String2.replaceAll(fullClassName.substring(0, logPo + 1), ".", "/"); String2.setupLog( false, false, String2.getClassPath() + logDir + "log.txt", // with / separator true, String2.logFileDefaultMaxSize); // append? String2.log( "\n" + String2.makeString('*', 80) + "\nCWDataBrowser.constructor " + constructorDateTime + "\nlogFile=" + String2.logFileName() + "\n" + String2.standardHelpAboutMessage()); // get baseDataDirectory (for access within this program) baseDataDirectory = classRB2.getString("dataDirectory", null); Test.ensureNotNull(baseDataDirectory, "dataDirectory"); // get dataServer (for web-based access to the data) dataServer = classRB2.getString("dataServer", null); Test.ensureNotNull(dataServer, "dataServer"); // how often should reset be called? resetEveryNMillis = classRB2.getInt("resetEveryNMinutes", 10) * 60000; // millis/min // printTopNMostRequested printTopNMostRequested = classRB2.getInt("printTopNMostRequested", 50); // lookForAllUnusedDataFiles lookForAllUnusedDataFiles = classRB2.getBoolean("lookForAllUnusedDataFiles", false); // get the name of the file with the small regions map regionsImage = classRB2.getString("regionsImage", ""); regionsImageTitle = classRB2.getString("regionsImage.title", ""); regionsImageAlt = classRB2.getString("regionsImage.alt", ""); // get title title = classRB2.getString("title.value", ""); // get dataSet properties dataSetOptions = classRB2.getString("dataSet.options", null).split("\f"); dataSetTitles = classRB2.getString("dataSet.title", null).split("\f"); dataSetDirectories = classRB2.getString("dataSet.directories", null).split("\f"); dataSetRegexs = classRB2.getString("dataSet.regexs", null).split("\f"); if (dataSetRequests == null) dataSetRequests = new int[dataSetOptions.length]; boolean trouble = dataSetOptions.length != (dataSetTitles.length - 1) || // 1 extra title (main) dataSetOptions.length != dataSetDirectories.length || dataSetOptions.length != dataSetRegexs.length; if (verbose || trouble) String2.log( "baseDataDirectory: " + baseDataDirectory + "\n" + "dataSetOptions: " + String2.toCSSVString(dataSetOptions) + "\n" + "dataSetTitles: " + String2.toNewlineString(dataSetTitles) + "\n" + "dataSetDirectories: " + String2.toCSSVString(dataSetDirectories) + "\n" + "dataSetRegexs: " + String2.toCSSVString(dataSetRegexs)); if (trouble) throw new RuntimeException( String2.ERROR + ": CWDataBrowser.reset " + "nDataSetOptions " + dataSetOptions.length + " != nDataSetTitles " + dataSetTitles.length + " != nDataSetDirectories " + dataSetDirectories.length + " != nDataSetRegexs " + dataSetRegexs.length); // get region properties regionOptions = classRB2.getString("region.options", null).split("\f"); regionTitles = classRB2.getString("region.title", null).split("\f"); regionRegexs = classRB2.getString("region.regexs", null).split("\f"); regionCoordinates = classRB2.getString("region.coordinates", null).split("\f"); regionRequests = new int[regionOptions.length]; trouble = regionOptions.length != (regionTitles.length - 1) || // 1 extra title (main) regionOptions.length != regionRegexs.length || regionOptions.length != regionCoordinates.length; if (verbose || trouble) String2.log( "regionOptions: " + String2.toCSSVString(regionOptions) + "\n" + "regionTitles: " + String2.toNewlineString(regionTitles) + "\n" + "regionRegexs: " + String2.toCSSVString(regionRegexs)); if (trouble) throw new RuntimeException( String2.ERROR + ": CWDataBrowser.reset " + "nRegionOptions " + regionOptions.length + " != nRegionTitles " + regionTitles.length + " != nRegionRegexs " + regionRegexs.length + " != nRegionCoordinates " + regionCoordinates.length); // get timePeriod properties timePeriodOptions = classRB2.getString("timePeriod.options", null).split("\f"); timePeriodTitles = classRB2.getString("timePeriod.title", null).split("\f"); timePeriodDirectories = classRB2.getString("timePeriod.directories", null).split("\f"); timePeriodRequests = new int[timePeriodOptions.length]; trouble = timePeriodOptions.length != (timePeriodTitles.length - 1) || // 1 extra title (main) timePeriodOptions.length != timePeriodDirectories.length; if (verbose || trouble) String2.log( "timePeriodOptions: " + String2.toCSSVString(timePeriodOptions) + "\n" + "timePeriodTitles: " + String2.toNewlineString(timePeriodTitles) + "\n" + "timePeriodDirectories: " + String2.toCSSVString(timePeriodDirectories)); if (trouble) throw new RuntimeException( String2.ERROR + ": CWDataBrowser.reset " + "nTimePeriodOptions " + timePeriodOptions.length + " != nTimePeriodTitles " + timePeriodTitles.length + " " + " != nTimePeriodDirectories " + timePeriodDirectories.length); // get 'get' properties // the first 'get' option must be .gif; a .gif file must be present before looking for others getOptions = classRB2.getString("get.options", null).split("\f"); getTitles = classRB2.getString("get.title", null).split("\f"); getDirectories = classRB2.getString("get.directories", null).split("\f"); getRegexs = classRB2.getString("get.regexs", null).split("\f"); getExtensions = classRB2.getString("get.extensions", null).split("\f"); hereIs = classRB2.getString("hereIs", null); hereIsAlt = classRB2.getString("hereIsAlt", null); trouble = getOptions.length != (getTitles.length - 1) || // 1 extra title (main) getOptions.length != getDirectories.length || getOptions.length != getRegexs.length || getOptions.length != getExtensions.length; if (verbose || trouble) String2.log( "getOptions: " + String2.toCSSVString(getOptions) + "\n" + "getDirectories: " + String2.toCSSVString(getDirectories) + "\n" + "getExtensions: " + String2.toCSSVString(getExtensions) + "\n" + "getRegexs: " + String2.toCSSVString(getRegexs)); if (trouble) throw new RuntimeException( String2.ERROR + ": CWDataBrowser.reset \n" + "nGetOptions " + getOptions.length + " != nGetTitles " + getTitles.length + " != nGetDirectories " + getDirectories.length + " != nGetRegexs " + getRegexs.length + " != nGetExtensions " + getExtensions.length); requestedFilesMap = new ConcurrentHashMap(128, 0.75f, 4); // thread-safe // EmaAttribute.verbose= true; // reset after attributes have been created runCWDataBrowserReset(); resetThread.join(); boolean ok = getDataFromReset(); // it should succeed first try if (!ok) throw new RuntimeException(String2.ERROR + " in CWDataBrowserReset."); }