Search in sources :

Example 1 with BundleApplicationsService

use of de.alpharogroup.db.resource.bundles.service.api.BundleApplicationsService in project bundle-app-ui by astrapi69.

the class ApplicationDashboardContentPanel method onChooseImportResourceBundle.

/**
 * Callback method which import resourcebundles from a folder of file.
 *
 * @param dir the dir
 */
protected void onChooseImportResourceBundle(final boolean dir) {
    final int returnVal = fileChooser.showOpenDialog(ApplicationDashboardContentPanel.this);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        final File resourceBundleToImport = fileChooser.getSelectedFile();
        getModelObject().setResourceBundleToImport(resourceBundleToImport);
        try {
            if (dir) {
                ApplicationDashboardBean mo = getModelObject();
                BundleApplications bundleApplications = SpringApplicationContext.getInstance().getBundleApplicationsService().get(mo.getBundleApplication().getId());
                final Locale defaultLocale = SpringApplicationContext.getInstance().getLanguageLocalesService().resolveLocale(bundleApplications.getDefaultLocale());
                final PropertiesListResolver resolver1 = new PropertiesListResolver(resourceBundleToImport, defaultLocale);
                resolver1.resolve();
                final List<KeyValuePair<File, Locale>> propertiesList = resolver1.getPropertiesList();
                getModelObject().setFoundProperties(ConvertExtensions.convertAndSort(propertiesList));
                // 1. create bundleapp
                final BundleApplicationsService bundleApplicationsService = SpringApplicationContext.getInstance().getBundleApplicationsService();
                final ResourcebundlesService resourcebundlesService = SpringApplicationContext.getInstance().getResourcebundlesService();
                BundleApplications bundleApplication = getModelObject().getBundleApplication();
                // 2. get properties files
                final List<Triple<File, Locale, KeyValuePair<Boolean, File>>> foundProperties = getModelObject().getFoundProperties();
                // 3. save properties files the to the bundleapp
                final Set<BundleNames> set = SetExtensions.newHashSet();
                for (final Triple<File, Locale, KeyValuePair<Boolean, File>> entry : foundProperties) {
                    if (BooleanUtils.toBoolean(entry.getRight().getKey())) {
                        final File propertiesFile = entry.getLeft();
                        final Locale locale = entry.getMiddle();
                        final String bundlename = LocaleResolver.resolveBundlename(propertiesFile);
                        Properties properties = null;
                        try {
                            properties = PropertiesExtensions.loadProperties(propertiesFile);
                        } catch (final IOException e) {
                            log.error(e.getLocalizedMessage(), e);
                        }
                        final BundleNames bundleNames = resourcebundlesService.updateProperties(bundleApplication, properties, bundlename, locale);
                        set.add(bundleNames);
                    }
                }
                bundleApplication = bundleApplicationsService.merge(bundleApplication);
            } else {
                final Properties importedProperties = PropertiesExtensions.loadProperties(resourceBundleToImport);
                getModelObject().setImportedProperties(importedProperties);
                final List<KeyValuePair<String, String>> keyValuePairs = PropertiesExtensions.toKeyValuePairs(importedProperties);
                Collections.sort(keyValuePairs, NullCheckComparator.<KeyValuePair<String, String>>of(new KeyValuePairKeyComparator<>()));
                getModelObject().setImportedKeyValuePairs(keyValuePairs);
                MainApplication.get().getApplicationEventBus().post(ApplicationDashboardContentPanel.this.getModelObject());
                getCardLayout().show(this, ApplicationDashboardView.IMPORT_RB.name());
            }
        } catch (final IOException e) {
            log.error(e.getLocalizedMessage(), e);
        }
    }
}
Also used : Locale(java.util.Locale) KeyValuePair(de.alpharogroup.collections.pairs.KeyValuePair) PropertiesListResolver(de.alpharogroup.resourcebundle.inspector.search.PropertiesListResolver) BundleApplications(de.alpharogroup.db.resource.bundles.entities.BundleApplications) IOException(java.io.IOException) Properties(java.util.Properties) Triple(de.alpharogroup.collections.pairs.Triple) BundleApplicationsService(de.alpharogroup.db.resource.bundles.service.api.BundleApplicationsService) BundleNames(de.alpharogroup.db.resource.bundles.entities.BundleNames) ResourcebundlesService(de.alpharogroup.db.resource.bundles.service.api.ResourcebundlesService) KeyValuePairKeyComparator(de.alpharogroup.comparators.pairs.KeyValuePairKeyComparator) File(java.io.File)

Example 2 with BundleApplicationsService

use of de.alpharogroup.db.resource.bundles.service.api.BundleApplicationsService in project bundle-app-ui by astrapi69.

the class ImportWizardPanel method startDbImport.

