Search in sources :

Example 1 with PkgLocalization

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;
}
Also used : PkgLocalization(org.haiku.haikudepotserver.dataobjects.PkgLocalization) org.haiku.haikudepotserver.api1.model.pkg(org.haiku.haikudepotserver.api1.model.pkg) org.haiku.haikudepotserver.pkg.model(org.haiku.haikudepotserver.pkg.model) ObjectContext(org.apache.cayenne.ObjectContext)

Example 2 with PkgLocalization

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");
    }
}
Also used : PkgLocalization(org.haiku.haikudepotserver.dataobjects.PkgLocalization) ObjectId(org.apache.cayenne.ObjectId) InputStream(java.io.InputStream) Pkg(org.haiku.pkg.model.Pkg) PkgSupplement(org.haiku.haikudepotserver.dataobjects.PkgSupplement) RepositorySource(org.haiku.haikudepotserver.dataobjects.RepositorySource) PkgVersion(org.haiku.pkg.model.PkgVersion) ObjectContext(org.apache.cayenne.ObjectContext) AbstractIntegrationTest(org.haiku.haikudepotserver.AbstractIntegrationTest) Test(org.junit.jupiter.api.Test)

Aggregations

ObjectContext (org.apache.cayenne.ObjectContext)2 PkgLocalization (org.haiku.haikudepotserver.dataobjects.PkgLocalization)2 InputStream (java.io.InputStream)1 ObjectId (org.apache.cayenne.ObjectId)1 AbstractIntegrationTest (org.haiku.haikudepotserver.AbstractIntegrationTest)1 org.haiku.haikudepotserver.api1.model.pkg (org.haiku.haikudepotserver.api1.model.pkg)1 PkgSupplement (org.haiku.haikudepotserver.dataobjects.PkgSupplement)1 RepositorySource (org.haiku.haikudepotserver.dataobjects.RepositorySource)1 org.haiku.haikudepotserver.pkg.model (org.haiku.haikudepotserver.pkg.model)1 Pkg (org.haiku.pkg.model.Pkg)1 PkgVersion (org.haiku.pkg.model.PkgVersion)1 Test (org.junit.jupiter.api.Test)1