View Javadoc

1   /**
2    * Copyright 2010-2013 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.common.util.execute;
17  
18  import java.io.File;
19  import java.util.List;
20  
21  import org.kuali.common.util.Assert;
22  import org.kuali.common.util.LocationUtils;
23  import org.kuali.common.util.nullify.NullUtils;
24  import org.slf4j.Logger;
25  import org.slf4j.LoggerFactory;
26  
27  public abstract class AbstractCopyLocationsExecutable implements Executable {
28  
29  	private static final Logger logger = LoggerFactory.getLogger(AbstractCopyLocationsExecutable.class);
30  
31  	String locationListing;
32  	File directory;
33  
34  	protected abstract List<File> getFiles(List<String> locations);
35  
36  	@Override
37  	public void execute() {
38  		if (NullUtils.isNullOrNone(locationListing)) {
39  			logger.info("Skipping execution.  Location listing [{}]", locationListing);
40  			return;
41  		}
42  		Assert.notNull(locationListing);
43  		Assert.notNull(directory);
44  		Assert.isTrue(LocationUtils.exists(locationListing));
45  		logger.info("Copying [{}] -> [{}]", locationListing, LocationUtils.getCanonicalPath(directory));
46  		List<String> locations = LocationUtils.getLocations(locationListing);
47  		List<File> files = getFiles(locations);
48  		LocationUtils.copyLocationsToFiles(locations, files);
49  		logger.info("Copied {} files", locations.size());
50  	}
51  
52  	public String getLocationListing() {
53  		return locationListing;
54  	}
55  
56  	public void setLocationListing(String locationListing) {
57  		this.locationListing = locationListing;
58  	}
59  
60  	public File getDirectory() {
61  		return directory;
62  	}
63  
64  	public void setDirectory(File directory) {
65  		this.directory = directory;
66  	}
67  }