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