diff --git a/haikudepotserver-core-test/src/test/java/org/haiku/haikudepotserver/pkg/PkgImportServiceImplIT.java b/haikudepotserver-core-test/src/test/java/org/haiku/haikudepotserver/pkg/PkgImportServiceImplIT.java index 799498e0..97b28158 100644 --- a/haikudepotserver-core-test/src/test/java/org/haiku/haikudepotserver/pkg/PkgImportServiceImplIT.java +++ b/haikudepotserver-core-test/src/test/java/org/haiku/haikudepotserver/pkg/PkgImportServiceImplIT.java @@ -1,5 +1,5 @@ /* - * Copyright 2018-2019, Andrew Lindesay + * Copyright 2018-2020, Andrew Lindesay * Distributed under the terms of the MIT License. */ @@ -18,6 +18,7 @@ import org.haiku.haikudepotserver.pkg.model.PkgImportService; import org.haiku.haikudepotserver.pkg.model.PkgLocalizationService; import org.haiku.haikudepotserver.pkg.model.PkgService; +import org.haiku.haikudepotserver.support.ExposureType; import org.haiku.haikudepotserver.support.FileHelper; import org.haiku.pkg.model.Pkg; import org.haiku.pkg.model.PkgArchitecture; @@ -186,7 +187,7 @@ public void testImport_payloadLength() throws Exception { { ObjectContext context = serverRuntime.newContext(); RepositorySource repositorySource = RepositorySource.tryGetByCode(context, "testreposrc_xyz").get(); - repositoryDirectory = new File(repositorySource.tryGetExternalFacingPackagesBaseURL().get().getPath()); + repositoryDirectory = new File(repositorySource.tryGetPackagesBaseURL(ExposureType.INTERNAL_FACING).get().getPath()); if (!repositoryDirectory.mkdirs()) { throw new IllegalStateException("unable to create the on-disk repository"); diff --git a/haikudepotserver-core/src/main/java/org/haiku/haikudepotserver/dataobjects/PkgVersion.java b/haikudepotserver-core/src/main/java/org/haiku/haikudepotserver/dataobjects/PkgVersion.java index 3c090a66..eaacdb34 100644 --- a/haikudepotserver-core/src/main/java/org/haiku/haikudepotserver/dataobjects/PkgVersion.java +++ b/haikudepotserver-core/src/main/java/org/haiku/haikudepotserver/dataobjects/PkgVersion.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2018, Andrew Lindesay + * Copyright 2013-2020, Andrew Lindesay * Distributed under the terms of the MIT License. */ @@ -18,6 +18,7 @@ import org.apache.commons.lang3.builder.ToStringStyle; import org.haiku.haikudepotserver.dataobjects.auto._PkgVersion; import org.haiku.haikudepotserver.dataobjects.support.MutableCreateAndModifyTimestamped; +import org.haiku.haikudepotserver.support.ExposureType; import org.haiku.haikudepotserver.support.SingleCollector; import org.haiku.haikudepotserver.support.VersionCoordinates; import org.haiku.haikudepotserver.support.VersionCoordinatesComparator; @@ -133,7 +134,7 @@ public void validateForInsert(ValidationResult validationResult) { } if (null == getViewCounter()) { - setViewCounter(0l); + setViewCounter(0L); } if (null == getIsLatest()) { @@ -222,11 +223,11 @@ public PkgVersionLocalization getPkgVersionLocalizationOrFallbackByCode(final St pkgVersionLocalizationOptional = getPkgVersionLocalization(naturalLanguageCode); } - if (!pkgVersionLocalizationOptional.isPresent()) { + if (pkgVersionLocalizationOptional.isEmpty()) { pkgVersionLocalizationOptional = getPkgVersionLocalization(NaturalLanguage.CODE_ENGLISH); } - if (!pkgVersionLocalizationOptional.isPresent()) { + if (pkgVersionLocalizationOptional.isEmpty()) { throw new IllegalStateException("unable to find the fallback localization for " + toString()); } @@ -282,8 +283,8 @@ public Optional getDerivedAggregatedUserRatingSampleSize() { *

This method will provide a URL to the actual data of the package.

*/ - public Optional tryGetHpkgURL() { - return getRepositorySource().tryGetExternalFacingPackagesBaseURL() + public Optional tryGetHpkgURL(ExposureType exposureType) { + return getRepositorySource().tryGetPackagesBaseURL(exposureType) .map(u -> { try { return new URL( diff --git a/haikudepotserver-core/src/main/java/org/haiku/haikudepotserver/dataobjects/RepositorySource.java b/haikudepotserver-core/src/main/java/org/haiku/haikudepotserver/dataobjects/RepositorySource.java index 1c6462b3..26a270ba 100644 --- a/haikudepotserver-core/src/main/java/org/haiku/haikudepotserver/dataobjects/RepositorySource.java +++ b/haikudepotserver-core/src/main/java/org/haiku/haikudepotserver/dataobjects/RepositorySource.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2018, Andrew Lindesay + * Copyright 2015-2020, Andrew Lindesay * Distributed under the terms of the MIT License. */ @@ -116,8 +116,8 @@ private void validateUrl(ValidationResult validationResult, String url, String p *

This is the URL at which one might find the packages for this repository.

*/ - public Optional tryGetExternalFacingPackagesBaseURL() { - return tryGetBaseURL(ExposureType.EXTERNAL_FACING) + public Optional tryGetPackagesBaseURL(ExposureType exposureType) { + return tryGetBaseURL(exposureType) .map(bu -> { try { return UriComponentsBuilder.fromUriString(bu.toString()) diff --git a/haikudepotserver-core/src/main/java/org/haiku/haikudepotserver/pkg/PkgImportServiceImpl.java b/haikudepotserver-core/src/main/java/org/haiku/haikudepotserver/pkg/PkgImportServiceImpl.java index 68dc3088..548e1b8b 100644 --- a/haikudepotserver-core/src/main/java/org/haiku/haikudepotserver/pkg/PkgImportServiceImpl.java +++ b/haikudepotserver-core/src/main/java/org/haiku/haikudepotserver/pkg/PkgImportServiceImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2018-2019, Andrew Lindesay + * Copyright 2018-2020, Andrew Lindesay * Distributed under the terms of the MIT License. */ @@ -14,6 +14,7 @@ import org.haiku.haikudepotserver.dataobjects.*; import org.haiku.haikudepotserver.pkg.model.PkgImportService; import org.haiku.haikudepotserver.pkg.model.PkgLocalizationService; +import org.haiku.haikudepotserver.support.ExposureType; import org.haiku.haikudepotserver.support.URLHelper; import org.haiku.haikudepotserver.support.VersionCoordinates; import org.haiku.haikudepotserver.support.VersionCoordinatesComparator; @@ -252,7 +253,7 @@ private void importCopyrights(ObjectContext objectContext, org.haiku.pkg.model.P private void populatePayloadLength(PkgVersion persistedPkgVersion) { long length = -1; - Optional pkgVersionHpkgURLOptional = persistedPkgVersion.tryGetHpkgURL(); + Optional pkgVersionHpkgURLOptional = persistedPkgVersion.tryGetHpkgURL(ExposureType.INTERNAL_FACING); if (pkgVersionHpkgURLOptional.isPresent()) { diff --git a/haikudepotserver-core/src/main/java/org/haiku/haikudepotserver/pkg/PkgServiceImpl.java b/haikudepotserver-core/src/main/java/org/haiku/haikudepotserver/pkg/PkgServiceImpl.java index 23b57714..e2748974 100644 --- a/haikudepotserver-core/src/main/java/org/haiku/haikudepotserver/pkg/PkgServiceImpl.java +++ b/haikudepotserver-core/src/main/java/org/haiku/haikudepotserver/pkg/PkgServiceImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2018-2019, Andrew Lindesay + * Copyright 2018-2020, Andrew Lindesay * Distributed under the terms of the MIT License. */ @@ -22,10 +22,7 @@ import org.haiku.haikudepotserver.dataobjects.*; import org.haiku.haikudepotserver.pkg.model.PkgSearchSpecification; import org.haiku.haikudepotserver.pkg.model.PkgService; -import org.haiku.haikudepotserver.support.DateTimeHelper; -import org.haiku.haikudepotserver.support.SingleCollector; -import org.haiku.haikudepotserver.support.StoppableConsumer; -import org.haiku.haikudepotserver.support.VersionCoordinatesComparator; +import org.haiku.haikudepotserver.support.*; import org.haiku.haikudepotserver.support.cayenne.ExpressionHelper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -163,7 +160,7 @@ public Optional adjustLatest( for (PkgVersion pkgVersion : pkgVersions) { if (pkgVersion.getIsLatest() && - (!pkgVersionOptional.isPresent() || + (pkgVersionOptional.isEmpty() || !pkgVersion.equals(pkgVersionOptional.get()) ) ) { @@ -540,7 +537,7 @@ public Optional tryGetMainPkgNameForSubordinatePkg( @Override public String createHpkgDownloadUrl(PkgVersion pkgVersion) { - return pkgVersion.tryGetHpkgURL() + return pkgVersion.tryGetHpkgURL(ExposureType.EXTERNAL_FACING) .filter(u -> ImmutableSet.of("http", "https").contains(u.getProtocol())) .map(URL::toString) .orElseGet(() -> { diff --git a/haikudepotserver-core/src/main/java/org/haiku/haikudepotserver/pkg/job/PkgVersionPayloadLengthPopulationJobRunner.java b/haikudepotserver-core/src/main/java/org/haiku/haikudepotserver/pkg/job/PkgVersionPayloadLengthPopulationJobRunner.java index e3c638b5..3c0a16f5 100644 --- a/haikudepotserver-core/src/main/java/org/haiku/haikudepotserver/pkg/job/PkgVersionPayloadLengthPopulationJobRunner.java +++ b/haikudepotserver-core/src/main/java/org/haiku/haikudepotserver/pkg/job/PkgVersionPayloadLengthPopulationJobRunner.java @@ -1,5 +1,5 @@ /* - * Copyright 2018, Andrew Lindesay + * Copyright 2018-2020, Andrew Lindesay * Distributed under the terms of the MIT License. */ @@ -14,6 +14,7 @@ import org.haiku.haikudepotserver.job.AbstractJobRunner; import org.haiku.haikudepotserver.job.model.JobService; import org.haiku.haikudepotserver.pkg.model.PkgVersionPayloadLengthPopulationJobSpecification; +import org.haiku.haikudepotserver.support.ExposureType; import org.haiku.haikudepotserver.support.URLHelper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -68,7 +69,7 @@ public void run( for(int i=0;i urlOptional = pkgVersion.tryGetHpkgURL(); + Optional urlOptional = pkgVersion.tryGetHpkgURL(ExposureType.INTERNAL_FACING); if (urlOptional.isPresent()) { long len; @@ -86,7 +87,7 @@ public void run( } } else { LOGGER.info("unable to get the length of [{}] because no url" + - "hpkg url was able to be obtained"); + "hpkg url was able to be obtained", pkgVersion); } jobService.setJobProgressPercent( diff --git a/haikudepotserver-webapp/src/main/java/org/haiku/haikudepotserver/pkg/controller/PkgDownloadController.java b/haikudepotserver-webapp/src/main/java/org/haiku/haikudepotserver/pkg/controller/PkgDownloadController.java index ab4eab0e..0c7bfa73 100644 --- a/haikudepotserver-webapp/src/main/java/org/haiku/haikudepotserver/pkg/controller/PkgDownloadController.java +++ b/haikudepotserver-webapp/src/main/java/org/haiku/haikudepotserver/pkg/controller/PkgDownloadController.java @@ -1,5 +1,5 @@ /* - * Copyright 2018-2019, Andrew Lindesay + * Copyright 2018-2020, Andrew Lindesay * Distributed under the terms of the MIT License. */ @@ -17,6 +17,7 @@ import org.haiku.haikudepotserver.dataobjects.PkgVersion; import org.haiku.haikudepotserver.dataobjects.Repository; import org.haiku.haikudepotserver.pkg.PkgServiceImpl; +import org.haiku.haikudepotserver.support.ExposureType; import org.haiku.haikudepotserver.support.VersionCoordinates; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -122,9 +123,9 @@ public void download( return new RequestObjectNotFound(); }); - Optional urlOptional = pkgVersion.tryGetHpkgURL(); + Optional urlOptional = pkgVersion.tryGetHpkgURL(ExposureType.EXTERNAL_FACING); - if (!urlOptional.isPresent()) { + if (urlOptional.isEmpty()) { LOGGER.info("unable to allow download of the hpkg data as no url was able to be generated"); response.setStatus(HttpServletResponse.SC_NOT_FOUND); } else { @@ -163,6 +164,6 @@ public void download( } @ResponseStatus(value= HttpStatus.NOT_FOUND, reason="the requested package was unable to found") - private class RequestObjectNotFound extends RuntimeException {} + private static class RequestObjectNotFound extends RuntimeException {} }