use of org.haiku.haikudepotserver.multipage.MultipageObjectNotFoundException in project haikudepotserver by haiku.
the class ViewPkgController method viewPkg.
@RequestMapping(value = "{name}/{repositoryCode}/{major}/{minor}/{micro}/{preRelease}/{revision}/{architectureCode}", method = RequestMethod.GET)
public ModelAndView viewPkg(HttpServletRequest httpServletRequest, @PathVariable(value = "repositoryCode") String repositoryCode, @PathVariable(value = "name") String pkgName, @PathVariable(value = "major") String major, @PathVariable(value = "minor") String minor, @PathVariable(value = "micro") String micro, @PathVariable(value = "preRelease") String preRelease, @PathVariable(value = "revision") String revisionStr, @PathVariable(value = "architectureCode") String architectureCode) throws MultipageObjectNotFoundException {
major = hyphenToNull(major);
minor = hyphenToNull(minor);
micro = hyphenToNull(micro);
preRelease = hyphenToNull(preRelease);
revisionStr = hyphenToNull(revisionStr);
Integer revision = null == revisionStr ? null : Integer.parseInt(revisionStr);
ObjectContext context = serverRuntime.newContext();
Optional<Pkg> pkgOptional = Pkg.tryGetByName(context, pkgName);
if (!pkgOptional.isPresent()) {
// 404
throw new MultipageObjectNotFoundException(Pkg.class.getSimpleName(), pkgName);
}
Architecture architecture = Architecture.tryGetByCode(context, architectureCode).orElseThrow(() -> new MultipageObjectNotFoundException(Architecture.class.getSimpleName(), architectureCode));
Repository repository = Repository.tryGetByCode(context, repositoryCode).orElseThrow(() -> new MultipageObjectNotFoundException(Repository.class.getSimpleName(), repositoryCode));
VersionCoordinates coordinates = new VersionCoordinates(Strings.emptyToNull(major), Strings.emptyToNull(minor), Strings.emptyToNull(micro), Strings.emptyToNull(preRelease), revision);
Optional<PkgVersion> pkgVersionOptional = PkgVersion.getForPkg(context, pkgOptional.get(), repository, architecture, coordinates);
if (!pkgVersionOptional.isPresent() || !pkgVersionOptional.get().getActive()) {
throw new MultipageObjectNotFoundException(PkgVersion.class.getSimpleName(), pkgName + "...");
}
String homeUrl;
{
UriComponentsBuilder builder = UriComponentsBuilder.fromPath(MultipageConstants.PATH_MULTIPAGE);
String naturalLanguageCode = httpServletRequest.getParameter(WebConstants.KEY_NATURALLANGUAGECODE);
if (!Strings.isNullOrEmpty(naturalLanguageCode)) {
builder.queryParam(WebConstants.KEY_NATURALLANGUAGECODE, naturalLanguageCode);
}
homeUrl = builder.build().toString();
}
ViewPkgVersionData data = new ViewPkgVersionData();
data.setPkgVersion(pkgVersionOptional.get());
data.setCurrentNaturalLanguage(NaturalLanguageWebHelper.deriveNaturalLanguage(context, httpServletRequest));
data.setHomeUrl(homeUrl);
data.setIsSourceAvailable(hasSource(context, pkgVersionOptional.get()));
ModelAndView result = new ModelAndView("multipage/viewPkgVersion");
result.addObject("data", data);
return result;
}
Aggregations