Search in sources :

Example 6 with ImexProperties

use of com.liferay.imex.core.api.configuration.model.ImexProperties in project liferay-imex by jpdacunha.

the class ImexImportServiceImpl method executeRegisteredImporters.

private void executeRegisteredImporters(Map<String, ServiceReference<Importer>> importers, File companyDir, long companyId, String companyName, String profileId, boolean debug) throws ImexException {
    User user = UserUtil.getDefaultAdmin(companyId);
    if (user == null) {
        reportService.getError(_log, "Company [" + companyName + "]", "Missing omni admin user");
        return;
    }
    reportService.getStartMessage(_log, "company : [" + companyName + "] import process");
    reportService.getMessage(_log, "Using user [" + user.getEmailAddress() + "] as default user");
    for (Map.Entry<String, ServiceReference<Importer>> entry : importers.entrySet()) {
        ServiceReference<Importer> reference = entry.getValue();
        Bundle bundle = reference.getBundle();
        Importer importer = bundle.getBundleContext().getService(reference);
        reportService.getStartMessage(_log, importer.getProcessDescription(), 1);
        // Loading configuration for each Importer
        ImexProperties config = new ImexProperties();
        configurationService.loadImporterAndCoreConfiguration(bundle, config);
        reportService.displayConfigurationLoadingInformation(config, _log, bundle);
        Properties configAsProperties = config.getProperties();
        if (configAsProperties == null || configAsProperties.size() == 0) {
            reportService.getMessage(_log, bundle, "has no defined configuration.");
        } else {
            reportService.displayProperties(configAsProperties, bundle, _log);
        }
        try {
            // Manage Root directory
            File destDir = getRootDirectory(companyDir, importer);
            if (destDir != null) {
                // Manage Profile
                String profileDirName = getValidProfile(profileId, bundle, importer, configAsProperties);
                if (Validator.isNotNull(profileDirName)) {
                    File profileDir = new File(destDir, profileDirName);
                    destDir = profileDir;
                } else {
                    _log.debug("Importer [" + bundle.getSymbolicName() + "] is not configured to use profiles");
                }
                Company company = companyLocalService.getCompany(companyId);
                ServiceContext serviceContext = new ServiceContext();
                serviceContext.setCompanyId(companyId);
                serviceContext.setPathMain(PortalUtil.getPathMain());
                serviceContext.setUserId(user.getUserId());
                if (user != null) {
                    serviceContext.setSignedIn(!user.isDefaultUser());
                }
                // Managing locale
                Locale locale = company.getLocale();
                // This is a workaround because Liferay is not able to manage default locale correctly in batch mode
                LocaleThreadLocal.setDefaultLocale(locale);
                if (locale == null) {
                    reportService.getError(_log, IMEX_IMPORT_SERVICE_ERROR, "company default locale is null");
                } else {
                    reportService.getMessage(_log, "Using [" + locale + "] as default locale");
                }
                importer.doImport(bundle, serviceContext, user, configAsProperties, destDir, companyId, locale, debug);
            } else {
                reportService.getSkipped(_log, "[" + bundle.getSymbolicName() + "]");
            }
        } catch (PortalException e) {
            _log.error(e, e);
        }
        reportService.getEndMessage(_log, importer.getProcessDescription(), 1);
    }
    reportService.getEndMessage(_log, "[" + companyName + "] import process");
}
Also used : Locale(java.util.Locale) Company(com.liferay.portal.kernel.model.Company) User(com.liferay.portal.kernel.model.User) Bundle(org.osgi.framework.Bundle) ServiceContext(com.liferay.portal.kernel.service.ServiceContext) ImexProperties(com.liferay.imex.core.api.configuration.model.ImexProperties) Properties(java.util.Properties) ServiceReference(org.osgi.framework.ServiceReference) ImexProperties(com.liferay.imex.core.api.configuration.model.ImexProperties) PortalException(com.liferay.portal.kernel.exception.PortalException) Map(java.util.Map) File(java.io.File) Importer(com.liferay.imex.core.api.importer.Importer)

Example 7 with ImexProperties

use of com.liferay.imex.core.api.configuration.model.ImexProperties in project liferay-imex by jpdacunha.

the class ImexExecutionReportServiceImpl method initializeLogger.

private void initializeLogger(String logsPath) {
    if (configurator == null) {
        _log.debug("Initializing logger ...");
        configurator = Configurator.defaultConfig();
        configurator.level(Level.DEBUG);
        configurator.formatPattern("{date:yyyy-MM-dd HH:mm:ss} {level} [{thread}] [{context:" + ImexExecutionReportService.IDENTIFIER_KEY + "}] : {message}");
        if (_log.isDebugEnabled()) {
            _log.debug("IMEX output log path : " + logsPath);
        }
        RollingFileWriter writer = new RollingFileWriter(logsPath + "/" + LOG_FILE_NAME, 3, new TimestampLabeler("yyyy-MM-dd"), new DailyPolicy());
        configurator.addWriter(writer);
        configurator.activate();
        _log.debug("Done.");
    }
    if (this.displayInLiferayLogs == null) {
        ImexProperties coreConfig = new ImexProperties();
        configurationService.loadCoreConfiguration(coreConfig);
        this.displayInLiferayLogs = GetterUtil.getBoolean(coreConfig.getProperties().get(ImExCorePropsKeys.DISPLAY_EXECUTION_IN_LIFERAY_LOGS));
    }
}
Also used : TimestampLabeler(org.pmw.tinylog.labelers.TimestampLabeler) DailyPolicy(org.pmw.tinylog.policies.DailyPolicy) ImexProperties(com.liferay.imex.core.api.configuration.model.ImexProperties) RollingFileWriter(org.pmw.tinylog.writers.RollingFileWriter)

