Package org.apache.oodt.cas.metadata

Examples of org.apache.oodt.cas.metadata.Metadata


    cs.addCatalog(catalogFactory.createCatalog());
  }
 
  public void testDataSourceCatalogIngestQueryAndDelete() throws CatalogServiceException, ParseException, TokenMgrError {
    //test ingest
    Metadata m = new Metadata();
    m.addMetadata("testkey1", "testval1");
    TransactionReceipt tr = cs.ingest(m);
    Vector<TransactionReceipt> receipts = new Vector<TransactionReceipt>();
    receipts.add(tr);
    List<TransactionalMetadata> metadatas = cs.getMetadata(receipts);
    assertEquals(metadatas.size(), 1);
    Metadata ingestedMetadata = metadatas.get(0).getMetadata();
    assertEquals(ingestedMetadata.getMetadata("testkey1"), "testval1");
    assertEquals(ingestedMetadata.getAllMetadata("testkey1").size(), 2);

    //test ingest update
    m.replaceMetadata(CatalogServiceLocal.CATALOG_SERVICE_TRANSACTION_ID_MET_KEY.toString(), tr.getTransactionId().toString());
    m.replaceMetadata(CatalogServiceLocal.ENABLE_UPDATE_MET_KEY, "true");
    tr = cs.ingest(m);
    receipts = new Vector<TransactionReceipt>();
    receipts.add(tr);
    metadatas = cs.getMetadata(receipts);
    assertEquals(metadatas.size(), 1);
    ingestedMetadata = metadatas.get(0).getMetadata();
    assertEquals(ingestedMetadata.getMetadata("testkey1"), "testval1");
    assertEquals(ingestedMetadata.getAllMetadata("testkey1").size(), 2);

    //test query using querypager
    QueryExpression qe = QueryParser.parseQueryExpression("testkey1 == 'testval1'");
    QueryPager pager = cs.query(qe);
    metadatas = cs.getNextPage(pager);
    assertEquals(metadatas.size(), 1);
    ingestedMetadata = metadatas.get(0).getMetadata();
    assertEquals(ingestedMetadata.getMetadata("testkey1"), "testval1");
    assertEquals(ingestedMetadata.getAllMetadata("testkey1").size(), 2);

    //test query using std paging
    qe = QueryParser.parseQueryExpression("testkey1 == 'testval1'");
    Page page = cs.getPage(new PageInfo(20, PageInfo.FIRST_PAGE), qe);
    metadatas = cs.getMetadata(page);
    assertEquals(metadatas.size(), 1);
    ingestedMetadata = metadatas.get(0).getMetadata();
    assertEquals(ingestedMetadata.getMetadata("testkey1"), "testval1");
    assertEquals(ingestedMetadata.getAllMetadata("testkey1").size(), 2);

    //test query using std paging with catalog restriction
    qe = QueryParser.parseQueryExpression("testkey1 == 'testval1'");
    page = cs.getPage(new PageInfo(20, PageInfo.FIRST_PAGE), qe, Collections.singleton("TestCatalog1"));
    metadatas = cs.getMetadata(page);
    assertEquals(metadatas.size(), 1);
    ingestedMetadata = metadatas.get(0).getMetadata();
    assertEquals(ingestedMetadata.getMetadata("testkey1"), "testval1");
    assertEquals(ingestedMetadata.getAllMetadata("testkey1").size(), 1);

    //test delete
    m = new Metadata();
    m.addMetadata(CatalogServiceLocal.CATALOG_SERVICE_TRANSACTION_ID_MET_KEY.toString(), tr.getTransactionId().toString());
    cs.delete(m);
    assertEquals(cs.getMetadata(Collections.singletonList(tr)).size(), 0);
  }
