private boolean filter( InvDataset d) { if (serviceType == null) return true; return d.getAccess( serviceType) != null; }
private void recursivelyRemoveEmptyCollectionDatasets( InvDataset parentDataset) { InvDataset curDs = null; for ( Iterator it = parentDataset.getDatasets().iterator(); it.hasNext(); ) { curDs = (InvDataset) it.next(); // Do not remove accessible dataset. if ( curDs.hasAccess()) continue; // Do not remove catalogRef datasets. if ( curDs instanceof InvCatalogRef) continue; // Recurse into collection datasets children. if ( curDs.hasNestedDatasets()) { this.recursivelyRemoveEmptyCollectionDatasets( curDs); } // Remove any empty collection datasets. else { it.remove(); } } }
public boolean addMetadata( InvDataset dataset ) { InvDataset parentDs = dataset.getParent(); String curId = ( parentDs == null) ? this.baseId : parentDs.getID(); if ( curId == null) curId = this.baseId; if ( dataset.getName() != null && ! dataset.getName().equals( "") ) curId += "/" + dataset.getName(); ( (InvDatasetImpl) dataset).setID( curId ); return ( true ); } }
/** * If this dataset has an authority and an ID, then the concatenation of them is the * globally unique ID. * * @return globally unique ID, or null if missing authority or ID. */ public String getUniqueID() { String authority = getAuthority(); if ((authority != null) && (getID() != null)) return authority + ":" + getID(); else if (getID() != null) return getID(); else return null; }
/** * Return the query fragment referencing this dataset, ie "catalog=catalog.xml&dataset=datasetID" * * @return the query fragment for this dataset */ public String getSubsetUrl() { if (getID() == null) return null; return "catalog=" + getParentCatalog().baseURI.toString() + "&dataset=" + getID(); }
/** * Find an immediate child dataset by its name. * * @param name match on this name * @return dataset if found or null if not exist. */ public InvDatasetImpl findDatasetByName(String name) { for (InvDataset ds : getDatasets()) { if (ds.getName().equals(name)) return (InvDatasetImpl) ds; } return null; }
private void writeDataset(InvDataset ds, Element rootElem, StringBuffer mess) { String entryId = StringUtil2.allow(ds.getUniqueID(), "_-.", '-'); rootElem.addContent( new Element("Entry_ID", defNS).addContent(entryId)); rootElem.addContent( new Element("Entry_Title", defNS).addContent(ds.getFullName())); ThreddsMetadata.Variables vs = ds.getVariables("DIF"); boolean hasVocab = (vs != null) && (vs.getVariableList().size() != 0); if (hasVocab) { vs = ds.getVariables("GRIB-1"); if ((vs != null) && (vs.getVariableList().size() != 0)) { Iterator iter = translateGribVocabulary(vs, true, mess); vs = ds.getVariables("GRIB-2"); if ((vs != null) && (vs.getVariableList().size() != 0)) { Iterator iter = translateGribVocabulary(vs, false, mess); List list = ds.getKeywords(); if (list.size() > 0) { for (int i=0; i<list.size(); i++) { DateRange tm = ds.getTimeCoverage(); if (tm != null) { DateType end = tm.getEnd(); ThreddsMetadata.GeospatialCoverage geo = ds.getGeospatialCoverage(); if (geo != null) { Element geoElem = new Element("Spatial_Coverage", defNS); String rights = ds.getDocumentation("rights");
generalElem.addContent( new Element("title", defNS).addContent("Dataset "+ds.getFullName())); generalElem.addContent( new Element("description", defNS).addContent(ds.getDocumentation("summary"))); generalElem.addContent( new Element("language", defNS).addContent("en")); List list = ds.getKeywords(); if (list.size() > 0) { Element keywords = new Element("keywords", defNS); if ((ds.getPublishers().size() > 0) || (ds.getCreators().size() > 0)){ Element contributors = new Element("contributors", defNS); lifeElem.addContent( contributors); list = ds.getPublishers(); for (int i=0; i<list.size(); i++) { ThreddsMetadata.Source p = (ThreddsMetadata.Source) list.get(i); list = ds.getCreators(); for (int i=0; i<list.size(); i++) { ThreddsMetadata.Source p = (ThreddsMetadata.Source) list.get(i); String id = StringUtil2.allow(ds.getUniqueID(), ".", '-'); entry.setAttribute("entry", id); entry.addContent("THREDDS"); InvCatalogImpl cat = (InvCatalogImpl) ds.getParentCatalog(); String catURL = cat.getBaseURI().toString(); int pos = catURL.lastIndexOf('.'); String catURLh = catURL.substring(0,pos)+".html"; href = catURLh+"?dataset="+ds.getID();
rootElem.addContent( new Element("title", defNS).addContent(ds.getName())); rootElem.addContent( new Element("Entry_ID", defNS).addContent(ds.getUniqueID())); List list = ds.getKeywords(); if (list.size() > 0) { for (int i=0; i<list.size(); i++) { CalendarDateRange tm = ds.getCalendarDateCoverage(); Element tmElem = new Element("Temporal_Coverage", defNS); rootElem.addContent( tmElem); ThreddsMetadata.GeospatialCoverage geo = ds.getGeospatialCoverage(); Element geoElem = new Element("Spatial_Coverage", defNS); rootElem.addContent( geoElem); rootElem.addContent( new Element("Use_Constraints", defNS).addContent(ds.getDocumentation("rights"))); list = ds.getPublishers(); if (list.size() > 0) { for (int i=0; i<list.size(); i++) { rootElem.addContent( new Element("Summary", defNS).addContent(ds.getDocumentation("summary"))); "?catalog="+((InvCatalogImpl)ds.getParentCatalog()).getBaseURI().toString() + "&dataset="+ds.getID(); primaryURLelem.addContent( new Element("URL_Content_Type", defNS).addContent("THREDDS access page")); primaryURLelem.addContent( new Element("URL", defNS).addContent(primaryURL));
private void printInvDatasets(final List<InvDataset> invDatasets) { for (InvDataset datasetNode : invDatasets) { System.out.println("-----------------------------------------------------------------------"); System.out.println("datasetNode.getID() = " + datasetNode.getID()); if (datasetNode instanceof InvCatalogRef) { final InvCatalogRef catalogRef = (InvCatalogRef) datasetNode; System.out.println(" ds.hasAccess() = " + ds.hasAccess()); List<InvAccess> dsAccesses = ds.getAccess(); for (InvAccess dsAccess : dsAccesses) { InvService dsAccessService = dsAccess.getService(); System.out.println("datasetNode.getIdAuthority() = " + datasetNode.getAuthority()); List<InvMetadata> metadatas = datasetNode.getMetadata(); for (InvMetadata metadata : metadatas) { System.out.println(" metadata.getContent() = " + metadata.getContentObject()); List<InvProperty> properties = datasetNode.getProperties(); for (InvProperty property : properties) { System.out.println(" property.getName() = " + property.getName()); System.out.println(" property.getValue() = " + property.getValue()); printInvDatasets(datasetNode.getDatasets());
InvCatalogRef catref = (InvCatalogRef) ds; if (out != null) out.println(" **CATREF " + catref.getURI() + " (" + ds.getName() + ") "); countCatrefs++; List<InvDataset> dlist = ds.getDatasets(); List<InvDataset> leaves = new ArrayList<InvDataset>(); for (InvDataset dds : dlist) { if (dds.hasAccess()) leaves.add(dds); if (dds.hasNestedDatasets()) crawlDirectDatasets(dds, task, out, context, release); if ((task != null) && task.isCancel())
void findServices(List<InvService> result, InvDataset ds) { if (ds instanceof InvCatalogRef) return; // look for access elements with unresolved services for (InvAccess a : ds.getAccess()) { InvService s = a.getService(); InvDataset d = a.getDataset(); if (null == d.findService(s.getName()) && !(result.contains(s))) result.add(s); } // recurse into nested datasets for (InvDataset nested : ds.getDatasets()) { findServices(result, nested); } }
ncDataset.setTitle(ds.getName()); ncDataset.setId(ds.getID()); for (InvProperty p : ds.getProperties()) { String name = p.getName(); if (null == ncDataset.findGlobalAttribute(name)) {
private NetcdfDataset openDataset(InvAccess access, boolean acquire, ucar.nc2.util.CancelTask task, Result result) throws IOException { InvDataset invDataset = access.getDataset(); String datasetId = invDataset.getID(); String title = invDataset.getName(); List list = invDataset.getMetadata(MetadataType.NcML); if (list.size() > 0) { InvMetadata ncmlMetadata = (InvMetadata) list.get(0);
private void doOneDataset( InvDataset ds) { if (!ds.isHarvest()) { messBuffer.append( " Dataset "+ ds.getName()+ " id = "+ds.getID()+" has harvest = false\n"); } else if (isDatasetUseable( ds, messBuffer)) { String id = StringUtil2.replace(ds.getID(), "/", "-"); String fileOutName = fileDir+"/"+id+".adn.xml"; try { OutputStream out = new BufferedOutputStream(new FileOutputStream( fileOutName)); writeOneItem(ds, out); out.close(); messBuffer.append(" OK on Write\n"); } catch (IOException ioe) { messBuffer.append("FAILED on Write "+ioe.getMessage()+"\n"); ioe.printStackTrace(); } } }
private void doDataset( InvDataset ds, String fileDir) { if (ds.isHarvest() && (ds.getID() != null)) { String fileOutName = fileDir+"/"+ds.getID()+".dc.xml"; try ( OutputStream out = new BufferedOutputStream(new FileOutputStream(fileOutName))) { writeOneItem(ds, System.out); writeOneItem(ds, out); return; } catch (IOException ioe) { ioe.printStackTrace(); } } for (InvDataset nested : ds.getDatasets()) { doDataset( nested, fileDir); } }
private InvDatasetImpl openResolver(String urlString, ucar.nc2.util.CancelTask task, Result result) { InvCatalogFactory catFactory = new InvCatalogFactory("", false); InvCatalogImpl catalog = catFactory.readXML(urlString); if (catalog == null) { result.errLog.format("Couldnt open Resolver %s %n ", urlString); return null; } StringBuilder buff = new StringBuilder(); if (!catalog.check(buff)) { result.errLog.format("Invalid catalog from Resolver <%s>%n%s%n", urlString, buff.toString()); result.fatalError = true; return null; } InvDataset top = catalog.getDataset(); if (top.hasAccess()) return (InvDatasetImpl) top; else { java.util.List datasets = top.getDatasets(); return (InvDatasetImpl) datasets.get(0); } }
void appendToNode(final JTree jTree, List<InvDataset> datasets, MutableTreeNode parentNode, boolean goDeeper) { for (InvDataset dataset : datasets) { final MutableTreeNode deeperParent; if (!goDeeper || !CatalogTreeUtils.isHyraxId(dataset.getID())) { appendToNode(jTree, dataset, parentNode); if (parentNode.getChildCount() == 0) { continue; } deeperParent = (MutableTreeNode) parentNode.getChildAt(parentNode.getChildCount() - 1); } else { deeperParent = parentNode; } if (goDeeper && !(dataset instanceof InvCatalogRef)) { appendToNode(jTree, dataset.getDatasets(), deeperParent, false); } } }
@Override public void getDataset(InvDataset ds, Object context) { if (ds.hasAccess()) { ThreddsDataFactory tdataFactory = new ThreddsDataFactory(); InvAccess access = tdataFactory.chooseDatasetAccess(ds.getAccess()); if (access == null) throw new IllegalStateException(); MFileRemote mfile = new MFileRemote(access); if (mfile.getPath().endsWith(".xml")) return; // eliminate latest.xml LOOK kludge-o-rama mfiles.add(mfile); if (debug) System.out.format("add %s %n", mfile.getPath()); } }