Search in sources :

Example 1 with Exporter

use of com.liferay.imex.core.api.exporter.Exporter in project liferay-imex by jpdacunha.

the class ImexExportServiceImpl method executeRegisteredExporters.

private void executeRegisteredExporters(Map<String, ServiceReference<Exporter>> exporters, 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;
    }
    for (Map.Entry<String, ServiceReference<Exporter>> entry : exporters.entrySet()) {
        ServiceReference<Exporter> reference = entry.getValue();
        Bundle bundle = reference.getBundle();
        Exporter exporter = bundle.getBundleContext().getService(reference);
        reportService.getStartMessage(_log, exporter.getProcessDescription(), 1);
        // Loading configuration for each exporter
        ImexProperties config = new ImexProperties();
        configurationService.loadExporterAndCoreConfiguration(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);
        }
        // Manage Root directory
        String exporterRootDirName = exporter.getRootDirectoryName();
        File exporterRootDir = new File(companyDir, exporterRootDirName);
        boolean success = exporterRootDir.mkdirs();
        if (!success) {
            throw new ImexException("Failed to create directory " + exporterRootDir);
        }
        File destDir = exporterRootDir;
        // Manage Profile
        String profileDirName = getValidProfile(profileId, bundle, exporter, configAsProperties);
        if (Validator.isNotNull(profileDirName)) {
            File profileDir = new File(exporterRootDir, profileDirName);
            success = profileDir.mkdirs();
            if (!success) {
                throw new ImexException("Failed to create directory " + profileDir);
            }
            destDir = profileDir;
        } else {
            _log.debug("Exporter [" + bundle.getSymbolicName() + "] is not configured to use profiles");
        }
        try {
            Company company = companyLocalService.getCompany(companyId);
            // Trigger Exporter specific code
            exporter.doExport(user, configAsProperties, destDir, companyId, company.getLocale(), this.rawExportContentList, debug);
        } catch (PortalException e) {
            _log.error(e, e);
        }
        reportService.getEndMessage(_log, exporter.getProcessDescription(), 1);
    }
}
Also used : Company(com.liferay.portal.kernel.model.Company) User(com.liferay.portal.kernel.model.User) Bundle(org.osgi.framework.Bundle) Exporter(com.liferay.imex.core.api.exporter.Exporter) ImexProperties(com.liferay.imex.core.api.configuration.model.ImexProperties) Properties(java.util.Properties) ServiceReference(org.osgi.framework.ServiceReference) ImexException(com.liferay.imex.core.util.exception.ImexException) ImexProperties(com.liferay.imex.core.api.configuration.model.ImexProperties) PortalException(com.liferay.portal.kernel.exception.PortalException) Map(java.util.Map) File(java.io.File)

Example 2 with Exporter

use of com.liferay.imex.core.api.exporter.Exporter in project liferay-imex by jpdacunha.

the class ListExporterCommand method le.

public void le() {
    Map<String, ServiceReference<Exporter>> exporters = trackerService.getExporters();
    if (exporters != null && exporters.size() > 0) {
        TableBuilder tableBuilder = new TableBuilder();
        tableBuilder.addHeaders(COLUMN_NAMES);
        for (Map.Entry<String, ServiceReference<Exporter>> entry : exporters.entrySet()) {
            ServiceReference<Exporter> 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();
            Exporter exporter = bundle.getBundleContext().getService(serviceReference);
            boolean supportProfile = exporter.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) Exporter(com.liferay.imex.core.api.exporter.Exporter) Map(java.util.Map) ServiceReference(org.osgi.framework.ServiceReference)

Example 3 with Exporter

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

use of com.liferay.imex.core.api.exporter.Exporter in project liferay-imex by jpdacunha.

the class ExporterTrackerService method addingService.

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

Example 5 with Exporter

use of com.liferay.imex.core.api.exporter.Exporter in project liferay-imex by jpdacunha.

the class ExportersResourceImpl method getExportersPage.

@Override
public Page<ExporterDescriptor> getExportersPage() throws Exception {
    List<ExporterDescriptor> descriptors = new ArrayList<>();
    Map<String, ServiceReference<Exporter>> exporters = trackerService.getExporters();
    if (exporters != null && exporters.size() > 0) {
        for (Map.Entry<String, ServiceReference<Exporter>> entry : exporters.entrySet()) {
            ServiceReference<Exporter> serviceReference = entry.getValue();
            Bundle bundle = serviceReference.getBundle();
            Exporter exporter = 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 = exporter.isProfiled();
            ExporterDescriptor descriptor = new ExporterDescriptor();
            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();
            String[] supportedProfilesIds = CollectionUtil.getArray(configAsProperties.getProperty(ImExCorePropsKeys.MANAGES_PROFILES_LIST));
            descriptor.setSupportedProfilesIds(supportedProfilesIds);
            descriptors.add(descriptor);
            Collections.sort(descriptors, new ExporterDescriptorNameComparator());
        }
    } else {
        _log.debug("No registered exporters");
    }
    return Page.of(descriptors);
}
Also used : Bundle(org.osgi.framework.Bundle) ExporterDescriptorNameComparator(com.liferay.imex.rest.trigger.api.comparator.ExporterDescriptorNameComparator) ArrayList(java.util.ArrayList) Exporter(com.liferay.imex.core.api.exporter.Exporter) 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) ExporterDescriptor(com.liferay.imex.rest.trigger.api.dto.v1_0.ExporterDescriptor) Map(java.util.Map)

Aggregations

Exporter (com.liferay.imex.core.api.exporter.Exporter)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 ProcessIdentifierGenerator (com.liferay.imex.core.api.identifier.ProcessIdentifierGenerator)1 Importer (com.liferay.imex.core.api.importer.Importer)1 Trigger (com.liferay.imex.core.api.trigger.Trigger)1 ConfigurationOverrideProcessIdentifier (com.liferay.imex.core.service.configuration.model.ConfigurationOverrideProcessIdentifier)1 ImexException (com.liferay.imex.core.util.exception.ImexException)1 ExporterDescriptorNameComparator (com.liferay.imex.rest.trigger.api.comparator.ExporterDescriptorNameComparator)1 ExporterDescriptor (com.liferay.imex.rest.trigger.api.dto.v1_0.ExporterDescriptor)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 File (java.io.File)1 ArrayList (java.util.ArrayList)1