Search in sources :

Example 1 with Importer

use of com.liferay.imex.core.api.importer.Importer 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 2 with Importer

use of com.liferay.imex.core.api.importer.Importer in project liferay-imex by jpdacunha.

the class ImporterTrackerService method addingService.

@Override
public Importer addingService(ServiceReference<Importer> serviceReference) {
    _serviceReferences.addServiceReference(serviceReference);
    Importer importer = _bundleContext.getService(serviceReference);
    // Calling deploy method on custom service
    importer.deploy();
    return importer;
}
Also used : Importer(com.liferay.imex.core.api.importer.Importer)

Example 3 with Importer

use of com.liferay.imex.core.api.importer.Importer 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 4 with Importer

use of com.liferay.imex.core.api.importer.Importer 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)

Example 5 with Importer

use of com.liferay.imex.core.api.importer.Importer in project liferay-imex by jpdacunha.

the class ListImporterCommand method li.

public void li() {
    Map<String, ServiceReference<Importer>> importers = trackerService.getImporters();
    if (importers != null && importers.size() > 0) {
        TableBuilder tableBuilder = new TableBuilder();
        tableBuilder.addHeaders(COLUMN_NAMES);
        for (Map.Entry<String, ServiceReference<Importer>> entry : importers.entrySet()) {
            ServiceReference<Importer> serviceReference = entry.getValue();
            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);
            Bundle bundle = serviceReference.getBundle();
            Importer importer = bundle.getBundleContext().getService(serviceReference);
            boolean supportProfile = importer.isProfiled();
            if (bundle != null) {
                tableBuilder.addRow(ranking, bundle.getSymbolicName(), description, priority, supportProfile + "");
            }
        }
        tableBuilder.print();
    } else {
        System.out.println("No IMEX importers registered.");
    }
}
Also used : Bundle(org.osgi.framework.Bundle) TableBuilder(com.liferay.imex.shell.client.util.TableBuilder) Map(java.util.Map) ServiceReference(org.osgi.framework.ServiceReference) Importer(com.liferay.imex.core.api.importer.Importer)

Aggregations

Importer (com.liferay.imex.core.api.importer.Importer)5 Map (java.util.Map)4 Bundle (org.osgi.framework.Bundle)4 ServiceReference (org.osgi.framework.ServiceReference)4 ImexProperties (com.liferay.imex.core.api.configuration.model.ImexProperties)3 Properties (java.util.Properties)3 OrderedProperties (com.liferay.imex.core.api.configuration.model.OrderedProperties)1 Exporter (com.liferay.imex.core.api.exporter.Exporter)1 ProcessIdentifierGenerator (com.liferay.imex.core.api.identifier.ProcessIdentifierGenerator)1 Trigger (com.liferay.imex.core.api.trigger.Trigger)1 ConfigurationOverrideProcessIdentifier (com.liferay.imex.core.service.configuration.model.ConfigurationOverrideProcessIdentifier)1 ImporterDescriptorNameComparator (com.liferay.imex.rest.trigger.api.comparator.ImporterDescriptorNameComparator)1 ImporterDescriptor (com.liferay.imex.rest.trigger.api.dto.v1_0.ImporterDescriptor)1 TableBuilder (com.liferay.imex.shell.client.util.TableBuilder)1 PortalException (com.liferay.portal.kernel.exception.PortalException)1 Company (com.liferay.portal.kernel.model.Company)1 User (com.liferay.portal.kernel.model.User)1 ServiceContext (com.liferay.portal.kernel.service.ServiceContext)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1