diff options
author | Martin Stockhammer <martin_s@apache.org> | 2020-06-30 13:24:49 +0200 |
---|---|---|
committer | Martin Stockhammer <martin_s@apache.org> | 2020-06-30 13:24:49 +0200 |
commit | bef02ef5b8d1f47f6cded2257ac49ae770e4f0fb (patch) | |
tree | 672aa61e2d5c1c8d64e19de558701b9d074b5b0f /archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src | |
parent | b9316745df508c88c3c691bb4a509265a523dfde (diff) | |
download | archiva-bef02ef5b8d1f47f6cded2257ac49ae770e4f0fb.tar.gz archiva-bef02ef5b8d1f47f6cded2257ac49ae770e4f0fb.zip |
Migrating return values of rest services away from simple types
Diffstat (limited to 'archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src')
5 files changed, 42 insertions, 25 deletions
diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultCommonServices.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultCommonServices.java index 25ee182f7..b57e66ce2 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultCommonServices.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultCommonServices.java @@ -40,6 +40,7 @@ import java.io.InputStream; import java.util.Map; import java.util.Properties; import java.util.concurrent.ConcurrentHashMap; +import java.util.stream.Collectors; /** * @author Olivier Lamy @@ -56,7 +57,7 @@ public class DefaultCommonServices @Inject private UtilServices utilServices; - private Map<String, String> cachei18n = new ConcurrentHashMap<String, String>(); + private Map<String, Map<String,String>> cachei18n = new ConcurrentHashMap<String, Map<String,String>>(); @Inject protected CronExpressionValidator cronExpressionValidator; @@ -72,7 +73,7 @@ public class DefaultCommonServices } @Override - public String getI18nResources( String locale ) + public Map<String,String> getI18nResources( String locale ) throws ArchivaRestServiceException { Properties properties = new Properties(); @@ -89,7 +90,14 @@ public class DefaultCommonServices log.warn( "skip error loading properties {}", resourceName ); } - return fromProperties( properties ); + return properties.entrySet().stream().collect( + Collectors.toMap( + e -> e.getKey().toString(), + e -> e.getValue().toString() + ) + ); + + } private void loadResource( Properties properties, StringBuilder resourceName, String locale ) @@ -142,11 +150,11 @@ public class DefaultCommonServices } @Override - public String getAllI18nResources( String locale ) + public Map<String,String> getAllI18nResources( String locale ) throws ArchivaRestServiceException { - String cachedi18n = cachei18n.get( StringUtils.isEmpty( locale ) ? "en" : StringUtils.lowerCase( locale ) ); + Map<String,String> cachedi18n = cachei18n.get( StringUtils.isEmpty( locale ) ? "en" : StringUtils.lowerCase( locale ) ); if ( cachedi18n != null ) { return cachedi18n; @@ -158,10 +166,14 @@ public class DefaultCommonServices Properties all = utilServices.getI18nProperties( locale ); StringBuilder resourceName = new StringBuilder( RESOURCE_NAME ); loadResource( all, resourceName, locale ); - - String i18n = fromProperties( all ); - cachei18n.put( StringUtils.isEmpty( locale ) ? "en" : StringUtils.lowerCase( locale ), i18n ); - return i18n; + Map<String, String> allMap = all.entrySet().stream().collect( + Collectors.toMap( + e -> e.getKey().toString(), + e -> e.getValue().toString() + ) + ); + cachei18n.put( StringUtils.isEmpty( locale ) ? "en" : StringUtils.lowerCase( locale ), allMap ); + return allMap; } catch ( IOException e ) { diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultManagedRepositoriesService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultManagedRepositoriesService.java index 6aec318da..ea84684f2 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultManagedRepositoriesService.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultManagedRepositoriesService.java @@ -30,6 +30,7 @@ import org.apache.archiva.metadata.repository.stats.model.RepositoryStatisticsMa import org.apache.archiva.rest.api.model.ActionStatus; import org.apache.archiva.rest.api.model.ArchivaRepositoryStatistics; import org.apache.archiva.rest.api.model.FileStatus; +import org.apache.archiva.rest.api.model.PomSnippet; import org.apache.archiva.rest.api.services.ArchivaRestServiceException; import org.apache.archiva.rest.api.services.ManagedRepositoriesService; import org.apache.commons.lang3.StringEscapeUtils; @@ -211,10 +212,10 @@ public class DefaultManagedRepositoriesService } @Override - public String getPomSnippet( String repositoryId ) + public PomSnippet getPomSnippet( String repositoryId ) throws ArchivaRestServiceException { - return createSnippet( getManagedRepository( repositoryId ) ); + return new PomSnippet( createSnippet( getManagedRepository( repositoryId ) ) ); } private String createSnippet( ManagedRepository repo ) diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultPingService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultPingService.java index 1d89c7e43..86032472e 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultPingService.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultPingService.java @@ -19,6 +19,7 @@ package org.apache.archiva.rest.services; * under the License. */ +import org.apache.archiva.rest.api.model.PingResult; import org.apache.archiva.rest.api.services.PingService; import org.springframework.stereotype.Service; @@ -31,13 +32,13 @@ public class DefaultPingService implements PingService { @Override - public String ping() + public PingResult ping() { - return "Yeah Baby It rocks!"; + return new PingResult( "Yeah Baby It rocks!" ); } @Override - public String pingWithAuthz() + public PingResult pingWithAuthz() { return ping(); } diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultSystemStatusService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultSystemStatusService.java index 775664662..2b1c8ab05 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultSystemStatusService.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultSystemStatusService.java @@ -29,8 +29,10 @@ import org.apache.archiva.repository.scanner.RepositoryScannerInstance; import org.apache.archiva.rest.api.model.ActionStatus; import org.apache.archiva.rest.api.model.CacheEntry; import org.apache.archiva.rest.api.model.ConsumerScanningStatistics; +import org.apache.archiva.rest.api.model.MemoryStatus; import org.apache.archiva.rest.api.model.QueueEntry; import org.apache.archiva.rest.api.model.RepositoryScannerStatistics; +import org.apache.archiva.rest.api.model.Timestamp; import org.apache.archiva.rest.api.services.ArchivaRestServiceException; import org.apache.archiva.rest.api.services.SystemStatusService; import org.apache.archiva.rest.services.utils.ConsumerScanningStatisticsComparator; @@ -86,7 +88,7 @@ public class DefaultSystemStatusService } @Override - public String getMemoryStatus() + public MemoryStatus getMemoryStatus() throws ArchivaRestServiceException { Runtime runtime = Runtime.getRuntime(); @@ -94,7 +96,7 @@ public class DefaultSystemStatusService long total = runtime.totalMemory(); long used = total - runtime.freeMemory(); long max = runtime.maxMemory(); - return formatMemory( used ) + "/" + formatMemory( total ) + " (Max: " + formatMemory( max ) + ")"; + return new MemoryStatus( formatMemory( used ) + "/" + formatMemory( total ) + " (Max: " + formatMemory( max ) + ")" ); } private static String formatMemory( long l ) @@ -103,11 +105,11 @@ public class DefaultSystemStatusService } @Override - public String getCurrentServerTime( String locale ) + public Timestamp getCurrentServerTime( String locale ) throws ArchivaRestServiceException { SimpleDateFormat sdf = new SimpleDateFormat( "EEE, d MMM yyyy HH:mm:ss Z", new Locale( locale ) ); - return sdf.format( new Date() ); + return new Timestamp( sdf.format( new Date( ) ) ); } @Override diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/PingServiceTest.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/PingServiceTest.java index 7fb242e95..6fff4d3d3 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/PingServiceTest.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/PingServiceTest.java @@ -19,6 +19,7 @@ package org.apache.archiva.rest.services; * under the License. */ +import org.apache.archiva.rest.api.model.PingResult; import org.apache.archiva.rest.api.services.PingService; import org.apache.cxf.jaxrs.client.WebClient; import org.junit.Ignore; @@ -42,8 +43,8 @@ public class PingServiceTest // 1000000L //WebClient.getConfig( userService ).getHttpConduit().getClient().setReceiveTimeout(3000); - String res = getPingService().ping(); - assertEquals( "Yeah Baby It rocks!", res ); + PingResult res = getPingService().ping(); + assertEquals( "Yeah Baby It rocks!", res.getOutput() ); } @Test( expected = ForbiddenException.class ) @@ -53,7 +54,7 @@ public class PingServiceTest try { - String res = getPingService().pingWithAuthz(); + PingResult res = getPingService().pingWithAuthz(); fail( "not in exception" ); } catch ( ForbiddenException e ) @@ -71,8 +72,8 @@ public class PingServiceTest PingService service = getPingService(); WebClient.getConfig( service ).getHttpConduit().getClient().setReceiveTimeout( 300000 ); WebClient.client( service ).header( "Authorization", authorizationHeader ); - String res = service.pingWithAuthz(); - assertEquals( "Yeah Baby It rocks!", res ); + PingResult res = service.pingWithAuthz(); + assertEquals( "Yeah Baby It rocks!", res.getOutput() ); } @Ignore( "FIXME guest failed ???" ) @@ -83,7 +84,7 @@ public class PingServiceTest PingService service = getPingService(); WebClient.getConfig( service ).getHttpConduit().getClient().setReceiveTimeout( 300000 ); WebClient.client( service ).header( "Authorization", guestAuthzHeader ); - String res = service.pingWithAuthz(); - assertEquals( "Yeah Baby It rocks!", res ); + PingResult res = service.pingWithAuthz(); + assertEquals( "Yeah Baby It rocks!", res.getOutput() ); } } |