Search in sources :

Example 6 with VersionCoordinates

use of org.haiku.haikudepotserver.support.VersionCoordinates in project haikudepotserver by haiku.

the class PkgImportServiceImpl method importFrom.

@Override
public void importFrom(ObjectContext objectContext, ObjectId repositorySourceObjectId, org.haiku.pkg.model.Pkg pkg, boolean populateFromPayload) {
    Preconditions.checkArgument(null != pkg, "the package must be provided");
    Preconditions.checkArgument(null != repositorySourceObjectId, "the repository source is must be provided");
    RepositorySource repositorySource = RepositorySource.get(objectContext, repositorySourceObjectId);
    if (!repositorySource.getActive()) {
        throw new IllegalStateException("it is not possible to import from a repository source that is not active; " + repositorySource);
    }
    if (!repositorySource.getRepository().getActive()) {
        throw new IllegalStateException("it is not possible to import from a repository that is not active; " + repositorySource.getRepository());
    }
    // first, check to see if the package is there or not.
    Optional<Pkg> persistedPkgOptional = Pkg.tryGetByName(objectContext, pkg.getName());
    Pkg persistedPkg;
    Optional<PkgVersion> persistedLatestExistingPkgVersion = Optional.empty();
    Architecture architecture = Architecture.tryGetByCode(objectContext, pkg.getArchitecture().name().toLowerCase()).orElseThrow(IllegalStateException::new);
    PkgVersion persistedPkgVersion = null;
    if (persistedPkgOptional.isEmpty()) {
        persistedPkg = createPkg(objectContext, pkg.getName());
        pkgServiceImpl.ensurePkgProminence(objectContext, persistedPkg, repositorySource.getRepository());
        LOGGER.info("the package [{}] did not exist; will create", pkg.getName());
    } else {
        persistedPkg = persistedPkgOptional.get();
        pkgServiceImpl.ensurePkgProminence(objectContext, persistedPkg, repositorySource.getRepository());
        // if we know that the package exists then we should look for the version.
        persistedPkgVersion = PkgVersion.getForPkg(objectContext, persistedPkg, repositorySource.getRepository(), architecture, new VersionCoordinates(pkg.getVersion())).orElse(null);
        persistedLatestExistingPkgVersion = pkgServiceImpl.getLatestPkgVersionForPkg(objectContext, persistedPkg, repositorySource.getRepository(), Collections.singletonList(architecture));
    }
    if (null == persistedPkgVersion) {
        persistedPkgVersion = objectContext.newObject(PkgVersion.class);
        persistedPkgVersion.setMajor(pkg.getVersion().getMajor());
        persistedPkgVersion.setMinor(pkg.getVersion().getMinor());
        persistedPkgVersion.setMicro(pkg.getVersion().getMicro());
        persistedPkgVersion.setPreRelease(pkg.getVersion().getPreRelease());
        persistedPkgVersion.setRevision(pkg.getVersion().getRevision());
        persistedPkgVersion.setRepositorySource(repositorySource);
        persistedPkgVersion.setArchitecture(architecture);
        persistedPkgVersion.setPkg(persistedPkg);
        LOGGER.info("the version [{}] of package [{}] did not exist; will create", pkg.getVersion().toString(), pkg.getName());
    } else {
        LOGGER.debug("the version [{}] of package [{}] did exist; will re-configure necessary data", pkg.getVersion().toString(), pkg.getName());
    }
    persistedPkgVersion.setActive(Boolean.TRUE);
    importCopyrights(objectContext, pkg, persistedPkgVersion);
    importLicenses(objectContext, pkg, persistedPkgVersion);
    importUrls(objectContext, pkg, persistedPkgVersion);
    if (!Strings.isNullOrEmpty(pkg.getSummary()) || !Strings.isNullOrEmpty(pkg.getDescription())) {
        pkgLocalizationService.updatePkgVersionLocalization(objectContext, persistedPkgVersion, NaturalLanguage.getEnglish(objectContext), // not supported quite yet
        null, pkg.getSummary(), pkg.getDescription());
    }
    // now possibly switch the latest flag over to the new one from the old one.
    possiblyReconfigurePersistedPkgVersionToBeLatest(objectContext, persistedLatestExistingPkgVersion.orElse(null), persistedPkgVersion);
    if (populateFromPayload && shouldPopulateFromPayload(persistedPkgVersion)) {
        populateFromPayload(objectContext, persistedPkgVersion);
    }
    LOGGER.debug("have processed package {}", pkg);
}
Also used : Architecture(org.haiku.haikudepotserver.dataobjects.Architecture) VersionCoordinates(org.haiku.haikudepotserver.support.VersionCoordinates) RepositorySource(org.haiku.haikudepotserver.dataobjects.RepositorySource) PkgVersion(org.haiku.haikudepotserver.dataobjects.PkgVersion) Pkg(org.haiku.haikudepotserver.dataobjects.Pkg)

