Search in sources :

Example 16 with ObjectNotFoundException

use of org.haiku.haikudepotserver.api1.support.ObjectNotFoundException in project haikudepotserver by haiku.

the class PkgApiImpl method removePkgScreenshot.

@Override
public RemovePkgScreenshotResult removePkgScreenshot(RemovePkgScreenshotRequest removePkgScreenshotRequest) {
    Preconditions.checkNotNull(removePkgScreenshotRequest);
    Preconditions.checkNotNull(removePkgScreenshotRequest.code);
    final ObjectContext context = serverRuntime.newContext();
    Optional<PkgScreenshot> screenshotOptional = PkgScreenshot.tryGetByCode(context, removePkgScreenshotRequest.code);
    if (screenshotOptional.isEmpty()) {
        throw new ObjectNotFoundException(PkgScreenshot.class.getSimpleName(), removePkgScreenshotRequest.code);
    }
    if (screenshotOptional.get().getPkgSupplement().getPkgs().stream().noneMatch(p -> permissionEvaluator.hasPermission(SecurityContextHolder.getContext().getAuthentication(), p, Permission.PKG_EDITSCREENSHOT))) {
        throw new AccessDeniedException("unable to remove the package screenshot for package");
    }
    pkgScreenshotService.deleteScreenshot(context, screenshotOptional.get());
    context.commitChanges();
    LOGGER.info("did remove the screenshot {}", removePkgScreenshotRequest.code);
    return new RemovePkgScreenshotResult();
}
Also used : AccessDeniedException(org.springframework.security.access.AccessDeniedException) PkgScreenshot(org.haiku.haikudepotserver.dataobjects.PkgScreenshot) ObjectNotFoundException(org.haiku.haikudepotserver.api1.support.ObjectNotFoundException) ObjectContext(org.apache.cayenne.ObjectContext)

Example 17 with ObjectNotFoundException

use of org.haiku.haikudepotserver.api1.support.ObjectNotFoundException in project haikudepotserver by haiku.

the class PkgApiImpl method updatePkgVersion.

@Override
public UpdatePkgVersionResult updatePkgVersion(UpdatePkgVersionRequest request) {
    Preconditions.checkArgument(null != request, "the request object must be supplied");
    Preconditions.checkArgument(!Strings.isNullOrEmpty(request.pkgName), "the package name must be supplied");
    Preconditions.checkArgument(!Strings.isNullOrEmpty(request.repositoryCode), "the repository code must be supplied");
    Preconditions.checkArgument(!Strings.isNullOrEmpty(request.architectureCode), "the architecture code must be supplied");
    Preconditions.checkArgument(!Strings.isNullOrEmpty(request.major), "the version major must be supplied");
    ObjectContext context = serverRuntime.newContext();
    Pkg pkg = getPkg(context, request.pkgName);
    if (!permissionEvaluator.hasPermission(SecurityContextHolder.getContext().getAuthentication(), pkg, Permission.PKG_EDITVERSION)) {
        throw new AccessDeniedException("unable to update the package version for package [" + pkg + "]");
    }
    PkgVersion pkgVersion = PkgVersion.getForPkg(context, pkg, getRepository(context, request.repositoryCode), getArchitecture(context, request.architectureCode), new VersionCoordinates(request.major, request.minor, request.micro, request.preRelease, request.revision)).orElseThrow(() -> new ObjectNotFoundException(PkgVersion.class.getSimpleName(), null));
    for (UpdatePkgVersionRequest.Filter filter : request.filter) {
        switch(filter) {
            case ACTIVE:
                LOGGER.info("will update the package version active flag to {} for {}", request.active, pkgVersion.toString());
                pkgVersion.setActive(request.active);
                pkgService.adjustLatest(context, pkgVersion.getPkg(), pkgVersion.getArchitecture());
                break;
        }
    }
    context.commitChanges();
    return new UpdatePkgVersionResult();
}
Also used : AccessDeniedException(org.springframework.security.access.AccessDeniedException) 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 18 with ObjectNotFoundException

use of org.haiku.haikudepotserver.api1.support.ObjectNotFoundException in project haikudepotserver by haiku.

the class PkgApiImpl method getPkgVersionLocalizations.

