Search in sources :

Example 11 with ObjectNotFoundException

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

the class MiscellaneousApiImpl method getAllMessages.

@Override
public GetAllMessagesResult getAllMessages(GetAllMessagesRequest getAllMessagesRequest) {
    Preconditions.checkNotNull(getAllMessagesRequest);
    Preconditions.checkNotNull(getAllMessagesRequest.naturalLanguageCode);
    ObjectContext context = serverRuntime.newContext();
    NaturalLanguage naturalLanguage = Optional.ofNullable(getAllMessagesRequest.naturalLanguageCode).filter(StringUtils::isNotBlank).flatMap(c -> NaturalLanguage.tryGetByCode(context, c)).orElseThrow(() -> new ObjectNotFoundException(NaturalLanguage.class.getSimpleName(), getAllMessagesRequest.naturalLanguageCode));
    Properties allLocalizationMessages = naturalLanguageService.getAllLocalizationMessages(naturalLanguage.getCode());
    GetAllMessagesResult getAllMessagesResult = new GetAllMessagesResult();
    getAllMessagesResult.messages = new HashMap<>();
    for (Object key : allLocalizationMessages.keySet()) {
        getAllMessagesResult.messages.put(key.toString(), allLocalizationMessages.get(key).toString());
    }
    return getAllMessagesResult;
}
Also used : ContributorsService(org.haiku.haikudepotserver.support.ContributorsService) ObjectContext(org.apache.cayenne.ObjectContext) java.util(java.util) Logger(org.slf4j.Logger) AutoJsonRpcServiceImpl(com.googlecode.jsonrpc4j.spring.AutoJsonRpcServiceImpl) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) RuntimeInformationService(org.haiku.haikudepotserver.support.RuntimeInformationService) org.haiku.haikudepotserver.api1.model.miscellaneous(org.haiku.haikudepotserver.api1.model.miscellaneous) StringUtils(org.apache.commons.lang3.StringUtils) FeedSpecification(org.haiku.haikudepotserver.feed.model.FeedSpecification) Collectors(java.util.stream.Collectors) org.haiku.haikudepotserver.dataobjects(org.haiku.haikudepotserver.dataobjects) Value(org.springframework.beans.factory.annotation.Value) Strings(com.google.common.base.Strings) Component(org.springframework.stereotype.Component) NaturalLanguageService(org.haiku.haikudepotserver.naturallanguage.model.NaturalLanguageService) Preconditions(com.google.common.base.Preconditions) FeedService(org.haiku.haikudepotserver.feed.model.FeedService) ServerRuntime(org.apache.cayenne.configuration.server.ServerRuntime) ObjectNotFoundException(org.haiku.haikudepotserver.api1.support.ObjectNotFoundException) MessageSource(org.springframework.context.MessageSource) StringUtils(org.apache.commons.lang3.StringUtils) ObjectNotFoundException(org.haiku.haikudepotserver.api1.support.ObjectNotFoundException) ObjectContext(org.apache.cayenne.ObjectContext)

Example 12 with ObjectNotFoundException

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

the class MiscellaneousApiImpl method generateFeedUrl.

@Override
public GenerateFeedUrlResult generateFeedUrl(final GenerateFeedUrlRequest request) {
    Preconditions.checkNotNull(request);
    final ObjectContext context = serverRuntime.newContext();
    FeedSpecification specification = new FeedSpecification();
    specification.setFeedType(FeedSpecification.FeedType.ATOM);
    specification.setLimit(request.limit);
    if (null != request.supplierTypes) {
        specification.setSupplierTypes(request.supplierTypes.stream().map(st -> FeedSpecification.SupplierType.valueOf(st.name())).collect(Collectors.toList()));
    }
    if (null != request.naturalLanguageCode) {
        specification.setNaturalLanguageCode(getNaturalLanguage(context, request.naturalLanguageCode).getCode());
    }
    if (null != request.pkgNames) {
        List<String> checkedPkgNames = new ArrayList<>();
        for (String pkgName : request.pkgNames) {
            Optional<Pkg> pkgOptional = Pkg.tryGetByName(context, pkgName);
            if (pkgOptional.isEmpty()) {
                throw new ObjectNotFoundException(Pkg.class.getSimpleName(), pkgName);
            }
            checkedPkgNames.add(pkgOptional.get().getName());
        }
        specification.setPkgNames(checkedPkgNames);
    }
    GenerateFeedUrlResult result = new GenerateFeedUrlResult();
    result.url = feedService.generateUrl(specification);
    return result;
}
Also used : ObjectNotFoundException(org.haiku.haikudepotserver.api1.support.ObjectNotFoundException) FeedSpecification(org.haiku.haikudepotserver.feed.model.FeedSpecification) ObjectContext(org.apache.cayenne.ObjectContext)

Example 13 with ObjectNotFoundException

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

the class PkgApiImpl method getPkgScreenshot.

