/** * Finish constructing after all elements have been added or modified. * This routine will do any needed internal consistency work. * Its ok to call multiple times. * * @return true if successful. */ public boolean finish() { // make topDataset if needed //if (topDataset == null) { if (datasets.size() == 1) { // already only one; make it top topDataset = (InvDatasetImpl) datasets.get(0); } else { // create one topDataset = new InvDatasetImpl(null, name == null ? "Top Dataset" : name); for (InvDataset dataset : datasets) topDataset.addDataset((InvDatasetImpl) dataset); topDataset.setServicesLocal(services); } //} topDataset.setCatalog(this); // build dataset hash table dsHash = new HashMap<String, InvDataset>(); addDatasetIds(topDataset); // recurse through the datasets and finish them return topDataset.finish(); }
public void addAccess(thredds.catalog.InvAccess p0) { proxy.addAccess( p0); }
/** * Transfer all inheritable metadata from fromDs to the local metadata of this dataset. * Called by InvDatasetScan to transfer inheritable metaddata to the nested catalogRef * * @param fromDs transfer from here */ public void transferMetadata(InvDatasetImpl fromDs, boolean copyInheritedMetadataFromParents) { if (fromDs == null) return; logger.debug(" transferMetadata= " + fromDs.getName()); if (this != fromDs) getLocalMetadata().add(fromDs.getLocalMetadata(), false); transferInheritableMetadata(fromDs, getLocalMetadataInheritable(), copyInheritedMetadataFromParents); setResourceControl(fromDs.getRestrictAccess()); }
/** * copy constructor * * @param from copy from here */ public InvDatasetImpl(InvDatasetImpl from) { super(from.getParent(), from.getName()); // steal everything this.tm = new ThreddsMetadata(from.getLocalMetadata()); this.tmi = new ThreddsMetadata(from.getLocalMetadataInheritable()); this.accessLocal = new ArrayList<InvAccess>(from.getAccessLocal()); this.servicesLocal = new ArrayList<InvService>(from.getServicesLocal()); this.harvest = from.harvest; this.collectionType = from.collectionType; }
/** * test */ public static void main(String[] args) { InvDatasetImpl topDs = new InvDatasetImpl(null, "topDs", FeatureType.valueOf("GRID"), "myService", "myUrlPath/"); InvService myS = new InvService("myService", ServiceType.DODS.toString(), "http://thredds.ucar.edu/cgi-bin/dods/nph-dods", "", null); topDs.addService(myS); topDs.getLocalMetadata().setServiceName("myService"); InvDatasetImpl childDs = new InvDatasetImpl(null, "childDs", null, null, "myUrlPath/"); topDs.addDataset(childDs); InvService ts = childDs.findService("myService"); System.out.println("InvDatasetImpl.main(): " + childDs.getAccess(ServiceType.DODS).toString()); }
dataset.setDataType(dataType); if (serviceName != null) dataset.setServiceName(serviceName); if (urlPath != null) dataset.setUrlPath(urlPath); if (authority != null) dataset.setAuthority(authority); if (id != null) dataset.setID(id); if (harvest != null) dataset.setHarvest(harvest.equalsIgnoreCase("true")); if (restrictAccess != null) dataset.setResourceControl(restrictAccess); dataset.setCollectionType(collectionType); for (Element curElem : serviceList) { InvService s = readService(curElem, base); dataset.addService(s); ThreddsMetadata tmg = dataset.getLocalMetadata(); readThreddsMetadata(catalog, dataset, dsElem, tmg); for (Element e : aList) { InvAccessImpl a = readAccess(dataset, e); dataset.addAccess(a); if (ncmlElem != null) { ncmlElem.detach(); dataset.setNcmlElement(ncmlElem);
private InvCatalogImpl makeCatalogRuns(URI catURI, State localState) throws IOException { InvCatalogImpl parent = (InvCatalogImpl) getParentCatalog(); //URI myURI = baseURI.resolve(getCatalogHref(RUNS)); InvCatalogImpl runCatalog = new InvCatalogImpl(getFullName(), parent.getVersion(), catURI); InvDatasetImpl top = new InvDatasetImpl(this); top.setParent(null); top.transferMetadata((InvDatasetImpl) this.getParent(), true); // make all inherited metadata local top.setName(RUN_TITLE); // add Variables, GeospatialCoverage, TimeCoverage ThreddsMetadata tmi = top.getLocalMetadataInheritable(); if (localState.vars != null) tmi.addVariables(localState.vars); if (localState.coverage != null) tmi.setGeospatialCoverage(localState.coverage); //if (localState.dateRange != null) tmi.setTimeCoverage(localState.dateRange); runCatalog.addDataset(top); // services need to be local runCatalog.addService(virtualService); top.getLocalMetadataInheritable().setServiceName(virtualService.getName()); for (InvDatasetImpl ds : makeRunDatasets()) top.addDataset(ds); runCatalog.finish(); return runCatalog; }
boolean ok = true; java.util.Iterator iter; if (debugInherit) System.out.println("Now finish " + getName() + " id= " + getID()); variables = new ArrayList<>(); canonicalize(); // canonicalize thredds metadata transfer2PublicMetadata(tm, true); // add local metadata transfer2PublicMetadata(tmi, true); // add local inherited metadata transferInheritable2PublicMetadata((InvDatasetImpl) getParent()); // add inheritable metadata from parents if ((urlPath != null) && (getServiceDefault() != null)) { InvAccessImpl a = new InvAccessImpl(this, urlPath, getServiceDefault()); a.setSize(size); a.finish(); addExpandedAccess(a); InvAccessImpl a = (InvAccessImpl) iter.next(); a.finish(); addExpandedAccess(a); for (InvDataset invDataset : this.getDatasets()) { InvDatasetImpl curDs = (InvDatasetImpl) invDataset; ok &= curDs.finish();
resultDs = new InvCatalogRef( null, catRef.getName(), catRef.getXlinkHref()); } else { resultDs = new InvDatasetImpl( null, dataset.getName() ); resultDs.setID( dataset.getID() ); resultDs.transferMetadata( (InvDatasetImpl) dataset, copyInheritedMetadataFromParents ); String urlPath = ( (InvDatasetImpl) dataset ).getUrlPath(); if ( urlPath != null ) resultDs.setUrlPath( urlPath ); else if ( access != null ) resultDs.addAccess( access ); curDsCopy.setParent( resultDs ); resultDs.addDataset( curDsCopy );
private List<InvDatasetImpl> makeOffsetDatasets() throws IOException { makeFmrc(); List<InvDatasetImpl> datasets = new ArrayList<InvDatasetImpl>(); String id = getID(); if (id == null) id = getPath(); for (Double offset : fmrc.getForecastOffsets()) { String name = getName()+"_"+OFFSET_NAME+offset+"hr"; name = StringUtil2.replace(name, ' ', "_"); InvDatasetImpl nested = new InvDatasetImpl(this, name); nested.setUrlPath(path+"/"+OFFSET+"/"+name); nested.setID(id+"/"+OFFSET+"/"+name); ThreddsMetadata tm = nested.getLocalMetadata(); tm.addDocumentation("summary", "Data from the "+offset+" hour forecasts, across different model runs."); datasets.add( nested); } return datasets; }
private void addTopLevelMetadata( InvCatalog catalog, boolean isRegularCatalog ) { if ( this.topLevelMetadataContainer == null ) return; if ( ! catalogLevel.getPath().equals( currentLevel.getPath() ) ) return; // Transfer all metadata from given metadata container to the top // InvDataset. This propagates any public metadata from the given // metadata container to all generated catalogs. InvDatasetImpl topInvDs = (InvDatasetImpl) catalog.getDataset(); topInvDs.transferMetadata( this.topLevelMetadataContainer, true ); // LOOK experimental datasetScan may have its own access elements for ( Iterator it = this.topLevelMetadataContainer.getAccess().iterator(); it.hasNext(); ) { InvAccess invAccess = (InvAccess) it.next(); topInvDs.addAccess( invAccess ); InvService s = invAccess.getService(); ( (InvCatalogImpl) catalog ).addService( s ); } // If this is a collection level scan, set some special attributes // that transferMetadata() doesn't transfer. boolean isCollectionLevel = catalogLevel.getPath().equals( collectionLevel.getPath() ); if ( isCollectionLevel && isRegularCatalog ) { topInvDs.setHarvest( this.topLevelMetadataContainer.isHarvest() ); topInvDs.setCollectionType( this.topLevelMetadataContainer.getCollectionType() ); } // Finish catalog. ( (InvCatalogImpl) catalog ).finish(); }
if (cat.hasFatalError()) { proxy = new InvDatasetImpl(null, "ERROR OPENING"); StringBuilder out = new StringBuilder(); cat.check(out); if (debug) System.out.println("PARSE ERROR =\n " + out.toString()); proxy.addProperty(new InvProperty("ERROR OPENING", out.toString())); proxy.finish(); if (proxy.getMark()) { proxy.setName(proxy.getName() + " (EMPTY)"); proxy.addProperty(new InvProperty("isEmpty", "true")); proxy.finish(); String proxyName = proxy.getName().trim();
private InvDataset createDataset(InvCatalog catalog, String datasetName, final String serviceName) { final InvDatasetImpl dapDataset = new InvDatasetImpl(null, datasetName, FeatureType.NONE, serviceName, "http://wherever.you.want.bc"); dapDataset.setCatalog(catalog); final InvService dapService = new InvService(serviceName, serviceName, "irrelevant", "irrelevant", "irrelevant"); dapDataset.addAccess(new InvAccessImpl(dapDataset, "http://y.z", dapService)); dapDataset.finish(); return dapDataset; }
/** * Munge this catalog so the given dataset is the top catalog. * * @param ds make this top; must be existing dataset in this catalog. * * @deprecated in favor of thredds.catalog.util.DeepCopyUtils.subsetCatalogOnDataset */ public void subset(InvDataset ds) { InvDatasetImpl dataset = (InvDatasetImpl) ds; // Make all inherited metadata local. dataset.transferMetadata(dataset, true); topDataset = dataset; datasets.clear(); // throw away the rest datasets.add(topDataset); // parent lookups need to be local //InvService service = dataset.getServiceDefault(); //if (service != null) LOOK // dataset.serviceName = service.getName(); dataset.dataType = dataset.getDataType(); // all properties need to be local // LOOK dataset.setPropertiesLocal( new ArrayList(dataset.getProperties())); // next part requires this before it dataset.setCatalog(this); dataset.parent = null; // any referenced services need to be local List<InvService> services = new ArrayList<InvService>(dataset.getServicesLocal()); findServices(services, dataset); dataset.setServicesLocal(services); finish(); }
private synchronized void read() { if (init) return; URI uriResolved = getURI(); if (uriResolved == null) { // this is to display an error message proxy = new InvDatasetImpl(null, "HREF ERROR"); proxy.addProperty(new InvProperty("HREF ERROR", errMessage)); datasets.add(proxy); init = true; return; } // open and read the referenced catalog XML try { if (debug) System.out.println(" InvCatalogRef read " + getFullName() + " hrefResolved = " + uriResolved); InvCatalogFactory factory = InvCatalogFactory.getDefaultFactory(true); // InvCatalogFactory factory = ((InvCatalogImpl) getParentCatalog()).getCatalogFactory(); InvCatalogImpl cat = factory.readXML(uriResolved.toString()); finishCatalog(cat); } catch (Exception e) { // this is to display an error message proxy = new InvDatasetImpl(null, "HREF ERROR"); if (debug) System.out.println("HREF ERROR =\n " + href + " err= " + e.getMessage()); proxy.addProperty(new InvProperty("HREF ERROR", href)); datasets.add(proxy); init = true; } }
protected InvDatasetImpl readDataset( InvCatalogImpl catalog, InvDatasetImpl parent, Element dsElem, URI base) { // deal with aliases String name = dsElem.getAttributeValue("name"); String alias = dsElem.getAttributeValue("alias"); if (alias != null) { InvDatasetImpl ds = (InvDatasetImpl) catalog.findDatasetByID( alias); if (ds == null) factory.appendErr(" ** Parse error: dataset named "+name+" has illegal alias = "+alias+"\n"); return new InvDatasetImplProxy(name, ds); } InvDatasetImpl dataset = new InvDatasetImpl( parent, name); readDatasetInfo( catalog, dataset, dsElem, base); if (InvCatalogFactory.debugXML) System.out.println (" Dataset added: "+ dataset.dump()); return dataset; }
/** * Construct an InvDatasetImpl which refers to a urlPath. * This is used to create a standalone InvDatasetImpl, outside of an InvCatalog. * An "anonymous" InvServerImpl is created and attached to the InvDataset. * * @param urlPath : construct URL from this path * @param dataType : data type * @param stype : ServiceType */ public InvDatasetImpl(String urlPath, FeatureType dataType, ServiceType stype) { super(null, "local file"); tm.setDataType(dataType); tm.setServiceName("anon"); this.urlPath = urlPath; // create anonymous service addService(new InvService(tm.getServiceName(), stype.toString(), "", "", null)); finish(); }
/** * Replace the given dataset if it is a nested dataset. * * @param remove - the dataset element to be removed * @param add - the dataset element to be added * @return true on success */ public boolean replaceDataset(InvDatasetImpl remove, InvDatasetImpl add) { if (topDataset.equals(remove)) { topDataset = add; topDataset.setCatalog(this); } for (int i = 0; i < datasets.size(); i++) { InvDataset dataset = datasets.get(i); if (dataset.equals(remove)) { datasets.set(i, add); removeDatasetByID(remove); addDatasetByID(add); return true; } } return false; }
public boolean addMetadata( InvDataset dataset) { // <dataset name="2005061512_NAM.wmo" urlPath="2005061512_NAM.wmo"/> java.util.regex.Matcher matcher = this.pattern.matcher( dataset.getName() ); if ( ! matcher.find()) return( false); // Pattern not found. StringBuffer startTime = new StringBuffer(); matcher.appendReplacement( startTime, this.substitutionPattern ); startTime.delete( 0, matcher.start() ); try { ((InvDatasetImpl) dataset).setTimeCoverage( new DateRange( new DateType( startTime.toString(), null, null), null, new TimeDuration( this.duration ), null ) ); } catch ( ParseException e ) { logger.debug( "Start time <" + startTime.toString() + "> or duration <" + this.duration + "> not parsable: " + e.getMessage()); return( false); } ( (InvDatasetImpl) dataset ).finish(); return ( true ); } }
public thredds.catalog.ThreddsMetadata getLocalMetadata() { return proxy.getLocalMetadata(); }