agave-files/files-core/src/main/java/org/iplantc/service/io/dao/LogicalFileDao.java
/**
	 * Finds logical files that would not be overwritten in a copy operation from 
	 * srcPath to destPath between the two systems.
	 *  
	 * @param srcPath
	 * @param srcSystemId
	 * @param destPath
	 * @param destSystemId
	 */
Finds logical files that would not be overwritten in a copy operation from
srcPath to destPath between the two systems.


Finds logical files that would not be overwritten in a copy operation from srcPath to destPath between the two systems .
@SuppressWarnings("unchecked")
	public static List<LogicalFile> findNonOverlappingChildren(String srcPath, Long srcSystemId, String destPath, Long destSystemId) 
	{
		if (StringUtils.isEmpty(srcPath)) {
			throw new HibernateException("No original path specified");
		}
		if (StringUtils.isEmpty(destPath)) {
			throw new HibernateException("No new path specified");
		}
		if (srcSystemId == null) {
			throw new HibernateException("No source system id specified");
		}
		if (destSystemId == null) {
			throw new HibernateException("No destination system id specified");
		}
		try {
			Session session = getSession();
			String sql = "select * from logical_files " +
						"where system_id = :srcsystemid and " +  
						"	path like :srcpathmatch and " +
						"	path <> :srcpath and " +  
						"	tenant_id = :tenantid and" +  
						"	id not in ( " +  
						"			select src.id " +
						"			from logical_files src " + 
						" 				inner join logical_files dest " +
						" 					on dest.path = REPLACE(src.path, :srcpath, :destpath) and " +
						"						dest.system_id = :destsystemid and " +
						"						src.system_id = :srcsystemid and " +
						"						src.tenant_id = dest.tenant_id " +
						"			where src.tenant_id = :tenantid and " +
						"				src.path like :srcpathmatch " +
						"			)";
			List<LogicalFile> files = (List<LogicalFile>)session.createSQLQuery(sql)
				.addEntity(LogicalFile.class)
				.setString("srcpath", srcPath)
				.setString("destpath", destPath)
				.setString("srcpathmatch", StringUtils.replace(srcPath + "/%", "//", "/"))
				.setLong("srcsystemid", srcSystemId)
				.setLong("destsystemid", destSystemId)
				.setString("tenantid", TenancyHelper.getCurrentTenantId())
				.list();
			session.flush();
			return files;
		}
		catch (HibernateException ex)
		{
			log.error("Failed to update logical file parent path", ex);
			try
			{
				if (HibernateUtil.getSession().isOpen()) {
					HibernateUtil.rollbackTransaction();
				}
			}
			catch (Exception ignored) {}
			throw ex;
		}
		finally
		{
			try { HibernateUtil.commitTransaction(); } catch (Exception ignored) {}
		}
	}
@ SuppressWarnings ( "unchecked" ) public static List < LogicalFile > findNonOverlappingChildren ( String srcPath , Long srcSystemId , String destPath , Long destSystemId ) { if ( StringUtils . isEmpty ( srcPath ) ) { throw new HibernateException ( "No original path specified" ) ; } if ( StringUtils . isEmpty ( destPath ) ) { throw new HibernateException ( "No new path specified" ) ; } if ( srcSystemId == null ) { throw new HibernateException ( "No source system id specified" ) ; } if ( destSystemId == null ) { throw new HibernateException ( "No destination system id specified" ) ; } try { Session session = getSession ( ) ; String sql = "select * from logical_files " + "where system_id = :srcsystemid and " + "	path like :srcpathmatch and " + "	path <> :srcpath and " + "	tenant_id = :tenantid and" + "	id not in ( " + "			select src.id " + "			from logical_files src " + " 				inner join logical_files dest " + " 					on dest.path = REPLACE(src.path, :srcpath, :destpath) and " + "						dest.system_id = :destsystemid and " + "						src.system_id = :srcsystemid and " + "						src.tenant_id = dest.tenant_id " + "			where src.tenant_id = :tenantid and " + "				src.path like :srcpathmatch " + "			)" ; List < LogicalFile > files = ( List < LogicalFile > ) session . createSQLQuery ( sql ) . addEntity ( LogicalFile . class ) . setString ( "srcpath" , srcPath ) . setString ( "destpath" , destPath ) . setString ( "srcpathmatch" , StringUtils . replace ( srcPath + "/%" , "//" , "/" ) ) . setLong ( "srcsystemid" , srcSystemId ) . setLong ( "destsystemid" , destSystemId ) . setString ( "tenantid" , TenancyHelper . getCurrentTenantId ( ) ) . list ( ) ; session . flush ( ) ; return files ; } catch ( HibernateException ex ) { log . error ( "Failed to update logical file parent path" , ex ) ; try { if ( HibernateUtil . getSession ( ) . isOpen ( ) ) { HibernateUtil . rollbackTransaction ( ) ; } } catch ( Exception ignored ) { } throw ex ; } finally { try { HibernateUtil . commitTransaction ( ) ; } catch ( Exception ignored ) { } } }
Finds logical files that would not be overwritten in a copy operation from
 srcPath to destPath between the two systems.
Finds logical files that would not be overwritten in a copy operation from srcPath to destPath between the two systems .
// update path of existing logical files where the is no corresponding destination logical_file