001    package org.apache.archiva.admin.model.beans;
002    /*
003     * Licensed to the Apache Software Foundation (ASF) under one
004     * or more contributor license agreements.  See the NOTICE file
005     * distributed with this work for additional information
006     * regarding copyright ownership.  The ASF licenses this file
007     * to you under the Apache License, Version 2.0 (the
008     * "License"); you may not use this file except in compliance
009     * with the License.  You may obtain a copy of the License at
010     *
011     *   http://www.apache.org/licenses/LICENSE-2.0
012     *
013     * Unless required by applicable law or agreed to in writing,
014     * software distributed under the License is distributed on an
015     * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
016     * KIND, either express or implied.  See the License for the
017     * specific language governing permissions and limitations
018     * under the License.
019     */
020    
021    import javax.xml.bind.annotation.XmlRootElement;
022    import java.io.Serializable;
023    import java.util.ArrayList;
024    import java.util.List;
025    
026    /**
027     * @author Olivier Lamy
028     * @since 1.4-M1
029     */
030    @XmlRootElement(name = "repositoryGroup")
031    public class RepositoryGroup
032        implements Serializable
033    {
034        /**
035         * repository group Id
036         */
037        private String id;
038    
039        /**
040         * repositories ids
041         */
042        private List<String> repositories;
043    
044        /**
045         * The path of the merged index.
046         */
047        private String mergedIndexPath = "/.indexer";
048    
049        /**
050         * The TTL (time to live) of the repo group's merged index.
051         */
052        private int mergedIndexTtl = 30;
053    
054        public RepositoryGroup()
055        {
056            // no op
057        }
058    
059        public RepositoryGroup( String id, List<String> repositories )
060        {
061            this.id = id;
062            this.repositories = repositories;
063        }
064    
065        /**
066         * Method addRepository.
067         *
068         * @param string
069         */
070        public void addRepository( String string )
071        {
072            getRepositories().add( string );
073        }
074    
075        /**
076         * Get the id of the repository group.
077         *
078         * @return String
079         */
080        public String getId()
081        {
082            return this.id;
083        }
084    
085        /**
086         * Method getRepositories.
087         *
088         * @return List
089         */
090        public List<String> getRepositories()
091        {
092            if ( this.repositories == null )
093            {
094                this.repositories = new ArrayList<String>( 0 );
095            }
096    
097            return this.repositories;
098        }
099    
100        /**
101         * Method removeRepository.
102         *
103         * @param string
104         */
105        public void removeRepository( String string )
106        {
107            getRepositories().remove( string );
108        }
109    
110        /**
111         * Set the id of the repository group.
112         *
113         * @param id
114         */
115        public void setId( String id )
116        {
117            this.id = id;
118        }
119    
120        /**
121         * Set the list of repository ids under the group.
122         *
123         * @param repositories
124         */
125        public void setRepositories( List<String> repositories )
126        {
127            this.repositories = repositories;
128        }
129    
130        public String getMergedIndexPath()
131        {
132            return mergedIndexPath;
133        }
134    
135        public void setMergedIndexPath( String mergedIndexPath )
136        {
137            this.mergedIndexPath = mergedIndexPath;
138        }
139    
140        public int getMergedIndexTtl() {
141            return mergedIndexTtl;
142        }
143    
144        /**
145         * Set the TTL of the repo group's merged index.
146         *
147         * @param mergedIndexTtl
148         */
149        public void setMergedIndexTtl(int mergedIndexTtl) {
150            this.mergedIndexTtl = mergedIndexTtl;
151        }
152    
153        public RepositoryGroup mergedIndexPath( String mergedIndexPath ) {
154            this.mergedIndexPath = mergedIndexPath;
155            return this;
156        }
157    
158        public RepositoryGroup mergedIndexTtl( int mergedIndexTtl ) {
159            this.mergedIndexTtl = mergedIndexTtl;
160            return this;
161        }
162    
163        public boolean equals( Object other )
164        {
165            if ( this == other )
166            {
167                return true;
168            }
169    
170            if ( !( other instanceof RepositoryGroup ) )
171            {
172                return false;
173            }
174    
175            RepositoryGroup that = (RepositoryGroup) other;
176            boolean result = true;
177            result = result && ( getId() == null ? that.getId() == null : getId().equals( that.getId() ) );
178            return result;
179        }
180    
181        public int hashCode()
182        {
183            int result = 17;
184            result = 37 * result + ( id != null ? id.hashCode() : 0 );
185            return result;
186        }
187    
188        @Override
189        public String toString()
190        {
191            final StringBuilder sb = new StringBuilder();
192            sb.append( "RepositoryGroup" );
193            sb.append( "{id='" ).append( id ).append( '\'' );
194            sb.append( ", repositories=" ).append( repositories );
195            sb.append( '}' );
196            return sb.toString();
197        }
198    }