1 package org.apache.archiva.rest.api.model.v2;/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing,
12 * software distributed under the License is distributed on an
13 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 * KIND, either express or implied. See the License for the
15 * specific language governing permissions and limitations
20 * Licensed to the Apache Software Foundation (ASF) under one
21 * or more contributor license agreements. See the NOTICE file
22 * distributed with this work for additional information
23 * regarding copyright ownership. The ASF licenses this file
24 * to you under the Apache License, Version 2.0 (the
25 * "License"); you may not use this file except in compliance
26 * with the License. You may obtain a copy of the License at
28 * http://www.apache.org/licenses/LICENSE-2.0
29 * Unless required by applicable law or agreed to in writing,
30 * software distributed under the License is distributed on an
31 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
32 * KIND, either express or implied. See the License for the
33 * specific language governing permissions and limitations
37 import io.swagger.v3.oas.annotations.media.Schema;
38 import org.apache.archiva.repository.ManagedRepository;
39 import org.apache.archiva.repository.RemoteRepository;
41 import java.io.Serializable;
42 import java.util.Locale;
45 * @author Martin Stockhammer <martin_s@apache.org>
48 @Schema(description = "Repository data")
49 public class Repository implements Serializable
51 private static final long serialVersionUID = -4741025877287175182L;
53 public static final String CHARACTERISTIC_MANAGED = "managed";
54 public static final String CHARACTERISTIC_REMOTE = "remote";
55 public static final String CHARACTERISTIC_UNKNOWN = "unknown";
58 protected String name;
59 protected String description;
60 protected String type;
61 protected String characteristic;
62 protected String location;
63 protected boolean scanned;
64 protected String schedulingDefinition;
65 protected boolean index;
66 protected String layout;
72 public static Repository of( org.apache.archiva.repository.Repository repository ) {
73 Repository newRepo = new Repository( );
74 newRepo.setId( repository.getId() );
75 newRepo.setName( repository.getName( ) );
76 newRepo.setDescription( repository.getDescription( ) );
77 newRepo.setLocation( repository.getLocation().toASCIIString() );
78 newRepo.setIndex( repository.hasIndex() );
79 newRepo.setLayout( repository.getLayout() );
80 newRepo.setType( repository.getType().name() );
81 newRepo.setScanned( repository.isScanned() );
82 newRepo.setSchedulingDefinition( repository.getSchedulingDefinition() );
83 if (repository instanceof RemoteRepository ) {
84 newRepo.setCharacteristic( CHARACTERISTIC_REMOTE );
85 } else if (repository instanceof ManagedRepository ) {
86 newRepo.setCharacteristic( CHARACTERISTIC_MANAGED );
88 newRepo.setCharacteristic( CHARACTERISTIC_UNKNOWN );
93 public static Repository of( org.apache.archiva.repository.Repository repository, Locale locale ) {
96 myLocale = Locale.getDefault( );
100 String repoName = repository.getName( myLocale );
101 if (repoName==null) {
102 repoName = repository.getName( );
104 String description = repository.getDescription( myLocale );
105 if (description==null) {
106 description = repository.getDescription( );
108 Repository newRepo = new Repository( );
109 newRepo.setId( repository.getId() );
110 newRepo.setName( repoName );
111 newRepo.setDescription( description );
112 newRepo.setLocation( repository.getLocation().toASCIIString() );
113 newRepo.setIndex( repository.hasIndex() );
114 newRepo.setLayout( repository.getLayout() );
115 newRepo.setType( repository.getType().name() );
116 newRepo.setScanned( repository.isScanned() );
117 newRepo.setSchedulingDefinition( repository.getSchedulingDefinition() );
118 if (repository instanceof RemoteRepository ) {
119 newRepo.setCharacteristic( CHARACTERISTIC_REMOTE );
120 } else if (repository instanceof ManagedRepository ) {
121 newRepo.setCharacteristic( CHARACTERISTIC_MANAGED );
123 newRepo.setCharacteristic( CHARACTERISTIC_UNKNOWN );
128 @Schema(description = "Category of the repository. Either 'managed' or 'remote'.")
129 public String getCharacteristic( )
131 return characteristic;
134 public void setCharacteristic( String characteristic )
136 this.characteristic = characteristic;
139 @Schema(description = "Unique identifier of the repository")
140 public String getId( )
145 public void setId( String id )
150 @Schema(description = "Display name of the repository")
151 public String getName( )
156 public void setName( String name )
161 @Schema(description = "Description of the repository")
162 public String getDescription( )
167 public void setDescription( String description )
169 this.description = description;
172 @Schema(description = "Repository type")
173 public String getType( )
178 public void setType( String type )
183 @Schema(description = "The location, where the repository data can be found")
184 public String getLocation( )
189 public void setLocation( String location )
191 this.location = location;
194 @Schema(description = "True, if this repository is scanned regularly")
195 public boolean isScanned( )
200 public void setScanned( boolean scanned )
202 this.scanned = scanned;
205 @Schema(name="scheduling_definition",description = "Definition of regular scheduled scan")
206 public String getSchedulingDefinition( )
208 return schedulingDefinition;
211 public void setSchedulingDefinition( String schedulingDefinition )
213 this.schedulingDefinition = schedulingDefinition;
216 @Schema(description = "True, if this is a indexed repository")
217 public boolean isIndex( )
222 public void setIndex( boolean index )
227 @Schema(description = "Layout type is implementation specific")
228 public String getLayout( )
233 public void setLayout( String layout )
235 this.layout = layout;
239 public boolean equals( Object o )
241 if ( this == o ) return true;
242 if ( o == null || getClass( ) != o.getClass( ) ) return false;
244 Repository that = (Repository) o;
246 if ( scanned != that.scanned ) return false;
247 if ( index != that.index ) return false;
248 if ( id != null ? !id.equals( that.id ) : that.id != null ) return false;
249 if ( name != null ? !name.equals( that.name ) : that.name != null ) return false;
250 if ( description != null ? !description.equals( that.description ) : that.description != null ) return false;
251 if ( type != null ? !type.equals( that.type ) : that.type != null ) return false;
252 if ( location != null ? !location.equals( that.location ) : that.location != null ) return false;
253 if ( schedulingDefinition != null ? !schedulingDefinition.equals( that.schedulingDefinition ) : that.schedulingDefinition != null )
255 return layout != null ? layout.equals( that.layout ) : that.layout == null;
259 public int hashCode( )
261 int result = id != null ? id.hashCode( ) : 0;
262 result = 31 * result + ( name != null ? name.hashCode( ) : 0 );
263 result = 31 * result + ( description != null ? description.hashCode( ) : 0 );
264 result = 31 * result + ( type != null ? type.hashCode( ) : 0 );
265 result = 31 * result + ( location != null ? location.hashCode( ) : 0 );
266 result = 31 * result + ( scanned ? 1 : 0 );
267 result = 31 * result + ( schedulingDefinition != null ? schedulingDefinition.hashCode( ) : 0 );
268 result = 31 * result + ( index ? 1 : 0 );
269 result = 31 * result + ( layout != null ? layout.hashCode( ) : 0 );
274 public String toString( )
276 final StringBuilder sb = new StringBuilder( "Repository{" );
277 sb.append( "id='" ).append( id ).append( '\'' );
278 sb.append( ", name='" ).append( name ).append( '\'' );
279 sb.append( ", description='" ).append( description ).append( '\'' );
280 sb.append( ", type='" ).append( type ).append( '\'' );
281 sb.append( ", location='" ).append( location ).append( '\'' );
282 sb.append( ", scanned=" ).append( scanned );
283 sb.append( ", schedulingDefinition='" ).append( schedulingDefinition ).append( '\'' );
284 sb.append( ", index=" ).append( index );
285 sb.append( ", layout='" ).append( layout ).append( '\'' );
287 return sb.toString( );