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.io.File;
019import java.util.List;
020
021import org.kuali.common.util.Assert;
022import org.kuali.common.util.LocationUtils;
023import org.kuali.common.util.nullify.NullUtils;
024import org.slf4j.Logger;
025import org.slf4j.LoggerFactory;
026
027@Deprecated
028public abstract class AbstractCopyLocationsExecutable implements Executable {
029
030        private static final Logger logger = LoggerFactory.getLogger(AbstractCopyLocationsExecutable.class);
031
032    public AbstractCopyLocationsExecutable() {
033        this(null, null);
034    }
035
036    public AbstractCopyLocationsExecutable(String locationListing, File directory) {
037        this.locationListing = locationListing;
038        this.directory = directory;
039    }
040
041        String locationListing;
042        File directory;
043
044        protected abstract List<File> getFiles(List<String> locations);
045
046        @Override
047        public void execute() {
048                if (NullUtils.isNullOrNone(locationListing)) {
049                        logger.info("Skipping execution.  Location listing [{}]", locationListing);
050                        return;
051                }
052                Assert.notNull(locationListing);
053                Assert.notNull(directory);
054                Assert.isTrue(LocationUtils.exists(locationListing));
055                logger.info("Copying [{}] -> [{}]", locationListing, LocationUtils.getCanonicalPath(directory));
056                List<String> locations = LocationUtils.getLocations(locationListing);
057                List<File> files = getFiles(locations);
058                LocationUtils.copyLocationsToFiles(locations, files);
059                logger.info("Copied {} files", locations.size());
060        }
061
062        public String getLocationListing() {
063                return locationListing;
064        }
065
066        public void setLocationListing(String locationListing) {
067                this.locationListing = locationListing;
068        }
069
070        public File getDirectory() {
071                return directory;
072        }
073
074        public void setDirectory(File directory) {
075                this.directory = directory;
076        }
077}