001    package org.apache.archiva.repository.scanner.functors;
002    
003    /*
004     * Licensed to the Apache Software Foundation (ASF) under one
005     * or more contributor license agreements.  See the NOTICE file
006     * distributed with this work for additional information
007     * regarding copyright ownership.  The ASF licenses this file
008     * to you under the Apache License, Version 2.0 (the
009     * "License"); you may not use this file except in compliance
010     * with the License.  You may obtain a copy of the License at
011     *
012     *  http://www.apache.org/licenses/LICENSE-2.0
013     *
014     * Unless required by applicable law or agreed to in writing,
015     * software distributed under the License is distributed on an
016     * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017     * KIND, either express or implied.  See the License for the
018     * specific language governing permissions and limitations
019     * under the License.
020     */
021    
022    import org.apache.archiva.admin.model.beans.ManagedRepository;
023    import org.apache.commons.collections.Closure;
024    import org.apache.archiva.consumers.ConsumerException;
025    import org.apache.archiva.consumers.RepositoryContentConsumer;
026    import org.slf4j.Logger;
027    import org.slf4j.LoggerFactory;
028    
029    import java.util.Date;
030    
031    /**
032     * TriggerBeginScanClosure 
033     *
034     *
035     */
036    public class TriggerBeginScanClosure
037        implements Closure
038    {
039        private Logger log = LoggerFactory.getLogger( TriggerBeginScanClosure.class );
040        
041        private ManagedRepository repository;
042        
043        private Date whenGathered;
044    
045        private boolean executeOnEntireRepo = true;
046    
047        public TriggerBeginScanClosure( ManagedRepository repository )
048        {
049            this.repository = repository;
050        }
051        
052        public TriggerBeginScanClosure( ManagedRepository repository, Date whenGathered )
053        {
054            this( repository );
055            this.whenGathered = whenGathered;
056        }
057    
058        public TriggerBeginScanClosure( ManagedRepository repository, Date whenGathered, boolean executeOnEntireRepo )
059        {
060            this( repository, whenGathered );
061            this.executeOnEntireRepo = executeOnEntireRepo;
062        }
063    
064        public void execute( Object input )
065        {
066            if ( input instanceof RepositoryContentConsumer )
067            {
068                RepositoryContentConsumer consumer = (RepositoryContentConsumer) input;
069                    
070                try
071                {
072                    consumer.beginScan( repository, whenGathered, executeOnEntireRepo );
073                }
074                catch ( ConsumerException e )
075                {
076                    log.warn( "Consumer [" + consumer.getId() + "] cannot begin: " + e.getMessage(), e );
077                }
078            }
079        }
080    }