You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@oodt.apache.org by bf...@apache.org on 2010/12/23 03:48:11 UTC
svn commit: r1052148 [5/17] - in /oodt/branches/wengine-branch/filemgr: ./
.settings/ src/ src/main/ src/main/assembly/ src/main/bin/ src/main/java/
src/main/java/gov/ src/main/java/gov/nasa/ src/main/java/gov/nasa/jpl/
src/main/java/gov/nasa/jpl/oodt/...
Added: oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/catalog/catalogservice/CatalogBuilder.java
URL: http://svn.apache.org/viewvc/oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/catalog/catalogservice/CatalogBuilder.java?rev=1052148&view=auto
==============================================================================
--- oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/catalog/catalogservice/CatalogBuilder.java (added)
+++ oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/catalog/catalogservice/CatalogBuilder.java Thu Dec 23 02:48:02 2010
@@ -0,0 +1,148 @@
+/*
+ * 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.catalog.catalogservice;
+
+//JDK imports
+import java.io.FileInputStream;
+import java.util.List;
+import java.util.Vector;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+//Spring imports
+import org.springframework.beans.factory.annotation.Required;
+
+//OODT imports
+import org.apache.oodt.cas.catalog.struct.Dictionary;
+import org.apache.oodt.cas.filemgr.catalog.CatalogFactory;
+import org.apache.oodt.cas.filemgr.repository.RepositoryManager;
+import org.apache.oodt.cas.filemgr.structs.ProductType;
+import org.apache.oodt.cas.filemgr.structs.exceptions.RepositoryManagerException;
+import org.apache.oodt.cas.filemgr.util.GenericFileManagerObjectFactory;
+import org.apache.oodt.cas.filemgr.validation.ValidationLayer;
+
+/**
+ *
+ * @author bfoster
+ *
+ */
+public class CatalogBuilder {
+
+ private static final Logger LOG = Logger.getLogger(CatalogBuilder.class.getName());
+
+ protected String catalogId;
+ protected CatalogFactory fmCatalogFactory;
+ protected List<String> supportedProductTypeIds;
+ protected String transactionIdFactory;
+ protected boolean restrictIngestPermissions;
+ protected boolean restrictQueryPermissions;
+ protected String filemgrPropertiesFile;
+
+ public CatalogBuilder() {}
+
+ public String getCatalogId() {
+ return this.catalogId;
+ }
+
+ public void setCatalogId(String catalogId) {
+ this.catalogId = catalogId;
+ }
+
+ public String getTransactionIdFactory() {
+ return transactionIdFactory;
+ }
+
+ @Required
+ public void setTransactionIdFactory(
+ String transactionIdFactory) {
+ this.transactionIdFactory = transactionIdFactory;
+ }
+
+ public String getFilemgrPropertiesFile() {
+ return this.filemgrPropertiesFile;
+ }
+
+ public void setFilemgrPropertiesFile(String filemgrPropertiesFile) {
+ this.filemgrPropertiesFile = filemgrPropertiesFile;
+ }
+
+ public CatalogFactory getFmCatalogFactory() {
+ return this.fmCatalogFactory;
+ }
+
+ @Required
+ public void setFmCatalogFactory(CatalogFactory fmCatalogFactory) {
+ this.fmCatalogFactory = fmCatalogFactory;
+ }
+
+ public List<String> getSupportedProductTypeIds() {
+ return this.supportedProductTypeIds;
+ }
+
+ @Required
+ public void setSupportedProductTypeIds(List<String> supportedProductTypeIds) {
+ this.supportedProductTypeIds = supportedProductTypeIds;
+ }
+
+ public boolean isRestrictIngestPermissions() {
+ return restrictIngestPermissions;
+ }
+
+ @Required
+ public void setRestrictIngestPermissions(boolean restrictIngestPermissions) {
+ this.restrictIngestPermissions = restrictIngestPermissions;
+ }
+
+ public boolean isRestrictQueryPermissions() {
+ return restrictQueryPermissions;
+ }
+
+ @Required
+ public void setRestrictQueryPermissions(boolean restrictQueryPermissions) {
+ this.restrictQueryPermissions = restrictQueryPermissions;
+ }
+
+ public org.apache.oodt.cas.catalog.system.Catalog createCatalog() {
+ try {
+ System.getProperties().load(new FileInputStream(this.filemgrPropertiesFile));
+ ValidationLayer validationLayer = GenericFileManagerObjectFactory.getValidationLayerFromFactory(System.getProperty("filemgr.validationLayer.factory"));
+ RepositoryManager repositoryManager = GenericFileManagerObjectFactory.getRepositoryManagerServiceFromFactory(System.getProperty("filemgr.repository.factory"));
+ List<Dictionary> dictionaries = new Vector<Dictionary>();
+ for (String productTypeId : this.supportedProductTypeIds) {
+ ProductDictionary productDictionary = new ProductDictionary();
+ ProductType type = repositoryManager.getProductTypeById(productTypeId);
+ if (type == null)
+ throw new RepositoryManagerException("ProductType '" + productTypeId + "' does not exist");
+ productDictionary.setProductType(type, validationLayer.getElements(type));
+ dictionaries.add(productDictionary);
+ }
+ FilemgrCatalogIndex index = new FilemgrCatalogIndex();
+ this.fmCatalogFactory.setValidationLayer(validationLayer);
+ index.setFmCatalogFactory(this.fmCatalogFactory);
+ List<ProductType> supportedProductTypes = new Vector<ProductType>();
+ for (String productTypeId : this.supportedProductTypeIds)
+ supportedProductTypes.add(repositoryManager.getProductTypeById(productTypeId));
+ index.setSupportedProductTypes(supportedProductTypes);
+ index.setTransactionIdFactory(this.transactionIdFactory);
+ return new org.apache.oodt.cas.catalog.system.Catalog(this.catalogId, index, dictionaries, this.restrictQueryPermissions, this.restrictIngestPermissions);
+ }catch (Exception e) {
+ LOG.log(Level.SEVERE, "Failed to create CatalogService Catalog : " + e.getMessage(), e);
+ return null;
+ }
+ }
+
+}
Added: oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/catalog/catalogservice/CatalogServiceMetKeys.java
URL: http://svn.apache.org/viewvc/oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/catalog/catalogservice/CatalogServiceMetKeys.java?rev=1052148&view=auto
==============================================================================
--- oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/catalog/catalogservice/CatalogServiceMetKeys.java (added)
+++ oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/catalog/catalogservice/CatalogServiceMetKeys.java Thu Dec 23 02:48:02 2010
@@ -0,0 +1,34 @@
+/*
+ * 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.catalog.catalogservice;
+
+/**
+ *
+ * @author bfoster
+ *
+ */
+public interface CatalogServiceMetKeys {
+
+ public static final String FILEMGR_CATALOGS_ONLY = "FilemgrCatalogsOnly";
+
+ public static final String PRODUCT_NAME_QUERY_EXPRESSION = "ProductNameQueryExpression";
+ public static final String PRODUCT_NAME_CUSTOM_KEY = "productName";
+
+ public static final String TOP_N_QUERY_EXPRESSION = "TopNQueryExpression";
+ public static final String N_CUSTOM_KEY = "n";
+
+}
Added: oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/catalog/catalogservice/CatalogServiceUtils.java
URL: http://svn.apache.org/viewvc/oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/catalog/catalogservice/CatalogServiceUtils.java?rev=1052148&view=auto
==============================================================================
--- oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/catalog/catalogservice/CatalogServiceUtils.java (added)
+++ oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/catalog/catalogservice/CatalogServiceUtils.java Thu Dec 23 02:48:02 2010
@@ -0,0 +1,417 @@
+/*
+ * 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.catalog.catalogservice;
+
+//OODT imports
+import org.apache.oodt.cas.catalog.exception.CatalogServiceException;
+import org.apache.oodt.cas.catalog.metadata.TransactionalMetadata;
+import org.apache.oodt.cas.catalog.page.CatalogReceipt;
+import org.apache.oodt.cas.catalog.page.Page;
+import org.apache.oodt.cas.catalog.page.QueryPager;
+import org.apache.oodt.cas.catalog.query.ComparisonQueryExpression;
+import org.apache.oodt.cas.catalog.query.CustomQueryExpression;
+import org.apache.oodt.cas.catalog.query.NotQueryExpression;
+import org.apache.oodt.cas.catalog.query.QueryExpression;
+import org.apache.oodt.cas.catalog.query.QueryLogicalGroup;
+import org.apache.oodt.cas.catalog.system.CatalogService;
+import org.apache.oodt.cas.catalog.term.Term;
+import org.apache.oodt.cas.catalog.term.TermBucket;
+import org.apache.oodt.cas.filemgr.metadata.CoreMetKeys;
+import org.apache.oodt.cas.filemgr.structs.BooleanQueryCriteria;
+import org.apache.oodt.cas.filemgr.structs.Element;
+import org.apache.oodt.cas.filemgr.structs.Product;
+import org.apache.oodt.cas.filemgr.structs.ProductPage;
+import org.apache.oodt.cas.filemgr.structs.ProductType;
+import org.apache.oodt.cas.filemgr.structs.QueryCriteria;
+import org.apache.oodt.cas.filemgr.structs.RangeQueryCriteria;
+import org.apache.oodt.cas.filemgr.structs.Reference;
+import org.apache.oodt.cas.filemgr.structs.TermQueryCriteria;
+import org.apache.oodt.cas.filemgr.structs.exceptions.QueryFormulationException;
+import org.apache.oodt.cas.filemgr.structs.mime.MimeType;
+import org.apache.oodt.cas.filemgr.structs.mime.MimeTypeException;
+import org.apache.oodt.cas.metadata.Metadata;
+
+//JDK imports
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.Vector;
+
+//APACHE imports
+import org.apache.commons.lang.StringUtils;
+
+/**
+ *
+ * @author bfoster
+ *
+ */
+public class CatalogServiceUtils {
+
+// public static QueryExpression getCatalogServiceQueryExpression(List<ProductType> productTypes) {
+// List<String> productTypeNames = new Vector<String>();
+// for (ProductType type : productTypes)
+// productTypeNames.add(type.getName());
+// return getCatalogServiceComparisonQueryExpression(CoreMetKeys.PRODUCT_TYPE, productTypeNames, ComparisonQueryExpression.Operator.EQUAL_TO, productTypes);
+// }
+
+ public static QueryExpression getMergedQueryExpression(QueryLogicalGroup.Operator operator, Set<String> productTypeNames, QueryExpression expression1, QueryExpression expression2, QueryExpression... otherExpressions) {
+ QueryLogicalGroup group = new QueryLogicalGroup();
+ group.setBucketNames(productTypeNames);
+ group.setOperator(operator);
+ group.addExpression(expression1);
+ group.addExpression(expression2);
+ group.addExpressions(Arrays.asList(otherExpressions));
+ return group;
+ }
+
+ public static ComparisonQueryExpression getCatalogServiceComparisonQueryExpression(String termName, List<String> values, ComparisonQueryExpression.Operator operator, Set<String> productTypeNames) {
+ ComparisonQueryExpression comparisonQueryExpression = new ComparisonQueryExpression();
+ comparisonQueryExpression.setBucketNames(productTypeNames);
+ comparisonQueryExpression.setTerm(new Term(termName, values));
+ comparisonQueryExpression.setOperator(operator);
+ return comparisonQueryExpression;
+ }
+
+ public static List<Product> asProducts(List<TransactionalMetadata> transactionalMetadataList, List<ProductType> supportedProductTypes) throws NumberFormatException, MimeTypeException {
+ List<Product> products = new Vector<Product>();
+ for (TransactionalMetadata transactionalMetadata : transactionalMetadataList)
+ products.add(asProduct(transactionalMetadata, supportedProductTypes));
+ return products;
+ }
+
+ public static Product asProduct(TransactionalMetadata transactionalMetadata, List<ProductType> supportedProductTypes) throws NumberFormatException, MimeTypeException {
+ HashSet<Term> terms = getProductTerms(transactionalMetadata.getMetadata());
+ terms.add(new Term(CatalogService.CATALOG_SERVICE_TRANSACTION_ID_MET_KEY, Collections.singletonList(transactionalMetadata.getTransactionId().toString())));
+ TermBucket termBucket = new TermBucket(transactionalMetadata.getMetadata().getMetadata(CoreMetKeys.PRODUCT_TYPE));
+ termBucket.addTerms(terms);
+ return asProduct(termBucket, supportedProductTypes);
+ }
+
+ public static Product asProduct(TermBucket termBucket, List<ProductType> supportedProductTypes) throws NumberFormatException, MimeTypeException {
+ String productId = safeReadTermValue(termBucket, CatalogService.CATALOG_SERVICE_TRANSACTION_ID_MET_KEY);
+ String productName = safeReadTermValue(termBucket, CoreMetKeys.PRODUCT_NAME);
+ String status = safeReadTermValue(termBucket, CoreMetKeys.PRODUCT_STATUS);
+ String structure = safeReadTermValue(termBucket, CoreMetKeys.PRODUCT_STRUCTURE);
+ ProductType productType = null;
+ for (ProductType type : supportedProductTypes)
+ if (type.getName().equals(termBucket.getName()))
+ productType = type;
+ List<String> origRefs = safeReadTermValues(termBucket, CoreMetKeys.PRODUCT_REFERENCE_ORIGINAL);
+ List<String> dataStoreRefs = safeReadTermValues(termBucket, CoreMetKeys.PRODUCT_REFERENCE_DATA_STORE);
+ List<String> refsFileSizes = safeReadTermValues(termBucket, CoreMetKeys.PRODUCT_REFERENCE_FILE_SIZE);
+ List<String> refsMimeTypes = safeReadTermValues(termBucket, CoreMetKeys.PRODUCT_REFERENCE_MIME_TYPE);
+ Vector<Reference> refs = new Vector<Reference>();
+ for (int i = 0; i < origRefs.size(); i++) {
+ String dataStoreRef = dataStoreRefs.size() > i ? dataStoreRefs.get(i) : null;
+ String refsFileSize = refsFileSizes.size() > i ? refsFileSizes.get(i) : null;
+ String refsMimeType = refsMimeTypes.size() > i ? refsMimeTypes.get(i) : null;
+ refs.add(new Reference(origRefs.get(i), dataStoreRef, Long.parseLong(refsFileSize), new MimeType(refsMimeType)));
+ }
+ if (termBucket.getTerms().contains(CoreMetKeys.PRODUCT_ROOT_REF_ORIG) ||
+ termBucket.getTerms().contains(CoreMetKeys.PRODUCT_ROOT_REF_DATA_STORE) ||
+ termBucket.getTerms().contains(CoreMetKeys.PRODUCT_ROOT_REF_FILE_SIZE) ||
+ termBucket.getTerms().contains(CoreMetKeys.PRODUCT_ROOT_REF_MIME_TYPE)) {
+ Reference rootRef = new Reference();
+ rootRef.setOrigReference(safeReadTermValue(termBucket, CoreMetKeys.PRODUCT_ROOT_REF_ORIG));
+ rootRef.setDataStoreReference(safeReadTermValue(termBucket,CoreMetKeys.PRODUCT_ROOT_REF_DATA_STORE));
+ if (termBucket.getTermByName(CoreMetKeys.PRODUCT_ROOT_REF_FILE_SIZE) != null)
+ rootRef.setFileSize(Long.parseLong(termBucket.getTermByName(CoreMetKeys.PRODUCT_ROOT_REF_FILE_SIZE).getFirstValue()));
+ rootRef.setMimeType(safeReadTermValue(termBucket, CoreMetKeys.PRODUCT_ROOT_REF_MIME_TYPE));
+ }
+ Product product = new Product();
+ product.setProductName(productName);
+ product.setProductType(productType);
+ product.setProductId(productId);
+ product.setProductReferences(refs);
+ product.setTransferStatus(status);
+ if (structure != null)
+ product.setProductStructure(structure);
+ return product;
+ }
+
+ protected static String safeReadTermValue(TermBucket termBucket, String termName) {
+ if (termName != null) {
+ Term term = termBucket.getTermByName(termName);
+ if (term != null)
+ return term.getFirstValue();
+ }
+ return null;
+ }
+
+ protected static List<String> safeReadTermValues(TermBucket termBucket, String termName) {
+ if (termName != null) {
+ Term term = termBucket.getTermByName(termName);
+ if (term != null)
+ return term.getValues();
+ }
+ return Collections.emptyList();
+ }
+
+// public static ProductPage getProductPage(QueryPager queryPager, CatalogService catalogService, List<ProductType> supportedProductTypes) throws CatalogServiceException, NumberFormatException, MimeTypeException {
+// List<TransactionalMetadata> metadatas = null;
+// if (queryPager.getPageNumber() >= 0) {
+// metadatas = catalogService.getNextPage(queryPager);
+// }else {
+// metadatas = catalogService.getAllPages(queryPager);
+// }
+//
+// if (metadatas.size() > 0)
+// return new ProductPage(queryPager.getPageNumber(), queryPager.getTotalNumPages(), queryPager.getPageSize(), CatalogServiceUtils.asProducts(metadatas, supportedProductTypes));
+// else
+// return ProductPage.blankPage();
+// }
+
+ public static ProductPage getProductPage(Page page, CatalogService catalogService, List<ProductType> supportedProductTypes) throws CatalogServiceException, NumberFormatException, MimeTypeException {
+ List<TransactionalMetadata> metadatas = null;
+ if (page.getPageNum() >= 1) {
+ metadatas = catalogService.getMetadata(page);
+ if (metadatas != null && metadatas.size() > 0)
+ return new ProductPage(page.getPageNum(), page.getPageSize(), page.getNumOfHits(), CatalogServiceUtils.asProducts(metadatas, supportedProductTypes));
+ }
+ return ProductPage.blankPage();
+ }
+
+ protected static Metadata asCatalogServiceMetadata(Product product) {
+ Metadata metadata = new Metadata();
+ if (product.getProductId() != null)
+ metadata.replaceMetadata(CatalogService.CATALOG_SERVICE_TRANSACTION_ID_MET_KEY, product.getProductId());
+ metadata.replaceMetadata(CoreMetKeys.PRODUCT_NAME, product.getProductName());
+ if (product.getProductStructure() != null)
+ metadata.replaceMetadata(CoreMetKeys.PRODUCT_STRUCTURE, product.getProductStructure());
+ if (product.getTransferStatus() != null)
+ metadata.replaceMetadata(CoreMetKeys.PRODUCT_STATUS, product.getTransferStatus());
+ metadata.replaceMetadata(CoreMetKeys.PRODUCT_TYPE, product.getProductType().getName());
+ if (product.getRootRef() != null) {
+ metadata.replaceMetadata(CoreMetKeys.PRODUCT_ROOT_REF_ORIG, product.getRootRef().getOrigReference());
+ metadata.replaceMetadata(CoreMetKeys.PRODUCT_ROOT_REF_DATA_STORE, product.getRootRef().getDataStoreReference());
+ metadata.replaceMetadata(CoreMetKeys.PRODUCT_ROOT_REF_FILE_SIZE, Long.toString(product.getRootRef().getFileSize()));
+ metadata.replaceMetadata(CoreMetKeys.PRODUCT_ROOT_REF_MIME_TYPE, product.getRootRef().getMimeType().getName());
+ }
+ for (Reference ref : product.getProductReferences()) {
+ metadata.addMetadata(CoreMetKeys.PRODUCT_REFERENCE_DATA_STORE, ref.getDataStoreReference());
+ metadata.addMetadata(CoreMetKeys.PRODUCT_REFERENCE_ORIGINAL, ref.getOrigReference());
+ metadata.addMetadata(CoreMetKeys.PRODUCT_REFERENCE_FILE_SIZE, Long.toString(ref.getFileSize()));
+ if (ref.getMimeType() != null)
+ metadata.addMetadata(CoreMetKeys.PRODUCT_REFERENCE_MIME_TYPE, ref.getMimeType().getName());
+ }
+ return metadata;
+ }
+
+ public static Metadata asCatalogServiceMetadata(Product product, Metadata metadata) {
+ Metadata catalogServiceMetadata = new Metadata();
+ catalogServiceMetadata.addMetadata(metadata.getHashtable());
+ catalogServiceMetadata.addMetadata(asCatalogServiceMetadata(product).getHashtable(), true);
+ return catalogServiceMetadata;
+ }
+
+ public static TermBucket asTermBucket(Product product, Metadata metadata, List<Element> productTypeElements) {
+ return asTermBucket(asCatalogServiceMetadata(product, metadata), product.getProductType(), productTypeElements);
+ }
+
+ public static TermBucket asTermBucket(Metadata metadata, ProductType productType, List<Element> productTypeElements) {
+ TermBucket termBucket = new TermBucket(productType.getName());
+ termBucket.addTerms(getProductTypeTerms(metadata, productType, productTypeElements), false);
+ termBucket.addTerms(getProductTerms(metadata), true);
+ if (termBucket.getTerms().size() > 0)
+ return termBucket;
+ else
+ return null;
+ }
+
+ public static HashSet<Term> getProductTerms(Metadata metadata) {
+ HashSet<Term> terms = new HashSet<Term>();
+ List<String> mimeTypes = metadata.getAllMetadata(CoreMetKeys.PRODUCT_REFERENCE_MIME_TYPE);
+ if (mimeTypes != null)
+ terms.add(new Term(CoreMetKeys.PRODUCT_REFERENCE_MIME_TYPE, mimeTypes, Term.Type.xml_string));
+ List<String> origRefs = metadata.getAllMetadata(CoreMetKeys.PRODUCT_REFERENCE_ORIGINAL);
+ if (origRefs != null)
+ terms.add(new Term(CoreMetKeys.PRODUCT_REFERENCE_ORIGINAL, origRefs, Term.Type.xml_string));
+ List<String> dataStoreRefs = metadata.getAllMetadata(CoreMetKeys.PRODUCT_REFERENCE_DATA_STORE);
+ if (dataStoreRefs != null)
+ terms.add(new Term(CoreMetKeys.PRODUCT_REFERENCE_DATA_STORE, dataStoreRefs, Term.Type.xml_string));
+ List<String> refsFileSize = metadata.getAllMetadata(CoreMetKeys.PRODUCT_REFERENCE_FILE_SIZE);
+ if (refsFileSize != null)
+ terms.add(new Term(CoreMetKeys.PRODUCT_REFERENCE_FILE_SIZE, refsFileSize, Term.Type.xml_string));
+ List<String> productStructure = metadata.getAllMetadata(CoreMetKeys.PRODUCT_STRUCTURE);
+ if (productStructure != null)
+ terms.add(new Term(CoreMetKeys.PRODUCT_STRUCTURE, productStructure, Term.Type.xml_string));
+ List<String> productStatus = metadata.getAllMetadata(CoreMetKeys.PRODUCT_STATUS);
+ if (productStatus != null)
+ terms.add(new Term(CoreMetKeys.PRODUCT_STATUS, productStatus, Term.Type.xml_string));
+ List<String> productRecievedTime = metadata.getAllMetadata(CoreMetKeys.PRODUCT_RECEVIED_TIME);
+ if (productRecievedTime != null)
+ terms.add(new Term(CoreMetKeys.PRODUCT_RECEVIED_TIME, productRecievedTime, Term.Type.xml_string));
+// List<String> productId = metadata.getAllMetadata(CatalogService.CATALOG_SERVICE_TRANSACTION_ID_MET_KEY);
+// if (productId != null)
+// terms.add(new Term(CatalogService.CATALOG_SERVICE_TRANSACTION_ID_MET_KEY, productId, Term.Type.xml_string));
+ List<String> productName = metadata.getAllMetadata(CoreMetKeys.PRODUCT_NAME);
+ if (productName != null)
+ terms.add(new Term(CoreMetKeys.PRODUCT_NAME, productName, Term.Type.xml_string));
+ List<String> productRootRefOrig = metadata.getAllMetadata(CoreMetKeys.PRODUCT_ROOT_REF_ORIG);
+ if (productRootRefOrig != null)
+ terms.add(new Term(CoreMetKeys.PRODUCT_ROOT_REF_ORIG, productRootRefOrig, Term.Type.xml_string));
+ List<String> productRootRefDataStore = metadata.getAllMetadata(CoreMetKeys.PRODUCT_ROOT_REF_DATA_STORE);
+ if (productRootRefDataStore != null)
+ terms.add(new Term(CoreMetKeys.PRODUCT_ROOT_REF_DATA_STORE, productRootRefDataStore, Term.Type.xml_string));
+ List<String> productRootRefFileSize = metadata.getAllMetadata(CoreMetKeys.PRODUCT_REFERENCE_FILE_SIZE);
+ if (productRootRefFileSize != null)
+ terms.add(new Term(CoreMetKeys.PRODUCT_REFERENCE_FILE_SIZE, productRootRefFileSize, Term.Type.xml_string));
+ List<String> productRootRefMimeType = metadata.getAllMetadata(CoreMetKeys.PRODUCT_REFERENCE_MIME_TYPE);
+ if (productRootRefMimeType != null)
+ terms.add(new Term(CoreMetKeys.PRODUCT_REFERENCE_MIME_TYPE, productRootRefMimeType, Term.Type.xml_string));
+ List<String> productType = metadata.getAllMetadata(CoreMetKeys.PRODUCT_TYPE);
+ if (productType != null)
+ terms.add(new Term(CoreMetKeys.PRODUCT_TYPE, productType, Term.Type.xml_string));
+ List<String> catalogAction = metadata.getAllMetadata(CatalogActions.CATALOG_ACTION_KEY);
+ if (catalogAction != null)
+ terms.add(new Term(CatalogActions.CATALOG_ACTION_KEY, catalogAction, Term.Type.xml_string));
+ return terms;
+ }
+
+ /**
+ * urn:<product_type_name>:<element_name> is also supported for metadata keys
+ * @param metadata
+ * @param productType
+ * @param validationLayer
+ * @return
+ * @throws ValidationLayerException
+ */
+ public static HashSet<Term> getProductTypeTerms(Metadata metadata, ProductType productType, List<Element> productTypeElements) {
+ HashSet<Term> terms = new HashSet<Term>();
+ //System.out.println("Looking for elements: " + validationLayer.getElements(productType));
+ //if (metadata.getAllMetadata(CoreMetKeys.PRODUCT_TYPE).contains(productType.getName())) {
+ for (Object objKey : metadata.getHashtable().keySet()) {
+ String elementName = (String) objKey;
+ String[] namespacedElementName = elementName.split(":");
+ if (namespacedElementName.length == 3 && namespacedElementName[0].equals("urn")) {
+ if (namespacedElementName[1].equals(productType.getName()))
+ elementName = namespacedElementName[2];
+ else
+ continue;
+ }
+ boolean found = false;
+ for (Element element : productTypeElements) {
+ //System.out.println("COMPARING: " + element.getElementName() + " " + elementName);
+ if (element.getElementName().equals(elementName)) {
+ found = true;
+ break;
+ }
+ }
+ if (found)
+ terms.add(new Term(elementName, metadata.getAllMetadata(elementName), Term.Type.xml_string));
+ else if (elementName.equals(CatalogActions.CATALOG_ACTION_KEY))
+ terms.add(new Term(CatalogActions.CATALOG_ACTION_KEY, metadata.getAllMetadata(elementName), Term.Type.xml_string));
+ }
+ //}
+ return terms;
+ }
+
+ public static Metadata asMetadata(TermBucket termBucket) {
+ Metadata metadata = new Metadata();
+ for (Term term : termBucket.getTerms())
+ metadata.addMetadata(term.getName(), term.getValues());
+ return metadata;
+ }
+
+ public static QueryExpression asQueryExpression(List<QueryCriteria> queryCriteriaList, Set<String> productTypeNames) throws QueryFormulationException {
+ if (queryCriteriaList.size() == 0) {
+ return null;
+ }else if (queryCriteriaList.size() == 1) {
+ return asQueryExpression(queryCriteriaList.get(0), productTypeNames);
+ }else {
+ BooleanQueryCriteria bqCriteria = new BooleanQueryCriteria();
+ bqCriteria.setOperator(BooleanQueryCriteria.AND);
+ for (QueryCriteria qc : queryCriteriaList)
+ bqCriteria.addTerm(qc);
+ return asQueryExpression(bqCriteria, productTypeNames);
+ }
+ }
+
+ public static QueryExpression asQueryExpression(QueryCriteria queryCriteria, Set<String> productTypeNames) throws QueryFormulationException {
+ if (queryCriteria instanceof BooleanQueryCriteria) {
+ BooleanQueryCriteria boolQC = (BooleanQueryCriteria) queryCriteria;
+ if (boolQC.getOperator() == BooleanQueryCriteria.NOT) {
+ NotQueryExpression notQE = new NotQueryExpression();
+ notQE.setBucketNames(productTypeNames);
+ notQE.setQueryExpression(asQueryExpression(boolQC.getTerms().get(0), productTypeNames));
+ return notQE;
+ }else if (boolQC.getOperator() == BooleanQueryCriteria.AND || boolQC.getOperator() == BooleanQueryCriteria.OR) {
+ QueryLogicalGroup queryGroup = new QueryLogicalGroup();
+ queryGroup.setBucketNames(productTypeNames);
+ queryGroup.setOperator((boolQC.getOperator() == BooleanQueryCriteria.AND) ? QueryLogicalGroup.Operator.AND : QueryLogicalGroup.Operator.OR);
+ for (QueryCriteria subQC : ((BooleanQueryCriteria) queryCriteria).getTerms())
+ queryGroup.addExpression(asQueryExpression(subQC, productTypeNames));
+ return queryGroup;
+ }else {
+ throw new QueryFormulationException("Badly formed BooleanQueryCriteria (unsupported operator): " + boolQC);
+ }
+ }else if (queryCriteria instanceof TermQueryCriteria) {
+ return CatalogServiceUtils.getCatalogServiceComparisonQueryExpression(queryCriteria.getElementName(), Collections.singletonList(((TermQueryCriteria) queryCriteria).getValue()), ComparisonQueryExpression.Operator.EQUAL_TO, productTypeNames);
+ }else if (queryCriteria instanceof RangeQueryCriteria) {
+ RangeQueryCriteria rangeQC = (RangeQueryCriteria) queryCriteria;
+ if (rangeQC.getStartValue() != null && rangeQC.getEndValue() != null) {
+ QueryExpression startRangeQueryExpression = CatalogServiceUtils.getCatalogServiceComparisonQueryExpression(rangeQC.getElementName(), Collections.singletonList(rangeQC.getStartValue()), rangeQC.getInclusive() ? ComparisonQueryExpression.Operator.GREATER_THAN_EQUAL_TO : ComparisonQueryExpression.Operator.GREATER_THAN, productTypeNames);
+ QueryExpression endRangeQueryExpression = CatalogServiceUtils.getCatalogServiceComparisonQueryExpression(rangeQC.getElementName(), Collections.singletonList(rangeQC.getEndValue()), rangeQC.getInclusive() ? ComparisonQueryExpression.Operator.LESS_THAN_EQUAL_TO : ComparisonQueryExpression.Operator.LESS_THAN, productTypeNames);
+ return getMergedQueryExpression(QueryLogicalGroup.Operator.AND, productTypeNames, startRangeQueryExpression, endRangeQueryExpression);
+ }else if (rangeQC.getStartValue() != null) {
+ return CatalogServiceUtils.getCatalogServiceComparisonQueryExpression(rangeQC.getElementName(), Collections.singletonList(rangeQC.getStartValue()), rangeQC.getInclusive() ? ComparisonQueryExpression.Operator.GREATER_THAN_EQUAL_TO : ComparisonQueryExpression.Operator.GREATER_THAN, productTypeNames);
+ }else if (rangeQC.getEndValue() != null) {
+ return CatalogServiceUtils.getCatalogServiceComparisonQueryExpression(rangeQC.getElementName(), Collections.singletonList(rangeQC.getEndValue()), rangeQC.getInclusive() ? ComparisonQueryExpression.Operator.LESS_THAN_EQUAL_TO : ComparisonQueryExpression.Operator.LESS_THAN, productTypeNames);
+ }else {
+ throw new QueryFormulationException("Badly formed RangeQueryCriteria: " + rangeQC);
+ }
+ }else {
+ throw new QueryFormulationException("Unsupported QueryCriteria: " + queryCriteria);
+ }
+ }
+
+ public static QueryCriteria asQueryCriteria(QueryExpression queryExpression) throws QueryFormulationException {
+ if (queryExpression instanceof QueryLogicalGroup) {
+ QueryLogicalGroup queryLogicalGroup = (QueryLogicalGroup) queryExpression;
+ BooleanQueryCriteria booleanQC = new BooleanQueryCriteria();
+ booleanQC.setOperator(queryLogicalGroup.getOperator().equals(QueryLogicalGroup.Operator.AND) ? BooleanQueryCriteria.AND : BooleanQueryCriteria.OR);
+ for (QueryExpression subQE : ((QueryLogicalGroup) queryExpression).getExpressions())
+ booleanQC.addTerm(asQueryCriteria(subQE));
+ return booleanQC;
+ }else if (queryExpression instanceof NotQueryExpression) {
+ BooleanQueryCriteria booleanQC = new BooleanQueryCriteria();
+ booleanQC.setOperator(BooleanQueryCriteria.NOT);
+ booleanQC.addTerm(asQueryCriteria(((NotQueryExpression) queryExpression).getQueryExpression()));
+ return booleanQC;
+ }else if (queryExpression instanceof ComparisonQueryExpression) {
+ ComparisonQueryExpression compQE = (ComparisonQueryExpression) queryExpression;
+ if (compQE.getOperator().equals(ComparisonQueryExpression.Operator.EQUAL_TO)) {
+ return new TermQueryCriteria(compQE.getTerm().getName(), compQE.getTerm().getFirstValue());
+ } else if (compQE.getOperator().equals(ComparisonQueryExpression.Operator.GREATER_THAN)) {
+ return new RangeQueryCriteria(compQE.getTerm().getName(), compQE.getTerm().getFirstValue(), null, false);
+ } else if (compQE.getOperator().equals(ComparisonQueryExpression.Operator.GREATER_THAN_EQUAL_TO)) {
+ return new RangeQueryCriteria(compQE.getTerm().getName(), compQE.getTerm().getFirstValue(), null, true);
+ } else if (compQE.getOperator().equals(ComparisonQueryExpression.Operator.LESS_THAN)) {
+ return new RangeQueryCriteria(compQE.getTerm().getName(), null, compQE.getTerm().getFirstValue(), false);
+ } else if (compQE.getOperator().equals(ComparisonQueryExpression.Operator.LESS_THAN_EQUAL_TO)) {
+ return new RangeQueryCriteria(compQE.getTerm().getName(), null, compQE.getTerm().getFirstValue(), true);
+ } else {
+ throw new QueryFormulationException("Unsupported QueryExpression: " + queryExpression);
+ }
+ }else {
+ return null;
+ }
+ }
+
+}
Added: oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/catalog/catalogservice/FilemgrCatalogIndex.java
URL: http://svn.apache.org/viewvc/oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/catalog/catalogservice/FilemgrCatalogIndex.java?rev=1052148&view=auto
==============================================================================
--- oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/catalog/catalogservice/FilemgrCatalogIndex.java (added)
+++ oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/catalog/catalogservice/FilemgrCatalogIndex.java Thu Dec 23 02:48:02 2010
@@ -0,0 +1,674 @@
+/*
+ * 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.catalog.catalogservice;
+
+//JDK imports
+import java.text.ParseException;
+import java.util.Collections;
+import java.util.Date;
+import java.util.GregorianCalendar;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+import java.util.Vector;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+//OODT imports
+import org.apache.oodt.cas.catalog.exception.CatalogIndexException;
+import org.apache.oodt.cas.catalog.exception.IngestServiceException;
+import org.apache.oodt.cas.catalog.exception.QueryServiceException;
+import org.apache.oodt.cas.catalog.page.IndexPager;
+import org.apache.oodt.cas.catalog.page.IngestReceipt;
+import org.apache.oodt.cas.catalog.page.TransactionReceipt;
+import org.apache.oodt.cas.catalog.query.CustomQueryExpression;
+import org.apache.oodt.cas.catalog.query.CustomWrapperQueryExpression;
+import org.apache.oodt.cas.catalog.query.QueryExpression;
+import org.apache.oodt.cas.catalog.struct.Index;
+import org.apache.oodt.cas.catalog.struct.IngestService;
+import org.apache.oodt.cas.catalog.struct.QueryService;
+import org.apache.oodt.cas.catalog.struct.TransactionId;
+import org.apache.oodt.cas.catalog.struct.TransactionIdFactory;
+import org.apache.oodt.cas.catalog.term.TermBucket;
+import org.apache.oodt.cas.filemgr.catalog.Catalog;
+import org.apache.oodt.cas.filemgr.catalog.CatalogFactory;
+import org.apache.oodt.cas.filemgr.metadata.CoreMetKeys;
+import org.apache.oodt.cas.filemgr.structs.Product;
+import org.apache.oodt.cas.filemgr.structs.ProductPage;
+import org.apache.oodt.cas.filemgr.structs.ProductType;
+import org.apache.oodt.cas.filemgr.structs.Query;
+import org.apache.oodt.cas.filemgr.structs.QueryCriteria;
+import org.apache.oodt.cas.filemgr.structs.query.QueryResult;
+import org.apache.oodt.cas.metadata.Metadata;
+import org.apache.oodt.commons.util.DateConvert;
+
+/**
+ * @author bfoster
+ * @version $Revision$
+ *
+ * <p></p>
+ *
+ */
+public class FilemgrCatalogIndex implements Index, QueryService, IngestService {
+
+// private static final long serialVersionUID = 8331106878686380577L;
+
+ private static Logger LOG = Logger.getLogger(FilemgrCatalogIndex.class.getName());
+
+ public static enum PropertyKeys {
+ SUPPORTED_PRODUCT_TYPES,
+ NUMBER_OF_PRODUCTS;
+
+ public static String generateNumOfProductsKeyName(String productTypeName) {
+ return productTypeName + ":" + NUMBER_OF_PRODUCTS.toString();
+ }
+ }
+
+ protected Catalog fmCatalog;
+ protected CatalogFactory fmCatalogFactory;
+ protected TransactionIdFactory transactionIdFactory;
+ protected List<ProductType> supportedProductTypes;
+ protected int fmCatalogPageSize;
+
+ public FilemgrCatalogIndex() {}
+
+ public CatalogFactory getFmCatalogFactory() {
+ return this.fmCatalogFactory;
+ }
+
+ public void setFmCatalogFactory(CatalogFactory fmCatalogFactory) {
+ this.fmCatalogFactory = fmCatalogFactory;
+ this.fmCatalog = fmCatalogFactory.createCatalog();
+ this.fmCatalogPageSize = this.fmCatalog.getPageSize();
+ }
+
+ public void setSupportedProductTypes(List<ProductType> supportedProductTypes) {
+ this.supportedProductTypes = new Vector<ProductType>(supportedProductTypes);
+ }
+
+ public List<ProductType> getSupportedProductTypes() {
+ if (this.supportedProductTypes != null)
+ return new Vector<ProductType>(this.supportedProductTypes);
+ else
+ return Collections.emptyList();
+ }
+
+ public TransactionIdFactory getTransactionIdFactory() {
+ return this.transactionIdFactory;
+ }
+
+ public void setTransactionIdFactory(String transactionIdFactory) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
+ this.transactionIdFactory = (TransactionIdFactory) Class.forName(transactionIdFactory).newInstance();
+ }
+
+ public String getProperty(String key) throws CatalogIndexException {
+ try {
+ String[] splitKey = key.split(":");
+ if (key.equals(PropertyKeys.SUPPORTED_PRODUCT_TYPES.toString())) {
+ String productTypeStringList = "";
+ for (ProductType productType : this.supportedProductTypes)
+ productTypeStringList += productType.getName() + ",";
+ return productTypeStringList.replaceAll(",$", "");
+ }else if (splitKey.length > 1 && splitKey[1].equals(PropertyKeys.NUMBER_OF_PRODUCTS.toString())) {
+ for (ProductType productType : this.supportedProductTypes) {
+ if (productType.getName().equals(splitKey[0]))
+ return Integer.toString(this.fmCatalog.getNumProducts(productType));
+ }
+ return null;
+ }else {
+ return this.getProperties().getProperty(key);
+ }
+ }catch (Exception e) {
+ throw new CatalogIndexException("Failed to get Property '" + key + "' from index : " + e.getMessage(), e);
+ }
+ }
+
+ public Properties getProperties() throws CatalogIndexException {
+ try {
+ Properties fmCatalogProps = new Properties();
+ String productTypeStringList = "";
+ int totalNumOfProducts = 0;
+ for (ProductType productType : this.supportedProductTypes) {
+ productTypeStringList += productType.getName() + ",";
+ int numOfProducts = this.fmCatalog.getNumProducts(productType);
+ fmCatalogProps.setProperty(PropertyKeys.generateNumOfProductsKeyName(productType.getName()), Integer.toString(numOfProducts));
+ totalNumOfProducts += numOfProducts;
+ }
+ fmCatalogProps.setProperty(PropertyKeys.NUMBER_OF_PRODUCTS.toString(), Integer.toString(totalNumOfProducts));
+ fmCatalogProps.setProperty(PropertyKeys.SUPPORTED_PRODUCT_TYPES.toString(), productTypeStringList.replaceAll(",$", ""));
+ return fmCatalogProps;
+ }catch (Exception e) {
+ throw new CatalogIndexException("Failed to get Properties from index : " + e.getMessage(), e);
+ }
+ }
+//
+// public List<TransactionReceipt> getPage(IndexPager indexPager) throws CatalogIndexException {
+// try {
+// List<String> elements = new Vector<String>();
+// Collections.addAll(elements, CoreMetKeys.PRODUCT_ID,CoreMetKeys.PRODUCT_RECEVIED_TIME);
+// HashMap<String, List<TransactionReceipt>> productTypeToReceiptMap = new HashMap<String, List<TransactionReceipt>>();
+//
+// for (ProductType productType : this.supportedProductTypes.values()) {
+// List<Metadata> metadatas = this.fmCatalog.getReducedMetadata(new Query(), productType, elements);
+// for (int i = (indexPager.getPageNumber() * indexPager.getPageSize()); i < metadatas.size() && i < ((indexPager.getPageNumber() + 1) * indexPager.getPageSize()); i++) {
+// Metadata metadata = metadatas.get(i);
+// List<TransactionReceipt> transactionReceipts = productTypeToReceiptMap.get(productType.getProductTypeId());
+// if (transactionReceipts == null)
+// transactionReceipts = new Vector<TransactionReceipt>();
+// transactionReceipts.add(this.generateReceipt(metadata));
+// productTypeToReceiptMap.put(productType.getProductTypeId(), transactionReceipts);
+// }
+// }
+//
+//
+// List<Metadata> metadatas = null;
+// if (queryExpression instanceof ProductTypeQueryExpression) {
+// Query fmQuery = new Query();
+// if (((ProductTypeQueryExpression) queryExpression).getQueryExpression() != null)
+// fmQuery.addCriterion(CatalogServiceUtils.asQueryCriteria(((ProductTypeQueryExpression) queryExpression).getQueryExpression()));
+// LOG.log(Level.INFO, "Performing Filemgr Query '" + fmQuery + "'");
+// metadatas = this.fmCatalog.getReducedMetadata(fmQuery, ((ProductTypeQueryExpression) queryExpression).getProductType(), elements);
+// }else if (queryExpression instanceof ProductNameQueryExpression) {
+// Product product = this.fmCatalog.getProductByName(((ProductNameQueryExpression) queryExpression).getProductName());
+// if (product != null)
+// metadatas = Collections.singletonList(this.fmCatalog.getReducedMetadata(product, elements));
+// else
+// metadatas = Collections.emptyList();
+// }else {
+// throw new QueryServiceException("Unknown Query type");
+// }
+// List<TransactionReceipt> transactionIds = new Vector<TransactionReceipt>();
+// for (Metadata metadata : metadatas)
+// transactionIds.add(generateReceipt(metadata));
+// return transactionIds;
+// }catch (Exception e) {
+// throw new QueryServiceException("Failed to perform CatalogQuery '" + queryExpression + "' : " + e.getMessage(), e);
+// }
+// }
+
+
+ public List<TransactionId<?>> getPage(IndexPager indexPager) throws CatalogIndexException {
+ try {
+
+ List<Product> productsPage = new Vector<Product>();
+ int startProductLoc = indexPager.getPageSize() * indexPager.getPageNum();
+ int curNumOfProds = 0;
+
+ for (ProductType productType : this.supportedProductTypes) {
+ int curProdTypeNumOfProds = this.fmCatalog.getNumProducts(productType);
+ //System.out.println("curProdTypeNumOfProds: " + curProdTypeNumOfProds);
+ int prevNumOfProds = curNumOfProds;
+ curNumOfProds += curProdTypeNumOfProds;
+
+ if (curNumOfProds >= startProductLoc) {
+ int locInCurProdType = startProductLoc - prevNumOfProds;
+ //System.out.println("locInCurProdType: " + locInCurProdType + " startProductLoc:" + startProductLoc + " prevNumOfProds: " + prevNumOfProds);
+ int curPtPage = locInCurProdType / this.fmCatalogPageSize;
+ int curPageShift = locInCurProdType % this.fmCatalogPageSize;
+ //System.out.println("CurPage: " + curPtPage + " shift: " + curPageShift);
+ ProductPage pp = this.fmCatalog.pagedQuery(new Query(), productType, curPtPage + 1);
+ for (int i = curPageShift; i < pp.getPageProducts().size(); i++)
+ productsPage.add(pp.getPageProducts().get(i));
+
+ while (productsPage.size() < indexPager.getPageSize()) {
+ int lastPage = pp.getPageNum();
+ pp = this.fmCatalog.getNextPage(productType, pp);
+ if (pp.getPageNum() > lastPage && pp.getPageProducts() != null && pp.getPageProducts().size() > 0) {
+ productsPage.addAll(pp.getPageProducts());
+ }else {
+ break;
+ }
+ }
+
+ startProductLoc += curProdTypeNumOfProds;
+
+ if (productsPage.size() == indexPager.getPageSize()) {
+ break;
+ }else if (productsPage.size() > indexPager.getPageSize()) {
+ List<Product> productsPageSubList = new Vector<Product>();
+ for (int i = 0; i < indexPager.getPageSize(); i++)
+ productsPageSubList.add(productsPage.get(i));
+ productsPage = productsPageSubList;
+ break;
+ }
+ }
+ }
+ // convert product ids to transaction ids
+ LinkedHashSet<TransactionId<?>> transactionIds = new LinkedHashSet<TransactionId<?>>();
+ for (Product product : productsPage)
+ transactionIds.add(this.generateTransactionId(product.getProductId()));
+ return new Vector<TransactionId<?>>(transactionIds);
+ }catch(Exception e) {
+ throw new CatalogIndexException("", e);
+ }
+ }
+
+ public boolean hasTransactionId(TransactionId<?> catalogTransactionId) throws CatalogIndexException {
+ try {
+ Product product = this.fmCatalog.getProductById(catalogTransactionId.toString());
+ return product != null && this.isSupportedProductTypeId(product.getProductType().getProductTypeId());
+ }catch(Exception e) {
+ throw new CatalogIndexException("", e);
+ }
+ }
+
+ public boolean delete(TransactionId<?> transactionId) throws IngestServiceException {
+ try {
+ Product product = this.fmCatalog.getProductById(transactionId.toString());
+ product.setProductType(this.getProductTypeById(product.getProductType().getProductTypeId()));
+ if (product != null) {
+ LOG.log(Level.INFO, "Deleting Product for TransactionId: " + transactionId);
+ this.fmCatalog.removeProduct(product);
+ return true;
+ }else {
+ LOG.log(Level.INFO, "Failed to find existing Product for TransactionId: " + transactionId);
+ return false;
+ }
+ }catch(Exception e) {
+ throw new IngestServiceException("Failed to delete product for TransactionId '" + transactionId + "' : " + e.getMessage(), e);
+ }
+ }
+
+ public IngestReceipt ingest(List<TermBucket> termBuckets) throws IngestServiceException {
+ TransactionId<?> transactionId = null;
+ try {
+ transactionId = this.getTransactionIdFactory().createNewTransactionId();
+ Product product = CatalogServiceUtils.asProduct(termBuckets.get(0), new Vector<ProductType>(this.supportedProductTypes));
+ product.setProductType(this.getProductTypeById(product.getProductType().getProductTypeId()));
+ Metadata metadata = CatalogServiceUtils.asMetadata(termBuckets.get(0));
+ String catalogAction = metadata.getMetadata(CatalogActions.CATALOG_ACTION_KEY);
+ if (catalogAction.equals(CatalogActions.INGEST_PRODUCT)) {
+ LOG.log(Level.INFO, "Ingesting Product metadata for TransactionId: " + transactionId);
+ this.fmCatalog.addProduct(product);
+ }else {
+ throw new IngestServiceException("Unsupport CatalogAction: '" + catalogAction + "' for TransactionId '" + transactionId + "'");
+ }
+// String productReceivedTime = metadata.getMetadata(CoreMetKeys.PRODUCT_RECEVIED_TIME);
+// if (productReceivedTime == null)
+// metadata.replaceMetadata(CoreMetKeys.PRODUCT_RECEVIED_TIME, DateConvert.isoFormat(new Date()));
+ metadata.replaceMetadata(CoreMetKeys.PRODUCT_ID, product.getProductId());
+ return this.generateReceipt(metadata);
+ }catch (Exception e) {
+ throw new IngestServiceException("Failed to Ingest Product for TransactionId: " + transactionId, e);
+ }
+ }
+
+ public boolean reduce(TransactionId<?> transactionId,
+ List<TermBucket> termBuckets) throws IngestServiceException {
+ try {
+ Product product = this.fmCatalog.getProductById(transactionId.toString());
+ product.setProductType(this.getProductTypeById(product.getProductType().getProductTypeId()));
+ Metadata metadata = CatalogServiceUtils.asMetadata(termBuckets.get(0));
+ String catalogAction = metadata.getMetadata(CatalogActions.CATALOG_ACTION_KEY);
+ if (catalogAction.equals(CatalogActions.REMOVE_PRODUCT)) {
+ LOG.log(Level.INFO, "Removing Product for TransactionId: " + transactionId);
+ this.fmCatalog.removeProduct(product);
+ }else if (catalogAction.equals(CatalogActions.REMOVE_METADATA)) {
+ LOG.log(Level.INFO, "Removing Product Metadata for TransactionId: " + transactionId);
+ this.fmCatalog.removeMetadata(metadata, product);
+ }
+ return true;
+ }catch (Exception e) {
+ throw new IngestServiceException("", e);
+ }
+ }
+
+ public IngestReceipt update(TransactionId<?> transactionId,
+ List<TermBucket> termBuckets) throws IngestServiceException {
+ try {
+ Product product = CatalogServiceUtils.asProduct(termBuckets.get(0), new Vector<ProductType>(this.supportedProductTypes));
+ product.setProductId(transactionId.toString());
+ product.setProductType(this.getProductTypeById(product.getProductType().getProductTypeId()));
+ Metadata metadata = CatalogServiceUtils.asMetadata(termBuckets.get(0));
+ metadata.replaceMetadata(CoreMetKeys.PRODUCT_ID, product.getProductId());
+ String catalogAction = metadata.getMetadata(CatalogActions.CATALOG_ACTION_KEY);
+ if (catalogAction.equals(CatalogActions.INGEST_PRODUCT)) {
+ LOG.log(Level.INFO, "Modifying Product for TransactionId: " + transactionId);
+ this.fmCatalog.modifyProduct(product);
+ }else if (catalogAction.equals(CatalogActions.STATUS_UPDATE)) {
+ LOG.log(Level.INFO, "Updating Product transfer status for TransactionId: " + transactionId);
+ this.fmCatalog.setProductTransferStatus(product);
+ }else if (catalogAction.equals(CatalogActions.INGEST_METADATA)) {
+ LOG.log(Level.INFO, "Adding Product Metadata for TransactionId: " + transactionId);
+ this.fmCatalog.addMetadata(metadata, product);
+ }else if (catalogAction.equals(CatalogActions.INGEST_REFERENCE)) {
+ LOG.log(Level.INFO, "Adding Product References for TransactionId: " + transactionId);
+ this.fmCatalog.addProductReferences(product);
+ }
+ return new IngestReceipt(transactionId, new Date());
+ }catch (Exception e) {
+ throw new IngestServiceException("", e);
+ }
+ }
+
+ public List<TermBucket> getBuckets(TransactionId<?> transactionId) throws QueryServiceException {
+ try {
+ Product product = this.fmCatalog.getProductById(transactionId.toString());
+ if (product != null) {
+ product.setProductType(this.getProductTypeById(product.getProductType().getProductTypeId()));
+ product.setProductReferences(this.fmCatalog.getProductReferences(product));
+ return Collections.singletonList(CatalogServiceUtils.asTermBucket(product, this.fmCatalog.getMetadata(product), this.fmCatalog.getValidationLayer().getElements(product.getProductType())));
+ }else {
+ return Collections.emptyList();
+ }
+ }catch (Exception e) {
+ throw new QueryServiceException("", e);
+ }
+ }
+
+ public Map<TransactionId<?>, List<TermBucket>> getBuckets(
+ List<TransactionId<?>> transactionIds) throws QueryServiceException {
+ HashMap<TransactionId<?>, List<TermBucket>> termBucketMap = new HashMap<TransactionId<?>, List<TermBucket>>();
+ for (TransactionId<?> transactionId : transactionIds)
+ termBucketMap.put(transactionId, this.getBuckets(transactionId));
+ return termBucketMap;
+ }
+
+ public List<IngestReceipt> query(QueryExpression queryExpression)
+ throws QueryServiceException {
+ try {
+ List<String> elements = new Vector<String>();
+ Collections.addAll(elements, CoreMetKeys.PRODUCT_ID,CoreMetKeys.PRODUCT_RECEVIED_TIME);
+
+ List<Metadata> metadatas = new Vector<Metadata>();
+
+ if (queryExpression instanceof CustomWrapperQueryExpression) {
+ CustomWrapperQueryExpression cwqe = (CustomWrapperQueryExpression) queryExpression;
+ if (cwqe.getMeaning().equals(CatalogServiceMetKeys.FILEMGR_CATALOGS_ONLY))
+ queryExpression = ((CustomWrapperQueryExpression) queryExpression).getQueryExpression();
+ else
+ return Collections.emptyList();
+ }
+
+ if (queryExpression instanceof CustomQueryExpression) {
+ CustomQueryExpression customQE = (CustomQueryExpression) queryExpression;
+ if (customQE.getName().equals(CatalogServiceMetKeys.PRODUCT_NAME_QUERY_EXPRESSION)) {
+ Product product = this.fmCatalog.getProductByName(customQE.getProperty(CatalogServiceMetKeys.PRODUCT_NAME_CUSTOM_KEY));
+ if (product != null && product.getProductType() != null && this.isSupportedProductTypeId(product.getProductType().getProductTypeId())) {
+ product.setProductType(this.getProductTypeById(product.getProductType().getProductTypeId()));
+ metadatas = Collections.singletonList(this.fmCatalog.getReducedMetadata(product, elements));
+ }else {
+ metadatas = Collections.emptyList();
+ }
+ }else if (customQE.getName().equals(CatalogServiceMetKeys.TOP_N_QUERY_EXPRESSION)) {
+ List<Product> topNProducts = this.fmCatalog.getTopNProducts(Integer.parseInt(customQE.getProperty(CatalogServiceMetKeys.N_CUSTOM_KEY)));
+ if (topNProducts != null) {
+ for (Product product : topNProducts) {
+ if (product != null && product.getProductType() != null && this.isSupportedProductTypeId(product.getProductType().getProductTypeId())) {
+ product.setProductType(this.getProductTypeById(product.getProductType().getProductTypeId()));
+ Metadata m = this.fmCatalog.getMetadata(product);
+ m.replaceMetadata(CoreMetKeys.PRODUCT_ID, product.getProductId());
+ metadatas.add(m);
+ }
+ }
+ }
+ }else {
+ throw new QueryServiceException("Unknown Custom Query type '" + (queryExpression != null ? queryExpression.getClass().getCanonicalName() : queryExpression) + "'");
+ }
+ }else {
+ Query fmQuery = new Query();
+ QueryCriteria qc = CatalogServiceUtils.asQueryCriteria(queryExpression);
+ if (qc != null)
+ fmQuery.addCriterion(qc);
+ LOG.log(Level.INFO, "Performing Filemgr Query '" + fmQuery + "'");
+ List<ProductType> supportedSubsetOfTypes = new Vector<ProductType>();
+ Set<String> productTypeNames = queryExpression.getBucketNames();
+ if (productTypeNames == null)
+ productTypeNames = this.getSupportedProductTypeNames();
+ for (String productTypeName : productTypeNames) {
+ ProductType type = this.getProductTypeByName(productTypeName);
+ if (type != null)
+ supportedSubsetOfTypes.add(type);
+ }
+ metadatas = this.fmCatalog.getReducedMetadata(fmQuery, supportedSubsetOfTypes, elements);
+ }
+
+ List<IngestReceipt> ingestReceipts = new Vector<IngestReceipt>();
+ for (Metadata metadata : metadatas)
+ ingestReceipts.add(generateReceipt(metadata));
+ return ingestReceipts;
+ }catch (Exception e) {
+ throw new QueryServiceException("Failed to perform CatalogQuery '" + queryExpression + "' : " + e.getMessage(), e);
+ }
+ }
+
+ public List<IngestReceipt> query(QueryExpression queryExpression, int startIndex, int endIndex)
+ throws QueryServiceException {
+ try {
+ List<String> elements = new Vector<String>();
+ Collections.addAll(elements, CoreMetKeys.PRODUCT_ID,CoreMetKeys.PRODUCT_RECEVIED_TIME);
+
+ List<Metadata> metadatas = new Vector<Metadata>();
+
+ if (queryExpression instanceof CustomWrapperQueryExpression) {
+ CustomWrapperQueryExpression cwqe = (CustomWrapperQueryExpression) queryExpression;
+ if (cwqe.getMeaning().equals(CatalogServiceMetKeys.FILEMGR_CATALOGS_ONLY))
+ queryExpression = ((CustomWrapperQueryExpression) queryExpression).getQueryExpression();
+ else
+ return Collections.emptyList();
+ }
+
+ if (queryExpression instanceof CustomQueryExpression) {
+ CustomQueryExpression customQE = (CustomQueryExpression) queryExpression;
+ if (customQE.getName().equals(CatalogServiceMetKeys.PRODUCT_NAME_QUERY_EXPRESSION)) {
+ Product product = this.fmCatalog.getProductByName(customQE.getProperty(CatalogServiceMetKeys.PRODUCT_NAME_CUSTOM_KEY));
+ if (product != null && product.getProductType() != null && this.isSupportedProductTypeId(product.getProductType().getProductTypeId())) {
+ product.setProductType(this.getProductTypeById(product.getProductType().getProductTypeId()));
+ metadatas = Collections.singletonList(this.fmCatalog.getReducedMetadata(product, elements));
+ }else {
+ metadatas = Collections.emptyList();
+ }
+ }else if (customQE.getName().equals(CatalogServiceMetKeys.TOP_N_QUERY_EXPRESSION)) {
+ List<Product> topNProducts = this.fmCatalog.getTopNProducts(Integer.parseInt(customQE.getProperty(CatalogServiceMetKeys.N_CUSTOM_KEY)));
+ if (topNProducts != null) {
+ for (Product product : topNProducts) {
+ if (product != null && product.getProductType() != null && this.isSupportedProductTypeId(product.getProductType().getProductTypeId())) {
+ product.setProductType(this.getProductTypeById(product.getProductType().getProductTypeId()));
+ Metadata m = this.fmCatalog.getMetadata(product);
+ m.replaceMetadata(CoreMetKeys.PRODUCT_ID, product.getProductId());
+ metadatas.add(m);
+ }
+ }
+ }
+ }else {
+ throw new QueryServiceException("Unknown Custom Query type '" + (queryExpression != null ? queryExpression.getClass().getCanonicalName() : queryExpression) + "'");
+ }
+ }else {
+ Query fmQuery = new Query();
+ QueryCriteria qc = CatalogServiceUtils.asQueryCriteria(queryExpression);
+ if (qc != null)
+ fmQuery.addCriterion(qc);
+ LOG.log(Level.INFO, "Performing Filemgr Query '" + fmQuery + "'");
+ List<ProductType> supportedSubsetOfTypes = new Vector<ProductType>();
+ Set<String> productTypeNames = queryExpression.getBucketNames();
+ if (productTypeNames == null)
+ productTypeNames = this.getSupportedProductTypeNames();
+ for (String productTypeName : productTypeNames) {
+ ProductType type = this.getProductTypeByName(productTypeName);
+ if (type != null)
+ supportedSubsetOfTypes.add(type);
+ }
+ int currentIndex = 0;
+ for (ProductType type : supportedSubsetOfTypes) {
+ ProductPage page = this.fmCatalog.pagedQuery(fmQuery, type, 1);
+ if (endIndex <= currentIndex)
+ break;
+ if (startIndex >= currentIndex && startIndex <= currentIndex + page.getNumOfHits()) {
+ int localIndex = startIndex - currentIndex;
+ int pageNum = (int) Math.ceil((double) localIndex / (double) this.fmCatalog.getPageSize());
+ int numOfPages = (int) Math.ceil((double) (endIndex - startIndex) / (double) this.fmCatalog.getPageSize());
+ for (int i = 0; i < numOfPages; i++, pageNum++) {
+ page = this.fmCatalog.pagedQuery(fmQuery, type, pageNum);
+ for (int k = 0, j = localIndex; k < page.getPageProducts().size() && j < (localIndex + this.fmCatalog.getPageSize()) && j < endIndex - currentIndex; k++, j++) {
+ Product product = page.getPageProducts().get(k);
+ product.setProductType(type);
+ metadatas.add(this.fmCatalog.getReducedMetadata(product, elements));
+ }
+ }
+ }
+ currentIndex += page.getNumOfHits();
+ }
+ }
+
+ List<IngestReceipt> ingestReceipts = new Vector<IngestReceipt>();
+ for (Metadata metadata : metadatas)
+ ingestReceipts.add(generateReceipt(metadata));
+ return ingestReceipts;
+ }catch (Exception e) {
+ throw new QueryServiceException("Failed to perform CatalogQuery '" + queryExpression + "' : " + e.getMessage(), e);
+ }
+ }
+
+ public int sizeOf(QueryExpression queryExpression) throws QueryServiceException {
+ try {
+ if (queryExpression instanceof CustomWrapperQueryExpression) {
+ CustomWrapperQueryExpression cwqe = (CustomWrapperQueryExpression) queryExpression;
+ if (cwqe.getMeaning().equals(CatalogServiceMetKeys.FILEMGR_CATALOGS_ONLY))
+ queryExpression = ((CustomWrapperQueryExpression) queryExpression).getQueryExpression();
+ else
+ return 0;
+ }
+
+ if (queryExpression instanceof CustomQueryExpression) {
+ CustomQueryExpression customQE = (CustomQueryExpression) queryExpression;
+ if (customQE.getName().equals(CatalogServiceMetKeys.PRODUCT_NAME_QUERY_EXPRESSION)) {
+ Product product = this.fmCatalog.getProductByName(customQE.getProperty(CatalogServiceMetKeys.PRODUCT_NAME_CUSTOM_KEY));
+ if (product != null && product.getProductType() != null && this.isSupportedProductTypeId(product.getProductType().getProductTypeId())) {
+ return 1;
+ }else {
+ return 0;
+ }
+ }else if (customQE.getName().equals(CatalogServiceMetKeys.TOP_N_QUERY_EXPRESSION)) {
+ List<Product> topNProducts = this.fmCatalog.getTopNProducts(Integer.parseInt(customQE.getProperty(CatalogServiceMetKeys.N_CUSTOM_KEY)));
+ if (topNProducts != null) {
+ return topNProducts.size();
+ }else {
+ return 0;
+ }
+ }else {
+ throw new QueryServiceException("Unknown Custom Query type '" + (queryExpression != null ? queryExpression.getClass().getCanonicalName() : queryExpression) + "'");
+ }
+ }else {
+ Query fmQuery = new Query();
+ QueryCriteria qc = CatalogServiceUtils.asQueryCriteria(queryExpression);
+ if (qc != null)
+ fmQuery.addCriterion(qc);
+ LOG.log(Level.INFO, "Performing Filemgr Query '" + fmQuery + "'");
+ List<ProductType> supportedSubsetOfTypes = new Vector<ProductType>();
+ Set<String> productTypeNames = queryExpression.getBucketNames();
+ if (productTypeNames == null)
+ productTypeNames = this.getSupportedProductTypeNames();
+ for (String productTypeName : productTypeNames) {
+ ProductType type = this.getProductTypeByName(productTypeName);
+ if (type != null)
+ supportedSubsetOfTypes.add(type);
+ }
+ int totalResults = 0;
+ for (ProductType type : supportedSubsetOfTypes)
+ totalResults += this.fmCatalog.pagedQuery(fmQuery, type, 1).getNumOfHits();
+ return totalResults;
+ }
+ }catch (Exception e) {
+ throw new QueryServiceException("Failed to perform CatalogQuery '" + queryExpression + "' : " + e.getMessage(), e);
+ }
+ }
+
+ protected TransactionId<?> generateTransactionId() {
+ return this.generateTransactionId(null);
+ }
+
+ protected TransactionId<?> generateTransactionId(String transactionId) {
+ try {
+ if (transactionId != null) {
+ return this.getTransactionIdFactory().createTransactionId(transactionId);
+ }else {
+ return this.getTransactionIdFactory().createNewTransactionId();
+ }
+ }catch (Exception e) {
+ e.printStackTrace();
+ return null;
+ }
+ }
+
+ protected IngestReceipt generateReceipt(Metadata metadata) throws ParseException {
+ String reveivedTimeString = metadata.getMetadata(CoreMetKeys.PRODUCT_RECEVIED_TIME);
+ Date receivedDate = new GregorianCalendar(2000, 01, 01).getTime();
+ if (reveivedTimeString != null)
+ receivedDate = DateConvert.isoParse(reveivedTimeString);
+// System.out.println("generating receipt for product_id : " + metadata.getMetadata(CoreMetKeys.PRODUCT_ID));
+ return new IngestReceipt(this.generateTransactionId(metadata.getMetadata(CoreMetKeys.PRODUCT_ID)), receivedDate);
+ }
+
+// private void writeObject(java.io.ObjectOutputStream out) throws IOException {
+// try {
+// XStream xStream = new XStream();
+// xStream.toXML(this.fmCatalogFactory, out);
+// out.writeObject(this.transactionIdClass.getName());
+// Vector<Hashtable<String, Object>> productTypeHash = XmlRpcStructFactory.getXmlRpcProductTypeList(new Vector<ProductType>(this.supportedProductTypes.values()));
+// out.writeObject(productTypeHash);
+// }catch (Exception e) {
+// LOG.log(Level.SEVERE, "Failed to serialized FilemgrCatalogIndex : " + e.getMessage(), e);
+// throw new IOException("");
+// }
+// }
+//
+// private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException {
+// try {
+// XStream xStream = new XStream();
+// this.setFmCatalogFactory((CatalogFactory) xStream.fromXML(in));
+// this.setTransactionIdClass((String) in.readObject());
+// this.setSupportedProductTypes(XmlRpcStructFactory.getProductTypeListFromXmlRpc((Vector<Hashtable<String, Object>>) in.readObject()));
+// }catch (Exception e) {
+// LOG.log(Level.SEVERE, "Failed to deserialized FilemgrCatalogIndex : " + e.getMessage(), e);
+// throw new IOException(e.getMessage());
+// }
+// }
+
+ protected boolean isSupportedProductTypeName(String name) {
+ return this.getProductTypeByName(name) != null;
+ }
+
+ protected boolean isSupportedProductTypeId(String id) {
+ return this.getProductTypeById(id) != null;
+ }
+
+ protected ProductType getProductTypeByName(String name) {
+ for (ProductType type : this.supportedProductTypes)
+ if (type.getName().equals(name))
+ return type;
+ return null;
+ }
+
+ protected ProductType getProductTypeById(String id) {
+ for (ProductType type : this.supportedProductTypes)
+ if (type.getProductTypeId().equals(id))
+ return type;
+ return null;
+ }
+
+ protected Set<String> getSupportedProductTypeNames() {
+ Set<String> productTypeNames = new HashSet<String>();
+ for (ProductType type : this.supportedProductTypes)
+ productTypeNames.add(type.getName());
+ return productTypeNames;
+ }
+
+}
Added: oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/catalog/catalogservice/ProductDictionary.java
URL: http://svn.apache.org/viewvc/oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/catalog/catalogservice/ProductDictionary.java?rev=1052148&view=auto
==============================================================================
--- oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/catalog/catalogservice/ProductDictionary.java (added)
+++ oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/catalog/catalogservice/ProductDictionary.java Thu Dec 23 02:48:02 2010
@@ -0,0 +1,181 @@
+/*
+ * 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.catalog.catalogservice;
+
+//JDK imports
+import java.util.List;
+import java.util.Set;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+//OODT imports
+import org.apache.oodt.cas.catalog.exception.CatalogDictionaryException;
+import org.apache.oodt.cas.catalog.query.CustomQueryExpression;
+import org.apache.oodt.cas.catalog.query.CustomWrapperQueryExpression;
+import org.apache.oodt.cas.catalog.query.QueryExpression;
+import org.apache.oodt.cas.catalog.query.QueryLogicalGroup;
+import org.apache.oodt.cas.catalog.query.StdQueryExpression;
+import org.apache.oodt.cas.catalog.query.TermQueryExpression;
+import org.apache.oodt.cas.catalog.struct.Dictionary;
+import org.apache.oodt.cas.catalog.term.Term;
+import org.apache.oodt.cas.catalog.term.TermBucket;
+import org.apache.oodt.cas.filemgr.metadata.CoreMetKeys;
+import org.apache.oodt.cas.filemgr.structs.Element;
+import org.apache.oodt.cas.filemgr.structs.ProductType;
+import org.apache.oodt.cas.filemgr.structs.exceptions.ValidationLayerException;
+import org.apache.oodt.cas.metadata.Metadata;
+
+/**
+ * @author bfoster
+ * @version $Revision$
+ *
+ * <p></p>
+ *
+ */
+public class ProductDictionary implements Dictionary {
+
+// private static final long serialVersionUID = 311618724382619649L;
+
+ private static Logger LOG = Logger.getLogger(ProductDictionary.class.getName());
+
+ protected ProductType productType;
+ protected List<Element> productTypeElements;
+
+ /*
+ * (non-Javadoc)
+ * @see gov.nasa.jpl.oodt.cas.catalog.struct.Dictionary#understands(gov.nasa.jpl.oodt.cas.catalog.query.QueryExpression)
+ */
+ public boolean understands(QueryExpression queryExpression) throws CatalogDictionaryException {
+ try {
+ Set<String> productTypeNames = queryExpression.getBucketNames();
+ if (productTypeNames == null || productTypeNames.contains(productType.getName())) {
+ if (queryExpression instanceof TermQueryExpression) {
+ return this.isUnderstoodProductTypeTerm(((TermQueryExpression) queryExpression).getTerm());
+ }else if (queryExpression instanceof CustomQueryExpression) {
+ CustomQueryExpression customQE = (CustomQueryExpression) queryExpression;
+ if (customQE.getName().equals(CatalogServiceMetKeys.PRODUCT_NAME_QUERY_EXPRESSION) || customQE.getName().equals(CatalogServiceMetKeys.TOP_N_QUERY_EXPRESSION))
+ return true;
+ }else if (queryExpression instanceof StdQueryExpression || queryExpression instanceof QueryLogicalGroup) {
+ return true;
+ }else if (queryExpression instanceof CustomWrapperQueryExpression) {
+ return ((CustomWrapperQueryExpression) queryExpression).getMeaning().equals(CatalogServiceMetKeys.FILEMGR_CATALOGS_ONLY);
+ }
+ }
+ return false;
+ }catch (Exception e) {
+ LOG.log(Level.SEVERE, "Failed to check if understood query : " + e.getMessage(), e);
+ throw new CatalogDictionaryException("Failed to check if understood query : " + e.getMessage(), e);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see gov.nasa.jpl.oodt.cas.catalog.struct.Dictionary#lookup(gov.nasa.jpl.oodt.cas.metadata.Metadata)
+ */
+ public TermBucket lookup(Metadata metadata) throws CatalogDictionaryException {
+ try {
+ List<String> productTypeNames = metadata.getAllMetadata(CoreMetKeys.PRODUCT_TYPE);
+ if (productTypeNames != null && productTypeNames.contains(this.productType.getName()))
+ return CatalogServiceUtils.asTermBucket(metadata, this.productType, this.productTypeElements);
+ else
+ return null;
+ }catch (Exception e) {
+ throw new CatalogDictionaryException("", e);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see gov.nasa.jpl.oodt.cas.catalog.struct.Dictionary#reverseLookup(gov.nasa.jpl.oodt.cas.catalog.term.TermBucket)
+ */
+ public Metadata reverseLookup(TermBucket termBucket) throws CatalogDictionaryException {
+ try {
+ Metadata metadata = new Metadata();
+ if (termBucket.getName().equals(this.productType.getName()))
+ for (Term term : termBucket.getTerms())
+ if (this.isUnderstoodTerm(term))
+ metadata.addMetadata(term.getName(), term.getValues());
+ return metadata;
+ }catch (Exception e) {
+ throw new CatalogDictionaryException("", e);
+ }
+ }
+
+ protected boolean isUnderstoodTerm(Term term) throws ValidationLayerException {
+ if (term.getName().equals(CoreMetKeys.PRODUCT_REFERENCE_MIME_TYPE) ||
+ term.getName().equals(CoreMetKeys.PRODUCT_REFERENCE_ORIGINAL) ||
+ term.getName().equals(CoreMetKeys.PRODUCT_REFERENCE_DATA_STORE) ||
+ term.getName().equals(CoreMetKeys.PRODUCT_REFERENCE_FILE_SIZE) ||
+ term.getName().equals(CoreMetKeys.PRODUCT_NAME) ||
+ term.getName().equals(CoreMetKeys.PRODUCT_STRUCTURE) ||
+ term.getName().equals(CoreMetKeys.PRODUCT_ROOT_REF_DATA_STORE) ||
+ term.getName().equals(CoreMetKeys.PRODUCT_ROOT_REF_ORIG) ||
+ term.getName().equals(CoreMetKeys.PRODUCT_ROOT_REF_FILE_SIZE) ||
+ term.getName().equals(CoreMetKeys.PRODUCT_ROOT_REF_MIME_TYPE) ||
+ term.getName().equals(CatalogActions.CATALOG_ACTION_KEY) ||
+ term.getName().equals(CoreMetKeys.PRODUCT_STATUS) ||
+ term.getName().equals(CoreMetKeys.PRODUCT_RECEVIED_TIME)) {
+ return true;
+ }else if (term.getName().equals(CoreMetKeys.PRODUCT_TYPE)) {
+ return term.getValues().contains(productType.getName());
+ }else {
+ return this.isUnderstoodProductTypeTerm(term);
+ }
+ }
+
+ protected boolean isUnderstoodProductTypeTerm(Term term) throws ValidationLayerException {
+ for (Element element : this.productTypeElements)
+ if (term.getName().equals(element.getElementName())
+ || term.getName().equals("urn:" + this.productType.getName()
+ + ":" + element.getElementName()))
+ return true;
+ return false;
+ }
+
+ public void setProductType(ProductType productType, List<Element> productTypeElements) {
+ this.productType = productType;
+ this.productTypeElements = productTypeElements;
+ }
+
+ public ProductType getProductType() {
+ return this.productType;
+ }
+
+// private void writeObject(java.io.ObjectOutputStream out) throws IOException {
+// try {
+// Hashtable<String, Object> productTypeHash = XmlRpcStructFactory.getXmlRpcProductType(this.productType);
+// out.writeObject(productTypeHash);
+// Vector<Hashtable<String, Object>> productTypeElementsHash = XmlRpcStructFactory.getXmlRpcElementList(this.productTypeElements);
+// out.writeObject(productTypeElementsHash);
+// }catch (Exception e) {
+// LOG.log(Level.SEVERE, "Failed to serialize ProductDictionary : " + e.getMessage(), e);
+// throw new IOException("Failed to serialize ProductDictionary : " + e.getMessage());
+// }
+// }
+//
+// private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException {
+// try {
+// this.productType = XmlRpcStructFactory.getProductTypeFromXmlRpc((Hashtable<String, Object>) in.readObject());
+// this.productTypeElements = XmlRpcStructFactory.getElementListFromXmlRpc((Vector<Hashtable<String, Object>>) in.readObject());
+// }catch (Exception e) {
+// LOG.log(Level.SEVERE, "Failed to deserialize ProductDictionary : " + e.getMessage(), e);
+// throw new IOException("Failed to deserialize ProductDictionary : " + e.getMessage());
+// }
+// }
+
+
+}
Added: oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/datatransfer/DataTransfer.java
URL: http://svn.apache.org/viewvc/oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/datatransfer/DataTransfer.java?rev=1052148&view=auto
==============================================================================
--- oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/datatransfer/DataTransfer.java (added)
+++ oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/datatransfer/DataTransfer.java Thu Dec 23 02:48:02 2010
@@ -0,0 +1,75 @@
+/*
+ * 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.datatransfer;
+
+//JDK imports
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+
+//OODT imports
+import org.apache.oodt.cas.filemgr.structs.Product;
+import org.apache.oodt.cas.filemgr.structs.exceptions.DataTransferException;
+
+/**
+ * @author mattmann
+ * @version $Revision$
+ *
+ * <p>
+ * Objects implementing this interface define how to transfer products to the
+ * {@link DataStore} repository.
+ * </p>
+ *
+ */
+public interface DataTransfer {
+ /* extension point ID */
+ public static final String X_POINT_ID = DataTransfer.class.getName();
+
+ /**
+ *
+ * @param url The URL to the File Manager that this transferer will be
+ * transferring Products to.
+ */
+ public void setFileManagerUrl(URL url);
+
+ /**
+ *
+ * @param product
+ * The product that is being transferred. The product should have
+ * both its origFileLocation, as well as its dataStoreRefs filled
+ * in to perform the transfer.
+ * @throws DataTransferException
+ * If a general error occurs during the transfer.
+ * @throws IOException
+ * If there is an IO eerror when performing the transfer.
+ */
+ public void transferProduct(Product product) throws DataTransferException,
+ IOException;
+
+ /**
+ * Requires that the data store reference be set, nothing else is used
+ * @param product The product whose data store reference will be copied
+ * @param directory The directory where the data store reference will be copied to
+ * @throws DataTransferException
+ * If a general error occurs during the transfer.
+ * @throws IOException
+ * If there is an IO eerror when performing the transfer.
+ */
+ public void copyProduct(Product product, File directory) throws DataTransferException,
+ IOException;
+
+}
Added: oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/datatransfer/DataTransferFactory.java
URL: http://svn.apache.org/viewvc/oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/datatransfer/DataTransferFactory.java?rev=1052148&view=auto
==============================================================================
--- oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/datatransfer/DataTransferFactory.java (added)
+++ oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/datatransfer/DataTransferFactory.java Thu Dec 23 02:48:02 2010
@@ -0,0 +1,32 @@
+/*
+ * 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.datatransfer;
+
+/**
+ * @author mattmann
+ * @version $Revision$
+ *
+ * <p>A Factory for creating {@link DataTransfer} implementation objects.</p>
+ *
+ */
+public interface DataTransferFactory {
+
+ /**
+ * @return A new {@link DataTransfer} implementation.
+ */
+ public DataTransfer createDataTransfer();
+}
Added: oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/datatransfer/InPlaceDataTransferFactory.java
URL: http://svn.apache.org/viewvc/oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/datatransfer/InPlaceDataTransferFactory.java?rev=1052148&view=auto
==============================================================================
--- oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/datatransfer/InPlaceDataTransferFactory.java (added)
+++ oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/datatransfer/InPlaceDataTransferFactory.java Thu Dec 23 02:48:02 2010
@@ -0,0 +1,42 @@
+/*
+ * 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.datatransfer;
+
+/**
+ * @author woollard
+ * @version $Revision$
+ *
+ * <p>Creates new {@link InPlaceDataTransferer}s.</p>
+ *
+ */
+public class InPlaceDataTransferFactory implements DataTransferFactory {
+
+ /**
+ * <p>Default Constructor</p>
+ */
+ public InPlaceDataTransferFactory() {
+ super();
+ }
+
+ /* (non-Javadoc)
+ * @see gov.nasa.jpl.oodt.cas.datatransfer.DataTransferFactory#createDataTransfer()
+ */
+ public DataTransfer createDataTransfer() {
+ return new InPlaceDataTransferer();
+ }
+
+}
Added: oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/datatransfer/InPlaceDataTransferer.java
URL: http://svn.apache.org/viewvc/oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/datatransfer/InPlaceDataTransferer.java?rev=1052148&view=auto
==============================================================================
--- oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/datatransfer/InPlaceDataTransferer.java (added)
+++ oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/datatransfer/InPlaceDataTransferer.java Thu Dec 23 02:48:02 2010
@@ -0,0 +1,94 @@
+/*
+ * 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.datatransfer;
+
+//JDK imports
+import java.io.File;
+import java.io.IOException;
+import java.util.logging.Logger;
+import java.util.logging.Level;
+import java.net.URL;
+
+//OODT imports
+import org.apache.oodt.cas.filemgr.structs.Product;
+import org.apache.oodt.cas.filemgr.structs.exceptions.ConnectionException;
+import org.apache.oodt.cas.filemgr.structs.exceptions.DataTransferException;
+import org.apache.oodt.cas.filemgr.system.XmlRpcFileManagerClient;
+
+/**
+ * @author mattmann
+ * @version $Revision$
+ *
+ * <p>
+ * An implementation of the {@link DataTransfer} interface that leaves products
+ * in the same place (i.e., "in place") and doesn't transfer them at all.
+ * </p>
+ *
+ */
+public class InPlaceDataTransferer implements DataTransfer {
+
+ /* our log stream */
+ private static Logger LOG = Logger.getLogger(InPlaceDataTransferer.class
+ .getName());
+
+ /* file manager client */
+ private XmlRpcFileManagerClient client = null;
+
+ /**
+ * <p>
+ * Default Constructor
+ * </p>
+ */
+ public InPlaceDataTransferer() {
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see gov.nasa.jpl.oodt.cas.filemgr.datatransfer.DataTransfer#setFileManagerUrl(java.net.URL)
+ */
+ public void setFileManagerUrl(URL url) {
+ try {
+ client = new XmlRpcFileManagerClient(url);
+ LOG.log(Level.INFO, "In Place Data Transfer to: ["
+ + client.getFileManagerUrl().toString() + "] enabled");
+ } catch (ConnectionException e) {
+ LOG.log(Level.WARNING, "Connection exception for filemgr: [" + url
+ + "]");
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see gov.nasa.jpl.oodt.cas.datatransfer.DataTransfer#transferProduct(gov.nasa.jpl.oodt.cas.data.structs.Product)
+ */
+ public void transferProduct(Product product) throws DataTransferException,
+ IOException {
+ // do nothing
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see gov.nasa.jpl.oodt.cas.filemgr.datatransfer.DataTransfer#copyProduct(gov.nasa.jpl.oodt.cas.filemgr.structs.Product, java.io.File)
+ */
+ public void copyProduct(Product product, File directory) throws DataTransferException,
+ IOException {
+ // do nothing
+ }
+
+}
Added: oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/datatransfer/LocalDataTransferFactory.java
URL: http://svn.apache.org/viewvc/oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/datatransfer/LocalDataTransferFactory.java?rev=1052148&view=auto
==============================================================================
--- oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/datatransfer/LocalDataTransferFactory.java (added)
+++ oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/datatransfer/LocalDataTransferFactory.java Thu Dec 23 02:48:02 2010
@@ -0,0 +1,42 @@
+/*
+ * 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.datatransfer;
+
+/**
+ * @author mattmann
+ * @version $Revision$
+ *
+ * <p>Creates new {@link LocalDataTransferer}s.</p>
+ *
+ */
+public class LocalDataTransferFactory implements DataTransferFactory {
+
+ /**
+ * <p>Default Constructor</p>
+ */
+ public LocalDataTransferFactory() {
+ super();
+ }
+
+ /* (non-Javadoc)
+ * @see gov.nasa.jpl.oodt.cas.datatransfer.DataTransferFactory#createDataTransfer()
+ */
+ public DataTransfer createDataTransfer() {
+ return new LocalDataTransferer();
+ }
+
+}