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;
}
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;
}
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;
}
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();
}
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();
}
Aggregations