@Override
public GetPkgScreenshotResult getPkgScreenshot(GetPkgScreenshotRequest request) {
    Preconditions.checkNotNull(request);
    Preconditions.checkNotNull(request.code);
    final ObjectContext context = serverRuntime.newContext();
    Optional<PkgScreenshot> pkgScreenshotOptional = PkgScreenshot.tryGetByCode(context, request.code);
    if (pkgScreenshotOptional.isEmpty()) {
        throw new ObjectNotFoundException(PkgScreenshot.class.getSimpleName(), request.code);
    }
    GetPkgScreenshotResult result = new GetPkgScreenshotResult();
    result.code = pkgScreenshotOptional.get().getCode();
    result.height = pkgScreenshotOptional.get().getHeight();
    result.width = pkgScreenshotOptional.get().getWidth();
    result.length = pkgScreenshotOptional.get().getLength();
    return result;
}
Also used : PkgScreenshot(org.haiku.haikudepotserver.dataobjects.PkgScreenshot) ObjectNotFoundException(org.haiku.haikudepotserver.api1.support.ObjectNotFoundException) ObjectContext(org.apache.cayenne.ObjectContext)

Example 14 with ObjectNotFoundException

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

the class PkgApiImpl method updatePkgProminence.

@Override
public UpdatePkgProminenceResult updatePkgProminence(UpdatePkgProminenceRequest request) {
    Preconditions.checkArgument(null != request);
    Preconditions.checkArgument(!Strings.isNullOrEmpty(request.pkgName), "the package name must be supplied on the request");
    Preconditions.checkArgument(null != request.prominenceOrdering, "the presence ordering must be supplied");
    Preconditions.checkArgument(!Strings.isNullOrEmpty(request.repositoryCode), "the repository code is required when updating a package prominence");
    final ObjectContext context = serverRuntime.newContext();
    Pkg pkg = getPkg(context, request.pkgName);
    Repository repository = getRepository(context, request.repositoryCode);
    if (!permissionEvaluator.hasPermission(SecurityContextHolder.getContext().getAuthentication(), pkg, Permission.PKG_EDITPROMINENCE)) {
        throw new AccessDeniedException("unable to edit the package prominence for [" + pkg + "]");
    }
    Optional<Prominence> prominenceOptional = Prominence.getByOrdering(context, request.prominenceOrdering);
    if (prominenceOptional.isEmpty()) {
        throw new ObjectNotFoundException(Prominence.class.getSimpleName(), request.prominenceOrdering);
    }
    PkgProminence pkgProminence = pkgService.ensurePkgProminence(context, pkg, repository);
    pkgProminence.setProminence(prominenceOptional.get());
    context.commitChanges();
    LOGGER.info("the prominence for {} has been set to; {}", pkg.toString(), prominenceOptional.get().toString());
    return new UpdatePkgProminenceResult();
}
Also used : AccessDeniedException(org.springframework.security.access.AccessDeniedException) ObjectNotFoundException(org.haiku.haikudepotserver.api1.support.ObjectNotFoundException) ObjectContext(org.apache.cayenne.ObjectContext)

Example 15 with ObjectNotFoundException

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

the class PkgApiImpl method updatePkgCategories.

@Override
public UpdatePkgCategoriesResult updatePkgCategories(UpdatePkgCategoriesRequest updatePkgCategoriesRequest) {
    Preconditions.checkNotNull(updatePkgCategoriesRequest);
    Preconditions.checkState(!Strings.isNullOrEmpty(updatePkgCategoriesRequest.pkgName));
    Preconditions.checkNotNull(updatePkgCategoriesRequest.pkgCategoryCodes);
    if (updatePkgCategoriesRequest.pkgCategoryCodes.size() > PKGPKGCATEGORIES_MAX) {
        throw new IllegalStateException("a package is not able to be configured with more than " + PKGPKGCATEGORIES_MAX + " categories");
    }
    final ObjectContext context = serverRuntime.newContext();
    Pkg pkg = getPkg(context, updatePkgCategoriesRequest.pkgName);
    if (!permissionEvaluator.hasPermission(SecurityContextHolder.getContext().getAuthentication(), pkg, Permission.PKG_EDITCATEGORIES)) {
        throw new AccessDeniedException("attempt to configure the categories for package [" + pkg + "], but the user is not able to");
    }
    List<PkgCategory> pkgCategories = new ArrayList<>(PkgCategory.getByCodes(context, updatePkgCategoriesRequest.pkgCategoryCodes));
    if (pkgCategories.size() != updatePkgCategoriesRequest.pkgCategoryCodes.size()) {
        LOGGER.warn("request for {} categories yielded only {}; must be a code mismatch", updatePkgCategoriesRequest.pkgCategoryCodes.size(), pkgCategories.size());
        throw new ObjectNotFoundException(PkgCategory.class.getSimpleName(), null);
    }
    pkgService.updatePkgCategories(context, pkg, pkgCategories);
    context.commitChanges();
    LOGGER.info("did configure {} categories for pkg {}", updatePkgCategoriesRequest.pkgCategoryCodes.size(), pkg.getName());
    return new UpdatePkgCategoriesResult();
}
Also used : AccessDeniedException(org.springframework.security.access.AccessDeniedException) ObjectNotFoundException(org.haiku.haikudepotserver.api1.support.ObjectNotFoundException) 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