Example 8 with ImexProperties

use of com.liferay.imex.core.api.configuration.model.ImexProperties in project liferay-imex by jpdacunha.

the class FilesystemTriggerListener method activate.

@Modified
@Activate
protected void activate(Map<String, Object> properties) {
    _log.info("Registering scheduler entry for [" + this.getClass().getSimpleName() + "] ...");
    Class<?> clazz = getClass();
    String className = clazz.getName();
    ImexProperties imexProperties = new ImexProperties();
    configurationService.loadTriggerAndCoreConfiguration(this.getClass(), imexProperties);
    Properties rawProps = imexProperties.getProperties();
    String cronExpression = GetterUtil.getString(rawProps.get(ImExFileSystemTriggerPropsKeys.TRIGGER_CHECK_PERIOD_CONR));
    if (Validator.isNotNull(cronExpression)) {
        Trigger trigger = _triggerFactory.createTrigger(className, className, new Date(), null, cronExpression);
        SchedulerEntry schedulerEntry = new SchedulerEntryImpl(className, trigger);
        _schedulerEngineHelper.register(this, schedulerEntry, DestinationNames.SCHEDULER_DISPATCH);
    } else {
        _log.error("Unable to start job : no cron expression is properly configured");
    }
    _log.info("Done.");
}
Also used : Trigger(com.liferay.portal.kernel.scheduler.Trigger) SchedulerEntryImpl(com.liferay.portal.kernel.scheduler.SchedulerEntryImpl) SchedulerEntry(com.liferay.portal.kernel.scheduler.SchedulerEntry) ImexProperties(com.liferay.imex.core.api.configuration.model.ImexProperties) ImexProperties(com.liferay.imex.core.api.configuration.model.ImexProperties) Properties(java.util.Properties) Date(java.util.Date) Modified(org.osgi.service.component.annotations.Modified) Activate(org.osgi.service.component.annotations.Activate)

Example 9 with ImexProperties

use of com.liferay.imex.core.api.configuration.model.ImexProperties in project liferay-imex by jpdacunha.

the class ImportersResourceImpl method getImportersPage.

@Override
public Page<ImporterDescriptor> getImportersPage() throws Exception {
    List<ImporterDescriptor> descriptors = new ArrayList<>();
    Map<String, ServiceReference<Importer>> importers = trackerService.getImporters();
    if (importers != null && importers.size() > 0) {
        for (Map.Entry<String, ServiceReference<Importer>> entry : importers.entrySet()) {
            ServiceReference<Importer> serviceReference = entry.getValue();
            Bundle bundle = serviceReference.getBundle();
            Importer importer = bundle.getBundleContext().getService(serviceReference);
            String ranking = (Integer) serviceReference.getProperty(OSGIServicePropsKeys.SERVICE_RANKING) + "";
            String description = (String) serviceReference.getProperty(OSGIServicePropsKeys.IMEX_COMPONENT_DESCRIPTION);
            String priority = (String) serviceReference.getProperty(OSGIServicePropsKeys.IMEX_COMPONENT_EXECUTION_PRIORITY);
            String name = bundle.getSymbolicName();
            boolean profiled = importer.isProfiled();
            ImporterDescriptor descriptor = new ImporterDescriptor();
            descriptor.setDescription(description);
            descriptor.setName(name);
            descriptor.setPriority(Integer.valueOf(priority));
            descriptor.setProfiled(profiled);
            descriptor.setRanking(ranking);
            ImexProperties config = new ImexProperties();
            configurationService.loadCoreConfiguration(config);
            Properties configAsProperties = config.getProperties();
            if (profiled) {
                String[] supportedProfilesIds = CollectionUtil.getArray(configAsProperties.getProperty(ImExCorePropsKeys.MANAGES_PROFILES_LIST));
                descriptor.setSupportedProfilesIds(supportedProfilesIds);
            }
            descriptors.add(descriptor);
            Collections.sort(descriptors, new ImporterDescriptorNameComparator());
        }
    } else {
        _log.debug("No registered importers");
    }
    return Page.of(descriptors);
}
Also used : Bundle(org.osgi.framework.Bundle) ArrayList(java.util.ArrayList) ImporterDescriptor(com.liferay.imex.rest.trigger.api.dto.v1_0.ImporterDescriptor) ImexProperties(com.liferay.imex.core.api.configuration.model.ImexProperties) Properties(java.util.Properties) ServiceReference(org.osgi.framework.ServiceReference) ImporterDescriptorNameComparator(com.liferay.imex.rest.trigger.api.comparator.ImporterDescriptorNameComparator) ImexProperties(com.liferay.imex.core.api.configuration.model.ImexProperties) Map(java.util.Map) Importer(com.liferay.imex.core.api.importer.Importer)