private void startDbImport() {
    // 1. create bundleapp
    final BundleApplicationsService bundleApplicationsService = SpringApplicationContext.getInstance().getBundleApplicationsService();
    final ResourcebundlesService resourcebundlesService = SpringApplicationContext.getInstance().getResourcebundlesService();
    BundleApplications bundleApplication = bundleApplicationsService.find(getModelObject().getBundleAppName());
    // 2. get properties files
    final List<Triple<File, Locale, KeyValuePair<Boolean, File>>> foundProperties = getModelObject().getFoundProperties();
    // 3. save properties files the to the bundleapp
    for (final Triple<File, Locale, KeyValuePair<Boolean, File>> entry : foundProperties) {
        if (BooleanUtils.toBoolean(entry.getRight().getKey())) {
            final File propertiesFile = entry.getLeft();
            final Locale locale = entry.getMiddle();
            final String bundlename = LocaleResolver.resolveBundlename(propertiesFile);
            Properties properties = null;
            try {
                properties = PropertiesExtensions.loadProperties(propertiesFile);
            } catch (final IOException e) {
                log.error("Loading Properties file " + propertiesFile.getAbsolutePath() + " failed.", e);
            }
            resourcebundlesService.updateProperties(bundleApplication, properties, bundlename, locale);
        }
    }
}
Also used : Locale(java.util.Locale) KeyValuePair(de.alpharogroup.collections.pairs.KeyValuePair) BundleApplications(de.alpharogroup.db.resource.bundles.entities.BundleApplications) IOException(java.io.IOException) Properties(java.util.Properties) Triple(de.alpharogroup.collections.pairs.Triple) BundleApplicationsService(de.alpharogroup.db.resource.bundles.service.api.BundleApplicationsService) ResourcebundlesService(de.alpharogroup.db.resource.bundles.service.api.ResourcebundlesService) File(java.io.File)

Example 3 with BundleApplicationsService

use of de.alpharogroup.db.resource.bundles.service.api.BundleApplicationsService in project bundle-app-ui by astrapi69.

the class NewBundleApplicationPanel method onSave.

protected void onSave(final ActionEvent e) {
    final BundleApplicationsService bundleApplicationsService = (BundleApplicationsService) SpringApplicationContext.getInstance().getApplicationContext().getBean("bundleApplicationsService");
    final String name = getTxtBundleName().getText();
    BundleApplications currentBundleApplication;
    if (getModelObject().getBundleApplication() != null) {
        currentBundleApplication = getModelObject().getBundleApplication();
        currentBundleApplication.setName(name);
        Locale dl = getModelObject().getDefaultLocale();
        LanguageLocales defaultLocale = SpringApplicationContext.getInstance().getLanguageLocalesService().getOrCreateNewLanguageLocales(dl);
        if (currentBundleApplication.getDefaultLocale() != null) {
            if (!currentBundleApplication.getDefaultLocale().equals(defaultLocale)) {
                currentBundleApplication.setDefaultLocale(defaultLocale);
            }
        } else {
            currentBundleApplication.setDefaultLocale(defaultLocale);
        }
        currentBundleApplication = bundleApplicationsService.merge(currentBundleApplication);
        getModelObject().setBundleApplication(currentBundleApplication);
    } else {
        BundleApplications newBundleApplication = bundleApplicationsService.find(name);
        if (newBundleApplication == null) {
            Locale dl = getModelObject().getDefaultLocale();
            LanguageLocales defaultLocale = SpringApplicationContext.getInstance().getLanguageLocalesService().find(dl);
            newBundleApplication = BundleApplications.builder().name(name).defaultLocale(defaultLocale).build();
            newBundleApplication = bundleApplicationsService.merge(newBundleApplication);
        }
        if (!MainFrame.getInstance().getModelObject().getBundleApplications().contains(newBundleApplication)) {
            MainFrame.getInstance().getModelObject().getBundleApplications().add(newBundleApplication);
        }
        getModelObject().setBundleApplication(newBundleApplication);
    }
}
Also used : Locale(java.util.Locale) BundleApplicationsService(de.alpharogroup.db.resource.bundles.service.api.BundleApplicationsService) LanguageLocales(de.alpharogroup.db.resource.bundles.entities.LanguageLocales) BundleApplications(de.alpharogroup.db.resource.bundles.entities.BundleApplications)

Example 4 with BundleApplicationsService

use of de.alpharogroup.db.resource.bundles.service.api.BundleApplicationsService in project bundle-app-ui by astrapi69.

the class SpringApplicationContext method initDb.

