001/**
002 * Copyright 2010-2014 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 */
016package org.kuali.common.util.execute;
017
018import java.util.Arrays;
019import java.util.List;
020
021import org.kuali.common.util.Assert;
022import org.kuali.common.util.FileSystemUtils;
023import org.slf4j.Logger;
024import org.slf4j.LoggerFactory;
025
026public class CopyFilesExecutable implements Executable {
027
028        private static final Logger logger = LoggerFactory.getLogger(CopyFilesExecutable.class);
029
030        boolean skip;
031        List<CopyFileRequest> requests;
032
033        // Filled in during execution
034        List<CopyFileResult> results;
035
036        public CopyFilesExecutable() {
037                this(null, false);
038        }
039
040        public CopyFilesExecutable(CopyFileRequest request) {
041                this(Arrays.asList(request), false);
042        }
043
044        public CopyFilesExecutable(List<CopyFileRequest> requests) {
045                this(requests, false);
046        }
047
048        public CopyFilesExecutable(List<CopyFileRequest> requests, boolean skip) {
049                super();
050                this.requests = requests;
051                this.skip = skip;
052        }
053
054        @Override
055        public void execute() {
056
057                // Might be nothing to do
058                if (skip) {
059                        return;
060                }
061
062                // Make sure we are configured correctly
063                Assert.notNull(requests, "requests is null");
064
065                // Show how many files we are copying
066                logger.info("Copying {} files", requests.size());
067
068                // Perform the file system copy
069                List<CopyFileResult> results = FileSystemUtils.copyFiles(requests);
070
071                // Store the results in our internal member variable
072                this.results = results;
073        }
074
075        /**
076         * Expose the copy results via a getter
077         */
078        public List<CopyFileResult> getResults() {
079                return results;
080        }
081
082        public List<CopyFileRequest> getRequests() {
083                return requests;
084        }
085
086        public void setRequests(List<CopyFileRequest> requests) {
087                this.requests = requests;
088        }
089
090        public boolean isSkip() {
091                return skip;
092        }
093
094        public void setSkip(boolean skip) {
095                this.skip = skip;
096        }
097
098}