View Javadoc
1   /**
2    * Copyright 2010-2014 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.util.Arrays;
19  import java.util.List;
20  
21  import org.kuali.common.util.Assert;
22  import org.kuali.common.util.FileSystemUtils;
23  import org.slf4j.Logger;
24  import org.slf4j.LoggerFactory;
25  
26  public class CopyFilesExecutable implements Executable {
27  
28  	private static final Logger logger = LoggerFactory.getLogger(CopyFilesExecutable.class);
29  
30  	boolean skip;
31  	List<CopyFileRequest> requests;
32  
33  	// Filled in during execution
34  	List<CopyFileResult> results;
35  
36  	public CopyFilesExecutable() {
37  		this(null, false);
38  	}
39  
40  	public CopyFilesExecutable(CopyFileRequest request) {
41  		this(Arrays.asList(request), false);
42  	}
43  
44  	public CopyFilesExecutable(List<CopyFileRequest> requests) {
45  		this(requests, false);
46  	}
47  
48  	public CopyFilesExecutable(List<CopyFileRequest> requests, boolean skip) {
49  		super();
50  		this.requests = requests;
51  		this.skip = skip;
52  	}
53  
54  	@Override
55  	public void execute() {
56  
57  		// Might be nothing to do
58  		if (skip) {
59  			return;
60  		}
61  
62  		// Make sure we are configured correctly
63  		Assert.notNull(requests, "requests is null");
64  
65  		// Show how many files we are copying
66  		logger.info("Copying {} files", requests.size());
67  
68  		// Perform the file system copy
69  		List<CopyFileResult> results = FileSystemUtils.copyFiles(requests);
70  
71  		// Store the results in our internal member variable
72  		this.results = results;
73  	}
74  
75  	/**
76  	 * Expose the copy results via a getter
77  	 */
78  	public List<CopyFileResult> getResults() {
79  		return results;
80  	}
81  
82  	public List<CopyFileRequest> getRequests() {
83  		return requests;
84  	}
85  
86  	public void setRequests(List<CopyFileRequest> requests) {
87  		this.requests = requests;
88  	}
89  
90  	public boolean isSkip() {
91  		return skip;
92  	}
93  
94  	public void setSkip(boolean skip) {
95  		this.skip = skip;
96  	}
97  
98  }