Package org.apache.oodt.cas.filemgr.structs

Examples of org.apache.oodt.cas.filemgr.structs.Reference


    private boolean hasMetadataAndRefs(CompleteProduct cp) {
        if (cp.getMetadata() != null && cp.getProduct() != null) {
            if (cp.getReferences() != null && cp.getReferences().size() > 0) {
                // make sure there is a data store ref for each of the refs
                for (Iterator<Reference> i = cp.getReferences().iterator(); i.hasNext();) {
                    Reference r = i.next();
                    if (r.getDataStoreReference() == null
                            || (r.getDataStoreReference() != null && r
                                    .getDataStoreReference().equals(""))) {
                        return false;
                    }
                }
View Full Code Here


    try
    {
      XmlRpcFileManagerClient client = getContextClient();
      for (FileTransferStatus status : client.getCurrentFileTransfers())
      {
        Reference reference = status.getFileRef();
        if (dataStoreRef.equals(reference.getDataStoreReference()))
        {
          Product product = status.getParentProduct();
          Metadata metadata = client.getMetadata(product);
          return new TransferResource(product, metadata, status);
        }
View Full Code Here

    CompleteProduct cp = new CompleteProduct();
    Product product = cp.getProduct();
    ProductType productType = product.getProductType();
    Metadata metadata = cp.getMetadata();
    List<Reference> references = product.getProductReferences();
    Reference rootReference = product.getRootRef();
   
    NodeList children = doc.getChildNodes();
    for (int j=0; j<children.getLength(); j++) {
     
      Node child = children.item(j);
      Element element = (Element)child;
      String name = element.getAttribute("name");
     
      /**
       *<arr name="ScanPointingSource">
       <str>G073.65+0.19</str>
       <str>J2015+3410</str>
       *  ..........
       */
      if (child.getNodeName().equals("arr")) {
       
        NodeList values = element.getChildNodes();
        List<String> vals = new ArrayList<String>();
        for (int k=0; k<values.getLength(); k++) {
          String value = ((Element)values.item(k)).getTextContent();
          vals.add(value);
        }
        // CAS.reference.... fields
        if (name.startsWith(Parameters.NS)) {         
            for (int k=0; k<values.getLength(); k++) {
              // create this reference
              if (references.size()<=k) references.add(new Reference());
              if (name.equals(Parameters.REFERENCE_ORIGINAL)) {
                references.get(k).setOrigReference(vals.get(k));
              } else if (name.equals(Parameters.REFERENCE_DATASTORE)) {
                references.get(k).setDataStoreReference(vals.get(k));
              } else if (name.equals(Parameters.REFERENCE_FILESIZE)) {
                references.get(k).setFileSize(Long.parseLong(vals.get(k)));
              } else if (name.equals(Parameters.REFERENCE_MIMETYPE)) {
                references.get(k).setMimeType(vals.get(k));
              }
            }
        // all other multi-valued fields
        } else {
          this.deserializeMultiValueField(name, vals, metadata);
        }
       
      /**
       *   <str name="id">6684d79d-a011-4bc0-b3b3-4f11817091c8</str>
       <str name="CAS.ProductId">6684d79d-a011-4bc0-b3b3-4f11817091c8</str>
       <str name="CAS.ProductName">tns_br145x4_20</str>
       <str name="FileLocation">/usr/local/ska-dc/data/archive</str>
       *  ...........
       */
      } else {
       
        String value = element.getTextContent();
       
        // core CAS fields
        if (name.startsWith(Parameters.NS)) {
          if (name.equals(Parameters.PRODUCT_ID)) {
            product.setProductId(value);
          } else if (name.equals(Parameters.PRODUCT_NAME)) {
            product.setProductName(value);
          } else if (name.equals(Parameters.PRODUCT_STRUCTURE)) {
            product.setProductStructure(value);
          } else if (name.equals(Parameters.PRODUCT_TRANSFER_STATUS)) {
            product.setTransferStatus(value);
          } else if (name.equals(Parameters.PRODUCT_TYPE_NAME)) {
            productType.setName(value);
          } else if (name.equals(Parameters.PRODUCT_TYPE_ID)) {
            productType.setProductTypeId(value);
          } else if (name.equals(Parameters.PRODUCT_RECEIVED_TIME)) {
            // ignore ?
           
          // CAS root reference
          } else if (name.startsWith(Parameters.NS+Parameters.ROOT)) {
            if (rootReference==null) rootReference = new Reference();
            if (name.equals(Parameters.ROOT_REFERENCE_ORIGINAL)) {
              rootReference.setOrigReference(value);
            } else if (name.equals(Parameters.ROOT_REFERENCE_DATASTORE)) {
              rootReference.setDataStoreReference(value);
            } else if (name.equals(Parameters.ROOT_REFERENCE_FILESIZE)) {
              rootReference.setFileSize(Long.parseLong(value));
            } else if (name.equals(Parameters.ROOT_REFERENCE_MIMETYPE)) {
              rootReference.setMimeType(value);
            }

          }
         
        // non core single-valued fields
View Full Code Here

        double pct = transferStatusTracker.getPctTransferred(product);
        return pct;
    }

    public double getRefPctTransferred(Hashtable<String, Object> refHash) {
        Reference reference = XmlRpcStructFactory
                .getReferenceFromXmlRpc(refHash);
        double pct = 0.0;

        try {
            pct = transferStatusTracker.getPctTransferred(reference);
        } catch (Exception e) {
            e.printStackTrace();
            LOG.log(Level.WARNING,
                    "Exception getting transfer percentage for ref: ["
                            + reference.getOrigReference() + "]: Message: "
                            + e.getMessage());
        }
        return pct;
    }
View Full Code Here

                        "Flat products must have a single reference: cannot move");
            }

            // okay, it's fine to move it
            // first, we need to update the data store ref
            Reference r = (Reference) p.getProductReferences().get(0);
            if (r.getDataStoreReference().equals(
                    new File(newPath).toURI().toString())) {
                throw new DataTransferException("cannot move product: ["
                        + p.getProductName() + "] to same location: ["
                        + r.getDataStoreReference() + "]");
            }

            // create a copy of the current data store path: we'll need it to
            // do the data transfer
            Reference copyRef = new Reference(r);

            // update the copyRef to have the data store ref as the orig ref
            // the the newLoc as the new ref
            copyRef.setOrigReference(r.getDataStoreReference());
            copyRef.setDataStoreReference(new File(newPath).toURI().toString());

            p.getProductReferences().clear();
            p.getProductReferences().add(copyRef);

            // now transfer it
            try {
                this.dataTransfer.transferProduct(p);
            } catch (IOException e) {
                throw new DataTransferException(e.getMessage());
            }

            // now delete the original copy
            try {
                if (!new File(new URI(copyRef.getOrigReference())).delete()) {
                    LOG.log(Level.WARNING, "Deletion of original file: ["
                            + r.getDataStoreReference()
                            + "] on product move returned false");
                }
            } catch (URISyntaxException e) {
View Full Code Here

    }

    public boolean removeFile(String filePath) throws DataTransferException, IOException {
      // TODO(bfoster): Clean this up so that it deletes by product not file.
      Product product = new Product();
      Reference r = new Reference();
      r.setDataStoreReference(filePath);
      product.setProductReferences(Lists.newArrayList(r));
      dataTransfer.deleteProduct(product);
      return true;
    }
View Full Code Here

            .size() == 0)) {
      return "N/A";
    }

    // get the first ref
    Reference r = (Reference) prod.getProductReferences().get(0);
    return safeGetFileFromUri(r.getDataStoreReference()).getAbsolutePath();
  }
View Full Code Here

        FileManagerUtils.getRootReference(prodName, p.getProductReferences())
            .getOrigReference()).getAbsolutePath();
  }

  public static Reference getRootReference(String productName, List refs) {
    Reference r = null;

    for (Iterator i = refs.iterator(); i.hasNext();) {
      Reference ref = (Reference) i.next();
      if (isRootDir(ref, productName)) {
        r = ref;
      }
    }
View Full Code Here

  private void deliverProductFile(HttpServletRequest req,
      HttpServletResponse res, int index, String productID)
      throws CatalogException, IOException {
    Product product = client.getProductById(productID);
    List refs = client.getProductReferences(product);
    Reference ref = (Reference) refs.get(index);
    res.addHeader(CONTENT_LENGTH_HDR, String.valueOf(ref.getFileSize()));
    String contentType = (ref.getMimeType() != null
        && ref.getMimeType().getName() != null && !ref.getMimeType().getName()
        .equals("")) ? ref.getMimeType().getName() : DataUtils
        .guessTypeFromName(ref.getDataStoreReference());
    res.addHeader(CONTENT_TYPE_HDR, contentType);
    try {
      res.addHeader(CONTENT_DISPOSITION_HDR, "attachment; filename=\""
          + new File(new URI(ref.getDataStoreReference())).getName() + "\"");
    } catch (URISyntaxException e) {
      LOG.log(Level.WARNING,
          "Unable to sense filename from data store URI: Message: "
              + e.getMessage());
    }
    URL url = new URL(ref.getDataStoreReference());
    URLConnection c = url.openConnection();
    InputStream in = c.getInputStream();
    OutputStream out = res.getOutputStream();
    byte[] buf = new byte[512];
    int n;
View Full Code Here

         * org.apache.wicket.markup.html.list.ListView#populateItem(org.apache
         * .wicket.markup.html.list.ListItem)
         */
        @Override
        protected void populateItem(ListItem<Reference> refItem) {
          Reference r = refItem.getModelObject();
          String filePath = null;
          try {
            filePath = new File(new URI(r.getDataStoreReference()))
                .getAbsolutePath();
          } catch (Exception ignore) {
          }

          refItem.add(new Label("ref_file_path", filePath));
          refItem.add(new Label("ref_file_size", String
              .valueOf(r.getFileSize())));
          try {
            refItem.add(new Label("ref_pct_transferred", NumberFormat
                .getPercentInstance().format(
                   fm.getFm()
                        .getRefPctTransferred(r))));
View Full Code Here

TOP

Related Classes of org.apache.oodt.cas.filemgr.structs.Reference

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.