This project has retired. For details please refer to its Attic page.
MetadataFacetModel xref
View Javadoc
1   package org.apache.archiva.metadata.repository.cassandra.model;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.archiva.metadata.repository.cassandra.CassandraUtils;
23  
24  import static org.apache.archiva.metadata.repository.cassandra.model.ColumnNames.*;
25  
26  /**
27   * Cassandra storage model for {@link org.apache.archiva.metadata.model.MetadataFacet}
28   *
29   * @author Olivier Lamy
30   * @since 2.0.0
31   */
32  public class MetadataFacetModel
33  {
34      public static final String[] COLUMNS = new String[] { FACET_ID.toString(), KEY.toString(), VALUE.toString(),
35          REPOSITORY_NAME.toString(), NAMESPACE_ID.toString(), PROJECT_ID.toString(), PROJECT_VERSION.toString() };
36  
37      private String facetId;
38  
39      private String key;
40  
41      private String name;
42  
43      private String value;
44  
45      private String projectVersion;
46  
47      public MetadataFacetModel()
48      {
49          // no op
50      }
51  
52      public MetadataFacetModel( String facetId, String key, String value, String name, String projectVersion )
53      {
54          this.key = key;
55          this.value = value;
56          this.name = name;
57          this.facetId = facetId;
58          this.projectVersion = projectVersion;
59      }
60  
61      public String getFacetId()
62      {
63          return facetId;
64      }
65  
66      public void setFacetId( String facetId )
67      {
68          this.facetId = facetId;
69      }
70  
71  
72      public String getName()
73      {
74          return name;
75      }
76  
77      public void setName( String name )
78      {
79          this.name = name;
80      }
81  
82      public String getKey()
83      {
84          return key;
85      }
86  
87      public void setKey( String key )
88      {
89          this.key = key;
90      }
91  
92      public String getValue()
93      {
94          return value;
95      }
96  
97      public void setValue( String value )
98      {
99          this.value = value;
100     }
101 
102     public String getProjectVersion()
103     {
104         return projectVersion;
105     }
106 
107     public void setProjectVersion( String projectVersion )
108     {
109         this.projectVersion = projectVersion;
110     }
111 
112     @Override
113     public String toString()
114     {
115         final StringBuilder sb = new StringBuilder( "MetadataFacetModel{" );
116         sb.append( ", key='" ).append( key ).append( '\'' );
117         sb.append( ", value='" ).append( value ).append( '\'' );
118         sb.append( '}' );
119         return sb.toString();
120     }
121 
122     public static class KeyBuilder
123     {
124 
125         private ArtifactMetadataModel artifactMetadataModel;
126 
127         private String key;
128 
129         private String name;
130 
131         private String facetId;
132 
133         private String repositoryId;
134 
135         public KeyBuilder()
136         {
137 
138         }
139 
140         public KeyBuilder withArtifactMetadataModel( ArtifactMetadataModel artifactMetadataModel )
141         {
142             this.artifactMetadataModel = artifactMetadataModel;
143             return this;
144         }
145 
146         public KeyBuilder withKey( String key )
147         {
148             this.key = key;
149             return this;
150         }
151 
152         public KeyBuilder withName( String name )
153         {
154             this.name = name;
155             return this;
156         }
157 
158         public KeyBuilder withFacetId( String facetId )
159         {
160             this.facetId = facetId;
161             return this;
162         }
163 
164         public KeyBuilder withRepositoryId( String repositoryId )
165         {
166             this.repositoryId = repositoryId;
167             return this;
168         }
169 
170         public String build()
171         {
172             // FIXME add some controls
173             // getArtifactMetadataModelId can have no namespace, no project and no projectid for statistics
174             // only repositoryId with artifactMetadataModel
175             String str = CassandraUtils.generateKey( this.artifactMetadataModel == null
176                                                          ? this.repositoryId
177                                                          : new ArtifactMetadataModel.KeyBuilder().withNamespace(
178                                                              this.artifactMetadataModel.getNamespace() ) //
179                                                              .withProject( this.artifactMetadataModel.getProject() )  //
180                                                              .withProjectVersion(
181                                                                  this.artifactMetadataModel.getProjectVersion() ) //
182                                                              .withRepositoryId(
183                                                                  this.artifactMetadataModel.getRepositoryId() ) //
184                                                              .withId( this.artifactMetadataModel.getId() ) //
185                                                              .build(), //
186                                                      this.facetId, //
187                                                      this.name, //
188                                                      this.key
189             );
190 
191             return str;
192         }
193     }
194 }