use of org.haiku.haikudepotserver.api1.support.ObjectNotFoundException in project haikudepotserver by haiku.
the class PkgApiImpl method incrementViewCounter.
@Override
public IncrementViewCounterResult incrementViewCounter(IncrementViewCounterRequest request) {
Preconditions.checkArgument(null != request, "the request object must be supplied");
Preconditions.checkArgument(!Strings.isNullOrEmpty(request.name), "the package name must be supplied");
Preconditions.checkArgument(!Strings.isNullOrEmpty(request.architectureCode), "the architecture must be supplied");
Preconditions.checkArgument(!Strings.isNullOrEmpty(request.repositoryCode), "the repository code must be supplied");
Preconditions.checkArgument(!Strings.isNullOrEmpty(request.major), "the version major must be supplied");
ObjectContext context = serverRuntime.newContext();
VersionCoordinates versionCoordinates = new VersionCoordinates(request.major, request.minor, request.micro, request.preRelease, request.revision);
PkgVersion pkgVersion = PkgVersion.getForPkg(context, Pkg.getByName(context, request.name), Repository.getByCode(context, request.repositoryCode), Architecture.getByCode(context, request.architectureCode), versionCoordinates).orElseThrow(() -> new ObjectNotFoundException(PkgVersion.class.getSimpleName(), versionCoordinates));
incrementCounter(pkgVersion);
return new IncrementViewCounterResult();
}
use of org.haiku.haikudepotserver.api1.support.ObjectNotFoundException in project haikudepotserver by haiku.
the class PkgJobApiImpl method queuePkgCategoryCoverageImportSpreadsheetJob.
@Override
public QueuePkgCategoryCoverageImportSpreadsheetJobResult queuePkgCategoryCoverageImportSpreadsheetJob(QueuePkgCategoryCoverageImportSpreadsheetJobRequest 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_PKGCATEGORYCOVERAGEIMPORTSPREADSHEET)) {
throw new AccessDeniedException("attempt to import package categories, 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
PkgCategoryCoverageImportSpreadsheetJobSpecification spec = new PkgCategoryCoverageImportSpreadsheetJobSpecification();
spec.setOwnerUserNickname(user.map(_User::getNickname).orElse(null));
spec.setInputDataGuid(request.inputDataGuid);
return new QueuePkgCategoryCoverageImportSpreadsheetJobResult(jobService.submit(spec, JobSnapshot.COALESCE_STATUSES_NONE));
}
use of org.haiku.haikudepotserver.api1.support.ObjectNotFoundException in project haikudepotserver by haiku.
the class RepositoryApiImpl method createRepositorySourceMirror.
@Override
public CreateRepositorySourceMirrorResult createRepositorySourceMirror(CreateRepositorySourceMirrorRequest request) {
Preconditions.checkArgument(null != request, "the request must be supplied");
Preconditions.checkArgument(!Strings.isNullOrEmpty(request.repositorySourceCode), "the code for the new repository source mirror");
Preconditions.checkArgument(!Strings.isNullOrEmpty(request.countryCode), "the country code should be supplied");
Preconditions.checkArgument(!Strings.isNullOrEmpty(request.baseUrl), "the base url should be supplied");
final ObjectContext context = serverRuntime.newContext();
Country country = Country.tryGetByCode(context, request.countryCode).orElseThrow(() -> new ObjectNotFoundException(Country.class.getSimpleName(), request.countryCode));
RepositorySource repositorySource = getRepositorySourceOrThrow(context, request.repositorySourceCode);
if (!permissionEvaluator.hasPermission(SecurityContextHolder.getContext().getAuthentication(), repositorySource.getRepository(), Permission.REPOSITORY_EDIT)) {
throw new AccessDeniedException("the repository [" + repositorySource.getRepository() + "] is not able to be edited");
}
if (tryGetRepositorySourceMirrorObjectIdForBaseUrl(repositorySource.getCode(), request.baseUrl).isPresent()) {
LOGGER.info("attempt to add a repository source mirror for a url [{}] that is " + " already in use", request.baseUrl);
throw new ValidationException(new ValidationFailure(RepositorySourceMirror.BASE_URL.getName(), "unique"));
}
// if there is no other mirror then this should be the primary.
RepositorySourceMirror mirror = context.newObject(RepositorySourceMirror.class);
mirror.setIsPrimary(repositorySource.tryGetPrimaryMirror().isEmpty());
mirror.setBaseUrl(request.baseUrl);
mirror.setRepositorySource(repositorySource);
mirror.setCountry(country);
mirror.setDescription(StringUtils.trimToNull(request.description));
mirror.setCode(UUID.randomUUID().toString());
repositorySource.getRepository().setModifyTimestamp();
context.commitChanges();
LOGGER.info("did add mirror [{}] to repository source [{}]", country.getCode(), repositorySource.getCode());
CreateRepositorySourceMirrorResult result = new CreateRepositorySourceMirrorResult();
result.code = mirror.getCode();
return result;
}
use of org.haiku.haikudepotserver.api1.support.ObjectNotFoundException in project haikudepotserver by haiku.
the class RepositoryApiImpl method getRepositorySourceMirror.
@Override
public GetRepositorySourceMirrorResult getRepositorySourceMirror(GetRepositorySourceMirrorRequest request) {
Preconditions.checkArgument(null != request, "the request must be provided");
Preconditions.checkArgument(StringUtils.isNotBlank(request.code), "a mirror code must be provided");
final ObjectContext context = serverRuntime.newContext();
RepositorySourceMirror repositorySourceMirror = RepositorySourceMirror.tryGetByCode(context, request.code).orElseThrow(() -> new ObjectNotFoundException(RepositorySourceMirror.class.getSimpleName(), request.code));
GetRepositorySourceMirrorResult result = new GetRepositorySourceMirrorResult();
result.active = repositorySourceMirror.getActive();
result.baseUrl = repositorySourceMirror.getBaseUrl();
result.code = repositorySourceMirror.getCode();
result.countryCode = repositorySourceMirror.getCountry().getCode();
result.createTimestamp = repositorySourceMirror.getCreateTimestamp().getTime();
result.modifyTimestamp = repositorySourceMirror.getModifyTimestamp().getTime();
result.description = repositorySourceMirror.getDescription();
result.isPrimary = repositorySourceMirror.getIsPrimary();
result.repositorySourceCode = repositorySourceMirror.getRepositorySource().getCode();
return result;
}
use of org.haiku.haikudepotserver.api1.support.ObjectNotFoundException in project haikudepotserver by haiku.
the class UserRatingApiImpl method searchUserRatings.
@Override
public SearchUserRatingsResult searchUserRatings(SearchUserRatingsRequest request) {
Preconditions.checkNotNull(request);
Preconditions.checkNotNull(request.limit);
Preconditions.checkState(request.limit > 0);
final ObjectContext context = serverRuntime.newContext();
UserRatingSearchSpecification searchSpecification = new UserRatingSearchSpecification();
if (null != request.daysSinceCreated) {
searchSpecification.setDaysSinceCreated(request.daysSinceCreated.intValue());
}
Architecture architecture = null;
if (null != request.pkgVersionArchitectureCode) {
architecture = getArchitecture(context, request.pkgVersionArchitectureCode);
}
Optional<Pkg> pkgOptional = Optional.empty();
if (null != request.pkgName) {
pkgOptional = Pkg.tryGetByName(context, request.pkgName);
if (pkgOptional.isEmpty()) {
throw new ObjectNotFoundException(Pkg.class.getSimpleName(), request.pkgName);
}
}
Optional<Repository> repositoryOptional = Optional.empty();
if (!Strings.isNullOrEmpty(request.repositoryCode)) {
searchSpecification.setRepository(getRepository(context, request.repositoryCode));
}
if (null != request.pkgVersionMajor) {
if (repositoryOptional.isEmpty()) {
throw new IllegalStateException("the repository is required when a pkg version is specified");
}
if (pkgOptional.isEmpty()) {
throw new IllegalStateException("the pkg is required when a pkg version is specified");
}
if (null == architecture) {
throw new IllegalStateException("the architecture is required when a pkg version is specified");
}
PkgVersion pkgVersion = PkgVersion.getForPkg(context, pkgOptional.get(), repositoryOptional.get(), architecture, new VersionCoordinates(request.pkgVersionMajor, request.pkgVersionMinor, request.pkgVersionMicro, request.pkgVersionPreRelease, request.pkgVersionRevision)).filter(_PkgVersion::getActive).orElseThrow(() -> new ObjectNotFoundException(PkgVersion.class.getSimpleName(), ""));
searchSpecification.setPkgVersion(pkgVersion);
} else {
searchSpecification.setArchitecture(architecture);
if (pkgOptional.isPresent()) {
searchSpecification.setPkg(pkgOptional.get());
}
}
if (null != request.userNickname) {
Optional<User> userOptional = User.tryGetByNickname(context, request.userNickname);
if (userOptional.isEmpty()) {
throw new ObjectNotFoundException(User.class.getSimpleName(), request.userNickname);
}
searchSpecification.setUser(userOptional.get());
}
searchSpecification.setLimit(request.limit);
searchSpecification.setOffset(request.offset);
List<UserRating> foundUserRatings = userRatingService.search(context, searchSpecification);
final SearchUserRatingsResult result = new SearchUserRatingsResult();
result.total = userRatingService.total(context, searchSpecification);
result.items = foundUserRatings.stream().map(ur -> {
SearchUserRatingsResult.UserRating resultUserRating = new SearchUserRatingsResult.UserRating();
resultUserRating.active = ur.getActive();
resultUserRating.code = ur.getCode();
resultUserRating.comment = ur.getComment();
resultUserRating.createTimestamp = ur.getCreateTimestamp().getTime();
resultUserRating.modifyTimestamp = ur.getModifyTimestamp().getTime();
resultUserRating.userRatingStabilityCode = null != ur.getUserRatingStability() ? ur.getUserRatingStability().getCode() : null;
resultUserRating.naturalLanguageCode = ur.getNaturalLanguage().getCode();
resultUserRating.pkgVersion = createPkgVersion(ur.getPkgVersion());
resultUserRating.rating = ur.getRating();
resultUserRating.user = createUser(ur.getUser());
return resultUserRating;
}).collect(Collectors.toList());
return result;
}
Aggregations