示例#1
0
  private void setVariables(Field.BeanTableField beanTableField) {
    List<ThreddsMetadata.Variables> variableLists = dataset.getLocalMetadata().getVariables();
    if ((variableLists != null) && (variableLists.size() > 0)) {
      ThreddsMetadata.Variables vars = variableLists.get(0);
      beanTableField.setValue(vars.getVariableList());
      setMode(beanTableField, 0);
      return;
    }

    variableLists = dataset.getLocalMetadataInheritable().getVariables();
    if ((variableLists != null) && (variableLists.size() > 0)) {
      ThreddsMetadata.Variables vars = variableLists.get(0);
      beanTableField.setValue(vars.getVariableList());
      setMode(beanTableField, 1);
      return;
    }

    variableLists = dataset.getVariables();
    if ((variableLists != null) && (variableLists.size() > 0)) {
      ThreddsMetadata.Variables vars = variableLists.get(0);
      beanTableField.setValue(vars.getVariableList());
      setMode(beanTableField, vars.getVariableList().size() == 0 ? 1 : 2);
      return;
    }

    // clear out the table
    beanTableField.setValue(new ArrayList());
  }
  private NetcdfDataset openDataset(
      InvDataset invDataset, boolean acquire, ucar.nc2.util.CancelTask task, Result result)
      throws IOException {

    IOException saveException = null;

    List<InvAccess> accessList =
        new ArrayList<InvAccess>(invDataset.getAccess()); // a list of all the accesses
    while (accessList.size() > 0) {
      InvAccess access = chooseDatasetAccess(accessList);

      // no valid access
      if (access == null) {
        result.errLog.format("No access that could be used in dataset %s %n", invDataset);
        if (saveException != null) throw saveException;
        return null;
      }

      String datasetLocation = access.getStandardUrlName();
      ServiceType serviceType = access.getService().getServiceType();
      if (debugOpen)
        System.out.println("ThreddsDataset.openDataset try " + datasetLocation + " " + serviceType);

      // deal with RESOLVER type
      if (serviceType == ServiceType.RESOLVER) {
        InvDatasetImpl rds = openResolver(datasetLocation, task, result);
        if (rds == null) return null;
        accessList = new ArrayList<InvAccess>(rds.getAccess());
        continue;
      }

      // ready to open it through netcdf API
      NetcdfDataset ds;

      // try to open
      try {
        ds = openDataset(access, acquire, task, result);

      } catch (IOException e) {
        result.errLog.format("Cant open %s %n err=%s%n", datasetLocation, e.getMessage());
        if (debugOpen) {
          System.out.println("Cant open= " + datasetLocation + " " + serviceType);
          e.printStackTrace();
        }

        accessList.remove(access);
        saveException = e;
        continue;
      }

      result.accessUsed = access;
      return ds;
    } // loop over accesses

    if (saveException != null) throw saveException;
    return null;
  }
示例#3
0
  private void level2level3catalog(
      RadarType radarType,
      String pathInfo,
      PrintWriter pw,
      HttpServletRequest req,
      HttpServletResponse res)
      throws IOException {

    try {
      String type;
      if (pathInfo.contains("level2")) type = radarType.toString() + "/level2";
      else type = radarType.toString() + "/level3";

      ByteArrayOutputStream os = new ByteArrayOutputStream(10000);
      InvCatalogFactory factory = InvCatalogFactory.getDefaultFactory(false);
      factory.writeXML(cat, os, true);
      InvCatalogImpl tCat = factory.readXML(new ByteArrayInputStream(os.toByteArray()), catURI);

      Iterator parents = tCat.getDatasets().iterator();
      while (parents.hasNext()) {
        ArrayList<InvDatasetImpl> delete = new ArrayList<InvDatasetImpl>();
        InvDatasetImpl top = (InvDatasetImpl) parents.next();
        Iterator tDatasets = top.getDatasets().iterator();
        while (tDatasets.hasNext()) {
          InvDatasetImpl ds = (InvDatasetImpl) tDatasets.next();
          if (ds instanceof InvDatasetScan) {
            InvDatasetScan ids = (InvDatasetScan) ds;
            if (ids.getPath() == null) continue;
            if (ids.getPath().contains(type)) {
              ids.setXlinkHref(ids.getPath() + "/dataset.xml");
            } else {
              delete.add(ds);
            }
          }
        }
        // remove datasets
        for (InvDatasetImpl idi : delete) {
          top.removeDataset(idi);
        }
      }
      if (pathInfo.endsWith("xml")) {
        String catAsString = factory.writeXML(tCat);
        pw.println(catAsString);
        pw.flush();
      } else {
        HtmlWriter.getInstance().writeCatalog(req, res, tCat, true); // show catalog as HTML
      }
    } catch (Throwable e) {
      log.error("RadarServer.level2level3catalog failed", e);
      if (!res.isCommitted()) res.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    }
    return;
  }
