Search in sources :

Example 1 with ImporterProcessIdentifier

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;
}
Also used : Company(com.liferay.portal.kernel.model.Company) ProcessIdentifierGenerator(com.liferay.imex.core.api.identifier.ProcessIdentifierGenerator) ImexProperties(com.liferay.imex.core.api.configuration.model.ImexProperties) File(java.io.File) ImporterProcessIdentifier(com.liferay.imex.core.service.importer.model.ImporterProcessIdentifier) ImexException(com.liferay.imex.core.util.exception.ImexException) PortalException(com.liferay.portal.kernel.exception.PortalException) IOException(java.io.IOException) ServiceReference(org.osgi.framework.ServiceReference)

Aggregations

ImexProperties (com.liferay.imex.core.api.configuration.model.ImexProperties)1 ProcessIdentifierGenerator (com.liferay.imex.core.api.identifier.ProcessIdentifierGenerator)1 ImporterProcessIdentifier (com.liferay.imex.core.service.importer.model.ImporterProcessIdentifier)1 ImexException (com.liferay.imex.core.util.exception.ImexException)1 PortalException (com.liferay.portal.kernel.exception.PortalException)1 Company (com.liferay.portal.kernel.model.Company)1 File (java.io.File)1 IOException (java.io.IOException)1 ServiceReference (org.osgi.framework.ServiceReference)1