use of org.haiku.haikudepotserver.dataobjects.PkgLocalization 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.dataobjects.PkgLocalization in project haikudepotserver by haiku.
the class PkgImportServiceImplIT method testImport_develPkgHandling.
/**
* <p>When a "_devel" package is imported there is a special behaviour that the localization and the
* icons are copied from the main package over to the "_devel" package.</p>
*/
@Test
public void testImport_develPkgHandling() throws Exception {
ObjectId respositorySourceObjectId;
{
integrationTestSupportService.createStandardTestData();
ObjectContext context = serverRuntime.newContext();
RepositorySource repositorySource = RepositorySource.tryGetByCode(context, "testreposrc_xyz").get();
respositorySourceObjectId = repositorySource.getObjectId();
}
// setup the base package.
{
Pkg importPkg = createPkg("2");
{
ObjectContext importObjectContext = serverRuntime.newContext();
pkgImportService.importFrom(importObjectContext, respositorySourceObjectId, importPkg, false);
importObjectContext.commitChanges();
}
// now add some localization to the imported package.
{
ObjectContext setupObjectContext = serverRuntime.newContext();
org.haiku.haikudepotserver.dataobjects.Pkg persistedPkg = org.haiku.haikudepotserver.dataobjects.Pkg.getByName(setupObjectContext, importPkg.getName());
setupObjectContext.commitChanges();
pkgLocalizationService.updatePkgLocalization(setupObjectContext, persistedPkg.getPkgSupplement(), NaturalLanguage.getByCode(setupObjectContext, NaturalLanguage.CODE_GERMAN), "title_kingston_black", "summary_kingston_black", "description_kingston_black");
setupObjectContext.commitChanges();
try (InputStream inputStream = Resources.asByteSource(Resources.getResource("sample-32x32.png")).openStream()) {
pkgIconService.storePkgIconImage(inputStream, MediaType.getByCode(setupObjectContext, com.google.common.net.MediaType.PNG.toString()), 32, setupObjectContext, persistedPkg.getPkgSupplement());
}
setupObjectContext.commitChanges();
}
}
// setup the devel package.
Pkg importDevelPkg = new Pkg("testpkg" + PkgServiceImpl.SUFFIX_PKG_DEVELOPMENT, new PkgVersion("1", "2", "3", "4", 5), PkgArchitecture.X86_64, null, Collections.emptyList(), Collections.emptyList(), "test-summary-en", "test-description-en", null);
// ---------------------------------
{
ObjectContext importObjectContext = serverRuntime.newContext();
pkgImportService.importFrom(importObjectContext, respositorySourceObjectId, importDevelPkg, false);
importObjectContext.commitChanges();
}
// ---------------------------------
// check it has the icon and the localization.
{
ObjectContext context = serverRuntime.newContext();
org.haiku.haikudepotserver.dataobjects.Pkg persistedDevelPkg = org.haiku.haikudepotserver.dataobjects.Pkg.getByName(context, importDevelPkg.getName());
PkgSupplement persistedDevelPkgSupplement = persistedDevelPkg.getPkgSupplement();
Assertions.assertThat(persistedDevelPkgSupplement.getPkgIcons().size()).isEqualTo(1);
Assertions.assertThat(persistedDevelPkgSupplement.getPkgIcons().get(0).getSize()).isEqualTo(32);
PkgLocalization pkgLocalization = persistedDevelPkgSupplement.getPkgLocalization(NaturalLanguage.CODE_GERMAN).get();
Assertions.assertThat(pkgLocalization.getTitle()).isEqualTo("title_kingston_black");
Assertions.assertThat(pkgLocalization.getSummary()).isEqualTo("summary_kingston_black");
Assertions.assertThat(pkgLocalization.getDescription()).isEqualTo("description_kingston_black");
}
}
Aggregations