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

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


   public void execute(ActionMessagePrinter printer)
         throws CmdLineActionException {
      try {
         Validate.notNull(origRef, "Must specify origRef");

         Reference ref = new Reference();
         ref.setOrigReference(getUri(origRef).toString());

         printer.println("Reference: [origRef=" + origRef + ",transferPct="
               + getClient().getRefPctTransferred(ref) + "]");
      } catch (Exception e) {
         throw new CmdLineActionException(
View Full Code Here


      }

      String productName = null;
      String productRepo = null;
      String transferType = null;
      Reference dirReference = null;

      List<Reference> fileReferences = null;

      for (int i = 0; i < args.length; i++) {
         if (args[i].equals("--dir")) {
            transferType = "dir";
            dirReference = new Reference();
            dirReference.setOrigReference(new File(new URI(args[++i])).toURI()
                  .toString());
            LOG.log(Level.FINER,
                  "LocalFileTransfer.main: Generated orig reference: "
                        + dirReference.getOrigReference());
         } else if (args[i].equals("--files")) {
            transferType = "files";
            fileReferences = new Vector<Reference>();
            for (int j = i + 1; j < args.length; j++) {
               LOG.log(Level.FINER, "LocalFileTransfer.main: Adding file ref: "
                     + args[j]);
               fileReferences.add(new Reference(args[j], null,
                     new File(args[j]).length(), mimeTypeRepo
                           .getMimeType(args[j])));
            }
         } else if (args[i].equals("--productName")) {
            productName = args[++i];
         } else if (args[i].equals("--productRepo")) {
            productRepo = args[++i];
         }
      }

      if (transferType == null
            || (transferType != null && ((transferType.equals("dir") && dirReference == null)
                  || (transferType.equals("files") && fileReferences == null)
                  || (transferType != null && !(transferType.equals("dir") || transferType
                        .equals("files"))) || productName == null || productRepo == null))) {
         System.err.println(usage);
         System.exit(1);
      }

      // construct a new Product
      Product p = new Product();
      p.setProductName(productName);

      if (transferType.equals("dir")) {
         p.setProductStructure(Product.STRUCTURE_HIERARCHICAL);
         dirReference.setDataStoreReference(new File(new URI(productRepo))
               .toURI().toURL().toExternalForm()
               + URLEncoder.encode(p.getProductName(), "UTF-8") + "/");
         p.getProductReferences().add(dirReference);
         /* we'll do a simple versioning scheme ourselves: no versioning! */
         p.getProductReferences().addAll(
               VersioningUtils.getReferencesFromDir(new File(new URI(
                     dirReference.getOrigReference()))));
         VersioningUtils.createBasicDataStoreRefsHierarchical(p
               .getProductReferences());
      } else if (transferType.equals("files")) {
         p.setProductStructure("Flat");
         p.getProductReferences().addAll(fileReferences);
View Full Code Here

   }

   private void copyDirToDir(Product product, File directory)
         throws IOException, URISyntaxException {
      Reference dirRef = (Reference) product.getProductReferences().get(0);
      LOG.log(
            Level.INFO,
            "LocalDataTransferer: Staging Directory: "
                  + dirRef.getDataStoreReference() + " into directory "
                  + directory.getAbsolutePath());

      for (Iterator<Reference> i = product.getProductReferences().iterator(); i
            .hasNext();) {
         Reference r = i.next();
         File fileRef = new File(new URI(r.getDataStoreReference()));

         if (fileRef.isFile()) {
            copyFile(r, directory);
         } else if (fileRef.isDirectory()
               && (fileRef.list() != null && fileRef.list().length == 0)) {
View Full Code Here

      }
   }

   private void moveDirToProductRepo(Product product) throws IOException,
         URISyntaxException {
      Reference dirRef = (Reference) product.getProductReferences().get(0);
      LOG.log(
            Level.INFO,
            "LocalDataTransferer: Moving Directory: "
                  + dirRef.getOrigReference() + " to "
                  + dirRef.getDataStoreReference());

      // notify the file manager that we started
      quietNotifyTransferProduct(product);

      for (Iterator<Reference> i = product.getProductReferences().iterator(); i
            .hasNext();) {
         Reference r = i.next();
         File fileRef = new File(new URI(r.getOrigReference()));

         if (fileRef.isFile()) {
            moveFile(r, false);
         } else if (fileRef.isDirectory()
               && (fileRef.list() != null && fileRef.list().length == 0)) {
            // if it's a directory and it doesn't exist yet, we should
            // create it
            // just in case there's no files in it
             if (!new File(new URI(r.getDataStoreReference())).exists()) {
                 LOG.log(Level.FINER, "Directory: [" + r.getDataStoreReference()
                         + "] doesn't exist: creating it");
                 try {
                     FileUtils.forceMkdir(new File(new URI(r.getDataStoreReference())));
                 }
                 catch(IOException e){
                     LOG.log(
                             Level.WARNING,
                             "Unable to create directory: ["
                                     + r.getDataStoreReference()
                                     + "] in local data transferer");
                 }
             }
         }
      }
View Full Code Here

      // notify the file manager that we started
      quietNotifyTransferProduct(product);

      for (Iterator<Reference> i = refs.iterator(); i.hasNext();) {
         Reference r = (Reference) i.next();
         moveFile(r, true);
      }

      // notify the file manager that we're done
      quietNotifyProductTransferComplete(product);
View Full Code Here

   private void copyFilesToDir(Product product, File directory)
         throws IOException, URISyntaxException {
      List<Reference> refs = product.getProductReferences();
      for (Iterator<Reference> i = refs.iterator(); i.hasNext();) {
         Reference r = (Reference) i.next();
         copyFile(r, directory);
      }
   }
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

            }

            // get the first reference, it tells us what directory to move it
            // to
            // TODO: fix that hack :-)
            Reference r = (Reference) product.getProductReferences().get(0);

            String dataStoreRef = null;

            try {
                dataStoreRef = new File(new URI(productRepoPath)).toURL()
                        .toExternalForm();
                if(!dataStoreRef.endsWith("/")){
                  dataStoreRef+="/";
                }
               
                dataStoreRef+= URLEncoder.encode(productName, "UTF-8") + "/";
                LOG.log(Level.INFO, "BasicVersioner: generated DataStore ref: "
                        + dataStoreRef + " from origRef: "
                        + r.getOrigReference());
                r.setDataStoreReference(dataStoreRef);
                VersioningUtils.createBasicDataStoreRefsHierarchical(product
                        .getProductReferences());
            } catch (URISyntaxException e) {
                LOG.log(Level.WARNING,
                        "BasicVersioner: URISyntaxException while generating initial "
                                + "data store ref for origRef: "
                                + r.getOrigReference());
                throw new VersioningException(e);
            } catch (MalformedURLException e) {
                LOG.log(Level.WARNING,
                        "BasicVersioner: MalformedURLException while generating initial "
                                + "data store ref for origRef: "
                                + r.getOrigReference());
                throw new VersioningException(e);
            } catch (UnsupportedEncodingException e) {
                LOG.log(Level.WARNING,
                        "BasicVersioner: UnsupportedEncodingException while generating "
                                + "initial data store ref for origRef: "
                                + r.getOrigReference());
                throw new VersioningException(e);
            }

        } else if (product.getProductStructure().equals(Product.STRUCTURE_FLAT)) {
            // just use the VersioningUtils
View Full Code Here

            if ((origRefs.length == dataStoreRefs.length)
                    && (origRefs.length == refLengths.length)) {
                List<Reference> references = new Vector<Reference>();
                for (int i = 0; i < origRefs.length; i++) {
                    Reference r = new Reference();
                    r.setOrigReference(origRefs[i]);
                    r.setDataStoreReference(dataStoreRefs[i]);
                    r.setFileSize((Long.parseLong(refLengths[i])));
                    if (refMimeTypes != null)
                        r.setMimeType(refMimeTypes[i]);
                    references.add(r);
                }

                product.setProductReferences(references);
            } else {
View Full Code Here

        }

        // add the product references
        for (Iterator<Reference> i = product.getProductReferences().iterator(); i
                .hasNext();) {
            Reference r = i.next();
            doc.add(new Field("reference_orig", r.getOrigReference(),
                    Field.Store.YES, Field.Index.NO));
            doc
                    .add(new Field("reference_data_store", r
                            .getDataStoreReference(), Field.Store.YES,
                            Field.Index.NO));
            doc.add(new Field("reference_fileSize", String.valueOf(r
                    .getFileSize()), Field.Store.YES, Field.Index.NO));
            doc.add(new Field("reference_mimeType", r.getMimeType() != null ? r
                    .getMimeType().getName() : "", Field.Store.YES,
                    Field.Index.UN_TOKENIZED));
        }

        // add special field for all products
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.