diff options
author | Martin Schreier <martin_s@apache.org> | 2022-01-11 21:30:42 +0100 |
---|---|---|
committer | Martin Schreier <martin_s@apache.org> | 2022-01-11 21:30:42 +0100 |
commit | 9a102721d6f0e4ef951901427c43f5c0dc936fd7 (patch) | |
tree | 30ba2ff907d396bb8b02db602f96a2e7d85bc5eb | |
parent | a0c5e5a0b0ad6502b0e3c82862bf57287c6a1c15 (diff) | |
download | archiva-9a102721d6f0e4ef951901427c43f5c0dc936fd7.tar.gz archiva-9a102721d6f0e4ef951901427c43f5c0dc936fd7.zip |
Changing mapper interface
16 files changed, 213 insertions, 79 deletions
diff --git a/archiva-modules/archiva-base/archiva-common/src/main/java/org/apache/archiva/common/AbstractMapper.java b/archiva-modules/archiva-base/archiva-common/src/main/java/org/apache/archiva/common/AbstractMapper.java new file mode 100644 index 000000000..c77c91cbe --- /dev/null +++ b/archiva-modules/archiva-base/archiva-common/src/main/java/org/apache/archiva/common/AbstractMapper.java @@ -0,0 +1,46 @@ +package org.apache.archiva.common; +/* + * 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. + */ + +/** + * @author Martin Schreier <martin_s@apache.org> + */ +public abstract class AbstractMapper<B,T,R> implements MultiModelMapper<B,T,R> +{ + @Override + public <S2, T2, R2> boolean supports( Class<S2> baseType, Class<T2> destinationType, Class<R2> reverseSourceType ) + { + return ( + baseType.isAssignableFrom( getBaseType( ) ) && + destinationType.isAssignableFrom( getDestinationType( ) ) && + reverseSourceType.isAssignableFrom( getReverseSourceType( ) ) + ); + } + + @Override + public int hashCode( ) + { + return getHash(); + } + + @Override + public boolean equals( Object obj ) + { + return super.hashCode( ) == obj.hashCode( ); + } +} diff --git a/archiva-modules/archiva-base/archiva-common/src/main/java/org/apache/archiva/common/ModelMapperFactory.java b/archiva-modules/archiva-base/archiva-common/src/main/java/org/apache/archiva/common/ModelMapperFactory.java index 30ee0c4c3..159b95d19 100644 --- a/archiva-modules/archiva-base/archiva-common/src/main/java/org/apache/archiva/common/ModelMapperFactory.java +++ b/archiva-modules/archiva-base/archiva-common/src/main/java/org/apache/archiva/common/ModelMapperFactory.java @@ -22,19 +22,21 @@ package org.apache.archiva.common; * * @author Martin Schreier <martin_s@apache.org> * - * @param <SB> The base source type for the model mapper - * @param <TB> The base target type for the model mapper + * @param <B> The base type for the model mapper + * @param <T> The target type for the model mapper + * @param <R> The reverse source type for the model mapper */ -public interface ModelMapperFactory<SB,TB> +public interface ModelMapperFactory<B,T,R> { /** * Returns a mapper for the given source and target type. If no mapper is registered for this combination, * it will throw a {@link IllegalArgumentException} - * @param sourceType the source type for the mapping - * @param targetType the destination type - * @param <S> source type - * @param <T> destination type + * @param baseType the source type for the mapping + * @param destinationType the destination type + * @param <B2> base type + * @param <T2> destination type + * @param <R2> Reverse source type * @return the mapper instance */ - <S extends SB, T extends TB> ModelMapper<S, T> getMapper( Class<S> sourceType, Class<T> targetType ) throws IllegalArgumentException; + <B2 extends B, T2 extends T, R2 extends R> MultiModelMapper<B2, T2, R2> getMapper( Class<B2> baseType, Class<T2> destinationType, Class<R2> reverseSourceType ) throws IllegalArgumentException; } diff --git a/archiva-modules/archiva-base/archiva-common/src/main/java/org/apache/archiva/common/ModelMapper.java b/archiva-modules/archiva-base/archiva-common/src/main/java/org/apache/archiva/common/MultiModelMapper.java index 1f7fda93b..d28b6da67 100644 --- a/archiva-modules/archiva-base/archiva-common/src/main/java/org/apache/archiva/common/ModelMapper.java +++ b/archiva-modules/archiva-base/archiva-common/src/main/java/org/apache/archiva/common/MultiModelMapper.java @@ -22,57 +22,72 @@ package org.apache.archiva.common; * * @author Martin Schreier <martin_s@apache.org> */ -public interface ModelMapper<S,T> +public interface MultiModelMapper<B,T,R> { /** * Converts the source instance to a new instance of the target type. * @param source the source instance * @return a new instance of the target type */ - T map(S source); + T map( B source); /** * Updates the target instance based on the source instance * @param source the source instance * @param target the target instance */ - void update( S source, T target ); + void update( B source, T target ); /** * Converts the target instance back to the source type - * @param target the target instance + * @param source the target instance * @return a new instance of the source type */ - S reverseMap(T target); + B reverseMap( R source); /** * Updates the source instance based on the target instance - * @param target the target instance - * @param source the source instance + * @param source the target instance + * @param target the source instance */ - void reverseUpdate( T target, S source); + void reverseUpdate( R source, B target); /** * Returns the class name of the source type * @return the source type */ - Class<S> getSourceType(); + Class<B> getBaseType(); /** - * Returns the class name of the target type + * Returns the class name of type that is the goal for the mapping. * @return the target type */ - Class<T> getTargetType(); + Class<T> getDestinationType(); + + /** + * Returns the class name of the source for the reverse mapping. + * @return + */ + Class<R> getReverseSourceType(); /** * Returns <code>true</code>, if the given type are the same or supertype of the mapping types. - * @param sourceType - * @param targetType + * @param baseType + * @param destinationType + * @param reverseSourceType * @param <S> * @param <T> * @return */ - <S, T> boolean supports( Class<S> sourceType, Class<T> targetType ); + <S, T, R> boolean supports( Class<S> baseType, Class<T> destinationType, Class<R> reverseSourceType); + + default int getHash() { + return getHash(getBaseType( ), getDestinationType( ), getReverseSourceType( ) ); + } + + static int getHash(Class<?> baseType, Class<?> destinationType, Class<?> reverseSourceType) { + return baseType.hashCode( ) ^ destinationType.hashCode( ) ^ reverseSourceType.hashCode( ); + } } diff --git a/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-model/pom.xml b/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-model/pom.xml index bd2591722..988c6f598 100644 --- a/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-model/pom.xml +++ b/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-model/pom.xml @@ -21,8 +21,8 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <parent> - <artifactId>archiva-configuration</artifactId> <groupId>org.apache.archiva.configuration</groupId> + <artifactId>archiva-configuration</artifactId> <version>3.0.0-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> diff --git a/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-model/src/main/java/org/apache/archiva/configuration/model/ConfigurationModel.java b/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-model/src/main/java/org/apache/archiva/configuration/model/ConfigurationModel.java index 6a9520aa7..0fbcd3054 100644 --- a/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-model/src/main/java/org/apache/archiva/configuration/model/ConfigurationModel.java +++ b/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-model/src/main/java/org/apache/archiva/configuration/model/ConfigurationModel.java @@ -18,6 +18,8 @@ package org.apache.archiva.configuration.model; */ /** + * Marker interface that is used for configuration model classes. + * * @author Martin Schreier <martin_s@apache.org> */ public interface ConfigurationModel diff --git a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/Repository.java b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/Repository.java index ac20ed536..323b071ef 100644 --- a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/Repository.java +++ b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/Repository.java @@ -23,7 +23,6 @@ import org.apache.archiva.indexer.ArchivaIndexingContext; import org.apache.archiva.event.EventSource; import org.apache.archiva.repository.storage.RepositoryStorage; import org.apache.archiva.repository.features.RepositoryFeature; -import org.apache.archiva.repository.storage.StorageAsset; import java.net.URI; import java.util.Locale; @@ -136,12 +135,12 @@ public interface Repository extends EventSource, RepositoryStorage { * Extension method that allows to provide different features that are not supported by all * repository types. * - * @param clazz The feature class that is requested * @param <T> This is the class of the feature + * @param clazz The feature class that is requested * @return The feature implementation for this repository instance, if it is supported * @throws UnsupportedFeatureException if the feature is not supported by this repository type */ - <T extends RepositoryFeature<T>> RepositoryFeature<T> getFeature(Class<T> clazz) throws UnsupportedFeatureException; + <T extends RepositoryFeature<T>> T getFeature( Class<T> clazz) throws UnsupportedFeatureException; /** diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/base/AbstractRepository.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/base/AbstractRepository.java index b01efafd7..694b36dd1 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/base/AbstractRepository.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/base/AbstractRepository.java @@ -22,7 +22,6 @@ package org.apache.archiva.repository.base; import com.cronutils.model.CronType; import com.cronutils.model.definition.CronDefinition; import com.cronutils.model.definition.CronDefinitionBuilder; -import com.cronutils.parser.CronParser; import org.apache.archiva.event.Event; import org.apache.archiva.event.EventHandler; import org.apache.archiva.event.EventManager; @@ -38,7 +37,6 @@ import org.apache.archiva.repository.storage.RepositoryStorage; import org.apache.archiva.repository.storage.StorageAsset; import org.apache.archiva.repository.features.RepositoryFeature; import org.apache.archiva.repository.features.StagingRepositoryFeature; -import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -200,10 +198,10 @@ public abstract class AbstractRepository implements EditableRepository, EventHan @SuppressWarnings( "unchecked" ) @Override - public <T extends RepositoryFeature<T>> RepositoryFeature<T> getFeature( Class<T> clazz ) throws UnsupportedFeatureException + public <T extends RepositoryFeature<T>> T getFeature( Class<T> clazz ) throws UnsupportedFeatureException { if (featureMap.containsKey( clazz )) { - return (RepositoryFeature<T>) featureMap.get(clazz); + return (T) featureMap.get(clazz); } else { throw new UnsupportedFeatureException( "Feature " + clazz + " not supported" ); diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/maven/repository/MavenManagedRepository.java b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/maven/repository/MavenManagedRepository.java index 5e81f868a..388c69cea 100644 --- a/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/maven/repository/MavenManagedRepository.java +++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/maven/repository/MavenManagedRepository.java @@ -96,15 +96,15 @@ public class MavenManagedRepository extends AbstractManagedRepository @SuppressWarnings( "unchecked" ) @Override - public <T extends RepositoryFeature<T>> RepositoryFeature<T> getFeature( Class<T> clazz ) throws UnsupportedFeatureException + public <T extends RepositoryFeature<T>> T getFeature( Class<T> clazz ) throws UnsupportedFeatureException { if (ArtifactCleanupFeature.class.equals( clazz )) { - return (RepositoryFeature<T>) artifactCleanupFeature; + return (T) artifactCleanupFeature; } else if (IndexCreationFeature.class.equals(clazz)) { - return (RepositoryFeature<T>) indexCreationFeature; + return (T) indexCreationFeature; } else if (StagingRepositoryFeature.class.equals(clazz)) { - return (RepositoryFeature<T>) stagingRepositoryFeature; + return (T) stagingRepositoryFeature; } else { throw new UnsupportedFeatureException( ); } diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/maven/repository/MavenRemoteRepository.java b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/maven/repository/MavenRemoteRepository.java index 1be681ece..95ad5a809 100644 --- a/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/maven/repository/MavenRemoteRepository.java +++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/maven/repository/MavenRemoteRepository.java @@ -91,12 +91,12 @@ public class MavenRemoteRepository extends AbstractRemoteRepository @SuppressWarnings( "unchecked" ) @Override - public <T extends RepositoryFeature<T>> RepositoryFeature<T> getFeature( Class<T> clazz ) throws UnsupportedFeatureException + public <T extends RepositoryFeature<T>> T getFeature( Class<T> clazz ) throws UnsupportedFeatureException { if (RemoteIndexFeature.class.equals( clazz )) { - return (RepositoryFeature<T>) remoteIndexFeature; + return (T) remoteIndexFeature; } else if (IndexCreationFeature.class.equals(clazz)) { - return (RepositoryFeature<T>) indexCreationFeature; + return (T) indexCreationFeature; } else { throw new UnsupportedFeatureException( ); } 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> diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/v2/svc/maven/DefaultMavenManagedRepositoryService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/v2/svc/maven/DefaultMavenManagedRepositoryService.java index f62fef2e0..5bec54dff 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/v2/svc/maven/DefaultMavenManagedRepositoryService.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/v2/svc/maven/DefaultMavenManagedRepositoryService.java @@ -220,7 +220,7 @@ public class DefaultMavenManagedRepositoryService implements MavenManagedReposit } try { - managedRepositoryAdmin.addManagedRepository( convert( managedRepository ), managedRepository.isHasStagingRepository(), getAuditInformation() ); + managedRepositoryAdmin.addManagedRepository( convert( managedRepository ), managedRepository.hasStagingRepository(), getAuditInformation() ); httpServletResponse.setStatus( 201 ); return MavenManagedRepository.of( repositoryRegistry.getManagedRepository( repoId ) ); } @@ -236,7 +236,7 @@ public class DefaultMavenManagedRepositoryService implements MavenManagedReposit org.apache.archiva.admin.model.beans.ManagedRepository repo = convert( managedRepository ); try { - managedRepositoryAdmin.updateManagedRepository( repo, managedRepository.isHasStagingRepository( ), getAuditInformation( ), managedRepository.isResetStats( ) ); + managedRepositoryAdmin.updateManagedRepository( repo, managedRepository.hasStagingRepository( ), getAuditInformation( ), managedRepository.isResetStats( ) ); ManagedRepository newRepo = repositoryRegistry.getManagedRepository( managedRepository.getId( ) ); if (newRepo==null) { throw new ArchivaRestServiceException( ErrorMessage.of( ErrorKeys.REPOSITORY_UPDATE_FAILED, repositoryId ) ); |