Example 10 with ImexProperties

use of com.liferay.imex.core.api.configuration.model.ImexProperties in project liferay-imex by jpdacunha.

the class ImexCoreServiceImpl method generateOverrideFileSystemConfigurationFiles.

@Override
public String generateOverrideFileSystemConfigurationFiles(List<String> bundleNames, boolean archive) {
    Map<String, ServiceReference<Importer>> importers = importerTrackerService.getFilteredImporters(bundleNames);
    Map<String, ServiceReference<Exporter>> exporters = exporterTrackerService.getFilteredExporters(bundleNames);
    Map<String, ServiceReference<Trigger>> triggers = triggerTrackerService.getTriggers();
    Map<String, Properties> props = configurationService.loadAllConfigurationMap(bundleNames, importers, exporters, triggers);
    ProcessIdentifierGenerator processIdentifier = new ConfigurationOverrideProcessIdentifier();
    String identifier = processIdentifier.getOrGenerateUniqueIdentifier();
    LoggingContext.put(ImexExecutionReportService.IDENTIFIER_KEY, identifier);
    reportService.getStartMessage(_log, "CFG_OVERRIDE process");
    // Initialisation répertoire de configuration
    initializeConfigurationtDirectories();
    if (props != null) {
        if (archive) {
            ImexProperties coreConfig = new ImexProperties();
            configurationService.loadCoreConfiguration(coreConfig);
            imexArchiverService.archiveCfgDirectory(coreConfig.getProperties(), processIdentifier);
        }
        Bundle coreBundle = FrameworkUtil.getBundle(this.getClass());
        String coreBundleName = coreBundle.getSymbolicName();
        mergeConfiguration(props, coreBundleName, coreBundle);
        // Merging importers
        for (Map.Entry<String, ServiceReference<Importer>> entry : importers.entrySet()) {
            ServiceReference<Importer> reference = entry.getValue();
            Bundle bundle = reference.getBundle();
            String key = entry.getKey();
            mergeConfiguration(props, key, bundle);
        }
        // Merging exporters
        for (Map.Entry<String, ServiceReference<Exporter>> entry : exporters.entrySet()) {
            ServiceReference<Exporter> reference = entry.getValue();
            Bundle bundle = reference.getBundle();
            String key = entry.getKey();
            mergeConfiguration(props, key, bundle);
        }
        // Merging triggers
        for (Map.Entry<String, ServiceReference<Trigger>> entry : triggers.entrySet()) {
            ServiceReference<Trigger> reference = entry.getValue();
            Bundle bundle = reference.getBundle();
            String key = entry.getKey();
            mergeConfiguration(props, key, bundle);
        }
    }
    reportService.getEndMessage(_log, "CFG_OVERRIDE process");
    return identifier;
}
Also used : Bundle(org.osgi.framework.Bundle) ImexProperties(com.liferay.imex.core.api.configuration.model.ImexProperties) Properties(java.util.Properties) OrderedProperties(com.liferay.imex.core.api.configuration.model.OrderedProperties) ConfigurationOverrideProcessIdentifier(com.liferay.imex.core.service.configuration.model.ConfigurationOverrideProcessIdentifier) Exporter(com.liferay.imex.core.api.exporter.Exporter) ServiceReference(org.osgi.framework.ServiceReference) ProcessIdentifierGenerator(com.liferay.imex.core.api.identifier.ProcessIdentifierGenerator) Trigger(com.liferay.imex.core.api.trigger.Trigger) ImexProperties(com.liferay.imex.core.api.configuration.model.ImexProperties) Map(java.util.Map) Importer(com.liferay.imex.core.api.importer.Importer)

Aggregations

ImexProperties (com.liferay.imex.core.api.configuration.model.ImexProperties)14 Properties (java.util.Properties)11 ServiceReference (org.osgi.framework.ServiceReference)8 Bundle (org.osgi.framework.Bundle)7 File (java.io.File)6 Map (java.util.Map)6 ProcessIdentifierGenerator (com.liferay.imex.core.api.identifier.ProcessIdentifierGenerator)4 ImexException (com.liferay.imex.core.util.exception.ImexException)4 PortalException (com.liferay.portal.kernel.exception.PortalException)4 Company (com.liferay.portal.kernel.model.Company)4 Exporter (com.liferay.imex.core.api.exporter.Exporter)3 Importer (com.liferay.imex.core.api.importer.Importer)3 OrderedProperties (com.liferay.imex.core.api.configuration.model.OrderedProperties)2 ExporterProcessIdentifierGenerator (com.liferay.imex.core.service.exporter.model.ExporterProcessIdentifierGenerator)2 User (com.liferay.portal.kernel.model.User)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 ExporterRawContent (com.liferay.imex.core.api.exporter.model.ExporterRawContent)1 Trigger (com.liferay.imex.core.api.trigger.Trigger)1