]> source.dussan.org Git - archiva.git/blob
1e4ed68a0b354bd8ea3b64ac456c59a1eb819fb8
[archiva.git] /
1 package org.apache.archiva.rest.api.v2.model.map;
2 /*
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied.  See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  */
19
20 import org.apache.archiva.configuration.model.ManagedRepositoryConfiguration;
21 import org.apache.archiva.repository.ManagedRepository;
22 import org.apache.archiva.repository.ReleaseScheme;
23 import org.apache.archiva.repository.RepositoryType;
24 import org.apache.archiva.repository.features.ArtifactCleanupFeature;
25 import org.apache.archiva.repository.features.IndexCreationFeature;
26 import org.apache.archiva.repository.features.StagingRepositoryFeature;
27 import org.apache.archiva.rest.api.v2.model.MavenManagedRepository;
28 import org.springframework.stereotype.Service;
29
30 /**
31  * Mapping implementation for Maven managed repository to managed repository configuration
32  *
33  * @author Martin Schreier <martin_s@apache.org>
34  */
35 @Service("mapper#managed_repository#maven")
36 public class MavenRepositoryMapper extends RestServiceMapper<MavenManagedRepository, ManagedRepositoryConfiguration, ManagedRepository>
37 {
38
39     private static final String TYPE = RepositoryType.MAVEN.name( );
40
41     @Override
42     public ManagedRepositoryConfiguration map( MavenManagedRepository source )
43     {
44         ManagedRepositoryConfiguration target = new ManagedRepositoryConfiguration( );
45         update( source, target );
46         return target;
47     }
48
49     @Override
50     public void update( MavenManagedRepository source, ManagedRepositoryConfiguration target )
51     {
52         if (source.getId()!=null)
53             target.setId( source.getId() );
54         if (source.getName()!=null)
55             target.setName( source.getName() );
56         if (source.getDescription()!=null)
57             target.setDescription( source.getDescription( ) );
58         target.setType( TYPE );
59
60         target.setBlockRedeployments( source.isBlocksRedeployments() );
61         target.setDeleteReleasedSnapshots( source.isDeleteSnapshotsOfRelease() );
62         if (source.getIndexPath()!=null)
63             target.setIndexDir( source.getIndexPath() );
64         if (source.getLayout()!=null)
65             target.setLayout( source.getLayout() );
66         if (source.getLocation()!=null)
67             target.setLocation( source.getLocation() );
68         if (source.getPackedIndexPath()!=null)
69             target.setPackedIndexDir( source.getPackedIndexPath() );
70         if (source.getSchedulingDefinition()!=null)
71             target.setRefreshCronExpression( source.getSchedulingDefinition() );
72         target.setReleases( source.getReleaseSchemes( ).contains( ReleaseScheme.RELEASE.name() ) );
73         target.setRetentionCount( source.getRetentionCount() );
74         target.setRetentionPeriod( source.getRetentionPeriod().getDays() );
75         target.setScanned( source.isScanned() );
76         target.setSkipPackedIndexCreation( source.isSkipPackedIndexCreation() );
77         target.setSnapshots( source.getReleaseSchemes( ).contains( ReleaseScheme.SNAPSHOT.name() ) );
78         target.setStageRepoNeeded( source.hasStagingRepository() );
79
80     }
81
82     @Override
83     public MavenManagedRepository reverseMap( ManagedRepository source )
84     {
85         MavenManagedRepository result = new MavenManagedRepository( );
86         reverseUpdate( source, result );
87         return result;
88     }
89
90     @Override
91     public void reverseUpdate( ManagedRepository source, MavenManagedRepository target )
92     {
93         StagingRepositoryFeature srf = source.getFeature( StagingRepositoryFeature.class );
94         ArtifactCleanupFeature acf = source.getFeature( ArtifactCleanupFeature.class );
95         IndexCreationFeature icf = source.getFeature( IndexCreationFeature.class );
96
97
98         target.setId( source.getId( ) );
99         target.setName( source.getName( ) );
100         target.setDescription( source.getDescription() );
101
102         target.setBlocksRedeployments( source.blocksRedeployments() );
103         target.setDeleteSnapshotsOfRelease( acf.isDeleteReleasedSnapshots() );
104         target.setIndex( source.hasIndex() );
105         target.setIndexPath( icf.getIndexPath().toString() );
106         target.setLayout( source.getLayout() );
107         target.setLocation( source.getLocation().toString() );
108         target.setPackedIndexPath( icf.getPackedIndexPath().toString() );
109         target.setSchedulingDefinition( source.getSchedulingDefinition() );
110         for ( ReleaseScheme scheme: source.getActiveReleaseSchemes() ) {
111             target.addReleaseScheme( scheme.toString() );
112         }
113         target.setRetentionCount( acf.getRetentionCount() );
114         target.setRetentionPeriod( acf.getRetentionPeriod() );
115         target.setScanned( source.isScanned() );
116         target.setSkipPackedIndexCreation( icf.isSkipPackedIndexCreation() );
117         if (srf.getStagingRepository()!=null)
118             target.setStagingRepository( srf.getStagingRepository().getId() );
119         target.setHasStagingRepository( srf.isStageRepoNeeded() );
120
121     }
122
123     @Override
124     public Class<MavenManagedRepository> getBaseType( )
125     {
126         return MavenManagedRepository.class;
127     }
128
129     @Override
130     public Class<ManagedRepositoryConfiguration> getDestinationType( )
131     {
132         return ManagedRepositoryConfiguration.class;
133     }
134
135     @Override
136     public Class<ManagedRepository> getReverseSourceType( )
137     {
138         return ManagedRepository.class;
139     }
140 }