protected void initDb(final ApplicationContext ac) {
    final LanguagesService languagesService = (LanguagesService) ac.getBean("languagesService");
    final LanguageLocalesService languageLocalesService = (LanguageLocalesService) ac.getBean("languageLocalesService");
    final BundleApplicationsService bundleApplicationsService = getBundleApplicationsService();
    final List<Languages> languages = DataObjectFactory.newLanguages();
    for (final Languages language : languages) {
        final Languages found = languagesService.find(language.getName(), language.getIso639Dash1());
        if (found == null) {
            languagesService.merge(language);
        }
    }
    final List<LanguageLocales> languageLocales = DataObjectFactory.newLanguageLocales();
    for (final LanguageLocales languageLocale : languageLocales) {
        final LanguageLocales found = languageLocalesService.find(languageLocale.getLocale());
        if (found == null) {
            languageLocalesService.merge(languageLocale);
        }
    }
    BundleApplications baseBundleApplication = bundleApplicationsService.find(BundleApplications.BASE_BUNDLE_APPLICATION);
    if (baseBundleApplication == null) {
        baseBundleApplication = BundleApplications.builder().name(BundleApplications.BASE_BUNDLE_APPLICATION).build();
        baseBundleApplication = bundleApplicationsService.merge(baseBundleApplication);
    }
}
Also used : BundleApplicationsService(de.alpharogroup.db.resource.bundles.service.api.BundleApplicationsService) LanguageLocales(de.alpharogroup.db.resource.bundles.entities.LanguageLocales) LanguagesService(de.alpharogroup.db.resource.bundles.service.api.LanguagesService) BundleApplications(de.alpharogroup.db.resource.bundles.entities.BundleApplications) Languages(de.alpharogroup.db.resource.bundles.entities.Languages) LanguageLocalesService(de.alpharogroup.db.resource.bundles.service.api.LanguageLocalesService)

Example 5 with BundleApplicationsService

use of de.alpharogroup.db.resource.bundles.service.api.BundleApplicationsService in project bundle-app-ui by astrapi69.

the class MainFrame method onInitializeComponents.

@Override
protected void onInitializeComponents() {
    super.onInitializeComponents();
    // create the tool bar
    toolbar = new JToolBar();
    setJMenuBar(menubar);
    setToolBar(toolbar);
    desktopPane = SingletonDesktopPane.getInstance();
    currentLookAndFeels = LookAndFeels.SYSTEM;
    getContentPane().add(desktopPane);
    try {
        final String iconPath = Messages.getString("global.icon.app.path");
        final BufferedImage appIcon = ImageIO.read(ClassExtensions.getResourceAsStream(iconPath));
        setIconImage(appIcon);
    } catch (final IOException e) {
        log.error("Icon file could not be readed.", e);
    }
    final ApplicationContext applicationContext = SpringApplicationContext.getInstance().getApplicationContext();
    final BundleApplicationsService bundleApplicationsService = (BundleApplicationsService) applicationContext.getBean("bundleApplicationsService");
    final Model<MainDashboardBean> model = BaseModel.<MainDashboardBean>of(MainDashboardBean.builder().bundleApplications(bundleApplicationsService.findAll()).build());
    setModel(model);
    final MainDashboardPanel mainDashboardPanel = new MainDashboardPanel(PropertyModel.<MainDashboardBean>of(this, "model.object"));
    replaceInternalFrame("Main dashboard", mainDashboardPanel);
}
Also used : BundleApplicationsService(de.alpharogroup.db.resource.bundles.service.api.BundleApplicationsService) SpringApplicationContext(de.alpharogroup.bundle.app.spring.SpringApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) MainDashboardPanel(de.alpharogroup.bundle.app.panels.dashboard.mainapp.MainDashboardPanel) MainDashboardBean(de.alpharogroup.bundle.app.panels.dashboard.mainapp.MainDashboardBean) JToolBar(javax.swing.JToolBar) IOException(java.io.IOException) BufferedImage(java.awt.image.BufferedImage)

Aggregations

BundleApplicationsService (de.alpharogroup.db.resource.bundles.service.api.BundleApplicationsService)5 BundleApplications (de.alpharogroup.db.resource.bundles.entities.BundleApplications)4 IOException (java.io.IOException)3 Locale (java.util.Locale)3 KeyValuePair (de.alpharogroup.collections.pairs.KeyValuePair)2 Triple (de.alpharogroup.collections.pairs.Triple)2 LanguageLocales (de.alpharogroup.db.resource.bundles.entities.LanguageLocales)2 ResourcebundlesService (de.alpharogroup.db.resource.bundles.service.api.ResourcebundlesService)2 File (java.io.File)2 Properties (java.util.Properties)2 MainDashboardBean (de.alpharogroup.bundle.app.panels.dashboard.mainapp.MainDashboardBean)1 MainDashboardPanel (de.alpharogroup.bundle.app.panels.dashboard.mainapp.MainDashboardPanel)1 SpringApplicationContext (de.alpharogroup.bundle.app.spring.SpringApplicationContext)1 KeyValuePairKeyComparator (de.alpharogroup.comparators.pairs.KeyValuePairKeyComparator)1 BundleNames (de.alpharogroup.db.resource.bundles.entities.BundleNames)1 Languages (de.alpharogroup.db.resource.bundles.entities.Languages)1 LanguageLocalesService (de.alpharogroup.db.resource.bundles.service.api.LanguageLocalesService)1 LanguagesService (de.alpharogroup.db.resource.bundles.service.api.LanguagesService)1 PropertiesListResolver (de.alpharogroup.resourcebundle.inspector.search.PropertiesListResolver)1 BufferedImage (java.awt.image.BufferedImage)1