001 /** 002 * Copyright 2010-2013 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 package org.kuali.common.util.execute; 017 018 import java.io.File; 019 import java.util.List; 020 021 import org.kuali.common.util.Assert; 022 import org.kuali.common.util.LocationUtils; 023 import org.kuali.common.util.nullify.NullUtils; 024 import org.slf4j.Logger; 025 import org.slf4j.LoggerFactory; 026 027 public abstract class AbstractCopyLocationsExecutable implements Executable { 028 029 private static final Logger logger = LoggerFactory.getLogger(AbstractCopyLocationsExecutable.class); 030 031 String locationListing; 032 File directory; 033 034 protected abstract List<File> getFiles(List<String> locations); 035 036 @Override 037 public void execute() { 038 if (NullUtils.isNullOrNone(locationListing)) { 039 logger.info("Skipping execution. Location listing [{}]", locationListing); 040 return; 041 } 042 Assert.notNull(locationListing); 043 Assert.notNull(directory); 044 Assert.isTrue(LocationUtils.exists(locationListing)); 045 logger.info("Copying [{}] -> [{}]", locationListing, LocationUtils.getCanonicalPath(directory)); 046 List<String> locations = LocationUtils.getLocations(locationListing); 047 List<File> files = getFiles(locations); 048 LocationUtils.copyLocationsToFiles(locations, files); 049 logger.info("Copied {} files", locations.size()); 050 } 051 052 public String getLocationListing() { 053 return locationListing; 054 } 055 056 public void setLocationListing(String locationListing) { 057 this.locationListing = locationListing; 058 } 059 060 public File getDirectory() { 061 return directory; 062 } 063 064 public void setDirectory(File directory) { 065 this.directory = directory; 066 } 067 }