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.Repository;
39 import org.apache.archiva.repository.features.IndexCreationFeature;
40 import org.apache.archiva.repository.features.RepositoryFeature;
42 import javax.xml.bind.annotation.XmlRootElement;
43 import java.io.Serializable;
44 import java.util.ArrayList;
45 import java.util.List;
46 import java.util.Objects;
47 import java.util.stream.Collectors;
50 * @author Martin Stockhammer <martin_s@apache.org>
52 @XmlRootElement(name="repositoryGroup")
53 @Schema(name="RepositoryGroup", description = "Information about a repository group, which combines multiple repositories as one virtual repository.")
54 public class RepositoryGroup implements Serializable
56 private static final long serialVersionUID = -7319687481737616081L;
58 private List<String> repositories = new ArrayList<>( );
59 private String location;
60 MergeConfiguration mergeConfiguration;
62 public RepositoryGroup( )
66 public RepositoryGroup(String id) {
70 public static RepositoryGroup of( org.apache.archiva.repository.RepositoryGroup modelObj ) {
71 RepositoryGroup result = new RepositoryGroup( );
72 MergeConfiguration mergeConfig = new MergeConfiguration( );
73 result.setMergeConfiguration( mergeConfig );
74 result.setId( modelObj.getId() );
75 result.setLocation( modelObj.getLocation().toString() );
76 result.setRepositories( modelObj.getRepositories().stream().map( Repository::getId ).collect( Collectors.toList()) );
77 if (modelObj.supportsFeature( IndexCreationFeature.class )) {
78 IndexCreationFeature icf = modelObj.getFeature( IndexCreationFeature.class ).get();
79 mergeConfig.setMergedIndexPath( icf.getIndexPath( ).toString() );
80 mergeConfig.setMergedIndexTtlMinutes( modelObj.getMergedIndexTTL( ) );
81 mergeConfig.setIndexMergeSchedule( modelObj.getSchedulingDefinition() );
86 @Schema(description = "The unique id of the repository group.")
87 public String getId( )
92 public void setId( String id )
97 @Schema(description = "The list of ids of repositories which are member of the repository group.")
98 public List<String> getRepositories( )
103 public void setRepositories( List<String> repositories )
105 this.repositories = new ArrayList<>( repositories );
108 public void addRepository(String repositoryId) {
109 if (!this.repositories.contains( repositoryId )) {
110 this.repositories.add( repositoryId );
114 @Schema(name="merge_configuration",description = "The configuration for index merge.")
115 public MergeConfiguration getMergeConfiguration( )
117 return mergeConfiguration;
120 public void setMergeConfiguration( MergeConfiguration mergeConfiguration )
122 this.mergeConfiguration = mergeConfiguration;
125 @Schema(description = "The storage location of the repository. The merged index is stored relative to this location.")
126 public String getLocation( )
131 public void setLocation( String location )
133 this.location = location;
137 public boolean equals( Object o )
139 if ( this == o ) return true;
140 if ( o == null || getClass( ) != o.getClass( ) ) return false;
142 RepositoryGroup that = (RepositoryGroup) o;
144 if ( !Objects.equals( id, that.id ) ) return false;
145 if ( !repositories.equals( that.repositories ) )
147 if ( !Objects.equals( location, that.location ) ) return false;
148 return Objects.equals( mergeConfiguration, that.mergeConfiguration );
152 public int hashCode( )
154 int result = id != null ? id.hashCode( ) : 0;
155 result = 31 * result + repositories.hashCode( );
156 result = 31 * result + ( location != null ? location.hashCode( ) : 0 );
157 result = 31 * result + ( mergeConfiguration != null ? mergeConfiguration.hashCode( ) : 0 );
161 @SuppressWarnings( "StringBufferReplaceableByString" )
163 public String toString( )
165 final StringBuilder sb = new StringBuilder( "RepositoryGroup{" );
166 sb.append( "id='" ).append( id ).append( '\'' );
167 sb.append( ", repositories=" ).append( repositories );
168 sb.append( ", location='" ).append( location ).append( '\'' );
169 sb.append( ", mergeConfiguration=" ).append( mergeConfiguration );
171 return sb.toString( );