View Full Code Here


  }
 
  public List<TransactionalMetadata> getMetadata(List<TransactionReceipt> transactionReceipts) throws CatalogServiceException {
    LinkedHashSet<TransactionalMetadata> metadataSet = new LinkedHashSet<TransactionalMetadata>();
    for (TransactionReceipt transactionReceipt : transactionReceipts) {
      Metadata metadata = new Metadata();
      Vector<CatalogReceipt> successfulCatalogReceipts = new Vector<CatalogReceipt>();
      for (CatalogReceipt catalogReceipt : transactionReceipt.getCatalogReceipts()) {
        try {
          Catalog catalog = this.getCatalog(catalogReceipt.getCatalogId());
          metadata.addMetadata(catalog.getMetadata(catalogReceipt.getTransactionId()));
          successfulCatalogReceipts.add(catalogReceipt);
        }catch (Exception e) {
          if (this.oneCatalogFailsAllFail)
            throw new CatalogServiceException("Failed to get metadata for transaction ids for catalog '" + catalogReceipt.getCatalogId() + "' : " + e.getMessage(), e);
          else
            LOG.log(Level.WARNING, "Failed to get metadata for transaction ids for catalog '" + catalogReceipt.getCatalogId() + "' : " + e.getMessage(), e);
        }
      }
      if (metadata.getHashtable().keySet().size() > 0)
        metadataSet.add(new TransactionalMetadata(new TransactionReceipt(transactionReceipt.getTransactionId(), successfulCatalogReceipts), metadata));
    }
    return new Vector<TransactionalMetadata>(metadataSet);
  }
View Full Code Here

  }
 
  public List<TransactionalMetadata> getMetadataFromTransactionIds(List<TransactionId<?>> catalogServiceTransactionIds) throws CatalogServiceException {
    LinkedHashSet<TransactionalMetadata> metadataSet = new LinkedHashSet<TransactionalMetadata>();
    for (TransactionId<?> catalogServiceTransactionId : catalogServiceTransactionIds) {
      Metadata metadata = new Metadata();
      Vector<CatalogReceipt> catalogReceipts = new Vector<CatalogReceipt>();
      for (Catalog catalog : this.getCurrentCatalogList()) {
        try {
          CatalogReceipt catalogReceipt = this.ingestMapper.getCatalogReceipt(catalogServiceTransactionId, catalog.getId());
          if (catalogReceipt != null) {
            metadata.addMetadata(catalog.getMetadata(catalogReceipt.getTransactionId()).getHashtable());
            catalogReceipts.add(catalogReceipt);
          }
        }catch (Exception e) {
          if (this.oneCatalogFailsAllFail)
            throw new CatalogServiceException("Failed to get metadata for transaction ids for catalog '" + catalog.getId() + "' : " + e.getMessage(), e);
          else
            LOG.log(Level.WARNING, "Failed to get metadata for transaction ids for catalog '" + catalog.getId() + "' : " + e.getMessage(), e);
        }
      }
      if (metadata.getHashtable().keySet().size() > 0)
        metadataSet.add(new TransactionalMetadata(new TransactionReceipt(catalogServiceTransactionId, catalogReceipts), metadata));
    }
    return new Vector<TransactionalMetadata>(metadataSet);
  }
View Full Code Here

   * org.apache.oodt.cas.metadata.AbstractMetExtractor#extrMetadata(java.io
   * .File)
   */
  @Override
  protected Metadata extrMetadata(File file) throws MetExtractionException {
    Metadata met = getCoreMet(file);
    addCommonMetadata(met);
    return met;
  }
View Full Code Here

  }

  private Metadata getCoreMet(File file) {
    PGEGroup substrOffsetGroup = getConf().getPgeSpecificGroups().get(
        SUBSTRING_OFFSET_GROUP);
    Metadata met = new Metadata();
    String filename = file.getName();

    for (PGEVector vec : substrOffsetGroup.getVectors().values()) {
      String metKeyName = vec.getName();
      LOG.log(Level.FINE, "Extracting key: ["+metKeyName+"]");
      int offset = Integer.valueOf((String) vec.getElements().get(0)) - 1;
      int length = Integer.valueOf((String) vec.getElements().get(1));
      String metVal = filename.substring(offset, offset + length).trim();
      met.addMetadata(metKeyName, metVal);
    }

    return met;
  }
