]> source.dussan.org Git - archiva.git/blob
d9f00fc4d319ec92ea177f772e9ab74e41a6fa16
[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.StagingRepositoryFeature;
26 import org.apache.archiva.rest.api.v2.model.MavenManagedRepository;
27 import org.springframework.stereotype.Service;
28
29 /**
30  * Mapping implementation for Maven managed repository to managed repository configuration
31  *
32  * @author Martin Schreier <martin_s@apache.org>
33  */
34 @Service("mapper#managed_repository#maven")
35 public class MavenRepositoryMapper extends RestServiceMapper<MavenManagedRepository, ManagedRepositoryConfiguration, ManagedRepository>
36 {
37
38     private static final String TYPE = RepositoryType.MAVEN.name( );
39
40     @Override
41     public ManagedRepositoryConfiguration map( MavenManagedRepository source )
42     {
43         ManagedRepositoryConfiguration target = new ManagedRepositoryConfiguration( );
44         update( source, target );
45         return target;
46     }
47
48     @Override
49     public void update( MavenManagedRepository source, ManagedRepositoryConfiguration target )
50     {
51         target.setId( source.getId() );
52         target.setName( source.getName() );
53         target.setDescription( source.getDescription( ) );
54         target.setType( TYPE );
55
56         target.setBlockRedeployments( source.isBlocksRedeployments() );
57         target.setDeleteReleasedSnapshots( source.isDeleteSnapshotsOfRelease() );
58         target.setIndexDir( source.getIndexPath() );
59         target.setLayout( source.getLayout() );
60         target.setLocation( source.getLocation() );
61         target.setPackedIndexDir( source.getPackedIndexPath() );
62         target.setRefreshCronExpression( source.getSchedulingDefinition() );
63         target.setReleases( source.getReleaseSchemes( ).contains( ReleaseScheme.RELEASE ) );
64         target.setRetentionCount( source.getRetentionCount() );
65         target.setRetentionPeriod( source.getRetentionPeriod().getDays() );
66         target.setScanned( source.isScanned() );
67         target.setSkipPackedIndexCreation( source.isSkipPackedIndexCreation() );
68         target.setSnapshots( source.getReleaseSchemes( ).contains( ReleaseScheme.SNAPSHOT ) );
69         target.setStageRepoNeeded( source.hasStagingRepository() );
70
71     }
72
73     @Override
74     public MavenManagedRepository reverseMap( ManagedRepository source )
75     {
76         MavenManagedRepository result = new MavenManagedRepository( );
77         StagingRepositoryFeature srf = source.getFeature( StagingRepositoryFeature.class );
78         ArtifactCleanupFeature acf = source.getFeature( ArtifactCleanupFeature.class );
79         result.setHasStagingRepository( srf.isStageRepoNeeded() );
80         result.setBlocksRedeployments( source.blocksRedeployments() );
81         result.setIndex( source.hasIndex() );
82         result.setStagingRepository( srf.getStagingRepository().getId() );
83         return null;
84     }
85
86     @Override
87     public void reverseUpdate( ManagedRepository source, MavenManagedRepository target )
88     {
89
90     }
91
92     @Override
93     public Class<MavenManagedRepository> getBaseType( )
94     {
95         return MavenManagedRepository.class;
96     }
97
98     @Override
99     public Class<ManagedRepositoryConfiguration> getDestinationType( )
100     {
101         return ManagedRepositoryConfiguration.class;
102     }
103
104     @Override
105     public Class<ManagedRepository> getReverseSourceType( )
106     {
107         return ManagedRepository.class;
108     }
109 }