Example 7 with VersionCoordinates

use of org.haiku.haikudepotserver.support.VersionCoordinates in project haikudepotserver by haiku.

the class UserRatingApiImpl method getUserRatingByUserAndPkgVersion.

@Override
public GetUserRatingByUserAndPkgVersionResult getUserRatingByUserAndPkgVersion(GetUserRatingByUserAndPkgVersionRequest request) {
    Preconditions.checkNotNull(request);
    Preconditions.checkState(!Strings.isNullOrEmpty(request.pkgName), "the package name must be supplied");
    Preconditions.checkState(!Strings.isNullOrEmpty(request.userNickname), "the user nickname must be supplied");
    Preconditions.checkState(!Strings.isNullOrEmpty(request.pkgVersionArchitectureCode), "the pkg version architecture code must be supplied");
    Preconditions.checkState(!Strings.isNullOrEmpty(request.pkgVersionMajor), "the package version major code must be supplied");
    Preconditions.checkArgument(!Strings.isNullOrEmpty(request.repositoryCode), "the repository code should be supplied");
    final ObjectContext context = serverRuntime.newContext();
    Architecture architecture = getArchitecture(context, request.pkgVersionArchitectureCode);
    User user = User.tryGetByNickname(context, request.userNickname).orElseThrow(() -> new ObjectNotFoundException(User.class.getSimpleName(), request.userNickname));
    Pkg pkg = Pkg.tryGetByName(context, request.pkgName).orElseThrow(() -> new ObjectNotFoundException(Pkg.class.getSimpleName(), request.pkgName));
    Repository repository = getRepository(context, request.repositoryCode);
    VersionCoordinates versionCoordinates = new VersionCoordinates(request.pkgVersionMajor, request.pkgVersionMinor, request.pkgVersionMicro, request.pkgVersionPreRelease, request.pkgVersionRevision);
    Optional<PkgVersion> pkgVersionOptional = PkgVersion.getForPkg(context, pkg, repository, architecture, versionCoordinates);
    if (pkgVersionOptional.isEmpty() || !pkgVersionOptional.get().getActive()) {
        throw new ObjectNotFoundException(PkgVersion.class.getSimpleName(), request.pkgName + "@" + versionCoordinates.toString());
    }
    Optional<UserRating> userRatingOptional = UserRating.getByUserAndPkgVersion(context, user, pkgVersionOptional.get());
    if (userRatingOptional.isEmpty()) {
        throw new ObjectNotFoundException(UserRating.class.getSimpleName(), "");
    }
    GetUserRatingByUserAndPkgVersionResult result = new GetUserRatingByUserAndPkgVersionResult();
    fillAbstractGetUserRatingResult(userRatingOptional.get(), result);
    return result;
}
Also used : VersionCoordinates(org.haiku.haikudepotserver.support.VersionCoordinates) ObjectNotFoundException(org.haiku.haikudepotserver.api1.support.ObjectNotFoundException) org.haiku.haikudepotserver.dataobjects.auto._PkgVersion(org.haiku.haikudepotserver.dataobjects.auto._PkgVersion) ObjectContext(org.apache.cayenne.ObjectContext)

Example 8 with VersionCoordinates

use of org.haiku.haikudepotserver.support.VersionCoordinates in project haikudepotserver by haiku.

the class PkgApiIT method testIncrementViewCounter.

