use of com.liferay.imex.core.service.exporter.model.ExporterProcessIdentifierGenerator in project liferay-imex by jpdacunha.
the class ImexExportServiceImpl method doExport.
@Override
public String doExport(List<String> bundleNames, String profileId, boolean debug) {
// Generate an unique identifier for this export process
ProcessIdentifierGenerator identifier = new ExporterProcessIdentifierGenerator();
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 export process for [" + bundleNames.toString() + "]");
} else {
reportService.getStartMessage(_log, "ALL export process");
}
try {
if (debug) {
reportService.getMessage(_log, "Running DEBUG mode ...");
}
Map<String, ServiceReference<Exporter>> exporters = trackerService.getFilteredExporters(bundleNames);
if (exporters == null || exporters.size() == 0) {
reportService.getMessage(_log, "There is no exporters 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.getExporters(), _log);
} else {
// Reading configuration
ImexProperties coreConfig = new ImexProperties();
configurationService.loadCoreConfiguration(coreConfig);
reportService.displayConfigurationLoadingInformation(coreConfig, _log);
// Archive actual files before importing
imexArchiverService.archiveDataDirectory(coreConfig.getProperties(), identifier);
File exportDir = initializeExportDirectory();
reportService.getPropertyMessage(_log, "IMEX export path", exportDir.toString());
List<Company> companies = companyLocalService.getCompanies();
// For each Liferay company
for (Company company : companies) {
reportService.getStartMessage(_log, company);
long companyId = company.getCompanyId();
String companyName = company.getName();
File companyDir = initializeCompanyExportDirectory(exportDir, company);
executeRegisteredExporters(exporters, companyDir, companyId, companyName, profileId, debug);
}
reportService.getSeparator(_log);
// Executing raw export
executeRawExport((ExporterProcessIdentifierGenerator) identifier, debug);
}
} catch (Exception e) {
reportService.getError(_log, "doExport", e);
}
reportService.getEndMessage(_log, "export process");
} else {
reportService.getMessage(_log, "##");
reportService.getMessage(_log, "## " + ImexCoreService.LOCKED_MESSAGE);
reportService.getMessage(_log, "##");
}
} finally {
imexCoreService.releaseLock();
}
return identifierStr;
}
use of com.liferay.imex.core.service.exporter.model.ExporterProcessIdentifierGenerator in project liferay-imex by jpdacunha.
the class ImexExportServiceImpl method executeRawExport.
private void executeRawExport(ExporterProcessIdentifierGenerator rootIdentifier, boolean debug) throws ImexException, IOException {
ImexProperties config = new ImexProperties();
configurationService.loadCoreConfiguration(config);
Properties coreConfigAsProperties = config.getProperties();
boolean rawExportEnabled = GetterUtil.getBoolean(coreConfigAsProperties.get(ImExCorePropsKeys.RAW_CONTENT_EXPORTER_ENABLED));
if (rawExportEnabled) {
ProcessIdentifierGenerator identifier = new RawExporterProcessIdentifierGeneratorWrapper(rootIdentifier);
String randomAlphanumeric = RandomStringUtils.randomAlphanumeric(4);
File tempDir = Files.createTempDirectory(randomAlphanumeric).toFile();
if (!tempDir.exists()) {
throw new ImexException("Failed to create directory " + tempDir);
}
File exportDir = initializeRawExportDirectory();
reportService.getStartMessage(_log, "Raw export process (human readable format)", 1);
// Since this a synchronized list
synchronized (rawExportContentList) {
for (ExporterRawContent content : rawExportContentList) {
writeRawContentInDir(tempDir, content, debug);
}
}
imexArchiverService.archiveAndClean(coreConfigAsProperties, tempDir, exportDir, identifier);
FileUtil.deltree(tempDir);
rawExportContentList.clear();
reportService.getEndMessage(_log, "Raw export process", 1);
} else {
if (rawExportContentList.size() > 0) {
reportService.getDisabled(_log, "raw content export");
reportService.getMessage(_log, "See [" + ImExCorePropsKeys.RAW_CONTENT_EXPORTER_ENABLED + "] to enable this feature", 4);
}
}
}
Aggregations