You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Repository.java 9.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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
  9. *
  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
  16. * under the License.
  17. */
  18. /*
  19. * Licensed to the Apache Software Foundation (ASF) under one
  20. * or more contributor license agreements. See the NOTICE file
  21. * distributed with this work for additional information
  22. * regarding copyright ownership. The ASF licenses this file
  23. * to you under the Apache License, Version 2.0 (the
  24. * "License"); you may not use this file except in compliance
  25. * with the License. You may obtain a copy of the License at
  26. *
  27. * http://www.apache.org/licenses/LICENSE-2.0
  28. * Unless required by applicable law or agreed to in writing,
  29. * software distributed under the License is distributed on an
  30. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  31. * KIND, either express or implied. See the License for the
  32. * specific language governing permissions and limitations
  33. * under the License.
  34. */
  35. import io.swagger.v3.oas.annotations.media.Schema;
  36. import org.apache.archiva.repository.ManagedRepository;
  37. import org.apache.archiva.repository.RemoteRepository;
  38. import java.io.Serializable;
  39. import java.util.Locale;
  40. /**
  41. * @author Martin Stockhammer <martin_s@apache.org>
  42. * @since 3.0
  43. */
  44. @Schema(description = "Repository data")
  45. public class Repository implements Serializable
  46. {
  47. private static final long serialVersionUID = -4741025877287175182L;
  48. public static final String CHARACTERISTIC_MANAGED = "managed";
  49. public static final String CHARACTERISTIC_REMOTE = "remote";
  50. public static final String CHARACTERISTIC_UNKNOWN = "unknown";
  51. protected String id;
  52. protected String name;
  53. protected String description;
  54. protected String type;
  55. protected String characteristic;
  56. protected String location;
  57. protected boolean scanned;
  58. protected String schedulingDefinition;
  59. protected boolean index;
  60. protected String layout;
  61. public Repository( )
  62. {
  63. }
  64. public static Repository of( org.apache.archiva.repository.Repository repository ) {
  65. Repository newRepo = new Repository( );
  66. newRepo.setId( repository.getId() );
  67. newRepo.setName( repository.getName( ) );
  68. newRepo.setDescription( repository.getDescription( ) );
  69. newRepo.setLocation( repository.getLocation().toASCIIString() );
  70. newRepo.setIndex( repository.hasIndex() );
  71. newRepo.setLayout( repository.getLayout() );
  72. newRepo.setType( repository.getType().name() );
  73. newRepo.setScanned( repository.isScanned() );
  74. newRepo.setSchedulingDefinition( repository.getSchedulingDefinition() );
  75. if (repository instanceof RemoteRepository ) {
  76. newRepo.setCharacteristic( CHARACTERISTIC_REMOTE );
  77. } else if (repository instanceof ManagedRepository ) {
  78. newRepo.setCharacteristic( CHARACTERISTIC_MANAGED );
  79. } else {
  80. newRepo.setCharacteristic( CHARACTERISTIC_UNKNOWN );
  81. }
  82. return newRepo;
  83. }
  84. public static Repository of( org.apache.archiva.repository.Repository repository, Locale locale ) {
  85. Locale myLocale;
  86. if (locale==null) {
  87. myLocale = Locale.getDefault( );
  88. } else {
  89. myLocale = locale;
  90. }
  91. String repoName = repository.getName( myLocale );
  92. if (repoName==null) {
  93. repoName = repository.getName( );
  94. }
  95. String description = repository.getDescription( myLocale );
  96. if (description==null) {
  97. description = repository.getDescription( );
  98. }
  99. Repository newRepo = new Repository( );
  100. newRepo.setId( repository.getId() );
  101. newRepo.setName( repoName );
  102. newRepo.setDescription( description );
  103. newRepo.setLocation( repository.getLocation().toASCIIString() );
  104. newRepo.setIndex( repository.hasIndex() );
  105. newRepo.setLayout( repository.getLayout() );
  106. newRepo.setType( repository.getType().name() );
  107. newRepo.setScanned( repository.isScanned() );
  108. newRepo.setSchedulingDefinition( repository.getSchedulingDefinition() );
  109. if (repository instanceof RemoteRepository ) {
  110. newRepo.setCharacteristic( CHARACTERISTIC_REMOTE );
  111. } else if (repository instanceof ManagedRepository ) {
  112. newRepo.setCharacteristic( CHARACTERISTIC_MANAGED );
  113. } else {
  114. newRepo.setCharacteristic( CHARACTERISTIC_UNKNOWN );
  115. }
  116. return newRepo;
  117. }
  118. @Schema(description = "Category of the repository. Either 'managed' or 'remote'.")
  119. public String getCharacteristic( )
  120. {
  121. return characteristic;
  122. }
  123. public void setCharacteristic( String characteristic )
  124. {
  125. this.characteristic = characteristic;
  126. }
  127. @Schema(description = "Unique identifier of the repository")
  128. public String getId( )
  129. {
  130. return id;
  131. }
  132. public void setId( String id )
  133. {
  134. this.id = id;
  135. }
  136. @Schema(description = "Display name of the repository")
  137. public String getName( )
  138. {
  139. return name;
  140. }
  141. public void setName( String name )
  142. {
  143. this.name = name;
  144. }
  145. @Schema(description = "Description of the repository")
  146. public String getDescription( )
  147. {
  148. return description;
  149. }
  150. public void setDescription( String description )
  151. {
  152. this.description = description;
  153. }
  154. @Schema(description = "Repository type")
  155. public String getType( )
  156. {
  157. return type;
  158. }
  159. public void setType( String type )
  160. {
  161. this.type = type;
  162. }
  163. @Schema(description = "The location, where the repository data can be found")
  164. public String getLocation( )
  165. {
  166. return location;
  167. }
  168. public void setLocation( String location )
  169. {
  170. this.location = location;
  171. }
  172. @Schema(description = "True, if this repository is scanned regularly")
  173. public boolean isScanned( )
  174. {
  175. return scanned;
  176. }
  177. public void setScanned( boolean scanned )
  178. {
  179. this.scanned = scanned;
  180. }
  181. @Schema(name="scheduling_definition",description = "Definition of regular scheduled scan")
  182. public String getSchedulingDefinition( )
  183. {
  184. return schedulingDefinition;
  185. }
  186. public void setSchedulingDefinition( String schedulingDefinition )
  187. {
  188. this.schedulingDefinition = schedulingDefinition;
  189. }
  190. @Schema(description = "True, if this is a indexed repository")
  191. public boolean isIndex( )
  192. {
  193. return index;
  194. }
  195. public void setIndex( boolean index )
  196. {
  197. this.index = index;
  198. }
  199. @Schema(description = "Layout type is implementation specific")
  200. public String getLayout( )
  201. {
  202. return layout;
  203. }
  204. public void setLayout( String layout )
  205. {
  206. this.layout = layout;
  207. }
  208. @Override
  209. public boolean equals( Object o )
  210. {
  211. if ( this == o ) return true;
  212. if ( o == null || getClass( ) != o.getClass( ) ) return false;
  213. Repository that = (Repository) o;
  214. if ( scanned != that.scanned ) return false;
  215. if ( index != that.index ) return false;
  216. if ( id != null ? !id.equals( that.id ) : that.id != null ) return false;
  217. if ( name != null ? !name.equals( that.name ) : that.name != null ) return false;
  218. if ( description != null ? !description.equals( that.description ) : that.description != null ) return false;
  219. if ( type != null ? !type.equals( that.type ) : that.type != null ) return false;
  220. if ( location != null ? !location.equals( that.location ) : that.location != null ) return false;
  221. if ( schedulingDefinition != null ? !schedulingDefinition.equals( that.schedulingDefinition ) : that.schedulingDefinition != null )
  222. return false;
  223. return layout != null ? layout.equals( that.layout ) : that.layout == null;
  224. }
  225. @Override
  226. public int hashCode( )
  227. {
  228. int result = id != null ? id.hashCode( ) : 0;
  229. result = 31 * result + ( name != null ? name.hashCode( ) : 0 );
  230. result = 31 * result + ( description != null ? description.hashCode( ) : 0 );
  231. result = 31 * result + ( type != null ? type.hashCode( ) : 0 );
  232. result = 31 * result + ( location != null ? location.hashCode( ) : 0 );
  233. result = 31 * result + ( scanned ? 1 : 0 );
  234. result = 31 * result + ( schedulingDefinition != null ? schedulingDefinition.hashCode( ) : 0 );
  235. result = 31 * result + ( index ? 1 : 0 );
  236. result = 31 * result + ( layout != null ? layout.hashCode( ) : 0 );
  237. return result;
  238. }
  239. @Override
  240. public String toString( )
  241. {
  242. final StringBuilder sb = new StringBuilder( "Repository{" );
  243. sb.append( "id='" ).append( id ).append( '\'' );
  244. sb.append( ", name='" ).append( name ).append( '\'' );
  245. sb.append( ", description='" ).append( description ).append( '\'' );
  246. sb.append( ", type='" ).append( type ).append( '\'' );
  247. sb.append( ", location='" ).append( location ).append( '\'' );
  248. sb.append( ", scanned=" ).append( scanned );
  249. sb.append( ", schedulingDefinition='" ).append( schedulingDefinition ).append( '\'' );
  250. sb.append( ", index=" ).append( index );
  251. sb.append( ", layout='" ).append( layout ).append( '\'' );
  252. sb.append( '}' );
  253. return sb.toString( );
  254. }
  255. }