1 package org.apache.archiva.rest.api.v2.model.map;
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
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
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;
31 * Mapping implementation for Maven managed repository to managed repository configuration
33 * @author Martin Schreier <martin_s@apache.org>
35 @Service("mapper#managed_repository#maven")
36 public class MavenRepositoryMapper extends RestServiceMapper<MavenManagedRepository, ManagedRepositoryConfiguration, ManagedRepository>
39 private static final String TYPE = RepositoryType.MAVEN.name( );
42 public ManagedRepositoryConfiguration map( MavenManagedRepository source )
44 ManagedRepositoryConfiguration target = new ManagedRepositoryConfiguration( );
45 update( source, target );
50 public void update( MavenManagedRepository source, ManagedRepositoryConfiguration target )
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 );
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() );
83 public MavenManagedRepository reverseMap( ManagedRepository source )
85 MavenManagedRepository result = new MavenManagedRepository( );
86 reverseUpdate( source, result );
91 public void reverseUpdate( ManagedRepository source, MavenManagedRepository target )
93 StagingRepositoryFeature srf = source.getFeature( StagingRepositoryFeature.class );
94 ArtifactCleanupFeature acf = source.getFeature( ArtifactCleanupFeature.class );
95 IndexCreationFeature icf = source.getFeature( IndexCreationFeature.class );
98 target.setId( source.getId( ) );
99 target.setName( source.getName( ) );
100 target.setDescription( source.getDescription() );
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() );
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() );
124 public Class<MavenManagedRepository> getBaseType( )
126 return MavenManagedRepository.class;
130 public Class<ManagedRepositoryConfiguration> getDestinationType( )
132 return ManagedRepositoryConfiguration.class;
136 public Class<ManagedRepository> getReverseSourceType( )
138 return ManagedRepository.class;