示例#4
0
  private void extractVariables() {
    if (leafDataset == null) leafDataset = findLeafDataset(dataset);
    if (leafDataset == null) return;

    ThreddsMetadata.Variables vars;
    try {
      vars = MetadataExtractor.extractVariables(leafDataset);
    } catch (IOException e) {
      return;
    }

    if (vars != null) {
      ThreddsMetadata tm = dataset.getLocalMetadataInheritable();
      List<ThreddsMetadata.Variables> varsList = tm.getVariables();
      boolean replaced = false;
      for (int i = 0; i < varsList.size(); i++) {
        ThreddsMetadata.Variables vs = varsList.get(i);
        if (vs.getVocabulary().equals(vars.getVocabulary())) {
          varsList.set(i, vars); // replace
          replaced = true;
          break;
        }
      }
      if (!replaced) tm.addVariables(vars);

      variablesFld.setValue(vars.getVariableList());
      setMode(variablesFld, 1);
    }
  }
示例#5
0
  private InvDatasetImpl getLeafDataset(InvDatasetImpl ds) {
    if (ds == null) return null;
    System.out.println("getLeafDataset " + ds.getFullName());
    List nestedList = ds.getDatasets();
    for (int i = 0; i < nestedList.size(); i++) {
      InvDatasetImpl nestedDS = (InvDatasetImpl) nestedList.get(i);

      if (nestedDS.hasAccess() && !nestedDS.hasNestedDatasets()) {
        InvDatasetImpl result =
            chooseLeafDataset(nestedList); // this assumes that they are uniform !!
        return (result.hasAccess()) ? result : nestedDS;
      }

      // depth first
      InvDatasetImpl leaf = getLeafDataset(nestedDS);
      if (leaf != null) return leaf;
    }

    return null;
  }
示例#6
0
  public void store2Dataset() {
    PersistentBean persBean = new PersistentBean(dataset); // reset the BeanMaps

    setStoreValue(NAME, persBean, false);
    setStoreValue(ID, persBean, false);

    setStoreValue(AUTHORITY, persBean, true);
    setStoreValue(SERVICE_NAME, persBean, true);

    setStoreValue(FORMAT_TYPE, persBean, true);
    setStoreValue(DATA_TYPE, persBean, true);

    setStoreValue(COLLECTION_TYPE, persBean, false);
    setStoreValue(HARVEST, persBean, false);

    String gcType = (String) metadataPP.getFieldValue(GC_TYPE);
    if (!gcType.equals(INHERITED)) {
      ThreddsMetadata.GeospatialCoverage gc = new ThreddsMetadata.GeospatialCoverage();
      storeGC(new PersistentBean(gc));
      if (gcType.equals(LOCAL)) {
        dataset.getLocalMetadata().setGeospatialCoverage(gc);
        dataset.getLocalMetadataInheritable().setGeospatialCoverage(null);

      } else {
        dataset.getLocalMetadata().setGeospatialCoverage(null);
        dataset.getLocalMetadataInheritable().setGeospatialCoverage(gc);
      }
    }

    String tcType = (String) metadataPP.getFieldValue(TC_TYPE);
    if (!tcType.equals(INHERITED)) {
      DateRange dateRange = dateRangeSelector.getDateRange();
      if (tcType.equals(LOCAL)) {
        dataset.getLocalMetadata().setTimeCoverage(dateRange);
        dataset.getLocalMetadataInheritable().setTimeCoverage((DateRange) null);

      } else {
        dataset.getLocalMetadata().setTimeCoverage((DateRange) null);
        dataset.getLocalMetadataInheritable().setTimeCoverage(dateRange);
      }
    }

    setStoreValue(SUMMARY, persBean, true);
    setStoreValue(RIGHTS, persBean, true);
    setStoreValue(HISTORY, persBean, true);
    setStoreValue(PROCESSING, persBean, true);

    // storeBeanList( variablesFld, VARIABLES, persBean);
    storeBeanList(creatorsFld, CREATORS, persBean);
    storeBeanList(publishersFld, PUBLISHERS, persBean);
    storeBeanList(projectsFld, PROJECTS, persBean);
    storeBeanList(keywordsFld, KEYWORDS, persBean);
    storeBeanList(datesFld, DATES, persBean);
    storeBeanList(contributorsFld, CONTRIBUTORS, persBean);
    storeBeanList(docsFld, DOCUMENTATION, persBean);

    if (dataset instanceof InvDatasetScan) {
      setStoreValue(dscanPP, DSCAN_PATH, persBean, false);
      setStoreValue(dscanPP, DSCAN_DIR, persBean, false);
      // setStoreValue( dscanPP, DSCAN_FILTER, persBean, false);
      setStoreValue(dscanPP, DSCAN_ADDSIZE, persBean, false);
      // setStoreValue( dscanPP, DSCAN_ADDLATEST, persBean, false);
      // setStoreValue( dscanPP, DSCAN_TC_MATCH, persBean, false);
      // setStoreValue( dscanPP, DSCAN_TC_SUBS, persBean, false);
      // setStoreValue( dscanPP, DSCAN_TC_DURATOPN, persBean, false);
    }

    dataset.finish();
  }
