use of com.liferay.imex.core.service.importer.model.ImporterProcessIdentifier in project liferay-imex by jpdacunha.
the class ImexImportServiceImpl method doImport.
@Override
public String doImport(List<String> bundleNames, String profileId, boolean debug) {
// Generate an unique identifier for this import process
ProcessIdentifierGenerator identifier = new ImporterProcessIdentifier();
String identifierStr = identifier.getOrGenerateUniqueIdentifier();
LoggingContext.put(ImexExecutionReportService.IDENTIFIER_KEY, identifierStr);
try {
if (imexCoreService.tryLock()) {
reportService.getSeparator(_log);
if (bundleNames != null && bundleNames.size() > 0) {
reportService.getStartMessage(_log, "PARTIAL import process for [" + bundleNames.toString() + "]");
} else {
reportService.getStartMessage(_log, "ALL import process");
}
try {
if (debug) {
reportService.getMessage(_log, "Running DEBUG mode ...");
}
Map<String, ServiceReference<Importer>> importers = trackerService.getFilteredImporters(bundleNames);
if (importers == null || importers.size() == 0) {
reportService.getMessage(_log, "There is no importers to execute. Please check : ");
reportService.getMessage(_log, "- All importers are correctly registered in OSGI container");
if (bundleNames != null) {
reportService.getMessage(_log, "- A registered bundle exists for each typed name [" + bundleNames + "]");
}
reportService.printKeys(trackerService.getImporters(), _log);
} else {
// Archive actual files before importing
ImexProperties coreConfig = new ImexProperties();
configurationService.loadCoreConfiguration(coreConfig);
reportService.displayConfigurationLoadingInformation(coreConfig, _log);
imexArchiverService.archiveDataDirectory(coreConfig.getProperties(), identifier);
File importDir = getImportDirectory();
reportService.getPropertyMessage(_log, "IMEX import path", importDir.toString());
List<Company> companies = companyLocalService.getCompanies();
// For each Liferay company
for (Company company : companies) {
long companyId = company.getCompanyId();
String companyName = company.getName();
File companyDir = getCompanyImportDirectory(importDir, company);
if (companyDir != null) {
executeRegisteredImporters(importers, companyDir, companyId, companyName, profileId, debug);
}
}
}
} catch (Exception e) {
reportService.getError(_log, "doImport", e);
}
reportService.getEndMessage(_log, "import process");
} else {
reportService.getMessage(_log, "##");
reportService.getMessage(_log, "## " + ImexCoreService.LOCKED_MESSAGE);
reportService.getMessage(_log, "##");
}
} finally {
imexCoreService.releaseLock();
}
return identifierStr;
}
Aggregations