@Override
public GetPkgVersionLocalizationsResult getPkgVersionLocalizations(GetPkgVersionLocalizationsRequest getPkgVersionLocalizationsRequest) {
    Preconditions.checkNotNull(getPkgVersionLocalizationsRequest);
    Preconditions.checkState(!Strings.isNullOrEmpty(getPkgVersionLocalizationsRequest.architectureCode));
    Preconditions.checkState(!Strings.isNullOrEmpty(getPkgVersionLocalizationsRequest.pkgName));
    Preconditions.checkNotNull(getPkgVersionLocalizationsRequest.naturalLanguageCodes);
    Preconditions.checkArgument(!Strings.isNullOrEmpty(getPkgVersionLocalizationsRequest.repositoryCode), "the repository code must be supplied");
    final ObjectContext context = serverRuntime.newContext();
    Pkg pkg = getPkg(context, getPkgVersionLocalizationsRequest.pkgName);
    Architecture architecture = getArchitecture(context, getPkgVersionLocalizationsRequest.architectureCode);
    Repository repository = getRepository(context, getPkgVersionLocalizationsRequest.repositoryCode);
    Optional<PkgVersion> pkgVersionOptional;
    if (null == getPkgVersionLocalizationsRequest.major) {
        pkgVersionOptional = pkgService.getLatestPkgVersionForPkg(context, pkg, repository, Collections.singletonList(architecture));
    } else {
        pkgVersionOptional = PkgVersion.getForPkg(context, pkg, repository, architecture, new VersionCoordinates(getPkgVersionLocalizationsRequest.major, getPkgVersionLocalizationsRequest.minor, getPkgVersionLocalizationsRequest.micro, getPkgVersionLocalizationsRequest.preRelease, getPkgVersionLocalizationsRequest.revision));
    }
    if (pkgVersionOptional.isEmpty() || !pkgVersionOptional.get().getActive()) {
        throw new ObjectNotFoundException(PkgVersion.class.getSimpleName(), pkg.getName() + "/" + architecture.getCode());
    }
    GetPkgVersionLocalizationsResult result = new GetPkgVersionLocalizationsResult();
    result.pkgVersionLocalizations = new ArrayList<>();
    for (String naturalLanguageCode : getPkgVersionLocalizationsRequest.naturalLanguageCodes) {
        Optional<PkgVersionLocalization> pkgVersionLocalizationOptional = pkgVersionOptional.get().getPkgVersionLocalization(naturalLanguageCode);
        if (pkgVersionLocalizationOptional.isPresent()) {
            org.haiku.haikudepotserver.api1.model.pkg.PkgVersionLocalization resultPkgVersionLocalization = new org.haiku.haikudepotserver.api1.model.pkg.PkgVersionLocalization();
            resultPkgVersionLocalization.naturalLanguageCode = naturalLanguageCode;
            resultPkgVersionLocalization.description = pkgVersionLocalizationOptional.get().getDescription().orElse(null);
            resultPkgVersionLocalization.summary = pkgVersionLocalizationOptional.get().getSummary().orElse(null);
            result.pkgVersionLocalizations.add(resultPkgVersionLocalization);
        }
    }
    return result;
}
Also used : PkgVersionLocalization(org.haiku.haikudepotserver.dataobjects.PkgVersionLocalization) org.haiku.haikudepotserver.api1.model.pkg(org.haiku.haikudepotserver.api1.model.pkg) ObjectNotFoundException(org.haiku.haikudepotserver.api1.support.ObjectNotFoundException) org.haiku.haikudepotserver.dataobjects.auto._PkgVersion(org.haiku.haikudepotserver.dataobjects.auto._PkgVersion) org.haiku.haikudepotserver.pkg.model(org.haiku.haikudepotserver.pkg.model) ObjectContext(org.apache.cayenne.ObjectContext)

Example 19 with ObjectNotFoundException

use of org.haiku.haikudepotserver.api1.support.ObjectNotFoundException in project haikudepotserver by haiku.

the class PkgJobApiImpl method queuePkgIconArchiveImportJob.

@Override
public QueuePkgIconArchiveImportJobResult queuePkgIconArchiveImportJob(QueuePkgIconArchiveImportJobRequest request) {
    Preconditions.checkArgument(null != request, "the request must be supplied");
    Preconditions.checkArgument(!Strings.isNullOrEmpty(request.inputDataGuid), "the input data must be identified by guid");
    final ObjectContext context = serverRuntime.newContext();
    Optional<User> user = tryObtainAuthenticatedUser(context);
    if (!permissionEvaluator.hasPermission(SecurityContextHolder.getContext().getAuthentication(), null, Permission.BULK_PKGICONIMPORTARCHIVE)) {
        throw new AccessDeniedException("attempt to import package icons, but was not authorized");
    }
    // now check that the data is present.
    jobService.tryGetData(request.inputDataGuid).orElseThrow(() -> new ObjectNotFoundException(JobData.class.getSimpleName(), request.inputDataGuid));
    // setup and go
    PkgIconImportArchiveJobSpecification spec = new PkgIconImportArchiveJobSpecification();
    spec.setOwnerUserNickname(user.map(_User::getNickname).orElse(null));
    spec.setInputDataGuid(request.inputDataGuid);
    return new QueuePkgIconArchiveImportJobResult(jobService.submit(spec, JobSnapshot.COALESCE_STATUSES_NONE));
}
Also used : AccessDeniedException(org.springframework.security.access.AccessDeniedException) org.haiku.haikudepotserver.dataobjects.auto._User(org.haiku.haikudepotserver.dataobjects.auto._User) User(org.haiku.haikudepotserver.dataobjects.User) ObjectNotFoundException(org.haiku.haikudepotserver.api1.support.ObjectNotFoundException) org.haiku.haikudepotserver.dataobjects.auto._User(org.haiku.haikudepotserver.dataobjects.auto._User) ObjectContext(org.apache.cayenne.ObjectContext)

