Search in sources :

Example 1 with ImexException

use of com.liferay.imex.core.util.exception.ImexException in project liferay-imex by jpdacunha.

the class ImexCoreServiceImpl method cleanBundleFiles.

@Override
public void cleanBundleFiles(DeployDirEnum destinationDirName, String toCopyBundleDirectoryName, Bundle bundle) {
    if (bundle != null) {
        if (destinationDirName != null) {
            List<URL> urls = FileUtil.findBundleResources(bundle, toCopyBundleDirectoryName, StringPool.STAR);
            if (urls != null && urls.size() > 0) {
                String imexHomePath = configurationService.getImexPath();
                String rootPath = imexHomePath + StringPool.SLASH + destinationDirName.getDirectoryPath();
                String bundleDirectoryPath = rootPath + StringPool.SLASH + bundle.getSymbolicName();
                File destinationDir = new File(bundleDirectoryPath);
                if (destinationDir.exists()) {
                    FileUtil.deleteDirectory(destinationDir);
                    File rootDir = new File(rootPath);
                    // Deleting root dir if empty
                    if (rootDir != null && rootDir.exists()) {
                        try {
                            if (FileUtil.isEmptyDirectory(rootDir)) {
                                FileUtil.deleteDirectory(rootDir);
                            } else {
                                _log.debug("rootDirectory is not empty");
                            }
                        } catch (ImexException e) {
                            _log.error(e, e);
                        } catch (IOException e) {
                            _log.error(e, e);
                        }
                    } else {
                        _log.debug("rootDirectory is null or it's does not exists");
                    }
                } else {
                    _log.info("[" + destinationDir.getAbsolutePath() + "] does not exists. Nothing to clean.");
                }
            } else {
                _log.debug("No files found to copy");
            }
        } else {
            _log.warn("Missing required parameter [destinationDirName]");
        }
    } else {
        _log.warn("Missing required parameter [bundle]");
    }
}
Also used : ImexException(com.liferay.imex.core.util.exception.ImexException) IOException(java.io.IOException) File(java.io.File) URL(java.net.URL)

Example 2 with ImexException

use of com.liferay.imex.core.util.exception.ImexException in project liferay-imex by jpdacunha.

the class ImexCoreServiceImpl method deployBundleFiles.

@Override
public void deployBundleFiles(DeployDirEnum destinationDirName, String toCopyBundleDirectoryName, Bundle bundle) {
    if (bundle != null) {
        if (destinationDirName != null) {
            List<URL> urls = FileUtil.findBundleResources(bundle, toCopyBundleDirectoryName, StringPool.STAR);
            if (urls != null && urls.size() > 0) {
                try {
                    String imexHomePath = configurationService.getImexPath();
                    String bundleDirectoryPath = imexHomePath + StringPool.SLASH + destinationDirName.getDirectoryPath() + StringPool.SLASH + bundle.getSymbolicName();
                    File destinationDir = FileUtil.initializeDirectory(bundleDirectoryPath);
                    FileUtil.copyUrlsAsFiles(destinationDir, urls);
                    setFilesPermissions(destinationDir);
                } catch (ImexException e) {
                    _log.error(e, e);
                }
            } else {
                _log.debug("No files found to copy");
            }
        } else {
            _log.warn("Missing required parameter [destinationDirName]");
        }
    } else {
        _log.warn("Missing required parameter [bundle]");
    }
}
Also used : ImexException(com.liferay.imex.core.util.exception.ImexException) File(java.io.File) URL(java.net.URL)

Example 3 with ImexException

use of com.liferay.imex.core.util.exception.ImexException 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);
    }
}
Also used : Company(com.liferay.portal.kernel.model.Company) User(com.liferay.portal.kernel.model.User) Bundle(org.osgi.framework.Bundle) Exporter(com.liferay.imex.core.api.exporter.Exporter) ImexProperties(com.liferay.imex.core.api.configuration.model.ImexProperties) Properties(java.util.Properties) ServiceReference(org.osgi.framework.ServiceReference) ImexException(com.liferay.imex.core.util.exception.ImexException) ImexProperties(com.liferay.imex.core.api.configuration.model.ImexProperties) PortalException(com.liferay.portal.kernel.exception.PortalException) Map(java.util.Map) File(java.io.File)

Example 4 with ImexException

use of com.liferay.imex.core.util.exception.ImexException 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);
        }
    }
}
Also used : ImexException(com.liferay.imex.core.util.exception.ImexException) ExporterProcessIdentifierGenerator(com.liferay.imex.core.service.exporter.model.ExporterProcessIdentifierGenerator) ProcessIdentifierGenerator(com.liferay.imex.core.api.identifier.ProcessIdentifierGenerator) RawExporterProcessIdentifierGeneratorWrapper(com.liferay.imex.core.service.exporter.model.RawExporterProcessIdentifierGeneratorWrapper) ExporterRawContent(com.liferay.imex.core.api.exporter.model.ExporterRawContent) ImexProperties(com.liferay.imex.core.api.configuration.model.ImexProperties) ImexProperties(com.liferay.imex.core.api.configuration.model.ImexProperties) Properties(java.util.Properties) File(java.io.File)

Example 5 with ImexException

use of com.liferay.imex.core.util.exception.ImexException in project liferay-imex by jpdacunha.

the class ImexExportServiceImpl method initializeExportDirectory.

private File initializeExportDirectory() throws ImexException {
    String exportFilePath = configurationService.getImexDataPath();
    File exportFile = new File(exportFilePath);
    if (exportFile.exists()) {
        FileUtil.deltree(exportFile);
    }
    exportFile.mkdirs();
    if (!exportFile.exists()) {
        throw new ImexException("Failed to create directory " + exportFile);
    }
    String logsDirPath = configurationService.getImexLogsPath();
    File logsDir = new File(logsDirPath);
    logsDir.mkdirs();
    if (!logsDir.exists()) {
        throw new ImexException("Failed to create directory " + logsDir);
    }
    return exportFile;
}
Also used : ImexException(com.liferay.imex.core.util.exception.ImexException) File(java.io.File)

Aggregations

ImexException (com.liferay.imex.core.util.exception.ImexException)20 File (java.io.File)16 PortalException (com.liferay.portal.kernel.exception.PortalException)3 Group (com.liferay.portal.kernel.model.Group)3 DDMTemplate (com.liferay.dynamic.data.mapping.model.DDMTemplate)2 ImexProperties (com.liferay.imex.core.api.configuration.model.ImexProperties)2 ExporterRawContent (com.liferay.imex.core.api.exporter.model.ExporterRawContent)2 ImexRole (com.liferay.imex.role.model.ImexRole)2 IOException (java.io.IOException)2 URL (java.net.URL)2 Properties (java.util.Properties)2 DDMStructure (com.liferay.dynamic.data.mapping.model.DDMStructure)1 ImExAdt (com.liferay.imex.adt.model.ImExAdt)1 Exporter (com.liferay.imex.core.api.exporter.Exporter)1 ProcessIdentifierGenerator (com.liferay.imex.core.api.identifier.ProcessIdentifierGenerator)1 ExporterProcessIdentifierGenerator (com.liferay.imex.core.service.exporter.model.ExporterProcessIdentifierGenerator)1 RawExporterProcessIdentifierGeneratorWrapper (com.liferay.imex.core.service.exporter.model.RawExporterProcessIdentifierGeneratorWrapper)1 RolePermissions (com.liferay.imex.role.model.RolePermissions)1 ImexSite (com.liferay.imex.site.model.ImexSite)1 NoSuchGroupException (com.liferay.portal.kernel.exception.NoSuchGroupException)1