agave-apps/apps-core/src/main/java/org/iplantc/service/apps/queue/actions/CloneAction.java
/**
     * Copies the zip archive for the public {@link Software} instance to the local file system 
     * for unpacking and relaying to the cloned {@link Software#getDeploymentPath()}.
     * 
     * @return {@link File} reference to the location of the cached deployment path on the local system.
     * @throws IOException if unable to create temp dir or write data
     */
Copies the zip archive for the public  Software instance to the local file system
for unpacking and relaying to the cloned  Software#getDeploymentPath().

@return  File reference to the location of the cached deployment path on the local system.
@throws IOException if unable to create temp dir or write data
Copies the zip archive for the public Software instance to the local file system for unpacking and relaying to the cloned Software#getDeploymentPath () . @return File reference to the location of the cached deployment path on the local system . @throws IOException if unable to create temp dir or write data
protected File fetchPublicAppArchiveFromDeploymentSystem(RemoteDataClient sourceSoftwareDataClient) 
    throws IOException 
    {  
        File tempAppDir = Files.createTempDir();
        try {
            sourceSoftwareDataClient.get(getEntity().getDeploymentPath(), tempAppDir.getAbsolutePath());
        }
        catch (FileNotFoundException e) {
            throw new SoftwareException("The original application deployment path, "
                    + getEntity().getDeploymentPath() + ", was not found on the deployment system " 
                    + getEntity().getStorageSystem().getSystemId(), e);
        }
        catch (Exception e) {
            throw new SoftwareException("Failed to retrieve application assets from the original application storage system, " 
                    + getEntity().getStorageSystem().getSystemId(), e);
        }
        File copiedDeploymentFolder = new File(tempAppDir, FilenameUtils.getName(getEntity().getDeploymentPath()));
        if (!copiedDeploymentFolder.getAbsoluteFile().equals(tempAppDir) && copiedDeploymentFolder.exists() && copiedDeploymentFolder.isDirectory()) {
            FileUtils.copyDirectory(copiedDeploymentFolder, tempAppDir, null, true);
            FileUtils.deleteQuietly(copiedDeploymentFolder);
        }
        File zippedFile = new File(tempAppDir, FilenameUtils.getName(getEntity().getDeploymentPath()));
        String checksum = MD5Checksum.getMD5Checksum(zippedFile);
        if (getEntity().getChecksum() == null || StringUtils.equals(checksum, getEntity().getChecksum()))
        {
            ZipUtil.unzip(zippedFile, tempAppDir);
            if (tempAppDir.list().length > 1) {
                zippedFile.delete();
            } else {
                throw new SoftwareException("Failed to unpack the application bundle.");
            }
        } 
        else 
        {
            throw new SoftwareException("The checksum calculated for the current public app bundle " +
                    "does not match the value calculated when the app was originally published. " +
                    "This may indicate data corruption. If this problem persists, please contact your " +
                    "tenant administrator for help resolving the problem.");
        }
        File localDeploymentPath = new File(tempAppDir, FilenameUtils.getName(getEntity().getExecutablePath()));
        if (localDeploymentPath.exists()) {
            return tempAppDir;
        } 
        else
        {
            for (File child: tempAppDir.listFiles()) 
            {
                if (child.isDirectory()) {
                    File buriedWrapperTemplateFile = new File(child, getEntity().getExecutablePath());
                    if (buriedWrapperTemplateFile.exists()) {
                        File deploymentSubPath = Files.createTempDir();
                        FileUtils.moveDirectory(child, deploymentSubPath);
                        FileUtils.deleteDirectory(tempAppDir);
                        return deploymentSubPath;
                    }
                }
            }
            log.error("Unable to find deployment path for public app " + getEntity().getUniqueName() + " while attempting to clone the app.");
            throw new SoftwareException("Unable to find the deployment path for the public app " + getEntity().getUniqueName() + " while attempting to clone.");
        }
    }
