This project has retired. For details please refer to its Attic page.
Source code
001package org.apache.archiva.metadata.repository.cassandra.model;
002
003/*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements.  See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership.  The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License.  You may obtain a copy of the License at
011 *
012 *   http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied.  See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022import static org.apache.archiva.metadata.repository.cassandra.model.ColumnNames.*;
023
024import org.apache.archiva.metadata.repository.cassandra.CassandraUtils;
025
026/**
027 * Cassandra storage model for {@link org.apache.archiva.metadata.model.MetadataFacet}
028 *
029 * @author Olivier Lamy
030 * @since 2.0.0
031 */
032public class MetadataFacetModel
033{
034    public static final String[] COLUMNS = new String[] { FACET_ID.toString(), KEY.toString(), VALUE.toString(),
035        REPOSITORY_NAME.toString(), NAMESPACE_ID.toString(), PROJECT_ID.toString(), PROJECT_VERSION.toString() };
036
037    private String facetId;
038
039    private String key;
040
041    private String name;
042
043    private String value;
044
045    private String projectVersion;
046
047    public MetadataFacetModel()
048    {
049        // no op
050    }
051
052    public MetadataFacetModel( String facetId, String key, String value, String name, String projectVersion )
053    {
054        this.key = key;
055        this.value = value;
056        this.name = name;
057        this.facetId = facetId;
058        this.projectVersion = projectVersion;
059    }
060
061    public String getFacetId()
062    {
063        return facetId;
064    }
065
066    public void setFacetId( String facetId )
067    {
068        this.facetId = facetId;
069    }
070
071
072    public String getName()
073    {
074        return name;
075    }
076
077    public void setName( String name )
078    {
079        this.name = name;
080    }
081
082    public String getKey()
083    {
084        return key;
085    }
086
087    public void setKey( String key )
088    {
089        this.key = key;
090    }
091
092    public String getValue()
093    {
094        return value;
095    }
096
097    public void setValue( String value )
098    {
099        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}