aboutsummaryrefslogtreecommitdiffstats
path: root/archiva-modules/archiva-web
diff options
context:
space:
mode:
authorMartin Schreier <martin_s@apache.org>2022-02-13 10:27:32 +0100
committerMartin Schreier <martin_s@apache.org>2022-02-13 10:27:32 +0100
commit0a2dab16770cce10bda6fa2cc2e2d9c7d64c5dbf (patch)
tree1e633e0ae7fc56a857b5467a12a67adfc017b9e2 /archiva-modules/archiva-web
parent99bd81ac000598105529473a53f62a5b53d885a5 (diff)
downloadarchiva-0a2dab16770cce10bda6fa2cc2e2d9c7d64c5dbf.tar.gz
archiva-0a2dab16770cce10bda6fa2cc2e2d9c7d64c5dbf.zip
Improving event API
Diffstat (limited to 'archiva-modules/archiva-web')
-rw-r--r--archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/v2/model/MavenManagedRepository.java31
-rw-r--r--archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/v2/model/MavenManagedRepositoryUpdate.java9
-rw-r--r--archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/v2/model/map/MavenRepositoryMapper.java12
-rw-r--r--archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/v2/svc/ErrorKeys.java6
-rw-r--r--archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/test/java/org/apache/archiva/rest/api/v2/model/map/MavenRepositoryMapperTest.java45
-rw-r--r--archiva-modules/archiva-web/archiva-rest/archiva-rest-services/pom.xml4
-rw-r--r--archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/v2/svc/AbstractService.java51
-rw-r--r--archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/v2/svc/maven/DefaultMavenManagedRepositoryService.java57
-rw-r--r--archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/v2/svc/maven/NativeMavenManagedRepositoryServiceTest.java3
9 files changed, 143 insertions, 75 deletions
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 01ec552c0..d3ce96819 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
@@ -73,37 +73,6 @@ public class MavenManagedRepository extends Repository
super.setType( RepositoryType.MAVEN.name( ) );
}
- protected static void update(MavenManagedRepository repo, ManagedRepository beanRepo) {
- repo.setDescription( beanRepo.getDescription() );
- repo.setId( beanRepo.getId() );
- repo.setIndex( true );
- repo.setLayout( beanRepo.getLayout() );
- repo.setBlocksRedeployments( beanRepo.blocksRedeployments() );
- repo.setReleaseSchemes( beanRepo.getActiveReleaseSchemes().stream().map( Objects::toString).collect( Collectors.toList()) );
- repo.setLocation( beanRepo.getLocation().toString() );
- repo.setName( beanRepo.getName());
- repo.setScanned( beanRepo.isScanned() );
- repo.setSchedulingDefinition( beanRepo.getSchedulingDefinition() );
- ArtifactCleanupFeature artifactCleanupFeature = beanRepo.getFeature( ArtifactCleanupFeature.class );
- repo.setDeleteSnapshotsOfRelease( artifactCleanupFeature.isDeleteReleasedSnapshots());
- repo.setRetentionCount( artifactCleanupFeature.getRetentionCount());
- repo.setRetentionPeriod( artifactCleanupFeature.getRetentionPeriod() );
- IndexCreationFeature icf = beanRepo.getFeature( IndexCreationFeature.class );
- repo.setIndex( icf.hasIndex( ) );
- repo.setIndexPath( icf.getIndexPath( ).getPath( ) );
- repo.setPackedIndexPath( icf.getPackedIndexPath( ).getPath( ) );
- repo.setSkipPackedIndexCreation( icf.isSkipPackedIndexCreation() );
- StagingRepositoryFeature srf = beanRepo.getFeature( StagingRepositoryFeature.class );
- repo.setHasStagingRepository( srf.isStageRepoNeeded( ) );
- repo.setStagingRepository( srf.getStagingRepository()!=null?srf.getStagingRepository().getId():"" );
- }
-
- public static MavenManagedRepository of( ManagedRepository beanRepo ) {
- MavenManagedRepository repo = new MavenManagedRepository( );
- update( repo, beanRepo );
- return repo;
- }
-
@Schema(name="blocks_redeployments",description = "True, if redeployments to this repository are not allowed")
public boolean isBlocksRedeployments( )
{
diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/v2/model/MavenManagedRepositoryUpdate.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/v2/model/MavenManagedRepositoryUpdate.java
index 5536ae9b0..1fcb1a0e3 100644
--- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/v2/model/MavenManagedRepositoryUpdate.java
+++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/v2/model/MavenManagedRepositoryUpdate.java
@@ -17,6 +17,7 @@ package org.apache.archiva.rest.api.v2.model;
* under the License.
*/
+import io.swagger.v3.oas.annotations.media.Schema;
import org.apache.archiva.repository.ManagedRepository;
import java.io.Serializable;
@@ -24,17 +25,13 @@ import java.io.Serializable;
/**
* @author Martin Stockhammer <martin_s@apache.org>
*/
+@Schema(name="MavenManagedRepositoryUpdate",description = "Data object for updating maven managed repositories")
public class MavenManagedRepositoryUpdate extends MavenManagedRepository implements Serializable
{
private static final long serialVersionUID = -9181643343284109862L;
private boolean resetStats = false;
- public static MavenManagedRepositoryUpdate of( ManagedRepository repository ) {
- MavenManagedRepositoryUpdate repo = new MavenManagedRepositoryUpdate( );
- update( repo, repository );
- return repo;
- }
-
+ @Schema(name="reset_stats",description = "True, if statistics should be reset after update")
public boolean isResetStats( )
{
return resetStats;
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 1e4ed68a0..75be52388 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
@@ -64,14 +64,22 @@ public class MavenRepositoryMapper extends RestServiceMapper<MavenManagedReposit
if (source.getLayout()!=null)
target.setLayout( source.getLayout() );
if (source.getLocation()!=null)
- target.setLocation( source.getLocation() );
+ {
+ target.setLocation( source.getLocation( ) );
+ } else {
+ if (target.getLocation()==null) {
+ target.setLocation( "" );
+ }
+ }
+
if (source.getPackedIndexPath()!=null)
target.setPackedIndexDir( source.getPackedIndexPath() );
if (source.getSchedulingDefinition()!=null)
target.setRefreshCronExpression( source.getSchedulingDefinition() );
target.setReleases( source.getReleaseSchemes( ).contains( ReleaseScheme.RELEASE.name() ) );
target.setRetentionCount( source.getRetentionCount() );
- target.setRetentionPeriod( source.getRetentionPeriod().getDays() );
+ if (source.getRetentionPeriod()!=null)
+ target.setRetentionPeriod( source.getRetentionPeriod().getDays() );
target.setScanned( source.isScanned() );
target.setSkipPackedIndexCreation( source.isSkipPackedIndexCreation() );
target.setSnapshots( source.getReleaseSchemes( ).contains( ReleaseScheme.SNAPSHOT.name() ) );
diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/v2/svc/ErrorKeys.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/v2/svc/ErrorKeys.java
index cc0a836a2..57e4d401f 100644
--- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/v2/svc/ErrorKeys.java
+++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/v2/svc/ErrorKeys.java
@@ -122,4 +122,10 @@ public interface ErrorKeys
* When the operation needs authentication, but not authenticated user was found in the request context.
*/
String NOT_AUTHENTICATED = PREFIX + "user.not_authenticated";
+
+ /**
+ * Repository add action failed
+ */
+ String REPOSITORY_ADD_FAILED = PREFIX + "add.failed";
+
}
diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/test/java/org/apache/archiva/rest/api/v2/model/map/MavenRepositoryMapperTest.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/test/java/org/apache/archiva/rest/api/v2/model/map/MavenRepositoryMapperTest.java
index 0fd77703c..3f0e04e12 100644
--- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/test/java/org/apache/archiva/rest/api/v2/model/map/MavenRepositoryMapperTest.java
+++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/test/java/org/apache/archiva/rest/api/v2/model/map/MavenRepositoryMapperTest.java
@@ -141,6 +141,51 @@ class MavenRepositoryMapperTest
}
@Test
+ void updateWithNullValues( )
+ {
+ MavenRepositoryMapper mapper = new MavenRepositoryMapper( );
+ MavenManagedRepository repo = new MavenManagedRepository( );
+ ManagedRepositoryConfiguration result = new ManagedRepositoryConfiguration( );
+ repo.setId( "repo01" );
+ repo.setName( "Repo 01" );
+ repo.setDescription( "This is repo 01" );
+ repo.setLocation( null );
+ repo.setHasStagingRepository( true );
+ repo.setSchedulingDefinition( "0,1,2 * * * *" );
+ repo.setPackedIndexPath( null );
+ repo.setIndexPath( null );
+ repo.setIndex( true );
+ repo.setDeleteSnapshotsOfRelease( false );
+ repo.setBlocksRedeployments( false );
+ repo.setReleaseSchemes( Arrays.asList( ReleaseScheme.RELEASE.name(), ReleaseScheme.SNAPSHOT.name() ) );
+ repo.setCharacteristic( Repository.CHARACTERISTIC_MANAGED );
+ repo.setScanned( true );
+ repo.setRetentionPeriod( null );
+ repo.setRetentionCount( 15 );
+ repo.setSkipPackedIndexCreation( false );
+ repo.setStagingRepository( null );
+ mapper.update( repo, result );
+
+ assertNotNull( result );
+ assertEquals( "repo01", result.getId( ) );
+ assertEquals( "Repo 01", result.getName( ) );
+ assertEquals( "This is repo 01", result.getDescription( ) );
+ assertNotNull( result.getLocation( ) );
+ assertTrue( result.isStageRepoNeeded( ) );
+ assertEquals( "0,1,2 * * * *", result.getRefreshCronExpression( ) );
+ assertEquals( "", result.getIndexDir( ) );
+ assertEquals( "", result.getPackedIndexDir( ) );
+ assertFalse( result.isDeleteReleasedSnapshots( ) );
+ assertFalse( result.isBlockRedeployments( ) );
+ assertTrue( result.isSnapshots( ) );
+ assertTrue( result.isReleases( ) );
+ assertTrue( result.isScanned( ) );
+ assertEquals( 100, result.getRetentionPeriod( ) );
+ assertEquals( 15, result.getRetentionCount( ) );
+ assertFalse( result.isSkipPackedIndexCreation( ) );
+ }
+
+ @Test
void reverseMap( ) throws IOException, URISyntaxException, UnsupportedURIException
{
MavenRepositoryMapper mapper = new MavenRepositoryMapper( );
diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/pom.xml b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/pom.xml
index 7dd8dad50..519fb1e5b 100644
--- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/pom.xml
+++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/pom.xml
@@ -49,6 +49,10 @@
<artifactId>archiva-storage-api</artifactId>
</dependency>
<dependency>
+ <groupId>org.apache.archiva.event</groupId>
+ <artifactId>archiva-event-api</artifactId>
+ </dependency>
+ <dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-repository-admin-api</artifactId>
</dependency>
diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/v2/svc/AbstractService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/v2/svc/AbstractService.java
new file mode 100644
index 000000000..09e367e8a
--- /dev/null
+++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/v2/svc/AbstractService.java
@@ -0,0 +1,51 @@
+package org.apache.archiva.rest.v2.svc;
+/*
+ * 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.
+ */
+
+import org.apache.archiva.admin.model.AuditInformation;
+import org.apache.archiva.redback.rest.services.RedbackAuthenticationThreadLocal;
+import org.apache.archiva.redback.rest.services.RedbackRequestInformation;
+import org.apache.archiva.redback.users.User;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.core.Context;
+
+/**
+ * @author Martin Schreier <martin_s@apache.org>
+ */
+public class AbstractService
+{
+ @Context
+ private HttpServletRequest httpServletRequest;
+
+ protected AuditInformation getAuditInformation( )
+ {
+ RedbackRequestInformation redbackRequestInformation = RedbackAuthenticationThreadLocal.get( );
+ User user;
+ String remoteAddr;
+ if (redbackRequestInformation==null) {
+ user = null;
+ remoteAddr = httpServletRequest.getRemoteAddr( );
+ } else
+ {
+ user = redbackRequestInformation.getUser( );
+ remoteAddr = redbackRequestInformation.getRemoteAddr( );
+ }
+ return new AuditInformation( user, remoteAddr );
+ }
+}
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 5bec54dff..406acff59 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
@@ -20,13 +20,12 @@ package org.apache.archiva.rest.v2.svc.maven;
import org.apache.archiva.admin.model.AuditInformation;
import org.apache.archiva.admin.model.RepositoryAdminException;
import org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin;
+import org.apache.archiva.common.MultiModelMapper;
import org.apache.archiva.components.rest.model.PagedResult;
import org.apache.archiva.components.rest.util.QueryHelper;
import org.apache.archiva.configuration.model.ManagedRepositoryConfiguration;
import org.apache.archiva.redback.authentication.AuthenticationResult;
import org.apache.archiva.redback.authorization.AuthorizationException;
-import org.apache.archiva.redback.rest.services.RedbackAuthenticationThreadLocal;
-import org.apache.archiva.redback.rest.services.RedbackRequestInformation;
import org.apache.archiva.redback.system.DefaultSecuritySession;
import org.apache.archiva.redback.system.SecuritySession;
import org.apache.archiva.redback.system.SecuritySystem;
@@ -36,6 +35,7 @@ import org.apache.archiva.redback.users.UserNotFoundException;
import org.apache.archiva.repository.ManagedRepository;
import org.apache.archiva.repository.ReleaseScheme;
import org.apache.archiva.repository.Repository;
+import org.apache.archiva.repository.RepositoryException;
import org.apache.archiva.repository.RepositoryRegistry;
import org.apache.archiva.repository.RepositoryType;
import org.apache.archiva.repository.content.ContentItem;
@@ -44,10 +44,12 @@ import org.apache.archiva.repository.storage.fs.FsStorageUtil;
import org.apache.archiva.rest.api.v2.model.FileInfo;
import org.apache.archiva.rest.api.v2.model.MavenManagedRepository;
import org.apache.archiva.rest.api.v2.model.MavenManagedRepositoryUpdate;
+import org.apache.archiva.rest.api.v2.model.map.ServiceMapperFactory;
import org.apache.archiva.rest.api.v2.svc.ArchivaRestServiceException;
import org.apache.archiva.rest.api.v2.svc.ErrorKeys;
import org.apache.archiva.rest.api.v2.svc.ErrorMessage;
import org.apache.archiva.rest.api.v2.svc.maven.MavenManagedRepositoryService;
+import org.apache.archiva.rest.v2.svc.AbstractService;
import org.apache.archiva.security.common.ArchivaRoleConstants;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
@@ -65,14 +67,14 @@ import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Collectors;
-import static org.apache.archiva.security.common.ArchivaRoleConstants.OPERATION_READ_REPOSITORY;
import static org.apache.archiva.security.common.ArchivaRoleConstants.OPERATION_ADD_ARTIFACT;
+import static org.apache.archiva.security.common.ArchivaRoleConstants.OPERATION_READ_REPOSITORY;
/**
* @author Martin Stockhammer <martin_s@apache.org>
*/
@Service("v2.managedMavenRepositoryService#rest")
-public class DefaultMavenManagedRepositoryService implements MavenManagedRepositoryService
+public class DefaultMavenManagedRepositoryService extends AbstractService implements MavenManagedRepositoryService
{
@Context
HttpServletResponse httpServletResponse;
@@ -80,6 +82,8 @@ public class DefaultMavenManagedRepositoryService implements MavenManagedReposit
@Context
UriInfo uriInfo;
+
+
private static final Logger log = LoggerFactory.getLogger( DefaultMavenManagedRepositoryService.class );
private static final QueryHelper<ManagedRepository> QUERY_HELPER = new QueryHelper<>( new String[]{"id", "name"} );
static
@@ -96,36 +100,20 @@ public class DefaultMavenManagedRepositoryService implements MavenManagedReposit
private final ManagedRepositoryAdmin managedRepositoryAdmin;
private final RepositoryRegistry repositoryRegistry;
private final SecuritySystem securitySystem;
+ private final ServiceMapperFactory serviceMapperFactory;
+ private final MultiModelMapper<MavenManagedRepository, ManagedRepositoryConfiguration, ManagedRepository> mapper;
+
public DefaultMavenManagedRepositoryService( SecuritySystem securitySystem,
RepositoryRegistry repositoryRegistry,
- ManagedRepositoryAdmin managedRepositoryAdmin )
+ ManagedRepositoryAdmin managedRepositoryAdmin,
+ ServiceMapperFactory serviceMapperFactory ) throws IllegalArgumentException
{
this.securitySystem = securitySystem;
this.repositoryRegistry = repositoryRegistry;
this.managedRepositoryAdmin = managedRepositoryAdmin;
- }
-
- protected AuditInformation getAuditInformation( )
- {
- RedbackRequestInformation redbackRequestInformation = RedbackAuthenticationThreadLocal.get( );
- User user;
- String remoteAddr;
- if (redbackRequestInformation==null) {
- user = null;
- remoteAddr = null;
- } else
- {
- user = redbackRequestInformation.getUser( );
- remoteAddr = redbackRequestInformation.getRemoteAddr( );
- }
- return new AuditInformation( user, remoteAddr );
- }
-
- public static ManagedRepositoryConfiguration toConfig(MavenManagedRepository repo) {
- ManagedRepositoryConfiguration cfg = new ManagedRepositoryConfiguration( );
- return cfg;
-
+ this.serviceMapperFactory = serviceMapperFactory;
+ this.mapper = serviceMapperFactory.getMapper( MavenManagedRepository.class, ManagedRepositoryConfiguration.class, ManagedRepository.class );
}
@Override
@@ -140,7 +128,7 @@ public class DefaultMavenManagedRepositoryService implements MavenManagedReposit
final Comparator<ManagedRepository> comparator = QUERY_HELPER.getComparator( orderBy, order );
int totalCount = Math.toIntExact( repos.stream( ).filter( queryFilter ).count( ) );
return PagedResult.of( totalCount, offset, limit, repos.stream( ).filter( queryFilter ).sorted( comparator )
- .map( MavenManagedRepository::of ).skip( offset ).limit( limit ).collect( Collectors.toList( ) ) );
+ .map( mapper::reverseMap ).skip( offset ).limit( limit ).collect( Collectors.toList( ) ) );
}
catch (ArithmeticException e) {
log.error( "Invalid number of repositories detected." );
@@ -158,7 +146,7 @@ public class DefaultMavenManagedRepositoryService implements MavenManagedReposit
if (repo.getType()!=RepositoryType.MAVEN) {
throw new ArchivaRestServiceException( ErrorMessage.of( ErrorKeys.REPOSITORY_WRONG_TYPE, repositoryId, repo.getType().name() ), 404 );
}
- return MavenManagedRepository.of( repo );
+ return mapper.reverseMap( repo );
}
@Override
@@ -220,13 +208,14 @@ public class DefaultMavenManagedRepositoryService implements MavenManagedReposit
}
try
{
- managedRepositoryAdmin.addManagedRepository( convert( managedRepository ), managedRepository.hasStagingRepository(), getAuditInformation() );
+ repositoryRegistry.putRepository( mapper.map( managedRepository ) );
httpServletResponse.setStatus( 201 );
- return MavenManagedRepository.of( repositoryRegistry.getManagedRepository( repoId ) );
+ return mapper.reverseMap( repositoryRegistry.getManagedRepository( repoId ) );
}
- catch ( RepositoryAdminException e )
+ catch ( RepositoryException e )
{
- throw new ArchivaRestServiceException( ErrorMessage.of( ErrorKeys.REPOSITORY_ADMIN_ERROR, e.getMessage( ) ) );
+ log.error( "Could not create repository: {}", e.getMessage( ), e );
+ throw new ArchivaRestServiceException( ErrorMessage.of( ErrorKeys.REPOSITORY_ADD_FAILED, repoId ) );
}
}
@@ -241,7 +230,7 @@ public class DefaultMavenManagedRepositoryService implements MavenManagedReposit
if (newRepo==null) {
throw new ArchivaRestServiceException( ErrorMessage.of( ErrorKeys.REPOSITORY_UPDATE_FAILED, repositoryId ) );
}
- return MavenManagedRepository.of( newRepo );
+ return mapper.reverseMap( newRepo );
}
catch ( RepositoryAdminException e )
{
diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/v2/svc/maven/NativeMavenManagedRepositoryServiceTest.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/v2/svc/maven/NativeMavenManagedRepositoryServiceTest.java
index 3dffabed1..d012d6175 100644
--- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/v2/svc/maven/NativeMavenManagedRepositoryServiceTest.java
+++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/v2/svc/maven/NativeMavenManagedRepositoryServiceTest.java
@@ -100,7 +100,6 @@ public class NativeMavenManagedRepositoryServiceTest extends AbstractNativeRestS
}
- @Disabled
@Test
@Order( 2 )
void testCreateRepository() {
@@ -111,7 +110,7 @@ public class NativeMavenManagedRepositoryServiceTest extends AbstractNativeRestS
assertNotNull( json );
assertEquals( "repo001", json.get( "id" ) );
assertEquals( "Repository 001", json.get( "name" ) );
- assertEquals( "maven", json.get( "type" ) );
+ assertEquals( "MAVEN", json.get( "type" ) );
assertEquals( "This is repository 001", json.get( "description" ) );
}