protected File fetchPublicAppArchiveFromDeploymentSystem ( RemoteDataClient sourceSoftwareDataClient ) throws IOException { File tempAppDir = Files . createTempDir ( ) ; try { sourceSoftwareDataClient . get ( getEntity ( ) . getDeploymentPath ( ) , tempAppDir . getAbsolutePath ( ) ) ; } catch ( FileNotFoundException e ) { throw new SoftwareException ( "The original application deployment path, " + getEntity ( ) . getDeploymentPath ( ) + ", was not found on the deployment system " + getEntity ( ) . getStorageSystem ( ) . getSystemId ( ) , e ) ; } catch ( Exception e ) { throw new SoftwareException ( "Failed to retrieve application assets from the original application storage system, " + getEntity ( ) . getStorageSystem ( ) . getSystemId ( ) , e ) ; } File copiedDeploymentFolder = new File ( tempAppDir , FilenameUtils . getName ( getEntity ( ) . getDeploymentPath ( ) ) ) ; if ( ! copiedDeploymentFolder . getAbsoluteFile ( ) . equals ( tempAppDir ) && copiedDeploymentFolder . exists ( ) && copiedDeploymentFolder . isDirectory ( ) ) { FileUtils . copyDirectory ( copiedDeploymentFolder , tempAppDir , null , true ) ; FileUtils . deleteQuietly ( copiedDeploymentFolder ) ; } File zippedFile = new File ( tempAppDir , FilenameUtils . getName ( getEntity ( ) . getDeploymentPath ( ) ) ) ; String checksum = MD5Checksum . getMD5Checksum ( zippedFile ) ; if ( getEntity ( ) . getChecksum ( ) == null || StringUtils . equals ( checksum , getEntity ( ) . getChecksum ( ) ) ) { ZipUtil . unzip ( zippedFile , tempAppDir ) ; if ( tempAppDir . list ( ) . length > 1 ) { zippedFile . delete ( ) ; } else { throw new SoftwareException ( "Failed to unpack the application bundle." ) ; } } else { throw new SoftwareException ( "The checksum calculated for the current public app bundle " + "does not match the value calculated when the app was originally published. " + "This may indicate data corruption. If this problem persists, please contact your " + "tenant administrator for help resolving the problem." ) ; } File localDeploymentPath = new File ( tempAppDir , FilenameUtils . getName ( getEntity ( ) . getExecutablePath ( ) ) ) ; if ( localDeploymentPath . exists ( ) ) { return tempAppDir ; } else { for ( File child : tempAppDir . listFiles ( ) ) { if ( child . isDirectory ( ) ) { File buriedWrapperTemplateFile = new File ( child , getEntity ( ) . getExecutablePath ( ) ) ; if ( buriedWrapperTemplateFile . exists ( ) ) { File deploymentSubPath = Files . createTempDir ( ) ; FileUtils . moveDirectory ( child , deploymentSubPath ) ; FileUtils . deleteDirectory ( tempAppDir ) ; return deploymentSubPath ; } } } log . error ( "Unable to find deployment path for public app " + getEntity ( ) . getUniqueName ( ) + " while attempting to clone the app." ) ; throw new SoftwareException ( "Unable to find the deployment path for the public app " + getEntity ( ) . getUniqueName ( ) + " while attempting to clone." ) ; } }
Copies the zip archive for the public {@link Software} instance to the local file system
 for unpacking and relaying to the cloned {@link Software#getDeploymentPath()}.
Copies the zip archive for the public { @link Software } instance to the local file system for unpacking and relaying to the cloned { @link Software#getDeploymentPath () } .
// now copy the contents of the deployment folder to the parent dir, which is tempAppDir // now delete the redundant deployment folder // validate the checksum to make sure the app itself hasn't  changed //        if (localDeploymentPath.exists())  //        { //            tempAppDir = localDeploymentPath.getAbsoluteFile(); //        }  // otherwise, we need to find the root of the project. This will be a folder such that  // the the Software#getExecutablePath() exists as a relative path to the folder.  //        else  //        { // this will proably cause problems if the app referred to an executable outside of the  // public Software.getDeploymentPath() tree. //            File deploymentSubdirectory = new File(tempAppDir, getEntity().getExecutablePath()); // check to see whether the zip archive bundled everything into a top level folder. We can // identify the root of the deploymentPath in the zipped archive by finding the first parent // which properly resolves the wrapper template relative path // the zipped archive expanded the contents into the temp directory. No wrapping // folder was present. use the temp dir as is. // need to go searching for the path. no idea how this could happen