use of org.haiku.haikudepotserver.api1.support.ObjectNotFoundException in project haikudepotserver by haiku.
the class UserRatingApiImpl method updateUserRating.
@Override
public UpdateUserRatingResult updateUserRating(UpdateUserRatingRequest request) {
Preconditions.checkNotNull(request);
Preconditions.checkState(!Strings.isNullOrEmpty(request.code));
Preconditions.checkNotNull(request.filter);
final ObjectContext context = serverRuntime.newContext();
UserRating userRating = UserRating.tryGetByCode(context, request.code).orElseThrow(() -> new ObjectNotFoundException(UserRating.class.getSimpleName(), request.code));
if (!permissionEvaluator.hasPermission(SecurityContextHolder.getContext().getAuthentication(), userRating, Permission.USERRATING_EDIT)) {
throw new AccessDeniedException("unable to edit the userrating");
}
for (UpdateUserRatingRequest.Filter filter : request.filter) {
switch(filter) {
case ACTIVE:
if (null == request.active) {
throw new IllegalStateException("the active flag must be supplied to configure this field");
}
userRating.setActive(request.active);
break;
case COMMENT:
if (null != request.comment) {
userRating.setComment(Strings.emptyToNull(request.comment.trim()));
} else {
userRating.setComment(null);
}
break;
case NATURALLANGUAGE:
NaturalLanguage naturalLanguage = getNaturalLanguage(context, request.naturalLanguageCode);
userRating.setNaturalLanguage(naturalLanguage);
break;
case RATING:
userRating.setRating(request.rating);
break;
case USERRATINGSTABILITY:
if (null == request.userRatingStabilityCode) {
userRating.setUserRatingStability(null);
} else {
userRating.setUserRatingStability(UserRatingStability.getByCode(context, request.userRatingStabilityCode).orElseThrow(() -> new ObjectNotFoundException(UserRatingStability.class.getSimpleName(), request.userRatingStabilityCode)));
}
break;
default:
throw new IllegalStateException("the filter; " + filter.name() + " is not handled");
}
}
LOGGER.info("did update user rating for user {} on package {}", userRating.getUser().toString(), userRating.getPkgVersion().getPkg().toString());
context.commitChanges();
return new UpdateUserRatingResult();
}
use of org.haiku.haikudepotserver.api1.support.ObjectNotFoundException in project haikudepotserver by haiku.
the class UserRatingApiImpl method getUserRating.
@Override
public GetUserRatingResult getUserRating(GetUserRatingRequest request) {
Preconditions.checkNotNull(request);
Preconditions.checkState(!Strings.isNullOrEmpty(request.code));
final ObjectContext context = serverRuntime.newContext();
UserRating userRating = UserRating.tryGetByCode(context, request.code).orElseThrow(() -> new ObjectNotFoundException(UserRating.class.getSimpleName(), request.code));
GetUserRatingResult result = new GetUserRatingResult();
fillAbstractGetUserRatingResult(userRating, result);
return result;
}
use of org.haiku.haikudepotserver.api1.support.ObjectNotFoundException in project haikudepotserver by haiku.
the class UserRatingApiImpl method removeUserRating.
@Override
public RemoveUserRatingResult removeUserRating(RemoveUserRatingRequest request) {
Preconditions.checkNotNull(request);
Preconditions.checkState(StringUtils.isNotBlank(request.code));
final ObjectContext context = serverRuntime.newContext();
UserRating userRating = UserRating.tryGetByCode(context, request.code).orElseThrow(() -> new ObjectNotFoundException(UserRating.class.getSimpleName(), request.code));
if (!permissionEvaluator.hasPermission(SecurityContextHolder.getContext().getAuthentication(), userRating, Permission.USERRATING_REMOVE)) {
throw new AccessDeniedException("unable to delete the userrating");
}
userRatingService.removeUserRatingAtomically(userRating.getCode());
return new RemoveUserRatingResult();
}
use of org.haiku.haikudepotserver.api1.support.ObjectNotFoundException in project haikudepotserver by haiku.
the class AbstractApiImpl method getNaturalLanguage.
protected NaturalLanguage getNaturalLanguage(ObjectContext context, String naturalLanguageCode) {
Preconditions.checkNotNull(context);
Preconditions.checkState(!Strings.isNullOrEmpty(naturalLanguageCode));
return NaturalLanguage.tryGetByCode(context, naturalLanguageCode).orElseThrow(() -> new ObjectNotFoundException(NaturalLanguage.class.getSimpleName(), naturalLanguageCode));
}
use of org.haiku.haikudepotserver.api1.support.ObjectNotFoundException in project haikudepotserver by haiku.
the class AbstractApiImpl method getArchitecture.
protected Architecture getArchitecture(ObjectContext context, String architectureCode) {
Preconditions.checkNotNull(context);
Preconditions.checkState(!Strings.isNullOrEmpty(architectureCode), "an architecture code is required to get the architecture");
return Architecture.tryGetByCode(context, architectureCode).orElseThrow(() -> new ObjectNotFoundException(Architecture.class.getSimpleName(), architectureCode));
}
Aggregations