1 package org.kuali.common.util.execute; 2 3 import java.io.File; 4 import java.util.List; 5 6 import org.kuali.common.util.Assert; 7 import org.kuali.common.util.LocationUtils; 8 import org.kuali.common.util.nullify.NullUtils; 9 import org.slf4j.Logger; 10 import org.slf4j.LoggerFactory; 11 12 public abstract class AbstractCopyLocationsExecutable implements Executable { 13 14 private static final Logger logger = LoggerFactory.getLogger(AbstractCopyLocationsExecutable.class); 15 16 String locationListing; 17 File directory; 18 19 protected abstract List<File> getFiles(List<String> locations); 20 21 @Override 22 public void execute() { 23 if (NullUtils.isNullOrNone(locationListing)) { 24 logger.info("Skipping execution. Location listing [{}]", locationListing); 25 return; 26 } 27 Assert.notNull(locationListing); 28 Assert.notNull(directory); 29 Assert.isTrue(LocationUtils.exists(locationListing)); 30 logger.info("Copying [{}] -> [{}]", locationListing, LocationUtils.getCanonicalPath(directory)); 31 List<String> locations = LocationUtils.getLocations(locationListing); 32 List<File> files = getFiles(locations); 33 LocationUtils.copyLocationsToFiles(locations, files); 34 logger.info("Copied {} files", locations.size()); 35 } 36 37 public String getLocationListing() { 38 return locationListing; 39 } 40 41 public void setLocationListing(String locationListing) { 42 this.locationListing = locationListing; 43 } 44 45 public File getDirectory() { 46 return directory; 47 } 48 49 public void setDirectory(File directory) { 50 this.directory = directory; 51 } 52 }