aboutsummaryrefslogtreecommitdiffstats
path: root/archiva-modules/archiva-web/archiva-rest/archiva-rest-api
diff options
context:
space:
mode:
Diffstat (limited to 'archiva-modules/archiva-web/archiva-rest/archiva-rest-api')
-rw-r--r--archiva-modules/archiva-web/archiva-rest/archiva-rest-api/pom.xml4
-rw-r--r--archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/v2/model/MavenManagedRepository.java2
-rw-r--r--archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/v2/model/map/MavenRepositoryMapper.java59
-rw-r--r--archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/v2/model/map/RestServiceMapper.java (renamed from archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/v2/model/map/RestMapper.java)7
-rw-r--r--archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/v2/model/map/ServiceMapperFactory.java47
-rw-r--r--archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/resources/META-INF/spring-context.xml33
6 files changed, 112 insertions, 40 deletions
diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/pom.xml b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/pom.xml
index 3075d15be..eeed333a3 100644
--- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/pom.xml
+++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/pom.xml
@@ -68,6 +68,10 @@
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-scheduler-indexing</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.apache.archiva.configuration</groupId>
+ <artifactId>archiva-configuration-model</artifactId>
+ </dependency>
<dependency>
<groupId>org.apache.archiva</groupId>
diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/v2/model/MavenManagedRepository.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/v2/model/MavenManagedRepository.java
index e82db108d..ba76efb85 100644
--- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/v2/model/MavenManagedRepository.java
+++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/v2/model/MavenManagedRepository.java
@@ -200,7 +200,7 @@ public class MavenManagedRepository extends Repository
}
@Schema(name="has_staging_repository", description = "True, if this repository has a staging repository assigned")
- public boolean isHasStagingRepository( )
+ public boolean hasStagingRepository( )
{
return hasStagingRepository;
}
diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/v2/model/map/MavenRepositoryMapper.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/v2/model/map/MavenRepositoryMapper.java
index d95dae4e3..305e8e798 100644
--- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/v2/model/map/MavenRepositoryMapper.java
+++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/v2/model/map/MavenRepositoryMapper.java
@@ -17,56 +17,93 @@ package org.apache.archiva.rest.api.v2.model.map;
* under the License.
*/
-import org.apache.archiva.common.ModelMapper;
import org.apache.archiva.configuration.model.ManagedRepositoryConfiguration;
+import org.apache.archiva.repository.ManagedRepository;
+import org.apache.archiva.repository.ReleaseScheme;
+import org.apache.archiva.repository.RepositoryType;
+import org.apache.archiva.repository.features.ArtifactCleanupFeature;
+import org.apache.archiva.repository.features.StagingRepositoryFeature;
import org.apache.archiva.rest.api.v2.model.MavenManagedRepository;
+import org.springframework.stereotype.Service;
/**
+ * Mapping implementation for Maven managed repository to managed repository configuration
+ *
* @author Martin Schreier <martin_s@apache.org>
*/
-public class MavenRepositoryMapper implements RestMapper<MavenManagedRepository, ManagedRepositoryConfiguration>
+@Service("mapper#managed_repository#maven")
+public class MavenRepositoryMapper extends RestServiceMapper<MavenManagedRepository, ManagedRepositoryConfiguration, ManagedRepository>
{
+
+ private static final String TYPE = RepositoryType.MAVEN.name( );
+
@Override
public ManagedRepositoryConfiguration map( MavenManagedRepository source )
{
- return null;
+ ManagedRepositoryConfiguration target = new ManagedRepositoryConfiguration( );
+ update( source, target );
+ return target;
}
@Override
public void update( MavenManagedRepository source, ManagedRepositoryConfiguration target )
{
+ target.setId( source.getId() );
+ target.setName( source.getName() );
+ target.setDescription( source.getDescription( ) );
+ target.setType( TYPE );
+
+ target.setBlockRedeployments( source.isBlocksRedeployments() );
+ target.setDeleteReleasedSnapshots( source.isDeleteSnapshotsOfRelease() );
+ target.setIndexDir( source.getIndexPath() );
+ target.setLayout( source.getLayout() );
+ target.setLocation( source.getLocation() );
+ target.setPackedIndexDir( source.getPackedIndexPath() );
+ target.setRefreshCronExpression( source.getSchedulingDefinition() );
+ target.setReleases( source.getReleaseSchemes( ).contains( ReleaseScheme.RELEASE ) );
+ target.setRetentionCount( source.getRetentionCount() );
+ target.setRetentionPeriod( source.getRetentionPeriod().getDays() );
+ target.setScanned( source.isScanned() );
+ target.setSkipPackedIndexCreation( source.isSkipPackedIndexCreation() );
+ target.setSnapshots( source.getReleaseSchemes( ).contains( ReleaseScheme.SNAPSHOT ) );
+ target.setStageRepoNeeded( source.hasStagingRepository() );
}
@Override
- public MavenManagedRepository reverseMap( ManagedRepositoryConfiguration target )
+ public MavenManagedRepository reverseMap( ManagedRepository source )
{
+ MavenManagedRepository result = new MavenManagedRepository( );
+ StagingRepositoryFeature srf = source.getFeature( StagingRepositoryFeature.class ).get( );
+ ArtifactCleanupFeature acf = source.getFeature( ArtifactCleanupFeature.class ).get( );
+ result.setHasStagingRepository( srf.isStageRepoNeeded() );
+ result.setBlocksRedeployments( source.blocksRedeployments() );
+ result.setIndex( source.hasIndex() );
+ result.setStagingRepository( srf.getStagingRepository().getId() );
return null;
}
@Override
- public void reverseUpdate( ManagedRepositoryConfiguration target, MavenManagedRepository source )
+ public void reverseUpdate( ManagedRepository source, MavenManagedRepository target )
{
}
@Override
- public Class<MavenManagedRepository> getSourceType( )
+ public Class<MavenManagedRepository> getBaseType( )
{
return MavenManagedRepository.class;
}
@Override
- public Class<ManagedRepositoryConfiguration> getTargetType( )
+ public Class<ManagedRepositoryConfiguration> getDestinationType( )
{
return ManagedRepositoryConfiguration.class;
}
@Override
- public <S, T> boolean supports( Class<S> sourceType, Class<T> targetType )
+ public Class<ManagedRepository> getReverseSourceType( )
{
- return (
- sourceType.isAssignableFrom( getSourceType() ) &&
- targetType.isAssignableFrom( getTargetType() ) );
+ return ManagedRepository.class;
}
}
diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/v2/model/map/RestMapper.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/v2/model/map/RestServiceMapper.java
index 36e6ee192..bccd8da21 100644
--- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/v2/model/map/RestMapper.java
+++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/v2/model/map/RestServiceMapper.java
@@ -17,13 +17,16 @@ package org.apache.archiva.rest.api.v2.model.map;
* under the License.
*/
-import org.apache.archiva.common.ModelMapper;
+import org.apache.archiva.common.AbstractMapper;
+import org.apache.archiva.common.MultiModelMapper;
import org.apache.archiva.configuration.model.ConfigurationModel;
+import org.apache.archiva.repository.Repository;
import org.apache.archiva.rest.api.v2.model.RestModel;
/**
* @author Martin Schreier <martin_s@apache.org>
*/
-public interface RestMapper<S extends RestModel, T extends ConfigurationModel> extends ModelMapper<S,T>
+public abstract class RestServiceMapper<S extends RestModel, T extends ConfigurationModel, R extends Repository> extends AbstractMapper<S,T,R>
+ implements MultiModelMapper<S,T,R>
{
}
diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/v2/model/map/ServiceMapperFactory.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/v2/model/map/ServiceMapperFactory.java
index 7d9ee87a7..0a9b55d4c 100644
--- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/v2/model/map/ServiceMapperFactory.java
+++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/v2/model/map/ServiceMapperFactory.java
@@ -17,13 +17,13 @@ package org.apache.archiva.rest.api.v2.model.map;
* under the License.
*/
-import org.apache.archiva.common.ModelMapper;
import org.apache.archiva.common.ModelMapperFactory;
+import org.apache.archiva.common.MultiModelMapper;
import org.apache.archiva.configuration.model.ConfigurationModel;
+import org.apache.archiva.repository.Repository;
import org.apache.archiva.rest.api.v2.model.RestModel;
import org.springframework.stereotype.Service;
-import javax.annotation.PostConstruct;
import javax.inject.Inject;
import java.util.HashMap;
import java.util.List;
@@ -32,45 +32,40 @@ import java.util.Map;
/**
* @author Martin Schreier <martin_s@apache.org>
*/
+@SuppressWarnings( "unchecked" )
@Service("modelMapperFactory#rest")
-public class ServiceMapperFactory implements ModelMapperFactory<RestModel, ConfigurationModel>
+public class ServiceMapperFactory implements ModelMapperFactory<RestModel, ConfigurationModel, Repository>
{
+ List<MultiModelMapper> modelMapperList;
+
@Inject
- List<ModelMapper> modelMapperList;
+ public ServiceMapperFactory( List<MultiModelMapper> modelMapperList )
+ {
+ this.modelMapperList = modelMapperList;
+ initMapper();
+ }
- Map<Class<? extends RestModel>, Map<Class<? extends ConfigurationModel>,ModelMapper<? extends RestModel, ? extends ConfigurationModel>>> modelMap;
+ Map<Integer, MultiModelMapper<? extends RestModel, ? extends ConfigurationModel, ? extends Repository>> modelMap = new HashMap<>( );
- @PostConstruct
void initMapper() {
modelMap = new HashMap<>( );
- for ( ModelMapper<?, ?> mapper : modelMapperList )
+ for ( MultiModelMapper<?, ?, ?> mapper : modelMapperList )
{
- if (!mapper.supports( RestModel.class, ConfigurationModel.class )) {
+ if (!mapper.supports( RestModel.class, ConfigurationModel.class, Repository.class )) {
continue;
}
- Class<? extends RestModel> sType = (Class<? extends RestModel>) mapper.getSourceType( );
- Class<? extends ConfigurationModel> tType = (Class<? extends ConfigurationModel>) mapper.getTargetType( );
- Map<Class<? extends ConfigurationModel>, ModelMapper<? extends RestModel, ? extends ConfigurationModel>> tMap;
- if (modelMap.containsKey( sType )) {
- tMap = modelMap.get( sType );
- } else {
- tMap = new HashMap<>( );
- }
- tMap.put( tType, (ModelMapper<? extends RestModel, ? extends ConfigurationModel>) mapper );
+ Integer key = mapper.hashCode( );
+ modelMap.put( key, (MultiModelMapper<? extends RestModel, ? extends ConfigurationModel, ? extends Repository>) mapper );
}
}
@Override
- public <S extends RestModel, T extends ConfigurationModel> ModelMapper<S, T> getMapper( Class<S> sourceType, Class<T> targetType ) throws IllegalArgumentException
+ public <S extends RestModel, T extends ConfigurationModel, R extends Repository> MultiModelMapper<S, T, R> getMapper( Class<S> baseType, Class<T> destinationType, Class<R> reverseSourceType ) throws IllegalArgumentException
{
- if (!modelMap.containsKey( sourceType )) {
- throw new IllegalArgumentException( "No mapper defined for the given source type "+sourceType );
- }
- Map<Class<? extends ConfigurationModel>, ModelMapper<? extends RestModel, ? extends ConfigurationModel>> tMap = modelMap.get( sourceType );
- if ( !tMap.containsKey( targetType ) )
- {
- throw new IllegalArgumentException( "No mapper defined for the given target type "+targetType );
+ Integer key = MultiModelMapper.getHash( baseType, destinationType, reverseSourceType );
+ if (!modelMap.containsKey( key )) {
+ throw new IllegalArgumentException( "No mapper defined for the given source type "+baseType );
}
- return (ModelMapper<S, T>) tMap.get( targetType );
+ return (MultiModelMapper<S, T, R>) modelMap.get( key );
}
}
diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/resources/META-INF/spring-context.xml b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/resources/META-INF/spring-context.xml
new file mode 100644
index 000000000..c8c8d6acf
--- /dev/null
+++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/resources/META-INF/spring-context.xml
@@ -0,0 +1,33 @@
+<?xml version="1.0"?>
+
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements. See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership. The ASF licenses this file
+ ~ to you under the Apache License, Version 2.0 (the
+ ~ "License"); you may not use this file except in compliance
+ ~ with the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing,
+ ~ software distributed under the License is distributed on an
+ ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ~ KIND, either express or implied. See the License for the
+ ~ specific language governing permissions and limitations
+ ~ under the License.
+ -->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:context="http://www.springframework.org/schema/context"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans
+ http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
+ http://www.springframework.org/schema/context
+ http://www.springframework.org/schema/context/spring-context-3.0.xsd" default-lazy-init="true">
+
+ <context:component-scan
+ base-package="org.apache.archiva.rest.api.v2.model.map"/>
+
+
+</beans>