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);
}
}
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.");
}
}
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;
}
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;
}
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);
}
Aggregations