Example 20 with ObjectNotFoundException

use of org.haiku.haikudepotserver.api1.support.ObjectNotFoundException in project haikudepotserver by haiku.

the class PkgJobApiImpl method queuePkgScreenshotArchiveImportJob.

@Override
public QueuePkgScreenshotArchiveImportJobResult queuePkgScreenshotArchiveImportJob(QueuePkgScreenshotArchiveImportJobRequest request) {
    Preconditions.checkArgument(null != request, "the request must be supplied");
    Preconditions.checkArgument(StringUtils.isNotBlank(request.inputDataGuid), "the data guid must be supplied");
    Preconditions.checkArgument(null != request.importStrategy, "the import strategy must be supplied");
    final ObjectContext context = serverRuntime.newContext();
    Optional<User> user = tryObtainAuthenticatedUser(context);
    if (!permissionEvaluator.hasPermission(SecurityContextHolder.getContext().getAuthentication(), null, Permission.BULK_PKGSCREENSHOTIMPORTARCHIVE)) {
        throw new AccessDeniedException("attempt to import package screenshots, but was not authorized");
    }
    // now check that the data is present.
    jobService.tryGetData(request.inputDataGuid).orElseThrow(() -> new ObjectNotFoundException(JobData.class.getSimpleName(), request.inputDataGuid));
    // setup and go
    PkgScreenshotImportArchiveJobSpecification spec = new PkgScreenshotImportArchiveJobSpecification();
    spec.setOwnerUserNickname(user.map(_User::getNickname).orElse(null));
    spec.setInputDataGuid(request.inputDataGuid);
    spec.setImportStrategy(PkgScreenshotImportArchiveJobSpecification.ImportStrategy.valueOf(request.importStrategy.name()));
    return new QueuePkgScreenshotArchiveImportJobResult(jobService.submit(spec, JobSnapshot.COALESCE_STATUSES_NONE));
}
Also used : AccessDeniedException(org.springframework.security.access.AccessDeniedException) org.haiku.haikudepotserver.dataobjects.auto._User(org.haiku.haikudepotserver.dataobjects.auto._User) User(org.haiku.haikudepotserver.dataobjects.User) ObjectNotFoundException(org.haiku.haikudepotserver.api1.support.ObjectNotFoundException) org.haiku.haikudepotserver.dataobjects.auto._User(org.haiku.haikudepotserver.dataobjects.auto._User) ObjectContext(org.apache.cayenne.ObjectContext)

Aggregations

ObjectNotFoundException (org.haiku.haikudepotserver.api1.support.ObjectNotFoundException)32 ObjectContext (org.apache.cayenne.ObjectContext)28 AccessDeniedException (org.springframework.security.access.AccessDeniedException)17 org.haiku.haikudepotserver.dataobjects.auto._PkgVersion (org.haiku.haikudepotserver.dataobjects.auto._PkgVersion)7 RepositorySourceMirror (org.haiku.haikudepotserver.dataobjects.RepositorySourceMirror)6 org.haiku.haikudepotserver.dataobjects.auto._RepositorySourceMirror (org.haiku.haikudepotserver.dataobjects.auto._RepositorySourceMirror)6 User (org.haiku.haikudepotserver.dataobjects.User)5 Preconditions (com.google.common.base.Preconditions)3 Strings (com.google.common.base.Strings)3 AutoJsonRpcServiceImpl (com.googlecode.jsonrpc4j.spring.AutoJsonRpcServiceImpl)3 Collectors (java.util.stream.Collectors)3 ServerRuntime (org.apache.cayenne.configuration.server.ServerRuntime)3 StringUtils (org.apache.commons.lang3.StringUtils)3 ValidationException (org.haiku.haikudepotserver.api1.support.ValidationException)3 ValidationFailure (org.haiku.haikudepotserver.api1.support.ValidationFailure)3 Country (org.haiku.haikudepotserver.dataobjects.Country)3 PkgScreenshot (org.haiku.haikudepotserver.dataobjects.PkgScreenshot)3 RepositorySource (org.haiku.haikudepotserver.dataobjects.RepositorySource)3 org.haiku.haikudepotserver.dataobjects.auto._User (org.haiku.haikudepotserver.dataobjects.auto._User)3 Logger (org.slf4j.Logger)3