use of org.haiku.haikudepotserver.api1.model.miscellaneous in project haikudepotserver by haiku.
the class PkgApiImpl method getPkgLocalizations.
@Override
public GetPkgLocalizationsResult getPkgLocalizations(GetPkgLocalizationsRequest getPkgLocalizationsRequest) {
Preconditions.checkArgument(null != getPkgLocalizationsRequest, "a request is required");
Preconditions.checkArgument(!Strings.isNullOrEmpty(getPkgLocalizationsRequest.pkgName), "a package name is required");
Preconditions.checkArgument(null != getPkgLocalizationsRequest.naturalLanguageCodes, "the natural language codes must be supplied");
final ObjectContext context = serverRuntime.newContext();
Pkg pkg = getPkg(context, getPkgLocalizationsRequest.pkgName);
GetPkgLocalizationsResult result = new GetPkgLocalizationsResult();
result.pkgLocalizations = new ArrayList<>();
List<PkgLocalization> pkgLocalizations = PkgLocalization.findForPkg(context, pkg);
for (PkgLocalization pkgLocalization : pkgLocalizations) {
if (getPkgLocalizationsRequest.naturalLanguageCodes.contains(pkgLocalization.getNaturalLanguage().getCode())) {
org.haiku.haikudepotserver.api1.model.pkg.PkgLocalization resultPkgVersionLocalization = new org.haiku.haikudepotserver.api1.model.pkg.PkgLocalization();
resultPkgVersionLocalization.naturalLanguageCode = pkgLocalization.getNaturalLanguage().getCode();
resultPkgVersionLocalization.title = pkgLocalization.getTitle();
resultPkgVersionLocalization.summary = pkgLocalization.getSummary();
resultPkgVersionLocalization.description = pkgLocalization.getDescription();
result.pkgLocalizations.add(resultPkgVersionLocalization);
}
}
return result;
}
use of org.haiku.haikudepotserver.api1.model.miscellaneous in project haikudepotserver by haiku.
the class PkgApiImpl method updatePkgLocalization.
@Override
public UpdatePkgLocalizationResult updatePkgLocalization(UpdatePkgLocalizationRequest updatePkgLocalizationRequest) {
Preconditions.checkArgument(null != updatePkgLocalizationRequest);
Preconditions.checkArgument(!Strings.isNullOrEmpty(updatePkgLocalizationRequest.pkgName), "the package name must be supplied");
final ObjectContext context = serverRuntime.newContext();
Pkg pkg = getPkg(context, updatePkgLocalizationRequest.pkgName);
User authUser = obtainAuthenticatedUser(context);
if (!permissionEvaluator.hasPermission(SecurityContextHolder.getContext().getAuthentication(), pkg, Permission.PKG_EDITLOCALIZATION)) {
throw new AccessDeniedException("unable to edit the package localization for [" + pkg + "]");
}
for (org.haiku.haikudepotserver.api1.model.pkg.PkgLocalization requestPkgVersionLocalization : updatePkgLocalizationRequest.pkgLocalizations) {
NaturalLanguage naturalLanguage = getNaturalLanguage(context, requestPkgVersionLocalization.naturalLanguageCode);
pkgLocalizationService.updatePkgLocalization(context, pkg.getPkgSupplement(), naturalLanguage, requestPkgVersionLocalization.title, requestPkgVersionLocalization.summary, requestPkgVersionLocalization.description);
}
context.commitChanges();
LOGGER.info("did update the localization for pkg {} for {} natural languages", pkg.getName(), updatePkgLocalizationRequest.pkgLocalizations.size());
return new UpdatePkgLocalizationResult();
}
use of org.haiku.haikudepotserver.api1.model.miscellaneous 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;
}
use of org.haiku.haikudepotserver.api1.model.miscellaneous in project haikudepotserver by haiku.
the class UserApiImpl method authenticateUser.
@Override
public ResponseEntity<AuthenticateUserResponseEnvelope> authenticateUser(AuthenticateUserRequestEnvelope authenticateUserRequestEnvelope) {
AuthenticateUserRequest requestV1 = new AuthenticateUserRequest();
requestV1.nickname = authenticateUserRequestEnvelope.getNickname();
requestV1.passwordClear = authenticateUserRequestEnvelope.getPasswordClear();
org.haiku.haikudepotserver.api1.model.user.AuthenticateUserResult resultV1 = userApiV1.authenticateUser(requestV1);
return ResponseEntity.ok(new AuthenticateUserResponseEnvelope().result(new AuthenticateUserResult().token(resultV1.token)));
}
use of org.haiku.haikudepotserver.api1.model.miscellaneous in project haikudepotserver by haiku.
the class UserRatingApiImpl method createUserRating.
@Override
public ResponseEntity<CreateUserRatingResponseEnvelope> createUserRating(@Valid CreateUserRatingRequestEnvelope createUserRatingRequestEnvelope) {
CreateUserRatingRequest requestV1 = new CreateUserRatingRequest();
requestV1.repositoryCode = createUserRatingRequestEnvelope.getRepositoryCode();
requestV1.naturalLanguageCode = createUserRatingRequestEnvelope.getNaturalLanguageCode();
requestV1.userNickname = createUserRatingRequestEnvelope.getUserNickname();
requestV1.userRatingStabilityCode = createUserRatingRequestEnvelope.getUserRatingStabilityCode();
requestV1.comment = createUserRatingRequestEnvelope.getComment();
requestV1.rating = Optional.ofNullable(createUserRatingRequestEnvelope.getRating()).map(Number::shortValue).orElse(null);
requestV1.pkgName = createUserRatingRequestEnvelope.getPkgName();
requestV1.pkgVersionArchitectureCode = createUserRatingRequestEnvelope.getPkgVersionArchitectureCode();
requestV1.pkgVersionMajor = createUserRatingRequestEnvelope.getPkgVersionMajor();
requestV1.pkgVersionMinor = createUserRatingRequestEnvelope.getPkgVersionMinor();
requestV1.pkgVersionMicro = createUserRatingRequestEnvelope.getPkgVersionMicro();
requestV1.pkgVersionPreRelease = createUserRatingRequestEnvelope.getPkgVersionPreRelease();
requestV1.pkgVersionRevision = createUserRatingRequestEnvelope.getPkgVersionRevision();
requestV1.pkgVersionType = Optional.ofNullable(createUserRatingRequestEnvelope.getPkgVersionType()).map(pvt -> PkgVersionType.valueOf(pvt.name())).orElse(null);
org.haiku.haikudepotserver.api1.model.userrating.CreateUserRatingResult resultV1 = userRatingApiV1.createUserRating(requestV1);
return ResponseEntity.ok(new CreateUserRatingResponseEnvelope().result(new CreateUserRatingResult().code(resultV1.code)));
}
Aggregations