Search in sources :

Example 1 with Pre4VersionDumpEntryJson

use of com.enonic.xp.repo.impl.dump.upgrade.obsoletemodel.pre4.Pre4VersionDumpEntryJson in project xp by enonic.

the class FlattenedPageDumpUpgrader method doUpgrade.

@Override
public void doUpgrade(final String dumpName) {
    super.doUpgrade(dumpName);
    final Path versionsFile = dumpReader.getVersionsFile(REPOSITORY_ID);
    if (Files.exists(versionsFile)) {
        // Gathers the template -> controller mappings
        final TemplateControllerMappings templateControllerMappings = new TemplateControllerMappings();
        processEntries((entryContent, entryName) -> {
            final Pre4VersionsDumpEntryJson sourceEntry = deserializeValue(entryContent, Pre4VersionsDumpEntryJson.class);
            final Pre4VersionDumpEntryJson sourceVersion = sourceEntry.getVersions().stream().findFirst().get();
            addTemplateControllerMapping(sourceVersion, templateControllerMappings);
        }, versionsFile);
        final Map<String, String> templateControllerMap = templateControllerMappings.getMappings();
        // Update contents with pages
        final FlattenedPageDataUpgrader dataUpgrader = FlattenedPageDataUpgrader.create().templateControllerMap(templateControllerMap).build();
        processEntries((entryContent, entryName) -> {
            result.processed();
            try {
                final Pre4VersionsDumpEntryJson sourceEntry = deserializeValue(entryContent, Pre4VersionsDumpEntryJson.class);
                sourceEntry.getVersions().forEach(version -> upgradeVersionMeta(version, dataUpgrader));
            } catch (Exception e) {
                result.error();
                LOG.error("Error while upgrading version entry [" + entryName + "]", e);
            }
        }, versionsFile);
    } else {
        dumpReader.getBranches(REPOSITORY_ID).forEach(this::upgradeBranch);
    }
}
Also used : Path(java.nio.file.Path) Pre4VersionsDumpEntryJson(com.enonic.xp.repo.impl.dump.upgrade.obsoletemodel.pre4.Pre4VersionsDumpEntryJson) Pre4VersionDumpEntryJson(com.enonic.xp.repo.impl.dump.upgrade.obsoletemodel.pre4.Pre4VersionDumpEntryJson) DumpUpgradeException(com.enonic.xp.repo.impl.dump.upgrade.DumpUpgradeException) IOException(java.io.IOException) RepoDumpException(com.enonic.xp.repo.impl.dump.RepoDumpException)

Example 2 with Pre4VersionDumpEntryJson

use of com.enonic.xp.repo.impl.dump.upgrade.obsoletemodel.pre4.Pre4VersionDumpEntryJson in project xp by enonic.

the class IndexAccessSegmentsDumpUpgrader method upgradeVersionDumpEntry.

private Pre6VersionDumpEntryJson upgradeVersionDumpEntry(final RepositoryId repositoryId, final Pre4VersionDumpEntryJson versionDumpEntry) {
    // Retrieves the existing node version
    final Segment nodeDataSegment = RepositorySegmentUtils.toSegment(repositoryId, DumpConstants.DUMP_NODE_SEGMENT_LEVEL);
    final BlobKey nodeBlobKey = BlobKey.from(versionDumpEntry.getBlobKey());
    final DumpBlobRecord nodeBlobRecord = dumpReader.getDumpBlobStore().getRecord(nodeDataSegment, nodeBlobKey);
    final Pre4NodeVersionJson nodeVersion = getNodeVersion(nodeBlobRecord);
    // Serializes the new index config blob
    final byte[] serializedIndexConfig = serialize(nodeVersion.getIndexConfigDocument());
    final Segment indexConfigSegment = RepositorySegmentUtils.toSegment(repositoryId, DumpConstants.DUMP_INDEX_CONFIG_SEGMENT_LEVEL);
    final BlobKey indexConfigBlobKey = addRecord(indexConfigSegment, serializedIndexConfig);
    // Serializes the new access control blob
    final byte[] serializedAccessControl = serializeAccessControl(nodeVersion);
    final Segment accessControlSegment = RepositorySegmentUtils.toSegment(repositoryId, DumpConstants.DUMP_ACCESS_CONTROL_SEGMENT_LEVEL);
    final BlobKey accessControlBlobKey = addRecord(accessControlSegment, serializedAccessControl);
    // Return the new version dump entry
    return Pre6VersionDumpEntryJson.create().nodePath(versionDumpEntry.getNodePath()).timestamp(versionDumpEntry.getTimestamp()).version(versionDumpEntry.getVersion()).nodeBlobKey(versionDumpEntry.getBlobKey()).indexConfigBlobKey(indexConfigBlobKey.toString()).accessControlBlobKey(accessControlBlobKey.toString()).nodeState(versionDumpEntry.getNodeState()).build();
}
Also used : Pre4NodeVersionJson(com.enonic.xp.repo.impl.dump.upgrade.obsoletemodel.pre4.Pre4NodeVersionJson) BlobKey(com.enonic.xp.blob.BlobKey) DumpBlobRecord(com.enonic.xp.repo.impl.dump.blobstore.DumpBlobRecord) Segment(com.enonic.xp.blob.Segment)

Aggregations

BlobKey (com.enonic.xp.blob.BlobKey)1 Segment (com.enonic.xp.blob.Segment)1 RepoDumpException (com.enonic.xp.repo.impl.dump.RepoDumpException)1 DumpBlobRecord (com.enonic.xp.repo.impl.dump.blobstore.DumpBlobRecord)1 DumpUpgradeException (com.enonic.xp.repo.impl.dump.upgrade.DumpUpgradeException)1 Pre4NodeVersionJson (com.enonic.xp.repo.impl.dump.upgrade.obsoletemodel.pre4.Pre4NodeVersionJson)1 Pre4VersionDumpEntryJson (com.enonic.xp.repo.impl.dump.upgrade.obsoletemodel.pre4.Pre4VersionDumpEntryJson)1 Pre4VersionsDumpEntryJson (com.enonic.xp.repo.impl.dump.upgrade.obsoletemodel.pre4.Pre4VersionsDumpEntryJson)1 IOException (java.io.IOException)1 Path (java.nio.file.Path)1