View Full Code Here

                    + e.getMessage(), e);
        }
    }

    private Metadata getMetadata(Product product) {
        Metadata met = null;

        try {
            met = this.fmClient.getMetadata(product);
        } catch (Exception e) {
            throw new RuntimeException("Unable to get metadata for product: ["
View Full Code Here

    public void dumpProduct(String productId, String outDirPath) {
        Product product = getProduct(productId);
        String fullProdFilePath = outDirPath;
        fullProdFilePath = (fullProdFilePath.endsWith("/")) ? fullProdFilePath
                : fullProdFilePath + "/";
        Metadata met = getMetadata(product);
        String filename = met.getMetadata(FILENAME) != null ? met
                .getMetadata(FILENAME) : met.getMetadata(PRODUCT_NAME);
        fullProdFilePath += filename + ".product";
        writeProductFileToDir(product, fullProdFilePath);
    }
View Full Code Here

    public Metadata getMetadata(Product product) throws CatalogException {
        Connection conn = null;
        Statement statement = null;
        ResultSet rs = null;
        Metadata m = null;

        try {
            conn = dataSource.getConnection();
            statement = conn.createStatement();

            String metadataSql = "SELECT * FROM "
                    + product.getProductType().getName() + "_metadata "
                    + " WHERE product_id = " + product.getProductId();

            LOG.log(Level.FINE, "getMetadata: Executing: " + metadataSql);
            rs = statement.executeQuery(metadataSql);
           
            m = new Metadata();
            List<Element> elements = null;

            try {
                elements = validationLayer.getElements(product.getProductType());
            } catch (ValidationLayerException e) {
                e.printStackTrace();
                throw new CatalogException(
                        "ValidationLayerException when trying to obtain element list for product type: "
                                + product.getProductType().getName()
                                + ": Message: " + e.getMessage());
            }

            while (rs.next()) {
                for (Iterator<Element> i = elements.iterator(); i.hasNext();) {
                    Element e = i.next();

                    // right now, we just support STRING
                    String elemValue = rs.getString("metadata_value");
                    String elemId = rs.getString("element_id");

                    if (elemId.equals(e.getElementId())) {
                        elemValue = (elemValue != null ? elemValue : "");
                        m.addMetadata(e.getElementName(), elemValue);
                    }
                }
            }

        } catch (Exception e) {
View Full Code Here

   
    public Metadata getReducedMetadata(Product product, List<String> elems) throws CatalogException {
        Connection conn = null;
        Statement statement = null;
        ResultSet rs = null;
        Metadata m = null;

        try {
            conn = dataSource.getConnection();
            statement = conn.createStatement();

            String elementIds = "";
            if (elems.size() > 0) {
                elementIds += " AND (element_id = '" + this.validationLayer.getElementByName(elems.get(0)).getElementId() + "'";
                for (int i = 1; i < elems.size(); i++)
                    elementIds += " OR element_id = '" + this.validationLayer.getElementByName(elems.get(i)).getElementId() + "'";
                elementIds += ")";
            }
            String metadataSql = "SELECT element_id,metadata_value FROM "
                    + product.getProductType().getName() + "_metadata"
                    + " WHERE product_id = " + product.getProductId() + elementIds;

            LOG.log(Level.FINE, "getMetadata: Executing: " + metadataSql);
            rs = statement.executeQuery(metadataSql);

            m = new Metadata();
            List<Element> elements = null;

            try {
                elements = validationLayer.getElements(product.getProductType());
            } catch (ValidationLayerException e) {
                e.printStackTrace();
                throw new CatalogException(
                        "ValidationLayerException when trying to obtain element list for product type: "
                                + product.getProductType().getName()
                                + ": Message: " + e.getMessage());
            }

            while (rs.next()) {
                for (Iterator<Element> i = elements.iterator(); i.hasNext();) {
                    Element e = i.next();

                    // right now, we just support STRING
                    String elemValue = rs.getString("metadata_value");
                    String elemId = rs.getString("element_id");

                    if (elemId.equals(e.getElementId())) {
                        elemValue = (elemValue != null ? elemValue : "");
                        m.addMetadata(e.getElementName(), elemValue);
                    }
                }
            }

        } catch (Exception e) {
View Full Code Here

  private void deliverProductAsZip(HttpServletRequest req,
      HttpServletResponse res, String productID) throws CatalogException {
    Product product = client.getProductById(productID);
    product.setProductReferences(client.getProductReferences(product));
    Metadata metadata = client.getMetadata(product);

    // we'll be delivering a zip
    res.addHeader(CONTENT_TYPE_HDR, FORMAT_ZIP);

    String productZipFilePath = null;
View Full Code Here

TOP

Related Classes of org.apache.oodt.cas.metadata.Metadata

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.