示例#7
0
  public boolean setDataset(InvDatasetImpl ds) {
    if (!accept()) return false;

    this.dataset = ds;
    this.leafDataset = null;
    exampleButton.setText("Example Dataset");

    //////////
    PersistentBean persBean = new PersistentBean(ds);

    setEditValue(NAME, persBean, 0);
    setEditValue(ID, persBean, 0);

    setEditValueWithInheritence(AUTHORITY, persBean);
    setEditValueWithInheritence(SERVICE_NAME, persBean);

    setEditValueWithInheritence(FORMAT_TYPE, persBean);
    setEditValueWithInheritence(DATA_TYPE, persBean);

    setEditValue(COLLECTION_TYPE, persBean, 0);
    setEditValue(HARVEST, persBean, 0);

    // gotta find which GeospatialCoverage to use.
    int mode = 0;
    ThreddsMetadata.GeospatialCoverage gc = ds.getLocalMetadata().getGeospatialCoverage();
    if ((gc == null) || gc.isEmpty()) {
      gc = ds.getLocalMetadataInheritable().getGeospatialCoverage();
      mode = 1;
    }
    if ((gc == null) || gc.isEmpty()) {
      gc = ds.getGeospatialCoverage();
      mode = 2; // inherited
    }
    metadataPP.setFieldValue(GC_TYPE, inherit_types.get(mode));
    setGC(gc, mode);

    // gotta find which TimeCoverage to use.
    mode = 0;
    CalendarDateRange tc = ds.getLocalMetadata().getCalendarDateCoverage();
    if (tc == null) {
      tc = ds.getLocalMetadataInheritable().getCalendarDateCoverage();
      mode = 1;
    }
    if (tc == null) {
      tc = ds.getCalendarDateCoverage();
      mode = 2; // inherited
    }
    metadataPP.setFieldValue(TC_TYPE, inherit_types.get(mode));
    if (tc != null) dateRangeSelector.setDateRange(tc.toDateRange());
    setTCmode(mode);

    setEditValueWithInheritence(SUMMARY, persBean);
    setEditValueWithInheritence(RIGHTS, persBean);
    setEditValueWithInheritence(HISTORY, persBean);
    setEditValueWithInheritence(PROCESSING, persBean);

    setVariables(variablesFld);
    setBeanList(creatorsFld, CREATORS, persBean);
    setBeanList(publishersFld, PUBLISHERS, persBean);
    setBeanList(projectsFld, PROJECTS, persBean);
    setBeanList(keywordsFld, KEYWORDS, persBean);
    setBeanList(datesFld, DATES, persBean);
    setBeanList(contributorsFld, CONTRIBUTORS, persBean);
    setBeanList(docsFld, DOCUMENTATION, persBean);

    if (ds instanceof InvDatasetScan) {
      dscanPP.setEnabled(true);
      setEditValue(dscanPP, DSCAN_PATH, persBean, 0);
      setEditValue(dscanPP, DSCAN_DIR, persBean, 0);
      // setEditValue( dscanPP, DSCAN_FILTER, persBean, 0);
      setEditValue(dscanPP, DSCAN_ADDSIZE, persBean, 0);
      // setEditValue( dscanPP, DSCAN_ADDLATEST, persBean, 0);
      // setEditValue( dscanPP, DSCAN_TC_MATCH, persBean, 0);
      // setEditValue( dscanPP, DSCAN_TC_SUBS, persBean, 0);
      // setEditValue( dscanPP, DSCAN_TC_DURATOPN, persBean, 0);
    } else dscanPP.setEnabled(false);

    return true;
  }