Skip to content

Commit

Permalink
fetching lengths of packages during import of hpkr should hit interna…
Browse files Browse the repository at this point in the history
…l facing urls
  • Loading branch information
andponlin committed Feb 4, 2020
1 parent 1b147a9 commit afff53c
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2018-2019, Andrew Lindesay
* Copyright 2018-2020, Andrew Lindesay
* Distributed under the terms of the MIT License.
*/

Expand All @@ -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;
Expand Down Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2018, Andrew Lindesay
* Copyright 2013-2020, Andrew Lindesay
* Distributed under the terms of the MIT License.
*/

Expand All @@ -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;
Expand Down Expand Up @@ -133,7 +134,7 @@ public void validateForInsert(ValidationResult validationResult) {
}

if (null == getViewCounter()) {
setViewCounter(0l);
setViewCounter(0L);
}

if (null == getIsLatest()) {
Expand Down Expand Up @@ -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());
}

Expand Down Expand Up @@ -282,8 +283,8 @@ public Optional<Integer> getDerivedAggregatedUserRatingSampleSize() {
* <p>This method will provide a URL to the actual data of the package.</p>
*/

public Optional<URL> tryGetHpkgURL() {
return getRepositorySource().tryGetExternalFacingPackagesBaseURL()
public Optional<URL> tryGetHpkgURL(ExposureType exposureType) {
return getRepositorySource().tryGetPackagesBaseURL(exposureType)
.map(u -> {
try {
return new URL(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015-2018, Andrew Lindesay
* Copyright 2015-2020, Andrew Lindesay
* Distributed under the terms of the MIT License.
*/

Expand Down Expand Up @@ -116,8 +116,8 @@ private void validateUrl(ValidationResult validationResult, String url, String p
* <p>This is the URL at which one might find the packages for this repository.</p>
*/

public Optional<URL> tryGetExternalFacingPackagesBaseURL() {
return tryGetBaseURL(ExposureType.EXTERNAL_FACING)
public Optional<URL> tryGetPackagesBaseURL(ExposureType exposureType) {
return tryGetBaseURL(exposureType)
.map(bu -> {
try {
return UriComponentsBuilder.fromUriString(bu.toString())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2018-2019, Andrew Lindesay
* Copyright 2018-2020, Andrew Lindesay
* Distributed under the terms of the MIT License.
*/

Expand All @@ -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;
Expand Down Expand Up @@ -252,7 +253,7 @@ private void importCopyrights(ObjectContext objectContext, org.haiku.pkg.model.P

private void populatePayloadLength(PkgVersion persistedPkgVersion) {
long length = -1;
Optional<URL> pkgVersionHpkgURLOptional = persistedPkgVersion.tryGetHpkgURL();
Optional<URL> pkgVersionHpkgURLOptional = persistedPkgVersion.tryGetHpkgURL(ExposureType.INTERNAL_FACING);

if (pkgVersionHpkgURLOptional.isPresent()) {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2018-2019, Andrew Lindesay
* Copyright 2018-2020, Andrew Lindesay
* Distributed under the terms of the MIT License.
*/

Expand All @@ -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;
Expand Down Expand Up @@ -163,7 +160,7 @@ public Optional<PkgVersion> adjustLatest(

for (PkgVersion pkgVersion : pkgVersions) {
if (pkgVersion.getIsLatest() &&
(!pkgVersionOptional.isPresent() ||
(pkgVersionOptional.isEmpty() ||
!pkgVersion.equals(pkgVersionOptional.get())
)
) {
Expand Down Expand Up @@ -540,7 +537,7 @@ public Optional<String> 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(() -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2018, Andrew Lindesay
* Copyright 2018-2020, Andrew Lindesay
* Distributed under the terms of the MIT License.
*/

Expand All @@ -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;
Expand Down Expand Up @@ -68,7 +69,7 @@ public void run(

for(int i=0;i<pkgVersions.size();i++) {
PkgVersion pkgVersion = pkgVersions.get(i);
Optional<URL> urlOptional = pkgVersion.tryGetHpkgURL();
Optional<URL> urlOptional = pkgVersion.tryGetHpkgURL(ExposureType.INTERNAL_FACING);

if (urlOptional.isPresent()) {
long len;
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2018-2019, Andrew Lindesay
* Copyright 2018-2020, Andrew Lindesay
* Distributed under the terms of the MIT License.
*/

Expand All @@ -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;
Expand Down Expand Up @@ -122,9 +123,9 @@ public void download(
return new RequestObjectNotFound();
});

Optional<URL> urlOptional = pkgVersion.tryGetHpkgURL();
Optional<URL> 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 {
Expand Down Expand Up @@ -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 {}

}

0 comments on commit afff53c

Please sign in to comment.