All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.oodt.cas.filemgr.versioning.MetadataBasedFileVersioner Maven / Gradle / Ivy

Go to download

The file management component of a Catalog and Archive Service. This component purposefully separates data stores and metadata stores as standard interfaces, and provides some out of the box backend implementations of them (including one based on the javax.sql.DataSource interface). This component provides everything that you need to catalog, archive and manage files, and directories, and their associated metadata.

There is a newer version: 1.9.1
Show newest version
/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.apache.oodt.cas.filemgr.versioning;

//JDK imports
import java.io.File;
import java.util.logging.Level;
import java.util.logging.Logger;

//OODT imports
import org.apache.oodt.cas.filemgr.structs.Product;
import org.apache.oodt.cas.filemgr.structs.Reference;
import org.apache.oodt.cas.filemgr.structs.exceptions.VersioningException;
import org.apache.oodt.cas.metadata.util.PathUtils;
import org.apache.oodt.cas.metadata.Metadata;

/**
 * @author mattmann
 * @version $Revision$
 * 
 * 

* A Versioner class that uses {@link Metadata} fields and a given * filePathSpec to version references. The filePathSpec should be * of the form:
*
* * /[FieldName1]/other/text/.../[FieldName2]... * * where FieldName1 and FieldName2 are Metadata * fields provided by the given Metadata object. *

. */ public class MetadataBasedFileVersioner implements Versioner { /* file path spec denoted by metadata fields and static path */ private String filePathSpec = null; /* our log stream */ private static final Logger LOG = Logger .getLogger(MetadataBasedFileVersioner.class.getName()); /* whether or not we only handle flat products */ private boolean flatProducts = true; public MetadataBasedFileVersioner() { filePathSpec = "/[Filename]"; } public MetadataBasedFileVersioner(String filePathSpec) { this.filePathSpec = filePathSpec; } /* * (non-Javadoc) * * @see org.apache.oodt.cas.filemgr.versioning.Versioner#createDataStoreReferences(gov.nasa. * jpl.oodt.cas.filemgr.structs.Product, * org.apache.oodt.cas.metadata.Metadata) */ public void createDataStoreReferences(Product product, Metadata metadata) throws VersioningException { // since we need the metadata, if the metadata is null, throw an // exception if (metadata == null) { throw new VersioningException( "Unable to version product with no metadata!"); } // we also only deal with Flat products, that is, Products with a single // reference if (flatProducts && !product.getProductStructure() .equals(Product.STRUCTURE_FLAT)) { throw new VersioningException( "Can only handle FLAT product structures"); } // get the product type repo path String productTypeRepoPath = VersioningUtils .getAbsolutePathFromUri(product.getProductType() .getProductRepositoryPath()); // parse the file path spec String filePathRef = parseFilePathSpec(filePathSpec, productTypeRepoPath, metadata); String filePathUri = new File(filePathRef).toURI().toString(); Reference r = (Reference) product.getProductReferences().get(0); LOG.log(Level.INFO, "Generated data store ref: [" + filePathUri + "] from origRef: [" + r.getOrigReference() + "]"); r.setDataStoreReference(filePathUri); } private String parseFilePathSpec(String filePathSpec, String productTypeRepoPath, Metadata metadata) { StringBuffer finalFilePath = new StringBuffer(); finalFilePath.append(productTypeRepoPath); if (finalFilePath.charAt(finalFilePath.length() - 1) == '/') { finalFilePath.deleteCharAt(finalFilePath.length() - 1); } if (!filePathSpec.startsWith("/")) { filePathSpec = "/" + filePathSpec; } finalFilePath.append(PathUtils.replaceEnvVariables(filePathSpec, metadata)); return finalFilePath.toString(); } /** * @return the filePathSpec */ public String getFilePathSpec() { return filePathSpec; } /** * @param filePathSpec * the filePathSpec to set */ public void setFilePathSpec(String filePathSpec) { this.filePathSpec = filePathSpec; } /** * @return the flatProducts */ public boolean isFlatProducts() { return flatProducts; } /** * @param flatProducts * the flatProducts to set */ public void setFlatProducts(boolean flatProducts) { this.flatProducts = flatProducts; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy