Search in sources :

Example 1 with ExporterRawContent

use of com.liferay.imex.core.api.exporter.model.ExporterRawContent 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 2 with ExporterRawContent

use of com.liferay.imex.core.api.exporter.model.ExporterRawContent in project liferay-imex by jpdacunha.

the class WcDDMExporter method writeTemplate.

private void writeTemplate(Group group, Locale locale, List<ExporterRawContent> rawContentToExport, File structureDir, String groupName, DDMTemplate ddmTemplate) throws Exception {
    ImExTemplate imexTemplate = new ImExTemplate(ddmTemplate);
    processor.write(imexTemplate, structureDir, FileNames.getTemplateFileName(ddmTemplate, locale, processor.getFileExtension()));
    String rawFileName = FileNames.getGroupTemplateFileName(ddmTemplate, group, locale, StringPool.PERIOD + imexTemplate.getLangType());
    rawContentToExport.add(new ExporterRawContent(rawFileName, imexTemplate.getData()));
}
Also used : ExporterRawContent(com.liferay.imex.core.api.exporter.model.ExporterRawContent) ImExTemplate(com.liferay.imex.wcddm.model.ImExTemplate)

Example 3 with ExporterRawContent

use of com.liferay.imex.core.api.exporter.model.ExporterRawContent in project liferay-imex by jpdacunha.

the class AdtExporter method doExport.

public void doExport(Properties config, Group group, File groupsDir, Locale locale, boolean debug, String classType, List<ExporterRawContent> rawContentToExport) throws ImexException {
    if (group != null) {
        long classNameId = classNameLocalService.getClassNameId(classType);
        List<DDMTemplate> adts = dDMTemplateLocalService.getTemplates(group.getGroupId(), classNameId);
        if (adts != null && adts.size() > 0) {
            File groupDir = initializeSingleGroupDirectory(groupsDir, group);
            if (groupDir != null) {
                if (groupDir.exists()) {
                    // Iterate over structures
                    for (DDMTemplate ddmTemplate : adts) {
                        File adtDir = initializeSingleAdtExportDirectory(groupDir, classType);
                        if (adtDir != null) {
                            if (adtDir.exists()) {
                                try {
                                    String groupName = GroupUtil.getGroupName(group, locale);
                                    ImExAdt imexAdt = new ImExAdt(ddmTemplate, classType);
                                    processor.write(imexAdt, adtDir, FileNames.getAdtFileName(ddmTemplate, locale, processor.getFileExtension()));
                                    String rawFileName = FileNames.getGroupAdtFileName(ddmTemplate, group, locale, StringPool.PERIOD + imexAdt.getLangType());
                                    rawContentToExport.add(new ExporterRawContent(rawFileName, imexAdt.getData()));
                                    reportService.getOK(_log, groupName, "ADT : " + ddmTemplate.getName(locale) + ", type : " + classType);
                                } catch (Exception e) {
                                    reportService.getError(_log, ddmTemplate.getName(locale), e);
                                    if (debug) {
                                        _log.error(e, e);
                                    }
                                }
                            } else {
                                reportService.getDNE(_log, adtDir.getAbsolutePath());
                            }
                        } else {
                            _log.error("adtDir is null ...");
                        }
                    }
                } else {
                    reportService.getDNE(_log, groupDir.getAbsolutePath());
                }
            } else {
                _log.error("groupDir is null ...");
            }
        } else {
            reportService.getEmpty(_log, group, locale, classType);
        }
    } else {
        _log.error("Skipping null group ...");
    }
}
Also used : ImExAdt(com.liferay.imex.adt.model.ImExAdt) ExporterRawContent(com.liferay.imex.core.api.exporter.model.ExporterRawContent) DDMTemplate(com.liferay.dynamic.data.mapping.model.DDMTemplate) File(java.io.File) ImexException(com.liferay.imex.core.util.exception.ImexException)

Example 4 with ExporterRawContent

use of com.liferay.imex.core.api.exporter.model.ExporterRawContent in project liferay-imex by jpdacunha.

the class WcDDMExporter method writeStructure.

private void writeStructure(Group group, Locale locale, List<ExporterRawContent> rawContentToExport, DDMStructure ddmStructure, File structureDir) throws Exception {
    ImExStructure imexStructure = new ImExStructure(ddmStructure);
    processor.write(imexStructure, structureDir, FileNames.getStructureFileName(ddmStructure, locale, processor.getFileExtension()));
    String rawFileName = FileNames.getGroupStructureFileName(ddmStructure, group, locale, FileUtil.JSON_EXTENSION);
    rawContentToExport.add(new ExporterRawContent(rawFileName, imexStructure.getData()));
}
Also used : ExporterRawContent(com.liferay.imex.core.api.exporter.model.ExporterRawContent) ImExStructure(com.liferay.imex.wcddm.model.ImExStructure)

Aggregations

ExporterRawContent (com.liferay.imex.core.api.exporter.model.ExporterRawContent)4 ImexException (com.liferay.imex.core.util.exception.ImexException)2 File (java.io.File)2 DDMTemplate (com.liferay.dynamic.data.mapping.model.DDMTemplate)1 ImExAdt (com.liferay.imex.adt.model.ImExAdt)1 ImexProperties (com.liferay.imex.core.api.configuration.model.ImexProperties)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 ImExStructure (com.liferay.imex.wcddm.model.ImExStructure)1 ImExTemplate (com.liferay.imex.wcddm.model.ImExTemplate)1 Properties (java.util.Properties)1