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