/** * <p> * Copy Constructor * </p> * * @param r * The Reference object to copy */ public Reference(Reference r) { this(r.getOrigReference(), r.getDataStoreReference(), r.getFileSize(), r.getMimeType()); }
public static Reference getReference(ResultSet rs) throws SQLException { Reference r = new Reference(); r.setOrigReference(rs.getString("product_orig_reference")); r.setDataStoreReference(rs.getString("product_datastore_reference")); r.setFileSize(rs.getLong("product_reference_filesize")); r.setMimeType(rs.getString("product_reference_mimetype")); return r; }
private void addProductDateTimeToReferences(List<Reference> references, String productionDateTime) { for (Reference r : references) { if (!r.getOrigReference().endsWith("/")) { r.setDataStoreReference(r.getDataStoreReference() + "." + productionDateTime); } } }
if (r.getDataStoreReference().equals( new File(newPath).toURI().toString())) { throw new DataTransferException("cannot move product: [" + p.getProductName() + "] to same location: [" + r.getDataStoreReference() + "]"); Reference copyRef = new Reference(r); copyRef.setOrigReference(r.getDataStoreReference()); copyRef.setDataStoreReference(new File(newPath).toURI().toString()); if (!new File(new URI(copyRef.getOrigReference())).delete()) { LOG.log(Level.WARNING, "Deletion of original file: [" + r.getDataStoreReference() + "] on product move returned false");
@Override public void execute(ActionMessagePrinter printer) throws CmdLineActionException { try (FileManagerClient client = getClient()) { FileTransferStatus status = client.getCurrentFileTransfer(); if (status == null) { throw new NullPointerException( "FileManager returned null transfer status"); } printer.println("File Transfer: [ref={orig=" + status.getFileRef().getOrigReference() + ",ds=" + status.getFileRef().getDataStoreReference() + "},product=" + status.getParentProduct().getProductName() + ",fileSize=" + status.getFileRef().getFileSize() + ",amtTransferred=" + status.getBytesTransferred() + ",pct=" + status.computePctTransferred() + "]"); } catch (Exception e) { throw new CmdLineActionException( "Failed to get current file transfer : " + e.getMessage(), e); } } }
@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)))); } catch (DataTransferException e) { LOG.log(Level.WARNING, "Unable to determine product reference size: Reason: " + e.getMessage()); refItem.add(new Label("ref_pct_transferred", "N/A")); } } });
private boolean isDir(Reference r) { File fileRef; try { fileRef = new File(new URI(r.getDataStoreReference())); return fileRef.isDirectory(); } catch (URISyntaxException e) { return false; } } }
private void moveFile(Reference r, boolean log) throws IOException, URISyntaxException { if (log) { LOG.log(Level.INFO, "LocalDataTransfer: Moving File: " + r.getOrigReference() + " to " + r.getDataStoreReference()); } File srcFileRef = new File(new URI(r.getOrigReference())); File destFileRef = new File(new URI(r.getDataStoreReference())); FileUtils.copyFile(srcFileRef, destFileRef); }
public void createDataStoreReferences(Product product, Metadata metadata) throws VersioningException { // first generate the first correct reference super.createDataStoreReferences(product, metadata); Reference root = (Reference) product.getProductReferences().get(0); if (!root.getDataStoreReference().endsWith("/")) { root.setDataStoreReference(root.getDataStoreReference() + "/"); } // now add the heirarchical refs VersioningUtils.createBasicDataStoreRefsHierarchical(product .getProductReferences()); }
@VisibleForTesting static Product createProduct(URI path) { Product product = new Product(); product.setProductStructure(Product.STRUCTURE_FLAT); //TODO: only support flat prods for now Reference reference = new Reference(); reference.setDataStoreReference(path.toString()); product.setProductReferences(Lists.newArrayList(reference)); return product; } }
public static void createDataStoreRefStream(String pn, String productRepoPath, Reference ref, String postfix) { URI uri = URI.create(ref.getOrigReference()); String[] parts = (postfix.equals(""))?new String[] {uri.toString()}:new String[] {uri.toString(),postfix}; ref.setDataStoreReference(StringUtils.join(parts,Reference.STREAM_REFERENCE_DELIMITER)); } public static void addRefsFromUris(Product p, List<String> uris) {
public static boolean isRootDir(Reference r, String prodName) { if (!r.getOrigReference().endsWith("/")) { return false; } else { String referenceURI = r.getOrigReference(); int lastFolderInPathStartIdx = referenceURI .substring(0, referenceURI.length() - 1).lastIndexOf("/") + 1; String lastFolderInPath = referenceURI.substring(lastFolderInPathStartIdx, referenceURI.length() - 1); return lastFolderInPath.startsWith(prodName); } }
/** * * @return The percentage of the file that has been transferred so far. */ public double computePctTransferred() { return ((double) (bytesTransferred * 1.0) / (fileRef.getFileSize() * 1.0)); }
Reference r = new Reference(); r.setOrigReference(dir.toURL().toExternalForm()); r.setFileSize(dir.length()); references.add(r); } catch (MalformedURLException e) { Reference r = new Reference(); r.setOrigReference(file.toURL().toExternalForm()); r.setFileSize(file.length()); references.add(r); } catch (MalformedURLException e) {
@Override 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( "Failed to get percent transfered for" + " file '" + origRef + "' : " + e.getMessage(), e); } }
private void scrubRefs(Product p) { if (p.getProductReferences() == null) { return; } for (Reference r : p.getProductReferences()) { r.setDataStoreReference(""); } }
public static void addRefsFromUris(Product p, List<String> uris) { // add the refs to the Product for (String ref : uris) { Reference r = new Reference(ref, null, (p.getProductStructure().equals(Product.STRUCTURE_STREAM) ? -1 : quietGetFileSizeFromUri(ref))); p.getProductReferences().add(r); } }
public Metadata doExtract(Product product, Metadata met) throws MetExtractionException { Metadata extractMet = new Metadata(); merge(met, extractMet); if (product.getProductStructure().equals(Product.STRUCTURE_FLAT)) { Reference prodRef = (Reference) product.getProductReferences().get( 0); extractMet.addMetadata(MIME_TYPE, prodRef.getMimeType().getName()); extractMet.addMetadata(MIME_TYPE, prodRef.getMimeType() .getType().getType()); extractMet.addMetadata(MIME_TYPE, prodRef.getMimeType() .getType().getSubtype()); } return extractMet; }
if (r.getDataStoreReference().equals( new File(newPath).toURI().toString())) { throw new DataTransferException("cannot move product: [" + p.getProductName() + "] to same location: [" + r.getDataStoreReference() + "]"); Reference copyRef = new Reference(r); copyRef.setOrigReference(r.getDataStoreReference()); copyRef.setDataStoreReference(new File(newPath).toURI().toString()); if (!new File(new URI(copyRef.getOrigReference())).delete()) { LOG.log(Level.WARNING, "Deletion of original file: [" + r.getDataStoreReference() + "] on product move returned false");
private void addProductDateTimeToReferences(List<Reference> references, String productionDateTime) { for (Reference r : references) { if (!r.getOrigReference().endsWith("/")) { r.setDataStoreReference(r.getDataStoreReference() + "." + productionDateTime); } } }