001    package org.apache.archiva.metadata.model.maven2;
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    
022    import org.apache.archiva.metadata.model.MetadataFacet;
023    import org.apache.commons.lang.StringUtils;
024    
025    import java.util.HashMap;
026    import java.util.Map;
027    
028    public class MavenArtifactFacet
029        implements MetadataFacet
030    {
031        private String classifier;
032    
033        private String type;
034    
035        private String timestamp;
036    
037        private int buildNumber;
038    
039        public static final String FACET_ID = "org.apache.archiva.metadata.repository.storage.maven2.artifact";
040    
041        public String getClassifier()
042        {
043            return classifier;
044        }
045    
046        public void setClassifier( String classifier )
047        {
048            this.classifier = classifier;
049        }
050    
051        public String getType()
052        {
053            return type;
054        }
055    
056        public void setType( String type )
057        {
058            this.type = type;
059        }
060    
061        public String getTimestamp()
062        {
063            return timestamp;
064        }
065    
066        public void setTimestamp( String timestamp )
067        {
068            this.timestamp = timestamp;
069        }
070    
071        public int getBuildNumber()
072        {
073            return buildNumber;
074        }
075    
076        public void setBuildNumber( int buildNumber )
077        {
078            this.buildNumber = buildNumber;
079        }
080    
081        public String getFacetId()
082        {
083            return FACET_ID;
084        }
085    
086        public String getName()
087        {
088            // TODO: not needed, perhaps artifact/version metadata facet should be separate interface?
089            return null;
090        }
091    
092        public Map<String, String> toProperties()
093        {
094            Map<String, String> properties = new HashMap<String, String>();
095            properties.put( "type", type );
096            if ( classifier != null )
097            {
098                properties.put( "classifier", classifier );
099            }
100            if ( timestamp != null )
101            {
102                properties.put( "timestamp", timestamp );
103            }
104            if ( buildNumber > 0 )
105            {
106                properties.put( "buildNumber", Integer.toString( buildNumber ) );
107            }
108            return properties;
109        }
110    
111        public void fromProperties( Map<String, String> properties )
112        {
113            type = properties.get( "type" );
114            classifier = properties.get( "classifier" );
115            timestamp = properties.get( "timestamp" );
116            String buildNumber = properties.get( "buildNumber" );
117            if ( buildNumber != null )
118            {
119                this.buildNumber = Integer.parseInt( buildNumber );
120            }
121        }
122    
123        @Override
124        public boolean equals( Object o )
125        {
126            if ( this == o )
127            {
128                return true;
129            }
130            if ( !( o instanceof MavenArtifactFacet ) )
131            {
132                return false;
133            }
134    
135            MavenArtifactFacet that = (MavenArtifactFacet) o;
136    
137            return StringUtils.equals( that.getClassifier(), this.classifier );
138        }
139    
140    }