@Test
public void testIncrementViewCounter() {
    integrationTestSupportService.createStandardTestData();
    IncrementViewCounterRequest request = new IncrementViewCounterRequest();
    request.major = "1";
    request.micro = "2";
    request.revision = 3;
    request.name = "pkg1";
    request.architectureCode = "x86_64";
    request.repositoryCode = "testrepo";
    // ------------------------------------
    IncrementViewCounterResult result = pkgApi.incrementViewCounter(request);
    // ------------------------------------
    Assertions.assertThat(result).isNotNull();
    {
        ObjectContext context = serverRuntime.newContext();
        Pkg pkg1 = Pkg.getByName(context, "pkg1");
        Repository repository = Repository.getByCode(context, "testrepo");
        Architecture architecture = Architecture.getByCode(context, "x86_64");
        PkgVersion pkgVersion = PkgVersion.getForPkg(context, pkg1, repository, architecture, new VersionCoordinates("1", null, "2", null, 3)).get();
        Assertions.assertThat(pkgVersion.getViewCounter()).isEqualTo(1L);
    }
}
Also used : IncrementViewCounterRequest(org.haiku.haikudepotserver.api1.model.pkg.IncrementViewCounterRequest) Repository(org.haiku.haikudepotserver.dataobjects.Repository) Architecture(org.haiku.haikudepotserver.dataobjects.Architecture) VersionCoordinates(org.haiku.haikudepotserver.support.VersionCoordinates) IncrementViewCounterResult(org.haiku.haikudepotserver.api1.model.pkg.IncrementViewCounterResult) PkgVersion(org.haiku.haikudepotserver.dataobjects.PkgVersion) ObjectContext(org.apache.cayenne.ObjectContext) Pkg(org.haiku.haikudepotserver.dataobjects.Pkg) AbstractIntegrationTest(org.haiku.haikudepotserver.AbstractIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 9 with VersionCoordinates

use of org.haiku.haikudepotserver.support.VersionCoordinates in project haikudepotserver by haiku.

the class PkgApiIT method updatePkgVersion_deactivate.

@Test
public void updatePkgVersion_deactivate() {
    integrationTestSupportService.createStandardTestData();
    setAuthenticatedUserToRoot();
    UpdatePkgVersionRequest request = new UpdatePkgVersionRequest();
    request.pkgName = "pkg1";
    request.repositoryCode = "testrepo";
    request.architectureCode = "x86_64";
    request.major = "1";
    request.micro = "2";
    request.revision = 3;
    request.filter = Collections.singletonList(UpdatePkgVersionRequest.Filter.ACTIVE);
    request.active = false;
    // ------------------------------------
    pkgApi.updatePkgVersion(request);
    // ------------------------------------
    {
        ObjectContext context = serverRuntime.newContext();
        Pkg pkg1 = Pkg.getByName(context, "pkg1");
        Repository repository = Repository.getByCode(context, "testrepo");
        Architecture architecture = Architecture.getByCode(context, "x86_64");
        PkgVersion pkgVersion = PkgVersion.getForPkg(context, pkg1, repository, architecture, new VersionCoordinates("1", null, "2", null, 3)).get();
        Assertions.assertThat(pkgVersion.getActive()).isFalse();
    }
}
Also used : Repository(org.haiku.haikudepotserver.dataobjects.Repository) Architecture(org.haiku.haikudepotserver.dataobjects.Architecture) VersionCoordinates(org.haiku.haikudepotserver.support.VersionCoordinates) UpdatePkgVersionRequest(org.haiku.haikudepotserver.api1.model.pkg.UpdatePkgVersionRequest) PkgVersion(org.haiku.haikudepotserver.dataobjects.PkgVersion) ObjectContext(org.apache.cayenne.ObjectContext) Pkg(org.haiku.haikudepotserver.dataobjects.Pkg) AbstractIntegrationTest(org.haiku.haikudepotserver.AbstractIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 10 with VersionCoordinates

use of org.haiku.haikudepotserver.support.VersionCoordinates in project haikudepotserver by haiku.

the class ViewPkgController method viewPkg.

@RequestMapping(value = "{name}/{repositoryCode}/{major}/{minor}/{micro}/{preRelease}/{revision}/{architectureCode}", method = RequestMethod.GET)
public ModelAndView viewPkg(HttpServletRequest httpServletRequest, @PathVariable(value = "repositoryCode") String repositoryCode, @PathVariable(value = "name") String pkgName, @PathVariable(value = "major") String major, @PathVariable(value = "minor") String minor, @PathVariable(value = "micro") String micro, @PathVariable(value = "preRelease") String preRelease, @PathVariable(value = "revision") String revisionStr, @PathVariable(value = "architectureCode") String architectureCode) throws MultipageObjectNotFoundException {
    major = hyphenToNull(major);
    minor = hyphenToNull(minor);
    micro = hyphenToNull(micro);
    preRelease = hyphenToNull(preRelease);
    revisionStr = hyphenToNull(revisionStr);
    Integer revision = null == revisionStr ? null : Integer.parseInt(revisionStr);
    ObjectContext context = serverRuntime.newContext();
    Optional<Pkg> pkgOptional = Pkg.tryGetByName(context, pkgName);
    if (!pkgOptional.isPresent()) {
        // 404
        throw new MultipageObjectNotFoundException(Pkg.class.getSimpleName(), pkgName);
    }
    Architecture architecture = Architecture.tryGetByCode(context, architectureCode).orElseThrow(() -> new MultipageObjectNotFoundException(Architecture.class.getSimpleName(), architectureCode));
    Repository repository = Repository.tryGetByCode(context, repositoryCode).orElseThrow(() -> new MultipageObjectNotFoundException(Repository.class.getSimpleName(), repositoryCode));
    VersionCoordinates coordinates = new VersionCoordinates(Strings.emptyToNull(major), Strings.emptyToNull(minor), Strings.emptyToNull(micro), Strings.emptyToNull(preRelease), revision);
    Optional<PkgVersion> pkgVersionOptional = PkgVersion.getForPkg(context, pkgOptional.get(), repository, architecture, coordinates);
    if (!pkgVersionOptional.isPresent() || !pkgVersionOptional.get().getActive()) {
        throw new MultipageObjectNotFoundException(PkgVersion.class.getSimpleName(), pkgName + "...");
    }
    String homeUrl;
    {
        UriComponentsBuilder builder = UriComponentsBuilder.fromPath(MultipageConstants.PATH_MULTIPAGE);
        String naturalLanguageCode = httpServletRequest.getParameter(WebConstants.KEY_NATURALLANGUAGECODE);
        if (!Strings.isNullOrEmpty(naturalLanguageCode)) {
            builder.queryParam(WebConstants.KEY_NATURALLANGUAGECODE, naturalLanguageCode);
        }
        homeUrl = builder.build().toString();
    }
    ViewPkgVersionData data = new ViewPkgVersionData();
    data.setPkgVersion(pkgVersionOptional.get());
    data.setCurrentNaturalLanguage(NaturalLanguageWebHelper.deriveNaturalLanguage(context, httpServletRequest));
    data.setHomeUrl(homeUrl);
    data.setIsSourceAvailable(hasSource(context, pkgVersionOptional.get()));
    ModelAndView result = new ModelAndView("multipage/viewPkgVersion");
    result.addObject("data", data);
    return result;
}
Also used : VersionCoordinates(org.haiku.haikudepotserver.support.VersionCoordinates) ModelAndView(org.springframework.web.servlet.ModelAndView) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) MultipageObjectNotFoundException(org.haiku.haikudepotserver.multipage.MultipageObjectNotFoundException) ObjectContext(org.apache.cayenne.ObjectContext) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

VersionCoordinates (org.haiku.haikudepotserver.support.VersionCoordinates)10 ObjectContext (org.apache.cayenne.ObjectContext)9 Architecture (org.haiku.haikudepotserver.dataobjects.Architecture)5 Pkg (org.haiku.haikudepotserver.dataobjects.Pkg)5 PkgVersion (org.haiku.haikudepotserver.dataobjects.PkgVersion)5 ObjectNotFoundException (org.haiku.haikudepotserver.api1.support.ObjectNotFoundException)3 org.haiku.haikudepotserver.dataobjects.auto._PkgVersion (org.haiku.haikudepotserver.dataobjects.auto._PkgVersion)3 Preconditions (com.google.common.base.Preconditions)2 Strings (com.google.common.base.Strings)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 URL (java.net.URL)2 Collectors (java.util.stream.Collectors)2 AbstractIntegrationTest (org.haiku.haikudepotserver.AbstractIntegrationTest)2 Repository (org.haiku.haikudepotserver.dataobjects.Repository)2 RepositorySource (org.haiku.haikudepotserver.dataobjects.RepositorySource)2 VersionCoordinatesComparator (org.haiku.haikudepotserver.support.VersionCoordinatesComparator)2 UserRatingSearchSpecification (org.haiku.haikudepotserver.userrating.model.UserRatingSearchSpecification)2 Test (org.junit.jupiter.api.Test)2 Logger (org.slf4j.Logger)2